Skip to content

Commit ebcf944

Browse files
authored
Merge pull request #3742 from softins/fetch-welcome-message
Add CLM protocol to get Welcome Message
2 parents 286191a + 431329d commit ebcf944

4 files changed

Lines changed: 60 additions & 0 deletions

File tree

src/protocol.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,18 @@ CONNECTION LESS MESSAGES
472472
473473
note: does not have any data -> n = 0
474474
475+
476+
- PROTMESSID_CLM_WELCOME_MESSAGE: Server welcome message
477+
478+
+------------------+--------------------------------------+
479+
| 2 bytes number n | n bytes UTF-8 string welcome message |
480+
+------------------+--------------------------------------+
481+
482+
483+
- PROTMESSID_CLM_REQ_WELCOME_MESSAGE: Request server welcome message
484+
485+
note: does not have any data -> n = 0
486+
475487
*/
476488

477489
#include "protocol.h"
@@ -964,6 +976,10 @@ void CProtocol::ParseConnectionLessMessageBody ( const CVector<uint8_t>& vecbyMe
964976
case PROTMESSID_CLM_REQ_SERVER_FEATURES:
965977
EvaluateCLReqServerFeaturesMes ( InetAddr );
966978
break;
979+
980+
case PROTMESSID_CLM_REQ_WELCOME_MESSAGE:
981+
EvaluateCLReqWelcomeMessageMes ( InetAddr );
982+
break;
967983
}
968984
}
969985

@@ -2655,6 +2671,35 @@ void CProtocol::CreateCLServerFeaturesMes ( const CHostAddress& InetAddr, const
26552671
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_SERVER_FEATURES, vecData, InetAddr );
26562672
}
26572673

2674+
bool CProtocol::EvaluateCLReqWelcomeMessageMes ( const CHostAddress& InetAddr )
2675+
{
2676+
// invoke message action
2677+
emit CLReqWelcomeMessage ( InetAddr );
2678+
2679+
return false; // no error
2680+
}
2681+
2682+
void CProtocol::CreateCLWelcomeMessageMes ( const CHostAddress& InetAddr, const QString strWelcomeMessage )
2683+
{
2684+
int iPos = 0; // init position pointer
2685+
2686+
// convert chat text string to utf-8
2687+
const QByteArray strUTF8WelcomeMessage = strWelcomeMessage.toUtf8();
2688+
2689+
const int iStrUTF8Len = strUTF8WelcomeMessage.size(); // get utf-8 str. size / string
2690+
2691+
// size of message body
2692+
const int iEntrLen = 2 + iStrUTF8Len; // utf-8 str. size / string
2693+
2694+
// build data vector
2695+
CVector<uint8_t> vecData ( iEntrLen );
2696+
2697+
// chat text
2698+
PutStringUTF8OnStream ( vecData, iPos, strUTF8WelcomeMessage );
2699+
2700+
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_WELCOME_MESSAGE, vecData, InetAddr );
2701+
}
2702+
26582703
/******************************************************************************\
26592704
* Message generation and parsing *
26602705
\******************************************************************************/

src/protocol.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@
108108
#define PROTMESSID_CLM_RED_SERVER_LIST 1018 // reduced server list
109109
#define PROTMESSID_CLM_SERVER_FEATURES 1019 // server features message
110110
#define PROTMESSID_CLM_REQ_SERVER_FEATURES 1020 // request server features
111+
#define PROTMESSID_CLM_WELCOME_MESSAGE 1021 // server welcome message
112+
#define PROTMESSID_CLM_REQ_WELCOME_MESSAGE 1022 // request server welcome message
111113

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

184187
static bool ParseMessageFrame ( const CVector<uint8_t>& vecbyData,
185188
const int iNumBytesIn,
@@ -308,6 +311,7 @@ class CProtocol : public QObject
308311
bool EvaluateCLChannelLevelListMes ( const CHostAddress& InetAddr, const CVector<uint8_t>& vecData );
309312
bool EvaluateCLRegisterServerResp ( const CHostAddress& InetAddr, const CVector<uint8_t>& vecData );
310313
bool EvaluateCLReqServerFeaturesMes ( const CHostAddress& InetAddr );
314+
bool EvaluateCLReqWelcomeMessageMes ( const CHostAddress& InetAddr );
311315

312316
int iOldRecID;
313317
int iOldRecCnt;
@@ -376,4 +380,5 @@ public slots:
376380
void CLChannelLevelListReceived ( CHostAddress InetAddr, CVector<uint16_t> vecLevelList );
377381
void CLRegisterServerResp ( CHostAddress InetAddr, ESvrRegResult eStatus );
378382
void CLReqServerFeatures ( CHostAddress InetAddr );
383+
void CLReqWelcomeMessage ( CHostAddress InetAddr );
379384
};

src/server.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ CServer::CServer ( const int iNewMaxNumChan,
294294

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

297+
QObject::connect ( &ConnLessProtocol, &CProtocol::CLReqWelcomeMessage, this, &CServer::OnCLReqWelcomeMessage );
298+
297299
QObject::connect ( &ServerListManager, &CServerListManager::SvrRegStatusChanged, this, &CServer::SvrRegStatusChanged );
298300

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

534+
void CServer::OnCLReqWelcomeMessage ( CHostAddress RecHostAddr )
535+
{
536+
// Create and send the message
537+
ConnLessProtocol.CreateCLWelcomeMessageMes ( RecHostAddr, strWelcomeMessage );
538+
}
539+
532540
void CServer::OnServerFull ( CHostAddress RecHostAddr )
533541
{
534542
// note: no mutex required here

src/server.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ public slots:
401401

402402
void OnCLReqServerFeatures ( CHostAddress InetAddr );
403403

404+
void OnCLReqWelcomeMessage ( CHostAddress InetAddr );
405+
404406
void OnCLDisconnection ( CHostAddress InetAddr );
405407

406408
void OnAboutToQuit();

0 commit comments

Comments
 (0)