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

#include <C4Network2Players.h>

Public Member Functions

 C4Network2Players ()
 
 ~C4Network2Players ()=default
 
void Init ()
 
void Clear ()
 
bool JoinLocalPlayer (const char *szLocalPlayerFilename, bool initial=false)
 
void SendUpdatedPlayers ()
 
void ResetUpdatedPlayers ()
 
void HandlePacket (char cStatus, const C4PacketBase *pPacket, class C4Network2IOConnection *pConn)
 
void OnClientPart (class C4Client *pPartClient)
 
void OnStatusGoReached ()
 
void RequestPlayerInfoUpdate (const class C4ClientPlayerInfos &rRequest)
 
void HandlePlayerInfo (const class C4ClientPlayerInfos &rInfoPacket)
 
void HandlePlayerInfoUpdRequest (const class C4ClientPlayerInfos *pInfoPacket, bool fByHost)
 
C4ClientPlayerInfosGetLocalPlayerInfoPacket () const
 
C4ClientPlayerInfosGetIndexedPlayerInfoPacket (int iIndex)
 
DWORD GetClientChatColor (int idForClient, bool fLobby) const
 

Detailed Description

Definition at line 39 of file C4Network2Players.h.

Constructor & Destructor Documentation

C4Network2Players::C4Network2Players ( )

Definition at line 33 of file C4Network2Players.cpp.

33  : rInfoList(Game.Parameters.PlayerInfos)
34 {
35  // ctor - init rInfoList-ref to only
36 }
C4Game Game
Definition: C4Globals.cpp:52
C4GameParameters & Parameters
Definition: C4Game.h:67
C4PlayerInfoList PlayerInfos
C4Network2Players::~C4Network2Players ( )
default

Member Function Documentation

void C4Network2Players::Clear ( )

Definition at line 63 of file C4Network2Players.cpp.

Referenced by C4Network2::Clear().

64 {
65  // nothing...
66 }

Here is the caller graph for this function:

DWORD C4Network2Players::GetClientChatColor ( int  idForClient,
bool  fLobby 
) const

Definition at line 482 of file C4Network2Players.cpp.

References C4PT_User, C4Game::Clients, Game, C4ClientList::getClientByID(), C4PlayerInfo::GetColor(), C4PlayerInfoList::GetInfoByClientID(), C4PlayerInfo::GetLobbyColor(), C4ClientPlayerInfos::GetPlayerInfo(), and C4Client::isActivated().

Referenced by C4GameLobby::MainDlg::OnMessage().

483 {
484  // return color of first joined player; force to white for unknown
485  // deactivated always white
486  const C4Client *pClient = Game.Clients.getClientByID(idForClient);
487  if (pClient && pClient->isActivated())
488  {
489  // get players for activated
490  C4ClientPlayerInfos *pInfoPacket = rInfoList.GetInfoByClientID(idForClient);
491  C4PlayerInfo *pPlrInfo;
492  if (pInfoPacket && (pPlrInfo = pInfoPacket->GetPlayerInfo(0, C4PT_User)))
493  {
494  if (fLobby)
495  return pPlrInfo->GetLobbyColor();
496  else
497  return pPlrInfo->GetColor();
498  }
499  }
500  // default color
501  return 0xffffff;
502 }
C4Game Game
Definition: C4Globals.cpp:52
uint32_t GetLobbyColor() const
bool isActivated() const
Definition: C4Client.h:110
C4PlayerInfo * GetPlayerInfo(int32_t iIndex) const
C4ClientPlayerInfos * GetInfoByClientID(int32_t iClientID) const
Definition: C4PlayerInfo.h:361
uint32_t GetColor() const
Definition: C4PlayerInfo.h:153
C4Client * getClientByID(int32_t iID) const
Definition: C4Client.cpp:200
C4ClientList & Clients
Definition: C4Game.h:69

Here is the call graph for this function:

Here is the caller graph for this function:

C4ClientPlayerInfos * C4Network2Players::GetIndexedPlayerInfoPacket ( int  iIndex)

Definition at line 476 of file C4Network2Players.cpp.

