#include <nNetwork.h>
Public Member Functions | |
nMachine () | |
constructor | |
virtual | ~nMachine () |
destructor | |
bool | operator== (nMachine const &other) const |
equality operator | |
bool | operator!= (nMachine const &other) const |
inequality operator | |
void | OnKick (REAL severity=1) |
call this when you kick a user from this machine, frequent kickees will be banned | |
void | Ban (REAL time) |
ban users from this machine for the given time | |
void | Ban (REAL time, tString const &reason) |
ban users from this machine for the given time | |
REAL | IsBanned () const |
returns the number of seconds users from this machine are currently banned for | |
void | AddPlayer () |
call when a player joins from this machine | |
void | RemovePlayer () |
call when a player rom this machine leaves | |
int | GetPlayerCount () |
returns the number of currently registered players | |
REAL | GetKicksPerHour (void) const |
Gets averaged kicks per hour of players from this machine. | |
nMachine const & | GetKicksPerHour (REAL &kph) const |
Gets averaged kicks per hour of players from this machine. | |
nMachine & | SetIP (tString const &IP) |
Sets IP address of the machine. | |
tString const & | GetIP (void) const |
Gets IP address of the machine. | |
nMachine const & | GetIP (tString &IP) const |
Gets IP address of the machine. | |
tString const & | GetBanReason (void) const |
Gets the reason of the ban. | |
nMachine const & | GetBanReason (tString &reason) const |
Gets the reason of the ban. | |
nMachineDecorator * | GetDecorators (void) const |
Gets list of decorators. | |
nMachine const & | GetDecorators (nMachineDecorator *&decorators) const |
Gets list of decorators. | |
template<class T> | |
T * | GetDecorator () |
returns the first machine decorator of a given type | |
Static Public Member Functions | |
static nMachine & | GetMachine (unsigned short userID) |
fetches the machine information of a user | |
static void | Expire () |
expires machine information that is no longer needed | |
static void | KickSpectators () |
remove clients without players from the server | |
template<class T> | |
static T * | GetNextDecorator (nMachineDecorator *run) |
returns the next machine decorator of a given type | |
Private Member Functions | |
nMachine (nMachine const &other) | |
copy constructor | |
nMachine & | operator= (nMachine const &other) |
copy operator | |
nMachine & | SetDecorators (nMachineDecorator *decorators) |
Sets list of decorators. | |
Private Attributes | |
double | lastUsed_ |
system time where this machine was last used | |
double | banned_ |
system time until that this machine is banned | |
tString | banReason_ |
reason for a ban | |
nAverager | kph_ |
averaged kicks per hour of players from this machine | |
int | players_ |
number of players coming from this machine currently | |
REAL | lastPlayerAction_ |
time of the last player action | |
tString | IP_ |
IP address of the machine. | |
nMachineDecorator * | decorators_ |
list of decorators | |
Friends | |
class | nMachineDecorator |
class | nMachinePersistor |
Definition at line 758 of file nNetwork.h.
nMachine::nMachine | ( | void | ) |
constructor
Definition at line 4068 of file nNetwork.cpp.
04072 : lastUsed_(tSysTimeFloat()) 04073 , banned_(-1) 04074 , players_(0) 04075 , decorators_(0) 04076 {
nMachine::~nMachine | ( | void | ) | [virtual] |
destructor
Definition at line 4087 of file nNetwork.cpp.
04091 { 04092 // destroy and remove the decorators 04093 while ( decorators_ ) 04094 { 04095 nMachineDecorator * decorator = decorators_; 04096 decorator->Remove();
nMachine::nMachine | ( | nMachine const & | other | ) | [private] |
copy constructor
bool nMachine::operator== | ( | nMachine const & | other | ) | const |
equality operator
other | the machine to compare with |
Definition at line 4109 of file nNetwork.cpp.
bool nMachine::operator!= | ( | nMachine const & | other | ) | const |
inequality operator
other | the machine to compare with |
Definition at line 4125 of file nNetwork.cpp.
nMachine & nMachine::GetMachine | ( | unsigned short | userID | ) | [static] |
fetches the machine information of a user
userID | the user ID to fetch the machine for |
Definition at line 4166 of file nNetwork.cpp.
Referenced by eVoteItemKick::DoExecute(), nNetObject::DoGetMachine(), FloodProtection(), eVoter::GetVoter(), and ePlayerNetID::MyInitAfterCreation().
04170 { 04171 // throw out old machines 04172 Expire(); 04173 04174 // hardcoding: the server itself 04175 if ( userID == 0 && sn_GetNetState() != nCLIENT ) 04176 { 04177 static nMachine server; 04178 return server; 04179 } 04180 04181 tASSERT( userID <= MAXCLIENTS+1 ); 04182 04183 if( sn_GetNetState() != nSERVER ) 04184 { 04185 // invalid ID, return invalid machine (clients don't track machines) 04186 static nMachine invalid; 04187 return invalid; 04188 } 04189 04190 // get address 04191 tVERIFY( userID <= MAXCLIENTS+1 ); 04192 if( !sn_Connections[userID].socket ) 04193 { 04194 // invalid ID, return invalid machine 04195 static nMachine invalid; 04196 return invalid; 04197 } 04198 tString address; 04199 peers[ userID ].GetAddress( address ); 04200 04201 #ifdef DEBUG_X 04202 // add client ID so multiple connects from one machine are distinquished 04203 tString newIP; 04204 newIP << address << " " << userID; 04205 address = newIP; 04206 #endif 04207
void nMachine::Expire | ( | void | ) | [static] |
expires machine information that is no longer needed
Definition at line 4228 of file nNetwork.cpp.
Referenced by rec_peer().
04232 { 04233 static double lastTime = tSysTimeFloat(); 04234 double time = tSysTimeFloat(); 04235 REAL dt = time - lastTime; 04236 if (dt <= 60) 04237 return; 04238 lastTime = time; 04239 04240 // iterate over known machines 04241 nMachineMap & map = sn_GetMachineMap(); 04242 nMachineMap::iterator toErase = map.end(); 04243 for( nMachineMap::iterator iter = map.begin(); iter != map.end(); ++iter ) 04244 { 04245 // erase last deleted machine 04246 sn_Erase( map, toErase ); 04247 04248 nMachine & machine = *(*iter).second.machine; 04249 04250 // advance the kick statistics if the user is not banned and has been active 04251 if ( time > machine.banned_ && ( machine.lastUsed_ > time - 300 || machine.players_ > 0 ) ) 04252 { 04253 machine.kph_.Add( 0, dt / 3600 ); 04254 machine.kph_.Timestep( dt / 3600*24 ); 04255 } 04256 04257 // if the machine is no longer in use, mark it for deletion 04258 if ( machine.players_ == 0 && machine.lastUsed_ < time - 300.0 && machine.banned_ < time && machine.kph_.GetAverage() < 0.5 ) 04259 toErase = iter; 04260 04261 } 04262
void nMachine::KickSpectators | ( | void | ) | [static] |
remove clients without players from the server
Definition at line 4277 of file nNetwork.cpp.
Referenced by gGame::StateUpdate(), and update_settings().
04281 { 04282 double time = tSysTimeFloat(); 04283 04284 // kick spectators 04285 if ( sn_GetNetState() == nSERVER && sn_spectatorTime > 0 ) 04286 { 04287 for ( int i = MAXCLIENTS; i >= 1; --i ) 04288 { 04289 if ( sn_Connections[i].socket ) 04290 { 04291 nMachine & machine = GetMachine( i ); 04292 if ( machine.players_ == 0 && machine.lastPlayerAction_ + sn_spectatorTime < time ) 04293 { 04294 sn_KickUser( i, tOutput("$network_kill_spectator"), 0 ); 04295 } 04296 }
void nMachine::OnKick | ( | REAL | severity = 1 |
) |
call this when you kick a user from this machine, frequent kickees will be banned
severity | the severity of the offense; 1 is standard. |
Definition at line 4317 of file nNetwork.cpp.
Referenced by eVoteItemKick::DoExecute().
04321 { 04322 // if the user is currently banned, don't count 04323 if ( banned_ > tSysTimeFloat() ) 04324 return; 04325 04326 // ban the user a bit, taking the kicks per hour into account 04327 REAL kph = kph_.GetAverage() - sn_autobanOffset; 04328 if ( kph > 0 ) 04329 { 04330 // the faster you get kicked when you turn up, the longer you get banned 04331 REAL banTime = 60 * kph * sn_autobanFactor; 04332 Ban( banTime, tString(tOutput( "$network_ban_kick" )) ); 04333 } 04334 04335 // add it to the statistics 04336 if ( sn_autobanMaxKPH > 0 ) 04337 kph_.Add( severity * sn_autobanMaxKPH, 2/sn_autobanMaxKPH );
void nMachine::Ban | ( | REAL | time | ) |
ban users from this machine for the given time
time | time in seconds the ban should be in effect |
Definition at line 4351 of file nNetwork.cpp.
Referenced by sn_UnBanConf().
04355 { 04356 lastUsed_ = tSysTimeFloat(); 04357 04358 // set the banning timeout to the current time plus the given time 04359 banned_ = tSysTimeFloat() + time; 04360 04361 if ( sn_printBans ) 04362 { 04363 if ( time > 0 ) 04364 con << tOutput( "$network_ban", GetIP(), int(time/60), banReason_.Len() > 1 ? banReason_ : tOutput( "$network_ban_noreason" ) ); 04365 else
ban users from this machine for the given time
time | time in seconds the ban should be in effect | |
reason | the reason for the ban |
Definition at line 4378 of file nNetwork.cpp.
04382 { 04383 banReason_ = tString(); 04384 if ( reason.Len() > 2 ) 04385 banReason_ = reason;
REAL nMachine::IsBanned | ( | void | ) | const |
returns the number of seconds users from this machine are currently banned for
Definition at line 4397 of file nNetwork.cpp.
Referenced by nMachinePersistor::SaveMachines().
04401 { 04402 // test for banning 04403 double time = tSysTimeFloat(); 04404 if ( time > banned_ ) 04405 return 0;
void nMachine::AddPlayer | ( | void | ) |
call when a player joins from this machine
Definition at line 4416 of file nNetwork.cpp.
Referenced by ePlayerNetID::RegisterWithMachine().
04420 { 04421 lastPlayerAction_ = lastUsed_ = tSysTimeFloat();
void nMachine::RemovePlayer | ( | void | ) |
call when a player rom this machine leaves
Definition at line 4432 of file nNetwork.cpp.
Referenced by ePlayerNetID::UnregisterWithMachine().
04436 { 04437 lastPlayerAction_ = lastUsed_ = tSysTimeFloat(); 04438 04439 players_--;
int nMachine::GetPlayerCount | ( | void | ) |
returns the number of currently registered players
Definition at line 4451 of file nNetwork.cpp.
REAL nMachine::GetKicksPerHour | ( | void | ) | const |
Gets averaged kicks per hour of players from this machine.
Definition at line 4548 of file nNetwork.cpp.
Gets averaged kicks per hour of players from this machine.
kph | averaged kicks per hour of players from this machine to fill |
Definition at line 4564 of file nNetwork.cpp.
Sets IP address of the machine.
IP | IP address of the machine to set |
Definition at line 4613 of file nNetwork.cpp.
04617 { 04618 lastUsed_ = tSysTimeFloat(); 04619
tString const & nMachine::GetIP | ( | void | ) | const |
Gets IP address of the machine.
Definition at line 4580 of file nNetwork.cpp.
Referenced by eVoter::Name(), and se_ListPlayers().
Gets IP address of the machine.
IP | IP address of the machine to fill |
Definition at line 4596 of file nNetwork.cpp.
tString const & nMachine::GetBanReason | ( | void | ) | const |
Gets the reason of the ban.
Definition at line 4631 of file nNetwork.cpp.
Referenced by nMachinePersistor::SaveMachines().
Gets the reason of the ban.
reason | Reason of the ban to fill |
Definition at line 4647 of file nNetwork.cpp.
nMachineDecorator * nMachine::GetDecorators | ( | void | ) | const [inline] |
Gets list of decorators.
Definition at line 1068 of file nNetwork.h.
References decorators_.
Referenced by GetDecorator(), GetQueryMessageStats(), and eVoter::GetVoter().
01069 { 01070 return this->decorators_; 01071 }
nMachine const & nMachine::GetDecorators | ( | nMachineDecorator *& | decorators | ) | const [inline] |
Gets list of decorators.
decorators | list of decorators to fill |
Definition at line 1084 of file nNetwork.h.
References decorators_.
01085 { 01086 decorators = this->decorators_; 01087 return *this; 01088 }
static T* nMachine::GetNextDecorator | ( | nMachineDecorator * | run | ) | [inline, static] |
returns the next machine decorator of a given type
Definition at line 813 of file nNetwork.h.
References tListItem< T >::Next().
00814 { 00815 while ( run ) 00816 { 00817 T * ret = dynamic_cast< T * >( run ); 00818 if ( ret ) 00819 { 00820 return ret; 00821 } 00822 run = run->Next(); 00823 } 00824 00825 return 0; 00826 }
T* nMachine::GetDecorator | ( | ) | [inline] |
returns the first machine decorator of a given type
Definition at line 829 of file nNetwork.h.
References GetDecorators().
00830 { 00831 return GetNextDecorator< T >( GetDecorators() ); 00832 }
nMachine & nMachine::SetDecorators | ( | nMachineDecorator * | decorators | ) | [inline, private] |
Sets list of decorators.
decorators | list of decorators to set |
Definition at line 1101 of file nNetwork.h.
References decorators_.
01102 { 01103 this->decorators_ = decorators; 01104 return *this; 01105 }
friend class nMachineDecorator [friend] |
Definition at line 760 of file nNetwork.h.
friend class nMachinePersistor [friend] |
Definition at line 761 of file nNetwork.h.
double nMachine::lastUsed_ [mutable, private] |
double nMachine::banned_ [mutable, private] |
tString nMachine::banReason_ [private] |
nAverager nMachine::kph_ [private] |
averaged kicks per hour of players from this machine
Definition at line 793 of file nNetwork.h.
Referenced by nMachinePersistor::SaveMachines().
int nMachine::players_ [private] |
REAL nMachine::lastPlayerAction_ [private] |
tString nMachine::IP_ [private] |
nMachineDecorator* nMachine::decorators_ [private] |
list of decorators
Definition at line 798 of file nNetwork.h.
Referenced by GetDecorators(), and SetDecorators().