support for setting predefined server in the server list by the command line arguments, bug fix with connection dialog if no country is given but a city, started work for unregistering server
This commit is contained in:
parent
d3b9f90f45
commit
e71166d96c
9 changed files with 170 additions and 38 deletions
|
@ -245,7 +245,8 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr,
|
||||||
|
|
||||||
// server location (city and country)
|
// server location (city and country)
|
||||||
QString strLocation = vecServerInfo[iIdx].strCity;
|
QString strLocation = vecServerInfo[iIdx].strCity;
|
||||||
if ( !strLocation.isEmpty() )
|
if ( ( !strLocation.isEmpty() ) &&
|
||||||
|
( vecServerInfo[iIdx].eCountry != QLocale::AnyCountry ) )
|
||||||
{
|
{
|
||||||
strLocation += ", ";
|
strLocation += ", ";
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="cbRegisterServer" >
|
<widget class="QCheckBox" name="cbRegisterServer" >
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
<string>Register Server</string>
|
<string>Register My Server at Central Server</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -82,7 +82,7 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="GroupBoxServerInfo" >
|
<widget class="QGroupBox" name="GroupBoxServerInfo" >
|
||||||
<property name="title" >
|
<property name="title" >
|
||||||
<string>Server Info</string>
|
<string>My Server Info</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" >
|
<layout class="QHBoxLayout" >
|
||||||
<item>
|
<item>
|
||||||
|
|
|
@ -437,9 +437,12 @@ QString UsageArguments ( char **argv )
|
||||||
" -y, --history enable connection history and set file\n"
|
" -y, --history enable connection history and set file\n"
|
||||||
" name (server only)\n"
|
" name (server only)\n"
|
||||||
" -e, --centralserver address of the central server (server only)\n"
|
" -e, --centralserver address of the central server (server only)\n"
|
||||||
" -o, --serverinfo infos of the server in the format:"
|
" -o, --serverinfo infos of the server(s) in the format:\n"
|
||||||
" [name];[city];[country as QLocale ID] (server "
|
" [name];[city];[country as QLocale ID]; ...\n"
|
||||||
" only)\n"
|
" [server1 address];[server1 name]; ...\n"
|
||||||
|
" [server1 city]; ...\n"
|
||||||
|
" [server1 country as QLocale ID]; ...\n"
|
||||||
|
" [server2 address]; ... (server only)\n"
|
||||||
" -c, --connect connect to last server on startup (client\n"
|
" -c, --connect connect to last server on startup (client\n"
|
||||||
" only)\n"
|
" only)\n"
|
||||||
" -d, --disableleds disable LEDs in main window (client only)\n"
|
" -d, --disableleds disable LEDs in main window (client only)\n"
|
||||||
|
|
|
@ -199,6 +199,12 @@ CONNECTION LESS MESSAGES
|
||||||
the QLocale class
|
the QLocale class
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
- PROTMESSID_CLM_UNREGISTER_SERVER: Unregister a server
|
||||||
|
|
||||||
|
note: does not have any data -> n = 0
|
||||||
|
|
||||||
|
|
||||||
- PROTMESSID_CLM_SERVER_LIST: Server list message
|
- PROTMESSID_CLM_SERVER_LIST: Server list message
|
||||||
|
|
||||||
for each registered server append following data:
|
for each registered server append following data:
|
||||||
|
@ -597,6 +603,10 @@ bool CProtocol::ParseConnectionLessMessage ( const CVector<uint8_t>& vecbyData,
|
||||||
case PROTMESSID_CLM_REGISTER_SERVER:
|
case PROTMESSID_CLM_REGISTER_SERVER:
|
||||||
bRet = EvaluateCLRegisterServerMes ( InetAddr, vecData );
|
bRet = EvaluateCLRegisterServerMes ( InetAddr, vecData );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROTMESSID_CLM_UNREGISTER_SERVER:
|
||||||
|
bRet = EvaluateCLUnregisterServerMes ( InetAddr );
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1314,6 +1324,20 @@ bool CProtocol::EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr,
|
||||||
return false; // no error
|
return false; // no error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CProtocol::CreateCLUnregisterServerMes ( const CHostAddress& InetAddr )
|
||||||
|
{
|
||||||
|
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_UNREGISTER_SERVER,
|
||||||
|
CVector<uint8_t> ( 0 ),
|
||||||
|
InetAddr );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CProtocol::EvaluateCLUnregisterServerMes ( const CHostAddress& InetAddr )
|
||||||
|
{
|
||||||
|
// invoke message action
|
||||||
|
emit CLUnregisterServerReceived ( InetAddr );
|
||||||
|
|
||||||
|
return false; // no error
|
||||||
|
}
|
||||||
|
|
||||||
void CProtocol::CreateCLServerListMes ( const CHostAddress& InetAddr,
|
void CProtocol::CreateCLServerListMes ( const CHostAddress& InetAddr,
|
||||||
const CVector<CServerInfo> vecServerInfo )
|
const CVector<CServerInfo> vecServerInfo )
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
#define PROTMESSID_CLM_PING_MS_WITHNUMCLIENTS 1002 // for ping time and num. of clients info
|
#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_SERVER_FULL 1003 // server full message
|
||||||
#define PROTMESSID_CLM_REGISTER_SERVER 1004 // register server
|
#define PROTMESSID_CLM_REGISTER_SERVER 1004 // register server
|
||||||
#define PROTMESSID_CLM_UNREGISTER_SERVER 1005 // unregister server -> TODO
|
#define PROTMESSID_CLM_UNREGISTER_SERVER 1005 // unregister server
|
||||||
#define PROTMESSID_CLM_SERVER_LIST 1006 // server list
|
#define PROTMESSID_CLM_SERVER_LIST 1006 // server list
|
||||||
#define PROTMESSID_CLM_REQ_SERVER_LIST 1007 // request 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_SEND_EMPTY_MESSAGE 1008 // an empty message shall be send
|
||||||
|
@ -103,6 +103,7 @@ public:
|
||||||
void CreateCLServerFullMes ( const CHostAddress& InetAddr );
|
void CreateCLServerFullMes ( const CHostAddress& InetAddr );
|
||||||
void CreateCLRegisterServerMes ( const CHostAddress& InetAddr,
|
void CreateCLRegisterServerMes ( const CHostAddress& InetAddr,
|
||||||
const CServerCoreInfo& ServerInfo );
|
const CServerCoreInfo& ServerInfo );
|
||||||
|
void CreateCLUnregisterServerMes ( const CHostAddress& InetAddr );
|
||||||
void CreateCLServerListMes ( const CHostAddress& InetAddr,
|
void CreateCLServerListMes ( const CHostAddress& InetAddr,
|
||||||
const CVector<CServerInfo> vecServerInfo );
|
const CVector<CServerInfo> vecServerInfo );
|
||||||
void CreateCLReqServerListMes ( const CHostAddress& InetAddr );
|
void CreateCLReqServerListMes ( const CHostAddress& InetAddr );
|
||||||
|
@ -213,6 +214,7 @@ protected:
|
||||||
bool EvaluateCLServerFullMes();
|
bool EvaluateCLServerFullMes();
|
||||||
bool EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr,
|
bool EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr,
|
||||||
const CVector<uint8_t>& vecData );
|
const CVector<uint8_t>& vecData );
|
||||||
|
bool EvaluateCLUnregisterServerMes ( const CHostAddress& InetAddr );
|
||||||
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 );
|
||||||
|
@ -259,6 +261,7 @@ signals:
|
||||||
int iNumClients );
|
int iNumClients );
|
||||||
void CLRegisterServerReceived ( CHostAddress InetAddr,
|
void CLRegisterServerReceived ( CHostAddress InetAddr,
|
||||||
CServerCoreInfo ServerInfo );
|
CServerCoreInfo ServerInfo );
|
||||||
|
void CLUnregisterServerReceived ( CHostAddress InetAddr );
|
||||||
void CLServerListReceived ( CHostAddress InetAddr,
|
void CLServerListReceived ( CHostAddress InetAddr,
|
||||||
CVector<CServerInfo> vecServerInfo );
|
CVector<CServerInfo> vecServerInfo );
|
||||||
void CLReqServerList ( CHostAddress InetAddr );
|
void CLReqServerList ( CHostAddress InetAddr );
|
||||||
|
|
|
@ -289,6 +289,10 @@ CServer::CServer ( const QString& strLoggingFileName,
|
||||||
SIGNAL ( CLRegisterServerReceived ( CHostAddress, CServerCoreInfo ) ),
|
SIGNAL ( CLRegisterServerReceived ( CHostAddress, CServerCoreInfo ) ),
|
||||||
this, SLOT ( OnCLRegisterServerReceived ( CHostAddress, CServerCoreInfo ) ) );
|
this, SLOT ( OnCLRegisterServerReceived ( CHostAddress, CServerCoreInfo ) ) );
|
||||||
|
|
||||||
|
QObject::connect ( &ConnLessProtocol,
|
||||||
|
SIGNAL ( CLUnregisterServerReceived ( CHostAddress ) ),
|
||||||
|
this, SLOT ( OnCLUnregisterServerReceived ( CHostAddress ) ) );
|
||||||
|
|
||||||
QObject::connect ( &ConnLessProtocol,
|
QObject::connect ( &ConnLessProtocol,
|
||||||
SIGNAL ( CLReqServerList ( CHostAddress ) ),
|
SIGNAL ( CLReqServerList ( CHostAddress ) ),
|
||||||
this, SLOT ( OnCLReqServerList ( CHostAddress ) ) );
|
this, SLOT ( OnCLReqServerList ( CHostAddress ) ) );
|
||||||
|
|
|
@ -254,6 +254,11 @@ public slots:
|
||||||
ServerListManager.RegisterServer ( InetAddr, ServerInfo );
|
ServerListManager.RegisterServer ( InetAddr, ServerInfo );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnCLUnregisterServerReceived ( CHostAddress InetAddr )
|
||||||
|
{
|
||||||
|
ServerListManager.UnregisterServer ( InetAddr );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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!!!
|
||||||
|
|
|
@ -29,12 +29,26 @@
|
||||||
CServerListManager::CServerListManager ( const QString& sNCentServAddr,
|
CServerListManager::CServerListManager ( const QString& sNCentServAddr,
|
||||||
const QString& strServerInfo,
|
const QString& strServerInfo,
|
||||||
CProtocol* pNConLProt )
|
CProtocol* pNConLProt )
|
||||||
: bUseDefaultCentralServerAddress ( false ),
|
: iNumPredefinedServers ( 0 ),
|
||||||
|
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
|
||||||
|
QStringList slServInfoSeparateParams;
|
||||||
|
int iServInfoNumSplitItems = 0;
|
||||||
|
|
||||||
|
if ( !strServerInfo.isEmpty() )
|
||||||
|
{
|
||||||
|
// split the different parameter strings
|
||||||
|
slServInfoSeparateParams = strServerInfo.split ( ";" );
|
||||||
|
|
||||||
|
// get the number of items in the split list
|
||||||
|
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();
|
||||||
|
@ -49,37 +63,87 @@ CServerListManager::CServerListManager ( const QString& sNCentServAddr,
|
||||||
QLocale::system().country(),
|
QLocale::system().country(),
|
||||||
"",
|
"",
|
||||||
USED_NUM_CHANNELS,
|
USED_NUM_CHANNELS,
|
||||||
false );
|
true );
|
||||||
|
|
||||||
// parse the server info string according to definition:
|
// parse the server info string according to definition:
|
||||||
// [name];[city];[country as QLocale ID]
|
// [this server name];[this server city]; ...
|
||||||
if ( !strServerInfo.isEmpty() )
|
// [this server country as QLocale ID]; ...
|
||||||
|
// per definition, we expect at least three parameters
|
||||||
|
if ( iServInfoNumSplitItems >= 3 )
|
||||||
{
|
{
|
||||||
// split the different parameter strings
|
// [this server name]
|
||||||
QStringList slSeparateParameters = strServerInfo.split ( ";" );
|
ThisServerListEntry.strName = slServInfoSeparateParams[0];
|
||||||
|
|
||||||
// per definition, we expect three parameters
|
// [this server city]
|
||||||
if ( slSeparateParameters.count() == 3 )
|
ThisServerListEntry.strCity = slServInfoSeparateParams[1];
|
||||||
{
|
|
||||||
// [name]
|
|
||||||
ThisServerListEntry.strName = slSeparateParameters[0];
|
|
||||||
|
|
||||||
// [city]
|
// [this server country as QLocale ID]
|
||||||
ThisServerListEntry.strCity = slSeparateParameters[1];
|
const int iCountry = slServInfoSeparateParams[2].toInt();
|
||||||
|
|
||||||
// [country as QLocale ID]
|
|
||||||
const int iCountry = slSeparateParameters[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 it the own server
|
// per definition, the first entry in the server list it the own server
|
||||||
ServerList.append ( ThisServerListEntry );
|
ServerList.append ( ThisServerListEntry );
|
||||||
|
|
||||||
|
// parse the predefined server infos (if any) according to definition:
|
||||||
|
// [server1 address];[server1 name];[server1 city]; ...
|
||||||
|
// [server1 country as QLocale ID]; ...
|
||||||
|
// [server2 address];[server2 name];[server2 city]; ...
|
||||||
|
// [server2 country as QLocale ID]; ...
|
||||||
|
// ...
|
||||||
|
int iCurUsedServInfoSplitItems = 3; // three items are used for this server
|
||||||
|
|
||||||
|
// we always expect four items per new server, also check for maximum
|
||||||
|
// allowed number of servers in the server list
|
||||||
|
while ( ( iServInfoNumSplitItems - iCurUsedServInfoSplitItems >= 4 ) &&
|
||||||
|
( iNumPredefinedServers <= MAX_NUM_SERVERS_IN_SERVER_LIST ) )
|
||||||
|
{
|
||||||
|
// create a new server list entry
|
||||||
|
CServerListEntry NewServerListEntry (
|
||||||
|
CHostAddress(),
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
QLocale::AnyCountry,
|
||||||
|
"",
|
||||||
|
USED_NUM_CHANNELS,
|
||||||
|
true );
|
||||||
|
|
||||||
|
// [server n address]
|
||||||
|
LlconNetwUtil().ParseNetworkAddress (
|
||||||
|
slServInfoSeparateParams[iCurUsedServInfoSplitItems],
|
||||||
|
NewServerListEntry.HostAddr );
|
||||||
|
|
||||||
|
// [server n name]
|
||||||
|
NewServerListEntry.strName =
|
||||||
|
slServInfoSeparateParams[iCurUsedServInfoSplitItems + 1];
|
||||||
|
|
||||||
|
// [server n city]
|
||||||
|
NewServerListEntry.strCity =
|
||||||
|
slServInfoSeparateParams[iCurUsedServInfoSplitItems + 2];
|
||||||
|
|
||||||
|
// [server n country as QLocale ID]
|
||||||
|
const int iCountry =
|
||||||
|
slServInfoSeparateParams[iCurUsedServInfoSplitItems + 3].toInt();
|
||||||
|
|
||||||
|
if ( ( iCountry >= 0 ) && ( iCountry <= QLocale::LastCountry ) )
|
||||||
|
{
|
||||||
|
NewServerListEntry.eCountry = static_cast<QLocale::Country> (
|
||||||
|
iCountry );
|
||||||
|
}
|
||||||
|
|
||||||
|
// add the new server to the server list
|
||||||
|
ServerList.append ( NewServerListEntry );
|
||||||
|
|
||||||
|
// we have used four items and have created one predefined server
|
||||||
|
// (adjust counters)
|
||||||
|
iCurUsedServInfoSplitItems += 4;
|
||||||
|
iNumPredefinedServers++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Connections -------------------------------------------------------------
|
// Connections -------------------------------------------------------------
|
||||||
QObject::connect ( &TimerPollList, SIGNAL ( timeout() ),
|
QObject::connect ( &TimerPollList, SIGNAL ( timeout() ),
|
||||||
|
@ -166,8 +230,8 @@ 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) if they are still valid
|
// server entry) and the predefined servers if they are still valid
|
||||||
for ( int iIdx = 1; 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() >
|
||||||
|
@ -232,6 +296,31 @@ void CServerListManager::RegisterServer ( const CHostAddress& InetAddr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CServerListManager::UnregisterServer ( const CHostAddress& InetAddr )
|
||||||
|
{
|
||||||
|
QMutexLocker locker ( &Mutex );
|
||||||
|
|
||||||
|
if ( bIsCentralServer && bEnabled )
|
||||||
|
{
|
||||||
|
const int iCurServerListSize = ServerList.size();
|
||||||
|
|
||||||
|
// Find the server to unregister in the list. The very first list entry
|
||||||
|
// must not be checked since this is per definition the central server
|
||||||
|
// (i.e., this server), also the predefined servers must not be checked
|
||||||
|
for ( int iIdx = 1 + iNumPredefinedServers; iIdx < iCurServerListSize; iIdx++ )
|
||||||
|
{
|
||||||
|
if ( ServerList[iIdx].HostAddr == InetAddr )
|
||||||
|
{
|
||||||
|
// remove this list entry
|
||||||
|
ServerList.removeAt ( iIdx );
|
||||||
|
|
||||||
|
// entry found, leave for-loop
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CServerListManager::QueryServerList ( const CHostAddress& InetAddr )
|
void CServerListManager::QueryServerList ( const CHostAddress& InetAddr )
|
||||||
{
|
{
|
||||||
QMutexLocker locker ( &Mutex );
|
QMutexLocker locker ( &Mutex );
|
||||||
|
|
|
@ -146,6 +146,8 @@ public:
|
||||||
void RegisterServer ( const CHostAddress& InetAddr,
|
void RegisterServer ( const CHostAddress& InetAddr,
|
||||||
const CServerCoreInfo& ServerInfo );
|
const CServerCoreInfo& ServerInfo );
|
||||||
|
|
||||||
|
void UnregisterServer ( const CHostAddress& InetAddr );
|
||||||
|
|
||||||
void QueryServerList ( const CHostAddress& InetAddr );
|
void QueryServerList ( const CHostAddress& InetAddr );
|
||||||
|
|
||||||
|
|
||||||
|
@ -173,6 +175,7 @@ protected:
|
||||||
QMutex Mutex;
|
QMutex Mutex;
|
||||||
QList<CServerListEntry> ServerList;
|
QList<CServerListEntry> ServerList;
|
||||||
QString strCentralServerAddress;
|
QString strCentralServerAddress;
|
||||||
|
int iNumPredefinedServers;
|
||||||
bool bEnabled;
|
bool bEnabled;
|
||||||
bool bIsCentralServer;
|
bool bIsCentralServer;
|
||||||
bool bUseDefaultCentralServerAddress;
|
bool bUseDefaultCentralServerAddress;
|
||||||
|
|
Loading…
Reference in a new issue