#include "tError.h"
#include "tString.h"
#include "tHeap.h"
#include "tLinkedList.h"
#include "tCallback.h"
#include "nObserver.h"
#include "tException.h"
#include <memory>
Go to the source code of this file.
Classes | |
class | nKillHim |
class | nIgnore |
class | nVersion |
class | nVersionFeature |
class | nSendBuffer |
class | nBandwidthControl |
class | nAverager |
class responsible for calculating averages More... | |
class | nPingAverager |
averager for pings, detects lag More... | |
struct | nConnectionInfo |
class | nDescriptor |
class | nMessage |
class | nWaitForAck |
class | nCallbackLoginLogout |
class | nCallbackAcceptPackedWithoutConnection |
class | nCallbackReceivedComplete |
class | nCurrentSenderID |
class | nMachineDecorator |
a decorator for machines for additional information to attach to them More... | |
class | nMachine |
class trying to collect information about a certain client, persistent between connections More... | |
class | nSocketResetInhibitor |
while an object of this class exists, the main network sockets won't get reopened More... | |
Defines | |
#define | MAXCLIENTS 16 |
#define | NET_ID_FIRST 100 |
Typedefs | |
typedef double | nTimeAbsolute |
typedef double | nTimeRolling |
typedef void | nHandler (nMessage &m) |
Enumerations | |
enum | nNetState { nSTANDALONE, nSERVER, nCLIENT } |
enum | nConnectError { nOK, nTIMEOUT, nDENIED, nABORT } |
enum | nLoginType { Login_Pre0252, Login_Post0252, Login_All } |
Functions | |
void | nReadError (bool critical=true) |
nConnectError | sn_GetLastError () |
nNetState | sn_GetNetState () |
void | sn_SetNetState (nNetState x) |
void | sn_DisconnectUser (int i, const tOutput &reason, nServerInfoBase *redirectTo=0) |
terminate connection with user i (peacefully) | |
void | sn_KickUser (int i, const tOutput &reason, REAL severity=1, nServerInfoBase *redirectTo=0) |
throw out user i (violently) | |
void | sn_GetAdr (int user, tString &name) |
unsigned int | sn_GetPort (int user) |
unsigned int | sn_GetServerPort () |
int | sn_NumUsers () |
int | sn_MaxUsers () |
int | sn_MessagesPending (int user) |
nMessage & | operator>> (nMessage &m, nVersion &ver) |
nMessage & | operator<< (nMessage &m, const nVersion &ver) |
std::istream & | operator>> (std::istream &s, nVersion &ver) |
std::ostream & | operator<< (std::ostream &s, const nVersion &ver) |
const nVersion & | sn_MyVersion () |
the version this progam maximally supports | |
const nVersion & | sn_CurrentVersion () |
the version currently supported by all connected players | |
void | sn_UpdateCurrentVersion () |
updates the sn_CurrentVersion() | |
std::istream & | operator>> (std::istream &stream, nAverager &averager) |
read operator for nAveragers | |
std::ostream & | operator<< (std::ostream &stream, nAverager const &averager) |
write operator for nAveragers | |
nConnectError | sn_Connect (nAddress const &server, nLoginType loginType=Login_All, nSocket const *socket=NULL) |
void | sn_Bend (nAddress const &server) |
void | sn_Bend (tString const &server, unsigned int port) |
void | RequestInfoHandler (nHandler *handle) |
void | sn_Delay () |
pause a bit, abort pause on network activity | |
void | sn_Receive () |
void | sn_ReceiveFromControlSocket () |
void | sn_DiscardFromControlSocket () |
void | sn_Sync (REAL timeout, bool sync_sn_netObjects=false, bool otherEnd=true) |
void | sn_ConsoleOut (const tOutput &message, int client=-1) |
nMessage * | sn_ConsoleOutMessage (const tOutput &message) |
void | sn_CenterMessage (const tOutput &message, int client=-1) |
void | sn_SendPlanned () |
int | sn_QueueLen (int user) |
void | sn_Statistics () |
tString const & | sn_GetMyAddress () |
return the public IP address and port of this machine, or "*.*.*.*:*" if it is unknown.. | |
bool | sn_IsLANAddress (tString const &address) |
checks wheter a given address is on the user's LAN (or on loopback). | |
std::auto_ptr< nServerInfoBase > | sn_GetRedirectTo () |
nServerInfoBase * | sn_PeekRedirectTo () |
Variables | |
nBasicNetworkSystem | sn_BasicNetworkSystem |
tString | sn_bigBrotherString |
tString | sn_programVersion |
tString | sn_serverName |
unsigned int | sn_serverPort |
const unsigned int | sn_defaultPort |
int | sn_defaultDelay |
tString | sn_DenyReason |
int | sn_maxRateIn |
int | sn_maxRateOut |
nConnectionInfo | sn_Connections [MAXCLIENTS+2] |
int | sn_maxNoAck |
int | sn_myNetID |
#define MAXCLIENTS 16 |
Definition at line 103 of file nNetwork.h.
Referenced by eVoteItem::AcceptNewVote(), nServerLag::Balance(), nNetObject::ClearAllDeleted(), nNetObject::ClearKnows(), eLag::Credit(), nNetObject::DoBroadcastExistence(), eVoteItemKick::DoExecute(), eVoteItem::Evaluate(), id_req_handler(), kill_id_hog(), login_callback(), eVoteItem::ReBroadcast(), nNetObject::RelabelOnConnect(), eLag::Report(), nNetObject::RequestSync(), nServerInfo::RunMaster(), se_BroadcastChat(), se_BroadcastChatLine(), se_ReadUser(), se_sendEventNotification(), nServerLag::SetClient(), sg_FullscreenMessage(), sn_GetTimeout(), sn_Sync(), gGame::StateUpdate(), nNetObject::SyncAll(), gGame::SyncState(), eLag::TakeCredit(), nNetObject::~nNetObject(), and nServerInfo::~nServerInfo().
#define NET_ID_FIRST 100 |
Definition at line 410 of file nNetwork.h.
Definition at line 378 of file nNetwork.h.
typedef double nTimeAbsolute |
Definition at line 50 of file nNetwork.h.
typedef double nTimeRolling |
Definition at line 53 of file nNetwork.h.
enum nConnectError |
enum nLoginType |
Definition at line 358 of file nNetwork.h.
00359 { 00360 Login_Pre0252, // use the login method known to pre-0.2.5.2 versions 00361 Login_Post0252, // use the newer login method 00362 Login_All // first attempt the new one, then the old one 00363 };
enum nNetState |
void nReadError | ( | bool | critical = true |
) |
Definition at line 2792 of file nNetwork.cpp.
References con.
Referenced by nNOInitialisator< T >::Init(), login_accept_handler(), nNetObject::Object(), nMessage::Read(), nNetObject::Register(), and nConfItemBase::s_GetConfigMessage().
02795 { 02796 // st_Breakpoint(); 02797 #ifndef NOEXCEPT 02798 if ( critical ) 02799 throw nKillHim(); 02800 else 02801 throw nIgnore(); 02802 #else 02803 con << "\nI told you not to use PGCC! Now we need to leave the\n" 02804 << "system in an undefined state. The progam will crash now.\n"
std::ostream& operator<< | ( | std::ostream & | stream, | |
nAverager const & | averager | |||
) |
write operator for nAveragers
stream | stream to write to | |
averager | averager to write |
Definition at line 3813 of file nNetwork.cpp.
std::ostream& operator<< | ( | std::ostream & | s, | |
const nVersion & | ver | |||
) |
std::istream& operator>> | ( | std::istream & | stream, | |
nAverager & | averager | |||
) |
read operator for nAveragers
stream | stream to read to | |
averager | averager to read |
Definition at line 3796 of file nNetwork.cpp.
std::istream& operator>> | ( | std::istream & | s, | |
nVersion & | ver | |||
) |
Definition at line 323 of file nNetwork.cpp.
00326 { 00327 int min,max; 00328 s >> min; 00329 s >> max; 00330 00331 ver = nVersion( min, max ); 00332
Definition at line 304 of file nNetwork.cpp.
00307 { 00308 int min,max; 00309 m >> min; 00310 m >> max; 00311 00312 ver = nVersion( min, max ); 00313
void RequestInfoHandler | ( | nHandler * | handle | ) |
void sn_Bend | ( | tString const & | server, | |
unsigned int | port | |||
) |
Definition at line 2623 of file nNetwork.cpp.
02626 { 02627 // fill address info 02628 nAddress address; 02629 address.SetHostname( server ); 02630 address.SetPort( port ); 02631 02632 // delegate
void sn_Bend | ( | nAddress const & | server | ) |
Definition at line 2615 of file nNetwork.cpp.
References nCLIENT, nSTANDALONE, sn_GetNetState(), and sn_SetNetState().
Referenced by nServerInfo::NetReadThis(), and nServerInfo::QueryServer().
02618 { 02619 if ((sn_GetNetState() == nSTANDALONE)) 02620 sn_SetNetState(nCLIENT); 02621
void sn_CenterMessage | ( | const tOutput & | message, | |
int | client = -1 | |||
) |
Definition at line 2911 of file nNetwork.cpp.
Referenced by gGame::Analysis(), StartNewMatch(), gGame::StateUpdate(), and update_settings().
02914 { 02915 tString message(o); 02916 02917 tJUST_CONTROLLED_PTR< nMessage > m=new nMessage(client_cen_nd); 02918 *m << message; 02919 if (client<0){ 02920 m->BroadCast(); 02921 con.CenterDisplay(message); 02922 } 02923 else if (client==sn_myNetID) 02924 con.CenterDisplay(message);
nConnectError sn_Connect | ( | nAddress const & | server, | |
nLoginType | loginType = Login_All , |
|||
nSocket const * | socket = NULL | |||
) |
Definition at line 2634 of file nNetwork.cpp.
Referenced by client(), nServerInfoBase::Connect(), and ntest().
02636 { 02637 sn_DenyReason = ""; 02638 02639 // reset redirection 02640 sn_redirectTo.release(); 02641 02642 // pings in the beginning of the login are not really representative 02643 nPingAverager::SetWeight(.0001); 02644 02645 // net_hostport = sn_clientPort; 02646 02647 sn_SetNetState(nSTANDALONE); 02648 sn_SetNetState(nCLIENT); 02649 02650 // set user requested socket 02651 if ( socket ) 02652 sn_Connections[0].socket = socket; 02653 02654 sn_Connections[0].ping.Reset(); 02655 02656 peers[0] = server; 02657 02658 reset_last_acks(0); 02659 nCallbackLoginLogout::UserLoggedOut(0); 02660 sn_Connections[0].sendBuffer_.Clear(); 02661 02662 tASSERT( sn_Connections[0].socket ); 02663 02664 // sn_Connections[0].socket->Connect( peers[0] ); // useless 02665 sn_Connections[0].bandwidthControl_.SetRate( sn_maxRateOut ); 02666 02667 sn_myNetID=0; // MAXCLIENTS+1; // reset network id 02668 02669 // first, get all pending messages 02670 sn_Receive(); 02671 sn_Receive(); 02672 sn_Receive(); 02673 02674 // reset version control until the true value is given by the server. 02675 sn_currentVersion = nVersion(0,0); 02676 02677 // Login stuff..... 02678 tJUST_CONTROLLED_PTR< nMessage > mess; 02679 if ( loginType != Login_Pre0252 ) 02680 { 02681 mess=new nMessage(login_2); 02682 mess->Write(sn_maxRateIn); 02683 02684 unsigned short bb = big_brother; 02685 mess->Write( bb ); 02686 if ( bb ){ 02687 (*mess) << sn_bigBrotherString; 02688 big_brother=false; 02689 } 02690 } 02691 else 02692 { 02693 mess=new nMessage(login); 02694 mess->Write(sn_maxRateIn); 02695 02696 // send (worthless) big brother string 02697 if (big_brother) 02698 { 02699 (*mess) << sn_bigBrotherString; 02700 } 02701 else 02702 { 02703 (*mess) << tString(""); 02704 } 02705 02706 big_brother=false; 02707 } 02708 02709 // write our version 02710 (*mess) << sn_MyVersion(); 02711 02712 // write our supported authentication methods 02713 (*mess) << nKrawall::nMethod::SupportedMethods(); 02714 02715 // write a random salt 02716 nKrawall::RandomSalt( loginSalt ); 02717 nKrawall::WriteScrambledPassword( loginSalt, *mess ); 02718 02719 mess->ClearMessageID(); 02720 mess->SendImmediately(0,false); 02721 nMessage::SendCollected(0); 02722 02723 con << tOutput("$network_login_process"); 02724 02725 login_failed=false; 02726 login_succeeded=false; 02727 02728 nTimeRolling timeout=tSysTimeFloat()+5; 02729 02730 static REAL resend = .25; 02731 nTimeAbsolute nextSend = tSysTimeFloat() + resend/5; 02732 while(sn_GetNetState()==nCLIENT && tSysTimeFloat()<timeout && 02733 !login_failed && !login_succeeded){ 02734 if ( tSysTimeFloat() > nextSend ) 02735 { 02736 // con << "retrying...\n"; 02737 nextSend = tSysTimeFloat() + resend; 02738 mess->SendImmediately(0,false); 02739 nMessage::SendCollected(0); 02740 } 02741 02742 tAdvanceFrame(10000); 02743 sn_Receive(); 02744 sn_SendPlanned(); 02745 02746 // check for user abort 02747 if ( tConsole::Idle() ) 02748 { 02749 con << tOutput("$network_login_failed_abort"); 02750 sn_SetNetState(nSTANDALONE); 02751 return nABORT; 02752 } 02753 } 02754 if (login_failed) 02755 { 02756 con << tOutput("$network_login_failed"); 02757 sn_SetNetState(nSTANDALONE); 02758 return nDENIED; 02759 } 02760 else if (tSysTimeFloat()>=timeout || sn_GetNetState()!=nCLIENT){ 02761 if ( loginType == Login_All ) 02762 { 02763 return sn_Connect( server, Login_Pre0252, socket ); 02764 } 02765 else 02766 { 02767 con << tOutput("$network_login_failed_timeout"); 02768 sn_SetNetState(nSTANDALONE); 02769 return nTIMEOUT; 02770 } 02771 } 02772 else{ 02773 nCallbackLoginLogout::UserLoggedIn(0); 02774 02775 tOutput mess; 02776 mess.SetTemplateParameter(1, sn_myNetID); 02777 mess << "$network_login_success"; 02778 con << mess; 02779 con << tOutput("$network_login_sync"); 02780 sn_Sync(40); 02781 con << tOutput("$network_login_relabeling"); 02782 con << tOutput("$network_login_sync2"); 02783 sn_Sync(40,true); 02784 con << tOutput("$network_login_done"); 02785 02786 // marginalize past ping values 02787 nPingAverager::SetWeight(1); 02788 02789 return nOK;
void sn_ConsoleOut | ( | const tOutput & | message, | |
int | client = -1 | |||
) |
Definition at line 2883 of file nNetwork.cpp.
Referenced by eVoteItem::AcceptNewVote(), eTeam::AddPlayer(), eTeam::AddScore(), ePlayerNetID::AddScore(), gGame::Analysis(), eVoteItem::BroadcastMessage(), eChatSpamTester::Check(), nSpamProtection::CheckSpam(), eVoteItem::CheckValid(), ePlayerNetID::CreateNewTeam(), eVoteItemKick::DoCheckValid(), eVoteItemHarm::DoCheckValid(), ePlayerNetID::FindPlayerByName(), eVoteItem::GetControlMessage(), eVoter::GetVoter(), eVoter::HandleChat(), nDescriptor::HandleMessage(), eTeam::Invite(), IsSilencedWithWarning(), gCycle::KillAt(), gBaseZoneHack::OnVanish(), eVoteItem::ReBroadcast(), ePlayerNetID::ReceiveControlNet(), eTeam::RemovePlayer(), se_CancelAllVotes(), se_ChatMe(), se_ChatMsg(), se_ChatShuffle(), se_ChatTeam(), se_ChatTeamLeave(), se_FindPlayerInChatCommand(), se_LoginWanted(), se_rubyEval(), se_SendTo(), eTeam::SetLocked(), ePlayerNetID::SetTeam(), ePlayerNetID::SetTeamWish(), sg_CreateWinDeathZone(), sg_FullscreenMessage(), sg_TopologyPoliceKill(), eTeam::Shuffle(), StartNewMatch(), gGame::StateUpdate(), ePlayerNetID::Suspend(), ePlayerNetID::TeamChangeAllowed(), gBaseZoneHack::Timestep(), eTeam::UnInvite(), ePlayerNetID::Update(), update_settings(), eTeam::UpdateAppearance(), ePlayerNetID::UpdateName(), ePlayerNetID::UpdateTeam(), and ePlayerNetID::WaitToLeaveChat().
02886 { 02887 // tString message(o); 02888 02889 tJUST_CONTROLLED_PTR< nMessage > m = sn_ConsoleOutMessage( o ); 02890 02891 if (client<0){ 02892 m->BroadCast(); 02893 con << o; 02894 } 02895 else if (client==sn_myNetID) 02896 { 02897 con << o; 02898 }
Definition at line 2859 of file nNetwork.cpp.
Referenced by se_OldChatMessage().
02863 { 02864 tString message(o); 02865 message << "0xffffff"; 02866 02867 // truncate message to 1.4K, a safe size for all UDP packets 02868 static const int maxLen = 1400; 02869 static bool recurse = true; 02870 if ( message.Len() > maxLen && recurse ) 02871 { 02872 recurse = false; 02873 tERR_WARN( "Long console message truncated."); 02874 02875 message.SetLen( maxLen+1 ); 02876 message[maxLen]='\0'; 02877 recurse = false; 02878 } 02879 02880 nMessage* m=new nMessage(sn_ConsoleOut_nd); 02881 *m << message;
const nVersion& sn_CurrentVersion | ( | ) |
the version currently supported by all connected players
Definition at line 240 of file nNetwork.cpp.
Referenced by nServerInfo::DoGetFrom(), and nConfItemVersionWatcher::DoWritable().
void sn_Delay | ( | ) |
pause a bit, abort pause on network activity
Definition at line 134 of file nNetwork.cpp.
Referenced by ConnectToServerCore(), gGame::NetSyncIdle(), and sn_Sync().
00136 { 00137 sn_BasicNetworkSystem.Select( sn_defaultDelay / 1000000.0 ); 00138 tAdvanceFrame();
void sn_DiscardFromControlSocket | ( | ) |
Definition at line 2440 of file nNetwork.cpp.
References nSocket::Read(), and nConnectionInfo::socket.
Referenced by sg_Receive().
02443 { 02444 // new facts: pending incoming data on the control socket causes the idle loops 02445 // to use 100% CPU time, we need to fetch and discard the data instead of ignoring it. 02446 if ( sn_Connections[0].socket ) 02447 { 02448 int8 buff[2]; 02449 nAddress addrFrom; 02450 sn_Connections[0].socket->Read( reinterpret_cast<int8 *>(buff),0, addrFrom);
void sn_DisconnectUser | ( | int | i, | |
const tOutput & | reason, | |||
nServerInfoBase * | redirectTo = 0 | |||
) |
terminate connection with user i (peacefully)
Definition at line 3167 of file nNetwork.cpp.
Referenced by Cheater(), nDescriptor::HandleMessage(), kill_id_hog(), logout_handler(), ePlayerNetID::MyInitAfterCreation(), rec_peer(), req_info_handler(), and nServerInfo::RunMaster().
03171 { 03172 // don't be daft and kill yourself, server! 03173 if ( i == 0 && sn_GetNetState() == nSERVER ) 03174 { 03175 tERR_WARN( "Server tried to disconnect from itself." ); 03176 return; 03177 } 03178 03179 // clients can only disconnect from the server 03180 if ( i != 0 && sn_GetNetState() == nCLIENT ) 03181 { 03182 tERR_ERROR( "Client tried to disconnect from another client: impossible and a bad idea." ); 03183 return; 03184 } 03185 03186 // anything to do at all? 03187 if (!sn_Connections[i].socket) 03188 { 03189 return; 03190 }
void sn_GetAdr | ( | int | user, | |
tString & | name | |||
) |
Definition at line 3424 of file nNetwork.cpp.
Referenced by FinishHandlePasswordRequest(), GetSenderData(), nServerInfo::GiveSmallServerInfo(), and nServerInfoBase::NetReadThis().
nConnectError sn_GetLastError | ( | ) |
Definition at line 457 of file nNetwork.cpp.
References nOK.
Referenced by ConnectToServerCore().
00460 { 00461 nConnectError ret = sn_Error; 00462 sn_Error = nOK;
tString const& sn_GetMyAddress | ( | ) |
return the public IP address and port of this machine, or "*.*.*.*:*" if it is unknown..
Definition at line 64 of file nNetwork.cpp.
nNetState sn_GetNetState | ( | ) |
Definition at line 2453 of file nNetwork.cpp.
Referenced by eVoteItem::AcceptNewVote(), gCycle::Act(), gNetPlayerWall::ActionOnQuit(), gCycle::ActionOnQuit(), Activate(), gCycleChatBot::Activate(), nConfItemVersionWatcher::AdaptVersion(), gCycleMovement::AddDestination(), eTeam::AddPlayer(), eTeam::AddScore(), gEnemyInfluence::AddSensor(), gEnemyInfluence::AddWall(), gGame::Analysis(), blocks(), gNetPlayerWall::BlowHole(), nMessage::BroadCast(), eVoteItem::BroadcastMessage(), gCycleMovement::CalculateAcceleration(), eVoteItem::CheckValid(), client(), ConnectToServerCore(), gCycleMovement::CopyFrom(), gNetPlayerWall::CopyIntoGrid(), ePlayerNetID::CreateNewTeam(), ePlayerNetID::CreateNewTeamWish(), ePlayerNetID::CreateVoter(), eLag::Credit(), gCycle::Die(), nNetObject::DoBroadcastExistence(), eVoteItemKick::DoCheckValid(), eVoteItemHarm::DoCheckValid(), eVoteItemHarmServerControlled::DoFillFromMessage(), eVoteItem::DoFillFromMessage(), eVoteItemHarmServerControlled::DoFillToMessage(), eVoteItem::DoFillToMessage(), gCycle::DoTurn(), ePlayerNetID::Enemies(), eNetGameObject::eNetGameObject(), eTeam::Enforce(), eMenuItemKick::Enter(), eTimer::eTimer(), eVoteItemServerControlled::Evaluate(), eVoteItem::Evaluate(), exit_game_objects(), eVoteItem::FillFromMessage(), eGameObject::FindCurrentFace(), first_fill_ids(), GameLoop(), gGame::GameLoop(), nServerInfo::GetBigServerInfoMaster(), eVoteItem::GetControlMessage(), nServerInfo::GetFromLAN(), nServerInfo::GetFromLANContinuously(), nServerInfo::GetFromMaster(), gGame::gGame(), gNetPlayerWall::gNetPlayerWall(), handle_chat_client(), nAuthentication::HandlePasswordRequest(), id_req_handler(), ingame_menu_cleanup(), nNOInitialisator< T >::Init(), init_game_camera(), init_game_objects(), eVoter::IsSpamming(), eTimer::IsSynced(), gCycle::Kill(), gCycle::KillAt(), eNetGameObject::LagThreshold(), ePlayer::LogIn(), login_accept_handler(), login_callback(), login_ignore_handler(), LoginLogout(), MainMenu(), gCamera::MyInit(), gCycle::MyInitAfterCreation(), ePlayerNetID::MyInitAfterCreation(), net_clear_handler(), net_control_handler(), net_sync_handler(), new_destination_handler(), next_free(), next_free_server_nokill(), nNetObject::nNetObject(), gGame::NoLongerGoOn(), ntest(), nWaitForAck::nWaitForAck(), nNetObject::Object(), gCycleMovement::OnNotifyNewDestination(), gCycle::OnNotifyNewDestination(), gCycle::OnRemoveFromGame(), nConfItemVersionWatcher::OnVersionChange(), gParser::parseSetting(), gParser::parseZoneArthemis_v1(), gCycle::PassEdge(), eTimer::pause(), eTeam::PlayerMayJoin(), nNetObject::ReadSync(), eTeam::ReadSync(), eVoteItem::ReBroadcast(), rec_peer(), eNetGameObject::ReceiveControl(), nNetObject::ReceiveControlNet(), nNetObject::Register(), nNetObject::RelabelOnConnect(), ePlayerNetID::RemoveChatbots(), eTeam::RemovePlayer(), gCycle::Render(), req_id_handler(), nNetObject::RequestSync(), gCycle::RequestSyncAll(), gCycle::RequestSyncOwner(), eTimer::Reset(), eTeam::ResetScore(), gAIPlayer::RightBeforeDeath(), nConfItemBase::s_GetConfigMessage(), nConfItemBase::s_SendConfig(), se_CancelAllVotes(), se_GetPing(), se_HandleNewServerVote(), se_NeedsServer(), se_OptionalNameFilters(), se_PauseGameTimer(), se_receiveLagMessage(), se_rubyEval(), se_WantLogin(), nMessage::Send(), ePlayer::SendAuthNames(), nConfItemBase::SendConfig(), eNetGameObject::SendControl(), nMessage::SendImmediately(), server(), ePlayerNetID::SetChatting(), zShape::setColor(), ePlayerNetID::SetDefaultTeam(), ePlayerNetID::SetName(), eNetGameObject::SetPlayer(), zShape::setRotation2(), eTeam::SetScore(), gGame::SetState(), ePlayerNetID::SetTeam(), ePlayerNetID::SetTeamWish(), sg_Deprecated(), sg_DropTempWall(), sg_KillFutureWalls(), sg_ParseMap(), sg_Receive(), sg_RespawnPlayer(), sg_TopologyPoliceKill(), sg_UseAntiLagSliding(), sn_Bend(), sn_ConsoleOut_handler(), sn_Sync(), eVoter::Spam(), StartNewMatch(), gGame::StateUpdate(), sync_msg_handler(), nNetObject::SyncAll(), gCycle::SyncEnemy(), gGame::SyncState(), eTimer::SyncTime(), nServerInfo::TellMasterAboutMe(), gAIPlayer::ThinkCloseCombat(), gBaseZoneHack::Timestep(), gCycleMovement::Timestep(), gCycle::Timestep(), eNetGameObject::Timestep(), gCycleMovement::TimestepCore(), gCycle::TimestepCore(), eGameObject::TimestepThis(), eGameObject::TimestepThisWrapper(), gNetPlayerWall::Update(), ePlayerNetID::Update(), update_settings(), eTeam::UpdateAppearance(), ePlayerNetID::UpdateName(), eTeam::UpdateProperties(), ePlayerNetID::UpdateTeam(), eVoter::VotingPossible(), nConfItemBase::Writable(), nNetObject::WriteSync(), eVoteItemServerControlled::~eVoteItemServerControlled(), and nNetObject::~nNetObject().
unsigned int sn_GetPort | ( | int | user | ) |
Definition at line 3429 of file nNetwork.cpp.
Referenced by GetSenderData(), and nServerInfo::GiveSmallServerInfo().
std::auto_ptr< nServerInfoBase > sn_GetRedirectTo | ( | ) |
Definition at line 1376 of file nNetwork.cpp.
Referenced by ConnectToServer().
unsigned int sn_GetServerPort | ( | ) |
Definition at line 3434 of file nNetwork.cpp.
Referenced by nServerInfoBase::DoGetFrom(), and nServerInfo::TellMasterAboutMe().
bool sn_IsLANAddress | ( | tString const & | address | ) |
checks wheter a given address is on the user's LAN (or on loopback).
Definition at line 70 of file nNetwork.cpp.
Referenced by login_accept_handler().
00072 { 00073 if ( address.StartsWith("127.") || address.StartsWith("10.") || address.StartsWith("192.168.") ) 00074 { 00075 // easy LANs. Accept the client sent IP, we don't know our own LAN address. 00076 return true; 00077 } 00078 00079 if( address.StartsWith( "172." ) && address[6] == '.' ) 00080 { 00081 // more complicated LAN :) 00082 int second = address.SubStr(4,2).ToInt(); 00083 if ( 16 <= second && second < 32 ) 00084 { 00085 return true; 00086 } 00087 } 00088 00089 return false;
void sn_KickUser | ( | int | i, | |
const tOutput & | reason, | |||
REAL | severity = 1 , |
|||
nServerInfoBase * | redirectTo = 0 | |||
) |
throw out user i (violently)
Definition at line 3152 of file nNetwork.cpp.
Referenced by nSpamProtection::CheckSpam(), ePlayerNetID::RemoveChatbots(), and se_VoteKickUser().
03156 { 03157 // print it 03158 con << tOutput( "$network_kill_log", i, reason ); 03159 03160 // log it 03161 if ( severity > 0 ) 03162 { 03163 nMachine::GetMachine(i).OnKick( severity ); 03164 } 03165
int sn_MaxUsers | ( | ) |
Definition at line 3463 of file nNetwork.cpp.
Referenced by nServerInfo::DoGetFrom().
int sn_MessagesPending | ( | int | user | ) |
Definition at line 3468 of file nNetwork.cpp.
Referenced by client(), and nServerInfo::RunMaster().
const nVersion& sn_MyVersion | ( | ) |
the version this progam maximally supports
Definition at line 235 of file nNetwork.cpp.
Referenced by nServerInfo::CalcScore(), nServerInfo::Compatibility(), and nConfItemVersionWatcher::OnVersionChange().
int sn_NumUsers | ( | ) |
nServerInfoBase* sn_PeekRedirectTo | ( | ) |
Definition at line 1381 of file nNetwork.cpp.
Referenced by sg_NetworkError().
int sn_QueueLen | ( | int | user | ) |
Definition at line 3268 of file nNetwork.cpp.
Referenced by sn_Sync().
void sn_Receive | ( | ) |
Definition at line 3092 of file nNetwork.cpp.
Referenced by client(), nServerInfo::DoQueryAll(), nServerInfo::GetFromLAN(), nServerInfo::GetFromMaster(), main(), next_free(), ntest(), nNetObject::Object(), gBrowserMenuItem::RenderBackground(), nServerInfo::RunMaster(), server(), sg_Receive(), sn_Sync(), and nServerInfo::TellMasterAboutMe().
03095 { 03096 /* 03097 static bool reentry=false; 03098 if (reentry) 03099 return; 03100 reentry=true; 03101 */ 03102 03103 netTime=tSysTimeFloat(); 03104 // new_id=0; 03105 sn_Connections[MAXCLIENTS+1].ping.Reset(); 03106 03107 // create the ack messages (not required, is done on demand later) 03108 /* 03109 int i; 03110 for(i=0;i<=MAXCLIENTS+1;i++) 03111 if(sn_Connections[i].ackMess==NULL) 03112 sn_Connections[i].ackMess=new nAckMessage(); 03113 */ 03114 03115 03116 switch (current_state){ 03117 case nSERVER: 03118 { 03119 memset( &peers[0], 0, sizeof(sockaddr) ); 03120 03121 // listen on all sockets 03122 nSocketListener const & listener = sn_BasicNetworkSystem.GetListener(); 03123 for ( nSocketListener::iterator i = listener.begin(); i != listener.end(); ++i ) 03124 { 03125 // clear peer info used for receiving 03126 memset( &peers[MAXCLIENTS+1], 0, sizeof(sockaddr) ); 03127 03128 if((sn_Connections[MAXCLIENTS+1].socket = (*i).CheckNewConnection() ) != NULL) 03129 rec_peer(MAXCLIENTS+1); 03130 } 03131 } 03132 // z-man: after much thought, the server does also need to listen to the 03133 // network control socket. .... Thinking again, it's only important for the master 03134 // servers, and they call rec_peer(0) separately. 03135 break; 03136 03137 case nCLIENT: 03138 rec_peer(0); 03139 break; 03140 03141 case nSTANDALONE: 03142 default: 03143 break; 03144 } 03145 03146 /* 03147 // scedule regular messages 03148 REAL dt = sn_SendPlanned1(); 03149 03150 // actually resend messages
void sn_ReceiveFromControlSocket | ( | ) |
Definition at line 2434 of file nNetwork.cpp.
References rec_peer().
Referenced by main().
void sn_SendPlanned | ( | ) |
Definition at line 3070 of file nNetwork.cpp.
Referenced by client(), ConnectToServerCore(), nServerInfo::DoQueryAll(), gGame::GameLoop(), nServerInfo::GetFromLAN(), nServerInfo::GetFromMaster(), main(), gGame::NetSync(), next_free(), ntest(), nNetObject::Object(), gBrowserMenuItem::RenderBackground(), nServerInfo::RunMaster(), server(), sn_Sync(), and nServerInfo::TellMasterAboutMe().
03074 { 03075 // propagate messages to buffers 03076 REAL dt = sn_SendPlanned1(); 03077 03078 // schedule the acks: send them if it's possible (bandwith limit) or if there already is a packet in the pipe. 03079 for(int i=0;i<=MAXCLIENTS+1;i++) 03080 if(sn_Connections[i].socket && sn_Connections[i].ackMess && !sn_Connections[i].ackMess->End() 03081 // && sn_ackAckPending[i] <= 1+sn_Connections[].ackMess[i]->DataLen() 03082 && ( sn_Connections[i].bandwidthControl_.CanSend() || sn_Connections[i].sendBuffer_.Len() > 0 ) 03083 ){ 03084 sn_Connections[i].ackMess->SendImmediately(i, false); 03085 sn_Connections[i].ackMess=NULL; 03086 } 03087 03088 // schedule lost messages for resending 03089 nWaitForAck::Resend(); 03090
void sn_SetNetState | ( | nNetState | x | ) |
Definition at line 2529 of file nNetwork.cpp.
Referenced by client(), ConnectToServerCore(), nServerInfo::GetFromLAN(), nServerInfo::GetFromLANContinuously(), nServerInfo::GetFromLANContinuouslyStop(), nServerInfo::GetFromMaster(), main(), ntest(), Poll(), ret_to_MainMenu(), server(), sg_HostGame(), singlePlayer_game(), sn_Bend(), and nServerInfo::TellMasterAboutMe().
02531 { 02532 static bool reentry=false; 02533 if(!reentry && x!=current_state){ 02534 sn_UpdateCurrentVersion(); 02535 02536 //if (x == nSERVER) 02537 unsigned int net_hostport = sn_serverPort; 02538 02539 // save/load machines on entering/leaving server mode 02540 if ( x == nSERVER ) 02541 sn_LoadMachines(); 02542 else if ( current_state == nSERVER ) 02543 if ( !tRecorder::IsPlayingBack() ) 02544 sn_SaveMachines(); 02545 02546 reentry=true; 02547 if (x!=nSTANDALONE) 02548 { 02549 if (x==nCLIENT) 02550 { 02551 sn_DisconnectAll(); 02552 } 02553 else 02554 { 02555 sn_myNetID=0; 02556 } 02557 02558 if (!sn_Connections[0].socket) 02559 sn_Connections[0].socket=sn_BasicNetworkSystem.Init(); 02560 // bool success = true; 02561 if (x == nSERVER) 02562 { 02563 // bool success = 02564 sn_Listen( net_hostport, net_hostip ) || // first try: do it according to user specs 02565 sn_Listen( net_hostport, tString( "ANY" ) ) || // second try: bind to generic IP 02566 sn_Listen( net_hostport, tString( "ALL" ) ); // last try: bind to all available IPs 02567 02568 #ifdef DEDICATED 02569 // save host port that worked, otherwise it may change from the port sent to the master server 02570 sn_serverPort = net_hostport; 02571 #endif 02572 } 02573 } 02574 else 02575 { 02576 clear_owners(); 02577 for(int i=MAXCLIENTS+1;i>=0;i--){ 02578 if(sn_Connections[i].socket){ 02579 if (i==0 && current_state!=nSERVER) 02580 { // logout: fire and forget 02581 con << tOutput("$network_logout_process"); 02582 for(int j=3;j>=0;j--){ // just to make sure 02583 nMessage *lo=new nMessage(logout); 02584 lo->Write(static_cast<unsigned short>(sn_myNetID)); 02585 lo->ClearMessageID(); 02586 lo->SendImmediately(0, false); 02587 nMessage::SendCollected(0); 02588 tDelay(1000); 02589 } 02590 con << tOutput("$network_logout_done"); 02591 02592 sn_myNetID=0; // MAXCLIENTS+1; // reset network id 02593 } 02594 } 02595 sn_DisconnectUserNoWarn(i, "$network_kill_shutdown"); 02596 } 02597 02598 sn_Connections[0].socket = 0; 02599 02600 // shutdown network system to get new socket 02601 if ( !sn_noReset ) 02602 sn_BasicNetworkSystem.Shutdown(); 02603 } 02604 02605 current_state=x; 02606 reentry=false; 02607 } 02608
void sn_Statistics | ( | ) |
Definition at line 3340 of file nNetwork.cpp.
References con, dt, REAL, tOutput::SetTemplateParameter(), and tSysTimeFloat().
Referenced by gGame::StateUpdate().
03344 { 03345 nTimeRolling time = tSysTimeFloat(); 03346 REAL dt = time - sn_StatsTime; 03347 sn_StatsTime = time; 03348 03349 if (dt > 0 && (sn_SentPackets || sn_SentBytes)) 03350 { 03351 tOutput o; 03352 o.SetTemplateParameter(1,dt); 03353 o.SetTemplateParameter(2,sn_SentBytes); 03354 o.SetTemplateParameter(3,sn_SentPackets); 03355 o.SetTemplateParameter(4,sn_SentBytes/dt); 03356 o.SetTemplateParameter(5,sn_ReceivedBytes); 03357 o.SetTemplateParameter(6,sn_ReceivedPackets); 03358 o.SetTemplateParameter(7,sn_ReceivedBytes/dt); 03359 o << "$network_statistics1"; 03360 o << "$network_statistics2"; 03361 o << "$network_statistics3"; 03362 03363 con << o; 03364 } 03365 03366 sn_SentPackets = 0; 03367 sn_SentBytes = 0;
void sn_Sync | ( | REAL | timeout, | |
bool | sync_sn_netObjects = false , |
|||
bool | otherEnd = true | |||
) |
Definition at line 1901 of file nNetObject.cpp.
References MAXCLIENTS, nCLIENT, nSERVER, nConnectionInfo::PacketLoss(), REAL, sn_Connections, sn_Delay(), sn_GetNetState(), sn_QueueLen(), sn_Receive(), sn_SendPlanned(), nVersionFeature::Supported(), sync_nd, nNetObject::SyncAll(), and tSysTimeFloat().
Referenced by gGame::StateUpdate(), sync_msg_handler(), and gGame::SyncState().
01901 { 01902 nTimeAbsolute endTime=timeout+tSysTimeFloat(); 01903 01904 #ifdef DEBUG 01905 //con << "Start sync...\n"; 01906 #endif 01907 01908 if (sn_GetNetState()==nCLIENT){ 01909 // repeat as often as packet loss suggests: of 100 packets, we want a single lost packet left probability of 1%. 01910 REAL failureProbability = 1; 01911 while ( failureProbability > .0001 && timeout > .01 ) 01912 { 01913 failureProbability *= sn_Connections[0].PacketLoss(); 01914 // con << failureProbability << "\n"; 01915 01916 // server responding to sync request message 01917 static nVersionFeature sg_ServerSync( 10 ); 01918 01919 // ask server when we're fully synced from his side 01920 sync_ack[0]=true; 01921 if ( sg_ServerSync.Supported( 0 ) && otherEnd ) 01922 { 01923 tJUST_CONTROLLED_PTR< nMessage > m=new nMessage(sync_nd); 01924 *m << timeout; 01925 m->Write(sync_sn_netObjects); 01926 m->Write(c_sync); 01927 m->Send(0); 01928 sync_ack[0]=false; 01929 } 01930 else 01931 { 01932 // repeating the procedure is useless anyway 01933 failureProbability = 0; 01934 } 01935 01936 // wait for all packets to be sent and the sync ack packet to be received 01937 while ( sn_Connections[0].socket && ( sync_ack[0] == false || sn_Connections[0].ackPending>0 || sn_QueueLen(0)) && 01938 tSysTimeFloat()<endTime){ 01939 sn_Delay(); 01940 sn_Receive(); 01941 if (sync_sn_netObjects) 01942 nNetObject::SyncAll(); 01943 sn_SendPlanned(); 01944 } 01945 01946 // decrease timeout for next try 01947 timeout *= .5; 01948 endTime=timeout+tSysTimeFloat(); 01949 } 01950 } 01951 else if (sn_GetNetState()==nSERVER){ 01952 for (int user=MAXCLIENTS;user>0;user--){ 01953 sync_ack[user]=false; 01954 if (sn_Connections[user].socket){ 01955 tJUST_CONTROLLED_PTR< nMessage > m=new nMessage(sync_nd); 01956 *m << timeout; 01957 m->Write(sync_sn_netObjects); 01958 m->Write(c_sync); 01959 m->Send(user); 01960 } 01961 } 01962 01963 bool goon=true; 01964 while (goon){ 01965 sn_Delay(); 01966 sn_Receive(); 01967 if (sync_sn_netObjects) 01968 nNetObject::SyncAll(); 01969 sn_SendPlanned(); 01970 01971 goon=false; 01972 for (int user=MAXCLIENTS;user>0;user--) 01973 { 01974 if (sn_Connections[user].socket && 01975 (!sync_ack[user] || sn_Connections[user].ackPending>0 || sn_QueueLen(user))) 01976 { 01977 goon=true; 01978 } 01979 } 01980 01981 if (tSysTimeFloat()>endTime) 01982 { 01983 goon=false; 01984 } 01985 } 01986 } 01987 01988 #ifdef DEBUG 01989 //con << "Stop sync.\n"; 01990 #endif 01991 }
void sn_UpdateCurrentVersion | ( | ) |
updates the sn_CurrentVersion()
Definition at line 393 of file nNetwork.cpp.
Referenced by nConfItemVersionWatcher::OnChange().
00396 { 00397 // update the current version from the native version and the versions of all attached clients 00398 00399 // allow maximally sn_MaxBackwardsCompatibility old versions to connect 00400 int min = sn_myVersion.Max() - sn_MaxBackwardsCompatibility; 00401 if ( min < sn_myVersion.Min() ) 00402 min = sn_myVersion.Min(); 00403 00404 // disable features that are too new 00405 int max = sn_myVersion.Max() - sn_newFeatureDelay; 00406 if ( max < min ) 00407 max = min; 00408 00409 nVersion version( min, max ); 00410 00411 // ask configuration if version is OK 00412 nConfItemVersionWatcher::AdaptVersion( version ); 00413 00414 nVersion maxVersion = version; 00415 00416 if ( sn_GetNetState() == nCLIENT ) 00417 { 00418 sn_currentVersion = version; 00419 return; 00420 } 00421 00422 for ( int i = MAXCLIENTS; i>0; --i ) 00423 { 00424 const nConnectionInfo& info = sn_Connections[i]; 00425 if ( info.socket ) 00426 { 00427 if ( ! version.Merge( version, info.version ) ) 00428 { 00429 // kick user; it has gotten incompatible. 00430 static bool recurse = true; 00431 if ( recurse ) 00432 { 00433 recurse = false; 00434 sn_DisconnectUser( i, "$network_kill_incompatible" ); 00435 recurse = true; 00436 } 00437 00438 version = maxVersion; 00439 } 00440 } 00441 } 00442 00443 // inform configuration of changes 00444 nConfItemVersionWatcher::OnVersionChange( version ); 00445 00446 if ( version != sn_currentVersion ) 00447 { 00448 sn_currentVersion = version; 00449 00450 nMessage* m = tNEW( nMessage )( versionControl ); 00451 (*m) << version; 00452 00453 m->BroadCast();
Definition at line 3473 of file nNetwork.cpp.
Referenced by main(), sg_HostGame(), sn_Listen(), nServerInfo::TellMasterAboutMe(), update_settings(), and gNetIdler::Wait().
nConnectionInfo sn_Connections[MAXCLIENTS+2] |
Definition at line 206 of file nNetwork.cpp.
Referenced by eVoteItem::AcceptNewVote(), nServerLag::Balance(), Cheater(), nNetObject::ClearAllDeleted(), gNetPlayerWall::CopyIntoGrid(), ePlayerNetID::CreateVoter(), nNetObject::DoBroadcastExistence(), ePlayerNetID::ePlayerNetID(), GameLoop(), nServerInfo::GetBigServerInfoCommon(), nServerInfo::GiveBigServerInfo(), nServerInfo::GiveSmallServerInfo(), next_free(), nNetObject::Object(), nServerLag::Ping(), eTimer::ReadSync(), ready_handler(), gNetPlayerWall::RealWallReceived(), eVoteItem::ReBroadcast(), nServerInfo::RunMaster(), se_BroadcastChat(), se_BroadcastChatLine(), se_GetPing(), se_ReadUser(), se_sendEventNotification(), sg_FullscreenMessage(), sn_GetTimeout(), sn_Sync(), gGame::StateUpdate(), nNetObject::SyncAll(), gGame::SyncState(), nServerInfo::TellMasterAboutMe(), gCycleMovement::TimestepCore(), and gCycle::TimestepCore().
int sn_defaultDelay |
const unsigned int sn_defaultPort |
Definition at line 115 of file nNetwork.cpp.
Definition at line 1433 of file nNetwork.cpp.
Referenced by ConnectToServerCore(), and sg_NetworkError().
int sn_maxNoAck |
int sn_maxRateIn |
int sn_maxRateOut |
int sn_myNetID |
Definition at line 491 of file nNetwork.cpp.
Referenced by nNetObject::ClearKnows(), nNetObject::DoBroadcastExistence(), gCycle::DoTurn(), gCycle::EdgeIsDangerous(), new_destination_handler(), nNetObject::nNetObject(), gCycleMovement::OnNotifyNewDestination(), gCycle::OnNotifyNewDestination(), nNetObject::Owner(), gCycle::ReadSync(), gNetPlayerWall::RealWallReceived(), nNetObject::RelabelOnConnect(), nNetObject::RequestSync(), se_ChatState(), se_GetLocalPlayer(), se_GetPing(), eNetGameObject::SendControl(), ePlayerNetID::SetTeamWish(), nNetObject::SyncAll(), gCycle::SyncEnemy(), eNetGameObject::SyncIsNew(), gCycle::Timestep(), eNetGameObject::Timestep(), ePlayerNetID::Update(), and nNetObject::~nNetObject().
Referenced by nServerInfo::DoGetFrom(), main(), and MainMenu().
Referenced by nServerInfo::DoGetFrom(), and sg_HostGameMenu().
unsigned int sn_serverPort |