From b3dac8aade89f8e1cbd8d2ededb1982d6566008f Mon Sep 17 00:00:00 2001 From: Rob-NY Date: Fri, 11 Jun 2021 15:57:08 -0400 Subject: [PATCH 1/4] initial --- src/main.cpp | 15 +++++++ src/protocol.cpp | 37 ++++++++++++++++ src/protocol.h | 7 +++ src/server.cpp | 110 +++++++++++++++++++++++++++++++++++++++++++++++ src/server.h | 16 +++++++ 5 files changed, 185 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index fb601e74bd..e4853eed47 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -89,6 +89,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 ) ) @@ -437,6 +438,18 @@ 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; + } + + // Version number ------------------------------------------------------ if ( ( !strcmp ( argv[i], "--version" ) ) || ( !strcmp ( argv[i], "-v" ) ) ) { @@ -645,6 +658,7 @@ int main ( int argc, char** argv ) iPortNumber, iQosNumber, strHTMLStatusFileName, + strNotifyServer, strCentralServer, strServerInfo, strServerPublicIP, @@ -771,6 +785,7 @@ QString UsageArguments ( char** argv ) " 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" "\n" "Client only:\n" " -M, --mutestream starts the application in muted state\n" diff --git a/src/protocol.cpp b/src/protocol.cpp index 46aac578b3..9d8e177dd9 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -922,6 +922,10 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false; case PROTMESSID_CLM_REGISTER_SERVER_RESP: EvaluateCLRegisterServerResp ( InetAddr, vecbyMesBodyData ); break; + + case PROTMESSID_CLM_REQ_SERVER_STATUS: + EvaluateCLReqServerStatus( InetAddr ); + break; } } @@ -1716,6 +1720,32 @@ void CProtocol::CreateCLPingWithNumClientsMes ( const CHostAddress& InetAddr, co CreateAndImmSendConLessMessage ( PROTMESSID_CLM_PING_MS_WITHNUMCLIENTS, vecData, InetAddr ); } +/** +* Send json encoded server status +*/ + +void CProtocol::CreateCLServerStatusMes ( const CHostAddress& InetAddr, const QString strServerStatus ) +{ + int iPos = 0; // init position pointer + + // convert server info to utf-8 + const QByteArray strUTF8ServerStatus = strServerStatus.toUtf8(); + + const int iEntrLen = 2 + strUTF8ServerStatus.size(); + + // build data vector + CVector vecData ( iEntrLen ); + + // Server status + PutStringUTF8OnStream ( vecData, iPos, strUTF8ServerStatus ); + + CreateAndImmSendConLessMessage ( PROTMESSID_CLM_SERVER_STATUS, vecData, InetAddr ); + +} + + + + bool CProtocol::EvaluateCLPingWithNumClientsMes ( const CHostAddress& InetAddr, const CVector& vecData ) { int iPos = 0; // init position pointer @@ -2492,6 +2522,13 @@ bool CProtocol::EvaluateCLReqConnClientsListMes ( const CHostAddress& InetAddr ) return false; // no error } +bool CProtocol::EvaluateCLReqServerStatus( const CHostAddress& InetAddr ) +{ + emit CLReqServerStatus( InetAddr ); + return false; +} + + void CProtocol::CreateCLChannelLevelListMes ( const CHostAddress& InetAddr, const CVector& vecLevelList, const int iNumClients ) { // This must be a multiple of bytes at four bits per client diff --git a/src/protocol.h b/src/protocol.h index 5a0d60d788..a6d7895846 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -84,6 +84,9 @@ #define PROTMESSID_CLM_REGISTER_SERVER_EX 1017 // register server with extended information #define PROTMESSID_CLM_RED_SERVER_LIST 1018 // reduced server list +#define PROTMESSID_CLM_REQ_SERVER_STATUS 1020 // request server status +#define PROTMESSID_CLM_SERVER_STATUS 1021 // server status response + // special IDs #define PROTMESSID_SPECIAL_SPLIT_MESSAGE 2001 // a container for split messages @@ -153,6 +156,8 @@ void CreateReqChannelLevelListMes(); void CreateCLReqConnClientsListMes ( const CHostAddress& InetAddr ); void CreateCLChannelLevelListMes ( const CHostAddress& InetAddr, const CVector& vecLevelList, const int iNumClients ); void CreateCLRegisterServerResp ( const CHostAddress& InetAddr, const ESvrRegResult eResult ); + void CreateCLServerStatusMes ( const CHostAddress& InetAddr, const QString strServerStatus ); + static bool ParseMessageFrame ( const CVector& vecbyData, const int iNumBytesIn, @@ -265,6 +270,7 @@ void CreateReqChannelLevelListMes(); bool EvaluateCLReqVersionAndOSMes ( const CHostAddress& InetAddr ); bool EvaluateCLConnClientsListMes ( const CHostAddress& InetAddr, const CVector& vecData ); bool EvaluateCLReqConnClientsListMes ( const CHostAddress& InetAddr ); + bool EvaluateCLReqServerStatus ( const CHostAddress& InetAddr ); bool EvaluateCLChannelLevelListMes ( const CHostAddress& InetAddr, const CVector& vecData ); bool EvaluateCLRegisterServerResp ( const CHostAddress& InetAddr, const CVector& vecData ); @@ -331,6 +337,7 @@ public slots: void CLReqVersionAndOS ( CHostAddress InetAddr ); void CLConnClientsListMesReceived ( CHostAddress InetAddr, CVector vecChanInfo ); void CLReqConnClientsList ( CHostAddress InetAddr ); + void CLReqServerStatus ( CHostAddress InetAddr ); void CLChannelLevelListReceived ( CHostAddress InetAddr, CVector vecLevelList ); void CLRegisterServerResp ( CHostAddress InetAddr, ESvrRegResult eStatus ); }; diff --git a/src/server.cpp b/src/server.cpp index 21fe46f0b2..bc51719bae 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -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& strServerInfo, const QString& strServerListFilter, @@ -238,6 +239,8 @@ CServer::CServer ( const int iNewMaxNumChan, iFrameCount ( 0 ), bWriteStatusHTMLFile ( false ), strServerHTMLFileListName ( strHTMLStatusFileName ), + bNotifyServer( false ), + strNotifyServerAddr( strNotifyServer ), HighPrecisionTimer ( bNUseDoubleSystemFrameSize ), ServerListManager ( iPortNumber, strCentralServer, strServerInfo, strServerPublicIP, strServerListFilter, iNewMaxNumChan, &ConnLessProtocol ), JamController ( this ), @@ -374,6 +377,24 @@ CServer::CServer ( const int iNewMaxNumChan, WriteHTMLChannelList(); } + + // Notify Server Setup + if( !strNotifyServerAddr.isEmpty() ) + { + + if( NetworkUtil::ParseNetworkAddress( strNotifyServerAddr, addrNotifyServer ) ) + { + qInfo() << "-Server notifications sent to:" << addrNotifyServer.toString(); + 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 @@ -452,6 +473,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 ); @@ -549,6 +572,30 @@ void CServer::SendProtMessage ( int iChID, CVector 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"< 0 ) + { + // write entry for each connected client + for ( int i = 0; i < iMaxNumChannels; i++ ) + { + if ( vecChannels[i].IsConnected() ) + { + vecChannels[i].GetAddress ( InetAddr ); + 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 diff --git a/src/server.h b/src/server.h index 749694bb4f..9f6480cff1 100644 --- a/src/server.h +++ b/src/server.h @@ -30,6 +30,11 @@ #include #include #include + +#include +#include +#include + #include #ifdef USE_OPUS_SHARED_LIB # include "opus/opus_custom.h" @@ -158,6 +163,7 @@ class CServer : public QObject, public CServerSlots const quint16 iPortNumber, const quint16 iQosNumber, const QString& strHTMLStatusFileName, + const QString& strNotifyServer, const QString& strCentralServer, const QString& strServerInfo, const QString& strServerListFilter, @@ -284,6 +290,9 @@ class CServer : public QObject, public CServerSlots virtual void customEvent ( QEvent* pEvent ); + void BuildServerStatusJson( QString& strServerStatus ); + + // if server mode is normal or double system frame size bool bUseDoubleSystemFrameSize; int iServerFrameSizeSamples; @@ -352,6 +361,11 @@ class CServer : public QObject, public CServerSlots bool bWriteStatusHTMLFile; QString strServerHTMLFileListName; + // Notify Server + bool bNotifyServer; + CHostAddress addrNotifyServer; + QString strNotifyServerAddr; + CHighPrecisionTimer HighPrecisionTimer; // server list @@ -431,6 +445,8 @@ public slots: void OnCLReqConnClientsList ( CHostAddress InetAddr ) { ConnLessProtocol.CreateCLConnClientsListMes ( InetAddr, CreateChannelList() ); } + void OnCLReqServerStatus ( CHostAddress InetAddr ); + void OnCLRegisterServerReceived ( CHostAddress InetAddr, CHostAddress LInetAddr, CServerCoreInfo ServerInfo ) { ServerListManager.CentralServerRegisterServer ( InetAddr, LInetAddr, ServerInfo ); From 648af84497b2ec29b7f91c2b81e1ff20ace95499 Mon Sep 17 00:00:00 2001 From: Rob-NY Date: Wed, 8 Sep 2021 16:23:16 -0400 Subject: [PATCH 2/4] extended json with server-related location info --- src/server.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/server.cpp b/src/server.cpp index bc51719bae..e5175c6607 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1711,6 +1711,9 @@ void CServer::BuildServerStatusJson( QString& strServerStatus ) 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 ) { From 4202b8e709b1312ce55f35b373abc16fb88b7e05 Mon Sep 17 00:00:00 2001 From: Rob-NY Date: Wed, 8 Sep 2021 23:05:56 -0400 Subject: [PATCH 3/4] changed credits file per guidelines --- src/util.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util.cpp b/src/util.cpp index 5302e9fd03..3fc533cabb 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -489,6 +489,7 @@ CAboutDlg::CAboutDlg ( QWidget* parent ) : CBaseDlg ( parent ) "

