added a command line argument, some code style changes

This commit is contained in:
Volker Fischer 2011-04-05 18:38:22 +00:00
parent 74ac1d075f
commit 36d13454b3
5 changed files with 54 additions and 42 deletions

View File

@ -804,7 +804,7 @@ void CServer::CreateAndSendChanListForThisChan ( const int iCurChanID )
vecChannels[iCurChanID].CreateConClientListMes ( vecChanInfo ); vecChannels[iCurChanID].CreateConClientListMes ( vecChanInfo );
} }
void CServer::CreateAndSendChatTextForAllConChannels ( const int iCurChanID, void CServer::CreateAndSendChatTextForAllConChannels ( const int iCurChanID,
const QString& strChatText ) const QString& strChatText )
{ {
// Create message which is sent to all connected clients ------------------- // Create message which is sent to all connected clients -------------------

View File

@ -35,6 +35,7 @@
#include "channel.h" #include "channel.h"
#include "util.h" #include "util.h"
#include "serverlogging.h" #include "serverlogging.h"
#include "serverlist.h"
/* Definitions ****************************************************************/ /* Definitions ****************************************************************/
@ -106,7 +107,9 @@ public:
const quint16 iPortNumber, const quint16 iPortNumber,
const QString& strHTMLStatusFileName, const QString& strHTMLStatusFileName,
const QString& strHistoryFileName, const QString& strHistoryFileName,
const QString& strServerNameForHTMLStatusFile ); const QString& strServerNameForHTMLStatusFile,
const bool bIsCentralServer,
const QString& strCentralServer );
void Start(); void Start();
void Stop(); void Stop();
@ -178,6 +181,9 @@ protected:
CHighPrecisionTimer HighPrecisionTimer; CHighPrecisionTimer HighPrecisionTimer;
CVector<short> vecsSendData; CVector<short> vecsSendData;
// server list
CServerListManager ServerListManager;
public slots: public slots:
void OnTimer(); void OnTimer();
void OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage ); void OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage );

View File