References C4PlayerInfoList::GetIndexedInfo().

477 {
478  // just get from info list
479  return rInfoList.GetIndexedInfo(iIndex);
480 }
C4ClientPlayerInfos * GetIndexedInfo(int32_t iIndex) const
Definition: C4PlayerInfo.h:358

Here is the call graph for this function:

C4ClientPlayerInfos * C4Network2Players::GetLocalPlayerInfoPacket ( ) const

Definition at line 462 of file C4Network2Players.cpp.

References C4Game::Clients, Game, C4ClientPlayerInfos::GetClientID(), C4PlayerInfoList::GetIndexedInfo(), and C4ClientList::getLocalID().

463 {
464  // get local client ID
465  int iLocalClientID = Game.Clients.getLocalID();
466  // check all packets for same client ID as local
467  int i=0; C4ClientPlayerInfos *pkInfo;
468  while ((pkInfo = rInfoList.GetIndexedInfo(i++)))
469  if (pkInfo->GetClientID() == iLocalClientID)
470  // found
471  return pkInfo;
472  // not found
473  return nullptr;
474 }
C4Game Game
Definition: C4Globals.cpp:52
C4ClientPlayerInfos * GetIndexedInfo(int32_t iIndex) const
Definition: C4PlayerInfo.h:358
int32_t getLocalID() const
Definition: C4Client.h:171
int32_t GetClientID() const
Definition: C4PlayerInfo.h:257
C4ClientList & Clients
Definition: C4Game.h:69

Here is the call graph for this function:

void C4Network2Players::HandlePacket ( char  cStatus,
const C4PacketBase pPacket,
class C4Network2IOConnection pConn 
)

Definition at line 369 of file C4Network2Players.cpp.

References C4Network2::Clients, C4RoundResults::EvaluateLeague(), Game, C4Network2ClientList::GetClient(), C4Network2ClientList::GetClientByID(), C4Network2IOConnection::getClientID(), GETPKT, HandlePlayerInfoUpdRequest(), C4Network2Client::isHost(), C4Network2::isHost(), Network, PID_LeagueRoundResults, PID_PlayerInfoUpdReq, and C4Game::RoundResults.

Referenced by C4Network2IO::CallHandlers().

370 {
371  if (!pConn) return;
372 
373  // find associated client
374  C4Network2Client *pClient = ::Network.Clients.GetClient(pConn);
375  if (!pClient) pClient = ::Network.Clients.GetClientByID(pConn->getClientID());
376 
377 #define GETPKT(type, name) \
378  assert(pPacket); const type &name = \
379  static_cast<const type &>(*pPacket);
380 
381  // player join request?
382  if (cStatus == PID_PlayerInfoUpdReq)
383  {
385  // this packet is sent to the host only, and thus cannot have been sent from the host
386  if (!::Network.isHost()) return;
387  // handle this packet
388  HandlePlayerInfoUpdRequest(&pkPlrInfo.Info, false);
389  }
390  else if (cStatus == PID_LeagueRoundResults)
391  {
392  GETPKT(C4PacketLeagueRoundResults, pkLeagueInfo);
393  // accepted from the host only
394  if (!pClient || !pClient->isHost()) return;
395  // process
396  Game.RoundResults.EvaluateLeague(pkLeagueInfo.sResultsString.getData(), pkLeagueInfo.fSuccess, pkLeagueInfo.Players);
397  }
398 
399 #undef GETPKT
400 }
C4Network2Client * GetClientByID(int32_t iID) const
bool isHost() const
Definition: C4Network2.h:209
C4Game Game
Definition: C4Globals.cpp:52
C4Network2Client * GetClient(const char *szName) const
C4Network2 Network
Definition: C4Globals.cpp:53
C4RoundResults & RoundResults
Definition: C4Game.h:73
void EvaluateLeague(const char *szResultMsg, bool fSuccess, const C4RoundResultsPlayers &rLeagueInfo)
C4Network2ClientList Clients
Definition: C4Network2.h:116
void HandlePlayerInfoUpdRequest(const class C4ClientPlayerInfos *pInfoPacket, bool fByHost)
#define GETPKT(type, name)
bool isHost() const

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2Players::HandlePlayerInfo ( const class C4ClientPlayerInfos rInfoPacket)

