OpenClonk
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 ()
 
 ~C4Network2 () override
 
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 () override
 
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 ()
 
bool Execute (int, pollfd *) override
 

Protected Attributes

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

Private Member Functions

bool Execute (int, pollfd *) override
 

Friends

class C4Network2IO
 

Detailed Description

Definition at line 101 of file C4Network2.h.

Member Enumeration Documentation

◆ InitResult

Enumerator
IR_Success 
IR_Error 
IR_Fatal 

Definition at line 221 of file C4Network2.h.

222  {
224  };

Constructor & Destructor Documentation

◆ C4Network2()

C4Network2::C4Network2 ( )

Definition at line 126 of file C4Network2.cpp.

127  : Clients(&NetIO),
130 {
131 
132 }
C4Network2IO NetIO
Definition: C4Network2.h:110
C4TimeMilliseconds tLastActivateRequest
Definition: C4Network2.h:161
C4NetpuncherID NetpuncherGameID
Definition: C4Network2.h:197
C4Network2ClientList Clients
Definition: C4Network2.h:116

◆ ~C4Network2()

C4Network2::~C4Network2 ( )
override

Definition at line 134 of file C4Network2.cpp.

135 {
136  Clear();
137 }
void Clear()
Definition: C4Network2.cpp:712

References Clear().

Here is the call graph for this function:

Member Function Documentation

◆ AbortLobbyCountdown()

void C4Network2::AbortLobbyCountdown ( )

Definition at line 2870 of file C4Network2.cpp.

2871 {
2872  // aboert lobby countdown
2873  if (pLobbyCountdown)
2874  {
2876  delete pLobbyCountdown;
2877  pLobbyCountdown = nullptr;
2878  }
2879 }
C4GameLobby::Countdown * pLobbyCountdown
Definition: C4Network2.h:149

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddVote()

void C4Network2::AddVote ( const C4ControlVote Vote)

Definition at line 2689 of file C4Network2.cpp.

2690 {
2691  // Save back timestamp
2692  if (!Votes.firstPkt())
2693  iVoteStartTime = time(nullptr);
2694  // Save vote back
2696  // Set pause mode if this is the host
2697  if (isHost() && isRunning())
2698  {
2699  Pause();
2700  fPausedForVote = true;
2701  }
2702  // Check if the dialog should be opened
2703  OpenVoteDialog();
2704 }
@ CID_Vote
Definition: C4PacketBase.h:148
C4IDPacket * firstPkt() const
Definition: C4Control.h:78
void Add(C4PacketType eType, C4ControlPacket *pCtrl)
Definition: C4Control.h:82
C4Control Votes
Definition: C4Network2.h:181
bool Pause()
Definition: C4Network2.cpp:514
void OpenVoteDialog()
bool isRunning() const
Definition: C4Network2.h:206
bool fPausedForVote
Definition: C4Network2.h:183
time_t iVoteStartTime
Definition: C4Network2.h:184
bool isHost() const
Definition: C4Network2.h:209
void Vote(C4ControlVoteType eType, bool fApprove=true, int32_t iData=0)

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

Here is the call graph for this function:

◆ AllowJoin()

void C4Network2::AllowJoin ( bool  fAllow)

Definition at line 802 of file C4Network2.cpp.

803 {
804  if (!isHost()) return;
805  fAllowJoin = fAllow;
806  if (Game.IsRunning)
807  {
808  ::GraphicsSystem.FlashMessage(LoadResStr(fAllowJoin ? "IDS_NET_RUNTIMEJOINFREE" : "IDS_NET_RUNTIMEJOINBARRED"));
810  }
811 }
C4Config Config
Definition: C4Config.cpp:930
C4Game Game
Definition: C4Globals.cpp:52
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4ConfigNetwork Network
Definition: C4Config.h:259
int32_t NoRuntimeJoin
Definition: C4Config.h:142
bool IsRunning
Definition: C4Game.h:140
void FlashMessage(const char *message)
bool fAllowJoin
Definition: C4Network2.h:130

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ChangeGameStatus()

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

Definition at line 1817 of file C4Network2.cpp.

1818 {
1819  // change game status, announce. Can only be done by host.
1820  if (!isHost()) return false;
1821  // set status
1822  Status.Set(enState, iTargetCtrlTick);
1823  // update reference
1825  // control mode change?
1826  if (iCtrlMode >= 0) Status.SetCtrlMode(iCtrlMode);
1827  // log
1828  LogSilentF("Network: going into status %s (tick %d)", Status.getStateName(), iTargetCtrlTick);
1829  // set flags
1830  Clients.ResetReady();
1831  fStatusReached = fStatusAck = false;
1832  // send new status to all clients
1834  // check reach/ack
1836  // ok
1837  return true;
1838 }
bool LogSilentF(const char *strMessage,...)
Definition: C4Log.cpp:272
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
@ PID_Status
Definition: C4PacketBase.h:103
bool BroadcastMsgToClients(const C4NetIOPacket &rPkt)
C4Network2Status Status
Definition: C4Network2.h:122
void InvalidateReference()
bool fStatusReached
Definition: C4Network2.h:140
void CheckStatusReached(bool fFromFinalInit=false)
bool fStatusAck
Definition: C4Network2.h:140
void SetCtrlMode(int32_t iCtrlMode)
Definition: C4Network2.cpp:87
void Set(C4NetGameState eState, int32_t iTargetCtrlTick)
Definition: C4Network2.cpp:82
const char * getStateName() const
Definition: C4Network2.cpp:56

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckConn()

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

Definition at line 1317 of file C4Network2.cpp.

1318 {
1319  if (!pConn || !pClient) return false;
1320  // already connected? (shouldn't happen really)
1321  if (pClient->hasConn(pConn))
1322  { *szReply = "already connected"; return true; }
1323  // check core
1324  if (CCore.getDiffLevel(pClient->getCore()) > C4ClientCoreDL_IDMatch)
1325  { *szReply = "wrong client core"; return false; }
1326  // accept
1327  return true;
1328 }
const int32_t C4ClientCoreDL_IDMatch
Definition: C4Client.h:30
int32_t getDiffLevel(const C4ClientCore &CCore2) const
Definition: C4Client.cpp:75
bool hasConn(C4Network2IOConnection *pConn)
const C4ClientCore & getCore() const

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

Referenced by HandleConn().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckStatusAck()

void C4Network2::CheckStatusAck ( )
protected

Definition at line 1885 of file C4Network2.cpp.

1886 {
1887  // host only
1888  if (!isHost()) return;
1889  // status must be reached and not yet acknowledged
1890  if (!fStatusReached || fStatusAck) return;
1891  // all clients ready?
1893  {
1894  // pause/go: check for sync control that can be executed
1895  if (Status.getState() == GS_Go || Status.getState() == GS_Pause)
1897  // broadcast ack
1899  // handle
1900  OnStatusAck();
1901  }
1902 }
@ GS_Pause
Definition: C4Network2.h:65
@ GS_Go
Definition: C4Network2.h:66
@ PID_StatusAck
Definition: C4PacketBase.h:104
class C4GameControlNetwork * pControl
Definition: C4Network2.h:144
void OnStatusAck()
C4NetGameState getState() const
Definition: C4Network2.h:80

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckStatusReached()

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

Definition at line 1840 of file C4Network2.cpp.

1841 {
1842  // already reached?
1843  if (fStatusReached) return;
1844  if (Status.getState() == GS_Lobby)
1846  // game go / pause: control must be initialized and target tick reached
1847  else if (Status.getState() == GS_Go || Status.getState() == GS_Pause)
1848  {
1849  if (Game.IsRunning || fFromFinalInit)
1850  {
1851  // Make sure we have reached the tick and the control queue is empty (except for chasing)
1854  fStatusReached = true;
1855  else
1856  {
1857  // run ctrl so the tick can be reached
1859  Game.HaltCount = 0;
1861  }
1862  }
1863  }
1864  if (!fStatusReached) return;
1865  // call handler
1866  OnStatusReached();
1867  // host?
1868  if (isHost())
1869  // all clients ready?
1870  CheckStatusAck();
1871  else
1872  {
1874  // send response to host
1876  // do delayed activation request
1877  if (fDelayedActivateReq)
1878  {
1879  fDelayedActivateReq = false;
1880  RequestActivate();
1881  }
1882  }
1883 }
C4GameControl Control
C4Console Console
Definition: C4Globals.cpp:45
@ GS_Lobby
Definition: C4Network2.h:64
bool UpdateHaltCtrls(bool fHalt)
Definition: C4ConsoleGUI.h:152
int32_t ControlTick
Definition: C4GameControl.h:89
bool CtrlTickReached(int32_t iTick)
void SetRunning(bool fnRunning, int32_t inTargetTick=-1)
bool CtrlReady(int32_t iTick)
int32_t HaltCount
Definition: C4Game.h:112
bool SendMsgToHost(C4NetIOPacket rPkt)
bool fLobbyRunning
Definition: C4Network2.h:148
bool fDelayedActivateReq
Definition: C4Network2.h:178
void OnStatusReached()
void CheckStatusAck()
bool fChasing
Definition: C4Network2.h:141
void RequestActivate()
void SetTargetTick(int32_t iTargetCtrlTick)
Definition: C4Network2.cpp:92
int32_t getTargetCtrlTick() const
Definition: C4Network2.h:82

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Clear()

void C4Network2::Clear ( )

Definition at line 712 of file C4Network2.cpp.

713 {
714  // stop timer
715  Application.Remove(this);
716  // stop streaming
717  StopStreaming();
718  // clear league
719  if (pLeagueClient)
720  {
721  LeagueEnd();
722  DeinitLeague();
723  }
724  // stop lobby countdown
725  delete pLobbyCountdown; pLobbyCountdown = nullptr;
726  // cancel lobby
727  delete pLobby; pLobby = nullptr;
728  fLobbyRunning = false;
729  // deactivate
730  Status.Clear();
731  fStatusAck = fStatusReached = true;
732  // if control mode is network: change to local
733  if (::Control.isNetwork())
735  // clear all player infos
736  Players.Clear();
737  // remove all clients
738  Clients.Clear();
739  // close net classes
740  NetIO.Clear();
741  // clear resources
742  ResList.Clear();
743  // clear password
744  sPassword.Clear();
745  // stuff
746  fAllowJoin = false;
747  iDynamicTick = -1; fDynamicNeeded = false;
750  fDelayedActivateReq = false;
751  delete pVoteDialog; pVoteDialog = nullptr;
752  fPausedForVote = false;
753  iLastOwnVoting = 0;
755  Votes.Clear();
756  // don't clear fPasswordNeeded here, it's needed by InitClient
757 }
C4Application Application
Definition: C4Globals.cpp:44
void Clear()
Definition: C4Control.cpp:85
void ChangeToLocal()
bool isNetwork() const
Definition: C4GameControl.h:97
C4Network2Players Players
Definition: C4Network2.h:119
C4Network2ResList ResList
Definition: C4Network2.h:113
class C4LeagueClient * pLeagueClient
Definition: C4Network2.h:169
class C4VoteDialog * pVoteDialog
Definition: C4Network2.h:182
bool StopStreaming()
StdStrBuf sPassword
Definition: C4Network2.h:172
uint32_t iLastLeagueUpdate
Definition: C4Network2.h:165
uint32_t iLastReferenceUpdate
Definition: C4Network2.h:164
uint32_t iLastChaseTargetUpdate
Definition: C4Network2.h:158
time_t iLastOwnVoting
Definition: C4Network2.h:184
int32_t iDynamicTick
Definition: C4Network2.h:136
void DeinitLeague()
bool LeagueEnd(const char *szRecordName=nullptr, const BYTE *pRecordSHA=nullptr)
bool fDynamicNeeded
Definition: C4Network2.h:137
C4GameLobby::MainDlg * pLobby
Definition: C4Network2.h:147
void Remove(StdSchedulerProc *pProc)
void Clear()
Definition: StdBuf.h:466

References Application, C4GameControl::ChangeToLocal(), C4Control::Clear(), StdStrBuf::Clear(), C4Network2Status::Clear(), C4Network2ClientList::Clear(), C4Network2IO::Clear(), C4Network2Players::Clear(), C4Network2ResList::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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateDynamic()

bool C4Network2::CreateDynamic ( bool  fInit)
protected

Definition at line 1770 of file C4Network2.cpp.

1771 {
1772  if (!isHost()) return false;
1773  // remove all existing dynamic data
1774  RemoveDynamic();
1775  // log
1776  Log(LoadResStr("IDS_NET_SAVING"));
1777  // compose file name
1778  char szDynamicBase[_MAX_PATH_LEN], szDynamicFilename[_MAX_PATH_LEN];
1780  if (!ResList.FindTempResFileName(szDynamicBase, szDynamicFilename))
1781  Log(LoadResStr("IDS_NET_SAVE_ERR_CREATEDYNFILE"));
1782  // save dynamic data
1783  C4GameSaveNetwork SaveGame(fInit);
1784  if (!SaveGame.Save(szDynamicFilename) || !SaveGame.Close())
1785  { Log(LoadResStr("IDS_NET_SAVE_ERR_SAVEDYNFILE")); return false; }
1786  // add resource
1787  C4Network2Res::Ref pRes = ResList.AddByFile(szDynamicFilename, true, NRT_Dynamic);
1788  if (!pRes) { Log(LoadResStr("IDS_NET_SAVE_ERR_ADDDYNDATARES")); return false; }
1789  // save
1790  ResDynamic = pRes->getCore();
1792  fDynamicNeeded = false;
1793  // ok
1794  return true;
1795 }
bool Log(const char *szMessage)
Definition: C4Log.cpp:204
@ NRT_Dynamic
Definition: C4Network2Res.h:44
#define _MAX_PATH
#define _MAX_PATH_LEN
#define sprintf
Definition: Standard.h:162
char * GetFilename(char *szPath)
Definition: StdFile.cpp:42
const char * AtNetworkPath(const char *filename)
Definition: C4Config.cpp:607
int32_t getNextControlTick() const
char ScenarioFilename[_MAX_PATH_LEN]
Definition: C4Game.h:102
void RemoveDynamic()
C4Network2ResCore ResDynamic
Definition: C4Network2.h:133
const C4Network2ResCore & getCore() const
bool FindTempResFileName(const char *szFilename, char *pTarget)
C4Network2Res::Ref AddByFile(const char *strFilePath, bool fTemp, C4Network2ResType eType, int32_t iResID=-1, const char *szResName=nullptr, bool fAllowUnloadable=false)

References _MAX_PATH, _MAX_PATH_LEN, 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeactivateInactiveClients()

void C4Network2::DeactivateInactiveClients ( )

Definition at line 1971 of file C4Network2.cpp.

1972 {
1973  // host only and not in editor
1974  if (!isHost() || ::Application.isEditor) return;
1975  // update activity
1977  // find clients to deactivate
1978  for (C4Network2Client *pClient = Clients.GetNextClient(nullptr); pClient; pClient = Clients.GetNextClient(pClient))
1979  if (!pClient->isLocal() && pClient->isActivated())
1980  if (pClient->getLastActivity() + C4NetDeactivationDelay < Game.FrameCounter)
1982 }
@ CUT_Activate
Definition: C4Control.h:367
@ CDT_Sync
Definition: C4GameControl.h:35
const int C4NetDeactivationDelay
Definition: C4Network2.h:42
@ CID_ClientUpdate
Definition: C4PacketBase.h:145
void DoInput(C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)
int32_t FrameCounter
Definition: C4Game.h:129
C4Network2Client * GetNextClient(C4Network2Client *pClient)

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeinitLeague()

void C4Network2::DeinitLeague ( )
protected

Definition at line 2115 of file C4Network2.cpp.

2116 {
2117  // league clear
2121  if (pLeagueClient)
2122  {
2124  delete pLeagueClient; pLeagueClient = nullptr;
2125  }
2126 }
C4GameParameters & Parameters
Definition: C4Game.h:67
StdCopyStrBuf League
StdCopyStrBuf LeagueAddress
StdCopyStrBuf MasterServerAddress
Definition: C4Network2.h:152

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoLobby()

bool C4Network2::DoLobby ( )

Definition at line 433 of file C4Network2.cpp.

434 {
435  // shouldn't do lobby?
436  if (!isEnabled() || (!isHost() && !isLobbyActive()))
437  return true;
438 
439  // lobby runs
440  fLobbyRunning = true;
441  fAllowJoin = true;
442  Log(LoadResStr("IDS_NET_LOBBYWAITING"));
443 
444  // client: lobby status reached, message to host
445  if (!isHost())
447  // host: set lobby mode
448  else
450 
451  // determine lobby type
452  if (Console.Active)
453  {
454  // console lobby - update console
456  // init lobby countdown if specified
458  // do console lobby
459  while (isLobbyActive())
460  if (!Application.ScheduleProcs())
461  { Clear(); return false; }
462  }
463  else
464  {
465  // fullscreen lobby
466 
467  // init lobby dialog
469  if (!pLobby->FadeIn(::pGUI)) { delete pLobby; pLobby = nullptr; Clear(); return false; }
470 
471  // init lobby countdown if specified
473 
474  // while state lobby: keep looping
475  while (isLobbyActive() && pLobby && pLobby->IsShown())
476  if (!Application.ScheduleProcs())
477  { Clear(); return false; }
478 
479  // check whether lobby was aborted
480  if (pLobby && pLobby->IsAborted()) { delete pLobby; pLobby = nullptr; Clear(); return false; }
481 
482  // deinit lobby
483  if (pLobby && pLobby->IsShown()) pLobby->Close(true);
484  delete pLobby; pLobby = nullptr;
485 
486  // close any other dialogs
487  ::pGUI->CloseAllDialogs(false);
488  }
489 
490  // lobby end
491  delete pLobbyCountdown; pLobbyCountdown = nullptr;
492  fLobbyRunning = false;
494 
495  // notify user that the lobby has ended (for people who tasked out)
497 
498  // notify lobby end
499  bool fGameGo = isEnabled();
500  if (fGameGo) Log(LoadResStr("IDS_PRC_GAMEGO"));;
501 
502  // disabled?
503  return fGameGo;
504 }
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1191
void NotifyUserIfInactive()
Definition: C4App.cpp:89
void UpdateMenus()
Definition: C4Console.cpp:504
void Close(bool fOK)
bool IsShown()
Definition: C4Gui.h:2148
bool FadeIn(Screen *pOnScreen)
bool IsAborted()
Definition: C4Gui.h:2150
void CloseAllDialogs(bool fWithOK)
Definition: C4Gui.cpp:704
int32_t iLobbyTimeout
Definition: C4Game.h:120
bool isEnabled() const
Definition: C4Network2.h:203
bool ChangeGameStatus(C4NetGameState enState, int32_t iTargetCtrlTick, int32_t iCtrlMode=-1)
bool isLobbyActive() const
Definition: C4Network2.h:204
void StartLobbyCountdown(int32_t iCountdownTime)
bool Active
Definition: C4Window.h:274
bool ScheduleProcs(int iTimeout=1000/36)

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawStatus()

void C4Network2::DrawStatus ( C4TargetFacet cgo)

Definition at line 1084 of file C4Network2.cpp.