Dau Huy Ngoc (ngocdh)

" "

Jiri Popek (jardous)

" "

Gary Wang (BLumia)

" + "

Rob-NY (Rob-NY)

" "
" + tr ( "For details on the contributions check out the " ) + "" + tr ( "Github Contributors list" ) + From 8bf3999952321c36cf1cebe20d5e1b4043f24dc6 Mon Sep 17 00:00:00 2001 From: Rob-NY Date: Thu, 9 Sep 2021 18:48:31 -0400 Subject: [PATCH 4/4] clang.format issues fixed --- src/main.cpp | 1 - src/protocol.cpp | 15 ++++-------- src/protocol.h | 5 ++-- src/server.cpp | 60 ++++++++++++++++++++---------------------------- src/server.h | 7 +++--- 5 files changed, 35 insertions(+), 53 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f63290929d..497ab7db8c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -473,7 +473,6 @@ int main ( int argc, char** argv ) continue; } - // Client Name --------------------------------------------------------- if ( GetStringArgument ( argc, argv, diff --git a/src/protocol.cpp b/src/protocol.cpp index 9d8e177dd9..52a3410783 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -924,7 +924,7 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false; break; case PROTMESSID_CLM_REQ_SERVER_STATUS: - EvaluateCLReqServerStatus( InetAddr ); + EvaluateCLReqServerStatus ( InetAddr ); break; } } @@ -1721,8 +1721,8 @@ void CProtocol::CreateCLPingWithNumClientsMes ( const CHostAddress& InetAddr, co } /** -* Send json encoded server status -*/ + * Send json encoded server status + */ void CProtocol::CreateCLServerStatusMes ( const CHostAddress& InetAddr, const QString strServerStatus ) { @@ -1740,12 +1740,8 @@ void CProtocol::CreateCLServerStatusMes ( const CHostAddress& InetAddr, const QS PutStringUTF8OnStream ( vecData, iPos, strUTF8ServerStatus ); CreateAndImmSendConLessMessage ( PROTMESSID_CLM_SERVER_STATUS, vecData, InetAddr ); - } - - - bool CProtocol::EvaluateCLPingWithNumClientsMes ( const CHostAddress& InetAddr, const CVector& vecData ) { int iPos = 0; // init position pointer @@ -2522,13 +2518,12 @@ bool CProtocol::EvaluateCLReqConnClientsListMes ( const CHostAddress& InetAddr ) return false; // no error } -bool CProtocol::EvaluateCLReqServerStatus( const CHostAddress& InetAddr ) +bool CProtocol::EvaluateCLReqServerStatus ( const CHostAddress& InetAddr ) { - emit CLReqServerStatus( InetAddr ); + emit CLReqServerStatus ( InetAddr ); return false; } - void CProtocol::CreateCLChannelLevelListMes ( const CHostAddress& InetAddr, const CVector& vecLevelList, const int iNumClients ) { // This must be a multiple of bytes at four bits per client diff --git a/src/protocol.h b/src/protocol.h index a6d7895846..e94220882b 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -84,8 +84,8 @@ #define PROTMESSID_CLM_REGISTER_SERVER_EX 1017 // register server with extended information #define PROTMESSID_CLM_RED_SERVER_LIST 1018 // reduced server list -#define PROTMESSID_CLM_REQ_SERVER_STATUS 1020 // request server status -#define PROTMESSID_CLM_SERVER_STATUS 1021 // server status response +#define PROTMESSID_CLM_REQ_SERVER_STATUS 1020 // request server status +#define PROTMESSID_CLM_SERVER_STATUS 1021 // server status response // special IDs #define PROTMESSID_SPECIAL_SPLIT_MESSAGE 2001 // a container for split messages @@ -158,7 +158,6 @@ void CreateReqChannelLevelListMes(); void CreateCLRegisterServerResp ( const CHostAddress& InetAddr, const ESvrRegResult eResult ); void CreateCLServerStatusMes ( const CHostAddress& InetAddr, const QString strServerStatus ); - static bool ParseMessageFrame ( const CVector& vecbyData, const int iNumBytesIn, CVector& vecbyMesBodyData, diff --git a/src/server.cpp b/src/server.cpp index 6d02113366..66e1b08fcc 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -242,8 +242,8 @@ CServer::CServer ( const int iNewMaxNumChan, iFrameCount ( 0 ), bWriteStatusHTMLFile ( false ), strServerHTMLFileListName ( strHTMLStatusFileName ), - bNotifyServer( false ), - strNotifyServerAddr( strNotifyServer ), + bNotifyServer ( false ), + strNotifyServerAddr ( strNotifyServer ), HighPrecisionTimer ( bNUseDoubleSystemFrameSize ), ServerListManager ( iPortNumber, strCentralServer, @@ -389,23 +389,22 @@ CServer::CServer ( const int iNewMaxNumChan, WriteHTMLChannelList(); } - // Notify Server Setup - if( !strNotifyServerAddr.isEmpty() ) + if ( !strNotifyServerAddr.isEmpty() ) { // No IPv6 here - if( NetworkUtil::ParseNetworkAddress( strNotifyServerAddr, addrNotifyServer, false ) ) + if ( NetworkUtil::ParseNetworkAddress ( strNotifyServerAddr, addrNotifyServer, false ) ) { qInfo() << "-Server notifications sent to:" << addrNotifyServer.toString(); bNotifyServer = true; - OnCLReqServerStatus( addrNotifyServer ); + OnCLReqServerStatus ( addrNotifyServer ); } else { qInfo() << "- ** Could not parse notify server **"; - bNotifyServer = false; // default is already false - here just for clarity... + bNotifyServer = false; // default is already false - here just for clarity... } } @@ -592,25 +591,23 @@ void CServer::OnCLReqServerStatus ( CHostAddress InetAddr ) QString strServerStatus; // If not enabled, bail - if( ! bNotifyServer ) + if ( !bNotifyServer ) return; // Only process if the InetAddr is the same as that // specified in the command line argument. - if( !( InetAddr == addrNotifyServer) ) + if ( !( InetAddr == addrNotifyServer ) ) { - qInfo() << "** Denied server status message request from" << InetAddr.toString() << "only allowed to"< virtual void customEvent ( QEvent* pEvent ); - void BuildServerStatusJson( QString& strServerStatus ); - + void BuildServerStatusJson ( QString& strServerStatus ); // if server mode is normal or double system frame size bool bUseDoubleSystemFrameSize; @@ -374,9 +373,9 @@ class CServer : public QObject, public CServerSlots QString strServerHTMLFileListName; // Notify Server - bool bNotifyServer; + bool bNotifyServer; CHostAddress addrNotifyServer; - QString strNotifyServerAddr; + QString strNotifyServerAddr; CHighPrecisionTimer HighPrecisionTimer;