@ -33,7 +33,7 @@ CServerListManager::CServerListManager ( const bool NbEbld )
// never be deleted // never be deleted
ServerList.clear(); ServerList.clear();
// per definition the client substitudes the IP address of the master server // per definition the client substitudes the IP address of the central server
// itself for his server list // itself for his server list
ServerList.append ( CServerListEntry ( ServerList.append ( CServerListEntry (
CHostAddress(), CHostAddress(),
@ -47,10 +47,11 @@ ServerList.append ( CServerListEntry (
// connections ------------------------------------------------------------- // Connections -------------------------------------------------------------
QObject::connect ( &TimerPollList, SIGNAL ( timeout() ), QObject::connect ( &TimerPollList, SIGNAL ( timeout() ),
this, SLOT ( OnTimerPollList() ) ); this, SLOT ( OnTimerPollList() ) );
// Timers ------------------------------------------------------------------ // Timers ------------------------------------------------------------------
// start timer for polling the server list // start timer for polling the server list
if ( bEnabled ) if ( bEnabled )
@ -64,7 +65,7 @@ void CServerListManager::OnTimerPollList()
{ {
QMutexLocker locker ( &Mutex ); QMutexLocker locker ( &Mutex );
// check all list entries except of the very first one (which is the master // check all list entries except of the very first one (which is the central
// server entry) if they are still valid // server entry) if they are still valid
for ( int iIdx = 1; iIdx < ServerList.size(); iIdx++ ) for ( int iIdx = 1; iIdx < ServerList.size(); iIdx++ )
{ {
@ -83,41 +84,45 @@ void CServerListManager::RegisterServer ( const CHostAddress& InetAddr,
{ {
QMutexLocker locker ( &Mutex ); QMutexLocker locker ( &Mutex );
// define invalid index used as a flag if ( bEnabled )
const int ciInvalidIdx = -1;
// Check if server is already registered. Use IP number and port number to
// fully identify a server. The very first list entry must not be checked
// since this is per definition the master server (i.e., this server)
int iSelIdx = ciInvalidIdx; // initialize with an illegal value
for ( int iIdx = 1; iIdx < ServerList.size(); iIdx++ )
{ {
if ( ServerList[iIdx].HostAddr == InetAddr ) // define invalid index used as a flag
{ const int ciInvalidIdx = -1;
// store entry index
iSelIdx = iIdx;
// entry found, leave for-loop // Check if server is already registered. Use IP number and port number
continue; // to fully identify a server. The very first list entry must not be
// checked since this is per definition the central server (i.e., this
// server)
int iSelIdx = ciInvalidIdx; // initialize with an illegal value
for ( int iIdx = 1; iIdx < ServerList.size(); iIdx++ )
{
if ( ServerList[iIdx].HostAddr == InetAddr )
{
// store entry index
iSelIdx = iIdx;
// entry found, leave for-loop
continue;
}
}
// if server is not yet registered, we have to create a new entry
if ( iSelIdx == ciInvalidIdx )
{
// create a new server list entry and init with received data
ServerList.append ( CServerListEntry ( InetAddr, ServerInfo ) );
}
else
{
// update all data and call update registration function
ServerList[iSelIdx].strName = ServerInfo.strName;
ServerList[iSelIdx].strTopic = ServerInfo.strTopic;
ServerList[iSelIdx].eCountry = ServerInfo.eCountry;
ServerList[iSelIdx].strCity = ServerInfo.strCity;
ServerList[iSelIdx].iNumClients = ServerInfo.iNumClients;
ServerList[iSelIdx].iMaxNumClients = ServerInfo.iMaxNumClients;
ServerList[iSelIdx].bPermanentOnline = ServerInfo.bPermanentOnline;
ServerList[iSelIdx].UpdateRegistration();
} }
} }
// if server is not yet registered, we have to create a new entry
if ( iSelIdx == ciInvalidIdx )
{
// create a new server list entry and init with received data
ServerList.append ( CServerListEntry ( InetAddr, ServerInfo ) );
}
else
{
// update all data and call update registration function
ServerList[iSelIdx].strName = ServerInfo.strName;
ServerList[iSelIdx].strTopic = ServerInfo.strTopic;
ServerList[iSelIdx].eCountry = ServerInfo.eCountry;
ServerList[iSelIdx].strCity = ServerInfo.strCity;
ServerList[iSelIdx].iNumClients = ServerInfo.iNumClients;
ServerList[iSelIdx].iMaxNumClients = ServerInfo.iMaxNumClients;
ServerList[iSelIdx].bPermanentOnline = ServerInfo.bPermanentOnline;
ServerList[iSelIdx].UpdateRegistration();
}
} }

View File

@ -62,7 +62,8 @@ CHistoryGraph::CHistoryGraph() :
PlotPixmap = PlotPixmap.scaled ( PlotPixmap = PlotPixmap.scaled (
PlotCanvasRect.width(), PlotCanvasRect.height() ); PlotCanvasRect.width(), PlotCanvasRect.height() );
// connections
// Connections -------------------------------------------------------------
QObject::connect ( &TimerDailyUpdate, SIGNAL ( timeout() ), QObject::connect ( &TimerDailyUpdate, SIGNAL ( timeout() ),
this, SLOT ( OnTimerDailyUpdate() ) ); this, SLOT ( OnTimerDailyUpdate() ) );
} }
@ -100,7 +101,7 @@ void CHistoryGraph::DrawFrame ( const int iNewNumTicksX )
QPainter PlotPainter ( &PlotPixmap ); QPainter PlotPainter ( &PlotPixmap );
// create actual plot region (grid frame) ---------------------------------- // Create actual plot region (grid frame) ----------------------------------
PlotPainter.setPen ( PlotFrameColor ); PlotPainter.setPen ( PlotFrameColor );
PlotPainter.drawRect ( PlotGridFrame ); PlotPainter.drawRect ( PlotGridFrame );

View File

@ -44,7 +44,7 @@ void CSettings::ReadIniFile ( const QString& sFileName )
} }
// actual settings data --------------------------------------------------- // Actual settings data ---------------------------------------------------
// IP addresses // IP addresses
for ( int iIPAddrIdx = 0; iIPAddrIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIPAddrIdx++ ) for ( int iIPAddrIdx = 0; iIPAddrIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIPAddrIdx++ )
{ {
@ -191,7 +191,7 @@ void CSettings::WriteIniFile ( const QString& sFileName )
QDomDocument IniXMLDocument; QDomDocument IniXMLDocument;
// actual settings data --------------------------------------------------- // Actual settings data ---------------------------------------------------
// IP addresses // IP addresses
for ( int iIPAddrIdx = 0; iIPAddrIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIPAddrIdx++ ) for ( int iIPAddrIdx = 0; iIPAddrIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIPAddrIdx++ )
{ {