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

@pljones pljones Jun 20, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I suggest this is loosened a bit.

Currently, the welcome message is sent to the chat window because it looks like a chat message sent from the server to that client.

I'd like the same protocol here with the exception that it's connectionless. The request should come in and, should the server choose to respond (or support the request), the response should go out "looking like a chat message".

I'm hoping that way there can be more reuse of code than the approach here.

(Yes, it still needs two new protocol messages.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand what you're getting at here. The bit FS_HAS_WELCOME_MESSAGE in server features is true if the server operator gave something to -w on invocation, i.e. the welcome message is non-empty. The intention of this message is just to tell the caller what those contents are. I'm not sure what else it could be doing.

And a chat message just looks like | 2 bytes number n | n bytes UTF-8 string |, which is exactly what the contents of this message is too.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not talking about server features.

The server welcome message sent when a client connects to the server is sent as a chat message.

The code to do that exists.

You're writing completely new code to do exactly the same thing here.

Then saying, no, it's not a chat message, it's a welcome message.

That unnecessarily constrains the future use of the protocol 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