OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Network2 Class Reference

#include <C4Network2.h>

Inheritance diagram for C4Network2:
[legend]
Collaboration diagram for C4Network2:
[legend]

Classes

class  InitialConnect
 

Public Types

enum  InitResult { IR_Success, IR_Error, IR_Fatal }
 

Public Member Functions

 C4Network2 ()
 
virtual ~C4Network2 ()
 
bool isEnabled () const
 
bool isLobbyActive () const
 
bool isPastLobby () const
 
bool isRunning () const
 
bool isPaused () const
 
bool isPausing () const
 
bool isHost () const
 
bool isStatusAck () const
 
bool isFrozen () const
 
bool isJoinAllowed () const
 
bool isObservingAllowed () const
 
class C4GameLobby::MainDlgGetLobby () const
 
const char * GetPassword () const
 
bool isPassworded () const
 
bool InitHost (bool fLobby)
 
InitResult InitClient (const class C4Network2Reference &Ref, bool fObserver)
 
InitResult InitClient (const std::vector< class C4Network2Address > &Addrs, const class C4ClientCore &HostCore, const char *szPassword=nullptr)
 
bool DoLobby ()
 
bool Start ()
 
bool Pause ()
 
bool Sync ()
 
bool FinalInit ()
 
bool RetrieveScenario (char *szScenario)
 
C4Network2Res::Ref RetrieveRes (const C4Network2ResCore &Core, int32_t iTimeout, const char *szResName, bool fWaitForCore=false)
 
void OnSec1Timer ()
 
void Execute ()
 
void Clear ()
 
bool ToggleAllowJoin ()
 
bool ToggleClientListDlg ()
 
void AllowJoin (bool fAllow)
 
void SetAllowObserve (bool fAllow)
 
void SetCtrlMode (int32_t iCtrlMode)
 
void SetPassword (const char *szToPassword)
 
StdStrBuf QueryClientPassword ()
 
void OnConn (C4Network2IOConnection *pConn)
 
void OnDisconn (C4Network2IOConnection *pConn)
 
void HandlePacket (char cStatus, const C4PacketBase *pBasePkt, C4Network2IOConnection *pConn)
 
void HandleLobbyPacket (char cStatus, const C4PacketBase *pBasePkt, C4Network2IOConnection *pConn)
 
bool HandlePuncherPacket (C4NetpuncherPacket::uptr, C4NetIO::HostAddress::AddressFamily family)
 
void OnPuncherConnect (C4NetIO::addr_t addr)
 
void OnGameSynchronized ()
 
void DrawStatus (C4TargetFacet &cgo)
 
void RequestActivate ()
 
void DeactivateInactiveClients ()
 
void LeagueGameEvaluate (const char *szRecordName=nullptr, const BYTE *pRecordSHA=nullptr)
 
void LeagueSignupDisable ()
 
bool LeagueSignupEnable ()
 
void InvalidateReference ()
 
bool LeaguePlrAuth (C4PlayerInfo *pInfo)
 
bool LeaguePlrAuthCheck (C4PlayerInfo *pInfo)
 
void LeagueNotifyDisconnect (int32_t iClientID, enum C4LeagueDisconnectReason eReason)
 
void LeagueWaitNotBusy ()
 
void LeagueSurrender ()
 
void LeagueShowError (const char *szMsg)
 
void Vote (C4ControlVoteType eType, bool fApprove=true, int32_t iData=0)
 
void AddVote (const C4ControlVote &Vote)
 
C4IDPacketGetVote (int32_t iClientID, C4ControlVoteType eType, int32_t iData)
 
void EndVote (C4ControlVoteType eType, bool fApprove, int32_t iData)
 
void OpenVoteDialog ()
 
void OpenSurrenderDialog (C4ControlVoteType eType, int32_t iData)
 
void OnVoteDialogClosed ()
 
void StartLobbyCountdown (int32_t iCountdownTime)
 
void AbortLobbyCountdown ()
 
bool isLobbyCountDown ()
 
size_t getPendingStreamData () const
 
bool isStreaming () const
 
bool StartStreaming (C4Record *pRecord)
 
bool FinishStreaming ()
 
bool StopStreaming ()
 
C4NetpuncherID::valuegetNetpuncherGameID (C4NetIO::HostAddress::AddressFamily family)
 
C4NetpuncherID getNetpuncherGameID () const
 
StdStrBuf getNetpuncherAddr () const
 

Public Attributes

C4Network2IO NetIO
 
C4Network2ResList ResList
 
C4Network2ClientList Clients
 
C4Network2Players Players
 
C4Network2Status Status
 

Protected Member Functions

bool InitNetIO (bool fNoClientID, bool fHost)
 
void HandleConn (const class C4PacketConn &Pkt, C4Network2IOConnection *pConn, C4Network2Client *pClient)
 
bool CheckConn (const C4ClientCore &CCore, C4Network2IOConnection *pConn, C4Network2Client *pClient, StdStrBuf *szReply)
 
bool HostConnect (const C4ClientCore &CCore, C4Network2IOConnection *pConn, StdStrBuf *szReply)
 
bool Join (C4ClientCore &CCore, C4Network2IOConnection *pConn, StdStrBuf *szReply)
 
void HandleConnRe (const class C4PacketConnRe &Pkt, C4Network2IOConnection *pConn, C4Network2Client *pClient)
 
void HandleStatus (const C4Network2Status &nStatus)
 
void HandleStatusAck (const C4Network2Status &nStatus, C4Network2Client *pClient)
 
void HandleActivateReq (int32_t iTick, C4Network2Client *pClient)
 
void HandleJoinData (const class C4PacketJoinData &rPkt)
 
void OnConnect (C4Network2Client *pClient, C4Network2IOConnection *pConn, const char *szMsg, bool fFirstConnection)
 
void OnConnectFail (C4Network2IOConnection *pConn)
 
void OnDisconnect (C4Network2Client *pClient, C4Network2IOConnection *pConn)
 
void OnClientConnect (C4Network2Client *pClient, C4Network2IOConnection *pConn)
 
void OnClientDisconnect (C4Network2Client *pClient)
 
void SendJoinData (C4Network2Client *pClient)
 
bool CreateDynamic (bool fInit)
 
void RemoveDynamic ()
 
bool PauseGame (bool fAutoContinue)
 
bool ChangeGameStatus (C4NetGameState enState, int32_t iTargetCtrlTick, int32_t iCtrlMode=-1)
 
void CheckStatusReached (bool fFromFinalInit=false)
 
void CheckStatusAck ()
 
void OnStatusReached ()
 
void OnStatusAck ()
 
void UpdateChaseTarget ()
 
bool InitLeague (bool *pCancel)
 
void DeinitLeague ()
 
bool LeagueStart (bool *pCancel)
 
bool LeagueUpdate ()
 
bool LeagueUpdateProcessReply ()
 
bool LeagueEnd (const char *szRecordName=nullptr, const BYTE *pRecordSHA=nullptr)
 
bool StreamIn (bool fFinish)
 
bool StreamOut ()
 
void InitPuncher ()
 

Protected Attributes

bool fHost
 
bool fAllowJoin
 
bool fAllowObserve
 
C4Network2ResCore ResDynamic
 
int32_t iDynamicTick
 
bool fDynamicNeeded
 
bool fStatusAck
 
bool fStatusReached
 
bool fChasing
 
class C4GameControlNetworkpControl
 
C4GameLobby::MainDlgpLobby
 
bool fLobbyRunning
 
C4GameLobby::CountdownpLobbyCountdown
 
StdCopyStrBuf MasterServerAddress
 
int32_t iNextClientID
 
uint32_t iLastChaseTargetUpdate
 
C4TimeMilliseconds tLastActivateRequest
 
uint32_t iLastReferenceUpdate
 
uint32_t iLastLeagueUpdate
 
uint32_t iLeagueUpdateDelay
 
bool fLeagueEndSent
 
class C4LeagueClientpLeagueClient
 
StdStrBuf sPassword
 
bool fWrongPassword
 
bool fDelayedActivateReq
 
C4Control Votes
 
class C4VoteDialogpVoteDialog
 
bool fPausedForVote
 
time_t iVoteStartTime
 
time_t iLastOwnVoting
 
bool fStreaming
 
time_t iLastStreamAttempt
 
C4RecordpStreamedRecord
 
StdBuf StreamingBuf
 
z_stream StreamCompressor
 
class C4Network2HTTPClientpStreamer
 
unsigned int iCurrentStreamAmount
 
unsigned int iCurrentStreamPosition
 
C4NetpuncherID NetpuncherGameID
 
StdCopyStrBuf NetpuncherAddr
 

Private Member Functions

virtual bool Execute (int, pollfd *)
 
void Set ()
 
void SetDelay (uint32_t inDelay)
 
bool CheckAndReset ()
 
virtual C4TimeMilliseconds GetNextTick (C4TimeMilliseconds tNow)
 
virtual uint32_t TimerInterval ()
 
void Changed ()
 
bool ExecuteUntil (int iTimeout=-1)
 
virtual void GetFDs (std::vector< struct pollfd > &)
 
bool IsSignaled ()
 
virtual bool IsLowPriority ()
 
virtual bool IsNotify ()
 

Friends

class C4Network2IO
 

Detailed Description

Definition at line 101 of file C4Network2.h.

Member Enumeration Documentation

Enumerator
IR_Success 
IR_Error 
IR_Fatal 

Definition at line 221 of file C4Network2.h.

Constructor & Destructor Documentation

C4Network2::C4Network2 ( )

Definition at line 132 of file C4Network2.cpp.

133  : Clients(&NetIO),
134  fAllowJoin(false),
135  iDynamicTick(-1), fDynamicNeeded(false),
136  fStatusAck(false), fStatusReached(false),
137  fChasing(false),
138  pControl(nullptr),
139  pLobby(nullptr), fLobbyRunning(false), pLobbyCountdown(nullptr),
140  iNextClientID(0),
145  pLeagueClient(nullptr),
146  fDelayedActivateReq(false),
147  pVoteDialog(nullptr),
148  fPausedForVote(false),
149  iLastOwnVoting(0),
150  fStreaming(false),
152 {
153 
154 }
bool fStatusAck
Definition: C4Network2.h:140
uint32_t iLastLeagueUpdate
Definition: C4Network2.h:165
bool fStatusReached
Definition: C4Network2.h:140
C4Network2IO NetIO
Definition: C4Network2.h:110
bool fLobbyRunning
Definition: C4Network2.h:148
int32_t iNextClientID
Definition: C4Network2.h:155
class C4VoteDialog * pVoteDialog
Definition: C4Network2.h:182
bool fAllowJoin
Definition: C4Network2.h:130
int32_t iDynamicTick
Definition: C4Network2.h:136
class C4LeagueClient * pLeagueClient
Definition: C4Network2.h:169
bool fDelayedActivateReq
Definition: C4Network2.h:178
uint32_t iLastReferenceUpdate
Definition: C4Network2.h:164
bool fDynamicNeeded
Definition: C4Network2.h:137
C4GameLobby::MainDlg * pLobby
Definition: C4Network2.h:147
bool fPausedForVote
Definition: C4Network2.h:183
C4TimeMilliseconds tLastActivateRequest
Definition: C4Network2.h:161
C4Network2ClientList Clients
Definition: C4Network2.h:116
C4NetpuncherID NetpuncherGameID
Definition: C4Network2.h:197
time_t iLastOwnVoting
Definition: C4Network2.h:184
bool fStreaming
Definition: C4Network2.h:187
uint32_t iLastChaseTargetUpdate
Definition: C4Network2.h:158
class C4GameControlNetwork * pControl
Definition: C4Network2.h:144
C4GameLobby::Countdown * pLobbyCountdown
Definition: C4Network2.h:149
bool fChasing
Definition: C4Network2.h:141
C4Network2::~C4Network2 ( )
virtual

Definition at line 156 of file C4Network2.cpp.

References Clear().

157 {
158  Clear();
159 }
void Clear()
Definition: C4Network2.cpp:734

Here is the call graph for this function:

Member Function Documentation

void C4Network2::AbortLobbyCountdown ( )

Definition at line 2893 of file C4Network2.cpp.

References C4GameLobby::Countdown::Abort(), and pLobbyCountdown.

Referenced by C4GameLobby::MainDlg::OnRunBtn(), C4MessageInput::ProcessCommand(), and StartLobbyCountdown().

2894 {
2895  // aboert lobby countdown
2896  if (pLobbyCountdown)
2897  {
2899  delete pLobbyCountdown;
2900  pLobbyCountdown = nullptr;
2901  }
2902 }
C4GameLobby::Countdown * pLobbyCountdown
Definition: C4Network2.h:149

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::AddVote ( const C4ControlVote Vote)

Definition at line 2712 of file C4Network2.cpp.

References C4Control::Add(), CID_Vote, C4Control::firstPkt(), fPausedForVote, isHost(), isRunning(), iVoteStartTime, OpenVoteDialog(), Pause(), and Votes.

2713 {
2714  // Save back timestamp
2715  if (!Votes.firstPkt())
2716  iVoteStartTime = time(nullptr);
2717  // Save vote back
2718  Votes.Add(CID_Vote, new C4ControlVote(Vote));
2719  // Set pause mode if this is the host
2720  if (isHost() && isRunning())
2721  {
2722  Pause();
2723  fPausedForVote = true;
2724  }
2725  // Check if the dialog should be opened
2726  OpenVoteDialog();
2727 }
C4IDPacket * firstPkt() const
Definition: C4Control.h:78
time_t iVoteStartTime
Definition: C4Network2.h:184
bool isHost() const
Definition: C4Network2.h:209
bool isRunning() const
Definition: C4Network2.h:206
void Add(C4PacketType eType, C4ControlPacket *pCtrl)
Definition: C4Control.h:82
void OpenVoteDialog()
bool Pause()
Definition: C4Network2.cpp:536
bool fPausedForVote
Definition: C4Network2.h:183
C4Control Votes
Definition: C4Network2.h:181

Here is the call graph for this function:

void C4Network2::AllowJoin ( bool  fAllow)

Definition at line 824 of file C4Network2.cpp.

References Config, fAllowJoin, C4GraphicsSystem::FlashMessage(), Game, GraphicsSystem, isHost(), C4Game::IsRunning, LoadResStr(), C4Config::Network, and C4ConfigNetwork::NoRuntimeJoin.

Referenced by C4Game::InitNetworkHost(), and ToggleAllowJoin().

825 {
826  if (!isHost()) return;
827  fAllowJoin = fAllow;
828  if (Game.IsRunning)
829  {
830  ::GraphicsSystem.FlashMessage(LoadResStr(fAllowJoin ? "IDS_NET_RUNTIMEJOINFREE" : "IDS_NET_RUNTIMEJOINBARRED"));
832  }
833 }
bool IsRunning
Definition: C4Game.h:141
C4Config Config
Definition: C4Config.cpp:831
bool isHost() const
Definition: C4Network2.h:209
C4Game Game
Definition: C4Globals.cpp:52
bool fAllowJoin
Definition: C4Network2.h:130
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51
C4ConfigNetwork Network
Definition: C4Config.h:256
void FlashMessage(const char *szMessage)
int32_t NoRuntimeJoin
Definition: C4Config.h:143

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2::ChangeGameStatus ( C4NetGameState  enState,
int32_t  iTargetCtrlTick,
int32_t  iCtrlMode = -1 
)
protected

Definition at line 1841 of file C4Network2.cpp.

References C4Network2ClientList::BroadcastMsgToClients(), CheckStatusReached(), Clients, fStatusAck, fStatusReached, C4Network2Status::getStateName(), InvalidateReference(), isHost(), LogSilentF(), MkC4NetIOPacket(), PID_Status, C4Network2ClientList::ResetReady(), C4Network2Status::Set(), C4Network2Status::SetCtrlMode(), and Status.

Referenced by DoLobby(), HandleStatusAck(), OnClientDisconnect(), Pause(), SetCtrlMode(), Start(), and Sync().

1842 {
1843  // change game status, announce. Can only be done by host.
1844  if (!isHost()) return false;
1845  // set status
1846  Status.Set(enState, iTargetCtrlTick);
1847  // update reference
1849  // control mode change?
1850  if (iCtrlMode >= 0) Status.SetCtrlMode(iCtrlMode);
1851  // log
1852  LogSilentF("Network: going into status %s (tick %d)", Status.getStateName(), iTargetCtrlTick);
1853  // set flags
1854  Clients.ResetReady();
1855  fStatusReached = fStatusAck = false;
1856  // send new status to all clients
1858  // check reach/ack
1860  // ok
1861  return true;
1862 }
bool fStatusAck
Definition: C4Network2.h:140
bool fStatusReached
Definition: C4Network2.h:140
bool isHost() const
Definition: C4Network2.h:209
void Set(C4NetGameState eState, int32_t iTargetCtrlTick)
Definition: C4Network2.cpp:88
bool BroadcastMsgToClients(const C4NetIOPacket &rPkt)
void SetCtrlMode(int32_t iCtrlMode)
Definition: C4Network2.cpp:93
bool LogSilentF(const char *strMessage,...)
Definition: C4Log.cpp:263
void InvalidateReference()
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
const char * getStateName() const
Definition: C4Network2.cpp:62
C4Network2Status Status
Definition: C4Network2.h:122
C4Network2ClientList Clients
Definition: C4Network2.h:116
void CheckStatusReached(bool fFromFinalInit=false)

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2::CheckConn ( const C4ClientCore CCore,
C4Network2IOConnection pConn,
C4Network2Client pClient,
StdStrBuf szReply 
)
protected

Definition at line 1341 of file C4Network2.cpp.

References C4ClientCoreDL_IDMatch, C4Network2Client::getCore(), C4ClientCore::getDiffLevel(), and C4Network2Client::hasConn().

Referenced by HandleConn().

1342 {
1343  if (!pConn || !pClient) return false;
1344  // already connected? (shouldn't happen really)
1345  if (pClient->hasConn(pConn))
1346  { *szReply = "already connected"; return true; }
1347  // check core
1348  if (CCore.getDiffLevel(pClient->getCore()) > C4ClientCoreDL_IDMatch)
1349  { *szReply = "wrong client core"; return false; }
1350  // accept
1351  return true;
1352 }
const int32_t C4ClientCoreDL_IDMatch
Definition: C4Client.h:30
const C4ClientCore & getCore() const
int32_t getDiffLevel(const C4ClientCore &CCore2) const
Definition: C4Client.cpp:85
bool hasConn(C4Network2IOConnection *pConn)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::CheckStatusAck ( )
protected

Definition at line 1909 of file C4Network2.cpp.

References C4Network2ClientList::AllClientsReady(), C4Network2ClientList::BroadcastMsgToClients(), Clients, C4GameControlNetwork::ExecSyncControl(), fStatusAck, fStatusReached, C4Network2Status::getState(), GS_Go, GS_Pause, isHost(), MkC4NetIOPacket(), OnStatusAck(), pControl, PID_StatusAck, and Status.

Referenced by CheckStatusReached(), HandleStatusAck(), OnClientDisconnect(), and Sync().

1910 {
1911  // host only
1912  if (!isHost()) return;
1913  // status must be reached and not yet acknowledged
1914  if (!fStatusReached || fStatusAck) return;
1915  // all clients ready?
1917  {
1918  // pause/go: check for sync control that can be executed
1919  if (Status.getState() == GS_Go || Status.getState() == GS_Pause)
1921  // broadcast ack
1923  // handle
1924  OnStatusAck();
1925  }
1926 }
bool fStatusAck
Definition: C4Network2.h:140
bool fStatusReached
Definition: C4Network2.h:140
bool isHost() const
Definition: C4Network2.h:209
bool BroadcastMsgToClients(const C4NetIOPacket &rPkt)
void OnStatusAck()
bool AllClientsReady() const
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
C4Network2Status Status
Definition: C4Network2.h:122
C4NetGameState getState() const
Definition: C4Network2.h:80
C4Network2ClientList Clients
Definition: C4Network2.h:116
class C4GameControlNetwork * pControl
Definition: C4Network2.h:144

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::CheckStatusReached ( bool  fFromFinalInit = false)
protected

Definition at line 1864 of file C4Network2.cpp.

