OpenClonk
C4ClientPlayerInfos Class Reference

#include <C4PlayerInfo.h>

Public Member Functions

 C4ClientPlayerInfos (const char *szJoinFilenames=nullptr, bool fAdd=false, C4PlayerInfo *pAddInfo=nullptr)
 
 C4ClientPlayerInfos (const C4ClientPlayerInfos &rCopy)
 
 ~C4ClientPlayerInfos ()
 
C4ClientPlayerInfosoperator= (const C4ClientPlayerInfos &rCopy)
 
void Clear ()
 
void GrabMergeFrom (C4ClientPlayerInfos &rFrom)
 
void AddInfo (C4PlayerInfo *pAddInfo)
 
void RemoveIndexedInfo (int32_t iAtIndex)
 
void RemoveInfo (int32_t idPlr)
 
void SetUpdated ()
 
bool IsUpdated ()
 
void ResetUpdated ()
 
void SetAdd ()
 
void ResetAdd ()
 
int32_t GetPlayerCount () const
 
int32_t GetFlaggedPlayerCount (DWORD dwFlag) const
 
C4PlayerInfoGetPlayerInfo (int32_t iIndex) const
 
C4PlayerInfoGetPlayerInfo (int32_t iIndex, C4PlayerType eType) const
 
C4PlayerInfoGetPlayerInfoByID (int32_t id) const
 
C4PlayerInfoGetPlayerInfoByRes (int32_t idResID) const
 
int32_t GetClientID () const
 
bool HasUnjoinedPlayers () const
 
int32_t GetJoinedPlayerCount () const
 
bool IsAddPacket () const
 
bool IsInitialPacket () const
 
bool IsDeveloperPacket () const
 
void LoadResources ()
 
void CompileFunc (StdCompiler *pComp)
 

Detailed Description

Definition at line 208 of file C4PlayerInfo.h.

Constructor & Destructor Documentation

◆ C4ClientPlayerInfos() [1/2]

C4ClientPlayerInfos::C4ClientPlayerInfos ( const char *  szJoinFilenames = nullptr,
bool  fAdd = false,
C4PlayerInfo pAddInfo = nullptr 
)

Definition at line 372 of file C4PlayerInfo.cpp.

373 {
374  // init for local client?
375  if (szJoinFilenames || pAddInfo)
376  {
377  // set developer flag for developer hosts
378  if (SSearch(Config.GetRegistrationData("Type"), "Developer"))
379  dwFlags |= CIF_Developer;
380  // set local ID
381  iClientID = ::Control.ClientID();
382  // maybe control is not preinitialized
383  if (!::Control.isNetwork() && iClientID < 0) iClientID = 0;
384  // join packet or initial packet?
385  if (fAdd)
386  // packet is to be added to other players
387  dwFlags |= CIF_AddPlayers;
388  else
389  // set initial flag for first-time join packet
390  dwFlags |= CIF_Initial;
391  // join all players in list
392  if ((iPlayerCapacity = (szJoinFilenames ? SModuleCount(szJoinFilenames) : 0) + !!pAddInfo))
393  {
394  ppPlayers = new C4PlayerInfo *[iPlayerCapacity];
395  if (szJoinFilenames)
396  {
397  char szPlrFile[_MAX_PATH_LEN];
398  for (int32_t i=0; i<iPlayerCapacity; ++i)
399  if (SGetModule(szJoinFilenames, i, szPlrFile, _MAX_PATH))
400  {
401  C4PlayerInfo *pNewInfo = new C4PlayerInfo();
402  if (pNewInfo->LoadFromLocalFile(szPlrFile))
403  {
404  // player def loaded; register and count it
405  ppPlayers[iPlayerCount++] = pNewInfo;
406  }
407  else
408  {
409  // loading failure; clear info class
410  delete pNewInfo;
411  //
412  Log(FormatString(LoadResStr("IDS_ERR_LOAD_PLAYER"), szPlrFile).getData());
413  }
414  }
415  }
416  if (pAddInfo)
417  ppPlayers[iPlayerCount++] = pAddInfo;
418  }
419  }
420 }
C4Config Config
Definition: C4Config.cpp:930
C4GameControl Control
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
bool Log(const char *szMessage)
Definition: C4Log.cpp:204
#define _MAX_PATH
#define _MAX_PATH_LEN
const char * SSearch(const char *szString, const char *szIndex)
Definition: Standard.cpp:369
bool SGetModule(const char *szList, int iIndex, char *sTarget, int iSize)
Definition: Standard.cpp:539
int SModuleCount(const char *szList)
Definition: Standard.cpp:617
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
const char * GetRegistrationData(const char *field)
Definition: C4Config.h:285
int32_t ClientID() const
bool isNetwork() const
Definition: C4GameControl.h:97
bool LoadFromLocalFile(const char *szFilename)

