From ab4775f6a0a3be7814565a8f6b5a18c9f4027900 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Tue, 5 Apr 2011 20:09:16 +0000 Subject: [PATCH] support for some more connection less channel messages for the central server --- src/channel.cpp | 8 +++++ src/channel.h | 7 ++++ src/global.h | 2 ++ src/protocol.cpp | 8 ++--- src/protocol.h | 6 ++-- src/server.cpp | 9 +++++ src/server.h | 11 ++++++ src/serverlist.cpp | 84 +++++++++++++++++++++++++++++----------------- src/serverlist.h | 3 ++ 9 files changed, 98 insertions(+), 40 deletions(-) diff --git a/src/channel.cpp b/src/channel.cpp index cc36a73d..7a422bf8 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -561,4 +561,12 @@ CConnectionLessChannel::CConnectionLessChannel() QObject::connect( &Protocol, SIGNAL ( CLPingReceived ( CHostAddress, int ) ), SIGNAL ( CLPingReceived ( CHostAddress, int ) ) ); + + QObject::connect( &Protocol, + SIGNAL ( CLRegisterServerReceived ( CHostAddress, CServerCoreInfo ) ), + SIGNAL ( CLRegisterServerReceived ( CHostAddress, CServerCoreInfo ) ) ); + + QObject::connect( &Protocol, + SIGNAL ( CLSendEmptyMes ( CHostAddress, CHostAddress ) ), + SIGNAL ( CLSendEmptyMes ( CHostAddress, CHostAddress ) ) ); } diff --git a/src/channel.h b/src/channel.h index 112d6f7e..3a69861e 100755 --- a/src/channel.h +++ b/src/channel.h @@ -210,6 +210,9 @@ public: void CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs ) { Protocol.CreateCLPingMes ( InetAddr, iMs ); } + void CreateCLEmptyMes ( const CHostAddress& InetAddr ) + { Protocol.CreateCLEmptyMes ( InetAddr ); } + protected: // network protocol CProtocol Protocol; @@ -219,6 +222,10 @@ signals: CVector vecMessage ); void CLPingReceived ( CHostAddress InetAddr, int iMs ); + void CLRegisterServerReceived ( CHostAddress InetAddr, + CServerCoreInfo ServerInfo ); + void CLSendEmptyMes ( CHostAddress InetAddr, + CHostAddress TargetInetAddr ); }; diff --git a/src/global.h b/src/global.h index 23e622db..85b3958a 100755 --- a/src/global.h +++ b/src/global.h @@ -128,6 +128,8 @@ // without any other changes in the code #define USED_NUM_CHANNELS 6 // used number channels for server +// maximum number of servers registered in the server list +#define MAX_NUM_SERVERS_IN_SERVER_LIST 100 // defines the time interval at which the ping time is updated in the GUI #define PING_UPDATE_TIME_MS 500 // ms diff --git a/src/protocol.cpp b/src/protocol.cpp index d7d14705..bef7a75d 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -577,7 +577,7 @@ bool CProtocol::ParseConnectionLessMessage ( const CVector& vecbyData, break; case PROTMESSID_CLM_SEND_EMPTY_MESSAGE: - bRet = EvaluateCLSendEmptyMesMes ( InetAddr, vecData ); + bRet = EvaluateCLSendEmptyMesMes ( vecData ); break; case PROTMESSID_CLM_REGISTER_SERVER: @@ -1459,8 +1459,7 @@ void CProtocol::CreateCLSendEmptyMesMes ( const CHostAddress& InetAddr, InetAddr ); } -bool CProtocol::EvaluateCLSendEmptyMesMes ( const CHostAddress& InetAddr, - const CVector& vecData ) +bool CProtocol::EvaluateCLSendEmptyMesMes ( const CVector& vecData ) { int iPos = 0; // init position pointer @@ -1479,8 +1478,7 @@ bool CProtocol::EvaluateCLSendEmptyMesMes ( const CHostAddress& InetAddr, static_cast ( GetValFromStream ( vecData, iPos, 2 ) ); // invoke message action - emit CLSendEmptyMes ( InetAddr, - CHostAddress ( QHostAddress ( iIpAddr ), iPort ) ); + emit CLSendEmptyMes ( CHostAddress ( QHostAddress ( iIpAddr ), iPort ) ); return false; // no error } diff --git a/src/protocol.h b/src/protocol.h index 56d8af09..571980c5 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -210,8 +210,7 @@ protected: bool EvaluateCLServerListMes ( const CHostAddress& InetAddr, const CVector& vecData ); bool EvaluateCLReqServerListMes ( const CHostAddress& InetAddr ); - bool EvaluateCLSendEmptyMesMes ( const CHostAddress& InetAddr, - const CVector& vecData ); + bool EvaluateCLSendEmptyMesMes ( const CVector& vecData ); int iOldRecID; int iOldRecCnt; @@ -254,8 +253,7 @@ signals: void CLServerListReceived ( CHostAddress InetAddr, CVector vecServerInfo ); void CLReqServerList ( CHostAddress InetAddr ); - void CLSendEmptyMes ( CHostAddress InetAddr, - CHostAddress TargetInetAddr ); + void CLSendEmptyMes ( CHostAddress TargetInetAddr ); }; #endif /* !defined ( PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_ ) */ diff --git a/src/server.cpp b/src/server.cpp index f52c3adc..5f505669 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -283,6 +283,15 @@ CServer::CServer ( const QString& strLoggingFileName, SIGNAL ( CLPingReceived ( CHostAddress, int ) ), this, SLOT ( OnCLPingReceived ( CHostAddress, int ) ) ); + QObject::connect ( &ConnLessChannel, + SIGNAL ( CLRegisterServerReceived ( CHostAddress, CServerCoreInfo ) ), + this, SLOT ( OnCLRegisterServerReceived ( CHostAddress, CServerCoreInfo ) ) ); + + QObject::connect ( &ConnLessChannel, + SIGNAL ( CLSendEmptyMes ( CHostAddress ) ), + this, SLOT ( OnCLSendEmptyMes ( CHostAddress ) ) ); + + // CODE TAG: MAX_NUM_CHANNELS_TAG // make sure we have MAX_NUM_CHANNELS connections!!! // send message diff --git a/src/server.h b/src/server.h index 46bbc12e..707e9364 100755 --- a/src/server.h +++ b/src/server.h @@ -188,9 +188,20 @@ public slots: void OnTimer(); void OnSendProtMessage ( int iChID, CVector vecMessage ); void OnSendCLProtMessage ( CHostAddress InetAddr, CVector vecMessage ); + void OnCLPingReceived ( CHostAddress InetAddr, int iMs ) { ConnLessChannel.CreateCLPingMes ( InetAddr, iMs ); } + void OnCLSendEmptyMes ( CHostAddress TargetInetAddr ) + { ConnLessChannel.CreateCLEmptyMes ( TargetInetAddr ); } + + void OnCLRegisterServerReceived ( CHostAddress InetAddr, + CServerCoreInfo ServerInfo ) + { + ServerListManager.RegisterServer ( InetAddr, ServerInfo ); + } + + // CODE TAG: MAX_NUM_CHANNELS_TAG // make sure we have MAX_NUM_CHANNELS connections!!! // send message diff --git a/src/serverlist.cpp b/src/serverlist.cpp index 644e8ab2..a457e606 100755 --- a/src/serverlist.cpp +++ b/src/serverlist.cpp @@ -86,43 +86,65 @@ void CServerListManager::RegisterServer ( const CHostAddress& InetAddr, if ( bEnabled ) { - // define invalid index used as a flag - const int ciInvalidIdx = -1; + const int iCurServerListSize = ServerList.size(); - // Check if server is already registered. Use IP number and port number - // to fully identify a server. The very first list entry must not be - // checked since this is per definition the central server (i.e., this - // server) - int iSelIdx = ciInvalidIdx; // initialize with an illegal value - for ( int iIdx = 1; iIdx < ServerList.size(); iIdx++ ) + // check for maximum allowed number of servers in the server list + if ( iCurServerListSize < MAX_NUM_SERVERS_IN_SERVER_LIST ) { - if ( ServerList[iIdx].HostAddr == InetAddr ) + // define invalid index used as a flag + const int ciInvalidIdx = -1; + + // Check if server is already registered. Use IP number and port + // number to fully identify a server. The very first list entry must + // not be checked since this is per definition the central server + // (i.e., this server) + int iSelIdx = ciInvalidIdx; // initialize with an illegal value + for ( int iIdx = 1; iIdx < iCurServerListSize; iIdx++ ) { - // store entry index - iSelIdx = iIdx; + if ( ServerList[iIdx].HostAddr == InetAddr ) + { + // store entry index + iSelIdx = iIdx; - // entry found, leave for-loop - continue; + // entry found, leave for-loop + continue; + } } - } - // if server is not yet registered, we have to create a new entry - if ( iSelIdx == ciInvalidIdx ) - { - // create a new server list entry and init with received data - ServerList.append ( CServerListEntry ( InetAddr, ServerInfo ) ); - } - else - { - // update all data and call update registration function - ServerList[iSelIdx].strName = ServerInfo.strName; - ServerList[iSelIdx].strTopic = ServerInfo.strTopic; - ServerList[iSelIdx].eCountry = ServerInfo.eCountry; - ServerList[iSelIdx].strCity = ServerInfo.strCity; - ServerList[iSelIdx].iNumClients = ServerInfo.iNumClients; - ServerList[iSelIdx].iMaxNumClients = ServerInfo.iMaxNumClients; - ServerList[iSelIdx].bPermanentOnline = ServerInfo.bPermanentOnline; - ServerList[iSelIdx].UpdateRegistration(); + // if server is not yet registered, we have to create a new entry + if ( iSelIdx == ciInvalidIdx ) + { + // create a new server list entry and init with received data + ServerList.append ( CServerListEntry ( InetAddr, ServerInfo ) ); + } + else + { + // update all data and call update registration function + ServerList[iSelIdx].strName = ServerInfo.strName; + ServerList[iSelIdx].strTopic = ServerInfo.strTopic; + ServerList[iSelIdx].eCountry = ServerInfo.eCountry; + ServerList[iSelIdx].strCity = ServerInfo.strCity; + ServerList[iSelIdx].iNumClients = ServerInfo.iNumClients; + ServerList[iSelIdx].iMaxNumClients = ServerInfo.iMaxNumClients; + ServerList[iSelIdx].bPermanentOnline = ServerInfo.bPermanentOnline; + ServerList[iSelIdx].UpdateRegistration(); + } } } } + +void CServerListManager::QueryServerList ( const CHostAddress& InetAddr ) +{ + QMutexLocker locker ( &Mutex ); + + if ( bEnabled ) + { + +// TODO + +// extract the list data in message or transmit directly? + +// create "send empty message" for all registered servers + + } +} diff --git a/src/serverlist.h b/src/serverlist.h index 2e92afed..5bd82baa 100755 --- a/src/serverlist.h +++ b/src/serverlist.h @@ -128,6 +128,9 @@ public: void RegisterServer ( const CHostAddress& InetAddr, const CServerCoreInfo& ServerInfo ); + + void QueryServerList ( const CHostAddress& InetAddr ); + protected: QTimer TimerPollList; QMutex Mutex;