1085 {
1086  if (!isEnabled()) return;
1087 
1088  C4Network2Client *pLocal = Clients.GetLocal();
1089 
1090  StdStrBuf Stat;
1091 
1092  // local client status
1093  Stat.AppendFormat("Local: %s %s %s (ID %d)",
1094  pLocal->isObserver() ? "Observing" : pLocal->isActivated() ? "Active" : "Inactive", pLocal->isHost() ? "host" : "client",
1095  pLocal->getName(), pLocal->getID());
1096 
1097  // game status
1098  Stat.AppendFormat( "|Game Status: %s (tick %d)%s%s",
1100  fStatusReached ? " reached" : "", fStatusAck ? " ack" : "");
1101 
1102  // available protocols
1103  C4NetIO *pMsgIO = NetIO.MsgIO(), *pDataIO = NetIO.DataIO();
1104  if (pMsgIO && pDataIO)
1105  {
1106  C4Network2IOProtocol eMsgProt = NetIO.getNetIOProt(pMsgIO),
1107  eDataProt = NetIO.getNetIOProt(pDataIO);
1108  int32_t iMsgPort = 0, iDataPort = 0;
1109  switch (eMsgProt)
1110  {
1111  case P_TCP: iMsgPort = Config.Network.PortTCP; break;
1112  case P_UDP: iMsgPort = Config.Network.PortUDP; break;
1113  case P_NONE: assert(eMsgProt != P_NONE); break;
1114  }
1115  switch (eDataProt)
1116  {
1117  case P_TCP: iDataPort = Config.Network.PortTCP; break;
1118  case P_UDP: iDataPort = Config.Network.PortUDP; break;
1119  case P_NONE: assert(eMsgProt != P_NONE); break;
1120  }
1121  Stat.AppendFormat( "|Protocols: %s: %s (%d i%d o%d bc%d)",
1122  pMsgIO != pDataIO ? "Msg" : "Msg/Data",
1123  NetIO.getNetIOName(pMsgIO), iMsgPort,
1124  NetIO.getProtIRate(eMsgProt), NetIO.getProtORate(eMsgProt), NetIO.getProtBCRate(eMsgProt));
1125  if (pMsgIO != pDataIO)
1126  Stat.AppendFormat( ", Data: %s (%d i%d o%d bc%d)",
1127  NetIO.getNetIOName(pDataIO), iDataPort,
1128  NetIO.getProtIRate(eDataProt), NetIO.getProtORate(eDataProt), NetIO.getProtBCRate(eDataProt));
1129  }
1130  else
1131  Stat.Append("|Protocols: none");
1132 
1133  // some control statistics
1134  Stat.AppendFormat( "|Control: %s, Tick %d, Behind %d, Rate %d, PreSend %d, ACT: %d",
1135  Status.getCtrlMode() == CNM_Decentral ? "Decentral" : Status.getCtrlMode() == CNM_Central ? "Central" : "Async",
1138 
1139  // Streaming statistics
1140  if (fStreaming)
1141  Stat.AppendFormat( "|Streaming: %lu waiting, %u in, %lu out, %lu sent",
1142  static_cast<unsigned long>(pStreamedRecord ? pStreamedRecord->GetStreamingBuf().getSize() : 0),
1144  static_cast<unsigned long>(getPendingStreamData()),
1145  static_cast<unsigned long>(iCurrentStreamPosition));
1146 
1147  // clients
1148  Stat.Append("|Clients:");
1149  for (C4Network2Client *pClient = Clients.GetNextClient(nullptr); pClient; pClient = Clients.GetNextClient(pClient))
1150  {
1151  // ignore local
1152  if (pClient->isLocal()) continue;
1153  // client status
1154  const C4ClientCore &Core = pClient->getCore();
1155  const char *szClientStatus;
1156  switch (pClient->getStatus())
1157  {
1158  case NCS_Joining: szClientStatus = " (joining)"; break;
1159  case NCS_Chasing: szClientStatus = " (chasing)"; break;
1160  case NCS_NotReady: szClientStatus = " (!rdy)"; break;
1161  case NCS_Remove: szClientStatus = " (removed)"; break;
1162  default: szClientStatus = ""; break;
1163  }
1164  Stat.AppendFormat( "|- %s %s %s (ID %d) (wait %d ms, behind %d)%s%s",
1165  Core.isObserver() ? "Observing" : Core.isActivated() ? "Active" : "Inactive", Core.isHost() ? "host" : "client",
1166  Core.getName(), Core.getID(),
1167  pControl->ClientPerfStat(pClient->getID()),
1168  ::Control.ControlTick - pControl->ClientNextControl(pClient->getID()),
1169  szClientStatus,
1170  pClient->isActivated() && !pControl->ClientReady(pClient->getID(), ::Control.ControlTick) ? " (!ctrl)" : "");
1171  // connections
1172  if (pClient->isConnected())
1173  {
1174  Stat.AppendFormat( "| Connections: %s: %s (%s p%d l%d)",
1175  pClient->getMsgConn() == pClient->getDataConn() ? "Msg/Data" : "Msg",
1176  NetIO.getNetIOName(pClient->getMsgConn()->getNetClass()),
1177  pClient->getMsgConn()->getPeerAddr().ToString().getData(),
1178  pClient->getMsgConn()->getPingTime(),
1179  pClient->getMsgConn()->getPacketLoss());
1180  if (pClient->getMsgConn() != pClient->getDataConn())
1181  Stat.AppendFormat( ", Data: %s (%s p%d l%d)",
1182  NetIO.getNetIOName(pClient->getDataConn()->getNetClass()),
1183  pClient->getDataConn()->getPeerAddr().ToString().getData(),
1184  pClient->getDataConn()->getPingTime(),
1185  pClient->getDataConn()->getPacketLoss());
1186  }
1187  else
1188  Stat.Append("| Not connected");
1189  }
1190  if (!Clients.GetNextClient(nullptr))
1191  Stat.Append("| - none -");
1192 
1193  // draw
1194  pDraw->TextOut(Stat.getData(), ::GraphicsResource.FontRegular, 1.0, cgo.Surface,cgo.X + 20,cgo.Y + 50);
1195 }
C4Draw * pDraw
Definition: C4Draw.cpp:42
@ CNM_Decentral
@ CNM_Central
C4GraphicsResource GraphicsResource
@ NCS_Remove
@ NCS_Chasing
@ NCS_Joining
@ NCS_NotReady
C4Network2IOProtocol
Definition: C4Network2IO.h:30
@ P_NONE
Definition: C4Network2IO.h:31
@ P_UDP
Definition: C4Network2IO.h:31
@ P_TCP
Definition: C4Network2IO.h:31
bool isObserver() const
Definition: C4Client.h:60
const char * getName() const
Definition: C4Client.h:69
int32_t getID() const
Definition: C4Client.h:57
bool isHost() const
Definition: C4Client.h:58
bool isActivated() const
Definition: C4Client.h:59
int32_t PortUDP
Definition: C4Config.h:153
int32_t PortTCP
Definition: C4Config.h:153
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:561
C4Surface * Surface
Definition: C4Facet.h:117
float Y
Definition: C4Facet.h:118
float X
Definition: C4Facet.h:118
int32_t ControlRate
Definition: C4GameControl.h:88
int32_t ClientNextControl(int32_t iClientID)
int32_t ClientPerfStat(int32_t iClientID)
int32_t getAvgControlSendTime() const
int32_t getControlPreSend() const
int32_t GetBehind(int32_t iTick) const
bool ClientReady(int32_t iClientID, int32_t iTick)
const char * getName() const
int32_t getID() const
bool isActivated() const
bool isObserver() const
bool isHost() const
C4Network2Client * GetLocal() const
bool fStreaming
Definition: C4Network2.h:187
C4Record * pStreamedRecord
Definition: C4Network2.h:189
size_t getPendingStreamData() const
Definition: C4Network2.h:300
unsigned int iCurrentStreamPosition
Definition: C4Network2.h:194
C4NetIO * DataIO()
C4Network2IOProtocol getNetIOProt(C4NetIO *pNetIO)
int getProtORate(C4Network2IOProtocol eProt) const
Definition: C4Network2IO.h:154
C4NetIO * MsgIO()
int getProtBCRate(C4Network2IOProtocol eProt) const
Definition: C4Network2IO.h:155
int getProtIRate(C4Network2IOProtocol eProt) const
Definition: C4Network2IO.h:153
const char * getNetIOName(C4NetIO *pNetIO)
int32_t getCtrlMode() const
Definition: C4Network2.h:81
unsigned int GetStreamingPos() const
Definition: C4Record.h:262
const StdBuf & GetStreamingBuf() const
Definition: C4Record.h:263
size_t getSize() const
Definition: StdBuf.h:101
void AppendFormat(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:190
const char * getData() const
Definition: StdBuf.h:442
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EndVote()

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

Definition at line 2718 of file C4Network2.cpp.

2719 {
2720  // Remove all vote packets
2721  C4IDPacket *pPkt; int32_t iOrigin = C4ClientIDUnknown;
2722  while ((pPkt = GetVote(C4ClientIDAll, eType, iData)))
2723  {
2724  if (iOrigin == C4ClientIDUnknown)
2725  iOrigin = static_cast<C4ControlVote *>(pPkt->getPkt())->getByClient();
2726  Votes.Delete(pPkt);
2727  }
2728  // Reset timestamp
2729  iVoteStartTime = time(nullptr);
2730  // Approved own voting? Reset voting block
2731  if (fApprove && iOrigin == Game.Clients.getLocalID())
2732  iLastOwnVoting = 0;
2733  // Dialog open?
2734  if (pVoteDialog)
2735  if (pVoteDialog->getVoteType() == eType && pVoteDialog->getVoteData() == iData)
2736  {
2737  // close
2738  delete pVoteDialog;
2739  pVoteDialog = nullptr;
2740  }
2741  // Did we try to kick ourself? Ask if we'd like to surrender
2742  bool fCancelVote = (eType == VT_Kick && iData == Game.Clients.getLocalID()) || eType == VT_Cancel;
2743  if (!fApprove && fCancelVote && iOrigin == Game.Clients.getLocalID())
2744  OpenSurrenderDialog(eType, iData);
2745  // Check if the dialog should be opened
2746  OpenVoteDialog();
2747  // Pause/unpause voting?
2748  if (fApprove && eType == VT_Pause)
2749  fPausedForVote = !iData;
2750  // No voting left? Reset pause.
2751  if (!Votes.firstPkt())
2752  if (fPausedForVote)
2753  {
2754  Start();
2755  fPausedForVote = false;
2756  }
2757 }
const int32_t C4ClientIDUnknown
Definition: C4Client.h:24
@ VT_Pause
Definition: C4Control.h:564
@ VT_Cancel
Definition: C4Control.h:562
@ VT_Kick
Definition: C4Control.h:563
const int32_t C4ClientIDAll
int32_t getLocalID() const
Definition: C4Client.h:171
void Delete(C4IDPacket *pPkt)
Definition: C4Control.h:88
C4ClientList & Clients
Definition: C4Game.h:69
C4PacketBase * getPkt() const
Definition: C4PacketBase.h:260
void OpenSurrenderDialog(C4ControlVoteType eType, int32_t iData)
bool Start()
Definition: C4Network2.cpp:506
C4IDPacket * GetVote(int32_t iClientID, C4ControlVoteType eType, int32_t iData)
C4ControlVoteType getVoteType() const
Definition: C4Network2.h:402
int32_t getVoteData() const
Definition: C4Network2.h:403

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.

Here is the call graph for this function:

◆ Execute() [1/2]

void C4Network2::Execute ( )

Definition at line 649 of file C4Network2.cpp.

650 {
651 
652  // client connections
654 
655  // status reached?
657 
658  if (isHost())
659  {
660  // remove dynamic
662  RemoveDynamic();
663  // Set chase target
665  // check for inactive clients and deactivate them
667  // reference
668  if (!iLastReferenceUpdate || time(nullptr) > (time_t) (iLastReferenceUpdate + C4NetReferenceUpdateInterval))
669  if (NetIO.IsReferenceNeeded())
670  {
671  // create
673  pRef->InitLocal();
674  // set
675  NetIO.SetReference(pRef);
676  iLastReferenceUpdate = time(nullptr);
677  }
678  // league server reference
679  if (!iLastLeagueUpdate || time(nullptr) > (time_t) (iLastLeagueUpdate + iLeagueUpdateDelay))
680  {
681  LeagueUpdate();
682  }
683  // league update reply receive
685  {
687  }
688  // voting timeout
689  if (Votes.firstPkt() && time(nullptr) > (time_t) (iVoteStartTime + C4NetVotingTimeout))
690  {
691  C4ControlVote *pVote = static_cast<C4ControlVote *>(Votes.firstPkt()->getPkt());
693  CID_VoteEnd,
694  new C4ControlVoteEnd(pVote->getType(), false, pVote->getData()),
695  CDT_Sync);
696  iVoteStartTime = time(nullptr);
697  }
698  // record streaming
699  if (fStreaming)
700  {
701  StreamIn(false);
702  StreamOut();
703  }
704  }
705  else
706  {
707  // request activate, if neccessary
709  }
710 }
@ C4LA_Update
Definition: C4League.h:36
const unsigned int C4NetVotingTimeout
Definition: C4Network2.h:52
const unsigned int C4NetReferenceUpdateInterval
Definition: C4Network2.h:48
@ CID_VoteEnd
Definition: C4PacketBase.h:149
int32_t getData() const
Definition: C4Control.h:582
C4ControlVoteType getType() const
Definition: C4Control.h:580
bool isBusy() const
Definition: C4HTTP.h:86
C4LeagueAction getCurrentAction() const
Definition: C4League.h:216
bool StreamOut()
void UpdateChaseTarget()
void DeactivateInactiveClients()
bool LeagueUpdate()
bool StreamIn(bool fFinish)
bool LeagueUpdateProcessReply()
uint32_t iLeagueUpdateDelay
Definition: C4Network2.h:165
bool fHost
Definition: C4Network2.h:127
bool IsReferenceNeeded()
void SetReference(class C4Network2Reference *pReference)
bool isNull() const
Definition: C4Network2Res.h:85

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(), C4HTTPClient::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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Execute() [2/2]

bool C4ApplicationSec1Timer::Execute
inlineoverrideprotected

Definition at line 131 of file StdScheduler.h.

132  {
133  if (CheckAndReset())
134  OnSec1Timer();
135  return true;
136  }
void OnSec1Timer() override
Definition: C4Network2.cpp:644
bool CheckAndReset()
Definition: StdScheduler.h:107

◆ FinalInit()

bool C4Network2::FinalInit ( )

Definition at line 538 of file C4Network2.cpp.

539 {
540  // check reach
541  CheckStatusReached(true);
542  // reached, waiting for ack?
543  if (fStatusReached && !fStatusAck)
544  {
545  // wait for go acknowledgement
546  Log(LoadResStr("IDS_NET_JOINREADY"));
547 
548  // any pending keyboard commands should not be routed to cancel the wait dialog - flush the message queue!
549  if (!Application.FlushMessages()) return false;
550 
551  // show box
552  C4GUI::Dialog *pDlg = nullptr;
553  if (!Application.isEditor)
554  {
555  // separate dlgs for host/client
556  if (isHost())
557  pDlg = new C4Network2StartWaitDlg();
558  else
559  pDlg = new C4GUI::MessageDialog(LoadResStr("IDS_NET_WAITFORSTART"), LoadResStr("IDS_NET_CAPTION"),
561  // show it
562  if (!pDlg->Show(::pGUI, true)) return false;
563  }
564 
565  // wait for acknowledgement
566  while (fStatusReached && !fStatusAck)
567  {
568  if (pDlg)
569  {
570  // execute
571  if (!pDlg->Execute()) { delete pDlg; Clear(); return false; }
572  // aborted?
573  if (pDlg->IsAborted()) { delete pDlg; Clear(); return false; }
574  }
575  else if (!Application.ScheduleProcs())
576  { Clear(); return false; }
577  }
578  delete pDlg;
579  // log
580  Log(LoadResStr("IDS_NET_START"));
581  }
582  // synchronize
584  Game.Synchronize(false);
585  // finished
586  return isEnabled();
587 }
bool FlushMessages()
Definition: C4AppSDL.cpp:115
bool Show(Screen *pOnScreen, bool fCB)
void SyncClearance()
Definition: C4Game.cpp:3854
void Synchronize(bool save_player_files)
Definition: C4Game.cpp:3859
@ Ico_NetWait
Definition: C4Gui.h:644

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

Referenced by C4Game::Init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FinishStreaming()

bool C4Network2::FinishStreaming ( )

Definition at line 2909 of file C4Network2.cpp.

2910 {
2911  if (!fStreaming) return false;
2912 
2913  // Stream
2914  StreamIn(true);
2915 
2916  // Reset record pointer
2917  pStreamedRecord = nullptr;
2918 
2919  // Try to get rid of remaining data immediately
2920  iLastStreamAttempt = 0;
2921  StreamOut();
2922 
2923  return true;
2924 }
time_t iLastStreamAttempt
Definition: C4Network2.h:188

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

Here is the call graph for this function:

◆ GetLobby()

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

Definition at line 216 of file C4Network2.h.

216 { return pLobby; } // lobby publication

References pLobby.

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

Here is the caller graph for this function:

◆ getNetpuncherAddr()

StdStrBuf C4Network2::getNetpuncherAddr ( ) const
inline

Definition at line 309 of file C4Network2.h.

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

References NetpuncherAddr.

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

Here is the caller graph for this function:

◆ getNetpuncherGameID() [1/2]

C4NetpuncherID C4Network2::getNetpuncherGameID ( ) const
inline

Definition at line 308 of file C4Network2.h.

308 { return NetpuncherGameID; };

References NetpuncherGameID.

Referenced by HandlePuncherPacket(), and OnPuncherConnect().

Here is the caller graph for this function:

◆ getNetpuncherGameID() [2/2]

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

Definition at line 1005 of file C4Network2.cpp.

1006 {
1007  switch (family)
1008  {
1011  case C4NetIO::HostAddress::UnknownFamily: assert(!"Unexpected address family");
1012  }
1013  // We need to return a valid reference to satisfy the compiler, even though the code here is unreachable.
1014  return NetpuncherGameID.v4;
1015 }

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

Referenced by C4Network2Reference::InitLocal().

Here is the caller graph for this function:

◆ GetPassword()

const char* C4Network2::GetPassword ( ) const
inline

Definition at line 217 of file C4Network2.h.

217 { return sPassword.getData(); } // Oh noez, now the password is public!

References StdStrBuf::getData(), and sPassword.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPendingStreamData()

size_t C4Network2::getPendingStreamData ( ) const
inline

Definition at line 300 of file C4Network2.h.

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

References StdBuf::getSize(), StreamCompressor, and StreamingBuf.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetVote()

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

Definition at line 2706 of file C4Network2.cpp.

2707 {
2708  C4ControlVote *pVote;
2709  for (C4IDPacket *pPkt = Votes.firstPkt(); pPkt; pPkt = Votes.nextPkt(pPkt))
2710  if (pPkt->getPktType() == CID_Vote)
2711  if ((pVote = static_cast<C4ControlVote *>(pPkt->getPkt())))
2712  if (iClientID == C4ClientIDUnknown || pVote->getByClient() == iClientID)
2713  if (pVote->getType() == eType && pVote->getData() == iData)
2714  return pPkt;
2715  return nullptr;
2716 }
C4IDPacket * nextPkt(C4IDPacket *pPkt) const
Definition: C4Control.h:79
int32_t getByClient() const
Definition: C4Control.h:42

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleActivateReq()

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

Definition at line 1491 of file C4Network2.cpp.

1492 {
1493  if (!isHost()) return;
1494  // not allowed or already activated? ignore
1495  if (pByClient->isObserver() || pByClient->isActivated()) return;
1496  // not joined completely yet? ignore
1497  if (!pByClient->isWaitedFor()) return;
1498  // check behind limit
1499  if (isRunning())
1500  {
1501  // make a guess how much the client lags.
1502  int32_t iLagFrames = Clamp(pByClient->getMsgConn()->getPingTime() * Game.FPS / 500, 0, 100);
1503  if (iTick < Game.FrameCounter - iLagFrames - C4NetMaxBehind4Activation)
1504  return;
1505  }
1506  // activate him
1508  new C4ControlClientUpdate(pByClient->getID(), CUT_Activate, true),
1509  CDT_Sync);
1510 }
const int C4NetMaxBehind4Activation
Definition: C4Network2.h:41
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:44
int32_t FPS
Definition: C4Game.h:111

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleConn()

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

Definition at line 1220 of file C4Network2.cpp.

1221 {
1222  // security
1223  if (!pConn) return;
1224 
1225  // Handles a connect request (packet PID_Conn).
1226  // Check if this peer should be allowed to connect, make space for the new connection.
1227 
1228  // connection is closed?
1229  if (pConn->isClosed())
1230  return;
1231 
1232  // set up core
1233  const C4ClientCore &CCore = Pkt.getCCore();
1234  C4ClientCore NewCCore = CCore;
1235 
1236  // accept connection?
1237  StdStrBuf reply;
1238  bool fOK = false;
1239 
1240  // search client
1241  if (!pClient && Pkt.getCCore().getID() != C4ClientIDUnknown)
1242  pClient = Clients.GetClient(Pkt.getCCore());
1243 
1244  // check engine version
1245  bool fWrongPassword = false;
1246  if (Pkt.getVer() != C4XVER1*100 + C4XVER2)
1247  {
1248  reply.Format("wrong engine (%d.%d, I have %d.%d)", Pkt.getVer()/100, Pkt.getVer()%100, C4XVER1, C4XVER2);
1249  fOK = false;
1250  }
1251  else
1252  {
1253  if (pClient)
1254  if (CheckConn(NewCCore, pConn, pClient, &reply))
1255  {
1256  // accept
1257  if (!reply) reply = "connection accepted";
1258  fOK = true;
1259  }
1260  // client: host connection?
1261  if (!fOK && !isHost() && Status.getState() == GS_Init && !Clients.GetHost())
1262  if (HostConnect(NewCCore, pConn, &reply))
1263  {
1264  // accept
1265  if (!reply) reply = "host connection accepted";
1266  fOK = true;
1267  }
1268  // host: client join? (NewCCore will be changed by Join()!)
1269  if (!fOK && isHost() && !pClient)
1270  {
1271  // check password
1272  if (!sPassword.isNull() && !SEqual(Pkt.getPassword(), sPassword.getData()))
1273  {
1274  reply = "wrong password";
1275  fWrongPassword = true;
1276  }
1277  // accept join
1278  else if (Join(NewCCore, pConn, &reply))
1279  {
1280  // save core
1281  pConn->SetCCore(NewCCore);
1282  // accept
1283  if (!reply) reply = "join accepted";
1284  fOK = true;
1285  }
1286  }
1287  }
1288 
1289  // denied? set default reason
1290  if (!fOK && !reply) reply = "connection denied";
1291 
1292  // OK and already half accepted? Skip (double-checked: ok).
1293  if (fOK && pConn->isHalfAccepted())
1294  return;
1295 
1296  // send answer
1297  C4PacketConnRe pcr(fOK, fWrongPassword, reply.getData());
1298  if (!pConn->Send(MkC4NetIOPacket(PID_ConnRe, pcr)))
1299  return;
1300 
1301  // accepted?
1302  if (fOK)
1303  {
1304  // set status
1305  if (!pConn->isClosed())
1306  pConn->SetHalfAccepted();
1307  }
1308  // denied? close
1309  else
1310  {
1311  // log & close
1312  LogSilentF("Network: connection by %s (%s) blocked: %s", CCore.getName(), pConn->getPeerAddr().ToString().getData(), reply.getData());
1313  pConn->Close();
1314  }
1315 }
@ GS_Init
Definition: C4Network2.h:63
@ PID_ConnRe
Definition: C4PacketBase.h:89
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93
C4Network2Client * GetClient(const char *szName) const
C4Network2Client * GetHost()
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)
bool fWrongPassword
Definition: C4Network2.h:175
void SetCCore(const C4ClientCore &nCCore)
const C4NetIO::addr_t & getPeerAddr() const
Definition: C4Network2IO.h:266
bool isHalfAccepted() const
Definition: C4Network2IO.h:288
bool Send(const C4NetIOPacket &rPkt)
bool isNull() const
Definition: StdBuf.h:441
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174
StdStrBuf ToString(int flags=0) const
Definition: C4NetIO.cpp:604

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleConnRe()

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

Definition at line 1385 of file C4Network2.cpp.

1386 {
1387  // Handle the connection request reply. After this handling, the connection should
1388  // be either fully associated with a client (fully accepted) or closed.
1389  // Note that auto-accepted connection have to processed here once, too, as the
1390  // client must get associated with the connection. After doing so, the connection
1391  // auto-accept flag will be reset to mark the connection fully accepted.
1392 
1393  // security
1394  if (!pConn) return;
1395  if (!pClient) { pConn->Close(); return; }
1396 
1397  // negative reply?
1398  if (!Pkt.isOK())
1399  {
1400  // wrong password?
1401  fWrongPassword = Pkt.isPasswordWrong();
1402  // show message
1403  LogSilentF("Network: connection to %s (%s) refused: %s", pClient->getName(), pConn->getPeerAddr().ToString().getData(), Pkt.getMsg());
1404  // close connection
1405  pConn->Close();
1406  return;
1407  }
1408 
1409  // connection is closed?
1410  if (!pConn->isOpen())
1411  return;
1412 
1413  // already accepted? ignore
1414  if (pConn->isAccepted() && !pConn->isAutoAccepted()) return;
1415 
1416  // first connection?
1417  bool fFirstConnection = !pClient->isConnected();
1418 
1419  // accept connection
1420  pConn->SetAccepted(); pConn->ResetAutoAccepted();
1421 
1422  // add connection
1423  pConn->SetCCore(pClient->getCore());
1424  if (pConn->getNetClass() == NetIO.MsgIO()) pClient->SetMsgConn(pConn);
1425  if (pConn->getNetClass() == NetIO.DataIO()) pClient->SetDataConn(pConn);
1426 
1427  // add peer connect address to client address list
1428  if (!pConn->getConnectAddr().IsNull())
1429  {
1430  C4Network2Address Addr(pConn->getConnectAddr(), pConn->getProtocol());
1431  pClient->AddAddr(Addr, Status.getState() != GS_Init);
1432  }
1433 
1434  // handle
1435  OnConnect(pClient, pConn, Pkt.getMsg(), fFirstConnection);
1436 }
bool isConnected() const
void SetDataConn(C4Network2IOConnection *pConn)
bool AddAddr(const C4Network2Address &addr, bool fAnnounce)
void SetMsgConn(C4Network2IOConnection *pConn)
void OnConnect(C4Network2Client *pClient, C4Network2IOConnection *pConn, const char *szMsg, bool fFirstConnection)
C4NetIO * getNetClass() const
Definition: C4Network2IO.h:264
bool isAccepted() const
Definition: C4Network2IO.h:289
bool isAutoAccepted() const
Definition: C4Network2IO.h:291
const C4NetIO::addr_t & getConnectAddr() const
Definition: C4Network2IO.h:267
C4Network2IOProtocol getProtocol() const
Definition: C4Network2IO.h:265

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleJoinData()

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

Definition at line 1512 of file C4Network2.cpp.

1513 {
1514  // init only
1515  if (Status.getState() != GS_Init)
1516  { LogSilentF("Network: unexpected join data received!"); return; }
1517  // get client ID
1518  if (rPkt.getClientID() == C4ClientIDUnknown)
1519  { LogSilentF("Network: host didn't set client ID!"); Clear(); return; }
1520  // set local ID
1521  ResList.SetLocalID(rPkt.getClientID());
1522  Game.Parameters.Clients.SetLocalID(rPkt.getClientID());
1523  // read and validate status
1524  HandleStatus(rPkt.getStatus());
1525  if (Status.getState() != GS_Lobby && Status.getState() != GS_Pause && Status.getState() != GS_Go)
1526  { LogSilentF("Network: join data has bad game status: %s", Status.getStateName()); Clear(); return; }
1527  // copy scenario parameter defs for lobby display
1528  ::Game.ScenarioParameterDefs = rPkt.ScenarioParameterDefs;
1529  // copy parameters
1530  ::Game.Parameters = rPkt.Parameters;
1531  // set local client
1532  C4Client *pLocalClient = Game.Clients.getClientByID(rPkt.getClientID());
1533  if (!pLocalClient)
1534  { LogSilentF("Network: Could not find local client in join data!"); Clear(); return; }
1535  // save back dynamic data
1536  ResDynamic = rPkt.getDynamicCore();
1537  iDynamicTick = rPkt.getStartCtrlTick();
1538  // initialize control
1539  ::Control.ControlRate = rPkt.Parameters.ControlRate;
1540  pControl->Init(rPkt.getClientID(), false, rPkt.getStartCtrlTick(), pLocalClient->isActivated(), this);
1542  // set local core
1543  NetIO.SetLocalCCore(pLocalClient->getCore());
1544  // add the resources to the network resource list
1546  // load dynamic
1548  { LogFatal("Network: can not not retrieve dynamic!"); Clear(); return; }
1549  // load player resources
1551  // send additional addresses
1552  Clients.SendAddresses(nullptr);
1553 }
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:239
bool isActivated() const
Definition: C4Client.h:110
const C4ClientCore & getCore() const
Definition: C4Client.h:104
C4Client * getClientByID(int32_t iID) const
Definition: C4Client.cpp:200
void SetLocalID(int32_t iID)
Definition: C4Client.cpp:324
void CopyClientList(const C4ClientList &rClients)
bool Init(int32_t iClientID, bool fHost, int32_t iStartTick, bool fActivated, C4Network2 *pNetwork)
class C4ScenarioParameterDefs & ScenarioParameterDefs
Definition: C4Game.h:75
C4GameResList GameRes
C4ClientList Clients
C4PlayerInfoList PlayerInfos
bool InitNetwork(C4Network2ResList *pNetResList)
void SendAddresses(C4Network2IOConnection *pConn)
void HandleStatus(const C4Network2Status &nStatus)
void SetLocalCCore(const C4ClientCore &CCore)
void SetLocalID(int32_t iClientID)
C4Network2Res::Ref AddByCore(const C4Network2ResCore &Core, bool fLoad=true)

References C4Network2ResList::AddByCore(), C4ClientIDUnknown, Clear(), C4GameParameters::Clients, C4Game::Clients, 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(), C4Network2ResList::SetLocalID(), C4ClientList::SetLocalID(), and Status.

Referenced by HandlePacket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleLobbyPacket()

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

Definition at line 963 of file C4Network2.cpp.

964 {
965  // find associated client
966  C4Network2Client *pClient = Clients.GetClient(pConn);
967  if (!pClient) pClient = Clients.GetClientByID(pConn->getClientID());
968  // forward directly to lobby
969  if (pLobby) pLobby->HandlePacket(cStatus, pBasePkt, pClient);
970 }
void HandlePacket(char cStatus, const C4PacketBase *pBasePkt, C4Network2Client *pClient)
C4Network2Client * GetClientByID(int32_t iID) const

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

Referenced by C4Network2IO::CallHandlers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandlePacket()

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

Definition at line 879 of file C4Network2.cpp.

880 {
881  // find associated client
882  C4Network2Client *pClient = Clients.GetClient(pConn);
883  if (!pClient) pClient = Clients.GetClientByID(pConn->getClientID());
884 
885  // local? ignore
886  if (pClient && pClient->isLocal()) { pConn->Close(); return; }
887 
888 #define GETPKT(type, name) \
889  assert(pPacket); const type &name = \
890  static_cast<const type &>(*pPacket);
891 
892  switch (cStatus)
893  {
894  case PID_Conn: // connection request
895  {
896  if (!pConn->isOpen()) break;
897  GETPKT(C4PacketConn, rPkt);
898  HandleConn(rPkt, pConn, pClient);
899  }
900  break;
901 
902  case PID_ConnRe: // connection request reply
903  {
904  GETPKT(C4PacketConnRe, rPkt);
905  HandleConnRe(rPkt, pConn, pClient);
906  }
907  break;
908 
909  case PID_JoinData:
910  {
911  // host->client only
912  if (isHost() || !pClient || !pClient->isHost()) break;
913  if (!pConn->isOpen()) break;
914  // handle
915  GETPKT(C4PacketJoinData, rPkt)
916  HandleJoinData(rPkt);
917  }
918  break;
919 
920  case PID_Status: // status change
921  {
922  // by host only
923  if (isHost() || !pClient || !pClient->isHost()) break;
924  if (!pConn->isOpen()) break;
925  // must be initialized
926  if (Status.getState() == GS_Init) break;
927  // handle
928  GETPKT(C4Network2Status, rPkt);
929  HandleStatus(rPkt);
930  }
931  break;
932 
933  case PID_StatusAck: // status change acknowledgement
934  {
935  // host->client / client->host only
936  if (!pClient) break;
937  if (!isHost() && !pClient->isHost()) break;
938  // must be initialized
939  if (Status.getState() == GS_Init) break;
940  // handle
941  GETPKT(C4Network2Status, rPkt);
942  HandleStatusAck(rPkt, pClient);
943  }
944  break;
945 
946  case PID_ClientActReq: // client activation request
947  {
948  // client->host only
949  if (!isHost() || !pClient || pClient->isHost()) break;
950  // must be initialized
951  if (Status.getState() == GS_Init) break;
952  // handle
954  HandleActivateReq(rPkt.getTick(), pClient);
955  }
956  break;
957 
958  }
959 
960 #undef GETPKT
961 }
#define GETPKT(type, name)
@ PID_JoinData
Definition: C4PacketBase.h:116
@ PID_ClientActReq
Definition: C4PacketBase.h:110
@ PID_Conn
Definition: C4PacketBase.h:88
bool isLocal() const
void HandleJoinData(const class C4PacketJoinData &rPkt)
void HandleActivateReq(int32_t iTick, C4Network2Client *pClient)
void HandleStatusAck(const C4Network2Status &nStatus, C4Network2Client *pClient)
void HandleConnRe(const class C4PacketConnRe &Pkt, C4Network2IOConnection *pConn, C4Network2Client *pClient)
void HandleConn(const class C4PacketConn &Pkt, C4Network2IOConnection *pConn, C4Network2Client *pClient)

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

Referenced by C4Network2IO::CallHandlers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandlePuncherPacket()

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

Definition at line 972 of file C4Network2.cpp.

973 {
974  // TODO: is this all thread-safe?
975  assert(pkt);
976 #define GETPKT(c) dynamic_cast<C4NetpuncherPacket##c*>(pkt.get())
977  switch (pkt->GetType())
978  {
979  case PID_Puncher_CReq:
980  if (isHost())
981  {
982  NetIO.Punch(GETPKT(CReq)->GetAddr());
983  return true;
984  }
985  else
986  {
987  // The IP/Port should be already in the masterserver list, so just keep trying.
988  return Status.getState() == GS_Init;
989  }
990  case PID_Puncher_AssID:
991  if (isHost())
992  {
993  getNetpuncherGameID(family) = GETPKT(AssID)->GetID();
995  }
996  else
997  {
998  // The netpuncher hands out IDs for everyone, but clients have no use for them.
999  }
1000  return true;
1001  default: return false;
1002  }
1003 }
@ PID_Puncher_CReq
@ PID_Puncher_AssID
C4NetpuncherID getNetpuncherGameID() const
Definition: C4Network2.h:308
void Punch(const C4NetIO::addr_t &)

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

Referenced by C4Network2IO::HandlePuncherPacket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleStatus()

void C4Network2::HandleStatus ( const C4Network2Status nStatus)
protected

Definition at line 1438 of file C4Network2.cpp.

1439 {
1440  // set
1441  Status = nStatus;
1442  // log
1443  LogSilentF("Network: going into status %s (tick %d)", Status.getStateName(), nStatus.getTargetCtrlTick());
1444  // reset flags
1445  fStatusReached = fStatusAck = false;
1446  // check: reached?
1448 }

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

Referenced by HandleJoinData(), and HandlePacket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleStatusAck()

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

Definition at line 1450 of file C4Network2.cpp.

1451 {
1452  // security
1453  if (!pClient->hasJoinData() || pClient->isRemoved()) return;
1454  // status doesn't match?
1455  if (nStatus.getState() != Status.getState() || nStatus.getTargetCtrlTick() < Status.getTargetCtrlTick())
1456  return;
1457  // host: wait until all clients are ready
1458  if (isHost())
1459  {
1460  // check: target tick change?
1461  if (!fStatusAck && nStatus.getTargetCtrlTick() > Status.getTargetCtrlTick())
1462  // take the new status
1463  ChangeGameStatus(nStatus.getState(), nStatus.getTargetCtrlTick());
1464  // already acknowledged? Send another ack
1465  if (fStatusAck)
1466  pClient->SendMsg(MkC4NetIOPacket(PID_StatusAck, nStatus));
1467  // mark as ready (will clear chase-flag)
1468  pClient->SetStatus(NCS_Ready);
1469  // check: everyone ready?
1470  if (!fStatusAck && fStatusReached)
1471  CheckStatusAck();
1472  }
1473  else
1474  {
1475  // target tick doesn't match? ignore
1476  if (nStatus.getTargetCtrlTick() != Status.getTargetCtrlTick())
1477  return;
1478  // reached?
1479  // can be ignored safely otherwise - when the status is reached, we will send
1480  // status ack on which the host should generate another status ack (see above)
1481  if (fStatusReached)
1482  {
1483  // client: set flags, call handler
1484  fStatusAck = true; fChasing = false;
1485  OnStatusAck();
1486  }
1487 
1488  }
1489 }
@ NCS_Ready
void SetStatus(C4Network2ClientStatus enStatus)
bool SendMsg(C4NetIOPacket rPkt) const
bool hasJoinData() const
bool isRemoved() const

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HostConnect()

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

Definition at line 1330 of file C4Network2.cpp.

1331 {
1332  if (!pConn) return false;
1333  if (!CCore.isHost()) { *szReply = "not host"; return false; }
1334  // create client class for host
1335  // (core is unofficial, see InitClient() - will be overwritten later in HandleJoinData)
1336  C4Client *pClient = Game.Clients.Add(CCore);
1337  if (!pClient) return false;
1338  // accept
1339  return true;
1340 }
void Add(C4Client *pClient)
Definition: C4Client.cpp:181

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

Referenced by HandleConn().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitClient() [1/2]

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

Referenced by C4Game::InitNetworkFromReference().

Here is the caller graph for this function:

◆ InitClient() [2/2]

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

◆ InitHost()

bool C4Network2::InitHost ( bool  fLobby)

Definition at line 139 of file C4Network2.cpp.

140 {
141  if (isEnabled()) Clear();
142  // initialize everything
143  Status.Set(fLobby ? GS_Lobby : GS_Go, ::Control.ControlTick);
145  fHost = true;
146  fStatusAck = fStatusReached = true;
147  fChasing = false;
148  fAllowJoin = false;
152  // initialize client list
153  Clients.Init(&Game.Clients, true);
154  // initialize resource list
156  { LogFatal("Network: failed to initialize resource list!"); Clear(); return false; }
158  return false;
159  // create initial dynamic
160  if (!CreateDynamic(true))
161  return false;
162  // initialize net i/o
163  if (!InitNetIO(false, true))
164  { Clear(); return false; }
165  // init network control
167  pControl->Init(C4ClientIDHost, true, ::Control.getNextControlTick(), true, this);
168  // init league
169  bool fCancel = true;
170  if (!InitLeague(&fCancel) || !LeagueStart(&fCancel))
171  {
172  // deinit league
173  DeinitLeague();
174  // user cancelled?
175  if (fCancel)
176  return false;
177  // in console mode, bail out
178 #ifdef USE_CONSOLE
179  return false;
180 #endif
181  }
182  // allow connect
183  NetIO.SetAcceptMode(true);
184  // timer
185  Application.Add(this);
186  // ok
187  return true;
188 }
const int32_t C4ClientIDHost
Definition: C4Client.h:25
const int32_t C4ClientIDStart
Definition: C4Client.h:26
char PuncherAddress[CFG_MaxString+1]
Definition: C4Config.h:160
int32_t ControlMode
Definition: C4Config.h:155
C4GameControlNetwork Network
Definition: C4GameControl.h:67
bool InitNetwork(C4Network2ResList *pResList)
void Init(C4ClientList *pClientList, bool fHost)
bool LeagueStart(bool *pCancel)
bool InitNetIO(bool fNoClientID, bool fHost)
int32_t iNextClientID
Definition: C4Network2.h:155
bool InitLeague(bool *pCancel)
bool CreateDynamic(bool fInit)
void SetAcceptMode(bool fAcceptAll)
bool Init(int32_t iClientID, C4Network2IO *pIOClass)
void Add(StdSchedulerProc *pProc)

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, C4Network2ClientList::Init(), C4GameControlNetwork::Init(), C4Network2ResList::Init(), InitLeague(), InitNetIO(), C4GameParameters::InitNetwork(), isEnabled(), LeagueStart(), LogFatal(), NetIO, NetpuncherAddr, NetpuncherGameID, C4Config::Network, C4GameControl::Network, C4Game::Parameters, pControl, C4ConfigNetwork::PuncherAddress, ResList, C4Network2Status::Set(), C4Network2IO::SetAcceptMode(), C4Network2Status::SetCtrlMode(), and Status.