References _MAX_PATH, _MAX_PATH_LEN, C4GameControl::ClientID(), Config, Control, FormatString(), C4Config::GetRegistrationData(), C4GameControl::isNetwork(), C4PlayerInfo::LoadFromLocalFile(), LoadResStr(), Log(), SGetModule(), SModuleCount(), and SSearch().

Here is the call graph for this function:

◆ C4ClientPlayerInfos() [2/2]

C4ClientPlayerInfos::C4ClientPlayerInfos ( const C4ClientPlayerInfos rCopy)

Definition at line 422 of file C4PlayerInfo.cpp.

423 {
424  // copy fields
425  iClientID = rCopy.iClientID;
426  if ((iPlayerCount = rCopy.iPlayerCount))
427  {
428  // copy player infos
429  ppPlayers = new C4PlayerInfo *[iPlayerCapacity = rCopy.iPlayerCapacity];
430  int32_t i = iPlayerCount;
431  C4PlayerInfo **ppCurrPlrInfo = ppPlayers, **ppSrcPlrInfo = rCopy.ppPlayers;
432  while (i--) *ppCurrPlrInfo++ = new C4PlayerInfo(**ppSrcPlrInfo++);
433  }
434  // no players
435  else
436  {
437  ppPlayers = nullptr;
438  iPlayerCapacity = 0;
439  }
440  // misc fields
441  dwFlags = rCopy.dwFlags;
442 }

◆ ~C4ClientPlayerInfos()

C4ClientPlayerInfos::~C4ClientPlayerInfos ( )
inline

Definition at line 233 of file C4PlayerInfo.h.

233 { Clear(); } // dtor

References Clear().

Here is the call graph for this function:

Member Function Documentation

◆ AddInfo()

void C4ClientPlayerInfos::AddInfo ( C4PlayerInfo pAddInfo)

Definition at line 508 of file C4PlayerInfo.cpp.

509 {
510  // grow list if necessary
511  if (iPlayerCount == iPlayerCapacity) GrowList(4);
512  // add info
513  ppPlayers[iPlayerCount++] = pAddInfo;
514 }

Referenced by C4PlayerInfoList::CreateRestoreInfosForJoinedScriptPlayers().

Here is the caller graph for this function:

◆ Clear()

void C4ClientPlayerInfos::Clear ( )

Definition at line 469 of file C4PlayerInfo.cpp.

470 {
471  // del player infos
472  int32_t i = iPlayerCount; C4PlayerInfo **ppCurrPlrInfo = ppPlayers;
473  while (i--) delete *ppCurrPlrInfo++;
474  // del player info vector
475  delete [] ppPlayers; ppPlayers = nullptr;
476  // reset other fields
477  iPlayerCount = iPlayerCapacity = 0;
478  iClientID=-1;
479  dwFlags = 0;
480 }

Referenced by CompileFunc(), operator=(), and ~C4ClientPlayerInfos().

Here is the caller graph for this function:

◆ CompileFunc()

void C4ClientPlayerInfos::CompileFunc ( StdCompiler pComp)

Definition at line 636 of file C4PlayerInfo.cpp.

