diff --git a/src/protocol.cpp b/src/protocol.cpp index 18112a88..37e58f7f 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -123,13 +123,16 @@ MESSAGES - "base netw size": length of the base network packet (frame) in bytes - "block size fact": block size factor - - "num chan": number of channels of the audio signal, e.g. "2" is stereo + - "num chan": number of channels of the audio signal, e.g. "2" is + stereo - "sam rate": sample rate of the audio stream - "audiocod type": audio coding type, the following types are supported: - 0: none, no audio coding applied - 1: CELT - - "version": version of the audio coder, if not used this value shall be set to 0 - - "audiocod arg": argument for the audio coder, if not used this value shall be set to 0 + - "version": version of the audio coder, if not used this value + shall be set to 0 + - "audiocod arg": argument for the audio coder, if not used this value + shall be set to 0 - PROTMESSID_REQ_NETW_TRANSPORT_PROPS: Request properties for network transport @@ -146,7 +149,8 @@ MESSAGES CONNECTION LESS MESSAGES ------------------------ -- PROTMESSID_CLM_PING_MS: Connection less ping message (for measuring the ping time) +- PROTMESSID_CLM_PING_MS: Connection less ping message (for measuring the ping + time) note: same definition as PROTMESSID_PING_MS @@ -156,6 +160,35 @@ CONNECTION LESS MESSAGES note: does not have any data -> n = 0 +- PROTMESSID_CLM_REGISTER_SERVER: Register a server, providing server + information + + +------------------+----------------------------------+ ... + | 2 bytes number n | n bytes UTF-8 string server name | ... + +------------------+----------------------------------+ ... + ... -----------------+----------------------------+ ... + ... 2 bytes number n | n bytes UTF-8 string topic | ... + ... -----------------+----------------------------+ ... + ... ----------------+------------------+---------------------------+ ... + ... 2 bytes country | 2 bytes number n | n bytes UTF-8 string city | ... + ... ----------------+------------------+---------------------------+ ... + ... --------------------------------+ ... + ... 1 byte number connected clients | ... + ... --------------------------------+ ... + ... ---------------------------------+---------------------+ + ... 1 byte maximum connected clients | 1 byte is permanent | + ... ---------------------------------+---------------------+ + + - "country" is according to "Common Locale Data Repository" which is used in + the QLocale class + - "connected clients" is the current number of connected clients + - "maximum connected clients" is the maximum number of clients which can + be connected to the server at the same time + - "is permanent" is a flag which indicates if the server is permanent + online or not. If this value is any value <> 0 indicates that the server + is permanent online. + + ****************************************************************************** * * This program is free software; you can redistribute it and/or modify it under @@ -553,7 +586,7 @@ bool CProtocol::ParseConnectionLessMessage ( const CVector& vecbyData, void CProtocol::CreateJitBufMes ( const int iJitBufSize ) { CVector vecData ( 2 ); // 2 bytes of data - unsigned int iPos = 0; // init position pointer + unsigned int iPos = 0; // init position pointer // build data vector PutValOnStream ( vecData, iPos, static_cast ( iJitBufSize ), 2 ); @@ -604,7 +637,7 @@ bool CProtocol::EvaluateReqJitBufMes() void CProtocol::CreateChanGainMes ( const int iChanID, const double dGain ) { CVector vecData ( 3 ); // 3 bytes of data - unsigned int iPos = 0; // init position pointer + unsigned int iPos = 0; // init position pointer // build data vector // channel ID @@ -612,6 +645,7 @@ void CProtocol::CreateChanGainMes ( const int iChanID, const double dGain ) // actual gain, we convert from double with range 0..1 to integer const int iCurGain = static_cast ( dGain * ( 1 << 15 ) ); + PutValOnStream ( vecData, iPos, static_cast ( iCurGain ), 2 ); CreateAndSendMessage ( PROTMESSID_CHANNEL_GAIN, vecData ); @@ -752,8 +786,8 @@ bool CProtocol::EvaluateReqConnClientsList() void CProtocol::CreateChanNameMes ( const QString strName ) { - unsigned int iPos = 0; // init position pointer - const int iStrLen = strName.size(); // get string size + unsigned int iPos = 0; // init position pointer + const int iStrLen = strName.size(); // get string size // size of current list entry const int iEntrLen = 2 /* string size */ + iStrLen; @@ -825,8 +859,8 @@ bool CProtocol::EvaluateReqChanNameMes() void CProtocol::CreateChatTextMes ( const QString strChatText ) { - unsigned int iPos = 0; // init position pointer - const int iStrLen = strChatText.size(); // get string size + unsigned int iPos = 0; // init position pointer + const int iStrLen = strChatText.size(); // get string size // size of message body const int iEntrLen = 2 /* string size */ + iStrLen; @@ -917,9 +951,14 @@ void CProtocol::CreateNetwTranspPropsMes ( const CNetworkTransportProps& NetTrPr unsigned int iPos = 0; // init position pointer // size of current message body - const int iEntrLen = 4 /* netw size */ + 2 /* block size fact */ + - 1 /* num chan */ + 4 /* sam rate */ + 2 /* audiocod type */ + - 2 /* version */ + 4 /* audiocod arg */; + const int iEntrLen = + 4 /* netw size */ + + 2 /* block size fact */ + + 1 /* num chan */ + + 4 /* sam rate */ + + 2 /* audiocod type */ + + 2 /* version */ + + 4 /* audiocod arg */; // build data vector CVector vecData ( iEntrLen ); @@ -961,9 +1000,14 @@ bool CProtocol::EvaluateNetwTranspPropsMes ( const CVector& vecData ) CNetworkTransportProps ReceivedNetwTranspProps; // size of current message body - const int iEntrLen = 4 /* netw size */ + 2 /* block size fact */ + - 1 /* num chan */ + 4 /* sam rate */ + 2 /* audiocod type */ + - 2 /* version */ + 4 /* audiocod arg */; + const int iEntrLen = + 4 /* netw size */ + + 2 /* block size fact */ + + 1 /* num chan */ + + 4 /* sam rate */ + + 2 /* audiocod type */ + + 2 /* version */ + + 4 /* audiocod arg */; // check size if ( vecData.Size() != iEntrLen ) @@ -1127,6 +1171,94 @@ bool CProtocol::EvaluateCLServerFullMes() return false; // no error } +void CProtocol::CreateCLRegisterServerMes ( const CHostAddress& InetAddr, + const CServerInfo& ServerInfo ) +{ + unsigned int iPos = 0; // init position pointer + + // current string sizes + const int iNameLen = ServerInfo.strName.size(); + const int iTopicLen = ServerInfo.strTopic.size(); + const int iCityLen = ServerInfo.strCity.size(); + + // size of current message body + const int iEntrLen = + 2 /* name string size */ + iNameLen + + 2 /* topic string size */ + iTopicLen + + 2 /* country */ + + 2 /* city string size */ + iCityLen + + 1 /* number of connected clients */ + + 1 /* maximum number of connected clients */ + + 1 /* is permanent flag */; + + // build data vector + CVector vecData ( iEntrLen ); + + // number of bytes for name string (2 bytes) + PutValOnStream ( vecData, iPos, + static_cast ( iNameLen ), 2 ); + + // name string (n bytes) + for ( int j = 0; j < iNameLen; j++ ) + { + // byte-by-byte copying of the string data + PutValOnStream ( vecData, iPos, + static_cast ( ServerInfo.strName[j].toAscii() ), 1 ); + } + + // number of bytes for topic string (2 bytes) + PutValOnStream ( vecData, iPos, + static_cast ( iTopicLen ), 2 ); + + // topic string (n bytes) + for ( int j = 0; j < iTopicLen; j++ ) + { + // byte-by-byte copying of the string data + PutValOnStream ( vecData, iPos, + static_cast ( ServerInfo.strTopic[j].toAscii() ), 1 ); + } + + // country (2 bytes) + PutValOnStream ( vecData, iPos, + static_cast ( ServerInfo.eCountry ), 2 ); + + // number of bytes for city string (2 bytes) + PutValOnStream ( vecData, iPos, + static_cast ( iCityLen ), 2 ); + + // city string (n bytes) + for ( int j = 0; j < iCityLen; j++ ) + { + // byte-by-byte copying of the string data + PutValOnStream ( vecData, iPos, + static_cast ( ServerInfo.strCity[j].toAscii() ), 1 ); + } + + // number of connected clients (1 byte) + PutValOnStream ( vecData, iPos, + static_cast ( ServerInfo.iNumClients ), 1 ); + + // 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 ); + + CreateAndImmSendConLessMessage ( PROTMESSID_CLM_REGISTER_SERVER, + vecData, + InetAddr ); +} + +bool CProtocol::EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr, + const CVector& vecData ) +{ + + // TODO + +} + /******************************************************************************\ * Message generation (parsing) * diff --git a/src/protocol.h b/src/protocol.h index 43f66cda..1e040b8e 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -97,6 +97,8 @@ public: void CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs ); void CreateCLServerFullMes ( const CHostAddress& InetAddr ); + void CreateCLRegisterServerMes ( const CHostAddress& InetAddr, + const CServerInfo& ServerInfo ); void CreateAndImmSendDisconnectionMes(); void CreateAndImmSendAcknMess ( const int& iID, const int& iCnt ); @@ -187,6 +189,8 @@ protected: bool EvaluateCLPingMes ( const CHostAddress& InetAddr, const CVector& vecData ); bool EvaluateCLServerFullMes(); + bool EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr, + const CVector& vecData ); int iOldRecID, iOldRecCnt; diff --git a/src/serverlist.h b/src/serverlist.h index 66c68a25..78f835dc 100755 --- a/src/serverlist.h +++ b/src/serverlist.h @@ -73,60 +73,40 @@ class CServerListProperties { public: CServerListProperties() : - strName ( "" ), - strTopic ( "" ), - eCountry ( QLocale::AnyCountry ), - strCity ( "" ), - iNumClients ( 0 ), - iMaxNumClients ( 0 ), - bPermanentOnline ( false ) { RegisterTime.start(); } + ServerInfo ( "", + "", + QLocale::AnyCountry, + "", + 0, + 0, + false ) { RegisterTime.start(); } - CServerListProperties ( - const CHostAddress& NIAddr, - const QString& NsName, - const QString& NsTopic, - const QLocale::Country& NeCountry, - const QString& NsCity, - const int NiNumClients, - const int NiMaxNumClients, - const bool NbPermOnline) : - InetAddr ( NIAddr ), - strName ( NsName ), - strTopic ( NsTopic ), - eCountry ( NeCountry ), - strCity ( NsCity ), - iNumClients ( NiNumClients ), - iMaxNumClients ( NiMaxNumClients ), - bPermanentOnline ( NbPermOnline ) { RegisterTime.start(); } + CServerListProperties ( const CHostAddress& NIAddr, + const QString& NsName, + const QString& NsTopic, + const QLocale::Country& NeCountry, + const QString& NsCity, + const int NiNumClients, + const int NiMaxNumClients, + const bool NbPermOnline) + : InetAddr ( NIAddr ), ServerInfo ( NsName, + NsTopic, + NeCountry, + NsCity, + NiNumClients, + NiMaxNumClients, + NbPermOnline ) + { RegisterTime.start(); } public: // time on which the entry was registered - QTime RegisterTime; + QTime RegisterTime; // internet address of the server - CHostAddress InetAddr; + CHostAddress InetAddr; - // name of the server - QString strName; - - // topic of the current jam session or server - QString strTopic; - - // country in which the server is located - QLocale::Country eCountry; - - // city in which the server is located - QString strCity; - - // current number of connected clients - int iNumClients; - - // maximum number of clients which can connect to the server at the same - // time - int iMaxNumClients; - - // is the server permanently online or not (flag) - bool bPermanentOnline; + // infos of the server + CServerInfo ServerInfo; }; diff --git a/src/util.h b/src/util.h index 36c1ab63..23bd498a 100755 --- a/src/util.h +++ b/src/util.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include "global.h" using namespace std; // because of the library: "vector" @@ -384,6 +385,8 @@ protected: double dCurLevelR; }; + +// Host address ---------------------------------------------------------------- class CHostAddress { public: @@ -394,7 +397,7 @@ public: CHostAddress ( const QHostAddress NInetAddr, const quint16 iNPort ) : InetAddr ( NInetAddr ), - iPort ( iNPort ) {} + iPort ( iNPort ) {} CHostAddress ( const CHostAddress& NHAddr ) : InetAddr ( NHAddr.InetAddr ), @@ -425,6 +428,8 @@ public: quint16 iPort; }; + +// Short info of a channel ----------------------------------------------------- class CChannelShortInfo { public: @@ -445,12 +450,70 @@ public: QString strName; }; + +// Server info ----------------------------------------------------------------- +class CServerInfo +{ +public: + CServerInfo() : + strName ( "" ), + strTopic ( "" ), + eCountry ( QLocale::AnyCountry ), + strCity ( "" ), + iNumClients ( 0 ), + iMaxNumClients ( 0 ), + bPermanentOnline ( false ) {} + + CServerInfo ( + const QString& NsName, + const QString& NsTopic, + const QLocale::Country& NeCountry, + const QString& NsCity, + const int NiNumClients, + const int NiMaxNumClients, + const bool NbPermOnline) : + strName ( NsName ), + strTopic ( NsTopic ), + eCountry ( NeCountry ), + strCity ( NsCity ), + iNumClients ( NiNumClients ), + iMaxNumClients ( NiMaxNumClients ), + bPermanentOnline ( NbPermOnline ) {} + +public: + // name of the server + QString strName; + + // topic of the current jam session or server + QString strTopic; + + // country in which the server is located + QLocale::Country eCountry; + + // city in which the server is located + QString strCity; + + // current number of connected clients + int iNumClients; + + // maximum number of clients which can connect to the server at the same + // time + int iMaxNumClients; + + // is the server permanently online or not (flag) + bool bPermanentOnline; +}; + + +// Audio compression type enum ------------------------------------------------- enum EAudComprType { CT_NONE = 0, CT_CELT = 1 }; + +// Get data status enum -------------------------------------------------------- enum EGetDataStat { GS_BUFFER_OK, @@ -459,12 +522,16 @@ enum EGetDataStat GS_CHAN_NOT_CONNECTED }; + +// GUI design enum ------------------------------------------------------------- enum EGUIDesign { GD_STANDARD = 0, GD_ORIGINAL = 1 }; + +// Network transport properties ------------------------------------------------ class CNetworkTransportProps { public: @@ -501,7 +568,7 @@ public: }; -// Audio Reverbration ---------------------------------------------------------- +// Audio reverbration ---------------------------------------------------------- class CAudioReverb { public: @@ -553,7 +620,7 @@ public: // Precise time ---------------------------------------------------------------- -// needed for ping measurement +// required for ping measurement class CPreciseTime { public: @@ -659,6 +726,7 @@ protected: int iNewValueBoundFactor; }; + // Error rate measurement ------------------------------------------------------ class CErrorRate {