Definition at line 223 of file C4Network2Players.cpp.

References C4PlayerInfoList::AddInfo(), C4Game::Clients, Game, C4ClientList::getClientByID(), C4Network2::GetLobby(), C4Network2::InvalidateReference(), C4Client::isActivated(), C4Network2::isEnabled(), C4Network2::isHost(), C4Network2::isRunning(), C4PlayerInfoList::LoadResources(), Network, C4GameLobby::MainDlg::OnPlayersChange(), C4TeamList::RecheckPlayers(), C4TeamList::RecheckTeams(), SendUpdatedPlayers(), and C4Game::Teams.

224 {
225  // network only
226  assert(::Network.isEnabled());
227  // copy client player infos out of packet to be used in local list
228  C4ClientPlayerInfos *pClientInfo = new C4ClientPlayerInfos(rInfoPacket);
229  // add client info to local player info list - eventually deleting pClientInfo and
230  // returning a pointer to the new info structure when multiple player infos are merged
231  // may also replace existing info, if this is an update-call
232  pClientInfo = rInfoList.AddInfo(pClientInfo);
233  // make sure team list reflects teams set in player infos
235  Game.Teams.RecheckTeams(); // recheck random teams - if a player left, teams may need to be rebalanced
236  // make sure resources are loaded for those players
237  rInfoList.LoadResources();
238  // get associated client - note that pClientInfo might be nullptr for empty packets that got discarded
239  if (pClientInfo)
240  {
241  const C4Client *pClient = Game.Clients.getClientByID(pClientInfo->GetClientID());
242  // host, game running and client active already?
243  if (::Network.isHost() && ::Network.isRunning() && pClient && pClient->isActivated())
244  {
245  // then join the players immediately
246  JoinUnjoinedPlayersInControlQueue(pClientInfo);
247  }
248  }
249  // adding the player may have invalidated other players (through team settings). Send them.
251  // lobby: update players
253  if (pLobby) pLobby->OnPlayersChange();
254  // invalidate reference
256 }
void RecheckTeams()
Definition: C4Teams.cpp:669
void RecheckPlayers()
Definition: C4Teams.cpp:663
class C4GameLobby::MainDlg * GetLobby() const
Definition: C4Network2.h:216
bool isHost() const
Definition: C4Network2.h:209
bool isRunning() const
Definition: C4Network2.h:206
C4Game Game
Definition: C4Globals.cpp:52
bool isActivated() const
Definition: C4Client.h:110
C4TeamList & Teams
Definition: C4Game.h:70
C4Network2 Network
Definition: C4Globals.cpp:53
C4ClientPlayerInfos * AddInfo(C4ClientPlayerInfos *pNewClientInfo)
void InvalidateReference()
bool isEnabled() const
Definition: C4Network2.h:203
C4Client * getClientByID(int32_t iID) const
Definition: C4Client.cpp:200
C4ClientList & Clients
Definition: C4Game.h:69

Here is the call graph for this function:

void C4Network2Players::HandlePlayerInfoUpdRequest ( const class C4ClientPlayerInfos pInfoPacket,
bool  fByHost 
)

Definition at line 135 of file C4Network2Players.cpp.

References C4PlayerInfoList::AssignPlayerIDs(), C4PlayerInfoList::AssignTeams(), C4PT_Script, CDT_Direct, CID_PlrInfo, Control, C4GameControl::DoInput(), Game, C4PlayerInfo::GetID(), C4PlayerInfoList::GetInfoByClientID(), C4Network2::GetLobby(), C4PlayerInfoList::GetPlayerInfoByID(), C4ClientPlayerInfos::GetPlayerInfoByRes(), C4PlayerInfo::GetRes(), C4Network2Res::getResID(), C4PlayerInfo::GetType(), iCnt, C4Network2::isEnabled(), C4Network2::isHost(), C4GameParameters::isLeague(), C4Network2::isLobbyActive(), C4Network2::LeaguePlrAuthCheck(), Log(), Network, C4GameLobby::MainDlg::OnPlayersChange(), C4Game::Parameters, C4PlayerInfo::ResetLeagueProjectedGain(), C4PlayerInfoList::ResetLeagueProjectedGain(), SendUpdatedPlayers(), C4PlayerInfo::SetAuthID(), and C4PlayerInfoList::UpdatePlayerAttributes().