637 {
638  bool deserializing = pComp->isDeserializer();
639  if (deserializing) Clear();
640  pComp->Value(mkNamingAdapt(iClientID, "ID", C4ClientIDUnknown));
641 
642  // Flags
643  StdBitfieldEntry<uint32_t> Entries[] =
644  {
645  { "AddPlayers", CIF_AddPlayers },
646  { "Updated", CIF_Updated },
647  { "Initial", CIF_Initial },
648  { "Developer", CIF_Developer },
649 
650  { nullptr, 0 }
651  };
652  pComp->Value(mkNamingAdapt(mkBitfieldAdapt(dwFlags, Entries), "Flags", 0u));
653 
654  pComp->Value(mkNamingCountAdapt<int32_t>(iPlayerCount, "Player"));
655  if (iPlayerCount < 0 || iPlayerCount > C4MaxPlayer)
656  { pComp->excCorrupt("player count out of range"); return; }
657  // Grow list, if necessary
658  if (deserializing && iPlayerCount > iPlayerCapacity)
659  {
660  GrowList(iPlayerCount - iPlayerCapacity);
661  ZeroMem(ppPlayers, sizeof(*ppPlayers) * iPlayerCount);
662  }
663  // Compile
664  pComp->Value(mkNamingAdapt(mkArrayAdaptMap(ppPlayers, iPlayerCount, mkPtrAdaptNoNull<C4PlayerInfo>), "Player"));
665  // Force specialization
666  mkPtrAdaptNoNull<C4PlayerInfo>(*ppPlayers);
667 }
const int32_t C4ClientIDUnknown
Definition: C4Client.h:24
const int32_t C4MaxPlayer
Definition: C4Player.h:37
std::enable_if< std::is_pod< T >::value >::type ZeroMem(T *lpMem, size_t dwSize)
Definition: Standard.h:60
StdBitfieldAdapt< T > mkBitfieldAdapt(T &rVal, const StdBitfieldEntry< T > *pNames)
Definition: StdAdaptors.h:985
StdArrayAdapt< T, M > mkArrayAdaptMap(T *pArray, int iSize, M &&map)
Definition: StdAdaptors.h:340
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
Definition: StdAdaptors.h:883
void excCorrupt(const char *szMessage,...)
Definition: StdCompiler.h:249
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53

References C4ClientIDUnknown, C4MaxPlayer, Clear(), StdCompiler::excCorrupt(), StdCompiler::isDeserializer(), mkArrayAdaptMap(), mkBitfieldAdapt(), mkNamingAdapt(), StdCompiler::Value(), and ZeroMem().

Here is the call graph for this function:

◆ GetClientID()

int32_t C4ClientPlayerInfos::GetClientID ( ) const
inline

Definition at line 257 of file C4PlayerInfo.h.

257 { return iClientID; } // get target client ID

Referenced by C4PlayerInfoList::AddInfo(), C4PlayerInfoList::GetActivePlayerNames(), C4Network2Players::GetLocalPlayerInfoPacket(), C4PlayerInfoList::GetPlayerInfoByID(), C4Network2Players::HandlePlayerInfo(), C4Network2Players::HandlePlayerInfoUpdRequest(), C4Network2Players::OnStatusGoReached(), C4MessageInput::ProcessCommand(), C4PlayerInfoList::RecreatePlayers(), and C4PlayerInfoList::SetAsRestoreInfos().

Here is the caller graph for this function:

◆ GetFlaggedPlayerCount()

int32_t C4ClientPlayerInfos::GetFlaggedPlayerCount ( DWORD  dwFlag) const

Definition at line 557 of file C4PlayerInfo.cpp.

558 {
559  // check all players
560  int32_t iCount = 0;
561  int32_t i = iPlayerCount; C4PlayerInfo **ppCurrPlrInfo = ppPlayers;
562  while (i--) if ((*ppCurrPlrInfo++)->GetFlags() | dwFlag)
563  ++iCount;
564  // return number of matching infos
565  return iCount;
566 }

◆ GetJoinedPlayerCount()

int32_t C4ClientPlayerInfos::GetJoinedPlayerCount ( ) const

Definition at line 628 of file C4PlayerInfo.cpp.

629 {
630  // count all players with IsJoined()
631  int32_t i = iPlayerCount; int32_t cnt=0; C4PlayerInfo **ppCurrPlrInfo = ppPlayers;
632  while (i--) if ((*ppCurrPlrInfo++)->IsJoined()) ++cnt;
633  return cnt;
634 }

Referenced by C4Network2::OpenVoteDialog(), and C4PlayerInfoList::RecreatePlayers().

Here is the caller graph for this function:

