OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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::C4ClientPlayerInfos ( const char *  szJoinFilenames = nullptr,
bool  fAdd = false,
C4PlayerInfo pAddInfo = nullptr 
)

Definition at line 372 of file C4PlayerInfo.cpp.

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

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+1];
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 }
bool SGetModule(const char *szList, int iIndex, char *sTarget, int iSize)
Definition: Standard.cpp:511
C4Config Config
Definition: C4Config.cpp:833
const char * SSearch(const char *szString, const char *szIndex)
Definition: Standard.cpp:341
#define _MAX_PATH
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
const char * GetRegistrationData(const char *strField)
Definition: C4Config.h:281
bool isNetwork() const
Definition: C4GameControl.h:97
C4GameControl Control
int SModuleCount(const char *szList)
Definition: Standard.cpp:589
int32_t ClientID() const
bool LoadFromLocalFile(const char *szFilename)
bool Log(const char *szMessage)
Definition: C4Log.cpp:192
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

Here is the call graph for this function:

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

Definition at line 233 of file C4PlayerInfo.h.

References Clear().

233 { Clear(); } // dtor

Here is the call graph for this function:

Member Function Documentation

void C4ClientPlayerInfos::AddInfo ( C4PlayerInfo pAddInfo)

Definition at line 508 of file C4PlayerInfo.cpp.

Referenced by C4PlayerInfoList::CreateRestoreInfosForJoinedScriptPlayers().

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

Here is the caller graph for this function:

void C4ClientPlayerInfos::Clear ( )

Definition at line 469 of file C4PlayerInfo.cpp.

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

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 }

Here is the caller graph for this function:

void C4ClientPlayerInfos::CompileFunc ( StdCompiler pComp)

Definition at line 636 of file C4PlayerInfo.cpp.

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

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 }
Definition: StdAdaptors.h:850
void excCorrupt(const char *szMessage,...)
Definition: StdCompiler.h:249
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
StdBitfieldAdapt< T > mkBitfieldAdapt(T &rVal, const StdBitfieldEntry< T > *pNames)
Definition: StdAdaptors.h:953
void Value(const T &rStruct)
Definition: StdCompiler.h:161
const int32_t C4ClientIDUnknown
Definition: C4Client.h:24
const int32_t C4MaxPlayer
Definition: C4Player.h:37
virtual bool isDeserializer()
Definition: StdCompiler.h:53
std::enable_if< std::is_pod< T >::value >::type ZeroMem(T *lpMem, size_t dwSize)
Definition: Standard.h:60
StdArrayAdapt< T, M > mkArrayAdaptMap(T *pArray, int iSize, M &&map)
Definition: StdAdaptors.h:313

Here is the call graph for this function:

int32_t C4ClientPlayerInfos::GetClientID ( ) const
inline

Definition at line 257 of file C4PlayerInfo.h.

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

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

Here is the caller graph for this function:

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 }
int32_t C4ClientPlayerInfos::GetJoinedPlayerCount ( ) const

Definition at line 628 of file C4PlayerInfo.cpp.

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

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 }

Here is the caller graph for this function:

int32_t C4ClientPlayerInfos::GetPlayerCount ( ) const
inline

Definition at line 251 of file C4PlayerInfo.h.

Referenced by C4PlayerInfoList::AssignPlayerIDs(), C4PlayerInfoList::GetActivePlayerCount(), C4PlayerInfoList::GetActivePlayerNames(), C4PlayerInfoList::GetActiveScriptPlayerCount(), C4PlayerInfoList::GetJoinIssuedPlayerCount(), C4PlayerInfoList::GetJoinPendingPlayerCount(), C4Network2Players::JoinLocalPlayer(), C4Network2::OpenVoteDialog(), C4PlayerInfoList::RecreatePlayers(), and C4PlayerInfoList::SetAsRestoreInfos().

251 { return iPlayerCount; } // get number of player infos available

Here is the caller graph for this function:

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

Definition at line 576 of file C4PlayerInfo.cpp.

References C4PlayerInfo::GetType().

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

Here is the call graph for this function:

C4PlayerInfo * C4ClientPlayerInfos::GetPlayerInfoByID ( int32_t  id) const

Definition at line 590 of file C4PlayerInfo.cpp.

Referenced by C4MessageInput::ProcessCommand().

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 }

Here is the caller graph for this function:

C4PlayerInfo * C4ClientPlayerInfos::GetPlayerInfoByRes ( int32_t  idResID) const

Definition at line 603 of file C4PlayerInfo.cpp.

References C4Network2Res::getResID().

Referenced by C4Network2Players::HandlePlayerInfoUpdRequest().

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ClientPlayerInfos::GrabMergeFrom ( C4ClientPlayerInfos rFrom)

Definition at line 482 of file C4PlayerInfo.cpp.

Referenced by C4PlayerInfoList::AddInfo().

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 }

Here is the caller graph for this function:

bool C4ClientPlayerInfos::HasUnjoinedPlayers ( ) const

Definition at line 619 of file C4PlayerInfo.cpp.

Referenced by C4Network2Players::OnStatusGoReached().

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 }

Here is the caller graph for this function:

bool C4ClientPlayerInfos::IsAddPacket ( ) const
inline

Definition at line 260 of file C4PlayerInfo.h.

Referenced by C4PlayerInfoList::AddInfo().

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

Here is the caller graph for this function:

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!
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
bool C4ClientPlayerInfos::IsUpdated ( )
inline

Definition at line 245 of file C4PlayerInfo.h.

Referenced by C4Network2Players::SendUpdatedPlayers().

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

Here is the caller graph for this function:

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 }
C4ClientPlayerInfos & C4ClientPlayerInfos::operator= ( const C4ClientPlayerInfos rCopy)

Definition at line 444 of file C4PlayerInfo.cpp.

References Clear().

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 }

Here is the call graph for this function:

void C4ClientPlayerInfos::RemoveIndexedInfo ( int32_t  iAtIndex)

Definition at line 516 of file C4PlayerInfo.cpp.

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

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 }

Here is the caller graph for this function:

void C4ClientPlayerInfos::RemoveInfo ( int32_t  idPlr)

Definition at line 526 of file C4PlayerInfo.cpp.

References RemoveIndexedInfo().

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)

Here is the call graph for this function:

void C4ClientPlayerInfos::ResetAdd ( )
inline

Definition at line 248 of file C4PlayerInfo.h.

Referenced by C4PlayerInfoList::AddInfo().

248 { dwFlags &= ~CIF_AddPlayers; }

Here is the caller graph for this function:

void C4ClientPlayerInfos::ResetUpdated ( )
inline

Definition at line 246 of file C4PlayerInfo.h.

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

246 { dwFlags &= ~CIF_Updated; }

Here is the caller graph for this function:

void C4ClientPlayerInfos::SetAdd ( )
inline

Definition at line 247 of file C4PlayerInfo.h.

247 { dwFlags |= CIF_AddPlayers; }
void C4ClientPlayerInfos::SetUpdated ( )
inline

Definition at line 244 of file C4PlayerInfo.h.

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

244 { dwFlags |= CIF_Updated; }

Here is the caller graph for this function:


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