src/network/nServerInfo.cpp File Reference

#include "tMemManager.h"
#include "tSysTime.h"
#include "tConsole.h"
#include "tList.h"
#include "tLocale.h"
#include "tToDo.h"
#include "tDirectories.h"
#include "tConfiguration.h"
#include "tRandom.h"
#include "tRecorder.h"
#include "nSocket.h"
#include "nServerInfo.h"
#include "nNetObject.h"
#include <fstream>

Include dependency graph for nServerInfo.cpp:

Go to the source code of this file.

Classes

class  nQueryMessageStats
class  DeleteMaster

Functions

static int sn_MaxUnreachable ()
static int sn_MaxTNA ()
static int sn_MaxTNATotal ()
static void login_callback ()
tString ToString (const nServerInfoBase &info)
static nServerInfoCreateServerInfo ()
std::istream & operator>> (std::istream &s, nServerInfo &info)
std::ostream & operator<< (std::ostream &s, nServerInfo const &info)
static bool net_Accept ()
static void S_GlobalizeName (tString &connectionName)
static const tStringS_LocalizeName (const tString &connectionName)
nQueryMessageStatsGetQueryMessageStats (nMachine &machine)
bool FloodProtection (nMachine &machine, REAL timeFactor=1.0)
static void sn_ResetFirstInPacket ()
bool FloodProtection (nMessage const &m)
static bool TransIsNewer (unsigned int newTrans, unsigned int oldTrans)
int sn_NumRealUsers ()
tString MasterFile (char const *suffix)
void GetSenderData (const nMessage &m, tString &name, int &port)
static void sn_ReadFiltered (nMessage &m, tString &s)

Variables

static nServerInfosn_masterList = NULL
static nServerInfosn_FirstServer = NULL
static sn_ServerInfoCreatorsn_Creator = NULL
static nServerInfosn_Transmitting [MAXCLIENTS+2]
static unsigned int sn_LastKnown [MAXCLIENTS+2]
static bool sn_SendAll [MAXCLIENTS+2]
static bool sn_Requested [MAXCLIENTS+2]
static REAL sn_Timeout [MAXCLIENTS+2]
static nServerInfosn_Requesting = NULL
static unsigned int sn_NextTransactionNr = 0
static bool sn_AcceptingFromBroadcast = false
bool sn_AcceptingFromMaster = false
static bool sn_IsMaster = false
static nServerInfosn_QuerySoon = NULL
static nTimeRolling sn_QueryTimeout = 0
static REAL sn_queryDelay = 1.5f
static REAL sn_queryDelayGlobal = 0.1f
static int sn_numQueries = 3
static int sn_TNALostContact = 4
static tSettingItem< REALsn_queryDelayConf ("BROWSER_QUERY_DELAY_SINGLE", sn_queryDelay)
static tSettingItem< REALsn_queryDelayGlobalConf ("BROWSER_QUERY_DELAY_GLOBAL", sn_queryDelayGlobal)
static tSettingItem< int > sn_numQueriesConf ("BROWSER_NUM_QUERIES", sn_numQueries)
static tSettingItem< int > sn_TNALostContactConf ("BROWSER_CONTACTLOSS", sn_TNALostContact)
static tList< nServerInfosn_Polling
static tString sn_LastLoaded
static nCallbackLoginLogout nlc & login_callback
static const tString TRANSACTION ("transaction")
static const tString CONNECTION ("connection")
static const tString PORT ("port")
static const tString METHOD ("method")
static const tString KEY ("key")
static const tString TNA ("tna")
static const tString NAME ("name")
static const tString VERSION_TAG ("version")
static const tString RELEASE ("release")
static const tString SCOREBIAS ("scorebias")
static const tString URL ("url")
static const tString END ("ServerEnd")
static const tString START ("ServerBegin")
static nDescriptor SmallServerDescriptor (50, nServerInfo::GetSmallServerInfo,"small_server", true)
static nDescriptor BigServerDescriptor (51, nServerInfo::GetBigServerInfo,"big_server", true)
static nDescriptor BigServerMasterDescriptor (54, nServerInfo::GetBigServerInfoMaster,"big_server_master", true)
static nDescriptor RequestSmallServerInfoDescriptor (52, nServerInfo::GiveSmallServerInfo,"small_request", true)
static nDescriptor RequestBigServerInfoDescriptor (53, nServerInfo::GiveBigServerInfo,"big_request", true)
static nDescriptor RequestBigServerInfoMasterDescriptor (55, nServerInfo::GiveBigServerInfoMaster,"big_request_master", true)
static
nCallbackAcceptPackedWithoutConnection
net_acc & 
net_Accept
static int sn_ServerCount = 0
static tString sn_connectionName ("")
static const int sn_minPingCount = 4
static const int sn_minPingCounts [sn_minPingCount] = { 10,20,50,100 }
static REAL sn_minPingTimes [sn_minPingCount] = { 1,4,20,100 }
static tSettingItem< REALsn_minPingTime10 ("PING_FLOOD_TIME_10", sn_minPingTimes[0])
static tSettingItem< REALsn_minPingTime20 ("PING_FLOOD_TIME_20", sn_minPingTimes[1])
static tSettingItem< REALsn_minPingTime50 ("PING_FLOOD_TIME_50", sn_minPingTimes[2])
static tSettingItem< REALsn_minPingTime100 ("PING_FLOOD_TIME_100", sn_minPingTimes[3])
static bool sn_firstInPacket = true
static nCallbackReceivedComplete sn_resetFirstInPacket (sn_ResetFirstInPacket)
static REAL sn_minPingTimeGlobalFactor = 0.1
static tSettingItem< REALsn_minPingTimeGlobal ("PING_FLOOD_GLOBAL", sn_minPingTimeGlobalFactor)
static DeleteMaster sn_delm
static nServerInfoAdminsn_serverInfoAdmin = NULL
static tString net_dns ("")
static tConfItemLine sn_sbtip_official ("SERVER_DNS", net_dns)


