Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,18 @@ CONNECTION LESS MESSAGES

note: does not have any data -> n = 0


- PROTMESSID_CLM_WELCOME_MESSAGE: Server welcome message

+------------------+--------------------------------------+
| 2 bytes number n | n bytes UTF-8 string welcome message |
+------------------+--------------------------------------+


- PROTMESSID_CLM_REQ_WELCOME_MESSAGE: Request server welcome message

note: does not have any data -> n = 0

*/

#include "protocol.h"
Expand Down Expand Up @@ -964,6 +976,10 @@ void CProtocol::ParseConnectionLessMessageBody ( const CVector<uint8_t>& vecbyMe
case PROTMESSID_CLM_REQ_SERVER_FEATURES:
EvaluateCLReqServerFeaturesMes ( InetAddr );
break;

case PROTMESSID_CLM_REQ_WELCOME_MESSAGE:
EvaluateCLReqWelcomeMessageMes ( InetAddr );
break;
}
}

Expand Down Expand Up @@ -2655,6 +2671,35 @@ void CProtocol::CreateCLServerFeaturesMes ( const CHostAddress& InetAddr, const
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_SERVER_FEATURES, vecData, InetAddr );
}

bool CProtocol::EvaluateCLReqWelcomeMessageMes ( const CHostAddress& InetAddr )
{
// invoke message action
emit CLReqWelcomeMessage ( InetAddr );

return false; // no error
}

void CProtocol::CreateCLWelcomeMessageMes ( const CHostAddress& InetAddr, const QString strWelcomeMessage )
{
int iPos = 0; // init position pointer

// convert chat text string to utf-8
const QByteArray strUTF8WelcomeMessage = strWelcomeMessage.toUtf8();

const int iStrUTF8Len = strUTF8WelcomeMessage.size(); // get utf-8 str. size / string

// size of message body
const int iEntrLen = 2 + iStrUTF8Len; // utf-8 str. size / string

// build data vector
CVector<uint8_t> vecData ( iEntrLen );

// chat text
PutStringUTF8OnStream ( vecData, iPos, strUTF8WelcomeMessage );

CreateAndImmSendConLessMessage ( PROTMESSID_CLM_WELCOME_MESSAGE, vecData, InetAddr );
}

/******************************************************************************\
* Message generation and parsing *
\******************************************************************************/
Expand Down
5 changes: 5 additions & 0 deletions src/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@
#define PROTMESSID_CLM_RED_SERVER_LIST 1018 // reduced server list
#define PROTMESSID_CLM_SERVER_FEATURES 1019 // server features message
#define PROTMESSID_CLM_REQ_SERVER_FEATURES 1020 // request server features
#define PROTMESSID_CLM_WELCOME_MESSAGE 1021 // server welcome message
#define PROTMESSID_CLM_REQ_WELCOME_MESSAGE 1022 // request server welcome message

// special IDs
#define PROTMESSID_SPECIAL_SPLIT_MESSAGE 2001 // a container for split messages
Expand Down Expand Up @@ -180,6 +182,7 @@ class CProtocol : public QObject
void CreateCLChannelLevelListMes ( const CHostAddress& InetAddr, const CVector<uint16_t>& vecLevelList, const int iNumClients );
void CreateCLRegisterServerResp ( const CHostAddress& InetAddr, const ESvrRegResult eResult );
void CreateCLServerFeaturesMes ( const CHostAddress& InetAddr, const uint32_t iResult );
void CreateCLWelcomeMessageMes ( const CHostAddress& InetAddr, const QString strWelcomeMessage );

static bool ParseMessageFrame ( const CVector<uint8_t>& vecbyData,
const int iNumBytesIn,
Expand Down Expand Up @@ -308,6 +311,7 @@ class CProtocol : public QObject
bool EvaluateCLChannelLevelListMes ( const CHostAddress& InetAddr, const CVector<uint8_t>& vecData );
bool EvaluateCLRegisterServerResp ( const CHostAddress& InetAddr, const CVector<uint8_t>& vecData );
bool EvaluateCLReqServerFeaturesMes ( const CHostAddress& InetAddr );
bool EvaluateCLReqWelcomeMessageMes ( const CHostAddress& InetAddr );

int iOldRecID;
int iOldRecCnt;
Expand Down Expand Up @@ -376,4 +380,5 @@ public slots:
void CLChannelLevelListReceived ( CHostAddress InetAddr, CVector<uint16_t> vecLevelList );
void CLRegisterServerResp ( CHostAddress InetAddr, ESvrRegResult eStatus );
void CLReqServerFeatures ( CHostAddress InetAddr );
void CLReqWelcomeMessage ( CHostAddress InetAddr );
};
8 changes: 8 additions & 0 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ CServer::CServer ( const int iNewMaxNumChan,

QObject::connect ( &ConnLessProtocol, &CProtocol::CLReqServerFeatures, this, &CServer::OnCLReqServerFeatures );

QObject::connect ( &ConnLessProtocol, &CProtocol::CLReqWelcomeMessage, this, &CServer::OnCLReqWelcomeMessage );

QObject::connect ( &ServerListManager, &CServerListManager::SvrRegStatusChanged, this, &CServer::SvrRegStatusChanged );

QObject::connect ( &JamController, &recorder::CJamController::RestartRecorder, this, &CServer::RestartRecorder );
Expand Down Expand Up @@ -529,6 +531,12 @@ void CServer::OnCLReqServerFeatures ( CHostAddress RecHostAddr )
ConnLessProtocol.CreateCLServerFeaturesMes ( RecHostAddr, iFeatures );
}

void CServer::OnCLReqWelcomeMessage ( CHostAddress RecHostAddr )
{
// Create and send the message
ConnLessProtocol.CreateCLWelcomeMessageMes ( RecHostAddr, strWelcomeMessage );
}

void CServer::OnServerFull ( CHostAddress RecHostAddr )
{
// note: no mutex required here
Expand Down
2 changes: 2 additions & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ public slots:

void OnCLReqServerFeatures ( CHostAddress InetAddr );

void OnCLReqWelcomeMessage ( CHostAddress InetAddr );

void OnCLDisconnection ( CHostAddress InetAddr );

void OnAboutToQuit();
Expand Down
Loading