From d21acb0a7f3f6103e3f809ca2627a8ab6821e559 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Mon, 18 May 2020 19:00:56 +0200 Subject: [PATCH] server sends version info on initial connection --- src/channel.h | 1 + src/protocol.cpp | 77 +++++++++++++++++++++++++++++++++++++++++++++++- src/protocol.h | 4 +++ src/server.cpp | 3 ++ 4 files changed, 84 insertions(+), 1 deletion(-) diff --git a/src/channel.h b/src/channel.h index 3369b535..9b8638df 100755 --- a/src/channel.h +++ b/src/channel.h @@ -105,6 +105,7 @@ public: { Protocol.CreateChanInfoMes ( ChInfo ); } void CreateReqChanInfoMes() { Protocol.CreateReqChanInfoMes(); } + void CreateVersionAndOSMes() { Protocol.CreateVersionAndOSMes(); } void SetGain ( const int iChanID, const double dNewGain ); double GetGain ( const int iChanID ); diff --git a/src/protocol.cpp b/src/protocol.cpp index 090fa992..abbbb3c3 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -154,7 +154,7 @@ MESSAGES (with connection) | 1 byte licence type | +---------------------+ -- PROTMESSID_CLM_REQ_CHANNEL_LEVEL_LIST: Opt in or out of the channel level list +- PROTMESSID_REQ_CHANNEL_LEVEL_LIST: Opt in or out of the channel level list +---------------+ | 1 byte option | @@ -162,6 +162,12 @@ MESSAGES (with connection) option is boolean, true to opt in, false to opt out +- PROTMESSID_VERSION_AND_OS: Version number and operating system + + +-------------------------+------------------+------------------------------+ + | 1 byte operating system | 2 bytes number n | n bytes UTF-8 string version | + +-------------------------+------------------+------------------------------+ + // #### COMPATIBILITY OLD VERSION, TO BE REMOVED #### - PROTMESSID_OPUS_SUPPORTED: Informs that OPUS codec is supported @@ -608,6 +614,10 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false; case PROTMESSID_REQ_CHANNEL_LEVEL_LIST: bRet = EvaluateReqChannelLevelListMes ( vecbyMesBodyData ); break; + + case PROTMESSID_VERSION_AND_OS: + bRet = EvaluateVersionAndOSMes ( vecbyMesBodyData ); + break; } // immediately send acknowledge message @@ -1335,6 +1345,71 @@ bool CProtocol::EvaluateReqChannelLevelListMes ( const CVector& vecData return false; // no error } +void CProtocol::CreateVersionAndOSMes() +{ + int iPos = 0; // init position pointer + + // get the version number string + const QString strVerion = VERSION; + + // convert version string to utf-8 + const QByteArray strUTF8Version = strVerion.toUtf8(); + + // size of current message body + const int iEntrLen = + 1 /* operating system */ + + 2 /* version utf-8 string size */ + strUTF8Version.size(); + + // build data vector + CVector vecData ( iEntrLen ); + + // operating system (1 byte) + PutValOnStream ( vecData, iPos, + static_cast ( COSUtil::GetOperatingSystem() ), 1 ); + + // version + PutStringUTF8OnStream ( vecData, iPos, strUTF8Version ); + + CreateAndSendMessage ( PROTMESSID_VERSION_AND_OS, vecData ); +} + +bool CProtocol::EvaluateVersionAndOSMes ( const CVector& vecData ) +{ + int iPos = 0; // init position pointer + const int iDataLen = vecData.Size(); + + // check size (the first 1 byte) + if ( iDataLen < 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 VersionAndOSReceived ( eOSType, strVersion ); + + return false; // no error +} + // Connection less messages ---------------------------------------------------- void CProtocol::CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs ) diff --git a/src/protocol.h b/src/protocol.h index 027c4284..524c4927 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -55,6 +55,7 @@ #define PROTMESSID_OPUS_SUPPORTED 26 // tells that OPUS codec is supported #define PROTMESSID_LICENCE_REQUIRED 27 // licence required #define PROTMESSID_REQ_CHANNEL_LEVEL_LIST 28 // request the channel level list +#define PROTMESSID_VERSION_AND_OS 29 // version number and operating system // message IDs of connection less messages (CLM) // DEFINITION -> start at 1000, end at 1999, see IsConnectionLessMessageID @@ -106,6 +107,7 @@ public: void CreateLicenceRequiredMes ( const ELicenceType eLicenceType ); void CreateOpusSupportedMes(); void CreateReqChannelLevelListMes ( const bool bRCL ); + void CreateVersionAndOSMes(); void CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs ); void CreateCLPingWithNumClientsMes ( const CHostAddress& InetAddr, @@ -227,6 +229,7 @@ protected: bool EvaluateReqNetwTranspPropsMes(); bool EvaluateLicenceRequiredMes ( const CVector& vecData ); bool EvaluateReqChannelLevelListMes ( const CVector& vecData ); + bool EvaluateVersionAndOSMes ( const CVector& vecData ); bool EvaluateCLPingMes ( const CHostAddress& InetAddr, const CVector& vecData ); @@ -286,6 +289,7 @@ signals: void ReqNetTranspProps(); void LicenceRequired ( ELicenceType eLicenceType ); void ReqChannelLevelList ( bool bOptIn ); + void VersionAndOSReceived ( COSUtil::EOpSystemType eOSType, QString strVersion ); void CLPingReceived ( CHostAddress InetAddr, int iMs ); diff --git a/src/server.cpp b/src/server.cpp index 794799c1..6fa181bc 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -597,6 +597,9 @@ CreateAndSendChanListForAllConChannels(); vecChannels[iChID].CreateLicReqMes ( eLicenceType ); } + // send version info (for, e.g., feature activation in the client) + vecChannels[iChID].CreateVersionAndOSMes(); + // reset the conversion buffers DoubleFrameSizeConvBufIn[iChID].Reset(); DoubleFrameSizeConvBufOut[iChID].Reset();