support for some more connection less channel messages for the central server
This commit is contained in:
parent
36d13454b3
commit
ab4775f6a0
9 changed files with 98 additions and 40 deletions
|
@ -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 ) ) );
|
||||
}
|
||||
|
|
|
@ -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<uint8_t> vecMessage );
|
||||
|
||||
void CLPingReceived ( CHostAddress InetAddr, int iMs );
|
||||
void CLRegisterServerReceived ( CHostAddress InetAddr,
|
||||
CServerCoreInfo ServerInfo );
|
||||
void CLSendEmptyMes ( CHostAddress InetAddr,
|
||||
CHostAddress TargetInetAddr );
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -577,7 +577,7 @@ bool CProtocol::ParseConnectionLessMessage ( const CVector<uint8_t>& 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<uint8_t>& vecData )
|
||||
bool CProtocol::EvaluateCLSendEmptyMesMes ( const CVector<uint8_t>& vecData )
|
||||
{
|
||||
int iPos = 0; // init position pointer
|
||||
|
||||
|
@ -1479,8 +1478,7 @@ bool CProtocol::EvaluateCLSendEmptyMesMes ( const CHostAddress& InetAddr,
|
|||
static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
||||
|
||||
// invoke message action
|
||||
emit CLSendEmptyMes ( InetAddr,
|
||||
CHostAddress ( QHostAddress ( iIpAddr ), iPort ) );
|
||||
emit CLSendEmptyMes ( CHostAddress ( QHostAddress ( iIpAddr ), iPort ) );
|
||||
|
||||
return false; // no error
|
||||
}
|
||||
|
|
|
@ -210,8 +210,7 @@ protected:
|
|||
bool EvaluateCLServerListMes ( const CHostAddress& InetAddr,
|
||||
const CVector<uint8_t>& vecData );
|
||||
bool EvaluateCLReqServerListMes ( const CHostAddress& InetAddr );
|
||||
bool EvaluateCLSendEmptyMesMes ( const CHostAddress& InetAddr,
|
||||
const CVector<uint8_t>& vecData );
|
||||
bool EvaluateCLSendEmptyMesMes ( const CVector<uint8_t>& vecData );
|
||||
|
||||
int iOldRecID;
|
||||
int iOldRecCnt;
|
||||
|
@ -254,8 +253,7 @@ signals:
|
|||
void CLServerListReceived ( CHostAddress InetAddr,
|
||||
CVector<CServerInfo> vecServerInfo );
|
||||
void CLReqServerList ( CHostAddress InetAddr );
|
||||
void CLSendEmptyMes ( CHostAddress InetAddr,
|
||||
CHostAddress TargetInetAddr );
|
||||
void CLSendEmptyMes ( CHostAddress TargetInetAddr );
|
||||
};
|
||||
|
||||
#endif /* !defined ( PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_ ) */
|
||||
|
|
|
@ -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
|
||||
|
|
11
src/server.h
11
src/server.h
|
@ -188,9 +188,20 @@ public slots:
|
|||
void OnTimer();
|
||||
void OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage );
|
||||
void OnSendCLProtMessage ( CHostAddress InetAddr, CVector<uint8_t> 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
|
||||
|
|
|
@ -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
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,6 +128,9 @@ public:
|
|||
|
||||
void RegisterServer ( const CHostAddress& InetAddr,
|
||||
const CServerCoreInfo& ServerInfo );
|
||||
|
||||
void QueryServerList ( const CHostAddress& InetAddr );
|
||||
|
||||
protected:
|
||||
QTimer TimerPollList;
|
||||
QMutex Mutex;
|
||||
|
|
Loading…
Reference in a new issue