Referenced by C4Game::InitNetworkHost().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitLeague()

bool C4Network2::InitLeague ( bool *  pCancel)
protected

Definition at line 2047 of file C4Network2.cpp.

2048 {
2049 
2050  if (fHost)
2051  {
2052 
2053  // Clear parameters
2057  delete pLeagueClient;
2058  pLeagueClient = nullptr;
2059 
2060  // Not needed?
2062  return true;
2063 
2064  // Save address
2067  {
2069  // enforce some league rules
2071  }
2072 
2073  }
2074  else
2075  {
2076 
2077  // Get league server from parameters
2079 
2080  // Not needed?
2082  return true;
2083 
2084  }
2085 
2086  // Init
2087  pLeagueClient = new C4LeagueClient();
2088  if (!pLeagueClient->Init() ||
2090  {
2091  // Log message
2092  StdStrBuf Message = FormatString(LoadResStr("IDS_NET_ERR_LEAGUEINIT"), pLeagueClient->GetError());
2093  LogFatal(Message.getData());
2094  // Clear league
2095  delete pLeagueClient; pLeagueClient = nullptr;
2096  if (fHost)
2098  // Show message, allow abort
2099  bool fResult = true;
2100  if (!Application.isEditor)
2101  fResult = ::pGUI->ShowMessageModal(Message.getData(), LoadResStr("IDS_NET_ERR_LEAGUE"),
2104  if (pCancel) *pCancel = fResult;
2105  return false;
2106  }
2107 
2108  // Add to message loop
2110 
2111  // OK
2112  return true;
2113 }
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
int32_t MasterServerSignUp
Definition: C4Config.h:147
const char * GetLeagueServerAddress()
Definition: C4Config.cpp:661
int32_t LeagueServerSignUp
Definition: C4Config.h:151
bool ShowMessageModal(const char *szMessage, const char *szCaption, DWORD dwButtons, Icons icoIcon, int32_t *piConfigDontShowAgainSetting=nullptr)
C4Scenario C4S
Definition: C4Game.h:74
void EnforceLeagueRules(class C4Scenario *pScenario)
bool Init()
Definition: C4HTTP.cpp:42
virtual const char * GetError() const
Definition: C4HTTP.h:96
bool SetServer(const char *szServerAddress)
Definition: C4HTTP.cpp:298
size_t getLength() const
Definition: StdBuf.h:445
@ Ico_Error
Definition: C4Gui.h:652

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

Referenced by InitHost(), and LeagueSignupEnable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitNetIO()

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

Definition at line 1197 of file C4Network2.cpp.

1198 {
1199  // clear
1200  NetIO.Clear();
1202  // discovery: disable for client
1203  int16_t iPortDiscovery = fHost ? Config.Network.PortDiscovery : -1;
1204  int16_t iPortRefServer = fHost ? Config.Network.PortRefServer : -1;
1205  // init subclass
1206  if (!NetIO.Init(Config.Network.PortTCP, Config.Network.PortUDP, iPortDiscovery, iPortRefServer, fHost, !!Config.Network.EnableUPnP))
1207  return false;
1208  // set core (unset ID if sepecified, has to be set later)
1210  if (fNoClientID) Core.SetID(C4ClientIDUnknown);
1211  NetIO.SetLocalCCore(Core);
1212  // safe addresses of local client
1214  NetIO.hasTCP() ? Config.Network.PortTCP : -1,
1215  NetIO.hasUDP() ? Config.Network.PortUDP : -1);
1216  // ok
1217  return true;
1218 }
void SetID(int32_t inID)
Definition: C4Client.h:62
const C4ClientCore & getLocalCore() const
Definition: C4Client.h:169
void CheckPortsForCollisions()
Definition: C4Config.cpp:685
int32_t EnableUPnP
Definition: C4Config.h:154
int32_t PortRefServer
Definition: C4Config.h:153
int32_t PortDiscovery
Definition: C4Config.h:153
void AddLocalAddrs(int16_t iPortTCP, int16_t iPortUDP)
bool hasUDP() const
Definition: C4Network2IO.h:108
bool hasTCP() const
Definition: C4Network2IO.h:107
bool Init(int16_t iPortTCP, int16_t iPortUDP, int16_t iPortDiscovery=-1, int16_t iPortRefServer=-1, bool fBroadcast=false, bool enable_upnp=true)

References C4Network2Client::AddLocalAddrs(), C4ClientIDUnknown, C4ConfigNetwork::CheckPortsForCollisions(), C4Network2IO::Clear(), C4Game::Clients, Clients, Config, C4ConfigNetwork::EnableUPnP, fHost, 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitPuncher()

void C4Network2::InitPuncher ( )
protected

Definition at line 1044 of file C4Network2.cpp.

1045 {
1046  // We have an internet connection, so let's punch the puncher server here in order to open an udp port
1047  C4NetIO::addr_t PuncherAddr;
1049  if (!PuncherAddr.IsNull())
1050  {
1051  PuncherAddr.SetDefaultPort(C4NetStdPortPuncher);
1052  NetIO.InitPuncher(PuncherAddr);
1053  }
1055  if (!PuncherAddr.IsNull())
1056  {
1057  PuncherAddr.SetDefaultPort(C4NetStdPortPuncher);
1058  NetIO.InitPuncher(PuncherAddr);
1059  }
1060 }
const int16_t C4NetStdPortPuncher
Definition: C4Network2.h:33
StdStrBuf getNetpuncherAddr() const
Definition: C4Network2.h:309
bool InitPuncher(C4NetIO::addr_t PuncherAddr)
void SetAddress(const sockaddr *addr)
Definition: C4NetIO.cpp:364
void SetDefaultPort(uint16_t port)
Definition: C4NetIO.cpp:541

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InvalidateReference()

void C4Network2::InvalidateReference ( )

Definition at line 2040 of file C4Network2.cpp.

2041 {
2042  // Update both local and league reference as soon as possible
2045 }
const unsigned int C4NetMinLeagueUpdateInterval
Definition: C4Network2.h:49

References C4NetMinLeagueUpdateInterval, iLastReferenceUpdate, and iLeagueUpdateDelay.

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

Here is the caller graph for this function:

◆ isEnabled()

bool C4Network2::isEnabled ( ) const
inline

Definition at line 203 of file C4Network2.h.

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

References C4Network2Status::isEnabled(), and Status.

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(), C4Game::Init(), C4Network2Players::Init(), C4Game::InitControl(), 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isFrozen()

bool C4Network2::isFrozen ( ) const

Definition at line 1805 of file C4Network2.cpp.

1806 {
1807  // "frozen" means all clients are garantueed to be in the same tick.
1808  // This is only the case if the game is not started yet (lobby) or the
1809  // tick has been ensured (pause) and acknowledged by all joined clients.
1810  // Note unjoined clients must be ignored here - they can't be faster than
1811  // the host, anyway.
1812  if (Status.getState() == GS_Lobby) return true;
1813  if (Status.getState() == GS_Pause && fStatusAck) return true;
1814  return false;
1815 }

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isHost()

bool C4Network2::isHost ( ) const
inline

Definition at line 209 of file C4Network2.h.

209 { return fHost; }

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(), HandlePacket(), C4Network2Players::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().

Here is the caller graph for this function:

◆ isJoinAllowed()

bool C4Network2::isJoinAllowed ( ) const
inline

Definition at line 213 of file C4Network2.h.

213 { return fAllowJoin; }

References fAllowJoin.

Referenced by C4Network2Reference::InitLocal().

Here is the caller graph for this function:

◆ isLobbyActive()

bool C4Network2::isLobbyActive ( ) const
inline

Definition at line 204 of file C4Network2.h.

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

References C4Network2Status::isLobbyActive(), and Status.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isLobbyCountDown()

bool C4Network2::isLobbyCountDown ( )
inline

Definition at line 297 of file C4Network2.h.

297 { return pLobbyCountdown != nullptr; }

References pLobbyCountdown.

Referenced by C4MessageInput::ProcessCommand().

Here is the caller graph for this function:

◆ isObservingAllowed()

bool C4Network2::isObservingAllowed ( ) const
inline

Definition at line 214 of file C4Network2.h.

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

References fAllowObserve.

Referenced by C4Network2Reference::InitLocal().

Here is the caller graph for this function:

◆ isPassworded()

bool C4Network2::isPassworded ( ) const
inline

Definition at line 218 of file C4Network2.h.

218 { return !sPassword.isNull(); }

References StdStrBuf::isNull(), and sPassword.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isPastLobby()

bool C4Network2::isPastLobby ( ) const
inline

Definition at line 205 of file C4Network2.h.

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

References C4Network2Status::isPastLobby(), and Status.

Here is the call graph for this function:

◆ isPaused()

bool C4Network2::isPaused ( ) const
inline

Definition at line 207 of file C4Network2.h.

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

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

Here is the call graph for this function:

◆ isPausing()

bool C4Network2::isPausing ( ) const
inline

Definition at line 208 of file C4Network2.h.

208 { return Status.isPaused() && !fStatusAck; }

References fStatusAck, C4Network2Status::isPaused(), and Status.

Here is the call graph for this function:

◆ isRunning()

bool C4Network2::isRunning ( ) const
inline

Definition at line 206 of file C4Network2.h.

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

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isStatusAck()

bool C4Network2::isStatusAck ( ) const
inline

Definition at line 210 of file C4Network2.h.

210 { return fStatusAck; }

References fStatusAck.

Referenced by isPaused(), and isRunning().

Here is the caller graph for this function:

◆ isStreaming()

bool C4Network2::isStreaming ( ) const

Definition at line 3049 of file C4Network2.cpp.

3050 {
3051  // Streaming must be active and there must still be anything to stream
3052  return fStreaming;
3053 }

References fStreaming.

◆ Join()

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

Definition at line 1342 of file C4Network2.cpp.

1343 {
1344  if (!pConn) return false;
1345  // security
1346  if (!isHost()) { *szReply = "not host"; return false; }
1347  if (!fAllowJoin && !fAllowObserve) { *szReply = "join denied"; return false; }
1348  if (CCore.getID() != C4ClientIDUnknown) { *szReply = "join with set id not allowed"; return false; }
1349  // find free client id
1350  CCore.SetID(iNextClientID++);
1351  // observer?
1352  if (!fAllowJoin) CCore.SetObserver(true);
1353  // deactivate - client will have to ask for activation.
1354  CCore.SetActivated(false);
1355  // Name already in use? Find unused one
1356  if (Clients.GetClient(CCore.getName()))
1357  {
1358  char szNameTmpl[256+1], szNewName[256+1];
1359  SCopy(CCore.getName(), szNameTmpl, 254); SAppend("%d", szNameTmpl, 256);
1360  int32_t i = 1;
1361  do
1362  sprintf(szNewName, szNameTmpl, ++i);
1363  while (Clients.GetClient(szNewName));
1364  CCore.SetName(szNewName);
1365  }
1366  // join client
1368  // get client, set status
1369  C4Network2Client *pClient = Clients.GetClient(CCore);
1370  if (pClient) pClient->SetStatus(NCS_Joining);
1371  // warn if client revision doesn't match our host revision
1373  {
1374  LogF("[!]WARNING! Client %s engine revision (%s) differs from local revision (%s). Client might run out of sync.", CCore.getName(), CCore.getRevision(), Application.GetRevision());
1375  }
1376  // ok, client joined.
1377  return true;
1378  // Note that the connection isn't fully accepted at this point and won't be
1379  // associated with the client. The new-created client is waiting for connect.
1380  // Somewhat ironically, the connection may still timeout (resulting in an instant
1381  // removal and maybe some funny message sequences).
1382  // The final client initialization will be done at OnClientConnect.
1383 }
@ CDT_Direct
Definition: C4GameControl.h:36
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:262
@ CID_ClientJoin
Definition: C4PacketBase.h:144
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:213
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:263
const char * GetRevision() const
Definition: C4Application.h:72
void SetObserver(bool fnObserver)
Definition: C4Client.h:65
const char * getRevision() const
Definition: C4Client.h:72
void SetActivated(bool fnActivated)
Definition: C4Client.h:64
void SetName(const char *sznName)
Definition: C4Client.h:63

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

Referenced by HandleConn().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LeagueEnd()

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

Definition at line 2343 of file C4Network2.cpp.

2344 {
2345  C4RoundResultsPlayers RoundResults;
2346  StdStrBuf sResultMessage;
2347  bool fIsError = true;
2348 
2349  // Not needed?
2350  if (!pLeagueClient || !fHost || fLeagueEndSent)
2351  return true;
2352 
2353  // Make sure league client is available
2355 
2356  // Try until either aborted or successful
2357  const int MAX_RETRIES = 10;
2358  for (int iRetry = 0; iRetry < MAX_RETRIES; iRetry++)
2359  {
2360 
2361  // Do update
2362  C4Network2Reference Ref;
2363  Ref.InitLocal();
2364  if (!pLeagueClient->End(Ref, szRecordName, pRecordSHA))
2365  {
2366  // Log message
2367  sResultMessage = FormatString(LoadResStr("IDS_NET_ERR_LEAGUE_FINISHGAME"), pLeagueClient->GetError());
2368  Log(sResultMessage.getData());
2369  // Show message, allow retry
2370  if (Application.isEditor) break;
2371  bool fRetry = ::pGUI->ShowMessageModal(sResultMessage.getData(), LoadResStr("IDS_NET_ERR_LEAGUE"),
2373  if (fRetry) continue;
2374  break;
2375  }
2376  // Let's wait for response
2377  StdStrBuf Message = FormatString(LoadResStr("IDS_NET_LEAGUE_SENDRESULT"), pLeagueClient->getServerName());
2378  Log(Message.getData());
2379  // Wait for response
2380  while (pLeagueClient->isBusy())
2381  {
2382  // Check if league server has responded
2383  if (!pLeagueClient->Execute(100))
2384  break;
2385  }
2386  // Error?
2387  StdStrBuf LeagueServerMessage;
2388  if (!pLeagueClient->isSuccess() || !pLeagueClient->GetEndReply(&LeagueServerMessage, &RoundResults))
2389  {
2390  const char *pError = pLeagueClient->GetError() ? pLeagueClient->GetError() :
2391  LeagueServerMessage.getLength() ? LeagueServerMessage.getData() :
2392  LoadResStr("IDS_NET_ERR_LEAGUE_EMPTYREPLY");
2393  sResultMessage.Take(FormatString(LoadResStr("IDS_NET_ERR_LEAGUE_SENDRESULT"), pError));
2394  if (Application.isEditor) continue;
2395  // Only retry if we didn't get an answer from the league server
2396  bool fRetry = !pLeagueClient->isSuccess();
2397  fRetry = ::pGUI->ShowMessageModal(sResultMessage.getData(), LoadResStr("IDS_NET_ERR_LEAGUE"),
2400  if (fRetry) continue;
2401  }
2402  else
2403  {
2404  // All OK!
2405  sResultMessage.Copy(LoadResStr(Game.Parameters.isLeague() ? "IDS_MSG_LEAGUEEVALUATIONSUCCESSFU" : "IDS_MSG_INTERNETGAMEEVALUATED"));
2406  fIsError = false;
2407  }
2408  // Done
2409  break;
2410  }
2411 
2412  // Show message
2413  Log(sResultMessage.getData());
2414 
2415  // Take round results
2416  Game.RoundResults.EvaluateLeague(sResultMessage.getData(), !fIsError, RoundResults);
2417 
2418  // Send round results to other clients
2419  C4PacketLeagueRoundResults LeagueUpdatePacket(sResultMessage.getData(), !fIsError, RoundResults);
2421 
2422  // All done
2423  fLeagueEndSent = true;
2424  return true;
2425 }
@ PID_LeagueRoundResults
Definition: C4PacketBase.h:122
C4RoundResults & RoundResults
Definition: C4Game.h:73
bool isLeague() const
bool isSuccess() const
Definition: C4HTTP.h:88
bool Execute(int iMaxTime=-1, pollfd *readyfds=nullptr) override
Definition: C4HTTP.cpp:59
const char * getServerName() const
Definition: C4HTTP.h:94
bool GetEndReply(StdStrBuf *pMessage, class C4RoundResultsPlayers *pRoundResults)
Definition: C4League.cpp:390
bool End(const C4Network2Reference &Ref, const char *szRecordName, const BYTE *pRecordSHA)
Definition: C4League.cpp:375
bool fLeagueEndSent
Definition: C4Network2.h:166
void LeagueWaitNotBusy()
void EvaluateLeague(const char *szResultMsg, bool fSuccess, const C4RoundResultsPlayers &rLeagueInfo)
void Copy()
Definition: StdBuf.h:467
void Take(char *pnData)
Definition: StdBuf.h:457

References Application, C4Network2ClientList::BroadcastMsgToClients(), C4GUI::MessageDialog::btnAbort, C4GUI::MessageDialog::btnRetryAbort, Clients, StdStrBuf::Copy(), C4LeagueClient::End(), C4RoundResults::EvaluateLeague(), C4HTTPClient::Execute(), fHost, fLeagueEndSent, FormatString(), Game, StdStrBuf::getData(), C4LeagueClient::GetEndReply(), C4HTTPClient::GetError(), StdStrBuf::getLength(), C4HTTPClient::getServerName(), C4GUI::Ico_Error, C4Network2Reference::InitLocal(), C4HTTPClient::isBusy(), C4Application::isEditor, C4GameParameters::isLeague(), C4HTTPClient::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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LeagueGameEvaluate()

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

Definition at line 2009 of file C4Network2.cpp.

2010 {
2011  // already off?
2012  if (!pLeagueClient) return;
2013  // already evaluated?
2014  if (fLeagueEndSent) return;
2015  // end
2016  LeagueEnd(szRecordName, pRecordSHA);
2017 }

References fLeagueEndSent, LeagueEnd(), and pLeagueClient.

Referenced by C4Game::Evaluate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LeagueNotifyDisconnect()

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

Definition at line 2596 of file C4Network2.cpp.

2597 {
2598  // league active?
2599  if (!pLeagueClient || !Game.Parameters.isLeague()) return;
2600  // only in running game
2601  if (!Game.IsRunning || Game.GameOver) return;
2602  // clients send notifications for their own players; host sends for the affected client players
2603  if (!isHost()) { if (!Clients.GetLocal()) return; iClientID = Clients.GetLocal()->getID(); }
2604  // clients only need notifications if they have players in the game
2605  const C4ClientPlayerInfos *pInfos = Game.PlayerInfos.GetInfoByClientID(iClientID);
2606  if (!pInfos) return;
2607  int32_t i=0; C4PlayerInfo *pInfo;
2608  while ((pInfo = pInfos->GetPlayerInfo(i++))) if (pInfo->IsJoined() && !pInfo->IsRemoved()) break;
2609  if (!pInfo) return;
2610  // Make sure league client is avilable
2612  // report the disconnect!
2613  LogF(LoadResStr("IDS_LEAGUE_LEAGUEREPORTINGUNEXPECTED"), (int) eReason);
2614  pLeagueClient->ReportDisconnect(*pInfos, eReason);
2615  // wait for the reply
2617  // display it
2618  const char *szMsg;
2619  StdStrBuf sMessage;
2620  if (pLeagueClient->GetReportDisconnectReply(&sMessage))
2621  szMsg = LoadResStr("IDS_MSG_LEAGUEUNEXPECTEDDISCONNEC");
2622  else
2623  szMsg = LoadResStr("IDS_ERR_LEAGUEERRORREPORTINGUNEXP");
2624  LogF(szMsg, sMessage.getData());
2625 }
C4PlayerInfo * GetPlayerInfo(int32_t iIndex) const
C4PlayerInfoList & PlayerInfos
Definition: C4Game.h:71
bool GameOver
Definition: C4Game.h:114
bool GetReportDisconnectReply(StdStrBuf *pMessage)
Definition: C4League.cpp:500
bool ReportDisconnect(const C4ClientPlayerInfos &rSendPlayerFBIDs, C4LeagueDisconnectReason eReason)
Definition: C4League.cpp:485
bool IsRemoved() const
Definition: C4PlayerInfo.h:164
bool IsJoined() const
Definition: C4PlayerInfo.h:166
C4ClientPlayerInfos * GetInfoByClientID(int32_t iClientID) const
Definition: C4PlayerInfo.h:361

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LeaguePlrAuth()

bool C4Network2::LeaguePlrAuth ( C4PlayerInfo pInfo)

Definition at line 2427 of file C4Network2.cpp.

2428 {
2429 
2430  // Not possible?
2431  if (!pLeagueClient)
2432  return false;
2433 
2434  // Make sure league client is avilable
2436 
2437  // Official league?
2438  bool fOfficialLeague = SEqual(pLeagueClient->getServerName(), "league.openclonk.org");
2439 
2440  StdStrBuf Account, Password;
2441  bool fRememberLogin = false;
2442 
2443  // Default password from login token if present
2444  if (Config.Network.GetLeagueLoginData(pLeagueClient->getServerName(), pInfo->GetName(), &Account, &Password))
2445  {
2446  fRememberLogin = (Password.getLength()>0);
2447  }
2448  else
2449  {
2450  Account.Copy(pInfo->GetName());
2451  }
2452 
2453  for (;;)
2454  {
2455  // ask for account name and password
2456  if (!C4LeagueSignupDialog::ShowModal(pInfo->GetName(), Account.getData(), pLeagueClient->getServerName(), &Account, &Password, !fOfficialLeague, false, &fRememberLogin))
2457  return false;
2458 
2459  // safety (modal dlg may have deleted network)
2460  if (!pLeagueClient) return false;
2461 
2462  // Send authentication request
2463  if (!pLeagueClient->Auth(*pInfo, Account.getData(), Password.getData(), nullptr, nullptr, fRememberLogin))
2464  return false;
2465 
2466  // safety (modal dlg may have deleted network)
2467  if (!pLeagueClient) return false;
2468 
2469  // Wait for a response
2470  StdStrBuf Message = FormatString(LoadResStr("IDS_MSG_TRYLEAGUESIGNUP"), pInfo->GetName(), Account.getData(), pLeagueClient->getServerName());
2471  Log(Message.getData());
2472  // Set up a dialog
2473  C4GUI::MessageDialog *pDlg = nullptr;
2474  if (!Application.isEditor)
2475  {
2476  // create & show
2478  if (!pDlg || !pDlg->Show(::pGUI, true)) return false;
2479  }
2480  // Wait for response
2481  while (pLeagueClient->isBusy())
2482  {
2483  // Execute GUI
2484  if (!Application.ScheduleProcs() ||
2485  (pDlg && pDlg->IsAborted()))
2486  {
2487  // Clear up
2488  if (pDlg) delete pDlg;
2489  return false;
2490  }
2491  // Check if league server has responded
2492  if (!pLeagueClient->Execute(0))
2493  break;
2494  }
2495  // Close dialog
2496  if (pDlg)
2497  {
2498  pDlg->Close(true);
2499  delete pDlg;
2500  }
2501 
2502  // Success?
2503  StdStrBuf AUID, AccountMaster, LoginToken; bool fUnregistered = false;
2504  if (pLeagueClient->GetAuthReply(&Message, &AUID, &AccountMaster, &fUnregistered, &LoginToken))
2505  {
2506 
2507  // Set AUID
2508  pInfo->SetAuthID(AUID.getData());
2509 
2510  // Remember login data; set or clear login token
2511  Config.Network.SetLeagueLoginData(pLeagueClient->getServerName(), pInfo->GetName(), Account.getData(), fRememberLogin ? LoginToken.getData() : "");
2512 
2513  // Show welcome message, if any
2514  bool fSuccess;
2515  if (Message.getLength())
2516  fSuccess = ::pGUI->ShowMessageModal(
2517  Message.getData(), LoadResStr("IDS_DLG_LEAGUESIGNUPCONFIRM"),
2519  else if (AccountMaster.getLength())
2520  fSuccess = ::pGUI->ShowMessageModal(
2521  FormatString(LoadResStr("IDS_MSG_LEAGUEPLAYERSIGNUPAS"), pInfo->GetName(), AccountMaster.getData(), pLeagueClient->getServerName()).getData(), LoadResStr("IDS_DLG_LEAGUESIGNUPCONFIRM"),
2523  else
2524  fSuccess = ::pGUI->ShowMessageModal(
2525  FormatString(LoadResStr("IDS_MSG_LEAGUEPLAYERSIGNUP"), pInfo->GetName(), pLeagueClient->getServerName()).getData(), LoadResStr("IDS_DLG_LEAGUESIGNUPCONFIRM"),
2527 
2528  // Approved?
2529  if (fSuccess)
2530  // Done
2531  return true;
2532  else
2533  // Sign-up was cancelled by user
2534  ::pGUI->ShowMessageModal(FormatString(LoadResStr("IDS_MSG_LEAGUESIGNUPCANCELLED"), pInfo->GetName()).getData(), LoadResStr("IDS_DLG_LEAGUESIGNUP"), C4GUI::MessageDialog::btnOK, C4GUI::Ico_Notify);
2535 
2536  }
2537  else
2538  {
2539 
2540  // Authentification error
2541  LogF(LoadResStr("IDS_MSG_LEAGUESIGNUPERROR"), Message.getData());
2542  ::pGUI->ShowMessageModal(FormatString(LoadResStr("IDS_MSG_LEAGUESERVERMSG"), Message.getData()).getData(), LoadResStr("IDS_DLG_LEAGUESIGNUPFAILED"), C4GUI::MessageDialog::btnOK, C4GUI::Ico_Error);
2543  // after a league server error message, always fall-through to try again
2544  }
2545 
2546  // Try given account name as default next time
2547  if (AccountMaster.getLength())
2548  Account.Take(std::move(AccountMaster));
2549 
2550  // safety (modal dlg may have deleted network)
2551  if (!pLeagueClient) return false;
2552  }
2553 
2554 }
bool GetLeagueLoginData(const char *server_name, const char *player_name, StdStrBuf *account, StdStrBuf *login_token) const
Definition: C4Config.cpp:712
void SetLeagueLoginData(const char *server_name, const char *player_name, const char *account, const char *login_token)
Definition: C4Config.cpp:702
bool GetAuthReply(StdStrBuf *pMessage, StdStrBuf *pAUID, StdStrBuf *pAccount, bool *pRegister, StdStrBuf *pLoginToken)
Definition: C4League.cpp:425
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:405
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:661
const char * GetName() const
Definition: C4PlayerInfo.h:157
void SetAuthID(const char *sznAuthID)
Definition: C4PlayerInfo.h:133
@ Ico_Notify
Definition: C4Gui.h:642
@ Ico_Ex_League
Definition: C4Gui.h:706

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

Referenced by C4Network2Players::JoinLocalPlayer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LeaguePlrAuthCheck()

bool C4Network2::LeaguePlrAuthCheck ( C4PlayerInfo pInfo)

Definition at line 2556 of file C4Network2.cpp.

2557 {
2558 
2559  // Not possible?
2560  if (!pLeagueClient)
2561  return false;
2562 
2563  // Make sure league client is available
2565 
2566  // Ask league server to check the code
2567  if (!pLeagueClient->AuthCheck(*pInfo))
2568  return false;
2569 
2570  // Log
2571  StdStrBuf Message = FormatString(LoadResStr("IDS_MSG_LEAGUEJOINING"), pInfo->GetName());
2572  Log(Message.getData());
2573 
2574  // Wait for response
2575  while (pLeagueClient->isBusy())
2576  if (!pLeagueClient->Execute(100))
2577  break;
2578 
2579  // Check response validity
2580  if (!pLeagueClient->isSuccess())
2581  {
2583  return false;
2584  }
2585 
2586  // Check if league server approves. pInfo will have league info if this call is successful.
2587  if (!pLeagueClient->GetAuthCheckReply(&Message, Game.Parameters.League.getData(), pInfo))
2588  {
2589  LeagueShowError(FormatString(LoadResStr("IDS_MSG_LEAGUEJOINREFUSED"), pInfo->GetName(), Message.getData()).getData());
2590  return false;
2591  }
2592 
2593  return true;
2594 }
bool GetAuthCheckReply(StdStrBuf *pMessage, const char *szLeague, class C4PlayerInfo *pPlrInfo)
Definition: C4League.cpp:471
bool AuthCheck(const C4PlayerInfo &PlrInfo)
Definition: C4League.cpp:455
void LeagueShowError(const char *szMsg)

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

Referenced by C4Network2Players::HandlePlayerInfoUpdRequest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LeagueShowError()

void C4Network2::LeagueShowError ( const char *  szMsg)

Definition at line 2648 of file C4Network2.cpp.

2649 {
2650  if (!Application.isEditor)
2651  {
2652  ::pGUI->ShowErrorMessage(szMsg);
2653  }
2654  else
2655  {
2656  LogF(LoadResStr("IDS_LGA_SERVERFAILURE"), szMsg);
2657  }
2658 }
bool ShowErrorMessage(const char *szMessage)

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

Referenced by LeaguePlrAuthCheck().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LeagueSignupDisable()

void C4Network2::LeagueSignupDisable ( )

Definition at line 2019 of file C4Network2.cpp.

2020 {
2021  // already off?
2022  if (!pLeagueClient) return;
2023  // no post-disable if league is active
2024  if (pLeagueClient && Game.Parameters.isLeague()) return;
2025  // signup end
2026  LeagueEnd(); DeinitLeague();
2027 }

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

Referenced by C4GameOptionButtons::OnBtnInternet().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LeagueSignupEnable()

bool C4Network2::LeagueSignupEnable ( )

Definition at line 2029 of file C4Network2.cpp.

2030 {
2031  // already running?
2032  if (pLeagueClient) return true;
2033  // Start it!
2034  if (InitLeague(nullptr) && LeagueStart(nullptr)) return true;
2035  // Failure :'(
2036  DeinitLeague();
2037  return false;
2038 }

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

Referenced by C4GameOptionButtons::OnBtnInternet().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LeagueStart()

bool C4Network2::LeagueStart ( bool *  pCancel)
protected

Definition at line 2128 of file C4Network2.cpp.

2129 {
2130  // Not needed?
2131  if (!pLeagueClient || !fHost)
2132  return true;
2133 
2134  // Default
2135  if (pCancel) *pCancel = true;
2136 
2137  // Do update
2138  C4Network2Reference Ref;
2139  Ref.InitLocal();
2140  if (!pLeagueClient->Start(Ref))
2141  {
2142  // Log message
2143  StdStrBuf Message = FormatString(LoadResStr("IDS_NET_ERR_LEAGUE_STARTGAME"), pLeagueClient->GetError());
2144  LogFatal(Message.getData());
2145  // Show message
2146  if (!Application.isEditor)
2147  {
2148  // Show option to cancel, if possible
2149  bool fResult = ::pGUI->ShowMessageModal(
2150  Message.getData(),
2151  LoadResStr("IDS_NET_ERR_LEAGUE"),
2154  if (pCancel)
2155  *pCancel = !fResult;
2156  }
2157  // Failed
2158  return false;
2159  }
2160 
2161  InitPuncher();
2162 
2163  // Let's wait for response
2164  StdStrBuf Message = FormatString(LoadResStr("IDS_NET_LEAGUE_REGGAME"), pLeagueClient->getServerName());
2165  Log(Message.getData());
2166  // Set up a dialog
2167  C4GUI::MessageDialog *pDlg = nullptr;
2168  if (!Application.isEditor)
2169  {
2170  // create & show
2171  pDlg = new C4GUI::MessageDialog(Message.getData(), LoadResStr("IDS_NET_LEAGUE_STARTGAME"),
2173  if (!pDlg || !pDlg->Show(::pGUI, true)) return false;
2174  }
2175  // Wait for response
2176  while (pLeagueClient->isBusy())
2177  {
2178  // Execute GUI
2179  if (!Application.ScheduleProcs() ||
2180  (pDlg && pDlg->IsAborted()))
2181  {
2182  // Clear up
2183  if (pDlg) delete pDlg;
2184  return false;
2185  }
2186  // Check if league server has responded
2187  if (!pLeagueClient->Execute(100))
2188  break;
2189  }
2190  // Close dialog
2191  if (pDlg)
2192  {
2193  pDlg->Close(true);
2194  delete pDlg;
2195  }
2196  // Error?
2197  StdStrBuf LeagueServerMessage, League, StreamingAddr;
2198  int32_t Seed = Game.RandomSeed, MaxPlayersLeague = 0;
2199  if (!pLeagueClient->isSuccess() ||
2200  !pLeagueClient->GetStartReply(&LeagueServerMessage, &League, &StreamingAddr, &Seed, &MaxPlayersLeague))
2201  {
2202  const char *pError = pLeagueClient->GetError() ? pLeagueClient->GetError() :
2203  LeagueServerMessage.getLength() ? LeagueServerMessage.getData() :
2204  LoadResStr("IDS_NET_ERR_LEAGUE_EMPTYREPLY");
2205  StdStrBuf Message = FormatString(LoadResStr("IDS_NET_ERR_LEAGUE_REGGAME"), pError);
2206  // Log message
2207  Log(Message.getData());
2208  // Show message
2209  if (!Application.isEditor)
2210  {
2211  // Show option to cancel, if possible
2212  bool fResult = ::pGUI->ShowMessageModal(
2213  Message.getData(),
2214  LoadResStr("IDS_NET_ERR_LEAGUE"),
2217  if (pCancel)
2218  *pCancel = !fResult;
2219  }
2220  // Failed
2221  return false;
2222  }
2223 
2224  // Show message
2225  if (LeagueServerMessage.getLength())
2226  {
2227  StdStrBuf Message = FormatString(LoadResStr("IDS_MSG_LEAGUEGAMESIGNUP"), pLeagueClient->getServerName(), LeagueServerMessage.getData());
2228  // Log message
2229  Log(Message.getData());
2230  // Show message
2231  if (!Application.isEditor)
2232  {
2233  // Show option to cancel, if possible
2234  bool fResult = ::pGUI->ShowMessageModal(
2235  Message.getData(),
2236  LoadResStr("IDS_NET_ERR_LEAGUE"),
2239  if (pCancel)
2240  *pCancel = !fResult;
2241  if (!fResult)
2242  {
2243  LeagueEnd(); DeinitLeague();
2244  return false;
2245  }
2246  }
2247  }
2248 
2249  // Set game parameters for league game
2250  Game.Parameters.League = League;
2251  Game.RandomSeed = Seed;
2252  if (MaxPlayersLeague)
2253  Game.Parameters.MaxPlayers = MaxPlayersLeague;
2254  if (!League.getLength())
2255  {
2258  }
2259  else
2260  {
2261  Game.Parameters.StreamAddress = StreamingAddr;
2262  }
2263 
2264  // All ok
2265  fLeagueEndSent = false;
2266  return true;
2267 }
int32_t RandomSeed
Definition: C4Game.h:135
StdCopyStrBuf StreamAddress
bool Start(const C4Network2Reference &Ref)
Definition: C4League.cpp:298
bool GetStartReply(StdStrBuf *pMessage, StdStrBuf *pLeague, StdStrBuf *pStreamingAddr, int32_t *pSeed, int32_t *pMaxPlayers)
Definition: C4League.cpp:312
void InitPuncher()

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

Referenced by InitHost(), and LeagueSignupEnable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LeagueSurrender()

void C4Network2::LeagueSurrender ( )

Definition at line 2641 of file C4Network2.cpp.

2642 {
2643  // there's currently no functionality to surrender in the league
2644  // just stop responding so other clients will notify the disconnect
2645  DeinitLeague();
2646 }

References DeinitLeague().

Here is the call graph for this function:

◆ LeagueUpdate()

bool C4Network2::LeagueUpdate ( )
protected

Definition at line 2269 of file C4Network2.cpp.

2270 {
2271  // Not needed?
2272  if (!pLeagueClient || !fHost)
2273  return true;
2274 
2275  // League client currently busy?
2276  if (pLeagueClient->isBusy())
2277  return true;
2278 
2279  // Create reference
2280  C4Network2Reference Ref;
2281  Ref.InitLocal();
2282 
2283  // Do update
2284  if (!pLeagueClient->Update(Ref))
2285  {
2286  // Log
2287  LogF(LoadResStr("IDS_NET_ERR_LEAGUE_UPDATEGAME"), pLeagueClient->GetError());
2288  return false;
2289  }
2290 
2291  // Timing
2292  iLastLeagueUpdate = time(nullptr);
2294 
2295  return true;
2296 }
int32_t MasterReferencePeriod
Definition: C4Config.h:150
bool Update(const C4Network2Reference &Ref)
Definition: C4League.cpp:345

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

Referenced by Execute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LeagueUpdateProcessReply()

bool C4Network2::LeagueUpdateProcessReply ( )
protected

Definition at line 2298 of file C4Network2.cpp.

2299 {
2300  // safety: A reply must be present
2301  assert(pLeagueClient);
2302  assert(fHost);
2303  assert(!pLeagueClient->isBusy());
2305  // check reply success
2306  C4ClientPlayerInfos PlayerLeagueInfos;
2307  StdStrBuf LeagueServerMessage;
2308  bool fSucc = pLeagueClient->isSuccess() && pLeagueClient->GetUpdateReply(&LeagueServerMessage, &PlayerLeagueInfos);
2310  if (!fSucc)
2311  {
2312  const char *pError = pLeagueClient->GetError() ? pLeagueClient->GetError() :
2313  LeagueServerMessage.getLength() ? LeagueServerMessage.getData() :
2314  LoadResStr("IDS_NET_ERR_LEAGUE_EMPTYREPLY");
2315  StdStrBuf Message = FormatString(LoadResStr("IDS_NET_ERR_LEAGUE_UPDATEGAME"), pError);
2316  // Show message - no dialog, because it's not really fatal and might happen in the running game
2317  Log(Message.getData());
2318  return false;
2319  }
2320  // evaluate reply: Transfer data to players
2321  // Take round results
2322  C4PlayerInfoList &TargetList = Game.PlayerInfos;
2323  C4ClientPlayerInfos *pInfos; C4PlayerInfo *pInfo, *pResultInfo;
2324  for (int iClient = 0; (pInfos = TargetList.GetIndexedInfo(iClient)); iClient++)
2325  for (int iInfo = 0; (pInfo = pInfos->GetPlayerInfo(iInfo)); iInfo++)
2326  if ((pResultInfo = PlayerLeagueInfos.GetPlayerInfoByID(pInfo->GetID())))
2327  {
2328  int32_t iLeagueProjectedGain = pResultInfo->GetLeagueProjectedGain();
2329  if (iLeagueProjectedGain != pInfo->GetLeagueProjectedGain())
2330  {
2331  pInfo->SetLeagueProjectedGain(iLeagueProjectedGain);
2332  pInfos->SetUpdated();
2333  }
2334  }
2335  // transfer info update to other clients
2337  // if lobby is open, notify lobby of updated players
2338  if (pLobby) pLobby->OnPlayersChange();
2339  // OMFG SUCCESS!
2340  return true;
2341 }
C4PlayerInfo * GetPlayerInfoByID(int32_t id) const
void ResetCurrentAction()
Definition: C4League.h:217
bool GetUpdateReply(StdStrBuf *pMessage, C4ClientPlayerInfos *pPlayerLeagueInfos)
Definition: C4League.cpp:360
int32_t GetID() const
Definition: C4PlayerInfo.h:194
void SetLeagueProjectedGain(int32_t iProjectedGain)
Definition: C4PlayerInfo.h:143
int32_t GetLeagueProjectedGain() const
Definition: C4PlayerInfo.h:191
C4ClientPlayerInfos * GetIndexedInfo(int32_t iIndex) const
Definition: C4PlayerInfo.h:358

References C4LA_Update, fHost, FormatString(), Game, C4LeagueClient::getCurrentAction(), StdStrBuf::getData(), C4HTTPClient::GetError(), C4PlayerInfo::GetID(), C4PlayerInfoList::GetIndexedInfo(), C4PlayerInfo::GetLeagueProjectedGain(), StdStrBuf::getLength(), C4ClientPlayerInfos::GetPlayerInfo(), C4ClientPlayerInfos::GetPlayerInfoByID(), C4LeagueClient::GetUpdateReply(), C4HTTPClient::isBusy(), C4HTTPClient::isSuccess(), LoadResStr(), Log(), C4GameLobby::MainDlg::OnPlayersChange(), C4Game::PlayerInfos, Players, pLeagueClient, pLobby, C4LeagueClient::ResetCurrentAction(), C4Network2Players::SendUpdatedPlayers(), C4PlayerInfo::SetLeagueProjectedGain(), and C4ClientPlayerInfos::SetUpdated().

Referenced by Execute(), and LeagueWaitNotBusy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LeagueWaitNotBusy()

void C4Network2::LeagueWaitNotBusy ( )

Definition at line 2627 of file C4Network2.cpp.

2628 {
2629  // league client busy?
2630  if (!pLeagueClient || !pLeagueClient->isBusy()) return;
2631  // wait for it
2632  Log(LoadResStr("IDS_LEAGUE_WAITINGFORLASTLEAGUESERVE"));
2633  while (pLeagueClient->isBusy())
2634  if (!pLeagueClient->Execute(100))
2635  break;
2636  // if last request was an update request, process it
2639 }

References C4LA_Update, C4HTTPClient::Execute(), C4LeagueClient::getCurrentAction(), C4HTTPClient::isBusy(), LeagueUpdateProcessReply(), LoadResStr(), Log(), and pLeagueClient.

Referenced by LeagueEnd(), LeagueNotifyDisconnect(), LeaguePlrAuth(), and LeaguePlrAuthCheck().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnClientConnect()

void C4Network2::OnClientConnect ( C4Network2Client pClient,
C4Network2IOConnection pConn 
)
protected

Definition at line 1589 of file C4Network2.cpp.

1590 {
1591  // host: new client?
1592  if (isHost())
1593  {
1594  // dynamic available?
1595  if (!pClient->hasJoinData())
1596  SendJoinData(pClient);
1597 
1598  // notice lobby (doesn't do anything atm?)
1599  C4GameLobby::MainDlg *pDlg = GetLobby();
1600  if (isLobbyActive()) pDlg->OnClientConnect(pClient->getClient(), pConn);
1601 
1602  }
1603 
1604  // discover resources
1605  ResList.OnClientConnect(pConn);
1606 
1607 }
void OnClientConnect(C4Client *pClient, C4Network2IOConnection *pConn)
C4Client * getClient() const
class C4GameLobby::MainDlg * GetLobby() const
Definition: C4Network2.h:216
void SendJoinData(C4Network2Client *pClient)
void OnClientConnect(C4Network2IOConnection *pConn)

References C4Network2Client::getClient(), GetLobby(), C4Network2Client::hasJoinData(), isHost(), isLobbyActive(), C4GameLobby::MainDlg::OnClientConnect(), C4Network2ResList::OnClientConnect(), ResList, and SendJoinData().

Referenced by OnConnect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnClientDisconnect()

void C4Network2::OnClientDisconnect ( C4Network2Client pClient)
protected

Definition at line 1609 of file C4Network2.cpp.

1610 {
1611  // league: Notify regular client disconnect within the game
1612  if (pLeagueClient && (isHost() || pClient->isHost())) LeagueNotifyDisconnect(pClient->getID(), C4LDR_ConnectionFailed);
1613  // host? Remove this client from the game.
1614  if (isHost())
1615  {
1616  // log
1617  LogSilentF(LoadResStr("IDS_NET_CLIENTDISCONNECTED"), pClient->getName()); // silent, because a duplicate message with disconnect reason will follow
1618  // remove the client
1619  Game.Clients.CtrlRemove(pClient->getClient(), LoadResStr("IDS_MSG_DISCONNECTED"));
1620  // check status ack (disconnected client might be the last that was waited for)
1621  CheckStatusAck();
1622  // unreached pause/go? retry setting the state with current control tick
1623  // (client might be the only one claiming to have the given control)
1624  if (!fStatusReached)
1625  if (Status.getState() == GS_Go || Status.getState() == GS_Pause)
1627 #ifdef USE_CONSOLE
1628  // Dedicated server: stop hosting if there is only one client left we're hosting for.
1629  // TODO: Find a better place to do this.
1630  if (Game.IsRunning && Clients.Count() <= 3) Application.Quit(); // Off-by-1 error
1631 #endif // USE_CONSOLE
1632  }
1633  // host disconnected? Clear up
1634  if (!isHost() && pClient->isHost())
1635  {
1636  StdStrBuf sMsg; sMsg.Format(LoadResStr("IDS_NET_HOSTDISCONNECTED"), pClient->getName());
1637  Log(sMsg.getData());
1638  // host connection lost: clear up everything
1640  Clear();
1641  }
1642 }
@ C4LDR_ConnectionFailed
Definition: C4Constants.h:145
void Quit() override
void CtrlRemove(const C4Client *pClient, const char *szReason)
Definition: C4Client.cpp:333
void LeagueNotifyDisconnect(int32_t iClientID, enum C4LeagueDisconnectReason eReason)
void EvaluateNetwork(NetResult eResult, const char *szResultsString)

References Application, C4LDR_ConnectionFailed, ChangeGameStatus(), CheckStatusAck(), Clear(), C4Game::Clients, Clients, Control, C4GameControl::ControlTick, C4Network2ClientList::Count(), C4ClientList::CtrlRemove(), C4RoundResults::EvaluateNetwork(), StdStrBuf::Format(), fStatusReached, Game, C4Network2Client::getClient(), StdStrBuf::getData(), C4Network2Client::getID(), C4Network2Client::getName(), C4Network2Status::getState(), GS_Go, GS_Pause, isHost(), C4Network2Client::isHost(), C4Game::IsRunning, LeagueNotifyDisconnect(), LoadResStr(), Log(), LogSilentF(), C4RoundResults::NR_NetError, pLeagueClient, C4Application::Quit(), C4Game::RoundResults, and Status.

Referenced by OnConnectFail(), and OnDisconnect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnConn()

void C4Network2::OnConn ( C4Network2IOConnection pConn)

Definition at line 828 of file C4Network2.cpp.

829 {
830  // Nothing to do atm... New pending connections are managed mainly by C4Network2IO
831  // until they are accepted, see PID_Conn/PID_ConnRe handlers in HandlePacket.
832 
833  // Note this won't get called anymore because of this (see C4Network2IO::OnConn)
834 }

Referenced by C4Network2IO::OnThreadEvent().

Here is the caller graph for this function:

◆ OnConnect()

void C4Network2::OnConnect ( C4Network2Client pClient,
C4Network2IOConnection pConn,
const char *  szMsg,
bool  fFirstConnection 
)
protected

Definition at line 1555 of file C4Network2.cpp.

1556 {
1557  // log
1558  LogSilentF("Network: %s %s connected (%s/%s) (%s)", pClient->isHost() ? "host" : "client",
1559  pClient->getName(), pConn->getPeerAddr().ToString().getData(),
1560  NetIO.getNetIOName(pConn->getNetClass()), szMsg ? szMsg : "");
1561 
1562  // first connection for this peer? call special handler
1563  if (fFirstConnection) OnClientConnect(pClient, pConn);
1564 }
void OnClientConnect(C4Network2Client *pClient, C4Network2IOConnection *pConn)

References StdStrBuf::getData(), C4Network2Client::getName(), C4Network2IOConnection::getNetClass(), C4Network2IO::getNetIOName(), C4Network2IOConnection::getPeerAddr(), C4Network2Client::isHost(), LogSilentF(), NetIO, OnClientConnect(), and C4NetIO::EndpointAddress::ToString().

Referenced by HandleConnRe().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnConnectFail()

void C4Network2::OnConnectFail ( C4Network2IOConnection pConn)
protected

Definition at line 1566 of file C4Network2.cpp.

1567 {
1568  LogSilentF("Network: %s connection to %s failed!", NetIO.getNetIOName(pConn->getNetClass()),
1569  pConn->getPeerAddr().ToString().getData());
1570 
1571  // maybe client connection failure
1572  // (happens if the connection is not fully accepted and the client disconnects.
1573  // See C4Network2::Join)
1574  C4Network2Client *pClient = Clients.GetClientByID(pConn->getClientID());
1575  if (pClient && !pClient->isConnected())
1576  OnClientDisconnect(pClient);
1577 }
void OnClientDisconnect(C4Network2Client *pClient)

References Clients, C4Network2ClientList::GetClientByID(), C4Network2IOConnection::getClientID(), StdStrBuf::getData(), C4Network2IOConnection::getNetClass(), C4Network2IO::getNetIOName(), C4Network2IOConnection::getPeerAddr(), C4Network2Client::isConnected(), LogSilentF(), NetIO, OnClientDisconnect(), and C4NetIO::EndpointAddress::ToString().

Referenced by OnDisconn().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnDisconn()

void C4Network2::OnDisconn ( C4Network2IOConnection pConn)

Definition at line 836 of file C4Network2.cpp.

837 {
838  // could not establish host connection?
839  if (Status.getState() == GS_Init && !isHost())
840  {
841  if (!NetIO.getConnectionCount())
842  Clear();
843  return;
844  }
845 
846  // connection failed?
847  if (pConn->isFailed())
848  {
849  // call handler
850  OnConnectFail(pConn);
851  return;
852  }
853 
854  // search client
855  C4Network2Client *pClient = Clients.GetClient(pConn);
856  // not found? Search by ID (not associated yet, half-accepted connection)
857  if (!pClient) pClient = Clients.GetClientByID(pConn->getClientID());
858  // not found? ignore
859  if (!pClient) return;
860  // remove connection
861  pClient->RemoveConn(pConn);
862 
863  // create post-mortem if needed
864  C4PacketPostMortem PostMortem;
865  if (pConn->CreatePostMortem(&PostMortem))
866  {
867  LogSilentF("Network: Sending %d packets for recovery (%d-%d)", PostMortem.getPacketCount(), pConn->getOutPacketCounter() - PostMortem.getPacketCount(), pConn->getOutPacketCounter() - 1);
868  // This might fail because of this disconnect
869  // (If it's the only host connection. We're toast then anyway.)
871  assert(isHost() || !Clients.GetHost()->isConnected());
872  }
873 
874  // call handler
875  OnDisconnect(pClient, pConn);
876 
877 }
@ PID_PostMortem
Definition: C4PacketBase.h:96
void RemoveConn(C4Network2IOConnection *pConn)
bool SendMsgToClient(int32_t iClient, C4NetIOPacket &&rPkt)
void OnDisconnect(C4Network2Client *pClient, C4Network2IOConnection *pConn)
void OnConnectFail(C4Network2IOConnection *pConn)
bool CreatePostMortem(class C4PacketPostMortem *pPkt)
uint32_t getOutPacketCounter() const
Definition: C4Network2IO.h:284
int getConnectionCount()
Definition: C4Network2IO.h:418
uint32_t getPacketCount() const
Definition: C4Network2IO.h:436

References Clear(), Clients, C4Network2IOConnection::CreatePostMortem(), C4Network2ClientList::GetClient(), C4Network2ClientList::GetClientByID(), C4Network2IOConnection::getClientID(), C4Network2IO::getConnectionCount(), C4Network2ClientList::GetHost(), C4Network2IOConnection::getOutPacketCounter(), C4PacketPostMortem::getPacketCount(), C4Network2Status::getState(), GS_Init, C4Network2Client::isConnected(), C4Network2IOConnection::isFailed(), isHost(), LogSilentF(), MkC4NetIOPacket(), NetIO, OnConnectFail(), OnDisconnect(), PID_PostMortem, C4Network2Client::RemoveConn(), C4Network2ClientList::SendMsgToClient(), and Status.

Referenced by C4Network2IO::OnThreadEvent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnDisconnect()

void C4Network2::OnDisconnect ( C4Network2Client pClient,
C4Network2IOConnection pConn 
)
protected

Definition at line 1579 of file C4Network2.cpp.

1580 {
1581  LogSilentF("Network: %s connection to %s (%s) lost!", NetIO.getNetIOName(pConn->getNetClass()),
1582  pClient->getName(), pConn->getPeerAddr().ToString().getData());
1583 
1584  // connection lost?
1585  if (!pClient->isConnected())
1586  OnClientDisconnect(pClient);
1587 }

References StdStrBuf::getData(), C4Network2Client::getName(), C4Network2IOConnection::getNetClass(), C4Network2IO::getNetIOName(), C4Network2IOConnection::getPeerAddr(), C4Network2Client::isConnected(), LogSilentF(), NetIO, OnClientDisconnect(), and C4NetIO::EndpointAddress::ToString().

Referenced by OnDisconn().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnGameSynchronized()

void C4Network2::OnGameSynchronized ( )

Definition at line 1062 of file C4Network2.cpp.

1063 {
1064  // savegame needed?
1065  if (fDynamicNeeded)
1066  {
1067  // create dynamic
1068  bool fSuccess = CreateDynamic(false);
1069  // check for clients that still need join-data
1070  C4Network2Client *pClient = nullptr;
1071  while ((pClient = Clients.GetNextClient(pClient)))
1072  if (!pClient->hasJoinData())
1073  {
1074  if (fSuccess)
1075  // now we can provide join data: send it
1076  SendJoinData(pClient);
1077  else
1078  // join data could not be created: emergency kick
1079  Game.Clients.CtrlRemove(pClient->getClient(), LoadResStr("IDS_ERR_ERRORWHILECREATINGJOINDAT"));
1080  }
1081  }
1082 }

References C4Game::Clients, Clients, CreateDynamic(), C4ClientList::CtrlRemove(), fDynamicNeeded, Game, C4Network2Client::getClient(), C4Network2ClientList::GetNextClient(), C4Network2Client::hasJoinData(), LoadResStr(), and SendJoinData().

Referenced by C4Game::Synchronize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnPuncherConnect()

void C4Network2::OnPuncherConnect ( C4NetIO::addr_t  addr)

Definition at line 1017 of file C4Network2.cpp.

1018 {
1019  // NAT punching is only relevant for IPv4, so convert here to show a proper address.
1020  auto maybe_v4 = addr.AsIPv4();
1021  Application.InteractiveThread.ThreadLogS("Adding address from puncher: %s", maybe_v4.ToString().getData());
1022  // Add for local client
1023  C4Network2Client *pLocal = Clients.GetLocal();
1024  if (pLocal)
1025  {
1026  pLocal->AddAddrFromPuncher(maybe_v4);
1027  // Do not ::Network.InvalidateReference(); yet, we're expecting an ID from the netpuncher
1028  }
1029  auto family = maybe_v4.GetFamily();
1030  if (isHost())
1031  {
1032  // Host connection: request ID from netpuncher
1034  }
1035  else
1036  {
1037  // Client connection: request packet from host.
1038  if (Status.getState() == GS_Init && getNetpuncherGameID(family))
1039  NetIO.SendPuncherPacket(C4NetpuncherPacketSReq(getNetpuncherGameID(family)), family);
1040  }
1041 }
C4InteractiveThread InteractiveThread
Definition: C4Application.h:45
bool ThreadLogS(const char *szMessage,...) GNUC_FORMAT_ATTRIBUTE_O
void AddAddrFromPuncher(const C4NetIO::addr_t &addr)
void SendPuncherPacket(const C4NetpuncherPacket &, C4NetIO::HostAddress::AddressFamily family)
EndpointAddress AsIPv4() const
Definition: C4NetIO.cpp:341

References C4Network2Client::AddAddrFromPuncher(), Application, C4NetIO::EndpointAddress::AsIPv4(), Clients, C4Network2ClientList::GetLocal(), getNetpuncherGameID(), C4Network2Status::getState(), GS_Init, C4Application::InteractiveThread, isHost(), NetIO, C4Network2IO::SendPuncherPacket(), Status, and C4InteractiveThread::ThreadLogS().

Referenced by C4Network2IO::OnConn().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnSec1Timer()

void C4Network2::OnSec1Timer ( )
overridevirtual

Implements C4ApplicationSec1Timer.

Definition at line 644 of file C4Network2.cpp.

645 {
646  Execute();
647 }
void Execute()
Definition: C4Network2.cpp:649

References Execute().

Here is the call graph for this function:

◆ OnStatusAck()

void C4Network2::OnStatusAck ( )
protected

Definition at line 1914 of file C4Network2.cpp.

1915 {
1916  // log it
1917  LogSilentF("Network: status %s (tick %d) reached", Status.getStateName(), Status.getTargetCtrlTick());
1918  // pause?
1919  if (Status.getState() == GS_Pause)
1920  {
1921  // set halt-flag (show hold message)
1923  }
1924  // go?
1925  if (Status.getState() == GS_Go)
1926  {
1927  // set mode
1929  // notify player list of reached status - will add some input to the queue
1931  // start ctrl
1932  pControl->SetRunning(true);
1933  // reset halt-flag
1934  Game.HaltCount = 0;
1936  }
1937 }
C4GameControlNetworkMode
void SetCtrlMode(C4GameControlNetworkMode enMode)

References Console, Game, C4Network2Status::getCtrlMode(), C4Network2Status::getState(), C4Network2Status::getStateName(), C4Network2Status::getTargetCtrlTick(), GS_Go, GS_Pause, C4Game::HaltCount, LogSilentF(), C4Network2Players::OnStatusGoReached(), pControl, Players, C4GameControlNetwork::SetCtrlMode(), C4GameControlNetwork::SetRunning(), Status, and C4ConsoleGUI::UpdateHaltCtrls().

Referenced by CheckStatusAck(), and HandleStatusAck().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnStatusReached()

void C4Network2::OnStatusReached ( )
protected

Definition at line 1904 of file C4Network2.cpp.

1905 {
1906  // stop ctrl, wait for ack
1907  if (pControl->IsEnabled())
1908  {
1910  pControl->SetRunning(false);
1911  }
1912 }

References Console, Game, C4Game::HaltCount, C4GameControlNetwork::IsEnabled(), pControl, C4GameControlNetwork::SetRunning(), and C4ConsoleGUI::UpdateHaltCtrls().

Referenced by CheckStatusReached().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnVoteDialogClosed()

void C4Network2::OnVoteDialogClosed ( )

Definition at line 2804 of file C4Network2.cpp.

2805 {
2806  pVoteDialog = nullptr;
2807 }

References pVoteDialog.

◆ OpenSurrenderDialog()

void C4Network2::OpenSurrenderDialog ( C4ControlVoteType  eType,
int32_t  iData 
)

Definition at line 2792 of file C4Network2.cpp.

2793 {
2794  if (!pVoteDialog)
2795  {
2796  pVoteDialog = new C4VoteDialog(
2797  LoadResStr("IDS_VOTE_SURRENDERWARNING"), eType, iData, true);
2799  pVoteDialog->Show(::pGUI, true);
2800  }
2801 }
void SetDelOnClose(bool fToVal=true)
Definition: C4Gui.h:2191

References LoadResStr(), pGUI, pVoteDialog, C4GUI::Dialog::SetDelOnClose(), and C4GUI::Dialog::Show().

Referenced by EndVote(), and Vote().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenVoteDialog()

void C4Network2::OpenVoteDialog ( )

Definition at line 2759 of file C4Network2.cpp.

2760 {
2761  // Dialog already open?
2762  if (pVoteDialog) return;
2763  // No vote available?
2764  if (!Votes.firstPkt()) return;
2765  // Can't vote?
2767  if (!pPlayerInfos || !pPlayerInfos->GetPlayerCount() || !pPlayerInfos->GetJoinedPlayerCount())
2768  return;
2769  // Search a voting we have to vote on
2770  for (C4IDPacket *pPkt = Votes.firstPkt(); pPkt; pPkt = Votes.nextPkt(pPkt))
2771  {
2772  // Already voted on this matter?
2773  C4ControlVote *pVote = static_cast<C4ControlVote *>(pPkt->getPkt());
2774  if (!GetVote(::Control.ClientID(), pVote->getType(), pVote->getData()))
2775  {
2776  // Compose message
2777  C4Client *pSrcClient = Game.Clients.getClientByID(pVote->getByClient());
2778  StdStrBuf Msg; Msg.Format(LoadResStr("IDS_VOTE_WANTSTOALLOW"), pSrcClient ? pSrcClient->getName() : "???", pVote->getDesc().getData());
2779  Msg.AppendChar('|');
2780  Msg.Append(pVote->getDescWarning());
2781 
2782  // Open dialog
2783  pVoteDialog = new C4VoteDialog(Msg.getData(), pVote->getType(), pVote->getData(), false);
2785  pVoteDialog->Show(::pGUI, true);
2786 
2787  break;
2788  }
2789  }
2790 }
const char * getName() const
Definition: C4Client.h:107
int32_t GetPlayerCount() const
Definition: C4PlayerInfo.h:251
int32_t GetJoinedPlayerCount() const
StdStrBuf getDesc() const
Definition: C4Control.cpp:1675
StdStrBuf getDescWarning() const
Definition: C4Control.cpp:1704
int32_t ClientID() const
void AppendChar(char cChar)
Definition: StdBuf.h:588

References StdStrBuf::Append(), StdStrBuf::AppendChar(), C4GameControl::ClientID(), C4Game::Clients, Control, C4Control::firstPkt(), StdStrBuf::Format(), Game, C4ControlPacket::getByClient(), C4ClientList::getClientByID(), C4ControlVote::getData(), StdStrBuf::getData(), C4ControlVote::getDesc(), C4ControlVote::getDescWarning(), C4PlayerInfoList::GetInfoByClientID(), C4ClientPlayerInfos::GetJoinedPlayerCount(), C4ClientList::getLocalID(), C4Client::getName(), C4ClientPlayerInfos::GetPlayerCount(), C4ControlVote::getType(), GetVote(), LoadResStr(), C4Control::nextPkt(), pGUI, C4Game::PlayerInfos, pVoteDialog, C4GUI::Dialog::SetDelOnClose(), C4GUI::Dialog::Show(), and Votes.

Referenced by AddVote(), and EndVote().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Pause()

bool C4Network2::Pause ( )

Definition at line 514 of file C4Network2.cpp.

515 {
516  if (!isEnabled() || !isHost()) return false;
517  // change mode: pause
519 }

References ChangeGameStatus(), Control, C4GameControl::getNextControlTick(), GS_Pause, isEnabled(), and isHost().

Referenced by AddVote(), C4Game::Pause(), and Vote().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PauseGame()

bool C4Network2::PauseGame ( bool  fAutoContinue)
protected

◆ QueryClientPassword()

StdStrBuf C4Network2::QueryClientPassword ( )

Definition at line 785 of file C4Network2.cpp.

786 {
787  // ask client for a password; return nothing if user canceled
788  StdStrBuf sCaption; sCaption.Copy(LoadResStr("IDS_MSG_ENTERPASSWORD"));
789  C4GUI::InputDialog *pInputDlg = new C4GUI::InputDialog(LoadResStr("IDS_MSG_ENTERPASSWORD"), sCaption.getData(), C4GUI::Ico_Ex_Locked, nullptr, false);
790  pInputDlg->SetDelOnClose(false);
791  if (!::pGUI->ShowModalDlg(pInputDlg, false))
792  {
793  delete pInputDlg;
794  return StdStrBuf();
795  }
796  // copy to buffer
797  StdStrBuf Buf; Buf.Copy(pInputDlg->GetInputText());
798  delete pInputDlg;
799  return Buf;
800 }
const char * GetInputText()
Definition: C4Gui.h:2424
bool ShowModalDlg(Dialog *pDlg, bool fDestruct=true)
@ Ico_Ex_Locked
Definition: C4Gui.h:709

References StdStrBuf::Copy(), StdStrBuf::getData(), C4GUI::InputDialog::GetInputText(), C4GUI::Ico_Ex_Locked, LoadResStr(), pGUI, C4GUI::Dialog::SetDelOnClose(), and C4GUI::Screen::ShowModalDlg().

Here is the call graph for this function:

◆ RemoveDynamic()

void C4Network2::RemoveDynamic ( )
protected

Definition at line 1797 of file C4Network2.cpp.

1798 {
1800  if (pRes) pRes->Remove();
1801  ResDynamic.Clear();
1802  iDynamicTick = -1;
1803 }
int32_t getID() const
Definition: C4Network2Res.h:86
C4Network2Res::Ref getRefRes(int32_t iResID)

References C4Network2ResCore::Clear(), C4Network2ResCore::getID(), C4Network2ResList::getRefRes(), iDynamicTick, C4Network2Res::Remove(), ResDynamic, and ResList.

Referenced by CreateDynamic(), and Execute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RequestActivate()

void C4Network2::RequestActivate ( )

Definition at line 1939 of file C4Network2.cpp.

1940 {
1941  // neither observer nor activated?
1943  {
1945  return;
1946  }
1947  // host? just do it
1948  if (fHost)
1949  {
1950  // activate him
1953  CDT_Sync);
1954  return;
1955  }
1956  // ensure interval
1958  return;
1959  // status not reached yet? May be chasing, let's delay this.
1960  if (!fStatusReached)
1961  {
1962  fDelayedActivateReq = true;
1963  return;
1964  }
1965  // request
1967  // store time
1969 }
const int C4NetActivationReqInterval
Definition: C4Network2.h:40
bool isObserver() const
Definition: C4Client.h:111
C4Client * getLocal() const
Definition: C4Client.h:161
static C4TimeMilliseconds Now()

References C4ClientIDHost, C4NetActivationReqInterval, CDT_Sync, CID_ClientUpdate, C4Game::Clients, Clients, Control, CUT_Activate, C4GameControl::DoInput(), fDelayedActivateReq, fHost, C4Game::FrameCounter, fStatusReached, Game, C4ClientList::getLocal(), C4Client::isActivated(), C4Client::isObserver(), MkC4NetIOPacket(), C4TimeMilliseconds::NegativeInfinity, C4TimeMilliseconds::Now(), PID_ClientActReq, C4Network2ClientList::SendMsgToHost(), and tLastActivateRequest.

Referenced by CheckStatusReached(), Execute(), and C4Network2Players::JoinLocalPlayer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RetrieveRes()

C4Network2Res::Ref C4Network2::RetrieveRes ( const C4Network2ResCore Core,
int32_t  iTimeout,
const char *  szResName,
bool  fWaitForCore = false 
)

Definition at line 1678 of file C4Network2.cpp.

1679 {
1680  C4GUI::ProgressDialog *pDlg = nullptr;
1681  bool fLog = false;
1682  int32_t iProcess = -1;
1683  C4TimeMilliseconds tTimeout = C4TimeMilliseconds::Now() + iTimeoutLen;
1684  // wait for resource
1685  while (isEnabled())
1686  {
1687  // find resource
1688  C4Network2Res::Ref pRes = ResList.getRefRes(Core.getID());
1689  // res not found?
1690  if (!pRes)
1691  {
1692  if (Core.isNull())
1693  {
1694  // should wait for core?
1695  if (!fWaitForCore) return nullptr;
1696  }
1697  else
1698  {
1699  // start loading
1700  pRes = ResList.AddByCore(Core);
1701  }
1702  }
1703  // res found and loaded completely
1704  else if (!pRes->isLoading())
1705  {
1706  // log
1707  if (fLog) LogF(LoadResStr("IDS_NET_RECEIVED"), szResName, pRes->getCore().getFileName());
1708  // return
1709  if (pDlg) delete pDlg;
1710  return pRes;
1711  }
1712 
1713  // check: progress?
1714  if (pRes && pRes->getPresentPercent() != iProcess)
1715  {
1716  iProcess = pRes->getPresentPercent();
1717  tTimeout = C4TimeMilliseconds::Now() + iTimeoutLen;
1718  }
1719  else
1720  {
1721  // if not: check timeout
1722  if (C4TimeMilliseconds::Now() > tTimeout)
1723  {
1724  LogFatal(FormatString(LoadResStr("IDS_NET_ERR_RESTIMEOUT"), szResName).getData());
1725  if (pDlg) delete pDlg;
1726  return nullptr;
1727  }
1728  }
1729 
1730  // log
1731  if (!fLog)
1732  {
1733  LogF(LoadResStr("IDS_NET_WAITFORRES"), szResName);
1734  fLog = true;
1735  }
1736  // show progress dialog
1737  if (!pDlg && !Console.Active && ::pGUI)
1738  {
1739  // create
1740  pDlg = new C4GUI::ProgressDialog(FormatString(LoadResStr("IDS_NET_WAITFORRES"), szResName).getData(),
1741  LoadResStr("IDS_NET_CAPTION"), 100, 0, C4GUI::Ico_NetWait);
1742  // show dialog
1743  if (!pDlg->Show(::pGUI, true)) { delete pDlg; return nullptr; }
1744  }
1745 
1746  // wait
1747  if (pDlg)
1748  {
1749  // set progress bar
1750  pDlg->SetProgress(iProcess);
1751  // execute (will do message handling)
1752  if (!pDlg->Execute())
1753  { if (pDlg) delete pDlg; return nullptr; }
1754  // aborted?
1755  if (pDlg->IsAborted()) break;
1756  }
1757  else
1758  {
1760  { return nullptr; }
1761  }
1762 
1763  }
1764  // aborted
1765  delete pDlg;
1766  return nullptr;
1767 }
void SetProgress(int32_t iToProgress)
Definition: C4Gui.h:2379
const char * getFileName() const
Definition: C4Network2Res.h:94
int32_t getPresentPercent() const
bool isLoading() const

References C4Window::Active, C4Network2ResList::AddByCore(), Application, Console, C4GUI::Dialog::Execute(), FormatString(), C4Network2Res::getCore(), C4Network2ResCore::getFileName(), C4Network2ResCore::getID(), C4Network2Res::getPresentPercent(), C4Network2ResList::getRefRes(), C4GUI::Ico_NetWait, C4GUI::Dialog::IsAborted(), isEnabled(), C4Network2Res::isLoading(), C4Network2ResCore::isNull(), LoadResStr(), LogF(), LogFatal(), C4TimeMilliseconds::Now(), pGUI, ResList, StdScheduler::ScheduleProcs(), C4GUI::ProgressDialog::SetProgress(), and C4GUI::Dialog::Show().

Referenced by C4PlayerInfoList::RecreatePlayers(), C4GameResList::RetrieveFiles(), and RetrieveScenario().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RetrieveScenario()

bool C4Network2::RetrieveScenario ( char *  szScenario)

Definition at line 590 of file C4Network2.cpp.

591 {
592  // client only
593  if (isHost()) return false;
594 
595  // wait for scenario
597  C4NetResRetrieveTimeout, LoadResStr("IDS_NET_RES_SCENARIO"));
598  if (!pScenario)
599  return false;
600 
601  // wait for dynamic data
602  C4Network2Res::Ref pDynamic = RetrieveRes(ResDynamic, C4NetResRetrieveTimeout, LoadResStr("IDS_NET_RES_DYNAMIC"));
603  if (!pDynamic)
604  return false;
605 
606  // create unpacked copy of scenario
607  if (!ResList.FindTempResFileName(FormatString("Combined%d.ocs", Game.Clients.getLocalID()).getData(), szScenario) ||
608  !C4Group_CopyItem(pScenario->getFile(), szScenario) ||
609  !C4Group_UnpackDirectory(szScenario))
610  return false;
611 
612  // create unpacked copy of dynamic data
613  char szTempDynamic[_MAX_PATH_LEN];
614  if (!ResList.FindTempResFileName(pDynamic->getFile(), szTempDynamic) ||
615  !C4Group_CopyItem(pDynamic->getFile(), szTempDynamic) ||
616  !C4Group_UnpackDirectory(szTempDynamic))
617  return false;
618 
619  // unpack Material.ocg if materials need to be merged
620  StdStrBuf MaterialScenario, MaterialDynamic;
621  MaterialScenario.Format("%s" DirSep C4CFN_Material, szScenario);
622  MaterialDynamic.Format("%s" DirSep C4CFN_Material, szTempDynamic);
623  if (FileExists(MaterialScenario.getData()) && FileExists(MaterialDynamic.getData()))
624  if (!C4Group_UnpackDirectory(MaterialScenario.getData()) ||
625  !C4Group_UnpackDirectory(MaterialDynamic.getData()))
626  return false;
627 
628  // move all dynamic files to scenario
629  C4Group ScenGrp;
630  if (!ScenGrp.Open(szScenario) ||
631  !ScenGrp.Merge(szTempDynamic))
632  return false;
633  ScenGrp.Close();
634 
635  // remove dynamic temp file
636  EraseDirectory(szTempDynamic);
637 
638  // remove dynamic - isn't needed any more and will soon be out-of-date
639  pDynamic->Remove();
640 
641  return true;
642 }
#define C4CFN_Material
Definition: C4Components.h:25
bool C4Group_CopyItem(const char *source, const char *target, bool no_sorting, bool reset_attributes)
Definition: C4Group.cpp:115
bool C4Group_UnpackDirectory(const char *filename)
Definition: C4Group.cpp:401
const int C4NetResRetrieveTimeout
Definition: C4Network2.h:37
#define DirSep
bool EraseDirectory(const char *szDirName)
Definition: StdFile.cpp:785
bool FileExists(const char *szFileName)
const C4Network2ResCore * getResCore() const
bool Merge(const char *folders)
Definition: C4Group.cpp:1534
bool Close()
Definition: C4Group.cpp:971
bool Open(const char *group_name, bool do_create=false)
Definition: C4Group.cpp:660
C4Network2Res::Ref RetrieveRes(const C4Network2ResCore &Core, int32_t iTimeout, const char *szResName, bool fWaitForCore=false)
const char * getFile() const

References _MAX_PATH_LEN, C4CFN_Material, C4Group_CopyItem(), C4Group_UnpackDirectory(), C4NetResRetrieveTimeout, C4Game::Clients, C4Group::Close(), DirSep, EraseDirectory(), FileExists(), C4Network2ResList::FindTempResFileName(), StdStrBuf::Format(), FormatString(), Game, StdStrBuf::getData(), C4Network2Res::getFile(), C4ClientList::getLocalID(), C4GameRes::getResCore(), isHost(), LoadResStr(), C4Group::Merge(), C4Group::Open(), C4Game::Parameters, C4Network2Res::Remove(), ResDynamic, ResList, RetrieveRes(), and C4GameParameters::Scenario.

Referenced by C4Game::Init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SendJoinData()

void C4Network2::SendJoinData ( C4Network2Client pClient)
protected

Definition at line 1644 of file C4Network2.cpp.

1645 {
1646  if (pClient->hasJoinData()) return;
1647  // host only, scenario must be available
1648  assert(isHost());
1649  // dynamic available?
1651  {
1652  fDynamicNeeded = true;
1653  // add synchronization control (will callback, see C4Game::Synchronize)
1655  return;
1656  }
1657  // save his client ID
1658  C4PacketJoinData JoinData;
1659  JoinData.SetClientID(pClient->getID());
1660  // save status into packet
1661  JoinData.SetGameStatus(Status);
1662  // scenario parameter defs for lobby display (localized in host language)
1664  // parameters
1665  JoinData.Parameters = Game.Parameters;
1666  // core join data
1667  JoinData.SetStartCtrlTick(iDynamicTick);
1668  JoinData.SetDynamicCore(ResDynamic);
1669  // send
1670  pClient->SendMsg(MkC4NetIOPacket(PID_JoinData, JoinData));
1671  // send addresses
1672  Clients.SendAddresses(pClient->getMsgConn());
1673  // flag client (he will have to accept the network status sent next)
1674  pClient->SetStatus(NCS_Chasing);
1675  if (!iLastChaseTargetUpdate) iLastChaseTargetUpdate = time(nullptr);
1676 }
@ CID_Synchronize
Definition: C4PacketBase.h:152
C4Network2IOConnection * getMsgConn() const
C4ScenarioParameterDefs ScenarioParameterDefs
Definition: C4Network2.h:437
void SetStartCtrlTick(int32_t iTick)
Definition: C4Network2.h:451
C4GameParameters Parameters
Definition: C4Network2.h:440
void SetGameStatus(const C4Network2Status &Status)
Definition: C4Network2.h:449
void SetDynamicCore(const C4Network2ResCore &Core)
Definition: C4Network2.h:450
void SetClientID(int32_t inClientID)
Definition: C4Network2.h:448

References CDT_Sync, CID_Synchronize, Clients, Control, C4GameControl::ControlTick, C4GameControl::DoInput(), fDynamicNeeded, Game, C4Network2Client::getID(), C4Network2Client::getMsgConn(), C4Network2Client::hasJoinData(), iDynamicTick, iLastChaseTargetUpdate, isHost(), C4Network2ResCore::isNull(), MkC4NetIOPacket(), NCS_Chasing, C4Game::Parameters, C4PacketJoinData::Parameters, PID_JoinData, ResDynamic, C4Game::ScenarioParameterDefs, C4PacketJoinData::ScenarioParameterDefs, C4Network2ClientList::SendAddresses(), C4Network2Client::SendMsg(), C4PacketJoinData::SetClientID(), C4PacketJoinData::SetDynamicCore(), C4PacketJoinData::SetGameStatus(), C4PacketJoinData::SetStartCtrlTick(), C4Network2Client::SetStatus(), and Status.

Referenced by OnClientConnect(), and OnGameSynchronized().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetAllowObserve()

void C4Network2::SetAllowObserve ( bool  fAllow)

Definition at line 813 of file C4Network2.cpp.

814 {
815  if (!isHost()) return;
816  fAllowObserve = fAllow;
817 }

References fAllowObserve, and isHost().

Here is the call graph for this function:

◆ SetCtrlMode()

void C4Network2::SetCtrlMode ( int32_t  iCtrlMode)

Definition at line 819 of file C4Network2.cpp.

820 {
821  if (!isHost()) return;
822  // no change?
823  if (iCtrlMode == Status.getCtrlMode()) return;
824  // change game status
826 }

References ChangeGameStatus(), Control, C4GameControl::ControlTick, C4Network2Status::getCtrlMode(), C4Network2Status::getState(), isHost(), and Status.

Referenced by C4MessageInput::ProcessCommand().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetPassword()

void C4Network2::SetPassword ( const char *  szToPassword)

Definition at line 772 of file C4Network2.cpp.

773 {
774  bool fHadPassword = isPassworded();
775  // clear password?
776  if (!szToPassword || !*szToPassword)
777  sPassword.Clear();
778  else
779  // no? then set it
780  sPassword.Copy(szToPassword);
781  // if the has-password-state has changed, the reference is invalidated
782  if (fHadPassword != isPassworded()) InvalidateReference();
783 }
bool isPassworded() const
Definition: C4Network2.h:218

References StdStrBuf::Clear(), StdStrBuf::Copy(), InvalidateReference(), isPassworded(), and sPassword.

Referenced by C4StartupScenSelDlg::OnClosed(), C4GameOptionButtons::OnPasswordSet(), C4Application::ParseCommandLine(), and C4MessageInput::ProcessCommand().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Start()

bool C4Network2::Start ( )

Definition at line 506 of file C4Network2.cpp.

507 {
508  if (!isEnabled() || !isHost()) return false;
509  // change mode: go
511  return true;
512 }

References ChangeGameStatus(), Control, C4GameControl::ControlTick, GS_Go, isEnabled(), and isHost().

Referenced by EndVote(), C4Game::InitNetworkHost(), C4GameLobby::Countdown::OnSec1Timer(), C4MessageInput::ProcessCommand(), C4GameLobby::MainDlg::Start(), and C4Game::Unpause().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StartLobbyCountdown()

void C4Network2::StartLobbyCountdown ( int32_t  iCountdownTime)

Definition at line 2862 of file C4Network2.cpp.

2863 {
2864  // abort previous
2866  // start new
2867  pLobbyCountdown = new C4GameLobby::Countdown(iCountdownTime);
2868 }
void AbortLobbyCountdown()

References AbortLobbyCountdown(), and pLobbyCountdown.

Referenced by DoLobby(), C4MessageInput::ProcessCommand(), and C4GameLobby::MainDlg::Start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StartStreaming()

bool C4Network2::StartStreaming ( C4Record pRecord)

Definition at line 2883 of file C4Network2.cpp.

2884 {
2885  // Save back
2886  fStreaming = true;
2887  pStreamedRecord = pRecord;
2888  iLastStreamAttempt = time(nullptr);
2889 
2890  // Initialize compressor
2892  if (deflateInit(&StreamCompressor, 9) != Z_OK)
2893  return false;
2894 
2895  // Create stream buffer
2897  StreamCompressor.next_out = reinterpret_cast<BYTE*>(StreamingBuf.getMData());
2899 
2900  // Initialize HTTP client
2901  pStreamer = new C4HTTPClient();
2902  if (!pStreamer->Init())
2903  return false;
2905 
2906  return true;
2907 }
const size_t C4NetStreamingMaxBlockSize
Definition: C4Network2.h:57
uint8_t BYTE
std::enable_if< std::is_pod< T >::value >::type ZeroMem(T *lpMem, size_t dwSize)
Definition: Standard.h:60
class C4HTTPClient * pStreamer
Definition: C4Network2.h:193
void * getMData()
Definition: StdBuf.h:100
void New(size_t inSize)
Definition: StdBuf.h:146

References StdScheduler::Add(), Application, C4NetStreamingMaxBlockSize, fStreaming, StdBuf::getMData(), iLastStreamAttempt, C4HTTPClient::Init(), StdBuf::New(), pStreamedRecord, pStreamer, StreamCompressor, StreamingBuf, and ZeroMem().

Here is the call graph for this function:

◆ StopStreaming()

bool C4Network2::StopStreaming ( )

Definition at line 2926 of file C4Network2.cpp.

2927 {
2928  if (!fStreaming) return false;
2929 
2930  // Clear
2932  fStreaming = false;
2933  pStreamedRecord = nullptr;
2934  deflateEnd(&StreamCompressor);
2935  StreamingBuf.Clear();
2936  delete pStreamer;
2937  pStreamer = nullptr;
2938 
2939  // ... finalization?
2940  return true;
2941 }
void Clear()
Definition: StdBuf.h:190

References Application, StdBuf::Clear(), fStreaming, pStreamedRecord, pStreamer, StdScheduler::Remove(), StreamCompressor, and StreamingBuf.

Referenced by Clear(), and StreamOut().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StreamIn()

bool C4Network2::StreamIn ( bool  fFinish)
protected

Definition at line 2943 of file C4Network2.cpp.

2944 {
2945  if (!pStreamedRecord) return false;
2946 
2947  // Get data from record
2948  const StdBuf &Data = pStreamedRecord->GetStreamingBuf();
2949  if (!fFinish)
2950  if (!Data.getSize() || !StreamCompressor.avail_out)
2951  return false;
2952 
2953  do
2954  {
2955 
2956  // Compress
2957  StreamCompressor.next_in = const_cast<BYTE *>(getBufPtr<BYTE>(Data));
2958  StreamCompressor.avail_in = Data.getSize();
2959  int ret = deflate(&StreamCompressor, fFinish ? Z_FINISH : Z_NO_FLUSH);
2960 
2961  // Anything consumed?
2962  unsigned int iInAmount = Data.getSize() - StreamCompressor.avail_in;
2963  if (iInAmount > 0)
2964  pStreamedRecord->ClearStreamingBuf(iInAmount);
2965 
2966  // Done?
2967  if (!fFinish || ret == Z_STREAM_END)
2968  break;
2969 
2970  // Error while finishing?
2971  if (ret != Z_OK)
2972  return false;
2973 
2974  // Enlarge buffer, if neccessary
2975  size_t iPending = getPendingStreamData();
2976  size_t iGrow = StreamingBuf.getSize();
2977  StreamingBuf.Grow(iGrow);
2978  StreamCompressor.avail_out += iGrow;
2979  StreamCompressor.next_out = getMBufPtr<BYTE>(StreamingBuf, iPending);
2980 
2981  }
2982  while (true);
2983 
2984  return true;
2985 }
void ClearStreamingBuf(unsigned int iAmount)
Definition: C4Record.cpp:339
Definition: StdBuf.h:30
void Grow(size_t iGrow)
Definition: StdBuf.h:171

References C4Record::ClearStreamingBuf(), getPendingStreamData(), StdBuf::getSize(), C4Record::GetStreamingBuf(), StdBuf::Grow(), pStreamedRecord, StreamCompressor, and StreamingBuf.

Referenced by Execute(), FinishStreaming(), and StreamOut().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StreamOut()

bool C4Network2::StreamOut ( )
protected

Definition at line 2987 of file C4Network2.cpp.

2988 {
2989  // Streamer busy?
2990  if (!pStreamer || pStreamer->isBusy())
2991  return false;
2992 
2993  // Streamer done?
2994  if (pStreamer->isSuccess())
2995  {
2996 
2997  // Move new data to front of buffer
3000 
3001  // Free buffer space
3004 
3005  // Advance stream
3007 
3008  // Get input
3009  StreamIn(false);
3010  }
3011 
3012  // Clear streamer
3013  pStreamer->Clear();
3014 
3015  // Record is still running?
3016  if (pStreamedRecord)
3017  {
3018 
3019  // Enough available to send?
3021  return false;
3022 
3023  // Overflow protection
3025  return false;
3026 
3027  }
3028  // All data finished?
3029  else if (!getPendingStreamData())
3030  {
3031  // Then we're done.
3032  StopStreaming();
3033  return false;
3034  }
3035 
3036  // Set stream address
3037  StdStrBuf StreamAddr;
3038  StreamAddr.Copy(Game.Parameters.StreamAddress);
3039  StreamAddr.AppendFormat("pos=%d&end=%d", iCurrentStreamPosition, !pStreamedRecord);
3040  pStreamer->SetServer(StreamAddr.getData());
3041 
3042  // Send data
3043  size_t iStreamAmount = getPendingStreamData();
3044  iCurrentStreamAmount = iStreamAmount;
3045  iLastStreamAttempt = time(nullptr);
3046  return pStreamer->Query(StdBuf(StreamingBuf.getData(), iStreamAmount), false);
3047 }
const size_t C4NetStreamingMinBlockSize
Definition: C4Network2.h:56
const int C4NetStreamingInterval
Definition: C4Network2.h:58
bool Query(const StdBuf &Data, bool fBinary)
Definition: C4HTTP.cpp:158
void Clear()
Definition: C4HTTP.cpp:290
unsigned int iCurrentStreamAmount
Definition: C4Network2.h:194
const void * getData() const
Definition: StdBuf.h:99
void Move(size_t iFrom, size_t inSize, size_t iTo=0)
Definition: StdBuf.h:159

References StdStrBuf::AppendFormat(), C4NetStreamingInterval, C4NetStreamingMinBlockSize, C4HTTPClient::Clear(), StdStrBuf::Copy(), Game, StdBuf::getData(), StdStrBuf::getData(), getPendingStreamData(), iCurrentStreamAmount, iCurrentStreamPosition, iLastStreamAttempt, C4HTTPClient::isBusy(), C4HTTPClient::isSuccess(), StdBuf::Move(), C4Game::Parameters, pStreamedRecord, pStreamer, C4HTTPClient::Query(), C4HTTPClient::SetServer(), StopStreaming(), C4GameParameters::StreamAddress, StreamCompressor, StreamIn(), and StreamingBuf.

Referenced by Execute(), and FinishStreaming().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Sync()

bool C4Network2::Sync ( )

Definition at line 521 of file C4Network2.cpp.

522 {
523  // host only
524  if (!isEnabled() || !isHost()) return false;
525  // already syncing the network?
526  if (!fStatusAck)
527  {
528  // maybe we are already sync?
530  return true;
531  }
532  // already sync?
533  if (isFrozen()) return true;
534  // ok, so let's do a sync: change in the same state we are already in
536 }
bool isFrozen() const

References ChangeGameStatus(), CheckStatusAck(), Control, fStatusAck, fStatusReached, C4GameControl::getNextControlTick(), C4Network2Status::getState(), isEnabled(), isFrozen(), isHost(), and Status.

Referenced by C4GameControlNetwork::DoInput().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToggleAllowJoin()

bool C4Network2::ToggleAllowJoin ( )

Definition at line 759 of file C4Network2.cpp.

760 {
761  // just toggle
763  return true; // toggled
764 }
void AllowJoin(bool fAllow)
Definition: C4Network2.cpp:802

References AllowJoin(), and fAllowJoin.

Referenced by C4Game::InitKeyboard().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToggleClientListDlg()

bool C4Network2::ToggleClientListDlg ( )

Definition at line 766 of file C4Network2.cpp.

767 {
769  return true;
770 }

References C4Network2ClientListDlg::Toggle().

Referenced by C4Game::InitKeyboard().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateChaseTarget()

void C4Network2::UpdateChaseTarget ( )
protected

Definition at line 1984 of file C4Network2.cpp.

1985 {
1986  // no chasing clients?
1987  C4Network2Client *pClient;
1988  for (pClient = Clients.GetNextClient(nullptr); pClient; pClient = Clients.GetNextClient(pClient))
1989  if (pClient->isChasing())
1990  break;
1991  if (!pClient)
1992  {
1994  return;
1995  }
1996  // not time for an update?
1998  return;
1999  // copy status, set current tick
2000  C4Network2Status ChaseTarget = Status;
2001  ChaseTarget.SetTargetTick(::Control.ControlTick);
2002  // send to everyone involved
2003  for (pClient = Clients.GetNextClient(nullptr); pClient; pClient = Clients.GetNextClient(pClient))
2004  if (pClient->isChasing())
2005  pClient->SendMsg(MkC4NetIOPacket(PID_Status, ChaseTarget));
2006  iLastChaseTargetUpdate = time(nullptr);
2007 }
const unsigned int C4NetChaseTargetUpdateInterval
Definition: C4Network2.h:45
bool isChasing() const

References C4NetChaseTargetUpdateInterval, Clients, Control, C4GameControl::ControlTick, C4Network2ClientList::GetNextClient(), iLastChaseTargetUpdate, C4Network2Client::isChasing(), MkC4NetIOPacket(), PID_Status, C4Network2Client::SendMsg(), C4Network2Status::SetTargetTick(), and Status.

Referenced by Execute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Vote()

void C4Network2::Vote ( C4ControlVoteType  eType,
bool  fApprove = true,
int32_t  iData = 0 
)

Definition at line 2660 of file C4Network2.cpp.

2661 {
2662  // Original vote?
2663  if (!GetVote(C4ClientIDUnknown, eType, iData))
2664  {
2665  // Too fast?
2666  if (time(nullptr) < (time_t) (iLastOwnVoting + C4NetMinVotingInterval))
2667  {
2668  Log(LoadResStr("IDS_TEXT_YOUCANONLYSTARTONEVOTINGE"));
2669  if ((eType == VT_Kick && iData == Game.Clients.getLocalID()) || eType == VT_Cancel)
2670  OpenSurrenderDialog(eType, iData);
2671  return;
2672  }
2673  // Save timestamp
2674  iLastOwnVoting = time(nullptr);
2675  }
2676  // Already voted? Ignore
2677  if (GetVote(::Control.ClientID(), eType, iData))
2678  return;
2679  // Set pause mode if this is the host
2680  if (isHost() && isRunning())
2681  {
2682  Pause();
2683  fPausedForVote = true;
2684  }
2685  // send vote control
2686  ::Control.DoInput(CID_Vote, new C4ControlVote(eType, fApprove, iData), CDT_Direct);
2687 }
const unsigned int C4NetMinVotingInterval
Definition: C4Network2.h:53

References C4ClientIDUnknown, C4NetMinVotingInterval, CDT_Direct, CID_Vote, C4GameControl::ClientID(), C4Game::Clients, Control, C4GameControl::DoInput(), fPausedForVote, Game, C4ClientList::getLocalID(), GetVote(), iLastOwnVoting, isHost(), isRunning(), LoadResStr(), Log(), OpenSurrenderDialog(), Pause(), VT_Cancel, and VT_Kick.

Referenced by C4Game::Abort(), AddVote(), C4MainMenu::MenuCommand(), C4Game::Pause(), C4MessageInput::ProcessCommand(), and C4Game::Unpause().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ C4Network2IO

friend class C4Network2IO
friend

Definition at line 103 of file C4Network2.h.

Member Data Documentation

◆ Clients

◆ fAllowJoin

bool C4Network2::fAllowJoin {false}
protected

Definition at line 130 of file C4Network2.h.

Referenced by AllowJoin(), Clear(), DoLobby(), InitHost(), isJoinAllowed(), Join(), and ToggleAllowJoin().

◆ fAllowObserve

bool C4Network2::fAllowObserve
protected

Definition at line 130 of file C4Network2.h.

Referenced by isObservingAllowed(), Join(), and SetAllowObserve().

◆ fChasing

bool C4Network2::fChasing {false}
protected

Definition at line 141 of file C4Network2.h.

Referenced by CheckStatusReached(), HandleStatusAck(), and InitHost().

◆ fDelayedActivateReq

bool C4Network2::fDelayedActivateReq {false}
protected

Definition at line 178 of file C4Network2.h.

Referenced by CheckStatusReached(), Clear(), and RequestActivate().

◆ fDynamicNeeded

bool C4Network2::fDynamicNeeded {false}
protected

Definition at line 137 of file C4Network2.h.

Referenced by Clear(), CreateDynamic(), OnGameSynchronized(), and SendJoinData().

◆ fHost

bool C4Network2::fHost
protected

◆ fLeagueEndSent

bool C4Network2::fLeagueEndSent
protected

Definition at line 166 of file C4Network2.h.

Referenced by LeagueEnd(), LeagueGameEvaluate(), and LeagueStart().

◆ fLobbyRunning

bool C4Network2::fLobbyRunning {false}
protected

Definition at line 148 of file C4Network2.h.

Referenced by CheckStatusReached(), Clear(), and DoLobby().

◆ fPausedForVote

bool C4Network2::fPausedForVote {false}
protected

Definition at line 183 of file C4Network2.h.

Referenced by AddVote(), Clear(), EndVote(), and Vote().

◆ fStatusAck

bool C4Network2::fStatusAck {false}
protected

◆ fStatusReached

bool C4Network2::fStatusReached {false}
protected

◆ fStreaming

bool C4Network2::fStreaming {false}
protected

◆ fWrongPassword

bool C4Network2::fWrongPassword
protected

Definition at line 175 of file C4Network2.h.

Referenced by HandleConn(), and HandleConnRe().

◆ iCurrentStreamAmount

unsigned int C4Network2::iCurrentStreamAmount
protected

Definition at line 194 of file C4Network2.h.

Referenced by StreamOut().

◆ iCurrentStreamPosition

unsigned int C4Network2::iCurrentStreamPosition
protected

Definition at line 194 of file C4Network2.h.

Referenced by DrawStatus(), and StreamOut().

◆ iDynamicTick

int32_t C4Network2::iDynamicTick {-1}
protected

Definition at line 136 of file C4Network2.h.

Referenced by Clear(), CreateDynamic(), Execute(), HandleJoinData(), RemoveDynamic(), and SendJoinData().

◆ iLastChaseTargetUpdate

uint32_t C4Network2::iLastChaseTargetUpdate {0}
protected

Definition at line 158 of file C4Network2.h.

Referenced by Clear(), SendJoinData(), and UpdateChaseTarget().

◆ iLastLeagueUpdate

uint32_t C4Network2::iLastLeagueUpdate {0}
protected

Definition at line 165 of file C4Network2.h.

Referenced by Clear(), Execute(), and LeagueUpdate().

◆ iLastOwnVoting

time_t C4Network2::iLastOwnVoting {0}
protected

Definition at line 184 of file C4Network2.h.

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

◆ iLastReferenceUpdate

uint32_t C4Network2::iLastReferenceUpdate {0}
protected

Definition at line 164 of file C4Network2.h.

Referenced by Clear(), Execute(), and InvalidateReference().

◆ iLastStreamAttempt

time_t C4Network2::iLastStreamAttempt
protected

Definition at line 188 of file C4Network2.h.

Referenced by FinishStreaming(), StartStreaming(), and StreamOut().

◆ iLeagueUpdateDelay

uint32_t C4Network2::iLeagueUpdateDelay
protected

Definition at line 165 of file C4Network2.h.

Referenced by Execute(), InvalidateReference(), and LeagueUpdate().

◆ iNextClientID

int32_t C4Network2::iNextClientID {0}
protected

Definition at line 155 of file C4Network2.h.

Referenced by InitHost(), and Join().

◆ iVoteStartTime

time_t C4Network2::iVoteStartTime
protected

Definition at line 184 of file C4Network2.h.

Referenced by AddVote(), EndVote(), and Execute().

◆ MasterServerAddress

StdCopyStrBuf C4Network2::MasterServerAddress
protected

Definition at line 152 of file C4Network2.h.

Referenced by DeinitLeague(), and InitLeague().

◆ NetIO

◆ NetpuncherAddr

StdCopyStrBuf C4Network2::NetpuncherAddr
protected

Definition at line 198 of file C4Network2.h.

Referenced by getNetpuncherAddr(), and InitHost().

◆ NetpuncherGameID

C4NetpuncherID C4Network2::NetpuncherGameID
protected

Definition at line 197 of file C4Network2.h.

Referenced by Clear(), getNetpuncherGameID(), and InitHost().

◆ pControl

class C4GameControlNetwork* C4Network2::pControl {nullptr}
protected

◆ Players

◆ pLeagueClient

◆ pLobby

C4GameLobby::MainDlg* C4Network2::pLobby {nullptr}
protected

Definition at line 147 of file C4Network2.h.

Referenced by Clear(), DoLobby(), GetLobby(), HandleLobbyPacket(), and LeagueUpdateProcessReply().

◆ pLobbyCountdown

C4GameLobby::Countdown* C4Network2::pLobbyCountdown {nullptr}
protected

◆ pStreamedRecord

C4Record* C4Network2::pStreamedRecord
protected

◆ pStreamer

class C4HTTPClient* C4Network2::pStreamer
protected

Definition at line 193 of file C4Network2.h.

Referenced by StartStreaming(), StopStreaming(), and StreamOut().

◆ pVoteDialog

class C4VoteDialog* C4Network2::pVoteDialog {nullptr}
protected

Definition at line 182 of file C4Network2.h.

Referenced by Clear(), EndVote(), OnVoteDialogClosed(), OpenSurrenderDialog(), and OpenVoteDialog().

◆ ResDynamic

C4Network2ResCore C4Network2::ResDynamic
protected

◆ ResList

◆ sPassword

StdStrBuf C4Network2::sPassword
protected

Definition at line 172 of file C4Network2.h.

Referenced by Clear(), GetPassword(), HandleConn(), isPassworded(), and SetPassword().

◆ Status

◆ StreamCompressor

z_stream C4Network2::StreamCompressor
protected

◆ StreamingBuf

StdBuf C4Network2::StreamingBuf
protected

◆ tLastActivateRequest

C4TimeMilliseconds C4Network2::tLastActivateRequest
protected

Definition at line 161 of file C4Network2.h.

Referenced by Clear(), Execute(), and RequestActivate().

◆ Votes

C4Control C4Network2::Votes
protected

Definition at line 181 of file C4Network2.h.

Referenced by AddVote(), Clear(), EndVote(), Execute(), GetVote(), and OpenVoteDialog().


The documentation for this class was generated from the following files: