From 1cc421fc566090f6ec0ef47121007ca63d0fde30 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Fri, 8 Aug 2008 06:28:47 +0000 Subject: [PATCH] added initial code for server status file --- src/channel.cpp | 84 ++++++++++++++++++++++++++++++++++++++++++++++++- src/channel.h | 5 +++ 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/src/channel.cpp b/src/channel.cpp index 68dacbe5..b662fc94 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -28,7 +28,7 @@ /******************************************************************************\ * CChannelSet * \******************************************************************************/ -CChannelSet::CChannelSet() +CChannelSet::CChannelSet() : bWriteStatusHTMLFile ( false ) { // enable all channels for ( int i = 0; i < MAX_NUM_CHANNELS; i++ ) @@ -301,6 +301,12 @@ bool CChannelSet::PutData ( const CVector& vecbyRecBuf, // request, only the already connected clients get the list // automatically, because they don't know when new clients connect CreateAndSendChanListForAllExceptThisChan ( iCurChanID ); + + // create status HTML file if enabled + if ( bWriteStatusHTMLFile ) + { + WriteHTMLChannelList(); + } } } Mutex.unlock(); @@ -385,6 +391,12 @@ void CChannelSet::GetBlockAllConC ( CVector& vecChanID, { // update channel list for all currently connected clients CreateAndSendChanListForAllConChannels(); + + // create status HTML file if enabled + if ( bWriteStatusHTMLFile ) + { + WriteHTMLChannelList(); + } } } Mutex.unlock(); // release mutex @@ -422,6 +434,76 @@ void CChannelSet::GetConCliParam ( CVector& vecHostAddresses, + + + + + + +// TEST +void CChannelSet::WriteHTMLChannelList() +{ + // create channel list + CVector vecChanInfo ( CChannelSet::CreateChannelList() ); + +// TEST +QString strServerHTMLFileListName = "llconserverxxx.txt"; + + // prepare file and stream + QFile serverFileListFile ( strServerHTMLFileListName ); + if ( !serverFileListFile.open ( QIODevice::WriteOnly | QIODevice::Text ) ) + { + return; + } + + QTextStream streamFileOut ( &serverFileListFile ); + +// TEST +QString strServerNameWithPort = "llcon.dyndns.org:22122"; + + streamFileOut << strServerNameWithPort << endl << "
    " << endl; + + // get the number of connected clients + int iNumConnClients = 0; + for ( int i = 0; i < MAX_NUM_CHANNELS; i++ ) + { + if ( vecChannels[i].IsConnected() ) + { + iNumConnClients++; + } + } + + // depending on number of connected clients write list + if ( iNumConnClients == 0 ) + { + // no clients are connected -> empty server + streamFileOut << " Empty server" << endl; + } + else + { + // write entry for each connected client + for ( int i = 0; i < MAX_NUM_CHANNELS; i++ ) + { + if ( vecChannels[i].IsConnected() ) + { + streamFileOut << "
  • " << vecChannels[i].GetName() << "
  • " << endl; + } + } + } + + // finish list + streamFileOut << "
" << endl; +} + + + + + + + + + + /******************************************************************************\ * CChannel * \******************************************************************************/ diff --git a/src/channel.h b/src/channel.h index 830be799..c1a9fce9 100755 --- a/src/channel.h +++ b/src/channel.h @@ -27,6 +27,8 @@ #include #include +#include +#include #include "global.h" #include "buffer.h" #include "audiocompr.h" @@ -241,12 +243,15 @@ protected: void CreateAndSendChanListForAllExceptThisChan ( const int iCurChanID ); void CreateAndSendChanListForThisChan ( const int iCurChanID ); void CreateAndSendChatTextForAllConChannels ( const int iCurChanID, const QString& strChatText ); + void WriteHTMLChannelList(); /* do not use the vector class since CChannel does not have appropriate copy constructor/operator */ CChannel vecChannels[MAX_NUM_CHANNELS]; QMutex Mutex; + bool bWriteStatusHTMLFile; + public slots: // CODE TAG: MAX_NUM_CHANNELS_TAG // make sure we have MAX_NUM_CHANNELS connections!!!