unregistering the server does work now correctly

This commit is contained in:
Volker Fischer 2011-05-04 07:15:50 +00:00
parent ed74f3e370
commit 97d32de751
4 changed files with 47 additions and 24 deletions

View file

@ -228,9 +228,21 @@ void CLlconServerDlg::OnDefaultCentralServerStateChanged ( int value )
void CLlconServerDlg::OnRegisterServerStateChanged ( int value )
{
const bool bRegState = ( value == Qt::Checked );
// apply new setting to the server and update it
pServer->SetServerListEnabled ( value == Qt::Checked );
pServer->UpdateServerList();
pServer->SetServerListEnabled ( bRegState );
// If registering is enabled, update data. If registering is disabled,
// unregister slave server
if ( bRegState )
{
pServer->UpdateServerList();
}
else
{
pServer->UnregisterSlaveServer();
}
// update GUI dependencies
UpdateGUIDependencies();

View file

@ -130,6 +130,8 @@ public:
// Server list management --------------------------------------------------
void UpdateServerList() { ServerListManager.Update(); }
void UnregisterSlaveServer() { ServerListManager.SlaveServerUnregister(); }
void SetServerListEnabled ( const bool bState )
{ ServerListManager.SetEnabled ( bState ); }

View file

@ -376,37 +376,43 @@ void CServerListManager::CentralServerQueryServerList ( const CHostAddress& Inet
/* Slave server functionality *************************************************/
void CServerListManager::OnTimerRegistering()
void CServerListManager::SlaveServerRegisterServer ( const bool bIsRegister )
{
// we need the lock since the user might change the server properties at
// any time
QMutexLocker locker ( &Mutex );
if ( !bIsCentralServer && bEnabled )
// get the correct central server address
QString strCurCentrServAddr;
if ( bUseDefaultCentralServerAddress )
{
// get the correct central server address
QString strCurCentrServAddr;
if ( bUseDefaultCentralServerAddress )
{
strCurCentrServAddr = DEFAULT_SERVER_ADDRESS;
}
else
{
strCurCentrServAddr = strCentralServerAddress;
}
strCurCentrServAddr = DEFAULT_SERVER_ADDRESS;
}
else
{
strCurCentrServAddr = strCentralServerAddress;
}
// For the slave server, the slave server properties are store in the
// very first item in the server list (which is actually no server list
// but just one item long for the slave server).
// Note that we always have to parse the server address again since if
// it is an URL of a dynamic IP address, the IP address might have
// changed in the meanwhile.
CHostAddress HostAddress;
if ( LlconNetwUtil().ParseNetworkAddress ( strCurCentrServAddr,
HostAddress ) )
// For the slave server, the slave server properties are store in the
// very first item in the server list (which is actually no server list
// but just one item long for the slave server).
// Note that we always have to parse the server address again since if
// it is an URL of a dynamic IP address, the IP address might have
// changed in the meanwhile.
CHostAddress HostAddress;
if ( LlconNetwUtil().ParseNetworkAddress ( strCurCentrServAddr,
HostAddress ) )
{
if ( bIsRegister )
{
// register server
pConnLessProtocol->CreateCLRegisterServerMes ( HostAddress,
ServerList[0] );
}
else
{
// unregister server
pConnLessProtocol->CreateCLUnregisterServerMes ( HostAddress );
}
}
}

View file

@ -150,6 +150,7 @@ public:
void CentralServerQueryServerList ( const CHostAddress& InetAddr );
void SlaveServerUnregister() { SlaveServerRegisterServer ( false ); }
// set server infos -> per definition the server info of this server is
// stored in the first entry of the list, we assume here that the first
@ -170,6 +171,8 @@ public:
QLocale::Country GetServerCountry() { return ServerList[0].eCountry; }
protected:
void SlaveServerRegisterServer ( const bool bIsRegister );
QTimer TimerPollList;
QTimer TimerRegistering;
QMutex Mutex;
@ -184,7 +187,7 @@ protected:
public slots:
void OnTimerPollList();
void OnTimerRegistering();
void OnTimerRegistering() { SlaveServerRegisterServer ( true ); }
};
#endif /* !defined ( SERVERLIST_HOIJH8OUWEF_WFEIOBU_3_43445KJIUHF1912__INCLUDED_ ) */