From b5bae73ab397cf8b30688dbf97d378fae86d8d44 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sat, 17 Oct 2015 15:37:58 +0000 Subject: [PATCH] added support for server disconnection --- ChangeLog | 1 + src/client.cpp | 4 ++++ src/client.h | 1 + src/main.cpp | 16 ++++++++++++++++ src/server.cpp | 34 ++++++++++++++++++++++------------ src/server.h | 2 ++ 6 files changed, 46 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 460d30c4..88179664 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 3.3.10 +- added support for server disconnection diff --git a/src/client.cpp b/src/client.cpp index 431f8261..e4d80060 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -211,6 +211,10 @@ QObject::connect ( &Channel, SIGNAL ( OpusSupported() ), SIGNAL ( CLPingWithNumClientsReceived ( CHostAddress, int, int ) ), this, SLOT ( OnCLPingWithNumClientsReceived ( CHostAddress, int, int ) ) ); + QObject::connect ( &ConnLessProtocol, + SIGNAL ( CLDisconnection ( CHostAddress ) ), + this, SLOT ( OnCLDisconnection ( CHostAddress ) ) ); + #ifdef ENABLE_CLIENT_VERSION_AND_OS_DEBUGGING QObject::connect ( &ConnLessProtocol, SIGNAL ( CLVersionAndOSReceived ( CHostAddress, COSUtil::EOpSystemType, QString ) ), diff --git a/src/client.h b/src/client.h index 5a1d1e39..096eac28 100755 --- a/src/client.h +++ b/src/client.h @@ -399,6 +399,7 @@ public slots: void OnJittBufSizeChanged ( int iNewJitBufSize ); void OnReqChanInfo() { Channel.SetRemoteInfo ( ChannelInfo ); } void OnNewConnection(); + void OnCLDisconnection ( CHostAddress InetAddr ) { if ( InetAddr == Channel.GetAddress() ) { Stop(); } } void OnCLPingReceived ( CHostAddress InetAddr, int iMs ); diff --git a/src/main.cpp b/src/main.cpp index 08f43bd1..1bc2aa78 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -57,6 +57,7 @@ int main ( int argc, char** argv ) bool bUseGUI = true; bool bStartMinimized = false; bool bShowComplRegConnList = false; + bool bDisconnectAllClients = false; bool bShowAnalyzerConsole = false; bool bCentServPingServerInList = false; int iNumServerChannels = DEFAULT_USED_NUM_CHANNELS; @@ -174,6 +175,20 @@ int main ( int argc, char** argv ) } + // Disconnect all clients (emergency mode) ----------------------------- + // Undocumented debugging command line argument: Needed to disconnect + // an unwanted client. + if ( GetFlagArgument ( argv, + i, + "--disconnectall", // no short form + "--disconnectall" ) ) + { + bDisconnectAllClients = true; + tsConsole << "- disconnect all clients" << endl; + continue; + } + + // Show analyzer console ----------------------------------------------- // Undocumented debugging command line argument: Show the analyzer // console to debug network buffer properties. @@ -448,6 +463,7 @@ int main ( int argc, char** argv ) strServerInfo, strWelcomeMessage, bCentServPingServerInList, + bDisconnectAllClients, eLicenceType ); if ( bUseGUI ) diff --git a/src/server.cpp b/src/server.cpp index a58d24a8..53d160cc 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -207,19 +207,21 @@ CServer::CServer ( const int iNewMaxNumChan, const QString& strServerInfo, const QString& strNewWelcomeMessage, const bool bNCentServPingServerInList, + const bool bNDisconnectAllClients, const ELicenceType eNLicenceType ) : - iMaxNumChannels ( iNewMaxNumChan ), - Socket ( this, iPortNumber ), - bWriteStatusHTMLFile ( false ), - ServerListManager ( iPortNumber, - strCentralServer, - strServerInfo, - iNewMaxNumChan, - bNCentServPingServerInList, - &ConnLessProtocol ), - bAutoRunMinimized ( false ), - strWelcomeMessage ( strNewWelcomeMessage ), - eLicenceType ( eNLicenceType ) + iMaxNumChannels ( iNewMaxNumChan ), + Socket ( this, iPortNumber ), + bWriteStatusHTMLFile ( false ), + ServerListManager ( iPortNumber, + strCentralServer, + strServerInfo, + iNewMaxNumChan, + bNCentServPingServerInList, + &ConnLessProtocol ), + bAutoRunMinimized ( false ), + strWelcomeMessage ( strNewWelcomeMessage ), + eLicenceType ( eNLicenceType ), + bDisconnectAllClients ( bNDisconnectAllClients ) { int iOpusError; int i; @@ -560,6 +562,14 @@ void CServer::OnSendProtMessage ( int iChID, CVector vecMessage ) void CServer::OnNewConnection ( int iChID, CHostAddress RecHostAddr ) { + // in the special case that all clients shall be disconnected, just send the + // disconnect message and leave this function + if ( bDisconnectAllClients ) + { + ConnLessProtocol.CreateCLDisconnection ( RecHostAddr ); + return; + } + // on a new connection we query the network transport properties for the // audio packets (to use the correct network block size and audio // compression properties, etc.) diff --git a/src/server.h b/src/server.h index 619abd69..74dedd9a 100755 --- a/src/server.h +++ b/src/server.h @@ -131,6 +131,7 @@ public: const QString& strServerInfo, const QString& strNewWelcomeMessage, const bool bNCentServPingServerInList, + const bool bNDisconnectAllClients, const ELicenceType eNLicenceType ); void Start(); @@ -273,6 +274,7 @@ protected: // messaging QString strWelcomeMessage; ELicenceType eLicenceType; + bool bDisconnectAllClients; signals: void Started();