Referenced by HandlePacket(), JoinLocalPlayer(), and RequestPlayerInfoUpdate().

136 {
137  // network host only
138  assert(::Network.isEnabled());
139  assert(::Network.isHost());
140  // copy client infos (need to be adjusted)
141  C4ClientPlayerInfos OwnInfoPacket(*pInfoPacket);
142  // safety: check any duplicate, unjoined players first
143  // check those with unassigned IDs only, so update packets won't be rejected by this
144  if (!OwnInfoPacket.IsInitialPacket())
145  {
146  C4ClientPlayerInfos *pExistingClientInfo = rInfoList.GetInfoByClientID(OwnInfoPacket.GetClientID());
147  if (pExistingClientInfo)
148  {
149  int iCnt=OwnInfoPacket.GetPlayerCount(); C4PlayerInfo *pPlrInfo;
150  C4Network2Res *pRes;
151  while (iCnt--) if ((pPlrInfo=OwnInfoPacket.GetPlayerInfo(iCnt)))
152  if (!pPlrInfo->GetID()) if ((pRes = pPlrInfo->GetRes()))
153  if (pExistingClientInfo->GetPlayerInfoByRes(pRes->getResID()))
154  {
155  // double join: simply deny without message
156 #ifdef _DEBUG
157  Log("Network: Duplicate player join rejected!");
158 #endif
159  OwnInfoPacket.RemoveIndexedInfo(iCnt);
160  }
161  }
162  if (!OwnInfoPacket.GetPlayerCount())
163  {
164  // player join request without players: probably all removed because doubled
165 #ifdef _DEBUG
166  Log("Network: Empty player join request ignored!");
167 #endif
168  return;
169  }
170  }
171  // assign player IDs
172  if (!rInfoList.AssignPlayerIDs(&OwnInfoPacket) && OwnInfoPacket.IsAddPacket())
173  {
174  // no players could be joined in an add request: probably because the maximum player limit has been reached
175  return;
176  }
177  // check doubled savegame player usage
178  UpdateSavegameAssignments(&OwnInfoPacket);
179  // update teams
180  rInfoList.AssignTeams(&OwnInfoPacket, fByHost);
181  // update any other player colors and names
182  // this may only change colors and names of all unjoined players (which is all players in lobby mode)
183  // any affected players will get an updated-flag
184  rInfoList.UpdatePlayerAttributes(&OwnInfoPacket, true);
185  // league score gains may now be different
186  rInfoList.ResetLeagueProjectedGain(true);
187  int32_t iPlrInfo = 0;
188  C4PlayerInfo *pPlrInfo;
189  while ((pPlrInfo = OwnInfoPacket.GetPlayerInfo(iPlrInfo++))) pPlrInfo->ResetLeagueProjectedGain();
190  if (Game.Parameters.isLeague())
191  {
192  // check league authentication for new players
193  for (int i = 0; i < OwnInfoPacket.GetPlayerCount(); i++)
194  {
195  if (!rInfoList.GetPlayerInfoByID(OwnInfoPacket.GetPlayerInfo(i)->GetID()))
196  {
197  C4PlayerInfo *pInfo = OwnInfoPacket.GetPlayerInfo(i);
198  // remove normal (non-script) player infos without authentication or when not in the lobby
199  if (pInfo->GetType() != C4PT_Script && (!::Network.isLobbyActive() || !::Network.LeaguePlrAuthCheck(pInfo)))
200  {
201  OwnInfoPacket.RemoveIndexedInfo(i);
202  i--;
203  }
204  else
205  // always reset authentication ID after check - it's not needed anymore
206  pInfo->SetAuthID("");
207  }
208  }
209  }
210  // send updates to all other clients and reset update flags
212  // finally, add new player join as direct input
213  // this will add the player infos directly on host side (DirectExec as a subcall),
214  // so future player join request will take the other joined clients into consideration
215  // when assigning player colors, etc.; it will also start resource loading
216  // in running mode, this call will also put the actual player joins into the queue
218  // notify lobby of updates
220  if (pLobby) pLobby->OnPlayersChange();
221 }
class C4GameLobby::MainDlg * GetLobby() const
Definition: C4Network2.h:216
C4Network2Res * GetRes() const
Definition: C4PlayerInfo.h:163
bool isHost() const
Definition: C4Network2.h:209
bool LeaguePlrAuthCheck(C4PlayerInfo *pInfo)
C4Game Game
Definition: C4Globals.cpp:52
C4PlayerInfo * GetPlayerInfoByRes(int32_t idResID) const
bool isLobbyActive() const
Definition: C4Network2.h:204
void SetAuthID(const char *sznAuthID)
Definition: C4PlayerInfo.h:133
void UpdatePlayerAttributes(C4ClientPlayerInfos *pForInfo, bool fResolveConflicts)
C4GameParameters & Parameters
Definition: C4Game.h:67
C4PlayerInfo * GetPlayerInfoByID(int32_t id) const
void AssignTeams(C4ClientPlayerInfos *pNewClientInfo, bool fByHost)
C4Network2 Network
Definition: C4Globals.cpp:53
int iCnt
Definition: TstC4NetIO.cpp:32
C4GameControl Control
void DoInput(C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)
bool isEnabled() const
Definition: C4Network2.h:203
C4ClientPlayerInfos * GetInfoByClientID(int32_t iClientID) const
Definition: C4PlayerInfo.h:361
bool Log(const char *szMessage)
Definition: C4Log.cpp:192
bool isLeague() const
int32_t GetID() const
Definition: C4PlayerInfo.h:194
C4PlayerType GetType() const
Definition: C4PlayerInfo.h:152
bool AssignPlayerIDs(C4ClientPlayerInfos *pNewClientInfo)
void ResetLeagueProjectedGain(bool fSetUpdated)
void ResetLeagueProjectedGain()
Definition: C4PlayerInfo.h:145
int32_t getResID() const

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2Players::Init ( )