Function Documentation

static nServerInfo* CreateServerInfo (  )  [static]

Definition at line 143 of file nServerInfo.cpp.

References sn_Creator, and tNEW.

Referenced by nServerInfo::GetBigServerInfoCommon(), nServerInfo::GetSmallServerInfo(), and nServerInfo::Load().

00144 {
00145     if (sn_Creator)
00146         return (*sn_Creator)();
00147     else
00148         return tNEW(nServerInfo());
00149 }

Here is the caller graph for this function:

bool FloodProtection ( nMessage const &  m  ) 

Definition at line 954 of file nServerInfo.cpp.

References nQueryMessageStats::Block(), FloodProtection(), nMachine::GetMachine(), GetQueryMessageStats(), nMessage::SenderID(), and server().

Referenced by FloodProtection(), nServerInfo::GetBigServerInfoMaster(), nServerInfo::GiveBigServerInfo(), nServerInfo::GiveBigServerInfoMaster(), and nServerInfo::GiveSmallServerInfo().

00955 {
00956     // get the machine infos
00957     nMachine & server = nMachine::GetMachine( 0 );
00958     nMachine & peer   = nMachine::GetMachine( m.SenderID() );
00959 
00960     // only accept one ping per packet
00961     if ( !sn_firstInPacket )
00962     {
00963         GetQueryMessageStats( peer ).Block();
00964 
00965         return true;
00966     }
00967 
00968     // don't accept further queries from this packet
00969     sn_firstInPacket = false;
00970 
00971     if ( sn_minPingTimes[sn_minPingCount - 1] <= 0 )
00972         return false;
00973 
00974     // and delegate
00975     return FloodProtection( peer ) || ( sn_minPingTimeGlobalFactor > 0 && FloodProtection( server, sn_minPingTimeGlobalFactor ) );
00976 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool FloodProtection ( nMachine machine,
REAL  timeFactor = 1.0 
)

Definition at line 937 of file nServerInfo.cpp.

References nQueryMessageStats::FloodProtection(), and GetQueryMessageStats().

00938 {
00939     // get the decorator and delegate
00940     return GetQueryMessageStats( machine ).FloodProtection( timeFactor );
00941 }

Here is the call graph for this function:

nQueryMessageStats& GetQueryMessageStats ( nMachine machine  ) 

Definition at line 919 of file nServerInfo.cpp.

References decorator, nMachine::GetDecorators(), tListItem< T >::Next(), NULL, and tNEW.

Referenced by FloodProtection().

00920 {
00921     // get the decorator
00922     nQueryMessageStats * stats = NULL;
00923     nMachineDecorator * decorator = machine.GetDecorators();
00924     while ( decorator && !stats )
00925     {
00926         stats = dynamic_cast< nQueryMessageStats * >( decorator );
00927         decorator = decorator->Next();
00928     }
00929     if ( !stats )
00930         stats = tNEW( nQueryMessageStats )( machine );
00931 
00932     // and delegate
00933     return *stats;
00934 }

Here is the call graph for this function:

Here is the caller graph for this function:

void GetSenderData ( const nMessage m,
tString name,
int &  port 
)

Definition at line 1888 of file nServerInfo.cpp.

References nMessage::SenderID(), sn_GetAdr(), and sn_GetPort().

01889 {
01890     sn_GetAdr(m.SenderID(),name);
01891     port = sn_GetPort(m.SenderID());
01892 }

Here is the call graph for this function:

static void login_callback (  )  [static]

Definition at line 103 of file nServerInfo.cpp.

References NULL, sn_LastKnown, sn_Requested, sn_SendAll, sn_Timeout, tSysTimeFloat(), and nCallbackLoginLogout::User().

00103                             {
00104     sn_Transmitting[nCallbackLoginLogout::User()] = NULL;
00105     sn_LastKnown   [nCallbackLoginLogout::User()] = 0;
00106     sn_SendAll     [nCallbackLoginLogout::User()] = true;
00107     sn_Requested   [nCallbackLoginLogout::User()] = false;
00108     sn_Timeout     [nCallbackLoginLogout::User()] = tSysTimeFloat() + 70;
00109 #ifdef KRAWALL_SERVER
00110     sn_Auth        [nCallbackLoginLogout::User()] = false;
00111 #endif
00112 
00113 }

Here is the call graph for this function:

tString MasterFile ( char const *  suffix  ) 

Definition at line 1376 of file nServerInfo.cpp.

Referenced by nServerInfo::GetFromMaster().

01377 {
01378     std::ostringstream filename;
01379     filename << "frommaster" << suffix << ".srv";
01380     return tString( filename.str().c_str() );
01381 }

Here is the caller graph for this function:

static bool net_Accept (  )  [static]

Definition at line 642 of file nServerInfo.cpp.

References BigServerDescriptor, BigServerMasterDescriptor, nCallbackAcceptPackedWithoutConnection::Descriptor(), nDescriptor::ID(), and SmallServerDescriptor.

Here is the call graph for this function:

std::ostream& operator<< ( std::ostream &  s,
nServerInfo const &  info 
)

Definition at line 537 of file nServerInfo.cpp.

References nServerInfo::Save().

00538 {
00539     info.Save( s );
00540 
00541     return s;
00542 }

Here is the call graph for this function:

std::istream& operator>> ( std::istream &  s,
nServerInfo info 
)

Definition at line 530 of file nServerInfo.cpp.

References nServerInfo::Load().

00531 {
00532     info.Load( s );
00533 
00534     return s;
00535 }

Here is the call graph for this function:

static void S_GlobalizeName ( tString connectionName  )  [static]

Definition at line 753 of file nServerInfo.cpp.

Referenced by nServerInfoBase::NetReadThis().

00754 {
00755 }

Here is the caller graph for this function:

static const tString& S_LocalizeName ( const tString connectionName  )  [static]

Definition at line 757 of file nServerInfo.cpp.

Referenced by nServerInfoBase::NetReadThis().

00758 {
00759     return connectionName;
00760 }

Here is the caller graph for this function:

static int sn_MaxTNA (  )  [static]

Definition at line 88 of file nServerInfo.cpp.

References sn_IsMaster.

Referenced by nServerInfo::DeleteUnreachable(), and nServerInfo::QueryServer().

00089 {
00090     return sn_IsMaster ? 30 : 10;
00091 }

Here is the caller graph for this function:

static int sn_MaxTNATotal (  )  [static]

Definition at line 93 of file nServerInfo.cpp.

References sn_IsMaster.

Referenced by nServerInfo::DeleteUnreachable().

00094 {
00095     return sn_IsMaster ? 300 : 50;
00096 }

Here is the caller graph for this function:

static int sn_MaxUnreachable (  )  [static]

Definition at line 83 of file nServerInfo.cpp.

References sn_IsMaster.

Referenced by nServerInfo::DeleteUnreachable().

00084 {
00085     return sn_IsMaster ? 10 : 5;
00086 }

Here is the caller graph for this function:

int sn_NumRealUsers (  ) 

Definition at line 3458 of file nNetwork.cpp.

Referenced by nServerInfo::DoGetFrom().

03462 {

Here is the caller graph for this function:

static void sn_ReadFiltered ( nMessage m,
tString s 
) [static]

Definition at line 2526 of file nServerInfo.cpp.

References tString::NetFilter().

Referenced by nServerInfo::NetReadThis(), and nServerInfoBase::NetReadThis().

02527 {
02528     tColoredString raw;
02529     m >> raw;
02530     raw.NetFilter();
02531     s = raw;
02532 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void sn_ResetFirstInPacket (  )  [static]

Definition at line 945 of file nServerInfo.cpp.

00946 {
00947     sn_firstInPacket = true;
00948 }

tString ToString ( const nServerInfoBase info  ) 

Definition at line 116 of file nServerInfo.cpp.

References nServerInfoBase::GetConnectionName(), and nServerInfoBase::GetPort().

Referenced by nServerInfoBase::AccessAddress(), nServerInfoBase::Connect(), nServerInfo::GetBigServerInfoCommon(), nServerInfo::GetSmallServerInfo(), nServerInfo::NetReadThis(), and nServerInfo::QueryServer().

00117 {
00118     tString ret;
00119     ret << info.GetConnectionName() << ":" << info.GetPort();
00120     return ret;
00121 }

Here is the call graph for this function:

Here is the caller graph for this function:

static bool TransIsNewer ( unsigned int  newTrans,
unsigned int  oldTrans 
) [static]

Definition at line 1069 of file nServerInfo.cpp.

Referenced by nServerInfo::GetFromMaster(), nServerInfo::QueryServer(), and nServerInfo::RunMaster().

01070 {
01071     int diff = newTrans - oldTrans;
01072     return (diff > 0);
01073 }

Here is the caller graph for this function:


Variable Documentation

nDescriptor BigServerDescriptor(51, nServerInfo::GetBigServerInfo,"big_server", true) [static]

Referenced by nServerInfo::GiveBigServerInfo(), and net_Accept().

nDescriptor BigServerMasterDescriptor(54, nServerInfo::GetBigServerInfoMaster,"big_server_master", true) [static]

Referenced by nServerInfo::GiveBigServerInfoMaster(), and net_Accept().

const tString CONNECTION("connection") [static]

Referenced by nServerInfo::Load(), and nServerInfo::Save().

const tString END("ServerEnd") [static]

Referenced by nServerInfo::Load(), and nServerInfo::Save().

const tString KEY("key") [static]

Referenced by nServerInfo::Load(), and nServerInfo::Save().

nCallbackLoginLogout nlc& login_callback [static]

Definition at line 141 of file nServerInfo.cpp.

const tString METHOD("method") [static]

Referenced by nServerInfo::Load(), and nServerInfo::Save().

const tString NAME("name") [static]

Referenced by nServerInfo::Load(), and nServerInfo::Save().

nCallbackAcceptPackedWithoutConnection net_acc & net_Accept [static]

Definition at line 650 of file nServerInfo.cpp.

tString net_dns("") [static]

Referenced by nServerInfoBase::DoGetFrom().

const tString PORT("port") [static]

Referenced by nServerInfo::Load(), and nServerInfo::Save().

const tString RELEASE("release") [static]

Referenced by nServerInfo::Load(), and nServerInfo::Save().

nDescriptor RequestBigServerInfoDescriptor(53, nServerInfo::GiveBigServerInfo,"big_request", true) [static]

Referenced by nServerInfo::QueryServer().

nDescriptor RequestBigServerInfoMasterDescriptor(55, nServerInfo::GiveBigServerInfoMaster,"big_request_master", true) [static]

Referenced by nServerInfo::QueryServer().

nDescriptor RequestSmallServerInfoDescriptor(52, nServerInfo::GiveSmallServerInfo,"small_request", true) [static]

Referenced by nServerInfo::GetFromLAN(), nServerInfo::GetFromLANContinuously(), and nServerInfo::GetFromMaster().

const tString SCOREBIAS("scorebias") [static]

Referenced by nServerInfo::Load(), and nServerInfo::Save().

nDescriptor SmallServerDescriptor(50, nServerInfo::GetSmallServerInfo,"small_server", true) [static]

Referenced by nServerInfo::GiveSmallServerInfo(), net_Accept(), nServerInfo::NetReadThis(), nServerInfo::RunMaster(), and nServerInfo::TellMasterAboutMe().

bool sn_AcceptingFromBroadcast = false [static]

Definition at line 66 of file nServerInfo.cpp.

Referenced by nServerInfo::GetFromLAN(), nServerInfo::GetFromLANContinuously(), nServerInfo::GetFromLANContinuouslyStop(), nServerInfoBase::NetReadThis(), and nServerInfo::RunMaster().

bool sn_AcceptingFromMaster = false

Definition at line 67 of file nServerInfo.cpp.

Referenced by nServerInfo::GetFromMaster(), and nServerInfoBase::NetReadThis().

tString sn_connectionName("") [static]

sn_ServerInfoCreator* sn_Creator = NULL [static]

Definition at line 51 of file nServerInfo.cpp.

Referenced by CreateServerInfo(), and nServerInfo::SetCreator().

DeleteMaster sn_delm [static]

Definition at line 2287 of file nServerInfo.cpp.

bool sn_firstInPacket = true [static]

Definition at line 944 of file nServerInfo.cpp.

nServerInfo* sn_FirstServer = NULL [static]

Definition at line 50 of file nServerInfo.cpp.

bool sn_IsMaster = false [static]

Definition at line 68 of file nServerInfo.cpp.

Referenced by nServerInfo::Alive(), nServerInfo::GetBigServerInfoCommon(), nServerInfo::GetSmallServerInfo(), nServerInfo::GiveBigServerInfo(), nServerInfo::GiveBigServerInfoMaster(), nServerInfo::GiveSmallServerInfo(), nServerInfo::NetReadThis(), nServerInfoBase::NetReadThis(), nServerInfo::nServerInfo(), nServerInfo::QueryServer(), nServerInfo::RunMaster(), sn_MaxTNA(), sn_MaxTNATotal(), and sn_MaxUnreachable().

unsigned int sn_LastKnown[MAXCLIENTS+2] [static]

Definition at line 54 of file nServerInfo.cpp.

Referenced by nServerInfo::GiveSmallServerInfo(), login_callback(), and nServerInfo::RunMaster().

tString sn_LastLoaded [static]

Definition at line 100 of file nServerInfo.cpp.

nServerInfo* sn_masterList = NULL [static]

Definition at line 49 of file nServerInfo.cpp.

const int sn_minPingCount = 4 [static]

Definition at line 785 of file nServerInfo.cpp.

const int sn_minPingCounts[sn_minPingCount] = { 10,20,50,100 } [static]

Definition at line 787 of file nServerInfo.cpp.

tSettingItem< REAL > sn_minPingTime10("PING_FLOOD_TIME_10", sn_minPingTimes[0]) [static]

tSettingItem< REAL > sn_minPingTime100("PING_FLOOD_TIME_100", sn_minPingTimes[3]) [static]

tSettingItem< REAL > sn_minPingTime20("PING_FLOOD_TIME_20", sn_minPingTimes[1]) [static]

tSettingItem< REAL > sn_minPingTime50("PING_FLOOD_TIME_50", sn_minPingTimes[2]) [static]

tSettingItem< REAL > sn_minPingTimeGlobal("PING_FLOOD_GLOBAL", sn_minPingTimeGlobalFactor) [static]

REAL sn_minPingTimeGlobalFactor = 0.1 [static]

Definition at line 950 of file nServerInfo.cpp.

REAL sn_minPingTimes[sn_minPingCount] = { 1,4,20,100 } [static]

Definition at line 789 of file nServerInfo.cpp.

unsigned int sn_NextTransactionNr = 0 [static]

Definition at line 64 of file nServerInfo.cpp.

Referenced by nServerInfo::Alive(), nServerInfo::nServerInfo(), and nServerInfo::RunMaster().

int sn_numQueries = 3 [static]

Definition at line 75 of file nServerInfo.cpp.

Referenced by nServerInfo::DoQueryAll().

tSettingItem< int > sn_numQueriesConf("BROWSER_NUM_QUERIES", sn_numQueries) [static]

tList<nServerInfo> sn_Polling [static]

Definition at line 98 of file nServerInfo.cpp.

Referenced by nServerInfo::DoQueryAll(), and nServerInfo::StartQueryAll().

REAL sn_queryDelay = 1.5f [static]

Definition at line 73 of file nServerInfo.cpp.

Referenced by nServerInfo::DoQueryAll().

tSettingItem< REAL > sn_queryDelayConf("BROWSER_QUERY_DELAY_SINGLE", sn_queryDelay) [static]

REAL sn_queryDelayGlobal = 0.1f [static]

Definition at line 74 of file nServerInfo.cpp.

Referenced by nServerInfo::DoQueryAll().

tSettingItem< REAL > sn_queryDelayGlobalConf("BROWSER_QUERY_DELAY_GLOBAL", sn_queryDelayGlobal) [static]

nServerInfo* sn_QuerySoon = NULL [static]

Definition at line 70 of file nServerInfo.cpp.

nTimeRolling sn_QueryTimeout = 0 [static]

Definition at line 71 of file nServerInfo.cpp.

Referenced by nServerInfo::GetSmallServerInfo(), and nServerInfo::RunMaster().

bool sn_Requested[MAXCLIENTS+2] [static]

Definition at line 56 of file nServerInfo.cpp.

Referenced by nServerInfo::GiveSmallServerInfo(), login_callback(), and nServerInfo::RunMaster().

nServerInfo* sn_Requesting = NULL [static]

Definition at line 63 of file nServerInfo.cpp.

nCallbackReceivedComplete sn_resetFirstInPacket(sn_ResetFirstInPacket) [static]

tConfItemLine sn_sbtip_official("SERVER_DNS", net_dns) [static]

bool sn_SendAll[MAXCLIENTS+2] [static]

Definition at line 55 of file nServerInfo.cpp.

Referenced by nServerInfo::GiveSmallServerInfo(), login_callback(), and nServerInfo::RunMaster().

int sn_ServerCount = 0 [static]

Definition at line 652 of file nServerInfo.cpp.

nServerInfoAdmin* sn_serverInfoAdmin = NULL [static]

Definition at line 2340 of file nServerInfo.cpp.

REAL sn_Timeout[MAXCLIENTS+2] [static]

Definition at line 57 of file nServerInfo.cpp.

Referenced by login_callback(), and nServerInfo::RunMaster().

int sn_TNALostContact = 4 [static]

Definition at line 76 of file nServerInfo.cpp.

Referenced by nServerInfo::Alive(), nServerInfo::DeleteUnreachable(), nServerInfo::Polling(), nServerInfo::QueryServer(), nServerInfo::Reachable(), and nServerInfo::RunMaster().

tSettingItem< int > sn_TNALostContactConf("BROWSER_CONTACTLOSS", sn_TNALostContact) [static]

nServerInfo* sn_Transmitting[MAXCLIENTS+2] [static]

Definition at line 53 of file nServerInfo.cpp.

const tString START("ServerBegin") [static]

Referenced by nServerInfo::Load(), and nServerInfo::Save().

const tString TNA("tna") [static]

Referenced by nServerInfo::DeleteUnreachable(), nServerInfo::Load(), nServerInfo::Save(), and nServerInfo::StartQueryAll().

const tString TRANSACTION("transaction") [static]

Referenced by nServerInfo::Load(), and nServerInfo::Save().

const tString URL("url") [static]

Referenced by nServerInfo::Load(), and nServerInfo::Save().

const tString VERSION_TAG("version") [static]

Referenced by nServerInfo::Load(), and nServerInfo::Save().


Generated on Sat Mar 15 23:02:17 2008 for Armagetron Advanced by  doxygen 1.5.4