From ac8a93d9ea60317e11c36416e338b85f242bd8ef Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sun, 10 Feb 2013 08:50:43 +0000 Subject: [PATCH] added protocol message for additional client infos for client list --- src/protocol.cpp | 132 +++++++++++++++++++++++++++++++++++++++++++++-- src/protocol.h | 4 ++ 2 files changed, 131 insertions(+), 5 deletions(-) diff --git a/src/protocol.cpp b/src/protocol.cpp index 58469b9f..3246cb69 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -76,6 +76,22 @@ MESSAGES (with connection) ... ----------------------+ +- PROTMESSID_CONN_CLIENTS_LIST_ADD: Additional information about connected + clients + + for each connected client append following data: + + +-------------------+-----------------+--------------------+ ... + | 1 byte channel ID | 2 bytes country | 4 bytes instrument | ... + +-------------------+-----------------+--------------------+ ... + ... --------------------+ ... + ... 1 byte skill level | ... + ... --------------------+ ... + ... ------------------+---------------------------+ + ... 2 bytes number n | n bytes UTF-8 string city | + ... ------------------+---------------------------+ + + - PROTMESSID_REQ_CONN_CLIENTS_LIST: Request connected clients list note: does not have any data -> n = 0 @@ -502,6 +518,10 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false; bRet = EvaluateConClientListMes ( vecData ); break; + case PROTMESSID_CONN_CLIENTS_LIST_ADD: + bRet = EvaluateConClientListAddMes ( vecData ); + break; + case PROTMESSID_REQ_CONN_CLIENTS_LIST: bRet = EvaluateReqConnClientsList(); break; @@ -737,18 +757,15 @@ void CProtocol::CreateConClientListMes ( const CVector& vecCh // convert name string to utf-8 const QByteArray strUTF8Name = vecChanInfo[i].strName.toUtf8(); - // current utf-8 string size - const int iCurStrUTF8Len = strUTF8Name.size(); - // size of current list entry const int iCurListEntrLen = 1 /* chan ID */ + 4 /* IP addr. */ + - 2 /* utf-8 str. size */ + iCurStrUTF8Len; + 2 /* utf-8 str. size */ + strUTF8Name.size(); // make space for new data vecData.Enlarge ( iCurListEntrLen ); - // channel ID + // channel ID (1 byte) PutValOnStream ( vecData, iPos, static_cast ( vecChanInfo[i].iChanID ), 1 ); @@ -811,6 +828,111 @@ bool CProtocol::EvaluateConClientListMes ( const CVector& vecData ) return false; // no error } +void CProtocol::CreateConClientListAddMes ( const CVector& vecChanInfo ) +{ + const int iNumClients = vecChanInfo.Size(); + + // build data vector + CVector vecData ( 0 ); + int iPos = 0; // init position pointer + + for ( int i = 0; i < iNumClients; i++ ) + { + // convert city string to utf-8 + const QByteArray strUTF8City = vecChanInfo[i].strCity.toUtf8(); + + // size of current list entry + const int iCurListEntrLen = + 1 /* chan ID */ + 2 /* country */ + + 4 /* instrument */ + 1 /* skill level */ + + 2 /* utf-8 str. size */ + strUTF8City.size(); + + // make space for new data + vecData.Enlarge ( iCurListEntrLen ); + + // channel ID (1 byte) + PutValOnStream ( vecData, iPos, + static_cast ( vecChanInfo[i].iChanID ), 1 ); + + // country (2 bytes) + PutValOnStream ( vecData, iPos, + static_cast ( vecChanInfo[i].eCountry ), 2 ); + + // instrument (4 bytes) + PutValOnStream ( vecData, iPos, + static_cast ( vecChanInfo[i].iInstrument ), 4 ); + + // skill level (1 byte) + PutValOnStream ( vecData, iPos, + static_cast ( vecChanInfo[i].iSkillLevel ), 1 ); + + // city + PutStringUTF8OnStream ( vecData, iPos, strUTF8City ); + } + + CreateAndSendMessage ( PROTMESSID_CONN_CLIENTS_LIST_ADD, vecData ); +} + +bool CProtocol::EvaluateConClientListAddMes ( const CVector& vecData ) +{ + int iPos = 0; // init position pointer + const int iDataLen = vecData.Size(); + CVector vecChanInfo ( 0 ); + + while ( iPos < iDataLen ) + { + // check size (the next 8 bytes) + if ( ( iDataLen - iPos ) < 8 ) + { + return true; // return error code + } + + // channel ID (1 byte) + const int iChanID = + static_cast ( GetValFromStream ( vecData, iPos, 1 ) ); + + // country (2 bytes) + const QLocale::Country eCountry = + static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); + + // instrument (4 bytes) + const int iInstrument = + static_cast ( GetValFromStream ( vecData, iPos, 4 ) ); + + // skill level (1 byte) + const int iSkillLevel = + static_cast ( GetValFromStream ( vecData, iPos, 1 ) ); + + // city + QString strCurStr; + if ( GetStringFromStream ( vecData, + iPos, + MAX_LEN_SERVER_CITY, + strCurStr ) ) + { + return true; // return error code + } + + // add channel information to vector + vecChanInfo.Add ( CChannelAdditionalInfo ( iChanID, + eCountry, + strCurStr, + iInstrument, + iSkillLevel ) ); + } + + // 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 ConClientListAddMesReceived ( vecChanInfo ); + + return false; // no error +} + void CProtocol::CreateReqConnClientsList() { CreateAndSendMessage ( PROTMESSID_REQ_CONN_CLIENTS_LIST, CVector ( 0 ) ); diff --git a/src/protocol.h b/src/protocol.h index d6fc567f..de75dfe5 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -51,6 +51,7 @@ #define PROTMESSID_REQ_NETW_TRANSPORT_PROPS 21 // request properties for network transport #define PROTMESSID_DISCONNECTION 22 // OLD (not used anymore) #define PROTMESSID_REQ_CHANNEL_NAME 23 // request channel name for fader tag +#define PROTMESSID_CONN_CLIENTS_LIST_ADD 24 // additional infos for connected clients // message IDs of connection less messages (CLM) // DEFINITION -> start at 1000, end at 1999, see IsConnectionLessMessageID @@ -88,6 +89,7 @@ public: void CreateReqJitBufMes(); void CreateChanGainMes ( const int iChanID, const double dGain ); void CreateConClientListMes ( const CVector& vecChanInfo ); + void CreateConClientListAddMes ( const CVector& vecChanInfo ); void CreateReqConnClientsList(); void CreateChanNameMes ( const QString strName ); void CreateReqChanNameMes(); @@ -199,6 +201,7 @@ protected: bool EvaluateReqJitBufMes(); bool EvaluateChanGainMes ( const CVector& vecData ); bool EvaluateConClientListMes ( const CVector& vecData ); + bool EvaluateConClientListAddMes ( const CVector& vecData ); bool EvaluateReqConnClientsList(); bool EvaluateChanNameMes ( const CVector& vecData ); bool EvaluateReqChanNameMes(); @@ -246,6 +249,7 @@ signals: void ChangeNetwBlSiFact ( int iNewNetwBlSiFact ); void ChangeChanGain ( int iChanID, double dNewGain ); void ConClientListMesReceived ( CVector vecChanInfo ); + void ConClientListAddMesReceived ( CVector vecChanInfo ); void ServerFullMesReceived(); void ReqConnClientsList(); void ChangeChanName ( QString strName );