References CheckStatusAck(), Clients, Console, Control, C4GameControl::ControlTick, C4GameControlNetwork::CtrlReady(), C4GameControl::CtrlTickReached(), fChasing, fDelayedActivateReq, fLobbyRunning, fStatusReached, Game, C4Network2Status::getState(), C4Network2Status::getTargetCtrlTick(), GS_Go, GS_Lobby, GS_Pause, C4Game::HaltCount, isHost(), C4Game::IsRunning, MkC4NetIOPacket(), OnStatusReached(), pControl, PID_StatusAck, RequestActivate(), C4Network2ClientList::SendMsgToHost(), C4GameControlNetwork::SetRunning(), C4Network2Status::SetTargetTick(), Status, and C4ConsoleGUI::UpdateHaltCtrls().

Referenced by ChangeGameStatus(), DoLobby(), Execute(), FinalInit(), and HandleStatus().

1865 {
1866  // already reached?
1867  if (fStatusReached) return;
1868  if (Status.getState() == GS_Lobby)
1870  // game go / pause: control must be initialized and target tick reached
1871  else if (Status.getState() == GS_Go || Status.getState() == GS_Pause)
1872  {
1873  if (Game.IsRunning || fFromFinalInit)
1874  {
1875  // Make sure we have reached the tick and the control queue is empty (except for chasing)
1878  fStatusReached = true;
1879  else
1880  {
1881  // run ctrl so the tick can be reached
1883  Game.HaltCount = 0;
1885  }
1886  }
1887  }
1888  if (!fStatusReached) return;
1889  // call handler
1890  OnStatusReached();
1891  // host?
1892  if (isHost())
1893  // all clients ready?
1894  CheckStatusAck();
1895  else
1896  {
1898  // send response to host
1900  // do delayed activation request
1901  if (fDelayedActivateReq)
1902  {
1903  fDelayedActivateReq = false;
1904  RequestActivate();
1905  }
1906  }
1907 }
void CheckStatusAck()
bool IsRunning
Definition: C4Game.h:141
int32_t getTargetCtrlTick() const
Definition: C4Network2.h:82
bool SendMsgToHost(C4NetIOPacket rPkt)
bool fStatusReached
Definition: C4Network2.h:140
int32_t ControlTick
Definition: C4GameControl.h:89
C4Console Console
Definition: C4Globals.cpp:45
bool isHost() const
Definition: C4Network2.h:209
C4Game Game
Definition: C4Globals.cpp:52
bool fLobbyRunning
Definition: C4Network2.h:148
void OnStatusReached()
bool CtrlReady(int32_t iTick)
bool fDelayedActivateReq
Definition: C4Network2.h:178
C4GameControl Control
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
C4Network2Status Status
Definition: C4Network2.h:122
C4NetGameState getState() const
Definition: C4Network2.h:80
C4Network2ClientList Clients
Definition: C4Network2.h:116
void SetTargetTick(int32_t iTargetCtrlTick)
Definition: C4Network2.cpp:98
bool UpdateHaltCtrls(bool fHalt)
Definition: C4ConsoleGUI.h:153
bool CtrlTickReached(int32_t iTick)
int32_t HaltCount
Definition: C4Game.h:114
void SetRunning(bool fnRunning, int32_t inTargetTick=-1)
void RequestActivate()
class C4GameControlNetwork * pControl
Definition: C4Network2.h:144
bool fChasing
Definition: C4Network2.h:141

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::Clear ( )

Definition at line 734 of file C4Network2.cpp.

References Application, C4GameControl::ChangeToLocal(), C4Network2Players::Clear(), C4Control::Clear(), C4Network2Status::Clear(), C4Network2IO::Clear(), C4Network2ClientList::Clear(), C4Network2ResList::Clear(), StdStrBuf::Clear(), Clients, Control, DeinitLeague(), fAllowJoin, fDelayedActivateReq, fDynamicNeeded, fLobbyRunning, fPausedForVote, fStatusAck, fStatusReached, iDynamicTick, iLastChaseTargetUpdate, iLastLeagueUpdate, iLastOwnVoting, iLastReferenceUpdate, C4GameControl::isNetwork(), LeagueEnd(), C4TimeMilliseconds::NegativeInfinity, NetIO, NetpuncherGameID, Players, pLeagueClient, pLobby, pLobbyCountdown, pVoteDialog, StdScheduler::Remove(), ResList, sPassword, Status, StopStreaming(), tLastActivateRequest, and Votes.

Referenced by C4Game::Clear(), DoLobby(), FinalInit(), HandleJoinData(), InitHost(), C4MainMenu::MenuCommand(), OnClientDisconnect(), OnDisconn(), and ~C4Network2().

735 {
736  // stop timer
737  Application.Remove(this);
738  // stop streaming
739  StopStreaming();
740  // clear league
741  if (pLeagueClient)
742  {
743  LeagueEnd();
744  DeinitLeague();
745  }
746  // stop lobby countdown
747  delete pLobbyCountdown; pLobbyCountdown = nullptr;
748  // cancel lobby
749  delete pLobby; pLobby = nullptr;
750  fLobbyRunning = false;
751  // deactivate
752  Status.Clear();
753  fStatusAck = fStatusReached = true;
754  // if control mode is network: change to local
755  if (::Control.isNetwork())
757  // clear all player infos
758  Players.Clear();
759  // remove all clients
760  Clients.Clear();
761  // close net classes
762  NetIO.Clear();
763  // clear resources
764  ResList.Clear();
765  // clear password
766  sPassword.Clear();
767  // stuff
768  fAllowJoin = false;
769  iDynamicTick = -1; fDynamicNeeded = false;
772  fDelayedActivateReq = false;
773  delete pVoteDialog; pVoteDialog = nullptr;
774  fPausedForVote = false;
775  iLastOwnVoting = 0;
777  Votes.Clear();
778  // don't clear fPasswordNeeded here, it's needed by InitClient
779 }
bool fStatusAck
Definition: C4Network2.h:140
uint32_t iLastLeagueUpdate
Definition: C4Network2.h:165
bool fStatusReached
Definition: C4Network2.h:140
C4Network2IO NetIO
Definition: C4Network2.h:110
void Clear()
Definition: StdBuf.h:474
bool fLobbyRunning
Definition: C4Network2.h:148
class C4VoteDialog * pVoteDialog
Definition: C4Network2.h:182
bool fAllowJoin
Definition: C4Network2.h:130
int32_t iDynamicTick
Definition: C4Network2.h:136
class C4LeagueClient * pLeagueClient
Definition: C4Network2.h:169
bool isNetwork() const
Definition: C4GameControl.h:97
bool fDelayedActivateReq
Definition: C4Network2.h:178
C4GameControl Control
uint32_t iLastReferenceUpdate
Definition: C4Network2.h:164
void Clear()
Definition: C4Control.cpp:95
C4Network2Status Status
Definition: C4Network2.h:122
bool fDynamicNeeded
Definition: C4Network2.h:137
C4GameLobby::MainDlg * pLobby
Definition: C4Network2.h:147
bool fPausedForVote
Definition: C4Network2.h:183
C4TimeMilliseconds tLastActivateRequest
Definition: C4Network2.h:161
C4Network2ResList ResList
Definition: C4Network2.h:113
void Remove(StdSchedulerProc *pProc)
C4Network2ClientList Clients
Definition: C4Network2.h:116
C4NetpuncherID NetpuncherGameID
Definition: C4Network2.h:197
time_t iLastOwnVoting
Definition: C4Network2.h:184
C4Network2Players Players
Definition: C4Network2.h:119
C4Control Votes
Definition: C4Network2.h:181
StdStrBuf sPassword
Definition: C4Network2.h:172
bool StopStreaming()
uint32_t iLastChaseTargetUpdate
Definition: C4Network2.h:158
bool LeagueEnd(const char *szRecordName=nullptr, const BYTE *pRecordSHA=nullptr)
C4Application Application
Definition: C4Globals.cpp:44
void DeinitLeague()
void ChangeToLocal()
C4GameLobby::Countdown * pLobbyCountdown
Definition: C4Network2.h:149

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2::CreateDynamic ( bool  fInit)
protected

Definition at line 1794 of file C4Network2.cpp.

References _MAX_PATH, C4Network2ResList::AddByFile(), C4Config::AtNetworkPath(), C4GameSave::Close(), Config, Control, fDynamicNeeded, C4Network2ResList::FindTempResFileName(), Game, C4Network2Res::getCore(), GetFilename(), C4GameControl::getNextControlTick(), iDynamicTick, isHost(), LoadResStr(), Log(), NRT_Dynamic, RemoveDynamic(), ResDynamic, ResList, C4GameSave::Save(), C4Game::ScenarioFilename, and sprintf.

Referenced by InitHost(), and OnGameSynchronized().

1795 {
1796  if (!isHost()) return false;
1797  // remove all existing dynamic data
1798  RemoveDynamic();
1799  // log
1800  Log(LoadResStr("IDS_NET_SAVING"));
1801  // compose file name
1802  char szDynamicBase[_MAX_PATH+1], szDynamicFilename[_MAX_PATH+1];
1804  if (!ResList.FindTempResFileName(szDynamicBase, szDynamicFilename))
1805  Log(LoadResStr("IDS_NET_SAVE_ERR_CREATEDYNFILE"));
1806  // save dynamic data
1807  C4GameSaveNetwork SaveGame(fInit);
1808  if (!SaveGame.Save(szDynamicFilename) || !SaveGame.Close())
1809  { Log(LoadResStr("IDS_NET_SAVE_ERR_SAVEDYNFILE")); return false; }
1810  // add resource
1811  C4Network2Res::Ref pRes = ResList.AddByFile(szDynamicFilename, true, NRT_Dynamic);
1812  if (!pRes) { Log(LoadResStr("IDS_NET_SAVE_ERR_ADDDYNDATARES")); return false; }
1813  // save
1814  ResDynamic = pRes->getCore();
1816  fDynamicNeeded = false;
1817  // ok
1818  return true;
1819 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:55
void RemoveDynamic()
char ScenarioFilename[_MAX_PATH+1]
Definition: C4Game.h:104
C4Config Config
Definition: C4Config.cpp:831
bool isHost() const
Definition: C4Network2.h:209
C4Game Game
Definition: C4Globals.cpp:52
#define sprintf
Definition: Standard.h:171
#define _MAX_PATH
int32_t iDynamicTick
Definition: C4Network2.h:136
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
const C4Network2ResCore & getCore() const
C4GameControl Control
const char * AtNetworkPath(const char *szFilename)
Definition: C4Config.cpp:545
C4Network2ResCore ResDynamic
Definition: C4Network2.h:133
bool fDynamicNeeded
Definition: C4Network2.h:137
C4Network2Res::Ref AddByFile(const char *strFilePath, bool fTemp, C4Network2ResType eType, int32_t iResID=-1, const char *szResName=nullptr, bool fAllowUnloadable=false)
C4Network2ResList ResList
Definition: C4Network2.h:113
bool FindTempResFileName(const char *szFilename, char *pTarget)
bool Log(const char *szMessage)
Definition: C4Log.cpp:195
int32_t getNextControlTick() const

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::DeactivateInactiveClients ( )

Definition at line 1995 of file C4Network2.cpp.

References Application, C4NetDeactivationDelay, CDT_Sync, CID_ClientUpdate, Clients, Control, CUT_Activate, C4GameControl::DoInput(), C4Game::FrameCounter, Game, C4Network2ClientList::GetNextClient(), C4Application::isEditor, isHost(), and C4Network2ClientList::UpdateClientActivity().

Referenced by Execute().

1996 {
1997  // host only and not in editor
1998  if (!isHost() || ::Application.isEditor) return;
1999  // update activity
2001  // find clients to deactivate
2002  for (C4Network2Client *pClient = Clients.GetNextClient(nullptr); pClient; pClient = Clients.GetNextClient(pClient))
2003  if (!pClient->isLocal() && pClient->isActivated())
2004  if (pClient->getLastActivity() + C4NetDeactivationDelay < Game.FrameCounter)
2005  ::Control.DoInput(CID_ClientUpdate, new C4ControlClientUpdate(pClient->getID(), CUT_Activate, false), CDT_Sync);
2006 }
bool isHost() const
Definition: C4Network2.h:209
C4Network2Client * GetNextClient(C4Network2Client *pClient)
C4Game Game
Definition: C4Globals.cpp:52
const int C4NetDeactivationDelay
Definition: C4Network2.h:42
int32_t FrameCounter
Definition: C4Game.h:130
C4GameControl Control
void DoInput(C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)
C4Network2ClientList Clients
Definition: C4Network2.h:116
C4Application Application
Definition: C4Globals.cpp:44

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::DeinitLeague ( )
protected

Definition at line 2138 of file C4Network2.cpp.

References Application, StdStrBuf::Clear(), Game, C4GameParameters::League, C4GameParameters::LeagueAddress, MasterServerAddress, C4Game::Parameters, pLeagueClient, and StdScheduler::Remove().

Referenced by Clear(), InitHost(), LeagueSignupDisable(), LeagueSignupEnable(), LeagueStart(), and LeagueSurrender().

2139 {
2140  // league clear
2144  if (pLeagueClient)
2145  {
2147  delete pLeagueClient; pLeagueClient = nullptr;
2148  }
2149 }
C4Game Game
Definition: C4Globals.cpp:52
void Clear()
Definition: StdBuf.h:474
StdCopyStrBuf League
StdCopyStrBuf MasterServerAddress
Definition: C4Network2.h:152
C4GameParameters & Parameters
Definition: C4Game.h:69
class C4LeagueClient * pLeagueClient
Definition: C4Network2.h:169
void Remove(StdSchedulerProc *pProc)
StdCopyStrBuf LeagueAddress
C4Application Application
Definition: C4Globals.cpp:44

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2::DoLobby ( )

Definition at line 455 of file C4Network2.cpp.

References C4Window::Active, Application, ChangeGameStatus(), CheckStatusReached(), Clear(), C4GUI::Dialog::Close(), C4GUI::Screen::CloseAllDialogs(), Config, Console, C4GUI::Dialog::FadeIn(), fAllowJoin, fLobbyRunning, Game, GS_Lobby, C4Game::iLobbyTimeout, C4GUI::Dialog::IsAborted(), isEnabled(), isHost(), isLobbyActive(), C4GUI::Dialog::IsShown(), LoadResStr(), Log(), C4Config::Network, C4ConfigNetwork::NoRuntimeJoin, C4AbstractApp::NotifyUserIfInactive(), pGUI, pLobby, pLobbyCountdown, StdScheduler::ScheduleProcs(), StartLobbyCountdown(), and C4Console::UpdateMenus().

Referenced by C4Game::Init(), and C4Game::InitNetworkHost().

456 {
457  // shouldn't do lobby?
458  if (!isEnabled() || (!isHost() && !isLobbyActive()))
459  return true;
460 
461  // lobby runs
462  fLobbyRunning = true;
463  fAllowJoin = true;
464  Log(LoadResStr("IDS_NET_LOBBYWAITING"));
465 
466  // client: lobby status reached, message to host
467  if (!isHost())
469  // host: set lobby mode
470  else
472 
473  // determine lobby type
474  if (Console.Active)
475  {
476  // console lobby - update console
478  // init lobby countdown if specified
480  // do console lobby
481  while (isLobbyActive())
482  if (!Application.ScheduleProcs())
483  { Clear(); return false; }
484  }
485  else
486  {
487  // fullscreen lobby
488 
489  // init lobby dialog
491  if (!pLobby->FadeIn(::pGUI)) { delete pLobby; pLobby = nullptr; Clear(); return false; }
492 
493  // init lobby countdown if specified
495 
496  // while state lobby: keep looping
497  while (isLobbyActive() && pLobby && pLobby->IsShown())
498  if (!Application.ScheduleProcs())
499  { Clear(); return false; }
500 
501  // check whether lobby was aborted
502  if (pLobby && pLobby->IsAborted()) { delete pLobby; pLobby = nullptr; Clear(); return false; }
503 
504  // deinit lobby
505  if (pLobby && pLobby->IsShown()) pLobby->Close(true);
506  delete pLobby; pLobby = nullptr;
507 
508  // close any other dialogs
509  ::pGUI->CloseAllDialogs(false);
510  }
511 
512  // lobby end
513  delete pLobbyCountdown; pLobbyCountdown = nullptr;
514  fLobbyRunning = false;
516 
517  // notify user that the lobby has ended (for people who tasked out)
519 
520  // notify lobby end
521  bool fGameGo = isEnabled();
522  if (fGameGo) Log(LoadResStr("IDS_PRC_GAMEGO"));;
523 
524  // disabled?
525  return fGameGo;
526 }
int32_t iLobbyTimeout
Definition: C4Game.h:121
C4Config Config
Definition: C4Config.cpp:831
C4Console Console
Definition: C4Globals.cpp:45
bool isHost() const
Definition: C4Network2.h:209
C4Game Game
Definition: C4Globals.cpp:52
bool fLobbyRunning
Definition: C4Network2.h:148
bool isLobbyActive() const
Definition: C4Network2.h:204
bool IsAborted()
Definition: C4Gui.h:2149
void Close(bool fOK)
bool fAllowJoin
Definition: C4Network2.h:130
void UpdateMenus()
Definition: C4Console.cpp:509
bool IsShown()
Definition: C4Gui.h:2147
void StartLobbyCountdown(int32_t iCountdownTime)
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1194
C4ConfigNetwork Network
Definition: C4Config.h:256
void Clear()
Definition: C4Network2.cpp:734
C4GameLobby::MainDlg * pLobby
Definition: C4Network2.h:147
bool isEnabled() const
Definition: C4Network2.h:203
bool ChangeGameStatus(C4NetGameState enState, int32_t iTargetCtrlTick, int32_t iCtrlMode=-1)
void CloseAllDialogs(bool fWithOK)
Definition: C4Gui.cpp:707
bool FadeIn(Screen *pOnScreen)
void NotifyUserIfInactive()
Definition: C4App.cpp:89
bool Active
Definition: C4Window.h:278
bool Log(const char *szMessage)
Definition: C4Log.cpp:195
int32_t NoRuntimeJoin
Definition: C4Config.h:143
bool ScheduleProcs(int iTimeout=1000/36)
void CheckStatusReached(bool fFromFinalInit=false)
C4Application Application
Definition: C4Globals.cpp:44
C4GameLobby::Countdown * pLobbyCountdown
Definition: C4Network2.h:149

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::DrawStatus ( C4TargetFacet cgo)

Definition at line 1108 of file C4Network2.cpp.

References StdStrBuf::Append(), StdStrBuf::AppendFormat(), C4GameControlNetwork::ClientNextControl(), C4GameControlNetwork::ClientPerfStat(), C4GameControlNetwork::ClientReady(), Clients, CNM_Central, CNM_Decentral, Config, Control, C4GameControl::ControlRate, C4GameControl::ControlTick, C4Network2IO::DataIO(), C4GraphicsResource::FontRegular, fStatusAck, fStatusReached, fStreaming, C4GameControlNetwork::getAvgControlSendTime(), C4GameControlNetwork::GetBehind(), C4GameControlNetwork::getControlPreSend(), C4Network2Status::getCtrlMode(), StdStrBuf::getData(), C4ClientCore::getID(), C4Network2Client::getID(), C4Network2ClientList::GetLocal(), C4ClientCore::getName(), C4Network2Client::getName(), C4Network2IO::getNetIOName(), C4Network2IO::getNetIOProt(), C4Network2ClientList::GetNextClient(), getPendingStreamData(), C4Network2IO::getProtBCRate(), C4Network2IO::getProtIRate(), C4Network2IO::getProtORate(), StdBuf::getSize(), C4Network2Status::getStateName(), C4Record::GetStreamingBuf(), C4Record::GetStreamingPos(), C4Network2Status::getTargetCtrlTick(), GraphicsResource, iCurrentStreamPosition, C4ClientCore::isActivated(), C4Network2Client::isActivated(), isEnabled(), C4ClientCore::isHost(), C4Network2Client::isHost(), C4ClientCore::isObserver(), C4Network2Client::isObserver(), C4Network2IO::MsgIO(), NCS_Chasing, NCS_Joining, NCS_NotReady, NCS_Remove, NetIO, C4Config::Network, P_NONE, P_TCP, P_UDP, pControl, pDraw, C4ConfigNetwork::PortTCP, C4ConfigNetwork::PortUDP, pStreamedRecord, Status, C4Facet::Surface, C4Draw::TextOut(), C4Facet::X, and C4Facet::Y.

Referenced by C4Viewport::Draw().

1109 {
1110  if (!isEnabled()) return;
1111 
1112  C4Network2Client *pLocal = Clients.GetLocal();
1113 
1114  StdStrBuf Stat;
1115 
1116  // local client status
1117  Stat.AppendFormat("Local: %s %s %s (ID %d)",
1118  pLocal->isObserver() ? "Observing" : pLocal->isActivated() ? "Active" : "Inactive", pLocal->isHost() ? "host" : "client",
1119  pLocal->getName(), pLocal->getID());
1120 
1121  // game status
1122  Stat.AppendFormat( "|Game Status: %s (tick %d)%s%s",
1124  fStatusReached ? " reached" : "", fStatusAck ? " ack" : "");
1125 
1126  // available protocols
1127  C4NetIO *pMsgIO = NetIO.MsgIO(), *pDataIO = NetIO.DataIO();
1128  if (pMsgIO && pDataIO)
1129  {
1130  C4Network2IOProtocol eMsgProt = NetIO.getNetIOProt(pMsgIO),
1131  eDataProt = NetIO.getNetIOProt(pDataIO);
1132  int32_t iMsgPort = 0, iDataPort = 0;
1133  switch (eMsgProt)
1134  {
1135  case P_TCP: iMsgPort = Config.Network.PortTCP; break;
1136  case P_UDP: iMsgPort = Config.Network.PortUDP; break;
1137  case P_NONE: assert(eMsgProt != P_NONE); break;
1138  }
1139  switch (eDataProt)
1140  {
1141  case P_TCP: iDataPort = Config.Network.PortTCP; break;
1142  case P_UDP: iDataPort = Config.Network.PortUDP; break;
1143  case P_NONE: assert(eMsgProt != P_NONE); break;
1144  }
1145  Stat.AppendFormat( "|Protocols: %s: %s (%d i%d o%d bc%d)",
1146  pMsgIO != pDataIO ? "Msg" : "Msg/Data",
1147  NetIO.getNetIOName(pMsgIO), iMsgPort,
1148  NetIO.getProtIRate(eMsgProt), NetIO.getProtORate(eMsgProt), NetIO.getProtBCRate(eMsgProt));
1149  if (pMsgIO != pDataIO)
1150  Stat.AppendFormat( ", Data: %s (%d i%d o%d bc%d)",
1151  NetIO.getNetIOName(pDataIO), iDataPort,
1152  NetIO.getProtIRate(eDataProt), NetIO.getProtORate(eDataProt), NetIO.getProtBCRate(eDataProt));
1153  }
1154  else
1155  Stat.Append("|Protocols: none");
1156 
1157  // some control statistics
1158  Stat.AppendFormat( "|Control: %s, Tick %d, Behind %d, Rate %d, PreSend %d, ACT: %d",
1159  Status.getCtrlMode() == CNM_Decentral ? "Decentral" : Status.getCtrlMode() == CNM_Central ? "Central" : "Async",
1162 
1163  // Streaming statistics
1164  if (fStreaming)
1165  Stat.AppendFormat( "|Streaming: %lu waiting, %u in, %lu out, %lu sent",
1166  static_cast<unsigned long>(pStreamedRecord ? pStreamedRecord->GetStreamingBuf().getSize() : 0),
1168  static_cast<unsigned long>(getPendingStreamData()),
1169  static_cast<unsigned long>(iCurrentStreamPosition));
1170 
1171  // clients
1172  Stat.Append("|Clients:");
1173  for (C4Network2Client *pClient = Clients.GetNextClient(nullptr); pClient; pClient = Clients.GetNextClient(pClient))
1174  {
1175  // ignore local
1176  if (pClient->isLocal()) continue;
1177  // client status
1178  const C4ClientCore &Core = pClient->getCore();
1179  const char *szClientStatus;
1180  switch (pClient->getStatus())
1181  {
1182  case NCS_Joining: szClientStatus = " (joining)"; break;
1183  case NCS_Chasing: szClientStatus = " (chasing)"; break;
1184  case NCS_NotReady: szClientStatus = " (!rdy)"; break;
1185  case NCS_Remove: szClientStatus = " (removed)"; break;
1186  default: szClientStatus = ""; break;
1187  }
1188  Stat.AppendFormat( "|- %s %s %s (ID %d) (wait %d ms, behind %d)%s%s",
1189  Core.isObserver() ? "Observing" : Core.isActivated() ? "Active" : "Inactive", Core.isHost() ? "host" : "client",
1190  Core.getName(), Core.getID(),
1191  pControl->ClientPerfStat(pClient->getID()),
1192  ::Control.ControlTick - pControl->ClientNextControl(pClient->getID()),
1193  szClientStatus,
1194  pClient->isActivated() && !pControl->ClientReady(pClient->getID(), ::Control.ControlTick) ? " (!ctrl)" : "");
1195  // connections
1196  if (pClient->isConnected())
1197  {
1198  Stat.AppendFormat( "| Connections: %s: %s (%s p%d l%d)",
1199  pClient->getMsgConn() == pClient->getDataConn() ? "Msg/Data" : "Msg",
1200  NetIO.getNetIOName(pClient->getMsgConn()->getNetClass()),
1201  pClient->getMsgConn()->getPeerAddr().ToString().getData(),
1202  pClient->getMsgConn()->getPingTime(),
1203  pClient->getMsgConn()->getPacketLoss());
1204  if (pClient->getMsgConn() != pClient->getDataConn())
1205  Stat.AppendFormat( ", Data: %s (%s:%d p%d l%d)",
1206  NetIO.getNetIOName(pClient->getDataConn()->getNetClass()),
1207  pClient->getDataConn()->getPeerAddr().ToString().getData(),
1208  pClient->getDataConn()->getPingTime(),
1209  pClient->getDataConn()->getPacketLoss());
1210  }
1211  else
1212  Stat.Append("| Not connected");
1213  }
1214  if (!Clients.GetNextClient(nullptr))
1215  Stat.Append("| - none -");
1216 
1217  // draw
1218  pDraw->TextOut(Stat.getData(), ::GraphicsResource.FontRegular, 1.0, cgo.Surface,cgo.X + 20,cgo.Y + 50);
1219 }
const char * getData() const
Definition: StdBuf.h:450
bool fStatusAck
Definition: C4Network2.h:140
int32_t getTargetCtrlTick() const
Definition: C4Network2.h:82
unsigned int iCurrentStreamPosition
Definition: C4Network2.h:194
bool isObserver() const
C4Config Config
Definition: C4Config.cpp:831
float Y
Definition: C4Facet.h:120
bool fStatusReached
Definition: C4Network2.h:140
int32_t ControlTick
Definition: C4GameControl.h:89
C4Network2Client * GetNextClient(C4Network2Client *pClient)
C4Network2IO NetIO
Definition: C4Network2.h:110
const StdBuf & GetStreamingBuf() const
Definition: C4Record.h:263
int getProtBCRate(C4Network2IOProtocol eProt) const
Definition: C4Network2IO.h:152
bool TextOut(const char *szText, CStdFont &rFont, float fZoom, C4Surface *sfcDest, float iTx, float iTy, DWORD dwFCol=0xffffffff, BYTE byForm=ALeft, bool fDoMarkup=true)
Definition: C4Draw.cpp:570
C4Network2IOProtocol
Definition: C4Network2IO.h:27
C4Record * pStreamedRecord
Definition: C4Network2.h:189
int32_t getID() const
C4GraphicsResource GraphicsResource
C4NetIO * MsgIO()
size_t getSize() const
Definition: StdBuf.h:109
bool isHost() const
Definition: C4Client.h:58
void AppendFormat(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:197
int32_t GetBehind(int32_t iTick) const
int32_t ClientPerfStat(int32_t iClientID)
int32_t getAvgControlSendTime() const
bool isObserver() const
Definition: C4Client.h:60
bool isActivated() const
Definition: C4Client.h:59
C4Network2IOProtocol getNetIOProt(C4NetIO *pNetIO)
C4GameControl Control
size_t getPendingStreamData() const
Definition: C4Network2.h:300
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:527
const char * getStateName() const
Definition: C4Network2.cpp:62
C4ConfigNetwork Network
Definition: C4Config.h:256
C4Network2Status Status
Definition: C4Network2.h:122
C4Draw * pDraw
Definition: C4Draw.cpp:45
bool isActivated() const
const char * getName() const
int32_t getID() const
Definition: C4Client.h:57
bool isEnabled() const
Definition: C4Network2.h:203
C4NetIO * DataIO()
int32_t getCtrlMode() const
Definition: C4Network2.h:81
int32_t getControlPreSend() const
int getProtORate(C4Network2IOProtocol eProt) const
Definition: C4Network2IO.h:151
C4Network2ClientList Clients
Definition: C4Network2.h:116
int32_t ClientNextControl(int32_t iClientID)
int getProtIRate(C4Network2IOProtocol eProt) const
Definition: C4Network2IO.h:150
bool ClientReady(int32_t iClientID, int32_t iTick)
C4Network2Client * GetLocal() const
bool fStreaming
Definition: C4Network2.h:187
const char * getName() const
Definition: C4Client.h:69
C4Surface * Surface
Definition: C4Facet.h:119
const char * getNetIOName(C4NetIO *pNetIO)
int32_t PortTCP
Definition: C4Config.h:154
float X
Definition: C4Facet.h:120
int32_t ControlRate
Definition: C4GameControl.h:88
int32_t PortUDP
Definition: C4Config.h:154
class C4GameControlNetwork * pControl
Definition: C4Network2.h:144
bool isHost() const
unsigned int GetStreamingPos() const
Definition: C4Record.h:262

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::EndVote ( C4ControlVoteType  eType,
bool  fApprove,
int32_t  iData 
)

Definition at line 2741 of file C4Network2.cpp.

References C4ClientIDAll, C4ClientIDUnknown, C4Game::Clients, C4Control::Delete(), C4Control::firstPkt(), fPausedForVote, Game, C4ClientList::getLocalID(), C4IDPacket::getPkt(), GetVote(), C4VoteDialog::getVoteData(), C4VoteDialog::getVoteType(), iLastOwnVoting, iVoteStartTime, OpenSurrenderDialog(), OpenVoteDialog(), pVoteDialog, Start(), Votes, VT_Cancel, VT_Kick, and VT_Pause.

2742 {
2743  // Remove all vote packets
2744  C4IDPacket *pPkt; int32_t iOrigin = C4ClientIDUnknown;
2745  while ((pPkt = GetVote(C4ClientIDAll, eType, iData)))
2746  {
2747  if (iOrigin == C4ClientIDUnknown)
2748  iOrigin = static_cast<C4ControlVote *>(pPkt->getPkt())->getByClient();
2749  Votes.Delete(pPkt);
2750  }
2751  // Reset timestamp
2752  iVoteStartTime = time(nullptr);
2753  // Approved own voting? Reset voting block
2754  if (fApprove && iOrigin == Game.Clients.getLocalID())
2755  iLastOwnVoting = 0;
2756  // Dialog open?
2757  if (pVoteDialog)
2758  if (pVoteDialog->getVoteType() == eType && pVoteDialog->getVoteData() == iData)
2759  {
2760  // close
2761  delete pVoteDialog;
2762  pVoteDialog = nullptr;
2763  }
2764  // Did we try to kick ourself? Ask if we'd like to surrender
2765  bool fCancelVote = (eType == VT_Kick && iData == Game.Clients.getLocalID()) || eType == VT_Cancel;
2766  if (!fApprove && fCancelVote && iOrigin == Game.Clients.getLocalID())
2767  OpenSurrenderDialog(eType, iData);
2768  // Check if the dialog should be opened
2769  OpenVoteDialog();
2770  // Pause/unpause voting?
2771  if (fApprove && eType == VT_Pause)
2772  fPausedForVote = !iData;
2773  // No voting left? Reset pause.
2774  if (!Votes.firstPkt())
2775  if (fPausedForVote)
2776  {
2777  Start();
2778  fPausedForVote = false;
2779  }
2780 }
const int32_t C4ClientIDAll
C4IDPacket * firstPkt() const
Definition: C4Control.h:78
bool Start()
Definition: C4Network2.cpp:528
time_t iVoteStartTime
Definition: C4Network2.h:184
C4Game Game
Definition: C4Globals.cpp:52
void Delete(C4IDPacket *pPkt)
Definition: C4Control.h:88
void OpenSurrenderDialog(C4ControlVoteType eType, int32_t iData)
class C4VoteDialog * pVoteDialog
Definition: C4Network2.h:182
void OpenVoteDialog()
int32_t getLocalID() const
Definition: C4Client.h:171
const int32_t C4ClientIDUnknown
Definition: C4Client.h:24
bool fPausedForVote
Definition: C4Network2.h:183
int32_t getVoteData() const
Definition: C4Network2.h:403
time_t iLastOwnVoting
Definition: C4Network2.h:184
C4ClientList & Clients
Definition: C4Game.h:71
C4IDPacket * GetVote(int32_t iClientID, C4ControlVoteType eType, int32_t iData)
C4Control Votes
Definition: C4Network2.h:181
C4ControlVoteType getVoteType() const
Definition: C4Network2.h:402
C4PacketBase * getPkt() const
Definition: C4PacketBase.h:255

Here is the call graph for this function:

void C4Network2::Execute ( )

Definition at line 671 of file C4Network2.cpp.

References C4LA_Update, C4NetReferenceUpdateInterval, C4NetVotingTimeout, CDT_Sync, CheckStatusReached(), CID_VoteEnd, Clients, Control, C4GameControl::ControlTick, DeactivateInactiveClients(), C4Network2ClientList::DoConnectAttempts(), C4GameControl::DoInput(), fHost, C4Control::firstPkt(), fStreaming, C4LeagueClient::getCurrentAction(), C4ControlVote::getData(), C4IDPacket::getPkt(), C4ControlVote::getType(), iDynamicTick, iLastLeagueUpdate, iLastReferenceUpdate, iLeagueUpdateDelay, C4Network2Reference::InitLocal(), C4Network2HTTPClient::isBusy(), isHost(), C4TimeMilliseconds::IsInfinite(), C4Network2ResCore::isNull(), C4Network2IO::IsReferenceNeeded(), iVoteStartTime, LeagueUpdate(), LeagueUpdateProcessReply(), NetIO, pLeagueClient, RemoveDynamic(), RequestActivate(), ResDynamic, C4Network2IO::SetReference(), StreamIn(), StreamOut(), tLastActivateRequest, UpdateChaseTarget(), and Votes.

Referenced by C4Game::Execute(), and OnSec1Timer().

672 {
673 
674  // client connections
676 
677  // status reached?
679 
680  if (isHost())
681  {
682  // remove dynamic
684  RemoveDynamic();
685  // Set chase target
687  // check for inactive clients and deactivate them
689  // reference
690  if (!iLastReferenceUpdate || time(nullptr) > (time_t) (iLastReferenceUpdate + C4NetReferenceUpdateInterval))
691  if (NetIO.IsReferenceNeeded())
692  {
693  // create
695  pRef->InitLocal();
696  // set
697  NetIO.SetReference(pRef);
698  iLastReferenceUpdate = time(nullptr);
699  }
700  // league server reference
701  if (!iLastLeagueUpdate || time(nullptr) > (time_t) (iLastLeagueUpdate + iLeagueUpdateDelay))
702  {
703  LeagueUpdate();
704  }
705  // league update reply receive
707  {
709  }
710  // voting timeout
711  if (Votes.firstPkt() && time(nullptr) > (time_t) (iVoteStartTime + C4NetVotingTimeout))
712  {
713  C4ControlVote *pVote = static_cast<C4ControlVote *>(Votes.firstPkt()->getPkt());
715  CID_VoteEnd,
716  new C4ControlVoteEnd(pVote->getType(), false, pVote->getData()),
717  CDT_Sync);
718  iVoteStartTime = time(nullptr);
719  }
720  // record streaming
721  if (fStreaming)
722  {
723  StreamIn(false);
724  StreamOut();
725  }
726  }
727  else
728  {
729  // request activate, if neccessary
731  }
732 }
void RemoveDynamic()
C4IDPacket * firstPkt() const
Definition: C4Control.h:78
const unsigned int C4NetReferenceUpdateInterval
Definition: C4Network2.h:48
void SetReference(class C4Network2Reference *pReference)
time_t iVoteStartTime
Definition: C4Network2.h:184
uint32_t iLastLeagueUpdate
Definition: C4Network2.h:165
int32_t ControlTick
Definition: C4GameControl.h:89
bool isHost() const
Definition: C4Network2.h:209
C4Network2IO NetIO
Definition: C4Network2.h:110
uint32_t iLeagueUpdateDelay
Definition: C4Network2.h:165
bool StreamIn(bool fFinish)
bool IsReferenceNeeded()
int32_t iDynamicTick
Definition: C4Network2.h:136
class C4LeagueClient * pLeagueClient
Definition: C4Network2.h:169
void DeactivateInactiveClients()
bool LeagueUpdate()
C4GameControl Control
uint32_t iLastReferenceUpdate
Definition: C4Network2.h:164
void DoInput(C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)
bool isNull() const
Definition: C4Network2Res.h:83
C4Network2ResCore ResDynamic
Definition: C4Network2.h:133
C4TimeMilliseconds tLastActivateRequest
Definition: C4Network2.h:161
C4ControlVoteType getType() const
Definition: C4Control.h:590
C4Network2ClientList Clients
Definition: C4Network2.h:116
int32_t getData() const
Definition: C4Control.h:592
bool StreamOut()
bool LeagueUpdateProcessReply()
bool IsInfinite() const
void UpdateChaseTarget()
bool fHost
Definition: C4Network2.h:127
C4Control Votes
Definition: C4Network2.h:181
bool fStreaming
Definition: C4Network2.h:187
C4LeagueAction getCurrentAction() const
Definition: C4League.h:216
const unsigned int C4NetVotingTimeout
Definition: C4Network2.h:52
void RequestActivate()
C4PacketBase * getPkt() const
Definition: C4PacketBase.h:255
void CheckStatusReached(bool fFromFinalInit=false)

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2::FinalInit ( )

Definition at line 560 of file C4Network2.cpp.

References Application, C4GUI::MessageDialog::btnAbort, CheckStatusReached(), Clear(), C4GUI::MessageDialog::dsSmall, C4GUI::Dialog::Execute(), C4AbstractApp::FlushMessages(), fStatusAck, fStatusReached, Game, C4GUI::Dialog::IsAborted(), C4Application::isEditor, isEnabled(), isHost(), LoadResStr(), Log(), pGUI, StdScheduler::ScheduleProcs(), C4GUI::Dialog::Show(), C4Game::SyncClearance(), and C4Game::Synchronize().

Referenced by C4Game::Init().

561 {
562  // check reach
563  CheckStatusReached(true);
564  // reached, waiting for ack?
565  if (fStatusReached && !fStatusAck)
566  {
567  // wait for go acknowledgement
568  Log(LoadResStr("IDS_NET_JOINREADY"));
569 
570  // any pending keyboard commands should not be routed to cancel the wait dialog - flush the message queue!
571  if (!Application.FlushMessages()) return false;
572 
573  // show box
574  C4GUI::Dialog *pDlg = nullptr;
575  if (!Application.isEditor)
576  {
577  // separate dlgs for host/client
578  if (isHost())
579  pDlg = new C4Network2StartWaitDlg();
580  else
581  pDlg = new C4GUI::MessageDialog(LoadResStr("IDS_NET_WAITFORSTART"), LoadResStr("IDS_NET_CAPTION"),
583  // show it
584  if (!pDlg->Show(::pGUI, true)) return false;
585  }
586 
587  // wait for acknowledgement
588  while (fStatusReached && !fStatusAck)
589  {
590  if (pDlg)
591  {
592  // execute
593  if (!pDlg->Execute()) { delete pDlg; Clear(); return false; }
594  // aborted?
595  if (pDlg->IsAborted()) { delete pDlg; Clear(); return false; }
596  }
597  else if (!Application.ScheduleProcs())
598  { Clear(); return false; }
599  }
600  delete pDlg;
601  // log
602  Log(LoadResStr("IDS_NET_START"));
603  }
604  // synchronize
606  Game.Synchronize(false);
607  // finished
608  return isEnabled();
609 }
bool fStatusAck
Definition: C4Network2.h:140
bool fStatusReached
Definition: C4Network2.h:140
bool isHost() const
Definition: C4Network2.h:209
void SyncClearance()
Definition: C4Game.cpp:3133
C4Game Game
Definition: C4Globals.cpp:52
bool IsAborted()
Definition: C4Gui.h:2149
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
bool FlushMessages()
Definition: C4AppSDL.cpp:119
bool Show(Screen *pOnScreen, bool fCB)
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1194
void Clear()
Definition: C4Network2.cpp:734
bool isEnabled() const
Definition: C4Network2.h:203
void Synchronize(bool fSavePlayerFiles)
Definition: C4Game.cpp:3139
bool Log(const char *szMessage)
Definition: C4Log.cpp:195
bool ScheduleProcs(int iTimeout=1000/36)
void CheckStatusReached(bool fFromFinalInit=false)
C4Application Application
Definition: C4Globals.cpp:44

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2::FinishStreaming ( )

Definition at line 2932 of file C4Network2.cpp.

References fStreaming, iLastStreamAttempt, pStreamedRecord, StreamIn(), and StreamOut().

2933 {
2934  if (!fStreaming) return false;
2935 
2936  // Stream
2937  StreamIn(true);
2938 
2939  // Reset record pointer
2940  pStreamedRecord = nullptr;
2941 
2942  // Try to get rid of remaining data immediately
2943  iLastStreamAttempt = 0;
2944  StreamOut();
2945 
2946  return true;
2947 }
bool StreamIn(bool fFinish)
C4Record * pStreamedRecord
Definition: C4Network2.h:189
time_t iLastStreamAttempt
Definition: C4Network2.h:188
bool StreamOut()
bool fStreaming
Definition: C4Network2.h:187

Here is the call graph for this function:

class C4GameLobby::MainDlg* C4Network2::GetLobby ( ) const
inline

Definition at line 216 of file C4Network2.h.

References pLobby.

Referenced by C4GameLobby::Countdown::Abort(), C4GameLobby::Countdown::Countdown(), C4Network2Players::HandlePlayerInfo(), C4Network2Players::HandlePlayerInfoUpdRequest(), C4GameLobby::LobbyError(), Log(), OnClientConnect(), C4GameLobby::Countdown::OnSec1Timer(), and C4MessageInput::ProcessCommand().

216 { return pLobby; } // lobby publication
C4GameLobby::MainDlg * pLobby
Definition: C4Network2.h:147

Here is the caller graph for this function:

StdStrBuf C4Network2::getNetpuncherAddr ( ) const
inline

Definition at line 309 of file C4Network2.h.

References NetpuncherAddr.

Referenced by C4Network2Reference::InitLocal(), and InitPuncher().

309 { return NetpuncherAddr; }
StdCopyStrBuf NetpuncherAddr
Definition: C4Network2.h:198

Here is the caller graph for this function:

C4NetpuncherID::value & C4Network2::getNetpuncherGameID ( C4NetIO::HostAddress::AddressFamily  family)

Definition at line 1027 of file C4Network2.cpp.

References C4NetIO::HostAddress::IPv4, C4NetIO::HostAddress::IPv6, NetpuncherGameID, C4NetIO::HostAddress::UnknownFamily, C4NetpuncherID::v4, and C4NetpuncherID::v6.

Referenced by C4Network2Reference::InitLocal().

1028 {
1029  switch (family)
1030  {
1033  case C4NetIO::HostAddress::UnknownFamily: assert(!"Unexpected address family");
1034  }
1035  // We need to return a valid reference to satisfy the compiler, even though the code here is unreachable.
1036  return NetpuncherGameID.v4;
1037 }
C4NetpuncherID NetpuncherGameID
Definition: C4Network2.h:197

Here is the caller graph for this function:

C4NetpuncherID C4Network2::getNetpuncherGameID ( ) const
inline

Definition at line 308 of file C4Network2.h.

References NetpuncherGameID.

Referenced by HandlePuncherPacket(), and OnPuncherConnect().

308 { return NetpuncherGameID; };
C4NetpuncherID NetpuncherGameID
Definition: C4Network2.h:197

Here is the caller graph for this function:

const char* C4Network2::GetPassword ( ) const
inline

Definition at line 217 of file C4Network2.h.

References StdStrBuf::getData().

Referenced by C4GameOptionButtons::OnBtnPassword(), and C4GameOptionButtons::UpdatePasswordBtn().

217 { return sPassword.getData(); } // Oh noez, now the password is public!
const char * getData() const
Definition: StdBuf.h:450
StdStrBuf sPassword
Definition: C4Network2.h:172

Here is the call graph for this function:

Here is the caller graph for this function:

size_t C4Network2::getPendingStreamData ( ) const
inline

Definition at line 300 of file C4Network2.h.

References StdBuf::getSize().

Referenced by DrawStatus(), StreamIn(), and StreamOut().

300 { return StreamingBuf.getSize() - StreamCompressor.avail_out; }
StdBuf StreamingBuf
Definition: C4Network2.h:190
size_t getSize() const
Definition: StdBuf.h:109
z_stream StreamCompressor
Definition: C4Network2.h:191

Here is the call graph for this function:

Here is the caller graph for this function:

C4IDPacket * C4Network2::GetVote ( int32_t  iClientID,
C4ControlVoteType  eType,
int32_t  iData 
)

Definition at line 2729 of file C4Network2.cpp.

References C4ClientIDUnknown, CID_Vote, C4Control::firstPkt(), C4ControlPacket::getByClient(), C4ControlVote::getData(), C4ControlVote::getType(), C4Control::nextPkt(), and Votes.

Referenced by EndVote(), OpenVoteDialog(), and Vote().

2730 {
2731  C4ControlVote *pVote;
2732  for (C4IDPacket *pPkt = Votes.firstPkt(); pPkt; pPkt = Votes.nextPkt(pPkt))
2733  if (pPkt->getPktType() == CID_Vote)
2734  if ((pVote = static_cast<C4ControlVote *>(pPkt->getPkt())))
2735  if (iClientID == C4ClientIDUnknown || pVote->getByClient() == iClientID)
2736  if (pVote->getType() == eType && pVote->getData() == iData)
2737  return pPkt;
2738  return nullptr;
2739 }
C4IDPacket * firstPkt() const
Definition: C4Control.h:78
int32_t getByClient() const
Definition: C4Control.h:42
const int32_t C4ClientIDUnknown
Definition: C4Client.h:24
C4ControlVoteType getType() const
Definition: C4Control.h:590
int32_t getData() const
Definition: C4Control.h:592
C4IDPacket * nextPkt(C4IDPacket *pPkt) const
Definition: C4Control.h:79
C4Control Votes
Definition: C4Network2.h:181

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::HandleActivateReq ( int32_t  iTick,
C4Network2Client pClient 
)
protected

Definition at line 1515 of file C4Network2.cpp.

References C4NetMaxBehind4Activation, CDT_Sync, CID_ClientUpdate, Clamp(), Control, CUT_Activate, C4GameControl::DoInput(), C4Game::FPS, C4Game::FrameCounter, Game, C4Network2Client::getID(), C4Network2Client::getMsgConn(), C4Network2IOConnection::getPingTime(), C4Network2Client::isActivated(), isHost(), C4Network2Client::isObserver(), isRunning(), and C4Network2Client::isWaitedFor().

Referenced by HandlePacket().

1516 {
1517  if (!isHost()) return;
1518  // not allowed or already activated? ignore
1519  if (pByClient->isObserver() || pByClient->isActivated()) return;
1520  // not joined completely yet? ignore
1521  if (!pByClient->isWaitedFor()) return;
1522  // check behind limit
1523  if (isRunning())
1524  {
1525  // make a guess how much the client lags.
1526  int32_t iLagFrames = Clamp(pByClient->getMsgConn()->getPingTime() * Game.FPS / 500, 0, 100);
1527  if (iTick < Game.FrameCounter - iLagFrames - C4NetMaxBehind4Activation)
1528  return;
1529  }
1530  // activate him
1532  new C4ControlClientUpdate(pByClient->getID(), CUT_Activate, true),
1533  CDT_Sync);
1534 }
bool isHost() const
Definition: C4Network2.h:209
bool isRunning() const
Definition: C4Network2.h:206
C4Game Game
Definition: C4Globals.cpp:52
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:46
int32_t FrameCounter
Definition: C4Game.h:130
int32_t FPS
Definition: C4Game.h:113
C4GameControl Control
void DoInput(C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)
const int C4NetMaxBehind4Activation
Definition: C4Network2.h:41

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::HandleConn ( const class C4PacketConn Pkt,
C4Network2IOConnection pConn,
C4Network2Client pClient 
)
protected

Definition at line 1244 of file C4Network2.cpp.

References C4ClientIDUnknown, CheckConn(), Clients, C4Network2IOConnection::Close(), StdStrBuf::Format(), fWrongPassword, C4PacketConn::getCCore(), C4Network2ClientList::GetClient(), StdStrBuf::getData(), C4Network2ClientList::GetHost(), C4ClientCore::getID(), C4ClientCore::getName(), C4PacketConn::getPassword(), C4Network2IOConnection::getPeerAddr(), C4Network2Status::getState(), C4PacketConn::getVer(), GS_Init, HostConnect(), C4Network2IOConnection::isClosed(), C4Network2IOConnection::isHalfAccepted(), isHost(), StdStrBuf::isNull(), Join(), LogSilentF(), MkC4NetIOPacket(), PID_ConnRe, C4Network2IOConnection::Send(), SEqual(), C4Network2IOConnection::SetCCore(), C4Network2IOConnection::SetHalfAccepted(), sPassword, Status, and C4NetIO::EndpointAddress::ToString().

Referenced by HandlePacket().

1245 {
1246  // security
1247  if (!pConn) return;
1248 
1249  // Handles a connect request (packet PID_Conn).
1250  // Check if this peer should be allowed to connect, make space for the new connection.
1251 
1252  // connection is closed?
1253  if (pConn->isClosed())
1254  return;
1255 
1256  // set up core
1257  const C4ClientCore &CCore = Pkt.getCCore();
1258  C4ClientCore NewCCore = CCore;
1259 
1260  // accept connection?
1261  StdStrBuf reply;
1262  bool fOK = false;
1263 
1264  // search client
1265  if (!pClient && Pkt.getCCore().getID() != C4ClientIDUnknown)
1266  pClient = Clients.GetClient(Pkt.getCCore());
1267 
1268  // check engine version
1269  bool fWrongPassword = false;
1270  if (Pkt.getVer() != C4XVER1*100 + C4XVER2)
1271  {
1272  reply.Format("wrong engine (%d.%d, I have %d.%d)", Pkt.getVer()/100, Pkt.getVer()%100, C4XVER1, C4XVER2);
1273  fOK = false;
1274  }
1275  else
1276  {
1277  if (pClient)
1278  if (CheckConn(NewCCore, pConn, pClient, &reply))
1279  {
1280  // accept
1281  if (!reply) reply = "connection accepted";
1282  fOK = true;
1283  }
1284  // client: host connection?
1285  if (!fOK && !isHost() && Status.getState() == GS_Init && !Clients.GetHost())
1286  if (HostConnect(NewCCore, pConn, &reply))
1287  {
1288  // accept
1289  if (!reply) reply = "host connection accepted";
1290  fOK = true;
1291  }
1292  // host: client join? (NewCCore will be changed by Join()!)
1293  if (!fOK && isHost() && !pClient)
1294  {
1295  // check password
1296  if (!sPassword.isNull() && !SEqual(Pkt.getPassword(), sPassword.getData()))
1297  {
1298  reply = "wrong password";
1299  fWrongPassword = true;
1300  }
1301  // accept join
1302  else if (Join(NewCCore, pConn, &reply))
1303  {
1304  // save core
1305  pConn->SetCCore(NewCCore);
1306  // accept
1307  if (!reply) reply = "join accepted";
1308  fOK = true;
1309  }
1310  }
1311  }
1312 
1313  // denied? set default reason
1314  if (!fOK && !reply) reply = "connection denied";
1315 
1316  // OK and already half accepted? Skip (double-checked: ok).
1317  if (fOK && pConn->isHalfAccepted())
1318  return;
1319 
1320  // send answer
1321  C4PacketConnRe pcr(fOK, fWrongPassword, reply.getData());
1322  if (!pConn->Send(MkC4NetIOPacket(PID_ConnRe, pcr)))
1323  return;
1324 
1325  // accepted?
1326  if (fOK)
1327  {
1328  // set status
1329  if (!pConn->isClosed())
1330  pConn->SetHalfAccepted();
1331  }
1332  // denied? close
1333  else
1334  {
1335  // log & close
1336  LogSilentF("Network: connection by %s (%s) blocked: %s", CCore.getName(), pConn->getPeerAddr().ToString().getData(), reply.getData());
1337  pConn->Close();
1338  }
1339 }
const char * getData() const
Definition: StdBuf.h:450
bool CheckConn(const C4ClientCore &CCore, C4Network2IOConnection *pConn, C4Network2Client *pClient, StdStrBuf *szReply)
bool isHost() const
Definition: C4Network2.h:209
void SetCCore(const C4ClientCore &nCCore)
StdStrBuf ToString(int flags=0) const
Definition: C4NetIO.cpp:605
bool Send(const C4NetIOPacket &rPkt)
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:181
C4Network2Client * GetClient(const char *szName) const
int32_t getID() const
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97
const C4NetIO::addr_t & getPeerAddr() const
Definition: C4Network2IO.h:262
bool isHalfAccepted() const
Definition: C4Network2IO.h:284
bool LogSilentF(const char *strMessage,...)
Definition: C4Log.cpp:263
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
C4Network2Status Status
Definition: C4Network2.h:122
bool fWrongPassword
Definition: C4Network2.h:175
const int32_t C4ClientIDUnknown
Definition: C4Client.h:24
C4NetGameState getState() const
Definition: C4Network2.h:80
C4Network2ClientList Clients
Definition: C4Network2.h:116
bool isNull() const
Definition: StdBuf.h:449
bool HostConnect(const C4ClientCore &CCore, C4Network2IOConnection *pConn, StdStrBuf *szReply)
StdStrBuf sPassword
Definition: C4Network2.h:172
const char * getName() const
Definition: C4Client.h:69
C4Network2Client * GetHost()
bool isClosed() const
Definition: C4Network2IO.h:286
bool Join(C4ClientCore &CCore, C4Network2IOConnection *pConn, StdStrBuf *szReply)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::HandleConnRe ( const class C4PacketConnRe Pkt,
C4Network2IOConnection pConn,
C4Network2Client pClient 
)
protected

Definition at line 1409 of file C4Network2.cpp.

References C4Network2Client::AddAddr(), C4Network2IOConnection::Close(), C4Network2IO::DataIO(), fWrongPassword, C4Network2IOConnection::getConnectAddr(), C4Network2Client::getCore(), StdStrBuf::getData(), C4PacketConnRe::getMsg(), C4Network2Client::getName(), C4Network2IOConnection::getNetClass(), C4Network2IOConnection::getPeerAddr(), C4Network2IOConnection::getProtocol(), C4Network2Status::getState(), GS_Init, C4Network2IOConnection::isAccepted(), C4Network2IOConnection::isAutoAccepted(), C4Network2Client::isConnected(), C4NetIO::EndpointAddress::IsNull(), C4PacketConnRe::isOK(), C4Network2IOConnection::isOpen(), C4PacketConnRe::isPasswordWrong(), LogSilentF(), C4Network2IO::MsgIO(), NetIO, OnConnect(), C4Network2IOConnection::ResetAutoAccepted(), C4Network2IOConnection::SetAccepted(), C4Network2IOConnection::SetCCore(), C4Network2Client::SetDataConn(), C4Network2Client::SetMsgConn(), Status, and C4NetIO::EndpointAddress::ToString().

Referenced by HandlePacket().

1410 {
1411  // Handle the connection request reply. After this handling, the connection should
1412  // be either fully associated with a client (fully accepted) or closed.
1413  // Note that auto-accepted connection have to processed here once, too, as the
1414  // client must get associated with the connection. After doing so, the connection
1415  // auto-accept flag will be reset to mark the connection fully accepted.
1416 
1417  // security
1418  if (!pConn) return;
1419  if (!pClient) { pConn->Close(); return; }
1420 
1421  // negative reply?
1422  if (!Pkt.isOK())
1423  {
1424  // wrong password?
1425  fWrongPassword = Pkt.isPasswordWrong();
1426  // show message
1427  LogSilentF("Network: connection to %s (%s) refused: %s", pClient->getName(), pConn->getPeerAddr().ToString().getData(), Pkt.getMsg());
1428  // close connection
1429  pConn->Close();
1430  return;
1431  }
1432 
1433  // connection is closed?
1434  if (!pConn->isOpen())
1435  return;
1436 
1437  // already accepted? ignore
1438  if (pConn->isAccepted() && !pConn->isAutoAccepted()) return;
1439 
1440  // first connection?
1441  bool fFirstConnection = !pClient->isConnected();
1442 
1443  // accept connection
1444  pConn->SetAccepted(); pConn->ResetAutoAccepted();
1445 
1446  // add connection
1447  pConn->SetCCore(pClient->getCore());
1448  if (pConn->getNetClass() == NetIO.MsgIO()) pClient->SetMsgConn(pConn);
1449  if (pConn->getNetClass() == NetIO.DataIO()) pClient->SetDataConn(pConn);
1450 
1451  // add peer connect address to client address list
1452  if (!pConn->getConnectAddr().IsNull())
1453  {
1454  C4Network2Address Addr(pConn->getConnectAddr(), pConn->getProtocol());
1455  pClient->AddAddr(Addr, Status.getState() != GS_Init);
1456  }
1457 
1458  // handle
1459  OnConnect(pClient, pConn, Pkt.getMsg(), fFirstConnection);
1460 }
const char * getData() const
Definition: StdBuf.h:450
C4Network2IO NetIO
Definition: C4Network2.h:110
void SetCCore(const C4ClientCore &nCCore)
StdStrBuf ToString(int flags=0) const
Definition: C4NetIO.cpp:605
const C4NetIO::addr_t & getPeerAddr() const
Definition: C4Network2IO.h:262
C4NetIO * MsgIO()
bool isConnected() const
const C4NetIO::addr_t & getConnectAddr() const
Definition: C4Network2IO.h:263
C4Network2IOProtocol getProtocol() const
Definition: C4Network2IO.h:261
bool LogSilentF(const char *strMessage,...)
Definition: C4Log.cpp:263
bool isAccepted() const
Definition: C4Network2IO.h:285
const C4ClientCore & getCore() const
void SetMsgConn(C4Network2IOConnection *pConn)
void SetDataConn(C4Network2IOConnection *pConn)
C4Network2Status Status
Definition: C4Network2.h:122
const char * getName() const
bool fWrongPassword
Definition: C4Network2.h:175
C4NetGameState getState() const
Definition: C4Network2.h:80
C4NetIO * DataIO()
void OnConnect(C4Network2Client *pClient, C4Network2IOConnection *pConn, const char *szMsg, bool fFirstConnection)
bool IsNull() const
Definition: C4NetIO.cpp:509
bool isAutoAccepted() const
Definition: C4Network2IO.h:287
C4NetIO * getNetClass() const
Definition: C4Network2IO.h:260
bool AddAddr(const C4Network2Address &addr, bool fAnnounce)
bool isOpen() const
Definition: C4Network2IO.h:283

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::HandleJoinData ( const class C4PacketJoinData rPkt)
protected

Definition at line 1536 of file C4Network2.cpp.

References C4Network2ResList::AddByCore(), C4ClientIDUnknown, Clear(), C4Game::Clients, Clients, C4GameParameters::Clients, Control, C4GameControl::ControlRate, C4GameParameters::ControlRate, C4GameControlNetwork::CopyClientList(), Game, C4GameParameters::GameRes, C4ClientList::getClientByID(), C4PacketJoinData::getClientID(), C4Client::getCore(), C4PacketJoinData::getDynamicCore(), C4PacketJoinData::getStartCtrlTick(), C4Network2Status::getState(), C4Network2Status::getStateName(), C4PacketJoinData::getStatus(), GS_Go, GS_Init, GS_Lobby, GS_Pause, HandleStatus(), iDynamicTick, C4GameControlNetwork::Init(), C4GameResList::InitNetwork(), C4Client::isActivated(), C4PlayerInfoList::LoadResources(), LogFatal(), LogSilentF(), NetIO, C4Game::Parameters, C4PacketJoinData::Parameters, pControl, C4GameParameters::PlayerInfos, ResDynamic, ResList, C4Game::ScenarioParameterDefs, C4PacketJoinData::ScenarioParameterDefs, C4Network2ClientList::SendAddresses(), C4Network2IO::SetLocalCCore(), C4ClientList::SetLocalID(), C4Network2ResList::SetLocalID(), and Status.

Referenced by HandlePacket().

1537 {
1538  // init only
1539  if (Status.getState() != GS_Init)
1540  { LogSilentF("Network: unexpected join data received!"); return; }
1541  // get client ID
1542  if (rPkt.getClientID() == C4ClientIDUnknown)
1543  { LogSilentF("Network: host didn't set client ID!"); Clear(); return; }
1544  // set local ID
1545  ResList.SetLocalID(rPkt.getClientID());
1546  Game.Parameters.Clients.SetLocalID(rPkt.getClientID());
1547  // read and validate status
1548  HandleStatus(rPkt.getStatus());
1549  if (Status.getState() != GS_Lobby && Status.getState() != GS_Pause && Status.getState() != GS_Go)
1550  { LogSilentF("Network: join data has bad game status: %s", Status.getStateName()); Clear(); return; }
1551  // copy scenario parameter defs for lobby display
1552  ::Game.ScenarioParameterDefs = rPkt.ScenarioParameterDefs;
1553  // copy parameters
1554  ::Game.Parameters = rPkt.Parameters;
1555  // set local client
1556  C4Client *pLocalClient = Game.Clients.getClientByID(rPkt.getClientID());
1557  if (!pLocalClient)
1558  { LogSilentF("Network: Could not find local client in join data!"); Clear(); return; }
1559  // save back dynamic data
1560  ResDynamic = rPkt.getDynamicCore();
1561  iDynamicTick = rPkt.getStartCtrlTick();
1562  // initialize control
1563  ::Control.ControlRate = rPkt.Parameters.ControlRate;
1564  pControl->Init(rPkt.getClientID(), false, rPkt.getStartCtrlTick(), pLocalClient->isActivated(), this);
1566  // set local core
1567  NetIO.SetLocalCCore(pLocalClient->getCore());
1568  // add the resources to the network resource list
1570  // load dynamic
1572  { LogFatal("Network: can not not retrieve dynamic!"); Clear(); return; }
1573  // load player resources
1575  // send additional addresses
1576  Clients.SendAddresses(nullptr);
1577 }
bool InitNetwork(C4Network2ResList *pNetResList)
void SetLocalID(int32_t iID)
Definition: C4Client.cpp:341
C4Network2Res::Ref AddByCore(const C4Network2ResCore &Core, bool fLoad=true)
C4Network2IO NetIO
Definition: C4Network2.h:110
C4Game Game
Definition: C4Globals.cpp:52
bool isActivated() const
Definition: C4Client.h:110
void HandleStatus(const C4Network2Status &nStatus)
C4ClientList Clients
class C4ScenarioParameterDefs & ScenarioParameterDefs
Definition: C4Game.h:77
int32_t iDynamicTick
Definition: C4Network2.h:136
C4GameParameters & Parameters
Definition: C4Game.h:69
void CopyClientList(const C4ClientList &rClients)
bool LogSilentF(const char *strMessage,...)
Definition: C4Log.cpp:263
C4GameControl Control
const C4ClientCore & getCore() const
Definition: C4Client.h:104
C4GameResList GameRes
const char * getStateName() const
Definition: C4Network2.cpp:62
C4Network2ResCore ResDynamic
Definition: C4Network2.h:133
C4Network2Status Status
Definition: C4Network2.h:122
void Clear()
Definition: C4Network2.cpp:734
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:230
const int32_t C4ClientIDUnknown
Definition: C4Client.h:24
C4Network2ResList ResList
Definition: C4Network2.h:113
C4NetGameState getState() const
Definition: C4Network2.h:80
void SetLocalCCore(const C4ClientCore &CCore)
C4Network2ClientList Clients
Definition: C4Network2.h:116
C4Client * getClientByID(int32_t iID) const
Definition: C4Client.cpp:217
bool Init(int32_t iClientID, bool fHost, int32_t iStartTick, bool fActivated, C4Network2 *pNetwork)
C4PlayerInfoList PlayerInfos
C4ClientList & Clients
Definition: C4Game.h:71
void SetLocalID(int32_t iClientID)
int32_t ControlRate
Definition: C4GameControl.h:88
class C4GameControlNetwork * pControl
Definition: C4Network2.h:144
void SendAddresses(C4Network2IOConnection *pConn)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::HandleLobbyPacket ( char  cStatus,
const C4PacketBase pBasePkt,
C4Network2IOConnection pConn 
)

Definition at line 985 of file C4Network2.cpp.

References Clients, C4Network2ClientList::GetClient(), C4Network2ClientList::GetClientByID(), C4Network2IOConnection::getClientID(), C4GameLobby::MainDlg::HandlePacket(), and pLobby.

Referenced by C4Network2IO::CallHandlers().

986 {
987  // find associated client
988  C4Network2Client *pClient = Clients.GetClient(pConn);
989  if (!pClient) pClient = Clients.GetClientByID(pConn->getClientID());
990  // forward directly to lobby
991  if (pLobby) pLobby->HandlePacket(cStatus, pBasePkt, pClient);
992 }
C4Network2Client * GetClientByID(int32_t iID) const
void HandlePacket(char cStatus, const C4PacketBase *pBasePkt, C4Network2Client *pClient)
C4Network2Client * GetClient(const char *szName) const
int getClientID() const
Definition: C4Network2IO.h:269
C4GameLobby::MainDlg * pLobby
Definition: C4Network2.h:147
C4Network2ClientList Clients
Definition: C4Network2.h:116

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::HandlePacket ( char  cStatus,
const C4PacketBase pBasePkt,
C4Network2IOConnection pConn 
)

Definition at line 901 of file C4Network2.cpp.

References Clients, C4Network2IOConnection::Close(), C4Network2ClientList::GetClient(), C4Network2ClientList::GetClientByID(), C4Network2IOConnection::getClientID(), GETPKT, C4Network2Status::getState(), GS_Init, HandleActivateReq(), HandleConn(), HandleConnRe(), HandleJoinData(), HandleStatus(), HandleStatusAck(), C4Network2Client::isHost(), isHost(), C4Network2Client::isLocal(), C4Network2IOConnection::isOpen(), PID_ClientActReq, PID_Conn, PID_ConnRe, PID_JoinData, PID_Status, PID_StatusAck, and Status.

Referenced by C4Network2IO::CallHandlers().

902 {
903  // find associated client
904  C4Network2Client *pClient = Clients.GetClient(pConn);
905  if (!pClient) pClient = Clients.GetClientByID(pConn->getClientID());
906 
907  // local? ignore
908  if (pClient && pClient->isLocal()) { pConn->Close(); return; }
909 
910 #define GETPKT(type, name) \
911  assert(pPacket); const type &name = \
912  static_cast<const type &>(*pPacket);
913 
914  switch (cStatus)
915  {
916  case PID_Conn: // connection request
917  {
918  if (!pConn->isOpen()) break;
919  GETPKT(C4PacketConn, rPkt);
920  HandleConn(rPkt, pConn, pClient);
921  }
922  break;
923 
924  case PID_ConnRe: // connection request reply
925  {
926  GETPKT(C4PacketConnRe, rPkt);
927  HandleConnRe(rPkt, pConn, pClient);
928  }
929  break;
930 
931  case PID_JoinData:
932  {
933  // host->client only
934  if (isHost() || !pClient || !pClient->isHost()) break;
935  if (!pConn->isOpen()) break;
936  // handle
937  GETPKT(C4PacketJoinData, rPkt)
938  HandleJoinData(rPkt);
939  }
940  break;
941 
942  case PID_Status: // status change
943  {
944  // by host only
945  if (isHost() || !pClient || !pClient->isHost()) break;
946  if (!pConn->isOpen()) break;
947  // must be initialized
948  if (Status.getState() == GS_Init) break;
949  // handle
950  GETPKT(C4Network2Status, rPkt);
951  HandleStatus(rPkt);
952  }
953  break;
954 
955  case PID_StatusAck: // status change acknowledgement
956  {
957  // host->client / client->host only
958  if (!pClient) break;
959  if (!isHost() && !pClient->isHost()) break;
960  // must be initialized
961  if (Status.getState() == GS_Init) break;
962  // handle
963  GETPKT(C4Network2Status, rPkt);
964  HandleStatusAck(rPkt, pClient);
965  }
966  break;
967 
968  case PID_ClientActReq: // client activation request
969  {
970  // client->host only
971  if (!isHost() || !pClient || pClient->isHost()) break;
972  // must be initialized
973  if (Status.getState() == GS_Init) break;
974  // handle
976  HandleActivateReq(rPkt.getTick(), pClient);
977  }
978  break;
979 
980  }
981 
982 #undef GETPKT
983 }
void HandleConnRe(const class C4PacketConnRe &Pkt, C4Network2IOConnection *pConn, C4Network2Client *pClient)
C4Network2Client * GetClientByID(int32_t iID) const
bool isHost() const
Definition: C4Network2.h:209
void HandleStatus(const C4Network2Status &nStatus)
C4Network2Client * GetClient(const char *szName) const
#define GETPKT(type, name)
void HandleConn(const class C4PacketConn &Pkt, C4Network2IOConnection *pConn, C4Network2Client *pClient)
void HandleJoinData(const class C4PacketJoinData &rPkt)
int getClientID() const
Definition: C4Network2IO.h:269
void HandleActivateReq(int32_t iTick, C4Network2Client *pClient)
C4Network2Status Status
Definition: C4Network2.h:122
void HandleStatusAck(const C4Network2Status &nStatus, C4Network2Client *pClient)
C4NetGameState getState() const
Definition: C4Network2.h:80
C4Network2ClientList Clients
Definition: C4Network2.h:116
bool isLocal() const
bool isOpen() const
Definition: C4Network2IO.h:283
bool isHost() const

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2::HandlePuncherPacket ( C4NetpuncherPacket::uptr  pkt,
C4NetIO::HostAddress::AddressFamily  family 
)

Definition at line 994 of file C4Network2.cpp.

References getNetpuncherGameID(), GETPKT, C4Network2Status::getState(), GS_Init, InvalidateReference(), isHost(), NetIO, PID_Puncher_AssID, PID_Puncher_CReq, C4Network2IO::Punch(), and Status.

Referenced by C4Network2IO::HandlePuncherPacket().

995 {
996  // TODO: is this all thread-safe?
997  assert(pkt);
998 #define GETPKT(c) dynamic_cast<C4NetpuncherPacket##c*>(pkt.get())
999  switch (pkt->GetType())
1000  {
1001  case PID_Puncher_CReq:
1002  if (isHost())
1003  {
1004  NetIO.Punch(GETPKT(CReq)->GetAddr());
1005  return true;
1006  }
1007  else
1008  {
1009  // The IP/Port should be already in the masterserver list, so just keep trying.
1010  return Status.getState() == GS_Init;
1011  }
1012  case PID_Puncher_AssID:
1013  if (isHost())
1014  {
1015  getNetpuncherGameID(family) = GETPKT(AssID)->GetID();
1017  }
1018  else
1019  {
1020  // The netpuncher hands out IDs for everyone, but clients have no use for them.
1021  }
1022  return true;
1023  default: return false;
1024  }
1025 }
bool isHost() const
Definition: C4Network2.h:209
C4Network2IO NetIO
Definition: C4Network2.h:110
C4NetpuncherID getNetpuncherGameID() const
Definition: C4Network2.h:308
#define GETPKT(type, name)
void Punch(const C4NetIO::addr_t &)
void InvalidateReference()
C4Network2Status Status
Definition: C4Network2.h:122
C4NetGameState getState() const
Definition: C4Network2.h:80

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::HandleStatus ( const C4Network2Status nStatus)
protected

Definition at line 1462 of file C4Network2.cpp.

References CheckStatusReached(), fStatusAck, fStatusReached, C4Network2Status::getStateName(), C4Network2Status::getTargetCtrlTick(), LogSilentF(), and Status.

Referenced by HandleJoinData(), and HandlePacket().

1463 {
1464  // set
1465  Status = nStatus;
1466  // log
1467  LogSilentF("Network: going into status %s (tick %d)", Status.getStateName(), nStatus.getTargetCtrlTick());
1468  // reset flags
1469  fStatusReached = fStatusAck = false;
1470  // check: reached?
1472 }
bool fStatusAck
Definition: C4Network2.h:140
int32_t getTargetCtrlTick() const
Definition: C4Network2.h:82
bool fStatusReached
Definition: C4Network2.h:140
bool LogSilentF(const char *strMessage,...)
Definition: C4Log.cpp:263
const char * getStateName() const
Definition: C4Network2.cpp:62
C4Network2Status Status
Definition: C4Network2.h:122
void CheckStatusReached(bool fFromFinalInit=false)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::HandleStatusAck ( const C4Network2Status nStatus,
C4Network2Client pClient 
)
protected

Definition at line 1474 of file C4Network2.cpp.

References ChangeGameStatus(), CheckStatusAck(), fChasing, fStatusAck, fStatusReached, C4Network2Status::getState(), C4Network2Status::getTargetCtrlTick(), C4Network2Client::hasJoinData(), isHost(), C4Network2Client::isRemoved(), MkC4NetIOPacket(), NCS_Ready, OnStatusAck(), PID_StatusAck, C4Network2Client::SendMsg(), C4Network2Client::SetStatus(), and Status.

Referenced by HandlePacket().

1475 {
1476  // security
1477  if (!pClient->hasJoinData() || pClient->isRemoved()) return;
1478  // status doesn't match?
1479  if (nStatus.getState() != Status.getState() || nStatus.getTargetCtrlTick() < Status.getTargetCtrlTick())
1480  return;
1481  // host: wait until all clients are ready
1482  if (isHost())
1483  {
1484  // check: target tick change?
1485  if (!fStatusAck && nStatus.getTargetCtrlTick() > Status.getTargetCtrlTick())
1486  // take the new status
1487  ChangeGameStatus(nStatus.getState(), nStatus.getTargetCtrlTick());
1488  // already acknowledged? Send another ack
1489  if (fStatusAck)
1490  pClient->SendMsg(MkC4NetIOPacket(PID_StatusAck, nStatus));
1491  // mark as ready (will clear chase-flag)
1492  pClient->SetStatus(NCS_Ready);
1493  // check: everyone ready?
1494  if (!fStatusAck && fStatusReached)
1495  CheckStatusAck();
1496  }
1497  else
1498  {
1499  // target tick doesn't match? ignore
1500  if (nStatus.getTargetCtrlTick() != Status.getTargetCtrlTick())
1501  return;
1502  // reached?
1503  // can be ignored safely otherwise - when the status is reached, we will send
1504  // status ack on which the host should generate another status ack (see above)
1505  if (fStatusReached)
1506  {
1507  // client: set flags, call handler
1508  fStatusAck = true; fChasing = false;
1509  OnStatusAck();
1510  }
1511 
1512  }
1513 }
void CheckStatusAck()
bool fStatusAck
Definition: C4Network2.h:140
int32_t getTargetCtrlTick() const
Definition: C4Network2.h:82
bool fStatusReached
Definition: C4Network2.h:140
bool isHost() const
Definition: C4Network2.h:209
void OnStatusAck()
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
bool isRemoved() const
C4Network2Status Status
Definition: C4Network2.h:122
C4NetGameState getState() const
Definition: C4Network2.h:80
void SetStatus(C4Network2ClientStatus enStatus)
bool ChangeGameStatus(C4NetGameState enState, int32_t iTargetCtrlTick, int32_t iCtrlMode=-1)
bool hasJoinData() const
bool SendMsg(C4NetIOPacket rPkt) const
bool fChasing
Definition: C4Network2.h:141

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2::HostConnect ( const C4ClientCore CCore,
C4Network2IOConnection pConn,
StdStrBuf szReply 
)
protected

Definition at line 1354 of file C4Network2.cpp.

References C4ClientList::Add(), C4Game::Clients, Game, and C4ClientCore::isHost().

Referenced by HandleConn().

1355 {
1356  if (!pConn) return false;
1357  if (!CCore.isHost()) { *szReply = "not host"; return false; }
1358  // create client class for host
1359  // (core is unofficial, see InitClient() - will be overwritten later in HandleJoinData)
1360  C4Client *pClient = Game.Clients.Add(CCore);
1361  if (!pClient) return false;
1362  // accept
1363  return true;
1364 }
C4Game Game
Definition: C4Globals.cpp:52
bool isHost() const
Definition: C4Client.h:58
C4ClientList & Clients
Definition: C4Game.h:71
void Add(C4Client *pClient)
Definition: C4Client.cpp:198

Here is the call graph for this function:

Here is the caller graph for this function:

InitResult C4Network2::InitClient ( const class C4Network2Reference Ref,
bool  fObserver 
)

Referenced by C4Game::InitNetworkFromReference().

Here is the caller graph for this function:

InitResult C4Network2::InitClient ( const std::vector< class C4Network2Address > &  Addrs,
const class C4ClientCore HostCore,
const char *  szPassword = nullptr 
)
bool C4Network2::InitHost ( bool  fLobby)

Definition at line 161 of file C4Network2.cpp.

References StdScheduler::Add(), Application, C4ClientIDHost, C4ClientIDStart, Clear(), C4Game::Clients, Clients, Config, Control, C4ConfigNetwork::ControlMode, C4GameControl::ControlTick, CreateDynamic(), DeinitLeague(), fAllowJoin, fChasing, fHost, fStatusAck, fStatusReached, Game, C4ClientList::getLocalID(), C4GameControl::getNextControlTick(), GS_Go, GS_Lobby, iNextClientID, C4GameControlNetwork::Init(), C4Network2ClientList::Init(), C4Network2ResList::Init(), InitLeague(), InitNetIO(), C4GameParameters::InitNetwork(), isEnabled(), LeagueStart(), LogFatal(), NetIO, NetpuncherAddr, NetpuncherGameID, C4GameControl::Network, C4Config::Network, C4Game::Parameters, pControl, C4ConfigNetwork::PuncherAddress, ResList, C4Network2Status::Set(), C4Network2IO::SetAcceptMode(), C4Network2Status::SetCtrlMode(), and Status.

Referenced by C4Game::InitNetworkHost().

162 {
163  if (isEnabled()) Clear();
164  // initialize everything
165  Status.Set(fLobby ? GS_Lobby : GS_Go, ::Control.ControlTick);
167  fHost = true;
168  fStatusAck = fStatusReached = true;
169  fChasing = false;
170  fAllowJoin = false;
174  // initialize client list
175  Clients.Init(&Game.Clients, true);
176  // initialize resource list
178  { LogFatal("Network: failed to initialize resource list!"); Clear(); return false; }
180  return false;
181  // create initial dynamic
182  if (!CreateDynamic(true))
183  return false;
184  // initialize net i/o
185  if (!InitNetIO(false, true))
186  { Clear(); return false; }
187  // init network control
189  pControl->Init(C4ClientIDHost, true, ::Control.getNextControlTick(), true, this);
190  // init league
191  bool fCancel = true;
192  if (!InitLeague(&fCancel) || !LeagueStart(&fCancel))
193  {
194  // deinit league
195  DeinitLeague();
196  // user cancelled?
197  if (fCancel)
198  return false;
199  // in console mode, bail out
200 #ifdef USE_CONSOLE
201  return false;
202 #endif
203  }
204  // allow connect
205  NetIO.SetAcceptMode(true);
206  // timer
207  Application.Add(this);
208  // ok
209  return true;
210 }
bool fStatusAck
Definition: C4Network2.h:140
C4Config Config
Definition: C4Config.cpp:831
bool InitNetIO(bool fNoClientID, bool fHost)
void Init(C4ClientList *pClientList, bool fHost)
bool fStatusReached
Definition: C4Network2.h:140
int32_t ControlTick
Definition: C4GameControl.h:89
C4Network2IO NetIO
Definition: C4Network2.h:110
C4Game Game
Definition: C4Globals.cpp:52
int32_t iNextClientID
Definition: C4Network2.h:155
void Set(C4NetGameState eState, int32_t iTargetCtrlTick)
Definition: C4Network2.cpp:88
bool InitNetwork(C4Network2ResList *pResList)
bool CreateDynamic(bool fInit)
char PuncherAddress[CFG_MaxString+1]
Definition: C4Config.h:161
bool fAllowJoin
Definition: C4Network2.h:130
void SetCtrlMode(int32_t iCtrlMode)
Definition: C4Network2.cpp:93
C4GameParameters & Parameters
Definition: C4Game.h:69
void Add(StdSchedulerProc *pProc)
bool Init(int32_t iClientID, C4Network2IO *pIOClass)
const int32_t C4ClientIDStart
Definition: C4Client.h:26
int32_t getLocalID() const
Definition: C4Client.h:171
bool InitLeague(bool *pCancel)
C4GameControl Control
bool LeagueStart(bool *pCancel)
C4ConfigNetwork Network
Definition: C4Config.h:256
void SetAcceptMode(bool fAcceptAll)
C4Network2Status Status
Definition: C4Network2.h:122
void Clear()
Definition: C4Network2.cpp:734
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:230
bool isEnabled() const
Definition: C4Network2.h:203
StdCopyStrBuf NetpuncherAddr
Definition: C4Network2.h:198
C4Network2ResList ResList
Definition: C4Network2.h:113
C4Network2ClientList Clients
Definition: C4Network2.h:116
C4GameControlNetwork Network
Definition: C4GameControl.h:67
C4NetpuncherID NetpuncherGameID
Definition: C4Network2.h:197
bool Init(int32_t iClientID, bool fHost, int32_t iStartTick, bool fActivated, C4Network2 *pNetwork)
int32_t ControlMode
Definition: C4Config.h:156
C4ClientList & Clients
Definition: C4Game.h:71
bool fHost
Definition: C4Network2.h:127
int32_t getNextControlTick() const
C4Application Application
Definition: C4Globals.cpp:44
void DeinitLeague()
const int32_t C4ClientIDHost
Definition: C4Client.h:25
class C4GameControlNetwork * pControl
Definition: C4Network2.h:144
bool fChasing
Definition: C4Network2.h:141

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2::InitLeague ( bool *  pCancel)
protected

Definition at line 2071 of file C4Network2.cpp.

References StdScheduler::Add(), Application, C4GUI::MessageDialog::btnAbort, C4GUI::MessageDialog::btnOK, C4Game::C4S, StdStrBuf::Clear(), Config, C4GameParameters::EnforceLeagueRules(), fHost, FormatString(), Game, StdStrBuf::getData(), C4NetIO::GetError(), C4ConfigNetwork::GetLeagueServerAddress(), StdStrBuf::getLength(), C4GUI::Ico_Error, C4NetIOTCP::Init(), C4Application::isEditor, C4GameParameters::League, C4GameParameters::LeagueAddress, C4ConfigNetwork::LeagueServerSignUp, LoadResStr(), LogFatal(), MasterServerAddress, C4ConfigNetwork::MasterServerSignUp, C4Config::Network, C4Game::Parameters, pGUI, pLeagueClient, C4Network2HTTPClient::SetServer(), and C4GUI::Screen::ShowMessageModal().

Referenced by InitHost(), and LeagueSignupEnable().

2072 {
2073 
2074  if (fHost)
2075  {
2076 
2077  // Clear parameters
2081  if (pLeagueClient) delete pLeagueClient; pLeagueClient = nullptr;
2082 
2083  // Not needed?
2085  return true;
2086 
2087  // Save address
2090  {
2092  // enforce some league rules
2094  }
2095 
2096  }
2097  else
2098  {
2099 
2100  // Get league server from parameters
2102 
2103  // Not needed?
2105  return true;
2106 
2107  }
2108 
2109  // Init
2110  pLeagueClient = new C4LeagueClient();
2111  if (!pLeagueClient->Init() ||
2113  {
2114  // Log message
2115  StdStrBuf Message = FormatString(LoadResStr("IDS_NET_ERR_LEAGUEINIT"), pLeagueClient->GetError());
2116  LogFatal(Message.getData());
2117  // Clear league
2118  delete pLeagueClient; pLeagueClient = nullptr;
2119  if (fHost)
2121  // Show message, allow abort
2122  bool fResult = true;
2123  if (!Application.isEditor)
2124  fResult = ::pGUI->ShowMessageModal(Message.getData(), LoadResStr("IDS_NET_ERR_LEAGUE"),
2127  if (pCancel) *pCancel = fResult;
2128  return false;
2129  }
2130 
2131  // Add to message loop
2132  Application.Add(pLeagueClient);
2133 
2134  // OK
2135  return true;
2136 }
const char * getData() const
Definition: StdBuf.h:450
C4Config Config
Definition: C4Config.cpp:831
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:76
void Clear()
Definition: StdBuf.h:474
void EnforceLeagueRules(class C4Scenario *pScenario)
StdCopyStrBuf League
virtual const char * GetError() const
Definition: C4NetIO.h:285
StdCopyStrBuf MasterServerAddress
Definition: C4Network2.h:152
C4GameParameters & Parameters
Definition: C4Game.h:69
void Add(StdSchedulerProc *pProc)
class C4LeagueClient * pLeagueClient
Definition: C4Network2.h:169
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1194
bool ShowMessageModal(const char *szMessage, const char *szCaption, DWORD dwButtons, Icons icoIcon, int32_t *piConfigDontShowAgainSetting=nullptr)
C4ConfigNetwork Network
Definition: C4Config.h:256
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:230
int32_t LeagueServerSignUp
Definition: C4Config.h:152
int32_t MasterServerSignUp
Definition: C4Config.h:148
bool fHost
Definition: C4Network2.h:127
virtual bool Init(uint16_t iPort=addr_t::IPPORT_NONE)
Definition: C4NetIO.cpp:824
size_t getLength() const
Definition: StdBuf.h:453
StdCopyStrBuf LeagueAddress
const char * GetLeagueServerAddress()
Definition: C4Config.cpp:588
bool SetServer(const char *szServerAddress)
C4Application Application
Definition: C4Globals.cpp:44
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2::InitNetIO ( bool  fNoClientID,
bool  fHost 
)
protected

Definition at line 1221 of file C4Network2.cpp.

References C4Network2Client::AddLocalAddrs(), C4ClientIDUnknown, C4ConfigNetwork::CheckPortsForCollisions(), C4Network2IO::Clear(), C4Game::Clients, Clients, Config, C4ConfigNetwork::EnableUPnP, Game, C4Network2ClientList::GetLocal(), C4ClientList::getLocalCore(), C4Network2IO::hasTCP(), C4Network2IO::hasUDP(), C4Network2IO::Init(), NetIO, C4Config::Network, C4ConfigNetwork::PortDiscovery, C4ConfigNetwork::PortRefServer, C4ConfigNetwork::PortTCP, C4ConfigNetwork::PortUDP, C4ClientCore::SetID(), and C4Network2IO::SetLocalCCore().

Referenced by InitHost().

1222 {
1223  // clear
1224  NetIO.Clear();
1226  // discovery: disable for client
1227  int16_t iPortDiscovery = fHost ? Config.Network.PortDiscovery : -1;
1228  int16_t iPortRefServer = fHost ? Config.Network.PortRefServer : -1;
1229  // init subclass
1230  if (!NetIO.Init(Config.Network.PortTCP, Config.Network.PortUDP, iPortDiscovery, iPortRefServer, fHost, !!Config.Network.EnableUPnP))
1231  return false;
1232  // set core (unset ID if sepecified, has to be set later)
1234  if (fNoClientID) Core.SetID(C4ClientIDUnknown);
1235  NetIO.SetLocalCCore(Core);
1236  // safe addresses of local client
1238  NetIO.hasTCP() ? Config.Network.PortTCP : -1,
1239  NetIO.hasUDP() ? Config.Network.PortUDP : -1);
1240  // ok
1241  return true;
1242 }
C4Config Config
Definition: C4Config.cpp:831
int32_t PortDiscovery
Definition: C4Config.h:154
C4Network2IO NetIO
Definition: C4Network2.h:110
C4Game Game
Definition: C4Globals.cpp:52
int32_t PortRefServer
Definition: C4Config.h:154
void SetID(int32_t inID)
Definition: C4Client.h:62
const C4ClientCore & getLocalCore() const
Definition: C4Client.h:169
void CheckPortsForCollisions()
Definition: C4Config.cpp:598
C4ConfigNetwork Network
Definition: C4Config.h:256
const int32_t C4ClientIDUnknown
Definition: C4Client.h:24
void SetLocalCCore(const C4ClientCore &CCore)
C4Network2ClientList Clients
Definition: C4Network2.h:116
C4ClientList & Clients
Definition: C4Game.h:71
bool fHost
Definition: C4Network2.h:127
C4Network2Client * GetLocal() const
bool hasUDP() const
Definition: C4Network2IO.h:106
bool Init(int16_t iPortTCP, int16_t iPortUDP, int16_t iPortDiscovery=-1, int16_t iPortRefServer=-1, bool fBroadcast=false, bool enable_upnp=true)
int32_t EnableUPnP
Definition: C4Config.h:155
bool hasTCP() const
Definition: C4Network2IO.h:105
int32_t PortTCP
Definition: C4Config.h:154
void AddLocalAddrs(int16_t iPortTCP, int16_t iPortUDP)
int32_t PortUDP
Definition: C4Config.h:154

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::InitPuncher ( )
protected

Definition at line 1068 of file C4Network2.cpp.

References C4NetStdPortPuncher, getNetpuncherAddr(), C4Network2IO::InitPuncher(), C4NetIO::HostAddress::IPv4, C4NetIO::HostAddress::IPv6, C4NetIO::EndpointAddress::IsNull(), NetIO, C4NetIO::EndpointAddress::SetAddress(), and C4NetIO::EndpointAddress::SetDefaultPort().

Referenced by LeagueStart().

1069 {
1070  // We have an internet connection, so let's punch the puncher server here in order to open an udp port
1071  C4NetIO::addr_t PuncherAddr;
1073  if (!PuncherAddr.IsNull())
1074  {
1075  PuncherAddr.SetDefaultPort(C4NetStdPortPuncher);
1076  NetIO.InitPuncher(PuncherAddr);
1077  }
1079  if (!PuncherAddr.IsNull())
1080  {
1081  PuncherAddr.SetDefaultPort(C4NetStdPortPuncher);
1082  NetIO.InitPuncher(PuncherAddr);
1083  }
1084 }
C4Network2IO NetIO
Definition: C4Network2.h:110
StdStrBuf getNetpuncherAddr() const
Definition: C4Network2.h:309
void SetAddress(const sockaddr *addr)
Definition: C4NetIO.cpp:370
bool IsNull() const
Definition: C4NetIO.cpp:509
bool InitPuncher(C4NetIO::addr_t PuncherAddr)
void SetDefaultPort(uint16_t port)
Definition: C4NetIO.cpp:542
const int16_t C4NetStdPortPuncher
Definition: C4Network2.h:33

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::InvalidateReference ( )

Definition at line 2064 of file C4Network2.cpp.

References C4NetMinLeagueUpdateInterval, iLastReferenceUpdate, and iLeagueUpdateDelay.

Referenced by ChangeGameStatus(), C4Network2Players::HandlePlayerInfo(), HandlePuncherPacket(), C4Network2Players::OnClientPart(), C4GameOptionButtons::OnCommentSet(), C4MessageInput::ProcessCommand(), and SetPassword().

2065 {
2066  // Update both local and league reference as soon as possible
2069 }
uint32_t iLeagueUpdateDelay
Definition: C4Network2.h:165
uint32_t iLastReferenceUpdate
Definition: C4Network2.h:164
const unsigned int C4NetMinLeagueUpdateInterval
Definition: C4Network2.h:49

Here is the caller graph for this function:

bool C4Network2::isEnabled ( ) const
inline

Definition at line 203 of file C4Network2.h.

References C4Network2Status::isEnabled().

Referenced by C4Game::Abort(), C4MainMenu::ActivateMain(), C4PlayerInfoList::AddInfo(), C4ChartDialog::C4ChartDialog(), C4Game::CanQuickSave(), DoLobby(), DrawStatus(), C4Game::Evaluate(), C4Viewport::Execute(), C4PlayerList::FileInUse(), FinalInit(), C4Network2Players::HandlePlayerInfo(), C4Network2Players::HandlePlayerInfoUpdRequest(), C4Console::In(), C4Network2Players::Init(), C4Game::Init(), C4Game::InitControl(), C4Game::InitGame(), C4Game::InitGameFinal(), InitHost(), C4PlayerInfoList::InitLocal(), C4Game::InitPlayers(), C4Game::IsPaused(), C4Network2Players::JoinLocalPlayer(), C4PlayerList::JoinNew(), C4PlayerInfo::LoadFromLocalFile(), C4PlayerInfoList::LocalJoinUnjoinedPlayersInQueue(), C4MainMenu::MenuCommand(), C4Network2Players::OnClientPart(), C4GameSaveSavegame::OnSaving(), C4AbortGameDialog::OnShown(), C4Game::OpenScenario(), C4Game::Pause(), Pause(), C4MessageInput::ProcessCommand(), C4TeamList::RecheckPlayerInfoTeams(), C4PlayerInfoList::RecreatePlayers(), C4Game::ReloadDef(), C4Game::ReloadFile(), C4Game::ReloadParticle(), C4Network2Players::RequestPlayerInfoUpdate(), C4PlayerInfoList::RestoreSavegameInfos(), RetrieveRes(), C4Console::SaveGame(), C4PlayerInfoList::SetAsRestoreInfos(), C4TeamList::SetTeamColors(), C4TeamList::SetTeamDistribution(), Start(), Sync(), C4Game::Synchronize(), C4Game::Unpause(), C4Console::UpdateNetMenu(), C4Console::UpdatePlayerMenu(), C4GameSaveSavegame::WriteDesc(), C4GameSaveRecord::WriteDesc(), and C4GameSave::WriteDescDate().

203 { return Status.isEnabled(); }
bool isEnabled() const
Definition: C4Network2.h:86
C4Network2Status Status
Definition: C4Network2.h:122

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2::isFrozen ( ) const

Definition at line 1829 of file C4Network2.cpp.

References fStatusAck, C4Network2Status::getState(), GS_Lobby, GS_Pause, and Status.

Referenced by C4GameControlNetwork::DecideControlDelivery(), C4GameControlNetwork::DoInput(), C4GameControlNetwork::HandleControlPkt(), and Sync().

1830 {
1831  // "frozen" means all clients are garantueed to be in the same tick.
1832  // This is only the case if the game is not started yet (lobby) or the
1833  // tick has been ensured (pause) and acknowledged by all joined clients.
1834  // Note unjoined clients must be ignored here - they can't be faster than
1835  // the host, anyway.
1836  if (Status.getState() == GS_Lobby) return true;
1837  if (Status.getState() == GS_Pause && fStatusAck) return true;
1838  return false;
1839 }
bool fStatusAck
Definition: C4Network2.h:140
C4Network2Status Status
Definition: C4Network2.h:122
C4NetGameState getState() const
Definition: C4Network2.h:80

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2::isHost ( ) const
inline

Definition at line 209 of file C4Network2.h.

References fHost.

Referenced by C4GameLobby::Countdown::Abort(), C4MainMenu::ActivateMain(), C4PlayerInfoList::AddInfo(), AddVote(), AllowJoin(), C4GameOverDlg::C4GameOverDlg(), C4Game::CanQuickSave(), ChangeGameStatus(), CheckStatusAck(), CheckStatusReached(), C4GameLobby::Countdown::Countdown(), CreateDynamic(), DeactivateInactiveClients(), DoLobby(), C4Game::Evaluate(), Execute(), FinalInit(), HandleActivateReq(), HandleConn(), C4Network2Players::HandlePacket(), HandlePacket(), C4Network2Players::HandlePlayerInfo(), C4Network2Players::HandlePlayerInfoUpdRequest(), HandlePuncherPacket(), HandleStatusAck(), C4Network2Players::Init(), C4Game::InitControl(), C4Game::InitGameFinal(), C4Game::InitPlayers(), Join(), C4Network2Players::JoinLocalPlayer(), LeagueNotifyDisconnect(), OnClientConnect(), OnClientDisconnect(), C4Network2Players::OnClientPart(), OnDisconn(), OnPuncherConnect(), C4GameLobby::MainDlg::OnRunBtn(), C4Network2Players::OnStatusGoReached(), C4Game::OpenScenario(), C4Game::Pause(), Pause(), C4MessageInput::ProcessCommand(), C4Network2Players::RequestPlayerInfoUpdate(), RetrieveScenario(), C4Console::SaveGame(), SendJoinData(), SetAllowObserve(), SetCtrlMode(), Start(), Sync(), C4Game::Unpause(), C4Console::UpdateNetMenu(), C4Console::UpdatePlayerMenu(), C4Network2ClientDlg::UpdateText(), and Vote().

209 { return fHost; }
bool fHost
Definition: C4Network2.h:127

Here is the caller graph for this function:

bool C4Network2::isJoinAllowed ( ) const
inline

Definition at line 213 of file C4Network2.h.

References fAllowJoin.

Referenced by C4Network2Reference::InitLocal().

213 { return fAllowJoin; }
bool fAllowJoin
Definition: C4Network2.h:130

Here is the caller graph for this function:

bool C4Network2::isLobbyActive ( ) const
inline

Definition at line 204 of file C4Network2.h.

References C4Network2Status::isLobbyActive().

Referenced by DoLobby(), C4GraphicsSystem::Execute(), C4Network2Players::HandlePlayerInfoUpdRequest(), C4Game::Init(), C4TeamList::IsTeamVisible(), OnClientConnect(), and C4TeamList::RecheckPlayerInfoTeams().

204 { return Status.isLobbyActive(); }
C4Network2Status Status
Definition: C4Network2.h:122
bool isLobbyActive() const
Definition: C4Network2.h:87

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2::isLobbyCountDown ( )
inline

Definition at line 297 of file C4Network2.h.

Referenced by C4MessageInput::ProcessCommand().

297 { return pLobbyCountdown != 0; }
C4GameLobby::Countdown * pLobbyCountdown
Definition: C4Network2.h:149

Here is the caller graph for this function:

bool C4Network2::isObservingAllowed ( ) const
inline

Definition at line 214 of file C4Network2.h.

References fAllowObserve.

Referenced by C4Network2Reference::InitLocal().

214 { return fAllowObserve; }
bool fAllowObserve
Definition: C4Network2.h:130

Here is the caller graph for this function:

bool C4Network2::isPassworded ( ) const
inline

Definition at line 218 of file C4Network2.h.

References StdStrBuf::isNull().

Referenced by C4GameOptionButtons::C4GameOptionButtons(), C4Network2Reference::InitLocal(), and SetPassword().

218 { return !sPassword.isNull(); }
bool isNull() const
Definition: StdBuf.h:449
StdStrBuf sPassword
Definition: C4Network2.h:172

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2::isPastLobby ( ) const
inline

Definition at line 205 of file C4Network2.h.

References C4Network2Status::isPastLobby().

205 { return Status.isPastLobby(); }
bool isPastLobby() const
Definition: C4Network2.h:88
C4Network2Status Status
Definition: C4Network2.h:122

Here is the call graph for this function:

bool C4Network2::isPaused ( ) const
inline

Definition at line 207 of file C4Network2.h.

References C4Network2Status::isPaused(), and isStatusAck().

207 { return Status.isPaused() && isStatusAck(); }
bool isStatusAck() const
Definition: C4Network2.h:210
C4Network2Status Status
Definition: C4Network2.h:122
bool isPaused() const
Definition: C4Network2.h:89

Here is the call graph for this function:

bool C4Network2::isPausing ( ) const
inline

Definition at line 208 of file C4Network2.h.

References fStatusAck, and C4Network2Status::isPaused().

208 { return Status.isPaused() && !fStatusAck; }
bool fStatusAck
Definition: C4Network2.h:140
C4Network2Status Status
Definition: C4Network2.h:122
bool isPaused() const
Definition: C4Network2.h:89

Here is the call graph for this function:

bool C4Network2::isRunning ( ) const
inline

Definition at line 206 of file C4Network2.h.

References C4Network2Status::isRunning(), and isStatusAck().

Referenced by AddVote(), HandleActivateReq(), C4Network2Players::HandlePlayerInfo(), C4Game::IsPaused(), and Vote().

206 { return Status.isRunning() && isStatusAck(); }
bool isStatusAck() const
Definition: C4Network2.h:210
C4Network2Status Status
Definition: C4Network2.h:122
bool isRunning() const
Definition: C4Network2.h:90

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2::isStatusAck ( ) const
inline

Definition at line 210 of file C4Network2.h.

References fStatusAck.

Referenced by isPaused(), and isRunning().

210 { return fStatusAck; }
bool fStatusAck
Definition: C4Network2.h:140

Here is the caller graph for this function:

bool C4Network2::isStreaming ( ) const

Definition at line 3072 of file C4Network2.cpp.

References fStreaming.

3073 {
3074  // Streaming must be active and there must still be anything to stream
3075  return fStreaming;
3076 }
bool fStreaming
Definition: C4Network2.h:187
bool C4Network2::Join ( C4ClientCore CCore,
C4Network2IOConnection pConn,
StdStrBuf szReply 
)
protected

Definition at line 1366 of file C4Network2.cpp.

References Application, C4ClientIDUnknown, CDT_Direct, CID_ClientJoin, Clients, Control, C4GameControl::DoInput(), fAllowJoin, fAllowObserve, C4Network2ClientList::GetClient(), C4ClientCore::getID(), C4ClientCore::getName(), C4ClientCore::getRevision(), C4Application::GetRevision(), iNextClientID, isHost(), LogF(), NCS_Joining, SAppend(), SCopy(), SEqualNoCase(), C4ClientCore::SetActivated(), C4ClientCore::SetID(), C4ClientCore::SetName(), C4ClientCore::SetObserver(), C4Network2Client::SetStatus(), and sprintf.

Referenced by HandleConn().

1367 {
1368  if (!pConn) return false;
1369  // security
1370  if (!isHost()) { *szReply = "not host"; return false; }
1371  if (!fAllowJoin && !fAllowObserve) { *szReply = "join denied"; return false; }
1372  if (CCore.getID() != C4ClientIDUnknown) { *szReply = "join with set id not allowed"; return false; }
1373  // find free client id
1374  CCore.SetID(iNextClientID++);
1375  // observer?
1376  if (!fAllowJoin) CCore.SetObserver(true);
1377  // deactivate - client will have to ask for activation.
1378  CCore.SetActivated(false);
1379  // Name already in use? Find unused one
1380  if (Clients.GetClient(CCore.getName()))
1381  {
1382  char szNameTmpl[256+1], szNewName[256+1];
1383  SCopy(CCore.getName(), szNameTmpl, 254); SAppend("%d", szNameTmpl, 256);
1384  int32_t i = 1;
1385  do
1386  sprintf(szNewName, szNameTmpl, ++i);
1387  while (Clients.GetClient(szNewName));
1388  CCore.SetName(szNewName);
1389  }
1390  // join client
1392  // get client, set status
1393  C4Network2Client *pClient = Clients.GetClient(CCore);
1394  if (pClient) pClient->SetStatus(NCS_Joining);
1395  // warn if client revision doesn't match our host revision
1397  {
1398  LogF("[!]WARNING! Client %s engine revision (%s) differs from local revision (%s). Client might run out of sync.", CCore.getName(), CCore.getRevision(), Application.GetRevision());
1399  }
1400  // ok, client joined.
1401  return true;
1402  // Note that the connection isn't fully accepted at this point and won't be
1403  // associated with the client. The new-created client is waiting for connect.
1404  // Somewhat ironically, the connection may still timeout (resulting in an instant
1405  // removal and maybe some funny message sequences).
1406  // The final client initialization will be done at OnClientConnect.
1407 }
void SetObserver(bool fnObserver)
Definition: C4Client.h:65
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
bool isHost() const
Definition: C4Network2.h:209
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:227
#define sprintf
Definition: Standard.h:171
int32_t iNextClientID
Definition: C4Network2.h:155
void SetID(int32_t inID)
Definition: C4Client.h:62
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:177
bool fAllowJoin
Definition: C4Network2.h:130
C4Network2Client * GetClient(const char *szName) const
const char * GetRevision() const
Definition: C4Application.h:72
void SetName(const char *sznName)
Definition: C4Client.h:63
C4GameControl Control
void DoInput(C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)
int32_t getID() const
Definition: C4Client.h:57
const char * getRevision() const
Definition: C4Client.h:72
const int32_t C4ClientIDUnknown
Definition: C4Client.h:24
void SetStatus(C4Network2ClientStatus enStatus)
C4Network2ClientList Clients
Definition: C4Network2.h:116
void SetActivated(bool fnActivated)
Definition: C4Client.h:64
bool fAllowObserve
Definition: C4Network2.h:130
const char * getName() const
Definition: C4Client.h:69
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253
C4Application Application
Definition: C4Globals.cpp:44

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2::LeagueEnd ( const char *  szRecordName = nullptr,
const BYTE pRecordSHA = nullptr 
)
protected

Definition at line 2366 of file C4Network2.cpp.

References Application, C4Network2ClientList::BroadcastMsgToClients(), C4GUI::MessageDialog::btnAbort, C4GUI::MessageDialog::btnRetryAbort, Clients, StdStrBuf::Copy(), C4LeagueClient::End(), C4RoundResults::EvaluateLeague(), C4Network2HTTPClient::Execute(), fHost, fLeagueEndSent, FormatString(), Game, StdStrBuf::getData(), C4LeagueClient::GetEndReply(), C4NetIO::GetError(), StdStrBuf::getLength(), C4Network2HTTPClient::getServerName(), C4GUI::Ico_Error, C4Network2Reference::InitLocal(), C4Network2HTTPClient::isBusy(), C4Application::isEditor, C4GameParameters::isLeague(), C4Network2HTTPClient::isSuccess(), LeagueWaitNotBusy(), LoadResStr(), Log(), MkC4NetIOPacket(), C4Game::Parameters, pGUI, PID_LeagueRoundResults, pLeagueClient, C4Game::RoundResults, C4GUI::Screen::ShowMessageModal(), and StdStrBuf::Take().

Referenced by Clear(), LeagueGameEvaluate(), LeagueSignupDisable(), and LeagueStart().

2367 {
2368  C4RoundResultsPlayers RoundResults;
2369  StdStrBuf sResultMessage;
2370  bool fIsError = true;
2371 
2372  // Not needed?
2373  if (!pLeagueClient || !fHost || fLeagueEndSent)
2374  return true;
2375 
2376  // Make sure league client is available
2378 
2379  // Try until either aborted or successful
2380  const int MAX_RETRIES = 10;
2381  for (int iRetry = 0; iRetry < MAX_RETRIES; iRetry++)
2382  {
2383 
2384  // Do update
2385  C4Network2Reference Ref;
2386  Ref.InitLocal();
2387  if (!pLeagueClient->End(Ref, szRecordName, pRecordSHA))
2388  {
2389  // Log message
2390  sResultMessage = FormatString(LoadResStr("IDS_NET_ERR_LEAGUE_FINISHGAME"), pLeagueClient->GetError());
2391  Log(sResultMessage.getData());
2392  // Show message, allow retry
2393  if (Application.isEditor) break;
2394  bool fRetry = ::pGUI->ShowMessageModal(sResultMessage.getData(), LoadResStr("IDS_NET_ERR_LEAGUE"),
2396  if (fRetry) continue;
2397  break;
2398  }
2399  // Let's wait for response
2400  StdStrBuf Message = FormatString(LoadResStr("IDS_NET_LEAGUE_SENDRESULT"), pLeagueClient->getServerName());
2401  Log(Message.getData());
2402  // Wait for response
2403  while (pLeagueClient->isBusy())
2404  {
2405  // Check if league server has responded
2406  if (!pLeagueClient->Execute(100))
2407  break;
2408  }
2409  // Error?
2410  StdStrBuf LeagueServerMessage;
2411  if (!pLeagueClient->isSuccess() || !pLeagueClient->GetEndReply(&LeagueServerMessage, &RoundResults))
2412  {
2413  const char *pError = pLeagueClient->GetError() ? pLeagueClient->GetError() :
2414  LeagueServerMessage.getLength() ? LeagueServerMessage.getData() :
2415  LoadResStr("IDS_NET_ERR_LEAGUE_EMPTYREPLY");
2416  sResultMessage.Take(FormatString(LoadResStr("IDS_NET_ERR_LEAGUE_SENDRESULT"), pError));
2417  if (Application.isEditor) continue;
2418  // Only retry if we didn't get an answer from the league server
2419  bool fRetry = !pLeagueClient->isSuccess();
2420  fRetry = ::pGUI->ShowMessageModal(sResultMessage.getData(), LoadResStr("IDS_NET_ERR_LEAGUE"),
2423  if (fRetry) continue;
2424  }
2425  else
2426  {
2427  // All OK!
2428  sResultMessage.Copy(LoadResStr(Game.Parameters.isLeague() ? "IDS_MSG_LEAGUEEVALUATIONSUCCESSFU" : "IDS_MSG_INTERNETGAMEEVALUATED"));
2429  fIsError = false;
2430  }
2431  // Done
2432  break;
2433  }
2434 
2435  // Show message
2436  Log(sResultMessage.getData());
2437 
2438  // Take round results
2439  Game.RoundResults.EvaluateLeague(sResultMessage.getData(), !fIsError, RoundResults);
2440 
2441  // Send round results to other clients
2442  C4PacketLeagueRoundResults LeagueUpdatePacket(sResultMessage.getData(), !fIsError, RoundResults);
2444 
2445  // All done
2446  fLeagueEndSent = true;
2447  return true;
2448 }
const char * getData() const
Definition: StdBuf.h:450
virtual bool Execute(int iMaxTime, pollfd *readyfds)
void LeagueWaitNotBusy()
C4Game Game
Definition: C4Globals.cpp:52
bool BroadcastMsgToClients(const C4NetIOPacket &rPkt)
virtual const char * GetError() const
Definition: C4NetIO.h:285
bool End(const C4Network2Reference &Ref, const char *szRecordName, const BYTE *pRecordSHA)
Definition: C4League.cpp:376
C4GameParameters & Parameters
Definition: C4Game.h:69
class C4LeagueClient * pLeagueClient
Definition: C4Network2.h:169
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1194
bool ShowMessageModal(const char *szMessage, const char *szCaption, DWORD dwButtons, Icons icoIcon, int32_t *piConfigDontShowAgainSetting=nullptr)
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
void Take(char *pnData)
Definition: StdBuf.h:465
bool GetEndReply(StdStrBuf *pMessage, class C4RoundResultsPlayers *pRoundResults)
Definition: C4League.cpp:391
C4RoundResults & RoundResults
Definition: C4Game.h:75
const char * getServerName() const
void EvaluateLeague(const char *szResultMsg, bool fSuccess, const C4RoundResultsPlayers &rLeagueInfo)
bool fLeagueEndSent
Definition: C4Network2.h:166
C4Network2ClientList Clients
Definition: C4Network2.h:116
bool Log(const char *szMessage)
Definition: C4Log.cpp:195
bool isLeague() const
bool fHost
Definition: C4Network2.h:127
size_t getLength() const
Definition: StdBuf.h:453
void Copy()
Definition: StdBuf.h:475
C4Application Application
Definition: C4Globals.cpp:44
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::LeagueGameEvaluate ( const char *  szRecordName = nullptr,
const BYTE pRecordSHA = nullptr 
)

Definition at line 2033 of file C4Network2.cpp.

References fLeagueEndSent, LeagueEnd(), and pLeagueClient.

Referenced by C4Game::Evaluate().

2034 {
2035  // already off?
2036  if (!pLeagueClient) return;
2037  // already evaluated?
2038  if (fLeagueEndSent) return;
2039  // end
2040  LeagueEnd(szRecordName, pRecordSHA);
2041 }
class C4LeagueClient * pLeagueClient
Definition: C4Network2.h:169
bool fLeagueEndSent
Definition: C4Network2.h:166
bool LeagueEnd(const char *szRecordName=nullptr, const BYTE *pRecordSHA=nullptr)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::LeagueNotifyDisconnect ( int32_t  iClientID,
enum C4LeagueDisconnectReason  eReason 
)

Definition at line 2619 of file C4Network2.cpp.

References Clients, Game, C4Game::GameOver, StdStrBuf::getData(), C4Network2Client::getID(), C4PlayerInfoList::GetInfoByClientID(), C4Network2ClientList::GetLocal(), C4ClientPlayerInfos::GetPlayerInfo(), C4LeagueClient::GetReportDisconnectReply(), isHost(), C4PlayerInfo::IsJoined(), C4GameParameters::isLeague(), C4PlayerInfo::IsRemoved(), C4Game::IsRunning, LeagueWaitNotBusy(), LoadResStr(), LogF(), C4Game::Parameters, C4Game::PlayerInfos, pLeagueClient, and C4LeagueClient::ReportDisconnect().

Referenced by OnClientDisconnect().

2620 {
2621  // league active?
2622  if (!pLeagueClient || !Game.Parameters.isLeague()) return;
2623  // only in running game
2624  if (!Game.IsRunning || Game.GameOver) return;
2625  // clients send notifications for their own players; host sends for the affected client players
2626  if (!isHost()) { if (!Clients.GetLocal()) return; iClientID = Clients.GetLocal()->getID(); }
2627  // clients only need notifications if they have players in the game
2628  const C4ClientPlayerInfos *pInfos = Game.PlayerInfos.GetInfoByClientID(iClientID);
2629  if (!pInfos) return;
2630  int32_t i=0; C4PlayerInfo *pInfo;
2631  while ((pInfo = pInfos->GetPlayerInfo(i++))) if (pInfo->IsJoined() && !pInfo->IsRemoved()) break;
2632  if (!pInfo) return;
2633  // Make sure league client is avilable
2635  // report the disconnect!
2636  LogF(LoadResStr("IDS_LEAGUE_LEAGUEREPORTINGUNEXPECTED"), (int) eReason);
2637  pLeagueClient->ReportDisconnect(*pInfos, eReason);
2638  // wait for the reply
2640  // display it
2641  const char *szMsg;
2642  StdStrBuf sMessage;
2643  if (pLeagueClient->GetReportDisconnectReply(&sMessage))
2644  szMsg = LoadResStr("IDS_MSG_LEAGUEUNEXPECTEDDISCONNEC");
2645  else
2646  szMsg = LoadResStr("IDS_ERR_LEAGUEERRORREPORTINGUNEXP");
2647  LogF(szMsg, sMessage.getData());
2648 }
const char * getData() const
Definition: StdBuf.h:450
bool IsRunning
Definition: C4Game.h:141
void LeagueWaitNotBusy()
bool isHost() const
Definition: C4Network2.h:209
C4Game Game
Definition: C4Globals.cpp:52
int32_t getID() const
C4GameParameters & Parameters
Definition: C4Game.h:69
class C4LeagueClient * pLeagueClient
Definition: C4Network2.h:169
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4PlayerInfo * GetPlayerInfo(int32_t iIndex) const
bool GameOver
Definition: C4Game.h:116
bool IsJoined() const
Definition: C4PlayerInfo.h:169
bool IsRemoved() const
Definition: C4PlayerInfo.h:167
C4ClientPlayerInfos * GetInfoByClientID(int32_t iClientID) const
Definition: C4PlayerInfo.h:364
C4Network2ClientList Clients
Definition: C4Network2.h:116
C4PlayerInfoList & PlayerInfos
Definition: C4Game.h:73
bool ReportDisconnect(const C4ClientPlayerInfos &rSendPlayerFBIDs, C4LeagueDisconnectReason eReason)
Definition: C4League.cpp:486
bool isLeague() const
bool GetReportDisconnectReply(StdStrBuf *pMessage)
Definition: C4League.cpp:501
C4Network2Client * GetLocal() const
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2::LeaguePlrAuth ( C4PlayerInfo pInfo)

Definition at line 2450 of file C4Network2.cpp.

References Application, C4LeagueClient::Auth(), C4GUI::MessageDialog::btnAbort, C4GUI::MessageDialog::btnOK, C4GUI::MessageDialog::btnOKAbort, C4GUI::Dialog::Close(), Config, StdStrBuf::Copy(), C4GUI::MessageDialog::dsRegular, C4Network2HTTPClient::Execute(), FormatString(), C4LeagueClient::GetAuthReply(), StdStrBuf::getData(), C4ConfigNetwork::GetLeagueLoginData(), StdStrBuf::getLength(), C4PlayerInfo::GetName(), C4Network2HTTPClient::getServerName(), C4GUI::Ico_Error, C4GUI::Ico_Ex_League, C4GUI::Ico_NetWait, C4GUI::Ico_Notify, C4Network2HTTPClient::isBusy(), C4Application::isEditor, LeagueWaitNotBusy(), LoadResStr(), Log(), LogF(), C4Config::Network, pGUI, pLeagueClient, StdScheduler::ScheduleProcs(), SEqual(), C4PlayerInfo::SetAuthID(), C4ConfigNetwork::SetLeagueLoginData(), C4GUI::Screen::ShowMessageModal(), and C4LeagueSignupDialog::ShowModal().

Referenced by C4Network2Players::JoinLocalPlayer().

2451 {
2452 
2453  // Not possible?
2454  if (!pLeagueClient)
2455  return false;
2456 
2457  // Make sure league client is avilable
2459 
2460  // Official league?
2461  bool fOfficialLeague = SEqual(pLeagueClient->getServerName(), "league.openclonk.org");
2462 
2463  StdStrBuf Account, Password;
2464  bool fRememberLogin = false;
2465 
2466  // Default password from login token if present
2467  if (Config.Network.GetLeagueLoginData(pLeagueClient->getServerName(), pInfo->GetName(), &Account, &Password))
2468  {
2469  fRememberLogin = (Password.getLength()>0);
2470  }
2471  else
2472  {
2473  Account.Copy(pInfo->GetName());
2474  }
2475 
2476  for (;;)
2477  {
2478  // ask for account name and password
2479  if (!C4LeagueSignupDialog::ShowModal(pInfo->GetName(), Account.getData(), pLeagueClient->getServerName(), &Account, &Password, !fOfficialLeague, false, &fRememberLogin))
2480  return false;
2481 
2482  // safety (modal dlg may have deleted network)
2483  if (!pLeagueClient) return false;
2484 
2485  // Send authentication request
2486  if (!pLeagueClient->Auth(*pInfo, Account.getData(), Password.getData(), nullptr, nullptr, fRememberLogin))
2487  return false;
2488 
2489  // safety (modal dlg may have deleted network)
2490  if (!pLeagueClient) return false;
2491 
2492  // Wait for a response
2493  StdStrBuf Message = FormatString(LoadResStr("IDS_MSG_TRYLEAGUESIGNUP"), pInfo->GetName(), Account.getData(), pLeagueClient->getServerName());
2494  Log(Message.getData());
2495  // Set up a dialog
2496  C4GUI::MessageDialog *pDlg = nullptr;
2497  if (!Application.isEditor)
2498  {
2499  // create & show
2501  if (!pDlg || !pDlg->Show(::pGUI, true)) return false;
2502  }
2503  // Wait for response
2504  while (pLeagueClient->isBusy())
2505  {
2506  // Execute GUI
2507  if (!Application.ScheduleProcs() ||
2508  (pDlg && pDlg->IsAborted()))
2509  {
2510  // Clear up
2511  if (pDlg) delete pDlg;
2512  return false;
2513  }
2514  // Check if league server has responded
2515  if (!pLeagueClient->Execute(0))
2516  break;
2517  }
2518  // Close dialog
2519  if (pDlg)
2520  {
2521  pDlg->Close(true);
2522  delete pDlg;
2523  }
2524 
2525  // Success?
2526  StdStrBuf AUID, AccountMaster, LoginToken; bool fUnregistered = false;
2527  if (pLeagueClient->GetAuthReply(&Message, &AUID, &AccountMaster, &fUnregistered, &LoginToken))
2528  {
2529 
2530  // Set AUID
2531  pInfo->SetAuthID(AUID.getData());
2532 
2533  // Remember login data; set or clear login token
2534  Config.Network.SetLeagueLoginData(pLeagueClient->getServerName(), pInfo->GetName(), Account.getData(), fRememberLogin ? LoginToken.getData() : "");
2535 
2536  // Show welcome message, if any
2537  bool fSuccess;
2538  if (Message.getLength())
2539  fSuccess = ::pGUI->ShowMessageModal(
2540  Message.getData(), LoadResStr("IDS_DLG_LEAGUESIGNUPCONFIRM"),
2542  else if (AccountMaster.getLength())
2543  fSuccess = ::pGUI->ShowMessageModal(
2544  FormatString(LoadResStr("IDS_MSG_LEAGUEPLAYERSIGNUPAS"), pInfo->GetName(), AccountMaster.getData(), pLeagueClient->getServerName()).getData(), LoadResStr("IDS_DLG_LEAGUESIGNUPCONFIRM"),
2546  else
2547  fSuccess = ::pGUI->ShowMessageModal(
2548  FormatString(LoadResStr("IDS_MSG_LEAGUEPLAYERSIGNUP"), pInfo->GetName(), pLeagueClient->getServerName()).getData(), LoadResStr("IDS_DLG_LEAGUESIGNUPCONFIRM"),
2550 
2551  // Approved?
2552  if (fSuccess)
2553  // Done
2554  return true;
2555  else
2556  // Sign-up was cancelled by user
2557  ::pGUI->ShowMessageModal(FormatString(LoadResStr("IDS_MSG_LEAGUESIGNUPCANCELLED"), pInfo->GetName()).getData(), LoadResStr("IDS_DLG_LEAGUESIGNUP"), C4GUI::MessageDialog::btnOK, C4GUI::Ico_Notify);
2558 
2559  }
2560  else
2561  {
2562 
2563  // Authentification error
2564  LogF(LoadResStr("IDS_MSG_LEAGUESIGNUPERROR"), Message.getData());
2565  ::pGUI->ShowMessageModal(FormatString(LoadResStr("IDS_MSG_LEAGUESERVERMSG"), Message.getData()).getData(), LoadResStr("IDS_DLG_LEAGUESIGNUPFAILED"), C4GUI::MessageDialog::btnOK, C4GUI::Ico_Error);
2566  // after a league server error message, always fall-through to try again
2567  }
2568 
2569  // Try given account name as default next time
2570  if (AccountMaster.getLength())
2571  Account.Take(std::move(AccountMaster));
2572 
2573  // safety (modal dlg may have deleted network)
2574  if (!pLeagueClient) return false;
2575  }
2576 
2577 }
const char * getData() const
Definition: StdBuf.h:450
bool Auth(const C4PlayerInfo &PlrInfo, const char *szAccount, const char *szPassword, const char *szNewAccount=nullptr, const char *szNewPassword=nullptr, bool fRememberLogin=false)
Definition: C4League.cpp:406
C4Config Config
Definition: C4Config.cpp:831
const char * GetName() const
Definition: C4PlayerInfo.h:160
virtual bool Execute(int iMaxTime, pollfd *readyfds)
void LeagueWaitNotBusy()
void SetAuthID(const char *sznAuthID)
Definition: C4PlayerInfo.h:136
void Close(bool fOK)
void SetLeagueLoginData(const char *szServer, const char *szPlayerName, const char *szAccount, const char *szLoginToken)
Definition: C4Config.cpp:615
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97
class C4LeagueClient * pLeagueClient
Definition: C4Network2.h:169
bool GetAuthReply(StdStrBuf *pMessage, StdStrBuf *pAUID, StdStrBuf *pAccount, bool *pRegister, StdStrBuf *pLoginToken)
Definition: C4League.cpp:426
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1194
bool ShowMessageModal(const char *szMessage, const char *szCaption, DWORD dwButtons, Icons icoIcon, int32_t *piConfigDontShowAgainSetting=nullptr)
C4ConfigNetwork Network
Definition: C4Config.h:256
const char * getServerName() const
bool Log(const char *szMessage)
Definition: C4Log.cpp:195
bool GetLeagueLoginData(const char *szServer, const char *szPlayerName, StdStrBuf *pAccount, StdStrBuf *pLoginToken) const
Definition: C4Config.cpp:625
static bool ShowModal(const char *szPlayerName, const char *szLeagueName, const char *szLeagueServerName, StdStrBuf *psAccount, StdStrBuf *psPass, bool fWarnThirdParty, bool fRegister, bool *pfRememberLogin)
Definition: C4League.cpp:662
size_t getLength() const
Definition: StdBuf.h:453
bool ScheduleProcs(int iTimeout=1000/36)
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253
void Copy()
Definition: StdBuf.h:475
C4Application Application
Definition: C4Globals.cpp:44
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2::LeaguePlrAuthCheck ( C4PlayerInfo pInfo)

Definition at line 2579 of file C4Network2.cpp.

References C4LeagueClient::AuthCheck(), C4Network2HTTPClient::Execute(), FormatString(), Game, C4LeagueClient::GetAuthCheckReply(), StdStrBuf::getData(), C4NetIO::GetError(), C4PlayerInfo::GetName(), C4Network2HTTPClient::isBusy(), C4Network2HTTPClient::isSuccess(), C4GameParameters::League, LeagueShowError(), LeagueWaitNotBusy(), LoadResStr(), Log(), C4Game::Parameters, and pLeagueClient.

Referenced by C4Network2Players::HandlePlayerInfoUpdRequest().

2580 {
2581 
2582  // Not possible?
2583  if (!pLeagueClient)
2584  return false;
2585 
2586  // Make sure league client is available
2588 
2589  // Ask league server to check the code
2590  if (!pLeagueClient->AuthCheck(*pInfo))
2591  return false;
2592 
2593  // Log
2594  StdStrBuf Message = FormatString(LoadResStr("IDS_MSG_LEAGUEJOINING"), pInfo->GetName());
2595  Log(Message.getData());
2596 
2597  // Wait for response
2598  while (pLeagueClient->isBusy())
2599  if (!pLeagueClient->Execute(100))
2600  break;
2601 
2602  // Check response validity
2603  if (!pLeagueClient->isSuccess())
2604  {
2606  return false;
2607  }
2608 
2609  // Check if league server approves. pInfo will have league info if this call is successful.
2610  if (!pLeagueClient->GetAuthCheckReply(&Message, Game.Parameters.League.getData(), pInfo))
2611  {
2612  LeagueShowError(FormatString(LoadResStr("IDS_MSG_LEAGUEJOINREFUSED"), pInfo->GetName(), Message.getData()).getData());
2613  return false;
2614  }
2615 
2616  return true;
2617 }
const char * getData() const
Definition: StdBuf.h:450
const char * GetName() const
Definition: C4PlayerInfo.h:160
virtual bool Execute(int iMaxTime, pollfd *readyfds)
void LeagueWaitNotBusy()
C4Game Game
Definition: C4Globals.cpp:52
StdCopyStrBuf League
virtual const char * GetError() const
Definition: C4NetIO.h:285
C4GameParameters & Parameters
Definition: C4Game.h:69
class C4LeagueClient * pLeagueClient
Definition: C4Network2.h:169
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
void LeagueShowError(const char *szMsg)
bool AuthCheck(const C4PlayerInfo &PlrInfo)
Definition: C4League.cpp:456
bool GetAuthCheckReply(StdStrBuf *pMessage, const char *szLeague, class C4PlayerInfo *pPlrInfo)
Definition: C4League.cpp:472
bool Log(const char *szMessage)
Definition: C4Log.cpp:195
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::LeagueShowError ( const char *  szMsg)

Definition at line 2671 of file C4Network2.cpp.

References Application, C4Application::isEditor, LoadResStr(), LogF(), pGUI, and C4GUI::Screen::ShowErrorMessage().

Referenced by LeaguePlrAuthCheck().

2672 {
2673  if (!Application.isEditor)
2674  {
2675  ::pGUI->ShowErrorMessage(szMsg);
2676  }
2677  else
2678  {
2679  LogF(LoadResStr("IDS_LGA_SERVERFAILURE"), szMsg);
2680  }
2681 }
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1194
bool ShowErrorMessage(const char *szMessage)
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253
C4Application Application
Definition: C4Globals.cpp:44

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::LeagueSignupDisable ( )

Definition at line 2043 of file C4Network2.cpp.

References DeinitLeague(), Game, C4GameParameters::isLeague(), LeagueEnd(), C4Game::Parameters, and pLeagueClient.

Referenced by C4GameOptionButtons::OnBtnInternet().

2044 {
2045  // already off?
2046  if (!pLeagueClient) return;
2047  // no post-disable if league is active
2048  if (pLeagueClient && Game.Parameters.isLeague()) return;
2049  // signup end
2050  LeagueEnd(); DeinitLeague();
2051 }
C4Game Game
Definition: C4Globals.cpp:52
C4GameParameters & Parameters
Definition: C4Game.h:69
class C4LeagueClient * pLeagueClient
Definition: C4Network2.h:169
bool isLeague() const
bool LeagueEnd(const char *szRecordName=nullptr, const BYTE *pRecordSHA=nullptr)
void DeinitLeague()

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2::LeagueSignupEnable ( )

Definition at line 2053 of file C4Network2.cpp.

References DeinitLeague(), InitLeague(), LeagueStart(), and pLeagueClient.

Referenced by C4GameOptionButtons::OnBtnInternet().

2054 {
2055  // already running?
2056  if (pLeagueClient) return true;
2057  // Start it!
2058  if (InitLeague(nullptr) && LeagueStart(nullptr)) return true;
2059  // Failure :'(
2060  DeinitLeague();
2061  return false;
2062 }
class C4LeagueClient * pLeagueClient
Definition: C4Network2.h:169
bool InitLeague(bool *pCancel)
bool LeagueStart(bool *pCancel)
void DeinitLeague()

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2::LeagueStart ( bool *  pCancel)
protected

Definition at line 2151 of file C4Network2.cpp.

References Application, C4GUI::MessageDialog::btnAbort, C4GUI::MessageDialog::btnOK, StdStrBuf::Clear(), C4GUI::Dialog::Close(), DeinitLeague(), C4GUI::MessageDialog::dsRegular, C4Network2HTTPClient::Execute(), fHost, fLeagueEndSent, FormatString(), Game, StdStrBuf::getData(), C4NetIO::GetError(), StdStrBuf::getLength(), C4Network2HTTPClient::getServerName(), C4LeagueClient::GetStartReply(), C4GUI::Ico_Error, C4GUI::Ico_NetWait, C4Network2Reference::InitLocal(), InitPuncher(), C4Network2HTTPClient::isBusy(), C4Application::isEditor, C4Network2HTTPClient::isSuccess(), C4GameParameters::League, C4GameParameters::LeagueAddress, LeagueEnd(), LoadResStr(), Log(), LogFatal(), C4GameParameters::MaxPlayers, C4Game::Parameters, pGUI, pLeagueClient, C4Game::RandomSeed, StdScheduler::ScheduleProcs(), C4GUI::Screen::ShowMessageModal(), C4LeagueClient::Start(), and C4GameParameters::StreamAddress.

Referenced by InitHost(), and LeagueSignupEnable().

2152 {
2153  // Not needed?
2154  if (!pLeagueClient || !fHost)
2155  return true;
2156 
2157  // Default
2158  if (pCancel) *pCancel = true;
2159 
2160  // Do update
2161  C4Network2Reference Ref;
2162  Ref.InitLocal();
2163  if (!pLeagueClient->Start(Ref))
2164  {
2165  // Log message
2166  StdStrBuf Message = FormatString(LoadResStr("IDS_NET_ERR_LEAGUE_STARTGAME"), pLeagueClient->GetError());
2167  LogFatal(Message.getData());
2168  // Show message
2169  if (!Application.isEditor)
2170  {
2171  // Show option to cancel, if possible
2172  bool fResult = ::pGUI->ShowMessageModal(
2173  Message.getData(),
2174  LoadResStr("IDS_NET_ERR_LEAGUE"),
2177  if (pCancel)
2178  *pCancel = !fResult;
2179  }
2180  // Failed
2181  return false;
2182  }
2183 
2184  InitPuncher();
2185 
2186  // Let's wait for response
2187  StdStrBuf Message = FormatString(LoadResStr("IDS_NET_LEAGUE_REGGAME"), pLeagueClient->getServerName());
2188  Log(Message.getData());
2189  // Set up a dialog
2190  C4GUI::MessageDialog *pDlg = nullptr;
2191  if (!Application.isEditor)
2192  {
2193  // create & show
2194  pDlg = new C4GUI::MessageDialog(Message.getData(), LoadResStr("IDS_NET_LEAGUE_STARTGAME"),
2196  if (!pDlg || !pDlg->Show(::pGUI, true)) return false;
2197  }
2198  // Wait for response
2199  while (pLeagueClient->isBusy())
2200  {
2201  // Execute GUI
2202  if (!Application.ScheduleProcs() ||
2203  (pDlg && pDlg->IsAborted()))
2204  {
2205  // Clear up
2206  if (pDlg) delete pDlg;
2207  return false;
2208  }
2209  // Check if league server has responded
2210  if (!pLeagueClient->Execute(100))
2211  break;
2212  }
2213  // Close dialog
2214  if (pDlg)
2215  {
2216  pDlg->Close(true);
2217  delete pDlg;
2218  }
2219  // Error?
2220  StdStrBuf LeagueServerMessage, League, StreamingAddr;
2221  int32_t Seed = Game.RandomSeed, MaxPlayersLeague = 0;
2222  if (!pLeagueClient->isSuccess() ||
2223  !pLeagueClient->GetStartReply(&LeagueServerMessage, &League, &StreamingAddr, &Seed, &MaxPlayersLeague))
2224  {
2225  const char *pError = pLeagueClient->GetError() ? pLeagueClient->GetError() :
2226  LeagueServerMessage.getLength() ? LeagueServerMessage.getData() :
2227  LoadResStr("IDS_NET_ERR_LEAGUE_EMPTYREPLY");
2228  StdStrBuf Message = FormatString(LoadResStr("IDS_NET_ERR_LEAGUE_REGGAME"), pError);
2229  // Log message
2230  Log(Message.getData());
2231  // Show message
2232  if (!Application.isEditor)
2233  {
2234  // Show option to cancel, if possible
2235  bool fResult = ::pGUI->ShowMessageModal(
2236  Message.getData(),
2237  LoadResStr("IDS_NET_ERR_LEAGUE"),
2240  if (pCancel)
2241  *pCancel = !fResult;
2242  }
2243  // Failed
2244  return false;
2245  }
2246 
2247  // Show message
2248  if (LeagueServerMessage.getLength())
2249  {
2250  StdStrBuf Message = FormatString(LoadResStr("IDS_MSG_LEAGUEGAMESIGNUP"), pLeagueClient->getServerName(), LeagueServerMessage.getData());
2251  // Log message
2252  Log(Message.getData());
2253  // Show message
2254  if (!Application.isEditor)
2255  {
2256  // Show option to cancel, if possible
2257  bool fResult = ::pGUI->ShowMessageModal(
2258  Message.getData(),
2259  LoadResStr("IDS_NET_ERR_LEAGUE"),
2262  if (pCancel)
2263  *pCancel = !fResult;
2264  if (!fResult)
2265  {
2266  LeagueEnd(); DeinitLeague();
2267  return false;
2268  }
2269  }
2270  }
2271 
2272  // Set game parameters for league game
2273  Game.Parameters.League = League;
2274  Game.RandomSeed = Seed;
2275  if (MaxPlayersLeague)
2276  Game.Parameters.MaxPlayers = MaxPlayersLeague;
2277  if (!League.getLength())
2278  {
2281  }
2282  else
2283  {
2284  Game.Parameters.StreamAddress = StreamingAddr;
2285  }
2286 
2287  // All ok
2288  fLeagueEndSent = false;
2289  return true;
2290 }
const char * getData() const
Definition: StdBuf.h:450
int32_t RandomSeed
Definition: C4Game.h:136
virtual bool Execute(int iMaxTime, pollfd *readyfds)
C4Game Game
Definition: C4Globals.cpp:52
void Clear()
Definition: StdBuf.h:474
StdCopyStrBuf League
void Close(bool fOK)
virtual const char * GetError() const
Definition: C4NetIO.h:285
C4GameParameters & Parameters
Definition: C4Game.h:69
class C4LeagueClient * pLeagueClient
Definition: C4Network2.h:169
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1194
bool ShowMessageModal(const char *szMessage, const char *szCaption, DWORD dwButtons, Icons icoIcon, int32_t *piConfigDontShowAgainSetting=nullptr)
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:230
const char * getServerName() const
bool fLeagueEndSent
Definition: C4Network2.h:166
bool Start(const C4Network2Reference &Ref)
Definition: C4League.cpp:299
bool GetStartReply(StdStrBuf *pMessage, StdStrBuf *pLeague, StdStrBuf *pStreamingAddr, int32_t *pSeed, int32_t *pMaxPlayers)
Definition: C4League.cpp:313
bool Log(const char *szMessage)
Definition: C4Log.cpp:195
StdCopyStrBuf StreamAddress
bool fHost
Definition: C4Network2.h:127
void InitPuncher()
size_t getLength() const
Definition: StdBuf.h:453
bool ScheduleProcs(int iTimeout=1000/36)
StdCopyStrBuf LeagueAddress
bool LeagueEnd(const char *szRecordName=nullptr, const BYTE *pRecordSHA=nullptr)
C4Application Application
Definition: C4Globals.cpp:44
void DeinitLeague()
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2::LeagueSurrender ( )

Definition at line 2664 of file C4Network2.cpp.

References DeinitLeague().

2665 {
2666  // there's currently no functionality to surrender in the league
2667  // just stop responding so other clients will notify the disconnect
2668  DeinitLeague();
2669 }
void DeinitLeague()

Here is the call graph for this function:

bool C4Network2::LeagueUpdate ( )
protected

Definition at line 2292 of file C4Network2.cpp.

References Config, fHost, C4NetIO::GetError(), iLastLeagueUpdate, iLeagueUpdateDelay, C4Network2Reference::InitLocal(), C4Network2HTTPClient::isBusy(), LoadResStr(), LogF(), C4ConfigNetwork::MasterReferencePeriod, C4Config::Network, pLeagueClient, and C4LeagueClient::Update().

Referenced by Execute().

2293 {
2294  // Not needed?
2295  if (!pLeagueClient || !fHost)
2296  return true;
2297 
2298  // League client currently busy?
2299  if (pLeagueClient->isBusy())
2300  return true;
2301 
2302  // Create reference
2303  C4Network2Reference Ref;
2304  Ref.InitLocal();
2305 
2306  // Do update
2307  if (!pLeagueClient->Update(Ref))
2308  {
2309  // Log
2310  LogF(LoadResStr("IDS_NET_ERR_LEAGUE_UPDATEGAME"), pLeagueClient->GetError());
2311  return false;
2312  }
2313 
2314  // Timing
2315  iLastLeagueUpdate = time(nullptr);
2317 
2318  return true;
2319 }
C4Config Config
Definition: C4Config.cpp:831
uint32_t iLastLeagueUpdate
Definition: C4Network2.h:165
uint32_t iLeagueUpdateDelay
Definition: C4Network2.h:165
virtual const char * GetError() const
Definition: C4NetIO.h:285
class C4LeagueClient * pLeagueClient
Definition: C4Network2.h:169
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4ConfigNetwork Network
Definition: C4Config.h:256
bool Update(const C4Network2Reference &Ref)
Definition: C4League.cpp:346
int32_t MasterReferencePeriod
Definition: C4Config.h:151
bool fHost
Definition: C4Network2.h:127
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253

Here is the call graph for this function:

Here is the caller graph for this function: