From 97d32de751b7afdf146f9930ca5a50f4bb0f349e Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Wed, 4 May 2011 07:15:50 +0000 Subject: [PATCH] unregistering the server does work now correctly --- src/llconserverdlg.cpp | 16 ++++++++++++-- src/server.h | 2 ++ src/serverlist.cpp | 48 ++++++++++++++++++++++++------------------ src/serverlist.h | 5 ++++- 4 files changed, 47 insertions(+), 24 deletions(-) diff --git a/src/llconserverdlg.cpp b/src/llconserverdlg.cpp index 59c231cd..632875b0 100755 --- a/src/llconserverdlg.cpp +++ b/src/llconserverdlg.cpp @@ -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(); diff --git a/src/server.h b/src/server.h index baa6139a..1eb18f2b 100755 --- a/src/server.h +++ b/src/server.h @@ -130,6 +130,8 @@ public: // Server list management -------------------------------------------------- void UpdateServerList() { ServerListManager.Update(); } + void UnregisterSlaveServer() { ServerListManager.SlaveServerUnregister(); } + void SetServerListEnabled ( const bool bState ) { ServerListManager.SetEnabled ( bState ); } diff --git a/src/serverlist.cpp b/src/serverlist.cpp index ba0b7a3d..2b25fe69 100755 --- a/src/serverlist.cpp +++ b/src/serverlist.cpp @@ -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 ); + } } } diff --git a/src/serverlist.h b/src/serverlist.h index 36f2b5b4..25545ad2 100755 --- a/src/serverlist.h +++ b/src/serverlist.h @@ -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_ ) */