Definition at line 38 of file C4Network2Players.cpp.

References C4Game::C4S, C4PlayerInfoList::CreateRestoreInfosForJoinedScriptPlayers(), Game, C4Scenario::Head, C4Network2::isEnabled(), C4Network2::isHost(), C4Game::IsRunning, JoinLocalPlayer(), Network, C4Game::PlayerFilenames, C4Game::PlayerInfos, C4SHead::Replay, and C4Game::RestorePlayerInfos.

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

39 {
40  // caution: In this call, only local players are joined
41  // remote players may have been added already for runtime joins
42  // not in replay
43  if (Game.C4S.Head.Replay) return;
44  // network only
45  assert(::Network.isEnabled());
46  // must init before game is running
47  assert(!Game.IsRunning);
48  if (::Network.isHost())
49  {
50  // host: Rejoin script players from savegame before joining local players so team distribution is done correctly
51  // But prepare empty host list before recreation
52  JoinLocalPlayer("", true);
55  }
56  else
57  {
58  // Client: join the local player(s)
60  }
61 }
bool IsRunning
Definition: C4Game.h:139
C4PlayerInfoList & RestorePlayerInfos
Definition: C4Game.h:72
bool isHost() const
Definition: C4Network2.h:209
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:74
bool Replay
Definition: C4Scenario.h:72
C4Network2 Network
Definition: C4Globals.cpp:53
bool isEnabled() const
Definition: C4Network2.h:203
C4PlayerInfoList & PlayerInfos
Definition: C4Game.h:71
char PlayerFilenames[20 *_MAX_PATH+1]
Definition: C4Game.h:104
C4SHead Head
Definition: C4Scenario.h:230
bool JoinLocalPlayer(const char *szLocalPlayerFilename, bool initial=false)
void CreateRestoreInfosForJoinedScriptPlayers(C4PlayerInfoList &rSavegamePlayers)

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2Players::JoinLocalPlayer ( const char *  szLocalPlayerFilename,
bool  initial = false 
)

Definition at line 68 of file C4Network2Players.cpp.

References C4Game::C4S, C4Game::Clients, C4Network2::Clients, Game, C4ClientList::getLocal(), C4ClientPlayerInfos::GetPlayerCount(), HandlePlayerInfoUpdRequest(), C4Scenario::Head, C4PacketPlayerInfoUpdRequest::Info, C4Client::isActivated(), C4Network2::isEnabled(), C4Network2::isHost(), C4GameParameters::isLeague(), C4Client::isObserver(), C4Network2::LeaguePlrAuth(), MkC4NetIOPacket(), Network, C4Game::Parameters, PID_PlayerInfoUpdReq, C4SHead::Replay, C4Network2::RequestActivate(), and C4Network2ClientList::SendMsgToHost().

Referenced by Init(), C4PlayerList::JoinNew(), C4GameLobby::MainDlg::OnClientAddPlayer(), and C4MessageInput::ProcessCommand().

69 {
70  // ignore in replay
71  // shouldn't even come here though
72  assert(!Game.C4S.Head.Replay);
73  if (Game.C4S.Head.Replay) return false;
74  // if observing: don't try
75  if (Game.Clients.getLocal()->isObserver()) return false;
76  // network only
77  assert(::Network.isEnabled());
78  // create join info packet
79  C4ClientPlayerInfos JoinInfo(szLocalPlayerFilename, !initial);
80  // league game: get authentication for players
81  if (Game.Parameters.isLeague())
82  for (int i = 0; i < JoinInfo.GetPlayerCount(); i++)
83  {
84  C4PlayerInfo *pInfo = JoinInfo.GetPlayerInfo(i);
85  if (!::Network.LeaguePlrAuth(pInfo))
86  {
87  JoinInfo.RemoveIndexedInfo(i);
88  i--;
89  }
90  }
91  // host or client?
92  if (::Network.isHost())
93  {
94  // error joining players? Zero players is OK for initial packet; marks host as observer
95  if (!initial && !JoinInfo.GetPlayerCount()) return false;
96  // handle it as a direct request
97  HandlePlayerInfoUpdRequest(&JoinInfo, true);
98  }
99  else
100  {
101  // clients request initial joins at host only
102  // create player info for local player joins
103  C4PacketPlayerInfoUpdRequest JoinRequest(JoinInfo);
104  // any players to join? Zero players is OK for initial packet; marks client as observer
105  // it's also necessary to send the empty player info packet, so the host will answer
106  // with infos of all other clients
107  if (!initial && !JoinRequest.Info.GetPlayerCount()) return false;
109  // request activation
110  if (JoinRequest.Info.GetPlayerCount() && !Game.Clients.getLocal()->isActivated())
112  }
113  // done, success
114  return true;
115 }
C4Client * getLocal() const
Definition: C4Client.h:161
bool SendMsgToHost(C4NetIOPacket rPkt)
bool isHost() const
Definition: C4Network2.h:209
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:74
bool Replay
Definition: C4Scenario.h:72
bool isActivated() const
Definition: C4Client.h:110
C4GameParameters & Parameters
Definition: C4Game.h:67
bool isObserver() const
Definition: C4Client.h:111
C4Network2 Network
Definition: C4Globals.cpp:53
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
bool LeaguePlrAuth(C4PlayerInfo *pInfo)
bool isEnabled() const
Definition: C4Network2.h:203
C4Network2ClientList Clients
Definition: C4Network2.h:116
C4ClientList & Clients
Definition: C4Game.h:69
bool isLeague() const
C4SHead Head
Definition: C4Scenario.h:230
void RequestActivate()
void HandlePlayerInfoUpdRequest(const class C4ClientPlayerInfos *pInfoPacket, bool fByHost)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2Players::OnClientPart ( class C4Client pPartClient)

Definition at line 402 of file C4Network2Players.cpp.

References Game, C4Client::getID(), C4PlayerInfoList::GetInfoPtrByClientID(), C4PlayerInfo::HasJoined(), C4Network2::InvalidateReference(), C4Network2::isEnabled(), C4Network2::isHost(), Network, C4Game::PlayerInfos, C4TeamList::RecheckPlayers(), C4TeamList::RecheckTeams(), C4PlayerInfoList::RemoveInfo(), C4PlayerInfoList::ResetLeagueProjectedGain(), SendUpdatedPlayers(), C4Game::Teams, and C4PlayerInfoList::UpdatePlayerAttributes().

403 {
404  // lobby could be notified about the removal - but this would be redundant, because
405  // client leave notification is already done directly; this will delete any associated players
406  C4ClientPlayerInfos **ppCltInfo = rInfoList.GetInfoPtrByClientID(pPartClient->getID());
407  // abort here if no info is registered - client seems to have had a short life only, anyway...
408  if (!ppCltInfo) return;
409  // remove all unjoined player infos
410  for (int32_t i = 0; i < (*ppCltInfo)->GetPlayerCount();)
411  {
412  C4PlayerInfo *pInfo = (*ppCltInfo)->GetPlayerInfo(i);
413  // not joined yet? remove it
414  if (!pInfo->HasJoined())
415  (*ppCltInfo)->RemoveIndexedInfo(i);
416  else
417  // just ignore, the "removed" flag will be set eventually
418  i++;
419  }
420  // empty? remove
421  if (!(*ppCltInfo)->GetPlayerCount())
422  rInfoList.RemoveInfo(ppCltInfo);
423  // update team association to left player
425  // host: update player data according to leaver
426  if (::Network.isHost() && ::Network.isEnabled())
427  {
428  // host: update any player colors and names
429  rInfoList.UpdatePlayerAttributes();
430  // team distribution of remaining unjoined players may change
432  // league score gains may now be different
434  // send changes to all clients and reset update flags
436  }
437  // invalidate reference
438  if (::Network.isHost())
440 }
void RecheckTeams()
Definition: C4Teams.cpp:669
void RecheckPlayers()
Definition: C4Teams.cpp:663
bool isHost() const
Definition: C4Network2.h:209
C4Game Game
Definition: C4Globals.cpp:52
void RemoveInfo(C4ClientPlayerInfos **ppRemoveInfo)
Definition: C4PlayerInfo.h:386
C4ClientPlayerInfos ** GetInfoPtrByClientID(int32_t iClientID) const
void UpdatePlayerAttributes(C4ClientPlayerInfos *pForInfo, bool fResolveConflicts)
C4TeamList & Teams
Definition: C4Game.h:70
C4Network2 Network
Definition: C4Globals.cpp:53
void InvalidateReference()
bool isEnabled() const
Definition: C4Network2.h:203
C4PlayerInfoList & PlayerInfos
Definition: C4Game.h:71
void ResetLeagueProjectedGain(bool fSetUpdated)
bool HasJoined() const
Definition: C4PlayerInfo.h:165

Here is the call graph for this function:

void C4Network2Players::OnStatusGoReached ( )

Definition at line 442 of file C4Network2Players.cpp.

References C4Game::Clients, Game, C4ClientList::getClientByID(), C4ClientPlayerInfos::GetClientID(), C4PlayerInfoList::GetIndexedInfo(), C4ClientPlayerInfos::HasUnjoinedPlayers(), C4Client::isActivated(), C4Network2::isHost(), and Network.

Referenced by C4Network2::OnStatusAck().

443 {
444  // host only
445  if (!::Network.isHost()) return;
446  // check all player lists
447  int i=0; C4ClientPlayerInfos *pkInfo;
448  while ((pkInfo = rInfoList.GetIndexedInfo(i++)))
449  // any unsent player joins?
450  if (pkInfo->HasUnjoinedPlayers())
451  {
452  // get client core
453  const C4Client *pClient = Game.Clients.getClientByID(pkInfo->GetClientID());
454  // don't send if client is unknown or not activated yet
455  if (!pClient || !pClient->isActivated()) continue;
456  // send them w/o info packet
457  // info packets are synced during pause mode
458  JoinUnjoinedPlayersInControlQueue(pkInfo);
459  }
460 }
bool isHost() const
Definition: C4Network2.h:209
C4Game Game
Definition: C4Globals.cpp:52
bool isActivated() const
Definition: C4Client.h:110
C4ClientPlayerInfos * GetIndexedInfo(int32_t iIndex) const
Definition: C4PlayerInfo.h:358
C4Network2 Network
Definition: C4Globals.cpp:53
int32_t GetClientID() const
Definition: C4PlayerInfo.h:257
C4Client * getClientByID(int32_t iID) const
Definition: C4Client.cpp:200
C4ClientList & Clients
Definition: C4Game.h:69
bool HasUnjoinedPlayers() const

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2Players::RequestPlayerInfoUpdate ( const class C4ClientPlayerInfos rRequest)

Definition at line 117 of file C4Network2Players.cpp.

References C4Network2::Clients, HandlePlayerInfoUpdRequest(), C4Network2::isEnabled(), C4Network2::isHost(), MkC4NetIOPacket(), Network, PID_PlayerInfoUpdReq, and C4Network2ClientList::SendMsgToHost().

Referenced by C4PlayerInfoList::DoPlayerInfoUpdate(), and C4MessageInput::ProcessCommand().

118 {
119  // network only
120  assert(::Network.isEnabled());
121  // host or client?
122  if (::Network.isHost())
123  {
124  // host processes directly
125  HandlePlayerInfoUpdRequest(&rRequest, true);
126  }
127  else
128  {
129  // client sends request to host
130  C4PacketPlayerInfoUpdRequest UpdateRequest(rRequest);
132  }
133 }
bool SendMsgToHost(C4NetIOPacket rPkt)
bool isHost() const
Definition: C4Network2.h:209
C4Network2 Network
Definition: C4Globals.cpp:53
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
bool isEnabled() const
Definition: C4Network2.h:203
C4Network2ClientList Clients
Definition: C4Network2.h:116
void HandlePlayerInfoUpdRequest(const class C4ClientPlayerInfos *pInfoPacket, bool fByHost)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2Players::ResetUpdatedPlayers ( )

Definition at line 323 of file C4Network2Players.cpp.

References C4PlayerInfoList::GetIndexedInfo(), and C4ClientPlayerInfos::ResetUpdated().

324 {
325  // mark all client packets as up-to-date
326  C4ClientPlayerInfos *pUpdInfo; int i=0;
327  while ((pUpdInfo = rInfoList.GetIndexedInfo(i++))) pUpdInfo->ResetUpdated();
328 }
C4ClientPlayerInfos * GetIndexedInfo(int32_t iIndex) const
Definition: C4PlayerInfo.h:358

Here is the call graph for this function:

void C4Network2Players::SendUpdatedPlayers ( )

Definition at line 258 of file C4Network2Players.cpp.

References CDT_Direct, CID_PlrInfo, Control, C4GameControl::DoInput(), C4PlayerInfoList::GetIndexedInfo(), C4ClientPlayerInfos::IsUpdated(), and C4ClientPlayerInfos::ResetUpdated().

Referenced by HandlePlayerInfo(), HandlePlayerInfoUpdRequest(), C4Network2::LeagueUpdateProcessReply(), OnClientPart(), C4TeamList::SetTeamColors(), and C4TeamList::SetTeamDistribution().

259 {
260  // check all clients for update
261  C4ClientPlayerInfos *pUpdInfo; int i=0;
262  while ((pUpdInfo = rInfoList.GetIndexedInfo(i++)))
263  if (pUpdInfo->IsUpdated())
264  {
265  pUpdInfo->ResetUpdated();
266  C4ControlPlayerInfo *pkSend = new C4ControlPlayerInfo(*pUpdInfo);
267  // send info to all
269  }
270 }
C4ClientPlayerInfos * GetIndexedInfo(int32_t iIndex) const
Definition: C4PlayerInfo.h:358
C4GameControl Control
void DoInput(C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)

Here is the call graph for this function:

Here is the caller graph for this function:


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