the number of connected clients are now not managed with the server list but by the connection less ping time message

This commit is contained in:
Volker Fischer 2011-04-25 10:51:57 +00:00
parent c4e0e6e000
commit 23d79c5f85
13 changed files with 2878 additions and 2799 deletions

View File

@ -114,8 +114,9 @@ CClient::CClient ( const quint16 iPortNumber ) :
SIGNAL ( CLServerListReceived ( CHostAddress, CVector<CServerInfo> ) ),
SIGNAL ( CLServerListReceived ( CHostAddress, CVector<CServerInfo> ) ) );
QObject::connect ( &ConnLessProtocol, SIGNAL ( CLPingReceived ( CHostAddress, int ) ),
this, SLOT ( OnCLPingReceived ( CHostAddress, int ) ) );
QObject::connect ( &ConnLessProtocol,
SIGNAL ( CLPingWithNumClientsReceived ( CHostAddress, int, int ) ),
this, SLOT ( OnCLPingWithNumClientsReceived ( CHostAddress, int, int ) ) );
QObject::connect ( &Sound, SIGNAL ( ReinitRequest() ),
this, SLOT ( OnSndCrdReinitRequest() ) );
@ -162,13 +163,17 @@ void CClient::OnReceivePingMessage ( int iMs )
}
}
void CClient::OnCLPingReceived ( CHostAddress InetAddr, int iMs )
void CClient::OnCLPingWithNumClientsReceived ( CHostAddress InetAddr,
int iMs,
int iNumClients )
{
// take care of wrap arounds (if wrapping, do not use result)
const int iCurDiff = EvaluatePingMessage ( iMs );
if ( iCurDiff >= 0 )
{
emit CLPingTimeReceived ( InetAddr, iCurDiff );
emit CLPingTimeWithNumClientsReceived ( InetAddr,
iCurDiff,
iNumClients );
}
}

View File

@ -307,7 +307,9 @@ public slots:
void OnReceivePingMessage ( int iMs );
void OnSendCLProtMessage ( CHostAddress InetAddr, CVector<uint8_t> vecMessage );
void OnCLPingReceived ( CHostAddress InetAddr, int iMs );
void OnCLPingWithNumClientsReceived ( CHostAddress InetAddr,
int iMs,
int iNumClients );
void OnSndCrdReinitRequest();
@ -317,7 +319,9 @@ signals:
void PingTimeReceived ( int iPingTime );
void CLServerListReceived ( CHostAddress InetAddr,
CVector<CServerInfo> vecServerInfo );
void CLPingTimeReceived ( CHostAddress InetAddr, int iPingTime );
void CLPingTimeWithNumClientsReceived ( CHostAddress InetAddr,
int iPingTime,
int iNumClients );
void Disconnected();
void Stopped();
};

View File

@ -234,13 +234,16 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr,
CurPingTimeFont.setBold ( true );
pNewListViewItem->setFont ( 1, CurPingTimeFont );
// number of clients
pNewListViewItem->setText ( 2,
QString().setNum ( vecServerInfo[iIdx].iNumClients ) );
// server location (city and country)
QString strLocation = vecServerInfo[iIdx].strCity;
if ( !strLocation.isEmpty() )
{
strLocation += ", ";
}
strLocation +=
QLocale::countryToString ( vecServerInfo[iIdx].eCountry );
// server country
pNewListViewItem->setText ( 3,
QLocale::countryToString ( vecServerInfo[iIdx].eCountry ) );
pNewListViewItem->setText ( 3, strLocation );
// store host address
pNewListViewItem->setData ( 0, Qt::UserRole,
@ -294,9 +297,10 @@ void CConnectDlg::OnTimerPing()
}
}
void CConnectDlg::SetPingTimeResult ( CHostAddress& InetAddr,
const int iPingTime,
const int iPingTimeLEDColor )
void CConnectDlg::SetPingTimeAndNumClientsResult ( CHostAddress& InetAddr,
const int iPingTime,
const int iPingTimeLEDColor,
const int iNumClients )
{
// apply the received ping time to the correct server list entry
const int iServerListLen = ListViewServers->topLevelItemCount();
@ -332,6 +336,10 @@ void CConnectDlg::SetPingTimeResult ( CHostAddress& InetAddr,
ListViewServers->topLevelItem ( iIdx )->
setText ( 1, QString().setNum ( iPingTime ) + " ms" );
// update number of clients text
ListViewServers->topLevelItem ( iIdx )->
setText ( 2, QString().setNum ( iNumClients ) );
// a ping time was received, set item to visible
ListViewServers->topLevelItem ( iIdx )->setHidden ( false );
}

View File

@ -61,9 +61,10 @@ public:
void LoadStoredServers ( const CVector<QString>& vstrNewIPAddresses );
void SetPingTimeResult ( CHostAddress& InetAddr,
const int iPingTime,
const int iPingTimeLEDColor );
void SetPingTimeAndNumClientsResult ( CHostAddress& InetAddr,
const int iPingTime,
const int iPingTimeLEDColor,
const int iNumClients );
bool GetStateOK() const { return bStateOK; }
bool GetServerListItemWasChosen() const { return bServerListItemWasChosen; }

View File

@ -389,8 +389,9 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP,
SIGNAL ( CLServerListReceived ( CHostAddress, CVector<CServerInfo> ) ),
this, SLOT ( OnCLServerListReceived ( CHostAddress, CVector<CServerInfo> ) ) );
QObject::connect ( pClient, SIGNAL ( CLPingTimeReceived ( CHostAddress, int ) ),
this, SLOT ( OnCLPingTimeResult ( CHostAddress, int ) ) );
QObject::connect ( pClient,
SIGNAL ( CLPingTimeWithNumClientsReceived ( CHostAddress, int, int ) ),
this, SLOT ( OnCLPingTimeWithNumClientsReceived ( CHostAddress, int, int ) ) );
QObject::connect ( &ClientSettingsDlg, SIGNAL ( GUIDesignChanged() ),
this, SLOT ( OnGUIDesignChanged() ) );
@ -698,8 +699,9 @@ void CLlconClientDlg::OnPingTimeResult ( int iPingTime )
LEDDelay->SetLight ( iOverallDelayLEDColor );
}
void CLlconClientDlg::OnCLPingTimeResult ( CHostAddress InetAddr,
int iPingTime )
void CLlconClientDlg::OnCLPingTimeWithNumClientsReceived ( CHostAddress InetAddr,
int iPingTime,
int iNumClients )
{
// color definition: <= 25 ms green, <= 50 ms yellow, otherwise red
int iPingTimeLEDColor;
@ -720,9 +722,10 @@ void CLlconClientDlg::OnCLPingTimeResult ( CHostAddress InetAddr,
}
// update connection dialog server list
ConnectDlg.SetPingTimeResult ( InetAddr,
iPingTime,
iPingTimeLEDColor );
ConnectDlg.SetPingTimeAndNumClientsResult ( InetAddr,
iPingTime,
iPingTimeLEDColor,
iNumClients );
}
void CLlconClientDlg::ConnectDisconnect ( const bool bDoStart )

View File

@ -115,7 +115,9 @@ public slots:
void OnTimerPing();
void OnPingTimeResult ( int iPingTime );
void OnCLPingTimeResult ( CHostAddress InetAddr, int iPingTime );
void OnCLPingTimeWithNumClientsReceived ( CHostAddress InetAddr,
int iPingTime,
int iNumClients );
void OnOpenGeneralSettings();
void OnOpenChatDialog()

View File