◆ GetPlayerCount()

int32_t C4ClientPlayerInfos::GetPlayerCount ( ) const
inline

◆ GetPlayerInfo() [1/2]

C4PlayerInfo * C4ClientPlayerInfos::GetPlayerInfo ( int32_t  iIndex) const

Definition at line 568 of file C4PlayerInfo.cpp.

569 {
570  // check range
571  if (iIndex<0 || iIndex>=iPlayerCount) return nullptr;
572  // return indexed info
573  return ppPlayers[iIndex];
574 }

Referenced by C4PlayerInfoList::AddInfo(), C4PlayerInfoList::AssignPlayerIDs(), C4PlayerInfoList::AssignTeams(), DisconnectData::CompileFunc(), C4PlayerInfoList::CreateRestoreInfosForJoinedScriptPlayers(), C4PlayerInfoList::FindUnassociatedRestoreInfo(), C4PlayerInfoList::GetActivePlayerCount(), C4PlayerInfoList::GetActivePlayerNames(), C4PlayerInfoList::GetActiveScriptPlayerCount(), C4Network2Players::GetClientChatColor(), C4PlayerInfoList::GetJoinIssuedPlayerCount(), C4PlayerInfoList::GetJoinPendingPlayerCount(), C4PlayerInfoList::GetPrimaryInfoByClientID(), C4Network2Players::HandlePlayerInfoUpdRequest(), C4PlayerInfoList::HasSameTeamPlayers(), C4Network2Reference::InitLocal(), C4Network2Players::JoinLocalPlayer(), C4Network2::LeagueNotifyDisconnect(), C4Network2::LeagueUpdateProcessReply(), C4PlayerInfoList::RecheckAutoGeneratedTeams(), C4PlayerInfoList::RecreatePlayerFiles(), C4PlayerInfoList::RecreatePlayers(), C4PlayerInfoList::RemoveUnassociatedPlayers(), C4PlayerInfoList::ResetLeagueProjectedGain(), C4PlayerInfoList::RestoreSavegameInfos(), C4PlayerInfoList::SetAsRestoreInfos(), C4GameLobby::MainDlg::Start(), and C4PlayerInfoList::UpdatePlayerAttributes().

Here is the caller graph for this function:

◆ GetPlayerInfo() [2/2]

C4PlayerInfo * C4ClientPlayerInfos::GetPlayerInfo ( int32_t  iIndex,
C4PlayerType  eType 
) const

Definition at line 576 of file C4PlayerInfo.cpp.

577 {
578  // get indexed matching info
579  for (int32_t iCheck=0; iCheck<iPlayerCount; ++iCheck)
580  {
581  C4PlayerInfo *pNfo = ppPlayers[iCheck];
582  if (pNfo->GetType() == eType)
583  if (!iIndex--)
584  return pNfo;
585  }
586  // nothing found
587  return nullptr;
588 }
C4PlayerType GetType() const
Definition: C4PlayerInfo.h:152

References C4PlayerInfo::GetType().

Here is the call graph for this function:

◆ GetPlayerInfoByID()

C4PlayerInfo * C4ClientPlayerInfos::GetPlayerInfoByID ( int32_t  id) const

Definition at line 590 of file C4PlayerInfo.cpp.

591 {
592  // check all infos
593  int32_t i = iPlayerCount; C4PlayerInfo **ppCurrPlrInfo = ppPlayers;
594  while (i--)
595  {
596  if ((*ppCurrPlrInfo)->GetID() == id) return *ppCurrPlrInfo;
597  ++ppCurrPlrInfo;
598  }
599  // none matched
600  return nullptr;
601 }

Referenced by C4Network2::LeagueUpdateProcessReply(), and C4MessageInput::ProcessCommand().

Here is the caller graph for this function:

◆ GetPlayerInfoByRes()

C4PlayerInfo * C4ClientPlayerInfos::GetPlayerInfoByRes ( int32_t  idResID) const

Definition at line 603 of file C4PlayerInfo.cpp.

604 {
605  int32_t i = iPlayerCount; C4PlayerInfo **ppCurrPlrInfo = ppPlayers;
606  C4Network2Res *pRes;
607  while (i--)
608  {
609  if ((pRes = (*ppCurrPlrInfo)->GetRes()))
610  if (pRes->getResID() == idResID)
611  // only if the player is actually using the resource
612  if ((*ppCurrPlrInfo)->IsUsingPlayerFile())
613  return *ppCurrPlrInfo;
614  ++ppCurrPlrInfo;
615  }
616  return nullptr;
617 }
int32_t getResID() const

References C4Network2Res::getResID().

Referenced by C4Network2Players::HandlePlayerInfoUpdRequest().

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

◆ GrabMergeFrom()

void C4ClientPlayerInfos::GrabMergeFrom ( C4ClientPlayerInfos rFrom)

Definition at line 482 of file C4PlayerInfo.cpp.

483 {
484  // anything to grab?
485  if (!rFrom.iPlayerCount) return;
486  // any previous players to copy?
487  if (iPlayerCount)
488  {
489  // buffer sufficient?
490  if (iPlayerCount + rFrom.iPlayerCount > iPlayerCapacity)
491  GrowList(rFrom.iPlayerCount);
492  // merge into new buffer
493  memcpy(ppPlayers + iPlayerCount, rFrom.ppPlayers, rFrom.iPlayerCount * sizeof(C4PlayerInfo *));
494  iPlayerCount += rFrom.iPlayerCount;
495  rFrom.iPlayerCount = rFrom.iPlayerCapacity = 0;
496  delete [] rFrom.ppPlayers; rFrom.ppPlayers = nullptr;
497  }
498  else
499  {
500  // no own players: take over buffer of pFrom
501  if (ppPlayers) delete [] ppPlayers;
502  ppPlayers = rFrom.ppPlayers; rFrom.ppPlayers = nullptr;
503  iPlayerCount = rFrom.iPlayerCount; rFrom.iPlayerCount = 0;
504  iPlayerCapacity = rFrom.iPlayerCapacity; rFrom.iPlayerCapacity = 0;
505  }
506 }

◆ HasUnjoinedPlayers()

bool C4ClientPlayerInfos::HasUnjoinedPlayers ( ) const

Definition at line 619 of file C4PlayerInfo.cpp.

620 {
621  // check all players
622  int32_t i = iPlayerCount; C4PlayerInfo **ppCurrPlrInfo = ppPlayers;
623  while (i--) if (!(*ppCurrPlrInfo++)->HasJoined()) return true;
624  // all joined
625  return false;
626 }

Referenced by C4Network2Players::OnStatusGoReached().

Here is the caller graph for this function:

◆ IsAddPacket()

bool C4ClientPlayerInfos::IsAddPacket ( ) const
inline

Definition at line 260 of file C4PlayerInfo.h.

260 { return !!(dwFlags & CIF_AddPlayers); } // return whether players are to be added to the current list (otherwise overwrite)

Referenced by C4PlayerInfoList::AddInfo(), and C4Network2Players::HandlePlayerInfoUpdRequest().

Here is the caller graph for this function:

◆ IsDeveloperPacket()

bool C4ClientPlayerInfos::IsDeveloperPacket ( ) const
inline

Definition at line 262 of file C4PlayerInfo.h.

262 { return !!(dwFlags & CIF_Developer); } // returns whether packet was created by a developer host - client side check only!

◆ IsInitialPacket()

bool C4ClientPlayerInfos::IsInitialPacket ( ) const
inline

Definition at line 261 of file C4PlayerInfo.h.

261 { return !!(dwFlags & CIF_Initial); } // returns whether this packet was sent as the first local-join packet

Referenced by C4Network2Players::HandlePlayerInfoUpdRequest().

Here is the caller graph for this function:

◆ IsUpdated()

bool C4ClientPlayerInfos::IsUpdated ( )
inline

Definition at line 245 of file C4PlayerInfo.h.

245 { return !!(dwFlags & CIF_Updated); }

Referenced by C4Network2Players::SendUpdatedPlayers().

Here is the caller graph for this function:

◆ LoadResources()

void C4ClientPlayerInfos::LoadResources ( )

Definition at line 669 of file C4PlayerInfo.cpp.

