code style changes
This commit is contained in:
parent
ddfa045419
commit
e32d80b9db
1 changed files with 437 additions and 434 deletions
|
@ -1,434 +1,437 @@
|
||||||
/******************************************************************************\
|
/******************************************************************************\
|
||||||
* Copyright (c) 2004-2011
|
* Copyright (c) 2004-2011
|
||||||
*
|
*
|
||||||
* Author(s):
|
* Author(s):
|
||||||
* Volker Fischer
|
* Volker Fischer
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it under
|
* This program is free software; you can redistribute it and/or modify it under
|
||||||
* the terms of the GNU General Public License as published by the Free Software
|
* the terms of the GNU General Public License as published by the Free Software
|
||||||
* Foundation; either version 2 of the License, or (at your option) any later
|
* Foundation; either version 2 of the License, or (at your option) any later
|
||||||
* version.
|
* version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
* details.
|
* details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License along with
|
* You should have received a copy of the GNU General Public License along with
|
||||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*
|
*
|
||||||
\******************************************************************************/
|
\******************************************************************************/
|
||||||
|
|
||||||
#include "serverlist.h"
|
#include "serverlist.h"
|
||||||
|
|
||||||
|
|
||||||
/* Implementation *************************************************************/
|
/* Implementation *************************************************************/
|
||||||
CServerListManager::CServerListManager ( const quint16 iNPortNum,
|
CServerListManager::CServerListManager ( const quint16 iNPortNum,
|
||||||
const QString& sNCentServAddr,
|
const QString& sNCentServAddr,
|
||||||
const QString& strServerInfo,
|
const QString& strServerInfo,
|
||||||
const int iNumChannels,
|
const int iNumChannels,
|
||||||
CProtocol* pNConLProt )
|
CProtocol* pNConLProt )
|
||||||
: iPortNumber ( iNPortNum ),
|
: iPortNumber ( iNPortNum ),
|
||||||
iNumPredefinedServers ( 0 ),
|
iNumPredefinedServers ( 0 ),
|
||||||
bUseDefaultCentralServerAddress ( false ),
|
bUseDefaultCentralServerAddress ( false ),
|
||||||
pConnLessProtocol ( pNConLProt )
|
pConnLessProtocol ( pNConLProt )
|
||||||
{
|
{
|
||||||
// set the central server address
|
// set the central server address
|
||||||
SetCentralServerAddress ( sNCentServAddr );
|
SetCentralServerAddress ( sNCentServAddr );
|
||||||
|
|
||||||
// prepare the server info information
|
// prepare the server info information
|
||||||
QStringList slServInfoSeparateParams;
|
QStringList slServInfoSeparateParams;
|
||||||
int iServInfoNumSplitItems = 0;
|
int iServInfoNumSplitItems = 0;
|
||||||
|
|
||||||
if ( !strServerInfo.isEmpty() )
|
if ( !strServerInfo.isEmpty() )
|
||||||
{
|
{
|
||||||
// split the different parameter strings
|
// split the different parameter strings
|
||||||
slServInfoSeparateParams = strServerInfo.split ( ";" );
|
slServInfoSeparateParams = strServerInfo.split ( ";" );
|
||||||
|
|
||||||
// get the number of items in the split list
|
// get the number of items in the split list
|
||||||
iServInfoNumSplitItems = slServInfoSeparateParams.count();
|
iServInfoNumSplitItems = slServInfoSeparateParams.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
// per definition, the very first entry is this server and this entry will
|
// per definition, the very first entry is this server and this entry will
|
||||||
// never be deleted
|
// never be deleted
|
||||||
ServerList.clear();
|
ServerList.clear();
|
||||||
|
|
||||||
// init server list entry (server info for this server) with defaults, per
|
// init server list entry (server info for this server) with defaults, per
|
||||||
// definition the client substitudes the IP address of the central server
|
// definition the client substitudes the IP address of the central server
|
||||||
// itself for his server list
|
// itself for his server list
|
||||||
CServerListEntry ThisServerListEntry (
|
CServerListEntry ThisServerListEntry ( CHostAddress(),
|
||||||
CHostAddress(),
|
iPortNumber,
|
||||||
iPortNumber,
|
"",
|
||||||
"",
|
"",
|
||||||
"",
|
QLocale::system().country(),
|
||||||
QLocale::system().country(),
|
"",
|
||||||
"",
|
iNumChannels,
|
||||||
iNumChannels,
|
true );
|
||||||
true );
|
|
||||||
|
// parse the server info string according to definition:
|
||||||
// parse the server info string according to definition:
|
// [this server name];[this server city]; ...
|
||||||
// [this server name];[this server city]; ...
|
// [this server country as QLocale ID]; ...
|
||||||
// [this server country as QLocale ID]; ...
|
// per definition, we expect at least three parameters
|
||||||
// per definition, we expect at least three parameters
|
if ( iServInfoNumSplitItems >= 3 )
|
||||||
if ( iServInfoNumSplitItems >= 3 )
|
{
|
||||||
{
|
// [this server name]
|
||||||
// [this server name]
|
ThisServerListEntry.strName = slServInfoSeparateParams[0];
|
||||||
ThisServerListEntry.strName = slServInfoSeparateParams[0];
|
|
||||||
|
// [this server city]
|
||||||
// [this server city]
|
ThisServerListEntry.strCity = slServInfoSeparateParams[1];
|
||||||
ThisServerListEntry.strCity = slServInfoSeparateParams[1];
|
|
||||||
|
// [this server country as QLocale ID]
|
||||||
// [this server country as QLocale ID]
|
const int iCountry = slServInfoSeparateParams[2].toInt();
|
||||||
const int iCountry = slServInfoSeparateParams[2].toInt();
|
if ( ( iCountry >= 0 ) && ( iCountry <= QLocale::LastCountry ) )
|
||||||
if ( ( iCountry >= 0 ) && ( iCountry <= QLocale::LastCountry ) )
|
{
|
||||||
{
|
ThisServerListEntry.eCountry = static_cast<QLocale::Country> (
|
||||||
ThisServerListEntry.eCountry = static_cast<QLocale::Country> (
|
iCountry );
|
||||||
iCountry );
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// per definition, the first entry in the server list is the own server
|
||||||
// per definition, the first entry in the server list is the own server
|
ServerList.append ( ThisServerListEntry );
|
||||||
ServerList.append ( ThisServerListEntry );
|
|
||||||
|
// parse the predefined server infos (if any) according to definition:
|
||||||
// parse the predefined server infos (if any) according to definition:
|
// [server1 address];[server1 name];[server1 city]; ...
|
||||||
// [server1 address];[server1 name];[server1 city]; ...
|
// [server1 country as QLocale ID]; ...
|
||||||
// [server1 country as QLocale ID]; ...
|
// [server2 address];[server2 name];[server2 city]; ...
|
||||||
// [server2 address];[server2 name];[server2 city]; ...
|
// [server2 country as QLocale ID]; ...
|
||||||
// [server2 country as QLocale ID]; ...
|
// ...
|
||||||
// ...
|
int iCurUsedServInfoSplitItems = 3; // three items are used for this server
|
||||||
int iCurUsedServInfoSplitItems = 3; // three items are used for this server
|
|
||||||
|
// we always expect four items per new server, also check for maximum
|
||||||
// we always expect four items per new server, also check for maximum
|
// allowed number of servers in the server list
|
||||||
// allowed number of servers in the server list
|
while ( ( iServInfoNumSplitItems - iCurUsedServInfoSplitItems >= 4 ) &&
|
||||||
while ( ( iServInfoNumSplitItems - iCurUsedServInfoSplitItems >= 4 ) &&
|
( iNumPredefinedServers <= MAX_NUM_SERVERS_IN_SERVER_LIST ) )
|
||||||
( iNumPredefinedServers <= MAX_NUM_SERVERS_IN_SERVER_LIST ) )
|
{
|
||||||
{
|
// create a new server list entry
|
||||||
// create a new server list entry
|
CServerListEntry NewServerListEntry ( CHostAddress(),
|
||||||
CServerListEntry NewServerListEntry (
|
0, // port number not used
|
||||||
CHostAddress(),
|
"",
|
||||||
0, // port number not used
|
"",
|
||||||
"",
|
QLocale::AnyCountry,
|
||||||
"",
|
"",
|
||||||
QLocale::AnyCountry,
|
iNumChannels,
|
||||||
"",
|
true );
|
||||||
iNumChannels,
|
|
||||||
true );
|
// [server n address]
|
||||||
|
LlconNetwUtil().ParseNetworkAddress (
|
||||||
// [server n address]
|
slServInfoSeparateParams[iCurUsedServInfoSplitItems],
|
||||||
LlconNetwUtil().ParseNetworkAddress (
|
NewServerListEntry.HostAddr );
|
||||||
slServInfoSeparateParams[iCurUsedServInfoSplitItems],
|
|
||||||
NewServerListEntry.HostAddr );
|
// [server n name]
|
||||||
|
NewServerListEntry.strName =
|
||||||
// [server n name]
|
slServInfoSeparateParams[iCurUsedServInfoSplitItems + 1];
|
||||||
NewServerListEntry.strName =
|
|
||||||
slServInfoSeparateParams[iCurUsedServInfoSplitItems + 1];
|
// [server n city]
|
||||||
|
NewServerListEntry.strCity =
|
||||||
// [server n city]
|
slServInfoSeparateParams[iCurUsedServInfoSplitItems + 2];
|
||||||
NewServerListEntry.strCity =
|
|
||||||
slServInfoSeparateParams[iCurUsedServInfoSplitItems + 2];
|
// [server n country as QLocale ID]
|
||||||
|
const int iCountry =
|
||||||
// [server n country as QLocale ID]
|
slServInfoSeparateParams[iCurUsedServInfoSplitItems + 3].toInt();
|
||||||
const int iCountry =
|
|
||||||
slServInfoSeparateParams[iCurUsedServInfoSplitItems + 3].toInt();
|
if ( ( iCountry >= 0 ) && ( iCountry <= QLocale::LastCountry ) )
|
||||||
|
{
|
||||||
if ( ( iCountry >= 0 ) && ( iCountry <= QLocale::LastCountry ) )
|
NewServerListEntry.eCountry =
|
||||||
{
|
static_cast<QLocale::Country> ( iCountry );
|
||||||
NewServerListEntry.eCountry = static_cast<QLocale::Country> (
|
}
|
||||||
iCountry );
|
|
||||||
}
|
// add the new server to the server list
|
||||||
|
ServerList.append ( NewServerListEntry );
|
||||||
// add the new server to the server list
|
|
||||||
ServerList.append ( NewServerListEntry );
|
// we have used four items and have created one predefined server
|
||||||
|
// (adjust counters)
|
||||||
// we have used four items and have created one predefined server
|
iCurUsedServInfoSplitItems += 4;
|
||||||
// (adjust counters)
|
|
||||||
iCurUsedServInfoSplitItems += 4;
|
iNumPredefinedServers++;
|
||||||
iNumPredefinedServers++;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
// Connections -------------------------------------------------------------
|
||||||
// Connections -------------------------------------------------------------
|
QObject::connect ( &TimerPollList, SIGNAL ( timeout() ),
|
||||||
QObject::connect ( &TimerPollList, SIGNAL ( timeout() ),
|
this, SLOT ( OnTimerPollList() ) );
|
||||||
this, SLOT ( OnTimerPollList() ) );
|
|
||||||
|
QObject::connect ( &TimerRegistering, SIGNAL ( timeout() ),
|
||||||
QObject::connect ( &TimerRegistering, SIGNAL ( timeout() ),
|
this, SLOT ( OnTimerRegistering() ) );
|
||||||
this, SLOT ( OnTimerRegistering() ) );
|
}
|
||||||
}
|
|
||||||
|
void CServerListManager::SetCentralServerAddress ( const QString sNCentServAddr )
|
||||||
void CServerListManager::SetCentralServerAddress ( const QString sNCentServAddr )
|
{
|
||||||
{
|
QMutexLocker locker ( &Mutex );
|
||||||
QMutexLocker locker ( &Mutex );
|
|
||||||
|
strCentralServerAddress = sNCentServAddr;
|
||||||
strCentralServerAddress = sNCentServAddr;
|
|
||||||
|
// per definition: If the central server address is empty, the server list
|
||||||
// per definition: If the central server address is empty, the server list
|
// is disabled.
|
||||||
// is disabled.
|
// per definition: If we are in server mode and the central server address
|
||||||
// per definition: If we are in server mode and the central server address
|
// is the localhost address, we are in central server mode. For the central
|
||||||
// is the localhost address, we are in central server mode. For the central
|
// server, the server list is always enabled.
|
||||||
// server, the server list is always enabled.
|
if ( !strCentralServerAddress.isEmpty() )
|
||||||
if ( !strCentralServerAddress.isEmpty() )
|
{
|
||||||
{
|
bIsCentralServer =
|
||||||
bIsCentralServer =
|
( !strCentralServerAddress.toLower().compare ( "localhost" ) ||
|
||||||
( !strCentralServerAddress.toLower().compare ( "localhost" ) ||
|
!strCentralServerAddress.compare ( "127.0.0.1" ) );
|
||||||
!strCentralServerAddress.compare ( "127.0.0.1" ) );
|
|
||||||
|
bEnabled = true;
|
||||||
bEnabled = true;
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
bIsCentralServer = false;
|
||||||
bIsCentralServer = false;
|
bEnabled = true;
|
||||||
bEnabled = true;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
void CServerListManager::Update()
|
||||||
void CServerListManager::Update()
|
{
|
||||||
{
|
QMutexLocker locker ( &Mutex );
|
||||||
QMutexLocker locker ( &Mutex );
|
|
||||||
|
if ( bEnabled )
|
||||||
if ( bEnabled )
|
{
|
||||||
{
|
if ( bIsCentralServer )
|
||||||
if ( bIsCentralServer )
|
{
|
||||||
{
|
// start timer for polling the server list if enabled
|
||||||
// start timer for polling the server list if enabled
|
// 1 minute = 60 * 1000 ms
|
||||||
// 1 minute = 60 * 1000 ms
|
TimerPollList.start ( SERVLIST_POLL_TIME_MINUTES * 60000 );
|
||||||
TimerPollList.start ( SERVLIST_POLL_TIME_MINUTES * 60000 );
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
// initiate registration right away so that we do not have to wait
|
||||||
// initiate registration right away so that we do not have to wait
|
// for the first time out of the timer until the slave server gets
|
||||||
// for the first time out of the timer until the slave server gets
|
// registered at the central server, note that we have to unlock
|
||||||
// registered at the central server, note that we have to unlock
|
// the mutex before calling the function since inside this function
|
||||||
// the mutex before calling the function since inside this function
|
// the mutex is locked, too
|
||||||
// the mutex is locked, too
|
locker.unlock();
|
||||||
locker.unlock();
|
{
|
||||||
{
|
OnTimerRegistering();
|
||||||
OnTimerRegistering();
|
}
|
||||||
}
|
locker.relock();
|
||||||
locker.relock();
|
|
||||||
|
// start timer for registering this server at the central server
|
||||||
// start timer for registering this server at the central server
|
// 1 minute = 60 * 1000 ms
|
||||||
// 1 minute = 60 * 1000 ms
|
TimerRegistering.start ( SERVLIST_REGIST_INTERV_MINUTES * 60000 );
|
||||||
TimerRegistering.start ( SERVLIST_REGIST_INTERV_MINUTES * 60000 );
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
// disable service -> stop timer
|
||||||
// disable service -> stop timer
|
if ( bIsCentralServer )
|
||||||
if ( bIsCentralServer )
|
{
|
||||||
{
|
TimerPollList.stop();
|
||||||
TimerPollList.stop();
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
TimerRegistering.stop();
|
||||||
TimerRegistering.stop();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
/* Central server functionality ***********************************************/
|
||||||
/* Central server functionality ***********************************************/
|
void CServerListManager::OnTimerPollList()
|
||||||
void CServerListManager::OnTimerPollList()
|
{
|
||||||
{
|
QMutexLocker locker ( &Mutex );
|
||||||
QMutexLocker locker ( &Mutex );
|
|
||||||
|
// Check all list entries except of the very first one (which is the central
|
||||||
// Check all list entries except of the very first one (which is the central
|
// server entry) and the predefined servers if they are still valid.
|
||||||
// server entry) and the predefined servers if they are still valid.
|
// Note that we have to use "ServerList.size()" function in the for loop
|
||||||
// Note that we have to use "ServerList.size()" function in the for loop
|
// since we may remove elements from the server list inside the for loop.
|
||||||
// since we may remove elements from the server list inside the for loop.
|
for ( int iIdx = 1 + iNumPredefinedServers; iIdx < ServerList.size(); iIdx++ )
|
||||||
for ( int iIdx = 1 + iNumPredefinedServers; iIdx < ServerList.size(); iIdx++ )
|
{
|
||||||
{
|
// 1 minute = 60 * 1000 ms
|
||||||
// 1 minute = 60 * 1000 ms
|
if ( ServerList[iIdx].RegisterTime.elapsed() >
|
||||||
if ( ServerList[iIdx].RegisterTime.elapsed() >
|
( SERVLIST_TIME_OUT_MINUTES * 60000 ) )
|
||||||
( SERVLIST_TIME_OUT_MINUTES * 60000 ) )
|
{
|
||||||
{
|
// remove this list entry
|
||||||
// remove this list entry
|
ServerList.removeAt ( iIdx );
|
||||||
ServerList.removeAt ( iIdx );
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
void CServerListManager::CentralServerRegisterServer ( const CHostAddress& InetAddr,
|
||||||
void CServerListManager::CentralServerRegisterServer ( const CHostAddress& InetAddr,
|
const CServerCoreInfo& ServerInfo )
|
||||||
const CServerCoreInfo& ServerInfo )
|
{
|
||||||
{
|
QMutexLocker locker ( &Mutex );
|
||||||
QMutexLocker locker ( &Mutex );
|
|
||||||
|
if ( bIsCentralServer && bEnabled )
|
||||||
if ( bIsCentralServer && bEnabled )
|
{
|
||||||
{
|
const int iCurServerListSize = ServerList.size();
|
||||||
const int iCurServerListSize = ServerList.size();
|
|
||||||
|
// check for maximum allowed number of servers in the server list
|
||||||
// check for maximum allowed number of servers in the server list
|
if ( iCurServerListSize < MAX_NUM_SERVERS_IN_SERVER_LIST )
|
||||||
if ( iCurServerListSize < MAX_NUM_SERVERS_IN_SERVER_LIST )
|
{
|
||||||
{
|
// define invalid index used as a flag
|
||||||
// define invalid index used as a flag
|
const int ciInvalidIdx = -1;
|
||||||
const int ciInvalidIdx = -1;
|
|
||||||
|
// Check if server is already registered. Use address to identify
|
||||||
// Check if server is already registered. Use address to identify
|
// a server. The very first list entry must not be checked since
|
||||||
// a server. The very first list entry must not be checked since
|
// this is per definition the central server (i.e., this server)
|
||||||
// this is per definition the central server (i.e., this server)
|
int iSelIdx = ciInvalidIdx; // initialize with an illegal value
|
||||||
int iSelIdx = ciInvalidIdx; // initialize with an illegal value
|
|
||||||
for ( int iIdx = 1; iIdx < iCurServerListSize; iIdx++ )
|
for ( int iIdx = 1; iIdx < iCurServerListSize; iIdx++ )
|
||||||
{
|
{
|
||||||
if ( ServerList[iIdx].HostAddr == InetAddr )
|
if ( ServerList[iIdx].HostAddr == InetAddr )
|
||||||
{
|
{
|
||||||
// store entry index
|
// store entry index
|
||||||
iSelIdx = iIdx;
|
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 ) );
|
// (note that the "update registration" is called in the
|
||||||
}
|
// constructor of the server list entry)
|
||||||
else
|
ServerList.append ( CServerListEntry ( InetAddr, ServerInfo ) );
|
||||||
{
|
}
|
||||||
// do not update the information in the predefined servers
|
else
|
||||||
if ( iSelIdx > iNumPredefinedServers )
|
{
|
||||||
{
|
// do not update the information in the predefined servers
|
||||||
// update all data and call update registration function
|
if ( iSelIdx > iNumPredefinedServers )
|
||||||
ServerList[iSelIdx].iLocalPortNumber = ServerInfo.iLocalPortNumber;
|
{
|
||||||
ServerList[iSelIdx].strName = ServerInfo.strName;
|
// update all data and call update registration function
|
||||||
ServerList[iSelIdx].strTopic = ServerInfo.strTopic;
|
ServerList[iSelIdx].iLocalPortNumber = ServerInfo.iLocalPortNumber;
|
||||||
ServerList[iSelIdx].eCountry = ServerInfo.eCountry;
|
ServerList[iSelIdx].strName = ServerInfo.strName;
|
||||||
ServerList[iSelIdx].strCity = ServerInfo.strCity;
|
ServerList[iSelIdx].strTopic = ServerInfo.strTopic;
|
||||||
ServerList[iSelIdx].iMaxNumClients = ServerInfo.iMaxNumClients;
|
ServerList[iSelIdx].eCountry = ServerInfo.eCountry;
|
||||||
ServerList[iSelIdx].bPermanentOnline = ServerInfo.bPermanentOnline;
|
ServerList[iSelIdx].strCity = ServerInfo.strCity;
|
||||||
|
ServerList[iSelIdx].iMaxNumClients = ServerInfo.iMaxNumClients;
|
||||||
ServerList[iSelIdx].UpdateRegistration();
|
ServerList[iSelIdx].bPermanentOnline = ServerInfo.bPermanentOnline;
|
||||||
}
|
|
||||||
}
|
ServerList[iSelIdx].UpdateRegistration();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
void CServerListManager::CentralServerUnregisterServer ( const CHostAddress& InetAddr )
|
}
|
||||||
{
|
|
||||||
QMutexLocker locker ( &Mutex );
|
void CServerListManager::CentralServerUnregisterServer ( const CHostAddress& InetAddr )
|
||||||
|
{
|
||||||
if ( bIsCentralServer && bEnabled )
|
QMutexLocker locker ( &Mutex );
|
||||||
{
|
|
||||||
const int iCurServerListSize = ServerList.size();
|
if ( bIsCentralServer && bEnabled )
|
||||||
|
{
|
||||||
// Find the server to unregister in the list. The very first list entry
|
const int iCurServerListSize = ServerList.size();
|
||||||
// must not be checked since this is per definition the central server
|
|
||||||
// (i.e., this server), also the predefined servers must not be checked.
|
// Find the server to unregister in the list. The very first list entry
|
||||||
for ( int iIdx = 1 + iNumPredefinedServers; iIdx < iCurServerListSize; iIdx++ )
|
// must not be checked since this is per definition the central server
|
||||||
{
|
// (i.e., this server), also the predefined servers must not be checked.
|
||||||
if ( ServerList[iIdx].HostAddr == InetAddr )
|
for ( int iIdx = 1 + iNumPredefinedServers; iIdx < iCurServerListSize; iIdx++ )
|
||||||
{
|
{
|
||||||
// remove this list entry
|
if ( ServerList[iIdx].HostAddr == InetAddr )
|
||||||
ServerList.removeAt ( iIdx );
|
{
|
||||||
|
// remove this list entry
|
||||||
// entry found, leave for-loop (it is important to exit the
|
ServerList.removeAt ( iIdx );
|
||||||
// for loop since when we remove an item from the server list,
|
|
||||||
// "iCurServerListSize" is not correct anymore and we could get
|
// entry found, leave for-loop (it is important to exit the
|
||||||
// a segmentation fault)
|
// for loop since when we remove an item from the server list,
|
||||||
break;
|
// "iCurServerListSize" is not correct anymore and we could get
|
||||||
}
|
// a segmentation fault)
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
void CServerListManager::CentralServerQueryServerList ( const CHostAddress& InetAddr )
|
}
|
||||||
{
|
|
||||||
QMutexLocker locker ( &Mutex );
|
void CServerListManager::CentralServerQueryServerList ( const CHostAddress& InetAddr )
|
||||||
|
{
|
||||||
if ( bIsCentralServer && bEnabled )
|
QMutexLocker locker ( &Mutex );
|
||||||
{
|
|
||||||
const int iCurServerListSize = ServerList.size();
|
if ( bIsCentralServer && bEnabled )
|
||||||
|
{
|
||||||
// allocate memory for the entire list
|
const int iCurServerListSize = ServerList.size();
|
||||||
CVector<CServerInfo> vecServerInfo ( iCurServerListSize );
|
|
||||||
|
// allocate memory for the entire list
|
||||||
// copy the list (we have to copy it since the message requires
|
CVector<CServerInfo> vecServerInfo ( iCurServerListSize );
|
||||||
// a vector but the list is actually stored in a QList object and
|
|
||||||
// not in a vector object
|
// copy the list (we have to copy it since the message requires
|
||||||
for ( int iIdx = 0; iIdx < iCurServerListSize; iIdx++ )
|
// a vector but the list is actually stored in a QList object and
|
||||||
{
|
// not in a vector object)
|
||||||
// copy list item
|
for ( int iIdx = 0; iIdx < iCurServerListSize; iIdx++ )
|
||||||
vecServerInfo[iIdx] = ServerList[iIdx];
|
{
|
||||||
|
// copy list item
|
||||||
if ( iIdx > 0 )
|
vecServerInfo[iIdx] = ServerList[iIdx];
|
||||||
{
|
|
||||||
// check if the address of the client which is requesting the
|
if ( iIdx > 0 )
|
||||||
// list is the same address as one server in the list -> in this
|
{
|
||||||
// case he has to connect to the local host address
|
// check if the address of the client which is requesting the
|
||||||
if ( vecServerInfo[iIdx].HostAddr.InetAddr == InetAddr.InetAddr )
|
// list is the same address as one server in the list -> in this
|
||||||
{
|
// case he has to connect to the local host address
|
||||||
vecServerInfo[iIdx].HostAddr.InetAddr =
|
if ( vecServerInfo[iIdx].HostAddr.InetAddr == InetAddr.InetAddr )
|
||||||
QHostAddress ( QHostAddress::LocalHost );
|
{
|
||||||
|
vecServerInfo[iIdx].HostAddr.InetAddr =
|
||||||
// take the local port number instead of the received port
|
QHostAddress ( QHostAddress::LocalHost );
|
||||||
// number since some NAT (network address translation) might
|
|
||||||
// have changed the port, note that the predefined servers
|
// take the local port number instead of the received port
|
||||||
// are treated differently, for these we assume that the
|
// number since some NAT (network address translation) might
|
||||||
// received port number is the same as the actual port
|
// have changed the port, note that the predefined servers
|
||||||
// number
|
// are treated differently, for these we assume that the
|
||||||
if ( iIdx > iNumPredefinedServers )
|
// received port number is the same as the actual port
|
||||||
{
|
// number
|
||||||
vecServerInfo[iIdx].HostAddr.iPort =
|
if ( iIdx > iNumPredefinedServers )
|
||||||
ServerList[iIdx].iLocalPortNumber;
|
{
|
||||||
}
|
vecServerInfo[iIdx].HostAddr.iPort =
|
||||||
}
|
ServerList[iIdx].iLocalPortNumber;
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
// create "send empty message" for all registered servers
|
else
|
||||||
// (except of the very first list entry since this is this
|
{
|
||||||
// server (central server) per definition) and also it is
|
// create "send empty message" for all registered servers
|
||||||
// not required to send this message, if the server is on
|
// (except of the very first list entry since this is this
|
||||||
// the same computer
|
// server (central server) per definition) and also it is
|
||||||
pConnLessProtocol->CreateCLSendEmptyMesMes (
|
// not required to send this message, if the server is on
|
||||||
vecServerInfo[iIdx].HostAddr,
|
// the same computer
|
||||||
InetAddr );
|
pConnLessProtocol->CreateCLSendEmptyMesMes (
|
||||||
}
|
vecServerInfo[iIdx].HostAddr,
|
||||||
}
|
InetAddr );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// send the server list to the client
|
}
|
||||||
pConnLessProtocol->CreateCLServerListMes ( InetAddr, vecServerInfo );
|
|
||||||
}
|
// send the server list to the client
|
||||||
}
|
pConnLessProtocol->CreateCLServerListMes ( InetAddr, vecServerInfo );
|
||||||
|
}
|
||||||
|
}
|
||||||
/* Slave server functionality *************************************************/
|
|
||||||
void CServerListManager::SlaveServerRegisterServer ( const bool bIsRegister )
|
|
||||||
{
|
/* Slave server functionality *************************************************/
|
||||||
// we need the lock since the user might change the server properties at
|
void CServerListManager::SlaveServerRegisterServer ( const bool bIsRegister )
|
||||||
// any time
|
{
|
||||||
QMutexLocker locker ( &Mutex );
|
// we need the lock since the user might change the server properties at
|
||||||
|
// any time
|
||||||
// get the correct central server address
|
QMutexLocker locker ( &Mutex );
|
||||||
const QString strCurCentrServAddr =
|
|
||||||
SELECT_SERVER_ADDRESS ( bUseDefaultCentralServerAddress,
|
// get the correct central server address
|
||||||
strCentralServerAddress );
|
const QString strCurCentrServAddr =
|
||||||
|
SELECT_SERVER_ADDRESS ( bUseDefaultCentralServerAddress,
|
||||||
// For the slave server, the slave server properties are store in the
|
strCentralServerAddress );
|
||||||
// very first item in the server list (which is actually no server list
|
|
||||||
// but just one item long for the slave server).
|
// For the slave server, the slave server properties are store in the
|
||||||
// Note that we always have to parse the server address again since if
|
// very first item in the server list (which is actually no server list
|
||||||
// it is an URL of a dynamic IP address, the IP address might have
|
// but just one item long for the slave server).
|
||||||
// changed in the meanwhile.
|
// Note that we always have to parse the server address again since if
|
||||||
CHostAddress HostAddress;
|
// it is an URL of a dynamic IP address, the IP address might have
|
||||||
if ( LlconNetwUtil().ParseNetworkAddress ( strCurCentrServAddr,
|
// changed in the meanwhile.
|
||||||
HostAddress ) )
|
CHostAddress HostAddress;
|
||||||
{
|
|
||||||
if ( bIsRegister )
|
if ( LlconNetwUtil().ParseNetworkAddress ( strCurCentrServAddr,
|
||||||
{
|
HostAddress ) )
|
||||||
// register server
|
{
|
||||||
pConnLessProtocol->CreateCLRegisterServerMes ( HostAddress,
|
if ( bIsRegister )
|
||||||
ServerList[0] );
|
{
|
||||||
}
|
// register server
|
||||||
else
|
pConnLessProtocol->CreateCLRegisterServerMes ( HostAddress,
|
||||||
{
|
ServerList[0] );
|
||||||
// unregister server
|
}
|
||||||
pConnLessProtocol->CreateCLUnregisterServerMes ( HostAddress );
|
else
|
||||||
}
|
{
|
||||||
}
|
// unregister server
|
||||||
}
|
pConnLessProtocol->CreateCLUnregisterServerMes ( HostAddress );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue