-
Notifications
You must be signed in to change notification settings - Fork 241
Add UDP Request/Response for JSON formatted server status #2006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b3dac8a
648af84
0571286
4202b8e
8bf3999
54a5212
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,6 +100,7 @@ int main ( int argc, char** argv ) | |
| QString strServerListFilter = ""; | ||
| QString strWelcomeMessage = ""; | ||
| QString strClientName = ""; | ||
| QString strNotifyServer = ""; | ||
|
|
||
| #if !defined( HEADLESS ) && defined( _WIN32 ) | ||
| if ( AttachConsole ( ATTACH_PARENT_PROCESS ) ) | ||
|
|
@@ -462,6 +463,16 @@ int main ( int argc, char** argv ) | |
| continue; | ||
| } | ||
|
|
||
| // Notification Server xxx.xxx.xxx.xxx:ppp----------------------------- | ||
| if ( GetStringArgument ( argc, argv, i, "--notifyserver", "--notifyserver", strArgument ) ) | ||
| { | ||
|
|
||
| strNotifyServer = strArgument; | ||
| qInfo() << qUtf8Printable ( QString ( "- notify server: %1" ).arg ( strNotifyServer ) ); | ||
| CommandLineOptions << "--notifyserver"; | ||
| continue; | ||
| } | ||
|
|
||
| // Client Name --------------------------------------------------------- | ||
| if ( GetStringArgument ( argc, | ||
| argv, | ||
|
|
@@ -852,6 +863,7 @@ int main ( int argc, char** argv ) | |
| iPortNumber, | ||
| iQosNumber, | ||
| strHTMLStatusFileName, | ||
| strNotifyServer, | ||
| strCentralServer, | ||
| strServerListFileName, | ||
| strServerInfo, | ||
|
|
@@ -985,6 +997,11 @@ QString UsageArguments ( char** argv ) | |
| " -w, --welcomemessage welcome message to display on connect\n" | ||
| " (string or filename)\n" | ||
| " -z, --startminimized start minimizied\n" | ||
| " --serverpublicip specify your public IP address when\n" | ||
| " running a slave and your own directory server\n" | ||
| " behind the same NAT\n" | ||
| " --serverbindip specify the IP address the server will bind to\n" | ||
| " --notifyserver specify server to receive UDP notifications IP:PORT\n" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest grabbing the short option |
||
| "\n" | ||
| "Client only:\n" | ||
| " -c, --connect connect to given server address on startup\n" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -218,6 +218,7 @@ CServer::CServer ( const int iNewMaxNumChan, | |
| const quint16 iPortNumber, | ||
| const quint16 iQosNumber, | ||
| const QString& strHTMLStatusFileName, | ||
| const QString& strNotifyServer, | ||
| const QString& strCentralServer, | ||
| const QString& strServerListFileName, | ||
| const QString& strServerInfo, | ||
|
|
@@ -241,6 +242,8 @@ CServer::CServer ( const int iNewMaxNumChan, | |
| iFrameCount ( 0 ), | ||
| bWriteStatusHTMLFile ( false ), | ||
| strServerHTMLFileListName ( strHTMLStatusFileName ), | ||
| bNotifyServer ( false ), | ||
| strNotifyServerAddr ( strNotifyServer ), | ||
| HighPrecisionTimer ( bNUseDoubleSystemFrameSize ), | ||
| ServerListManager ( iPortNumber, | ||
| strCentralServer, | ||
|
|
@@ -386,6 +389,25 @@ CServer::CServer ( const int iNewMaxNumChan, | |
| WriteHTMLChannelList(); | ||
| } | ||
|
|
||
| // Notify Server Setup | ||
| if ( !strNotifyServerAddr.isEmpty() ) | ||
| { | ||
|
|
||
| // No IPv6 here | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? |
||
|
|
||
| if ( NetworkUtil::ParseNetworkAddress ( strNotifyServerAddr, addrNotifyServer, false ) ) | ||
| { | ||
| qInfo() << "-Server notifications sent to:" << addrNotifyServer.toString(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| bNotifyServer = true; | ||
| OnCLReqServerStatus ( addrNotifyServer ); | ||
| } | ||
| else | ||
| { | ||
| qInfo() << "- ** Could not parse notify server **"; | ||
| bNotifyServer = false; // default is already false - here just for clarity... | ||
| } | ||
| } | ||
|
|
||
| // manage welcome message: if the welcome message is a valid link to a local | ||
| // file, the content of that file is used as the welcome message (#361) | ||
| SetWelcomeMessage ( strNewWelcomeMessage ); // first use given text, may be overwritten | ||
|
|
@@ -465,6 +487,8 @@ CServer::CServer ( const int iNewMaxNumChan, | |
|
|
||
| QObject::connect ( &ConnLessProtocol, &CProtocol::CLReqConnClientsList, this, &CServer::OnCLReqConnClientsList ); | ||
|
|
||
| QObject::connect ( &ConnLessProtocol, &CProtocol::CLReqServerStatus, this, &CServer::OnCLReqServerStatus ); | ||
|
|
||
| QObject::connect ( &ServerListManager, &CServerListManager::SvrRegStatusChanged, this, &CServer::SvrRegStatusChanged ); | ||
|
|
||
| QObject::connect ( &JamController, &recorder::CJamController::RestartRecorder, this, &CServer::RestartRecorder ); | ||
|
|
@@ -562,6 +586,28 @@ void CServer::SendProtMessage ( int iChID, CVector<uint8_t> vecMessage ) | |
| Socket.SendPacket ( vecMessage, vecChannels[iChID].GetAddress() ); | ||
| } | ||
|
|
||
| void CServer::OnCLReqServerStatus ( CHostAddress InetAddr ) | ||
| { | ||
| QString strServerStatus; | ||
|
|
||
| // If not enabled, bail | ||
| if ( !bNotifyServer ) | ||
| return; | ||
|
|
||
| // Only process if the InetAddr is the same as that | ||
| // specified in the command line argument. | ||
|
|
||
| if ( !( InetAddr == addrNotifyServer ) ) | ||
| { | ||
| qInfo() << "** Denied server status message request from" << InetAddr.toString() << "only allowed to" << addrNotifyServer.toString(); | ||
| return; | ||
| } | ||
|
|
||
| BuildServerStatusJson ( strServerStatus ); | ||
|
|
||
| ConnLessProtocol.CreateCLServerStatusMes ( InetAddr, strServerStatus ); | ||
| } | ||
|
|
||
| void CServer::OnNewConnection ( int iChID, CHostAddress RecHostAddr ) | ||
| { | ||
| QMutexLocker locker ( &Mutex ); | ||
|
|
@@ -1403,6 +1449,9 @@ void CServer::CreateAndSendChanListForAllConChannels() | |
| } | ||
| } | ||
|
|
||
| // Send Server Status to the designated host, if specified. | ||
| OnCLReqServerStatus ( addrNotifyServer ); | ||
|
|
||
| // create status HTML file if enabled | ||
| if ( bWriteStatusHTMLFile ) | ||
| { | ||
|
|
@@ -1457,6 +1506,8 @@ void CServer::CreateAndSendRecorderStateForAllConChannels() | |
| vecChannels[i].CreateRecorderStateMes ( eRecorderState ); | ||
| } | ||
| } | ||
|
|
||
| OnCLReqServerStatus ( addrNotifyServer ); | ||
| } | ||
|
|
||
| void CServer::CreateOtherMuteStateChanged ( const int iCurChanID, const int iOtherChanID, const bool bIsMuted ) | ||
|
|
@@ -1702,6 +1753,60 @@ void CServer::SetWelcomeMessage ( const QString& strNWelcMess ) | |
| strWelcomeMessage = strWelcomeMessage.left ( MAX_LEN_CHAT_TEXT ); | ||
| } | ||
|
|
||
| /** | ||
| * Build a server status json string that can be used to either | ||
| * write to a disk-based status file, or sent via CL message. | ||
| */ | ||
|
|
||
| void CServer::BuildServerStatusJson ( QString& strServerStatus ) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the maximum size of this JSON object? |
||
| { | ||
|
|
||
| CHostAddress InetAddr; | ||
| CChannelCoreInfo ci; | ||
|
|
||
| ERecorderState eRecorderState = JamController.GetRecorderState(); | ||
|
|
||
| int ccount = GetNumberOfConnectedClients(); | ||
|
|
||
| QJsonObject jobject; | ||
| QJsonArray jclients; | ||
|
|
||
| jobject["cc"] = ccount; | ||
| jobject["rs"] = eRecorderState; | ||
| jobject["ts"] = QDateTime::currentSecsSinceEpoch(); | ||
| jobject["svnm"] = ServerListManager.GetServerName(); | ||
| jobject["svct"] = ServerListManager.GetServerCity(); | ||
| jobject["svcn"] = ServerListManager.GetServerCountry(); | ||
|
|
||
| if ( ccount > 0 ) | ||
| { | ||
| // write entry for each connected client | ||
| for ( int i = 0; i < iMaxNumChannels; i++ ) | ||
| { | ||
| if ( vecChannels[i].IsConnected() ) | ||
| { | ||
| InetAddr = vecChannels[i].GetAddress(); | ||
| ci = vecChannels[i].GetChanInfo(); | ||
|
|
||
| QJsonObject temp; | ||
| temp["ip"] = InetAddr.toString(); | ||
| temp["in"] = ci.iInstrument; | ||
| temp["sk"] = ci.eSkillLevel; | ||
| temp["cn"] = ci.eCountry; | ||
| temp["ct"] = ci.strCity; | ||
| temp["nm"] = vecChannels[i].GetName(); | ||
|
|
||
| jclients.push_back ( QJsonValue ( temp ) ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| jobject["cl"] = jclients; | ||
|
|
||
| QJsonDocument jdoc ( jobject ); | ||
| strServerStatus = jdoc.toJson ( QJsonDocument::Compact ); | ||
| } | ||
|
|
||
| void CServer::WriteHTMLChannelList() | ||
| { | ||
| // prepare file and stream | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've managed to duplicate the help text some how.