diff --git a/ChangeLog b/ChangeLog index 5d649cde..b1be0a45 100644 --- a/ChangeLog +++ b/ChangeLog @@ -23,7 +23,7 @@ -TODO add new register message which contains version and, e.g., max number of clients +TODO bug fix: if group is set to disabled, reset "previous level" TODO improve settings management -> move settings class in client/server classes, move actual settings variables TODO store recorder settings (#313) @@ -38,7 +38,6 @@ TODO Inconsistency between Input meter and Audio mixer meter #423 - 3.5.8 (2020-06-30) - bug fix: incorrect selection of UI language (#408) diff --git a/src/protocol.cpp b/src/protocol.cpp index 37a5355d..2480bd64 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -289,6 +289,14 @@ CONNECTION LESS MESSAGES necessary, that value will contain the server internal address. +- PROTMESSID_CLM_REGISTER_SERVER_EX: Register a server, providing extended server + information + + +--------------------------------+-------------------------------+ + | PROTMESSID_CLM_REGISTER_SERVER | PROTMESSID_CLM_VERSION_AND_OS | + +--------------------------------+-------------------------------+ + + - PROTMESSID_CLM_UNREGISTER_SERVER: Unregister a server note: does not have any data -> n = 0 @@ -738,6 +746,10 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false; bRet = EvaluateCLRegisterServerMes ( InetAddr, vecbyMesBodyData ); break; + case PROTMESSID_CLM_REGISTER_SERVER_EX: + bRet = EvaluateCLRegisterServerExMes ( InetAddr, vecbyMesBodyData ); + break; + case PROTMESSID_CLM_UNREGISTER_SERVER: bRet = EvaluateCLUnregisterServerMes ( InetAddr ); break; @@ -1466,8 +1478,8 @@ void CProtocol::CreateReqChannelLevelListMes ( const bool bRCL ) { CVector vecData ( 1 ); // 1 byte of data int iPos = 0; // init position pointer - PutValOnStream ( vecData, iPos, - static_cast ( bRCL ), 1 ); + + PutValOnStream ( vecData, iPos, static_cast ( bRCL ), 1 ); CreateAndSendMessage ( PROTMESSID_REQ_CHANNEL_LEVEL_LIST, vecData ); } @@ -1820,6 +1832,162 @@ bool CProtocol::EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr, return false; // no error } +void CProtocol::CreateCLRegisterServerExMes ( const CHostAddress& InetAddr, + const CHostAddress& LInetAddr, + const CServerCoreInfo& ServerInfo ) +{ + int iPos = 0; // init position pointer + + // convert server info strings to utf-8 + const QByteArray strUTF8LInetAddr = LInetAddr.InetAddr.toString().toUtf8(); + const QByteArray strUTF8Name = ServerInfo.strName.toUtf8(); + const QByteArray strUTF8City = ServerInfo.strCity.toUtf8(); + const QByteArray strUTF8Version = QString ( VERSION ).toUtf8(); + + // size of current message body + const int iEntrLen = + 2 /* server internal port number */ + + 2 /* country */ + + 1 /* maximum number of connected clients */ + + 1 /* is permanent flag */ + + 2 /* name utf-8 string size */ + strUTF8Name.size() + + 2 /* server internal address utf-8 string size */ + strUTF8LInetAddr.size() + + 2 /* city utf-8 string size */ + strUTF8City.size() + + 1 /* operating system */ + + 2 /* version utf-8 string size */ + strUTF8Version.size(); + + // build data vector + CVector vecData ( iEntrLen ); + + // port number (2 bytes) + PutValOnStream ( vecData, iPos, static_cast ( LInetAddr.iPort ), 2 ); + + // country (2 bytes) + PutValOnStream ( vecData, iPos, static_cast ( ServerInfo.eCountry ), 2 ); + + // maximum number of connected clients (1 byte) + PutValOnStream ( vecData, iPos, static_cast ( ServerInfo.iMaxNumClients ), 1 ); + + // "is permanent" flag (1 byte) + PutValOnStream ( vecData, iPos, static_cast ( ServerInfo.bPermanentOnline ), 1 ); + + // name + PutStringUTF8OnStream ( vecData, iPos, strUTF8Name ); + + // server internal address (formerly unused topic) + PutStringUTF8OnStream ( vecData, iPos, strUTF8LInetAddr ); + + // city + PutStringUTF8OnStream ( vecData, iPos, strUTF8City ); + + // operating system (1 byte) + PutValOnStream ( vecData, iPos, + static_cast ( COSUtil::GetOperatingSystem() ), 1 ); + + // version + PutStringUTF8OnStream ( vecData, iPos, strUTF8Version ); + + CreateAndImmSendConLessMessage ( PROTMESSID_CLM_REGISTER_SERVER, + vecData, + InetAddr ); +} + +bool CProtocol::EvaluateCLRegisterServerExMes ( const CHostAddress& InetAddr, + const CVector& vecData ) +{ + int iPos = 0; // init position pointer + const int iDataLen = vecData.Size(); + QString sLocHost; // temp string for server internal address + CHostAddress LInetAddr; + CServerCoreInfo RecServerInfo; + + // check size (the first 6 bytes) + if ( iDataLen < 6 ) + { + return true; // return error code + } + + // port number (2 bytes) + LInetAddr.iPort = static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); + + // country (2 bytes) + RecServerInfo.eCountry = static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); + + // maximum number of connected clients (1 byte) + RecServerInfo.iMaxNumClients = static_cast ( GetValFromStream ( vecData, iPos, 1 ) ); + + // "is permanent" flag (1 byte) + RecServerInfo.bPermanentOnline = static_cast ( GetValFromStream ( vecData, iPos, 1 ) ); + + // server name + if ( GetStringFromStream ( vecData, + iPos, + MAX_LEN_SERVER_NAME, + RecServerInfo.strName ) ) + { + return true; // return error code + } + + // server internal address + if ( GetStringFromStream ( vecData, + iPos, + MAX_LEN_IP_ADDRESS, + sLocHost ) ) + { + return true; // return error code + } + + if ( sLocHost.isEmpty() ) + { + // old server, empty "topic", register as local host + LInetAddr.InetAddr.setAddress ( QHostAddress::LocalHost ); + } + else if ( !LInetAddr.InetAddr.setAddress ( sLocHost ) ) + { + return true; // return error code + } + + // server city + if ( GetStringFromStream ( vecData, + iPos, + MAX_LEN_SERVER_CITY, + RecServerInfo.strCity ) ) + { + return true; // return error code + } + + // check size (the next 1 byte) + if ( iDataLen < iPos + 1 ) + { + return true; // return error code + } + + // operating system (1 byte) + const COSUtil::EOpSystemType eOSType = + static_cast ( GetValFromStream ( vecData, iPos, 1 ) ); + + // version text + QString strVersion; + if ( GetStringFromStream ( vecData, + iPos, + MAX_LEN_VERSION_TEXT, + strVersion ) ) + { + return true; // return error code + } + + // check size: all data is read, the position must now be at the end + if ( iPos != iDataLen ) + { + return true; // return error code + } + + // invoke message action + emit CLRegisterServerExReceived ( InetAddr, LInetAddr, RecServerInfo, eOSType, strVersion ); + + return false; // no error +} + void CProtocol::CreateCLUnregisterServerMes ( const CHostAddress& InetAddr ) { CreateAndImmSendConLessMessage ( PROTMESSID_CLM_UNREGISTER_SERVER, diff --git a/src/protocol.h b/src/protocol.h index 2c4a0760..f9ea11aa 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -79,6 +79,7 @@ #define PROTMESSID_CLM_REQ_CONN_CLIENTS_LIST 1014 // request the connected clients list #define PROTMESSID_CLM_CHANNEL_LEVEL_LIST 1015 // channel level list #define PROTMESSID_CLM_REGISTER_SERVER_RESP 1016 // status of server registration request +#define PROTMESSID_CLM_REGISTER_SERVER_EX 1017 // register server with extended information // lengths of message as defined in protocol.cpp file #define MESS_HEADER_LENGTH_BYTE 7 // TAG (2), ID (2), cnt (1), length (2) @@ -125,6 +126,9 @@ public: void CreateCLRegisterServerMes ( const CHostAddress& InetAddr, const CHostAddress& LInetAddr, const CServerCoreInfo& ServerInfo ); + void CreateCLRegisterServerExMes ( const CHostAddress& InetAddr, + const CHostAddress& LInetAddr, + const CServerCoreInfo& ServerInfo ); void CreateCLUnregisterServerMes ( const CHostAddress& InetAddr ); void CreateCLServerListMes ( const CHostAddress& InetAddr, const CVector vecServerInfo ); @@ -250,6 +254,8 @@ protected: bool EvaluateCLServerFullMes(); bool EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr, const CVector& vecData ); + bool EvaluateCLRegisterServerExMes ( const CHostAddress& InetAddr, + const CVector& vecData ); bool EvaluateCLUnregisterServerMes ( const CHostAddress& InetAddr ); bool EvaluateCLServerListMes ( const CHostAddress& InetAddr, const CVector& vecData ); @@ -315,6 +321,11 @@ signals: void CLRegisterServerReceived ( CHostAddress InetAddr, CHostAddress LInetAddr, CServerCoreInfo ServerInfo ); + void CLRegisterServerExReceived ( CHostAddress InetAddr, + CHostAddress LInetAddr, + CServerCoreInfo ServerInfo, + COSUtil::EOpSystemType eOSType, + QString strVersion ); void CLUnregisterServerReceived ( CHostAddress InetAddr ); void CLServerListReceived ( CHostAddress InetAddr, CVector vecServerInfo ); diff --git a/src/server.cpp b/src/server.cpp index 56739a83..499c57cc 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -449,6 +449,9 @@ CServer::CServer ( const int iNewMaxNumChan, QObject::connect ( &ConnLessProtocol, &CProtocol::CLRegisterServerReceived, this, &CServer::OnCLRegisterServerReceived ); + QObject::connect ( &ConnLessProtocol, &CProtocol::CLRegisterServerExReceived, + this, &CServer::OnCLRegisterServerExReceived ); + QObject::connect ( &ConnLessProtocol, &CProtocol::CLUnregisterServerReceived, this, &CServer::OnCLUnregisterServerReceived ); diff --git a/src/server.h b/src/server.h index 8def4f9f..08766acb 100755 --- a/src/server.h +++ b/src/server.h @@ -462,6 +462,15 @@ public slots: ServerListManager.CentralServerRegisterServer ( InetAddr, LInetAddr, ServerInfo ); } + void OnCLRegisterServerExReceived ( CHostAddress InetAddr, + CHostAddress LInetAddr, + CServerCoreInfo ServerInfo, + COSUtil::EOpSystemType eOSType, + QString strVersion ) + { + ServerListManager.CentralServerRegisterServerEx ( InetAddr, LInetAddr, ServerInfo, eOSType, strVersion ); + } + void OnCLRegisterServerResp ( CHostAddress /* unused */, ESvrRegResult eResult ) { diff --git a/src/serverlist.cpp b/src/serverlist.cpp index 78074d87..e215835c 100755 --- a/src/serverlist.cpp +++ b/src/serverlist.cpp @@ -340,6 +340,16 @@ void CServerListManager::OnTimerPollList() } } +void CServerListManager::CentralServerRegisterServerEx ( const CHostAddress& InetAddr, + const CHostAddress& LInetAddr, + const CServerCoreInfo& ServerInfo, + const COSUtil::EOpSystemType , + const QString& ) +{ +// TODO right now we do not make use of the additional operating system and version number informations +CentralServerRegisterServer ( InetAddr, LInetAddr, ServerInfo ); +} + void CServerListManager::CentralServerRegisterServer ( const CHostAddress& InetAddr, const CHostAddress& LInetAddr, const CServerCoreInfo& ServerInfo ) diff --git a/src/serverlist.h b/src/serverlist.h index f26003bf..e2f0ff85 100755 --- a/src/serverlist.h +++ b/src/serverlist.h @@ -147,6 +147,12 @@ public: const CHostAddress& LInetAddr, const CServerCoreInfo& ServerInfo ); + void CentralServerRegisterServerEx ( const CHostAddress& InetAddr, + const CHostAddress& LInetAddr, + const CServerCoreInfo& ServerInfo, + const COSUtil::EOpSystemType , + const QString& ); + void CentralServerUnregisterServer ( const CHostAddress& InetAddr ); void CentralServerQueryServerList ( const CHostAddress& InetAddr );