@ -155,6 +155,17 @@ CONNECTION LESS MESSAGES
note: same definition as PROTMESSID_PING_MS
- PROTMESSID_CLM_PING_MS_WITHNUMCLIENTS: Connection less ping message (for
measuring the ping time) with the
info about the current number of
connected clients
+-----------------------------+---------------------------------+
| 4 bytes transmit time in ms | 1 byte number connected clients |
+-----------------------------+---------------------------------+
- PROTMESSID_SERVER_FULL: Connection less server full message
note: does not have any data -> n = 0
@ -163,30 +174,29 @@ CONNECTION LESS MESSAGES
- PROTMESSID_CLM_REGISTER_SERVER: Register a server, providing server
information
+-----------------+---------------------------------+ ...
| 2 bytes country | 1 byte number connected clients | ...
+-----------------+---------------------------------+ ...
... ---------------------------------+---------------------+ ...
... 1 byte maximum connected clients | 1 byte is permanent | ...
... ---------------------------------+---------------------+ ...
... -----------------+----------------------------------+ ...
... 2 bytes number n | n bytes UTF-8 string server name | ...
... -----------------+----------------------------------+ ...
... -----------------+----------------------------+ ...
... 2 bytes number n | n bytes UTF-8 string topic | ...
... -----------------+----------------------------+ ...
... -----------------+---------------------------+
... 2 bytes number n | n bytes UTF-8 string city |
... -----------------+---------------------------+
+-----------------+----------------------------------+ ...
| 2 bytes country | 1 byte maximum connected clients | ...
+-----------------+----------------------------------+ ...
... ---------------------+------------------+ ...
... 1 byte is permanent | 2 bytes number n | ...
... ---------------------+------------------+ ...
... ----------------------------------+ ...
... n bytes UTF-8 string server name | ...
... ----------------------------------+ ...
... ------------------+----------------------------+ ...
... 2 bytes number n | n bytes UTF-8 string topic | ...
... ------------------+----------------------------+ ...
... ------------------+---------------------------+
... 2 bytes number n | n bytes UTF-8 string city |
... ------------------+---------------------------+
- "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.
- "country" is according to "Common Locale Data Repository" which is used in
the QLocale class
- PROTMESSID_CLM_SERVER_LIST: Server list message
@ -564,6 +574,10 @@ bool CProtocol::ParseConnectionLessMessage ( const CVector<uint8_t>& vecbyData,
bRet = EvaluateCLPingMes ( InetAddr, vecData );
break;
case PROTMESSID_CLM_PING_MS_WITHNUMCLIENTS:
bRet = EvaluateCLPingWithNumClientsMes ( InetAddr, vecData );
break;
case PROTMESSID_CLM_SERVER_FULL:
bRet = EvaluateCLServerFullMes();
break;
@ -1133,6 +1147,51 @@ bool CProtocol::EvaluateCLPingMes ( const CHostAddress& InetAddr,
return false; // no error
}
void CProtocol::CreateCLPingWithNumClientsMes ( const CHostAddress& InetAddr,
const int iMs,
const int iNumClients )
{
int iPos = 0; // init position pointer
// build data vector (5 bytes long)
CVector<uint8_t> vecData ( 5 );
// transmit time (4 bytes)
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iMs ), 4 );
// current number of connected clients (1 byte)
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iNumClients ), 1 );
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_PING_MS_WITHNUMCLIENTS,
vecData,
InetAddr );
}
bool CProtocol::EvaluateCLPingWithNumClientsMes ( const CHostAddress& InetAddr,
const CVector<uint8_t>& vecData )
{
int iPos = 0; // init position pointer
// check size
if ( vecData.Size() != 5 )
{
return true; // return error code
}
// transmit time
const int iCurMs =
static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
// current number of connected clients
const int iCurNumClients =
static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
// invoke message action
emit CLPingWithNumClientsReceived ( InetAddr, iCurMs, iCurNumClients );
return false; // no error
}
void CProtocol::CreateCLServerFullMes ( const CHostAddress& InetAddr )
{
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_SERVER_FULL,
@ -1156,7 +1215,6 @@ void CProtocol::CreateCLRegisterServerMes ( const CHostAddress& InetAddr,
// size of current message body
const int iEntrLen =
2 /* country */ +
1 /* number of connected clients */ +
1 /* maximum number of connected clients */ +
1 /* is permanent flag */ +
2 /* name string size */ + ServerInfo.strName.size() +
@ -1170,10 +1228,6 @@ void CProtocol::CreateCLRegisterServerMes ( const CHostAddress& InetAddr,
PutValOnStream ( vecData, iPos,
static_cast<uint32_t> ( ServerInfo.eCountry ), 2 );
// number of connected clients (1 byte)
PutValOnStream ( vecData, iPos,
static_cast<uint32_t> ( ServerInfo.iNumClients ), 1 );
// maximum number of connected clients (1 byte)
PutValOnStream ( vecData, iPos,
static_cast<uint32_t> ( ServerInfo.iMaxNumClients ), 1 );
@ -1203,8 +1257,8 @@ bool CProtocol::EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr,
const int iDataLen = vecData.Size();
CServerCoreInfo RecServerInfo;
// check size (the first 5 bytes)
if ( iDataLen < 5 )
// check size (the first 4 bytes)
if ( iDataLen < 4 )
{
return true; // return error code
}
@ -1213,10 +1267,6 @@ bool CProtocol::EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr,
RecServerInfo.eCountry =
static_cast<QLocale::Country> ( GetValFromStream ( vecData, iPos, 2 ) );
// number of connected clients (1 byte)
RecServerInfo.iNumClients =
static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
// maximum number of connected clients (1 byte)
RecServerInfo.iMaxNumClients =
static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
@ -1281,7 +1331,6 @@ void CProtocol::CreateCLServerListMes ( const CHostAddress& InetAddr,
4 /* IP address */ +
2 /* port number */ +
2 /* country */ +
1 /* number of connected clients */ +
1 /* maximum number of connected clients */ +
1 /* is permanent flag */ +
2 /* name string size */ + vecServerInfo[i].strName.size() +
@ -1303,10 +1352,6 @@ void CProtocol::CreateCLServerListMes ( const CHostAddress& InetAddr,
PutValOnStream ( vecData, iPos,
static_cast<uint32_t> ( vecServerInfo[i].eCountry ), 2 );
// number of connected clients (1 byte)
PutValOnStream ( vecData, iPos,
static_cast<uint32_t> ( vecServerInfo[i].iNumClients ), 1 );
// maximum number of connected clients (1 byte)
PutValOnStream ( vecData, iPos,
static_cast<uint32_t> ( vecServerInfo[i].iMaxNumClients ), 1 );
@ -1339,8 +1384,8 @@ bool CProtocol::EvaluateCLServerListMes ( const CHostAddress& InetAddr,
while ( iPos < iDataLen )
{
// check size (the next 11 bytes)
if ( ( iDataLen - iPos ) < 11 )
// check size (the next 10 bytes)
if ( ( iDataLen - iPos ) < 10 )
{
return true; // return error code
}
@ -1357,10 +1402,6 @@ bool CProtocol::EvaluateCLServerListMes ( const CHostAddress& InetAddr,
const QLocale::Country eCountry =
static_cast<QLocale::Country> ( GetValFromStream ( vecData, iPos, 2 ) );
// number of connected clients (1 byte)
const int iNumClients =
static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
// maximum number of connected clients (1 byte)
const int iMaxNumClients =
static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
@ -1406,7 +1447,6 @@ bool CProtocol::EvaluateCLServerListMes ( const CHostAddress& InetAddr,
strTopic,
eCountry,
strCity,
iNumClients,
iMaxNumClients,
bPermanentOnline ) );
}

View File

@ -56,13 +56,14 @@
// message IDs of connection less messages (CLM)
// DEFINITION -> start at 1000, end at 1999, see IsConnectionLessMessageID
#define PROTMESSID_CLM_PING_MS 1001 // for measuring ping time
#define PROTMESSID_CLM_SERVER_FULL 1002 // server full message
#define PROTMESSID_CLM_REGISTER_SERVER 1003 // register server
#define PROTMESSID_CLM_UNREGISTER_SERVER 1004 // unregister server -> TODO
#define PROTMESSID_CLM_SERVER_LIST 1005 // server list
#define PROTMESSID_CLM_REQ_SERVER_LIST 1006 // request server list
#define PROTMESSID_CLM_SEND_EMPTY_MESSAGE 1007 // an empty message shall be send
#define PROTMESSID_CLM_EMPTY_MESSAGE 1008 // empty message
#define PROTMESSID_CLM_PING_MS_WITHNUMCLIENTS 1002 // for ping time and num. of clients info
#define PROTMESSID_CLM_SERVER_FULL 1003 // server full message
#define PROTMESSID_CLM_REGISTER_SERVER 1004 // register server
#define PROTMESSID_CLM_UNREGISTER_SERVER 1005 // unregister server -> TODO
#define PROTMESSID_CLM_SERVER_LIST 1006 // server list
#define PROTMESSID_CLM_REQ_SERVER_LIST 1007 // request server list
#define PROTMESSID_CLM_SEND_EMPTY_MESSAGE 1008 // an empty message shall be send
#define PROTMESSID_CLM_EMPTY_MESSAGE 1009 // empty message
// lengths of message as defined in protocol.cpp file
@ -96,6 +97,9 @@ public:
void CreateReqNetwTranspPropsMes();
void CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs );
void CreateCLPingWithNumClientsMes ( const CHostAddress& InetAddr,
const int iMs,
const int iNumClients );
void CreateCLServerFullMes ( const CHostAddress& InetAddr );
void CreateCLRegisterServerMes ( const CHostAddress& InetAddr,
const CServerCoreInfo& ServerInfo );
@ -204,6 +208,8 @@ protected:
bool EvaluateCLPingMes ( const CHostAddress& InetAddr,
const CVector<uint8_t>& vecData );
bool EvaluateCLPingWithNumClientsMes ( const CHostAddress& InetAddr,
const CVector<uint8_t>& vecData );
bool EvaluateCLServerFullMes();
bool EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr,
const CVector<uint8_t>& vecData );
@ -248,6 +254,9 @@ signals:
void Disconnection();
void CLPingReceived ( CHostAddress InetAddr, int iMs );
void CLPingWithNumClientsReceived ( CHostAddress InetAddr,
int iMs,
int iNumClients );
void CLRegisterServerReceived ( CHostAddress InetAddr,
CServerCoreInfo ServerInfo );
void CLServerListReceived ( CHostAddress InetAddr,

View File

@ -870,6 +870,23 @@ int CServer::GetFreeChan()
return INVALID_CHANNEL_ID;
}
int CServer::GetNumberOfConnectedClients()
{
int iNumConnClients = 0;
// check all possible channels for connection status
for ( int i = 0; i < USED_NUM_CHANNELS; i++ )
{
if ( vecChannels[i].IsConnected() )
{
// this channel is connected, increment counter
iNumConnClients += 1;
}
}
return iNumConnClients;
}
int CServer::CheckAddr ( const CHostAddress& Addr )
{
CHostAddress InetAddr;

View File

@ -135,6 +135,7 @@ protected:
int CheckAddr ( const CHostAddress& Addr );
int GetFreeChan();
int GetNumberOfConnectedClients();
CVector<CChannelShortInfo> CreateChannelList();
void CreateAndSendChanListForAllConChannels();
void CreateAndSendChanListForThisChan ( const int iCurChanID );
@ -189,7 +190,11 @@ public slots:
void OnSendCLProtMessage ( CHostAddress InetAddr, CVector<uint8_t> vecMessage );
void OnCLPingReceived ( CHostAddress InetAddr, int iMs )
{ ConnLessProtocol.CreateCLPingMes ( InetAddr, iMs ); }
{
ConnLessProtocol.CreateCLPingWithNumClientsMes ( InetAddr,
iMs,
GetNumberOfConnectedClients() );
}
void OnCLSendEmptyMes ( CHostAddress TargetInetAddr )
{

View File

@ -62,7 +62,6 @@ ServerList.append ( CServerListEntry (
"",
QLocale::Germany, // TEST
"Munich", // TEST
0, // will be updated later
USED_NUM_CHANNELS,
true ) ); // TEST
@ -187,7 +186,6 @@ void CServerListManager::RegisterServer ( const CHostAddress& InetAddr,
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();

View File

@ -81,7 +81,6 @@ public:
QLocale::AnyCountry,
"",
0,
0,
false ) { UpdateRegistration(); }
CServerListEntry ( const CHostAddress& NHAddr,
@ -89,7 +88,6 @@ public:
const QString& NsTopic,
const QLocale::Country& NeCountry,
const QString& NsCity,
const int NiNumClients,
const int NiMaxNumClients,
const bool NbPermOnline)
: CServerInfo ( NHAddr,
@ -97,7 +95,6 @@ public:
NsTopic,
NeCountry,
NsCity,
NiNumClients,
NiMaxNumClients,
NbPermOnline ) { UpdateRegistration(); }
@ -108,7 +105,6 @@ public:
NewCoreServerInfo.strTopic,
NewCoreServerInfo.eCountry,
NewCoreServerInfo.strCity,
NewCoreServerInfo.iNumClients,
NewCoreServerInfo.iMaxNumClients,
NewCoreServerInfo.bPermanentOnline )
{ UpdateRegistration(); }

View File

@ -487,7 +487,6 @@ public:
strTopic ( "" ),
eCountry ( QLocale::AnyCountry ),
strCity ( "" ),
iNumClients ( 0 ),
iMaxNumClients ( 0 ),
bPermanentOnline ( false ) {}
@ -496,14 +495,12 @@ public:
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 ) {}
@ -520,9 +517,6 @@ public:
// 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;
@ -540,7 +534,6 @@ public:
QLocale::AnyCountry,
"",
0,
0,
false ), HostAddr ( CHostAddress() ) {}
CServerInfo (
@ -549,14 +542,12 @@ public:
const QString& NsTopic,
const QLocale::Country& NeCountry,
const QString& NsCity,
const int NiNumClients,
const int NiMaxNumClients,
const bool NbPermOnline) :
CServerCoreInfo ( NsName,
NsTopic,
NeCountry,
NsCity,
NiNumClients,
NiMaxNumClients,
NbPermOnline ), HostAddr ( NHAddr ) {}