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,
|
QObject::connect( &Protocol,
|
||||||
SIGNAL ( CLPingReceived ( CHostAddress, int ) ),
|
SIGNAL ( CLPingReceived ( CHostAddress, int ) ),
|
||||||
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 )
|
void CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs )
|
||||||
{ Protocol.CreateCLPingMes ( InetAddr, iMs ); }
|
{ Protocol.CreateCLPingMes ( InetAddr, iMs ); }
|
||||||
|
|
||||||
|
void CreateCLEmptyMes ( const CHostAddress& InetAddr )
|
||||||
|
{ Protocol.CreateCLEmptyMes ( InetAddr ); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// network protocol
|
// network protocol
|
||||||
CProtocol Protocol;
|
CProtocol Protocol;
|
||||||
|
@ -219,6 +222,10 @@ signals:
|
||||||
CVector<uint8_t> vecMessage );
|
CVector<uint8_t> vecMessage );
|
||||||
|
|
||||||
void CLPingReceived ( CHostAddress InetAddr, int iMs );
|
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
|
// without any other changes in the code
|
||||||
#define USED_NUM_CHANNELS 6 // used number channels for server
|
#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
|
// defines the time interval at which the ping time is updated in the GUI
|
||||||
#define PING_UPDATE_TIME_MS 500 // ms
|
#define PING_UPDATE_TIME_MS 500 // ms
|
||||||
|
|
|
@ -577,7 +577,7 @@ bool CProtocol::ParseConnectionLessMessage ( const CVector<uint8_t>& vecbyData,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROTMESSID_CLM_SEND_EMPTY_MESSAGE:
|
case PROTMESSID_CLM_SEND_EMPTY_MESSAGE:
|
||||||
bRet = EvaluateCLSendEmptyMesMes ( InetAddr, vecData );
|
bRet = EvaluateCLSendEmptyMesMes ( vecData );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROTMESSID_CLM_REGISTER_SERVER:
|
case PROTMESSID_CLM_REGISTER_SERVER:
|
||||||
|
@ -1459,8 +1459,7 @@ void CProtocol::CreateCLSendEmptyMesMes ( const CHostAddress& InetAddr,
|
||||||
InetAddr );
|
InetAddr );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CProtocol::EvaluateCLSendEmptyMesMes ( const CHostAddress& InetAddr,
|
bool CProtocol::EvaluateCLSendEmptyMesMes ( const CVector<uint8_t>& vecData )
|
||||||
const CVector<uint8_t>& vecData )
|
|
||||||
{
|
{
|
||||||
int iPos = 0; // init position pointer
|
int iPos = 0; // init position pointer
|
||||||
|
|
||||||
|
@ -1479,8 +1478,7 @@ bool CProtocol::EvaluateCLSendEmptyMesMes ( const CHostAddress& InetAddr,
|
||||||
static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
||||||
|
|
||||||
// invoke message action
|
// invoke message action
|
||||||
emit CLSendEmptyMes ( InetAddr,
|
emit CLSendEmptyMes ( CHostAddress ( QHostAddress ( iIpAddr ), iPort ) );
|
||||||
CHostAddress ( QHostAddress ( iIpAddr ), iPort ) );
|
|
||||||
|
|
||||||
return false; // no error
|
return false; // no error
|
||||||
}
|
}
|
||||||
|
|
|
@ -210,8 +210,7 @@ protected:
|
||||||
bool EvaluateCLServerListMes ( const CHostAddress& InetAddr,
|
bool EvaluateCLServerListMes ( const CHostAddress& InetAddr,
|
||||||
const CVector<uint8_t>& vecData );
|
const CVector<uint8_t>& vecData );
|
||||||
bool EvaluateCLReqServerListMes ( const CHostAddress& InetAddr );
|
bool EvaluateCLReqServerListMes ( const CHostAddress& InetAddr );
|
||||||
bool EvaluateCLSendEmptyMesMes ( const CHostAddress& InetAddr,
|
bool EvaluateCLSendEmptyMesMes ( const CVector<uint8_t>& vecData );
|
||||||
const CVector<uint8_t>& vecData );
|
|
||||||
|
|
||||||
int iOldRecID;
|
int iOldRecID;
|
||||||
int iOldRecCnt;
|
int iOldRecCnt;
|
||||||
|
@ -254,8 +253,7 @@ signals:
|
||||||
void CLServerListReceived ( CHostAddress InetAddr,
|
void CLServerListReceived ( CHostAddress InetAddr,
|
||||||
CVector<CServerInfo> vecServerInfo );
|
CVector<CServerInfo> vecServerInfo );
|
||||||
void CLReqServerList ( CHostAddress InetAddr );
|
void CLReqServerList ( CHostAddress InetAddr );
|
||||||
void CLSendEmptyMes ( CHostAddress InetAddr,
|
void CLSendEmptyMes ( CHostAddress TargetInetAddr );
|
||||||
CHostAddress TargetInetAddr );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* !defined ( PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_ ) */
|
#endif /* !defined ( PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_ ) */
|
||||||
|
|
|
@ -283,6 +283,15 @@ CServer::CServer ( const QString& strLoggingFileName,
|
||||||
SIGNAL ( CLPingReceived ( CHostAddress, int ) ),
|
SIGNAL ( CLPingReceived ( CHostAddress, int ) ),
|
||||||
this, SLOT ( OnCLPingReceived ( 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
|
// CODE TAG: MAX_NUM_CHANNELS_TAG
|
||||||
// make sure we have MAX_NUM_CHANNELS connections!!!
|
// make sure we have MAX_NUM_CHANNELS connections!!!
|
||||||
// send message
|
// send message
|
||||||
|
|
11
src/server.h
11
src/server.h
|
@ -188,9 +188,20 @@ public slots:
|
||||||
void OnTimer();
|
void OnTimer();
|
||||||
void OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage );
|
void OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage );
|
||||||
void OnSendCLProtMessage ( CHostAddress InetAddr, CVector<uint8_t> vecMessage );
|
void OnSendCLProtMessage ( CHostAddress InetAddr, CVector<uint8_t> vecMessage );
|
||||||
|
|
||||||
void OnCLPingReceived ( CHostAddress InetAddr, int iMs )
|
void OnCLPingReceived ( CHostAddress InetAddr, int iMs )
|
||||||
{ ConnLessChannel.CreateCLPingMes ( InetAddr, 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
|
// CODE TAG: MAX_NUM_CHANNELS_TAG
|
||||||
// make sure we have MAX_NUM_CHANNELS connections!!!
|
// make sure we have MAX_NUM_CHANNELS connections!!!
|
||||||
// send message
|
// send message
|
||||||
|
|
|
@ -86,43 +86,65 @@ void CServerListManager::RegisterServer ( const CHostAddress& InetAddr,
|
||||||
|
|
||||||
if ( bEnabled )
|
if ( bEnabled )
|
||||||
{
|
{
|
||||||
// define invalid index used as a flag
|
const int iCurServerListSize = ServerList.size();
|
||||||
const int ciInvalidIdx = -1;
|
|
||||||
|
|
||||||
// Check if server is already registered. Use IP number and port number
|
// check for maximum allowed number of servers in the server list
|
||||||
// to fully identify a server. The very first list entry must not be
|
if ( iCurServerListSize < MAX_NUM_SERVERS_IN_SERVER_LIST )
|
||||||
// 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++ )
|
|
||||||
{
|
{
|
||||||
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
|
if ( ServerList[iIdx].HostAddr == InetAddr )
|
||||||
iSelIdx = iIdx;
|
{
|
||||||
|
// store entry index
|
||||||
|
iSelIdx = iIdx;
|
||||||
|
|
||||||
// entry found, leave for-loop
|
// entry found, leave for-loop
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// if server is not yet registered, we have to create a new entry
|
// if server is not yet registered, we have to create a new entry
|
||||||
if ( iSelIdx == ciInvalidIdx )
|
if ( iSelIdx == ciInvalidIdx )
|
||||||
{
|
{
|
||||||
// create a new server list entry and init with received data
|
// create a new server list entry and init with received data
|
||||||
ServerList.append ( CServerListEntry ( InetAddr, ServerInfo ) );
|
ServerList.append ( CServerListEntry ( InetAddr, ServerInfo ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// update all data and call update registration function
|
// update all data and call update registration function
|
||||||
ServerList[iSelIdx].strName = ServerInfo.strName;
|
ServerList[iSelIdx].strName = ServerInfo.strName;
|
||||||
ServerList[iSelIdx].strTopic = ServerInfo.strTopic;
|
ServerList[iSelIdx].strTopic = ServerInfo.strTopic;
|
||||||
ServerList[iSelIdx].eCountry = ServerInfo.eCountry;
|
ServerList[iSelIdx].eCountry = ServerInfo.eCountry;
|
||||||
ServerList[iSelIdx].strCity = ServerInfo.strCity;
|
ServerList[iSelIdx].strCity = ServerInfo.strCity;
|
||||||
ServerList[iSelIdx].iNumClients = ServerInfo.iNumClients;
|
ServerList[iSelIdx].iNumClients = ServerInfo.iNumClients;
|
||||||
ServerList[iSelIdx].iMaxNumClients = ServerInfo.iMaxNumClients;
|
ServerList[iSelIdx].iMaxNumClients = ServerInfo.iMaxNumClients;
|
||||||
ServerList[iSelIdx].bPermanentOnline = ServerInfo.bPermanentOnline;
|
ServerList[iSelIdx].bPermanentOnline = ServerInfo.bPermanentOnline;
|
||||||
ServerList[iSelIdx].UpdateRegistration();
|
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,
|
void RegisterServer ( const CHostAddress& InetAddr,
|
||||||
const CServerCoreInfo& ServerInfo );
|
const CServerCoreInfo& ServerInfo );
|
||||||
|
|
||||||
|
void QueryServerList ( const CHostAddress& InetAddr );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QTimer TimerPollList;
|
QTimer TimerPollList;
|
||||||
QMutex Mutex;
|
QMutex Mutex;
|
||||||
|
|
Loading…
Add table
Reference in a new issue