670 {
671  // load for all players
672  int32_t i = iPlayerCount; C4PlayerInfo **ppCurrPlrInfo = ppPlayers;
673  while (i--) (*ppCurrPlrInfo++)->LoadResource();
674 }

◆ operator=()

C4ClientPlayerInfos & C4ClientPlayerInfos::operator= ( const C4ClientPlayerInfos rCopy)

Definition at line 444 of file C4PlayerInfo.cpp.

445 {
446  Clear();
447  // copy fields
448  iClientID = rCopy.iClientID;
449  if ((iPlayerCount = rCopy.iPlayerCount))
450  {
451  // copy player infos
452  ppPlayers = new C4PlayerInfo *[iPlayerCapacity = rCopy.iPlayerCapacity];
453  int32_t i = iPlayerCount;
454  C4PlayerInfo **ppCurrPlrInfo = ppPlayers, **ppSrcPlrInfo = rCopy.ppPlayers;
455  while (i--) *ppCurrPlrInfo++ = new C4PlayerInfo(**ppSrcPlrInfo++);
456  }
457  // no players
458  else
459  {
460  ppPlayers = nullptr;
461  iPlayerCapacity = 0;
462  }
463  // misc fields
464  dwFlags = rCopy.dwFlags;
465  return *this;
466 }

References Clear().

Here is the call graph for this function:

◆ RemoveIndexedInfo()

void C4ClientPlayerInfos::RemoveIndexedInfo ( int32_t  iAtIndex)

Definition at line 516 of file C4PlayerInfo.cpp.

517 {
518  // bounds check
519  if (iAtIndex<0 || iAtIndex>=iPlayerCount) return;
520  // del player info at index
521  delete ppPlayers[iAtIndex];
522  // move down last index (may self-assign a ptr)
523  ppPlayers[iAtIndex] = ppPlayers[--iPlayerCount];
524 }

Referenced by C4PlayerInfoList::AssignPlayerIDs(), C4Network2Players::HandlePlayerInfoUpdRequest(), C4Network2Players::JoinLocalPlayer(), RemoveInfo(), and C4PlayerInfoList::SetAsRestoreInfos().

Here is the caller graph for this function:

◆ RemoveInfo()

void C4ClientPlayerInfos::RemoveInfo ( int32_t  idPlr)

Definition at line 526 of file C4PlayerInfo.cpp.

527 {
528  // check all infos; remove the one that matches
529  int32_t i = 0; C4PlayerInfo **ppCurrPlrInfo = ppPlayers;
530  while (i < iPlayerCount)
531  {
532  if ((*ppCurrPlrInfo)->GetID() == idPlr)
533  {
535  return;
536  }
537  ++ppCurrPlrInfo; ++i;
538  }
539  // none matched
540  return;
541 }
void RemoveIndexedInfo(int32_t iAtIndex)

References RemoveIndexedInfo().

Here is the call graph for this function:

◆ ResetAdd()

void C4ClientPlayerInfos::ResetAdd ( )
inline

Definition at line 248 of file C4PlayerInfo.h.

248 { dwFlags &= ~CIF_AddPlayers; }

Referenced by C4PlayerInfoList::AddInfo().

Here is the caller graph for this function:

◆ ResetUpdated()

void C4ClientPlayerInfos::ResetUpdated ( )
inline

Definition at line 246 of file C4PlayerInfo.h.

246 { dwFlags &= ~CIF_Updated; }

Referenced by C4Network2Players::ResetUpdatedPlayers(), and C4Network2Players::SendUpdatedPlayers().

Here is the caller graph for this function:

◆ SetAdd()

void C4ClientPlayerInfos::SetAdd ( )
inline

Definition at line 247 of file C4PlayerInfo.h.

247 { dwFlags |= CIF_AddPlayers; }

◆ SetUpdated()

void C4ClientPlayerInfos::SetUpdated ( )
inline

Definition at line 244 of file C4PlayerInfo.h.

244 { dwFlags |= CIF_Updated; }

Referenced by C4Network2::LeagueUpdateProcessReply(), C4TeamList::ReassignAllTeams(), C4TeamList::RecheckTeams(), C4PlayerInfoList::ResetLeagueProjectedGain(), and C4PlayerInfoList::UpdatePlayerAttributes().

Here is the caller graph for this function:

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