OpenClonk
C4PlayerInfoList Class Reference

#include <C4PlayerInfo.h>

Public Member Functions

 C4PlayerInfoList ()
 
 C4PlayerInfoList (const C4PlayerInfoList &rCpy)
 
 ~C4PlayerInfoList ()
 
C4PlayerInfoListoperator= (const C4PlayerInfoList &rCpy)
 
void Clear ()
 
bool DoPlayerInfoUpdate (C4ClientPlayerInfos *pUpdate)
 
bool DoLocalNonNetworkPlayerJoin (const char *szPlayerFile)
 
bool DoLocalNonNetworkPlayerInfoUpdate (C4ClientPlayerInfos *pUpdate)
 
bool AssignPlayerIDs (C4ClientPlayerInfos *pNewClientInfo)
 
void AssignTeams (C4ClientPlayerInfos *pNewClientInfo, bool fByHost)
 
void RecheckAutoGeneratedTeams ()
 
C4ClientPlayerInfosAddInfo (C4ClientPlayerInfos *pNewClientInfo)
 
void ResolvePlayerAttributeConflicts (C4ClientPlayerInfos *pSecPacket)
 
void UpdatePlayerAttributes (C4ClientPlayerInfos *pForInfo, bool fResolveConflicts)
 
void UpdatePlayerAttributes ()
 
int32_t GetInfoCount () const
 
C4ClientPlayerInfosGetIndexedInfo (int32_t iIndex) const
 
C4ClientPlayerInfos ** GetInfoPtrByClientID (int32_t iClientID) const
 
C4ClientPlayerInfosGetInfoByClientID (int32_t iClientID) const
 
C4PlayerInfoGetPlayerInfoByIndex (int32_t index) const
 
C4PlayerInfoGetPlayerInfoByID (int32_t id) const
 
C4PlayerInfoGetPlayerInfoByID (int32_t id, int32_t *pidClient) const
 
C4ClientPlayerInfosGetClientInfoByPlayerID (int32_t id) const
 
C4PlayerInfoGetPlayerInfoBySavegameID (int32_t id) const
 
C4PlayerInfoGetNextPlayerInfoByID (int32_t id) const
 
C4PlayerInfoGetActivePlayerInfoByName (const char *szName)
 
int32_t GetPlayerCount () const
 
int32_t GetJoinIssuedPlayerCount () const
 
int32_t GetJoinPendingPlayerCount () const
 
int32_t GetActivePlayerCount (bool fCountInvisible) const
 
StdStrBuf GetActivePlayerNames (bool fCountInvisible, int32_t iAtClientID=-1) const
 
int32_t GetActiveScriptPlayerCount (bool fCountSavegameResumes, bool fCountInvisible) const
 
C4PlayerInfoGetPrimaryInfoByClientID (int32_t iClientID) const
 
C4PlayerInfoFindSavegameResumePlayerInfo (const C4PlayerInfo *pMatchInfo, MatchingLevel mlMatchStart, MatchingLevel mlMatchEnd) const
 
bool HasSameTeamPlayers (int32_t iClient1, int32_t iClient2) const
 
C4PlayerInfoFindUnassociatedRestoreInfo (const C4PlayerInfoList &rRestoreInfoList)
 
void RemoveInfo (C4ClientPlayerInfos **ppRemoveInfo)
 
bool Load (C4Group &hGroup, const char *szFromFile, class C4LangStringTable *pLang=nullptr)
 
bool Save (C4Group &hGroup, const char *szToFile)
 
void SetIDCounter (int32_t idNewCounter)
 
int32_t GetIDCounter ()
 
void FixIDCounter ()
 
bool InitLocal ()
 
bool LocalJoinUnjoinedPlayersInQueue ()
 
int32_t GetStartupCount ()
 
void CreateRestoreInfosForJoinedScriptPlayers (C4PlayerInfoList &rSavegamePlayers)
 
bool RecreatePlayers (C4ValueNumbers *)
 
bool RecreatePlayerFiles ()
 
bool RestoreSavegameInfos (C4PlayerInfoList &rSavegamePlayers)
 
bool SetAsRestoreInfos (C4PlayerInfoList &rFromPlayers, bool fSaveUserPlrs, bool fSaveScriptPlrs, bool fSetUserPlrRefToLocalGroup, bool fSetScriptPlrRefToLocalGroup)
 
void RemoveUnassociatedPlayers (C4PlayerInfoList &rSavegamePlayers)
 
int32_t GetFreePlayerSlotCount ()
 
void ResetLeagueProjectedGain (bool fSetUpdated)
 
void LoadResources ()
 
void CompileFunc (StdCompiler *pComp)
 

Detailed Description

Definition at line 305 of file C4PlayerInfo.h.

Constructor & Destructor Documentation

◆ C4PlayerInfoList() [1/2]

C4PlayerInfoList::C4PlayerInfoList ( )
default

◆ C4PlayerInfoList() [2/2]

C4PlayerInfoList::C4PlayerInfoList ( const C4PlayerInfoList rCpy)

Definition at line 681 of file C4PlayerInfo.cpp.

681  : iClientCount(rCpy.iClientCount), iClientCapacity(rCpy.iClientCapacity),
682  ppClients(nullptr), iLastPlayerID(rCpy.iLastPlayerID)
683 {
684  // copy client info vector
685  if (rCpy.ppClients)
686  {
687  ppClients = new C4ClientPlayerInfos*[iClientCapacity];
688  C4ClientPlayerInfos **ppInfo = ppClients, **ppCpy = rCpy.ppClients;
689  int32_t i = iClientCount;
690  while (i--) *ppInfo++ = new C4ClientPlayerInfos(**ppCpy++);
691  }
692 }

◆ ~C4PlayerInfoList()

C4PlayerInfoList::~C4PlayerInfoList ( )
inline

Definition at line 321 of file C4PlayerInfo.h.

321 { Clear(); } // dtor

References Clear().

Here is the call graph for this function:

Member Function Documentation

◆ AddInfo()

C4ClientPlayerInfos * C4PlayerInfoList::AddInfo ( C4ClientPlayerInfos pNewClientInfo)

Definition at line 884 of file C4PlayerInfo.cpp.

885 {
886  assert(pNewClientInfo);
887  // caution: also called for RestorePlayerInfos-list
888  // host: reserve new IDs for all players
889  // client: all IDs should be assigned already by host
890  if (::Network.isHost() || !::Network.isEnabled())
891  {
892  if (!AssignPlayerIDs(pNewClientInfo) && pNewClientInfo->IsAddPacket())
893  {
894  // no players could be added (probably MaxPlayer)
895  delete pNewClientInfo;
896  return nullptr;
897  }
898  }
899  // ensure all teams specified in the list exist (this should be done for savegame teams as well)
900  C4PlayerInfo *pInfo; int32_t i=0;
901  while ((pInfo = pNewClientInfo->GetPlayerInfo(i++)))
902  {
903  int32_t idTeam = pInfo->GetTeam();
904  if (idTeam) Game.Teams.GetGenerateTeamByID(idTeam);
905  }
906  // add info for client; overwriting or appending to existing info if necessary
907  // try to find existing data of same client
908  C4ClientPlayerInfos **ppExistingInfo = GetInfoPtrByClientID(pNewClientInfo->GetClientID());
909  if (ppExistingInfo)
910  {
911  // info exists: append to it?
912  if (pNewClientInfo->IsAddPacket())
913  {
914  (*ppExistingInfo)->GrabMergeFrom(*pNewClientInfo);
915  // info added: remove unused class
916  delete pNewClientInfo;
917  // assign existing info for further usage in this fn
918  return pNewClientInfo = *ppExistingInfo;
919  }
920  // no add packet: overwrite current info
921  delete *ppExistingInfo;
922  return *ppExistingInfo = pNewClientInfo;
923  }
924  // no existing info: add it directly
925  pNewClientInfo->ResetAdd();
926  // may need to grow list (vector) for that
927  if (iClientCount >= iClientCapacity) GrowList(4);
928  ppClients[iClientCount++] = pNewClientInfo;
929  // done; return actual info
930  return pNewClientInfo;
931 }
C4Game Game
Definition: C4Globals.cpp:52
C4Network2 Network
Definition: C4Globals.cpp:53
int32_t GetClientID() const
Definition: C4PlayerInfo.h:257
C4PlayerInfo * GetPlayerInfo(int32_t iIndex) const
bool IsAddPacket() const
Definition: C4PlayerInfo.h:260
C4TeamList & Teams
Definition: C4Game.h:70
bool isEnabled() const
Definition: C4Network2.h:203
bool isHost() const
Definition: C4Network2.h:209
int32_t GetTeam() const
Definition: C4PlayerInfo.h:195
C4ClientPlayerInfos ** GetInfoPtrByClientID(int32_t iClientID) const
bool AssignPlayerIDs(C4ClientPlayerInfos *pNewClientInfo)
C4Team * GetGenerateTeamByID(int32_t iID)
Definition: C4Teams.cpp:390

References AssignPlayerIDs(), Game, C4ClientPlayerInfos::GetClientID(), C4TeamList::GetGenerateTeamByID(), GetInfoPtrByClientID(), C4ClientPlayerInfos::GetPlayerInfo(), C4PlayerInfo::GetTeam(), C4ClientPlayerInfos::IsAddPacket(), C4Network2::isEnabled(), C4Network2::isHost(), Network, C4ClientPlayerInfos::ResetAdd(), and C4Game::Teams.

Referenced by C4Network2Players::HandlePlayerInfo(), and InitLocal().

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

◆ AssignPlayerIDs()

bool C4PlayerInfoList::AssignPlayerIDs ( C4ClientPlayerInfos pNewClientInfo)

Definition at line 832 of file C4PlayerInfo.cpp.

833 {
834  // assign player IDs to those player infos without
835  C4PlayerInfo *pPlrInfo; int32_t i=0;
836  while ((pPlrInfo = pNewClientInfo->GetPlayerInfo(i++)))
837  if (!pPlrInfo->GetID())
838  {
839  // are there still any player slots free?
840  if (GetFreePlayerSlotCount()<1)
841  {
842  // nope - then deny this join!
843  Log(FormatString(LoadResStr("IDS_MSG_TOOMANYPLAYERS"), (int)Game.Parameters.MaxPlayers).getData());
844  pNewClientInfo->RemoveIndexedInfo(--i);
845  continue;
846  }
847  // Join OK; grant an ID
848  pPlrInfo->SetID(++iLastPlayerID);
849  }
850  // return whether any join remains
851  return !!pNewClientInfo->GetPlayerCount();
852 }
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
bool Log(const char *szMessage)
Definition: C4Log.cpp:204
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
void RemoveIndexedInfo(int32_t iAtIndex)
int32_t GetPlayerCount() const
Definition: C4PlayerInfo.h:251
C4GameParameters & Parameters
Definition: C4Game.h:67
void SetID(int32_t iToID)
Definition: C4PlayerInfo.h:114
int32_t GetID() const
Definition: C4PlayerInfo.h:194
int32_t GetFreePlayerSlotCount()
const char * getData() const
Definition: StdBuf.h:442

References FormatString(), Game, StdStrBuf::getData(), GetFreePlayerSlotCount(), C4PlayerInfo::GetID(), C4ClientPlayerInfos::GetPlayerCount(), C4ClientPlayerInfos::GetPlayerInfo(), LoadResStr(), Log(), C4GameParameters::MaxPlayers, C4Game::Parameters, C4ClientPlayerInfos::RemoveIndexedInfo(), and C4PlayerInfo::SetID().

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

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

◆ AssignTeams()

void C4PlayerInfoList::AssignTeams ( C4ClientPlayerInfos pNewClientInfo,
bool  fByHost 
)

Definition at line 860 of file C4PlayerInfo.cpp.

861 {
862  if (!Game.Teams.IsMultiTeams()) return;
863  // assign any unset teams (host/standalone only - fByHost determines whether the packet came from the host)
864  C4PlayerInfo *pPlrInfo; int32_t i=0;
865  while ((pPlrInfo = pNewClientInfo->GetPlayerInfo(i++)))
866  Game.Teams.RecheckPlayerInfoTeams(*pPlrInfo, fByHost);
867 }
bool IsMultiTeams() const
Definition: C4Teams.h:162
bool RecheckPlayerInfoTeams(C4PlayerInfo &rNewJoin, bool fByHost)
Definition: C4Teams.cpp:463

References Game, C4ClientPlayerInfos::GetPlayerInfo(), C4TeamList::IsMultiTeams(), C4TeamList::RecheckPlayerInfoTeams(), and C4Game::Teams.

Referenced by DoLocalNonNetworkPlayerInfoUpdate(), C4Network2Players::HandlePlayerInfoUpdRequest(), and InitLocal().

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

◆ Clear()

void C4PlayerInfoList::Clear ( )

Definition at line 712 of file C4PlayerInfo.cpp.

713 {
714  // delete client infos
715  C4ClientPlayerInfos **ppInfo = ppClients; int32_t i=iClientCount;
716  while (i--) delete *ppInfo++;
717  // clear client infos
718  delete [] ppClients; ppClients = nullptr;
719  iClientCount = iClientCapacity = 0;
720  // reset player ID counter
721  iLastPlayerID = 0;
722 }

Referenced by C4GameParameters::Clear(), CompileFunc(), C4Game::InitPlayers(), Load(), operator=(), and ~C4PlayerInfoList().

Here is the caller graph for this function:

◆ CompileFunc()

void C4PlayerInfoList::CompileFunc ( StdCompiler pComp)

Definition at line 1732 of file C4PlayerInfo.cpp.

1733 {
1734  bool deserializing = pComp->isDeserializer();
1735  if (deserializing) Clear();
1736  // skip compiling if there is nothing to compile (cosmentics)
1737  if (!deserializing && pComp->hasNaming() && iLastPlayerID == 0 && iClientCount == 0)
1738  return;
1739  // header
1740  pComp->Value(mkNamingAdapt(iLastPlayerID, "LastPlayerID", 0));
1741  // client count
1742  int32_t iTemp = iClientCount;
1743  pComp->Value(mkNamingCountAdapt<int32_t>(iTemp, "Client"));
1744  if (iTemp < 0 || iTemp > C4MaxClient)
1745  { pComp->excCorrupt("client count out of range"); return; }
1746  // grow list
1747  if (deserializing)
1748  {
1749  if (iTemp > iClientCapacity) GrowList(iTemp - iClientCapacity);
1750  iClientCount = iTemp;
1751  ZeroMem(ppClients, sizeof(*ppClients) * iClientCount);
1752  }
1753  // client packets
1754  pComp->Value(
1755  mkNamingAdapt(
1756  mkArrayAdaptMap(ppClients, iClientCount, mkPtrAdaptNoNull<C4ClientPlayerInfos>),
1757  "Client"));
1758  // force compiler to specialize
1759  mkPtrAdaptNoNull<C4ClientPlayerInfos>(*ppClients);
1760 }
const int32_t C4MaxClient
Definition: C4Player.h:38
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:340
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
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
virtual bool hasNaming()
Definition: StdCompiler.h:58

References C4MaxClient, Clear(), StdCompiler::excCorrupt(), StdCompiler::hasNaming(), StdCompiler::isDeserializer(), mkArrayAdaptMap(), mkNamingAdapt(), StdCompiler::Value(), and ZeroMem().

Here is the call graph for this function:

◆ CreateRestoreInfosForJoinedScriptPlayers()

void C4PlayerInfoList::CreateRestoreInfosForJoinedScriptPlayers ( C4PlayerInfoList rSavegamePlayers)

Definition at line 1325 of file C4PlayerInfo.cpp.

1326 {
1327  // create matching script player joins for all script playeers in restore info
1328  // Just copy their infos to the first client
1329  int32_t i;
1330  C4ClientPlayerInfos *pHostInfo = GetIndexedInfo(0);
1331  for (i=0; i<rSavegamePlayers.GetInfoCount(); ++i)
1332  {
1333  C4ClientPlayerInfos *pkInfo = rSavegamePlayers.GetIndexedInfo(i);
1334  int32_t j=0; C4PlayerInfo *pInfo;
1335  while ((pInfo = pkInfo->GetPlayerInfo(j++)))
1336  if (pInfo->GetType() == C4PT_Script)
1337  {
1338  // safety
1339  C4PlayerInfo *pRejoinInfo;
1340  if ((pRejoinInfo = GetPlayerInfoBySavegameID(pInfo->GetID())))
1341  {
1342  LogF("Warning: User player %s takes over script player %s!", pRejoinInfo->GetName(), pInfo->GetName());
1343  continue;
1344  }
1345  if (!pHostInfo)
1346  {
1347  LogF("Error restoring savegame script players: No host player infos to add to!");
1348  continue;
1349  }
1350  // generate takeover info
1351  pRejoinInfo = new C4PlayerInfo(*pInfo);
1352  pRejoinInfo->SetAssociatedSavegamePlayer(pInfo->GetID());
1353  pHostInfo->AddInfo(pRejoinInfo);
1354  }
1355  }
1356  // teams must recognize the change
1358 }
@ C4PT_Script
Definition: C4Constants.h:155
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:262
void AddInfo(C4PlayerInfo *pAddInfo)
void SetAssociatedSavegamePlayer(int32_t aidSavegamePlayer)
Definition: C4PlayerInfo.h:124
const char * GetName() const
Definition: C4PlayerInfo.h:157
C4PlayerType GetType() const
Definition: C4PlayerInfo.h:152
C4ClientPlayerInfos * GetIndexedInfo(int32_t iIndex) const
Definition: C4PlayerInfo.h:358
C4PlayerInfo * GetPlayerInfoBySavegameID(int32_t id) const
int32_t GetInfoCount() const
Definition: C4PlayerInfo.h:357
void RecheckPlayers()
Definition: C4Teams.cpp:663

References C4ClientPlayerInfos::AddInfo(), C4PT_Script, Game, C4PlayerInfo::GetID(), GetIndexedInfo(), GetInfoCount(), C4PlayerInfo::GetName(), C4ClientPlayerInfos::GetPlayerInfo(), GetPlayerInfoBySavegameID(), C4PlayerInfo::GetType(), LogF(), C4TeamList::RecheckPlayers(), C4PlayerInfo::SetAssociatedSavegamePlayer(), and C4Game::Teams.

Referenced by C4Network2Players::Init(), and InitLocal().

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

◆ DoLocalNonNetworkPlayerInfoUpdate()

bool C4PlayerInfoList::DoLocalNonNetworkPlayerInfoUpdate ( C4ClientPlayerInfos pUpdate)

Definition at line 762 of file C4PlayerInfo.cpp.

763 {
764  // assign IDs first: Must be done early, so AssignTeams works
765  if (!AssignPlayerIDs(pUpdate))
766  {
767  return false;
768  }
769  // set standard teams
770  AssignTeams(pUpdate, true);
771  // color/name change by team or savegame assignment
772  UpdatePlayerAttributes(pUpdate, true);
773  // add through queue: This will add directly, do the record and put player joins into the queue
774  // in running mode, this call will also put the actual player joins into the queue
776  // done, success
777  return true;
778 }
C4GameControl Control
@ CDT_Direct
Definition: C4GameControl.h:36
@ CDT_Queue
Definition: C4GameControl.h:34
@ CID_PlrInfo
Definition: C4PacketBase.h:158
void DoInput(C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)
bool IsRunning
Definition: C4Game.h:140
void AssignTeams(C4ClientPlayerInfos *pNewClientInfo, bool fByHost)
void UpdatePlayerAttributes()

References AssignPlayerIDs(), AssignTeams(), CDT_Direct, CDT_Queue, CID_PlrInfo, Control, C4GameControl::DoInput(), Game, C4Game::IsRunning, and UpdatePlayerAttributes().

Referenced by DoLocalNonNetworkPlayerJoin(), and DoPlayerInfoUpdate().

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

◆ DoLocalNonNetworkPlayerJoin()

bool C4PlayerInfoList::DoLocalNonNetworkPlayerJoin ( const char *  szPlayerFile)

Definition at line 738 of file C4PlayerInfo.cpp.

739 {
740  // construct joining information
741  C4ClientPlayerInfos *pNewJoin = new C4ClientPlayerInfos(szPlayerFile, true);
742  // handle it
743  bool fSuccess = DoLocalNonNetworkPlayerInfoUpdate(pNewJoin);
744  // done
745  delete pNewJoin;
746  return fSuccess;
747 }
bool DoLocalNonNetworkPlayerInfoUpdate(C4ClientPlayerInfos *pUpdate)

References DoLocalNonNetworkPlayerInfoUpdate().

Referenced by C4PlayerList::JoinNew().

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

◆ DoPlayerInfoUpdate()

bool C4PlayerInfoList::DoPlayerInfoUpdate ( C4ClientPlayerInfos pUpdate)

Definition at line 749 of file C4PlayerInfo.cpp.

750 {
751  // never done by clients or in replay - update will be handled via queue
752  if (!::Control.isCtrlHost()) return false;
753  // in network game, process by host. In offline game, just create control
754  bool fSucc = true;
755  if (::Control.isNetwork())
757  else
758  fSucc = DoLocalNonNetworkPlayerInfoUpdate(pUpdate);
759  return fSucc;
760 }
bool isCtrlHost() const
Definition: C4GameControl.h:99
bool isNetwork() const
Definition: C4GameControl.h:97
C4Network2Players Players
Definition: C4Network2.h:119
void RequestPlayerInfoUpdate(const class C4ClientPlayerInfos &rRequest)

References Control, DoLocalNonNetworkPlayerInfoUpdate(), C4GameControl::isCtrlHost(), C4GameControl::isNetwork(), Network, C4Network2::Players, and C4Network2Players::RequestPlayerInfoUpdate().

Here is the call graph for this function:

◆ FindSavegameResumePlayerInfo()

C4PlayerInfo * C4PlayerInfoList::FindSavegameResumePlayerInfo ( const C4PlayerInfo pMatchInfo,
MatchingLevel  mlMatchStart,
MatchingLevel  mlMatchEnd 
) const

Definition at line 1156 of file C4PlayerInfo.cpp.

1157 {
1158  assert(pMatchInfo);
1159  // try different matching levels using the infamous for-case-paradigm
1160  for (int iMatchLvl = mlMatchStart; iMatchLvl <= mlMatchEnd; ++iMatchLvl)
1161  {
1162  for (int32_t i=0; i<iClientCount; ++i)
1163  {
1164  int32_t j=0; C4PlayerInfo *pInfo;
1165  while ((pInfo = ppClients[i]->GetPlayerInfo(j++)))
1166  if (!Game.PlayerInfos.GetPlayerInfoByID(pInfo->GetID()) && !Game.PlayerInfos.GetPlayerInfoBySavegameID(pInfo->GetID())) // only unassigned player infos
1167  switch (iMatchLvl)
1168  {
1169  case PML_PlrFileName: // file name and player name must match
1170  if (!pMatchInfo->GetFilename() || !pInfo->GetFilename()) break;
1171  if (!SEqualNoCase(GetFilename(pMatchInfo->GetFilename()), GetFilename(pInfo->GetFilename()))) break;
1172  // nobreak: Check player name as well
1173  case PML_PlrName: // match player name
1174  if (SEqualNoCase(pMatchInfo->GetName(), pInfo->GetName()))
1175  return pInfo;
1176  break;
1177  case PML_PrefColor: // match player color
1178  if (pMatchInfo->GetOriginalColor() == pInfo->GetOriginalColor())
1179  return pInfo;
1180  break;
1181  case PML_Any: // match anything
1182  return pInfo;
1183  }
1184  }
1185  }
1186  // no match
1187  return nullptr;
1188 }
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:213
char * GetFilename(char *szPath)
Definition: StdFile.cpp:42
C4PlayerInfoList & PlayerInfos
Definition: C4Game.h:71
uint32_t GetOriginalColor() const
Definition: C4PlayerInfo.h:155
const char * GetFilename() const
Definition: C4PlayerInfo.h:161
C4PlayerInfo * GetPlayerInfoByID(int32_t id) const

References Game, C4PlayerInfo::GetFilename(), GetFilename(), C4PlayerInfo::GetID(), C4PlayerInfo::GetName(), C4PlayerInfo::GetOriginalColor(), GetPlayerInfoByID(), GetPlayerInfoBySavegameID(), C4Game::PlayerInfos, and SEqualNoCase().

Referenced by RestoreSavegameInfos().

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

◆ FindUnassociatedRestoreInfo()

C4PlayerInfo * C4PlayerInfoList::FindUnassociatedRestoreInfo ( const C4PlayerInfoList rRestoreInfoList)

Definition at line 1190 of file C4PlayerInfo.cpp.

1191 {
1192  // search given list for a player that's not associated locally
1193  C4ClientPlayerInfos *pRestoreClient; int32_t iClient=0;
1194  while ((pRestoreClient = rRestoreInfoList.GetIndexedInfo(iClient++)))
1195  {
1196  C4PlayerInfo *pRestoreInfo; int32_t iInfo=0;
1197  while ((pRestoreInfo = pRestoreClient->GetPlayerInfo(iInfo++)))
1198  if (pRestoreInfo->IsJoined())
1199  // match association either by savegame ID (before C4Game::InitPlayers) or real ID (after C4Game::InitPlayers)
1200  if (!GetPlayerInfoBySavegameID(pRestoreInfo->GetID()) && !GetPlayerInfoByID(pRestoreInfo->GetID()))
1201  return pRestoreInfo;
1202  }
1203  // no unassociated info found
1204  return nullptr;
1205 }
bool IsJoined() const
Definition: C4PlayerInfo.h:166

References C4PlayerInfo::GetID(), GetIndexedInfo(), C4ClientPlayerInfos::GetPlayerInfo(), GetPlayerInfoByID(), GetPlayerInfoBySavegameID(), and C4PlayerInfo::IsJoined().

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

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

◆ FixIDCounter()

void C4PlayerInfoList::FixIDCounter ( )

Definition at line 1782 of file C4PlayerInfo.cpp.

1783 {
1784  // make sure ID counter is same as largest info
1785  for (int32_t i=0; i<iClientCount; ++i)
1786  {
1787  int32_t j=0; C4PlayerInfo *pInfo;
1788  while ((pInfo = ppClients[i]->GetPlayerInfo(j++)))
1789  {
1790  iLastPlayerID = std::max<int32_t>(pInfo->GetID(), iLastPlayerID);
1791  }
1792  }
1793 }

References C4PlayerInfo::GetID().

Referenced by C4GameControl::ChangeToLocal().

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

◆ GetActivePlayerCount()

int32_t C4PlayerInfoList::GetActivePlayerCount ( bool  fCountInvisible) const

Definition at line 981 of file C4PlayerInfo.cpp.

982 {
983  // count players of all clients
984  int32_t iCount=0;
985  for (int32_t i=0; i<iClientCount; ++i)
986  {
987  C4ClientPlayerInfos *pClient = ppClients[i];
988  for (int32_t j=0; j<pClient->GetPlayerCount(); ++j)
989  {
990  C4PlayerInfo *pInfo = pClient->GetPlayerInfo(j);
991  if (!pInfo->IsRemoved())
992  if (fCountInvisible || !pInfo->IsInvisible())
993  ++iCount;
994  }
995  }
996  // return it
997  return iCount;
998 }
bool IsInvisible() const
Definition: C4PlayerInfo.h:175
bool IsRemoved() const
Definition: C4PlayerInfo.h:164

References C4ClientPlayerInfos::GetPlayerCount(), C4ClientPlayerInfos::GetPlayerInfo(), C4PlayerInfo::IsInvisible(), and C4PlayerInfo::IsRemoved().

Referenced by C4Game::InitPlayers(), C4StartupNetListEntry::OnReference(), and C4StartupNetListEntry::SetReference().

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

◆ GetActivePlayerInfoByName()

C4PlayerInfo * C4PlayerInfoList::GetActivePlayerInfoByName ( const char *  szName)

Definition at line 1141 of file C4PlayerInfo.cpp.

1142 {
1143  // check all packets for matching players
1144  for (int32_t i=0; i<iClientCount; ++i)
1145  {
1146  int32_t j=0; C4PlayerInfo *pInfo;
1147  while ((pInfo = ppClients[i]->GetPlayerInfo(j++)))
1148  if (!pInfo->IsRemoved())
1149  if (SEqualNoCase(szName, pInfo->GetName()))
1150  return pInfo;
1151  }
1152  // nothing found
1153  return nullptr;
1154 }

References C4PlayerInfo::GetName(), C4PlayerInfo::IsRemoved(), and SEqualNoCase().

Referenced by C4TeamList::GetScriptPlayerName().

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

◆ GetActivePlayerNames()

StdStrBuf C4PlayerInfoList::GetActivePlayerNames ( bool  fCountInvisible,
int32_t  iAtClientID = -1 
) const

Definition at line 1021 of file C4PlayerInfo.cpp.

1022 {
1023  // add up players of all clients
1024  StdStrBuf sPlr;
1025  int32_t iCount=0;
1026  for (int32_t i=0; i<iClientCount; ++i)
1027  {
1028  C4ClientPlayerInfos *pClient = ppClients[i];
1029  if (iAtClientID != -1 && pClient->GetClientID() != iAtClientID) continue;
1030  for (int32_t j=0; j<pClient->GetPlayerCount(); ++j)
1031  {
1032  C4PlayerInfo *pInfo = pClient->GetPlayerInfo(j);
1033  if (!pInfo->IsRemoved()) if (fCountInvisible || !pInfo->IsInvisible())
1034  {
1035  if (iCount++)
1036  {
1037  // not first name: Add separator
1038  sPlr.Append(", ");
1039  }
1040  sPlr.Append(pInfo->GetName());
1041  }
1042  }
1043  }
1044  // return it
1045  return sPlr;
1046 }
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519

References StdStrBuf::Append(), C4ClientPlayerInfos::GetClientID(), C4PlayerInfo::GetName(), C4ClientPlayerInfos::GetPlayerCount(), C4ClientPlayerInfos::GetPlayerInfo(), C4PlayerInfo::IsInvisible(), and C4PlayerInfo::IsRemoved().

Referenced by C4StartupNetListEntry::SetReference().

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

◆ GetActiveScriptPlayerCount()

int32_t C4PlayerInfoList::GetActiveScriptPlayerCount ( bool  fCountSavegameResumes,
bool  fCountInvisible 
) const

Definition at line 1000 of file C4PlayerInfo.cpp.

1001 {
1002  // count players of all clients
1003  int32_t iCount=0;
1004  for (int32_t i=0; i<iClientCount; ++i)
1005  {
1006  C4ClientPlayerInfos *pClient = ppClients[i];
1007  for (int32_t j=0; j<pClient->GetPlayerCount(); ++j)
1008  {
1009  C4PlayerInfo *pNfo = pClient->GetPlayerInfo(j);
1010  if (!pNfo->IsRemoved())
1011  if (pNfo->GetType() == C4PT_Script)
1012  if (fCountSavegameResumes || !pNfo->GetAssociatedSavegamePlayerID())
1013  if (fCountInvisible || !pNfo->IsInvisible())
1014  ++iCount;
1015  }
1016  }
1017  // return it
1018  return iCount;
1019 }
int32_t GetAssociatedSavegamePlayerID() const
Definition: C4PlayerInfo.h:126

References C4PT_Script, C4PlayerInfo::GetAssociatedSavegamePlayerID(), C4ClientPlayerInfos::GetPlayerCount(), C4ClientPlayerInfos::GetPlayerInfo(), C4PlayerInfo::GetType(), C4PlayerInfo::IsInvisible(), and C4PlayerInfo::IsRemoved().

Referenced by C4Game::InitPlayers().

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

◆ GetClientInfoByPlayerID()

C4ClientPlayerInfos * C4PlayerInfoList::GetClientInfoByPlayerID ( int32_t  id) const

Definition at line 1077 of file C4PlayerInfo.cpp.

1078 {
1079  // get client info that contains a specific player
1080  assert(id);
1081  for (int32_t i=0; i<iClientCount; ++i)
1082  {
1083  int32_t j=0; C4PlayerInfo *pInfo;
1084  while ((pInfo = ppClients[i]->GetPlayerInfo(j++)))
1085  if (pInfo->GetID() == id) return ppClients[i];
1086  }
1087  // nothing found
1088  return nullptr;
1089 }

References C4PlayerInfo::GetID().

Referenced by C4MessageInput::ProcessCommand(), C4TeamList::ReassignAllTeams(), and C4TeamList::RecheckTeams().

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

◆ GetFreePlayerSlotCount()

int32_t C4PlayerInfoList::GetFreePlayerSlotCount ( )

Definition at line 854 of file C4PlayerInfo.cpp.

855 {
856  // number of free slots depends on max player setting
857  return std::max<int32_t>(Game.Parameters.MaxPlayers - GetStartupCount(), 0);
858 }
int32_t GetStartupCount()

References Game, GetStartupCount(), C4GameParameters::MaxPlayers, and C4Game::Parameters.

Referenced by AssignPlayerIDs().

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

◆ GetIDCounter()

int32_t C4PlayerInfoList::GetIDCounter ( )
inline

Definition at line 395 of file C4PlayerInfo.h.

395 { return iLastPlayerID; }

Referenced by C4GameParameters::Load().

Here is the caller graph for this function:

◆ GetIndexedInfo()

◆ GetInfoByClientID()

C4ClientPlayerInfos* C4PlayerInfoList::GetInfoByClientID ( int32_t  iClientID) const
inline

Definition at line 361 of file C4PlayerInfo.h.

362  { C4ClientPlayerInfos **ppNfo = GetInfoPtrByClientID(iClientID); return ppNfo ? *ppNfo : nullptr; }

References GetInfoPtrByClientID().

Referenced by C4Network2Players::GetClientChatColor(), GetPrimaryInfoByClientID(), C4Network2Players::HandlePlayerInfoUpdRequest(), HasSameTeamPlayers(), C4Network2::LeagueNotifyDisconnect(), and C4Network2::OpenVoteDialog().

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

◆ GetInfoCount()

int32_t C4PlayerInfoList::GetInfoCount ( ) const
inline

Definition at line 357 of file C4PlayerInfo.h.

357 { return iClientCount; } // get number of registered client infos

Referenced by C4PlayerInfoListAttributeConflictResolver::C4PlayerInfoListAttributeConflictResolver(), CreateRestoreInfosForJoinedScriptPlayers(), InitLocal(), and RestoreSavegameInfos().

Here is the caller graph for this function:

◆ GetInfoPtrByClientID()

C4ClientPlayerInfos ** C4PlayerInfoList::GetInfoPtrByClientID ( int32_t  iClientID) const

Definition at line 933 of file C4PlayerInfo.cpp.

934 {
935  // search list
936  for (int32_t i=0; i<iClientCount; ++i) if (ppClients[i]->GetClientID() == iClientID) return ppClients+i;
937  // nothing found
938  return nullptr;
939 }

Referenced by AddInfo(), GetInfoByClientID(), LocalJoinUnjoinedPlayersInQueue(), C4Network2Players::OnClientPart(), and SetAsRestoreInfos().

Here is the caller graph for this function:

◆ GetJoinIssuedPlayerCount()

int32_t C4PlayerInfoList::GetJoinIssuedPlayerCount ( ) const

Definition at line 951 of file C4PlayerInfo.cpp.

952 {
953  // count players of all clients
954  int32_t iCount=0;
955  for (int32_t i=0; i<iClientCount; ++i)
956  {
957  C4ClientPlayerInfos *pClient = ppClients[i];
958  for (int32_t j=0; j<pClient->GetPlayerCount(); ++j)
959  if (pClient->GetPlayerInfo(j)->HasJoinIssued())
960  ++iCount;
961  }
962  // return it
963  return iCount;
964 }
bool HasJoinIssued() const
Definition: C4PlayerInfo.h:167

References C4ClientPlayerInfos::GetPlayerCount(), C4ClientPlayerInfos::GetPlayerInfo(), and C4PlayerInfo::HasJoinIssued().

Referenced by C4Viewport::Execute(), and C4Game::InitPlayers().

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

◆ GetJoinPendingPlayerCount()

int32_t C4PlayerInfoList::GetJoinPendingPlayerCount ( ) const

Definition at line 966 of file C4PlayerInfo.cpp.

967 {
968  // count players of all clients
969  int32_t iCount = 0;
970  for (int32_t i = 0; i<iClientCount; ++i)
971  {
972  C4ClientPlayerInfos *pClient = ppClients[i];
973  for (int32_t j = 0; j<pClient->GetPlayerCount(); ++j)
974  if (pClient->GetPlayerInfo(j)->HasJoinPending())
975  ++iCount;
976  }
977  // return it
978  return iCount;
979 }
bool HasJoinPending() const
Definition: C4PlayerInfo.h:168

References C4ClientPlayerInfos::GetPlayerCount(), C4ClientPlayerInfos::GetPlayerInfo(), and C4PlayerInfo::HasJoinPending().

Referenced by C4Game::OnPlayerJoinFinished().

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

◆ GetNextPlayerInfoByID()

C4PlayerInfo * C4PlayerInfoList::GetNextPlayerInfoByID ( int32_t  id) const

Definition at line 1125 of file C4PlayerInfo.cpp.

1126 {
1127  // check all packets for players
1128  C4PlayerInfo *pSmallest=nullptr;
1129  for (int32_t i=0; i<iClientCount; ++i)
1130  {
1131  int32_t j=0; C4PlayerInfo *pInfo;
1132  while ((pInfo = ppClients[i]->GetPlayerInfo(j++)))
1133  if (pInfo->GetID() > id)
1134  if (!pSmallest || pSmallest->GetID()>pInfo->GetID())
1135  pSmallest = pInfo;
1136  }
1137  // return best found
1138  return pSmallest;
1139 }

References C4PlayerInfo::GetID().

Referenced by C4MessageInput::ProcessCommand(), C4TeamList::ReassignAllTeams(), and C4Team::RecheckPlayers().

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

◆ GetPlayerCount()

int32_t C4PlayerInfoList::GetPlayerCount ( ) const

Definition at line 941 of file C4PlayerInfo.cpp.

942 {
943  // count players of all clients
944  int32_t iCount=0;
945  for (int32_t i=0; i<iClientCount; ++i)
946  iCount += ppClients[i]->GetPlayerCount();
947  // return it
948  return iCount;
949 }
int32_t GetPlayerCount() const

Referenced by C4GameLobby::Countdown::OnSec1Timer(), RestoreSavegameInfos(), and C4GameSave::WriteDescPlayers().

Here is the caller graph for this function:

◆ GetPlayerInfoByID() [1/2]

C4PlayerInfo * C4PlayerInfoList::GetPlayerInfoByID ( int32_t  id) const

Definition at line 1062 of file C4PlayerInfo.cpp.

1063 {
1064  // must be a valid ID
1065  assert(id);
1066  // check all packets for a player
1067  for (int32_t i=0; i<iClientCount; ++i)
1068  {
1069  int32_t j=0; C4PlayerInfo *pInfo;
1070  while ((pInfo = ppClients[i]->GetPlayerInfo(j++)))
1071  if (pInfo->GetID() == id) return pInfo;
1072  }
1073  // nothing found
1074  return nullptr;
1075 }

References C4PlayerInfo::GetID().

Referenced by C4Player::CreateGraphs(), C4Player::FindNewOwner(), FindSavegameResumePlayerInfo(), FindUnassociatedRestoreInfo(), C4Team::GetFirstUnjoinedPlayerID(), C4Player::GetInfo(), C4Team::GetNameWithParticipants(), C4Player::GetType(), C4Network2Players::HandlePlayerInfoUpdRequest(), C4Team::HasWon(), C4Player::IsInvisible(), C4Team::RecheckPlayers(), C4TeamList::RecheckTeams(), C4PlayerList::Remove(), RestoreSavegameInfos(), C4PlayerList::Save(), and UpdatePlayerAttributes().

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

◆ GetPlayerInfoByID() [2/2]

C4PlayerInfo * C4PlayerInfoList::GetPlayerInfoByID ( int32_t  id,
int32_t *  pidClient 
) const

Definition at line 1091 of file C4PlayerInfo.cpp.

1092 {
1093  // must be a valid ID
1094  assert(id); assert(pidClient);
1095  // check all packets for a player
1096  for (int32_t i=0; i<iClientCount; ++i)
1097  {
1098  int32_t j=0; C4PlayerInfo *pInfo;
1099  while ((pInfo = ppClients[i]->GetPlayerInfo(j++)))
1100  if (pInfo->GetID() == id)
1101  {
1102  *pidClient = ppClients[i]->GetClientID();
1103  return pInfo;
1104  }
1105  }
1106  // nothing found
1107  return nullptr;
1108 }

References C4ClientPlayerInfos::GetClientID(), and C4PlayerInfo::GetID().

Here is the call graph for this function:

◆ GetPlayerInfoByIndex()

C4PlayerInfo * C4PlayerInfoList::GetPlayerInfoByIndex ( int32_t  index) const

Definition at line 1048 of file C4PlayerInfo.cpp.

1049 {
1050  // check all packets for a player
1051  for (int32_t i=0; i<iClientCount; ++i)
1052  {
1053  int32_t j=0; C4PlayerInfo *pInfo;
1054  while ((pInfo = ppClients[i]->GetPlayerInfo(j++)))
1055  if (index-- <= 0)
1056  return pInfo;
1057  }
1058  // nothing found
1059  return nullptr;
1060 }

Referenced by C4Player::ScenarioInit(), and C4GameSave::WriteDescPlayers().

Here is the caller graph for this function:

◆ GetPlayerInfoBySavegameID()

C4PlayerInfo * C4PlayerInfoList::GetPlayerInfoBySavegameID ( int32_t  id) const

Definition at line 1110 of file C4PlayerInfo.cpp.

1111 {
1112  // must be a valid ID
1113  assert(id);
1114  // check all packets for a player
1115  for (int32_t i=0; i<iClientCount; ++i)
1116  {
1117  int32_t j=0; C4PlayerInfo *pInfo;
1118  while ((pInfo = ppClients[i]->GetPlayerInfo(j++)))
1119  if (pInfo->GetAssociatedSavegamePlayerID() == id) return pInfo;
1120  }
1121  // nothing found
1122  return nullptr;
1123 }

References C4PlayerInfo::GetAssociatedSavegamePlayerID().

Referenced by CreateRestoreInfosForJoinedScriptPlayers(), FindSavegameResumePlayerInfo(), FindUnassociatedRestoreInfo(), and RemoveUnassociatedPlayers().

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

◆ GetPrimaryInfoByClientID()

C4PlayerInfo* C4PlayerInfoList::GetPrimaryInfoByClientID ( int32_t  iClientID) const
inline

Definition at line 376 of file C4PlayerInfo.h.

377  {
378  C4ClientPlayerInfos *pInfoPkt = GetInfoByClientID(iClientID);
379  if (!pInfoPkt) return nullptr;
380  return pInfoPkt->GetPlayerInfo(0);
381  }
C4ClientPlayerInfos * GetInfoByClientID(int32_t iClientID) const
Definition: C4PlayerInfo.h:361

References GetInfoByClientID(), and C4ClientPlayerInfos::GetPlayerInfo().

Referenced by C4MessageInput::ProcessCommand().

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

◆ GetStartupCount()

int32_t C4PlayerInfoList::GetStartupCount ( )

Definition at line 1762 of file C4PlayerInfo.cpp.

1763 {
1764  // count all joined and to-be-joined
1765  int32_t iCnt=0;
1766  for (int32_t i=0; i<iClientCount; ++i)
1767  {
1768  int32_t j=0; C4PlayerInfo *pInfo;
1769  while ((pInfo = ppClients[i]->GetPlayerInfo(j++)))
1770  if (!pInfo->IsRemoved()) ++iCnt;
1771  }
1772  return iCnt;
1773 }
int iCnt
Definition: TstC4NetIO.cpp:32

References iCnt, and C4PlayerInfo::IsRemoved().

Referenced by GetFreePlayerSlotCount(), and C4Console::InitGame().

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

◆ HasSameTeamPlayers()

bool C4PlayerInfoList::HasSameTeamPlayers ( int32_t  iClient1,
int32_t  iClient2 
) const

Definition at line 1207 of file C4PlayerInfo.cpp.

1208 {
1209  // compare all player teams of clients
1210  const C4ClientPlayerInfos *pCnfo1 = GetInfoByClientID(iClient1);
1211  const C4ClientPlayerInfos *pCnfo2 = GetInfoByClientID(iClient2);
1212  if (!pCnfo1 || !pCnfo2) return false;
1213  int32_t i=0,j; const C4PlayerInfo *pNfo1, *pNfo2;
1214  while ((pNfo1 = pCnfo1->GetPlayerInfo(i++)))
1215  {
1216  if (!pNfo1->IsUsingTeam()) continue;
1217  j=0;
1218  while ((pNfo2 = pCnfo2->GetPlayerInfo(j++)))
1219  {
1220  if (!pNfo2->IsUsingTeam()) continue;
1221  if (pNfo2->GetTeam() == pNfo1->GetTeam())
1222  // match found!
1223  return true;
1224  }
1225  }
1226  // no match
1227  return false;
1228 }
bool IsUsingTeam() const
Definition: C4PlayerInfo.h:173

References GetInfoByClientID(), C4ClientPlayerInfos::GetPlayerInfo(), C4PlayerInfo::GetTeam(), and C4PlayerInfo::IsUsingTeam().

Here is the call graph for this function:

◆ InitLocal()

bool C4PlayerInfoList::InitLocal ( )

Definition at line 1271 of file C4PlayerInfo.cpp.

1272 {
1273  // not in replay
1274  if (Game.C4S.Head.Replay) return true;
1275  // no double init
1276  assert(!GetInfoCount());
1277  // no network
1278  assert(!::Network.isEnabled());
1279  // create player info for local player joins
1281  // register local info immediately
1282  pLocalInfo = AddInfo(pLocalInfo);
1283  // Script players in restore infos need to be associated with matching script players in main info list
1285  // and assign teams
1286  if (Game.Teams.IsMultiTeams() && pLocalInfo)
1287  AssignTeams(pLocalInfo, true);
1288  // done, success
1289  return true;
1290 }
C4Scenario C4S
Definition: C4Game.h:74
char PlayerFilenames[20 *_MAX_PATH_LEN]
Definition: C4Game.h:104
C4PlayerInfoList & RestorePlayerInfos
Definition: C4Game.h:72
void CreateRestoreInfosForJoinedScriptPlayers(C4PlayerInfoList &rSavegamePlayers)
C4ClientPlayerInfos * AddInfo(C4ClientPlayerInfos *pNewClientInfo)
bool Replay
Definition: C4Scenario.h:72
C4SHead Head
Definition: C4Scenario.h:232

References AddInfo(), AssignTeams(), C4Game::C4S, CreateRestoreInfosForJoinedScriptPlayers(), Game, GetInfoCount(), C4Scenario::Head, C4Network2::isEnabled(), C4TeamList::IsMultiTeams(), Network, C4Game::PlayerFilenames, C4SHead::Replay, C4Game::RestorePlayerInfos, and C4Game::Teams.

Here is the call graph for this function:

◆ Load()

bool C4PlayerInfoList::Load ( C4Group hGroup,
const char *  szFromFile,
class C4LangStringTable pLang = nullptr 
)

Definition at line 1230 of file C4PlayerInfo.cpp.

1231 {
1232  // clear previous
1233  Clear();
1234  // load file contents
1235  StdStrBuf Buf;
1236  if (!hGroup.LoadEntryString(szFromFile, &Buf))
1237  // no file is OK; means no player infos
1238  return true;
1239  // replace strings
1240  if (pLang) pLang->ReplaceStrings(Buf);
1241  // (try to) compile
1242  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(
1243  mkNamingAdapt(*this, "PlayerInfoList"),
1244  Buf, szFromFile))
1245  return false;
1246  // done, success
1247  return true;
1248 }
bool LoadEntryString(const char *entry_name, StdStrBuf *buffer)
Definition: C4Group.cpp:2430

References Clear(), C4Group::LoadEntryString(), mkNamingAdapt(), and C4LangStringTable::ReplaceStrings().

Referenced by C4Game::InitPlayers(), and C4GameParameters::Load().

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

◆ LoadResources()

void C4PlayerInfoList::LoadResources ( )

Definition at line 1775 of file C4PlayerInfo.cpp.

1776 {
1777  // load for all players
1778  int32_t i = iClientCount; C4ClientPlayerInfos **ppClient=ppClients;
1779  while (i--) (*ppClient++)->LoadResources();
1780 }

Referenced by C4Network2::HandleJoinData(), and C4Network2Players::HandlePlayerInfo().

Here is the caller graph for this function:

◆ LocalJoinUnjoinedPlayersInQueue()

bool C4PlayerInfoList::LocalJoinUnjoinedPlayersInQueue ( )

Definition at line 1292 of file C4PlayerInfo.cpp.

1293 {
1294  // local call only - in network, C4Network2Players joins players!
1295  assert(!::Network.isEnabled());
1296  // get local players
1297  C4ClientPlayerInfos **ppkLocal = GetInfoPtrByClientID(::Control.ClientID()), *pkLocal;
1298  if (!ppkLocal) return false;
1299  pkLocal = *ppkLocal;
1300  // check all players
1301  int32_t i=0; C4PlayerInfo *pInfo;
1302  while ((pInfo = pkLocal->GetPlayerInfo(i++)))
1303  // not yet joined?
1304  if (!pInfo->HasJoinIssued())
1305  {
1306  // join will be marked when queue is executed (C4Player::Join)
1307  // but better mark join now already to prevent permanent sending overkill
1308  pInfo->SetJoinIssued();
1309  // join by filename if possible. Script players may not have a filename assigned though
1310  const char *szFilename = pInfo->GetFilename();
1311  if (!szFilename && (pInfo->GetType() != C4PT_Script))
1312  {
1313  // failure for user players
1314  const char *szPlrName = pInfo->GetName(); if (!szPlrName) szPlrName="???";
1315  LogF(LoadResStr("IDS_ERR_JOINQUEUEPLRS"), szPlrName);
1316  continue;
1317  }
1319  new C4ControlJoinPlayer(szFilename, ::Control.ClientID(), pInfo->GetID()));
1320  }
1321  // done, success
1322  return true;
1323 }
@ CID_JoinPlr
Definition: C4PacketBase.h:159
void Add(C4PacketType eType, C4ControlPacket *pCtrl)
Definition: C4Control.h:82
int32_t ClientID() const
C4Control & Input
Definition: C4Game.h:82
void SetJoinIssued()
Definition: C4PlayerInfo.h:112

References C4Control::Add(), C4PT_Script, CID_JoinPlr, C4GameControl::ClientID(), Control, Game, C4PlayerInfo::GetFilename(), C4PlayerInfo::GetID(), GetInfoPtrByClientID(), C4PlayerInfo::GetName(), C4PlayerInfo::GetType(), C4PlayerInfo::HasJoinIssued(), C4Game::Input, C4Network2::isEnabled(), LoadResStr(), LogF(), Network, and C4PlayerInfo::SetJoinIssued().

Referenced by C4Game::InitPlayers().

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

◆ operator=()

C4PlayerInfoList & C4PlayerInfoList::operator= ( const C4PlayerInfoList rCpy)

Definition at line 694 of file C4PlayerInfo.cpp.

695 {
696  Clear();
697  iClientCount = rCpy.iClientCount;
698  iClientCapacity = rCpy.iClientCapacity;
699  iLastPlayerID = rCpy.iLastPlayerID;
700  if (rCpy.ppClients)
701  {
702  ppClients = new C4ClientPlayerInfos*[iClientCapacity];
703  C4ClientPlayerInfos **ppInfo = ppClients, **ppCpy = rCpy.ppClients;
704  int32_t i = iClientCount;
705  while (i--) *ppInfo++ = new C4ClientPlayerInfos(**ppCpy++);
706  }
707  else
708  ppClients = nullptr;
709  return *this;
710 }

References Clear().

Here is the call graph for this function:

◆ RecheckAutoGeneratedTeams()

void C4PlayerInfoList::RecheckAutoGeneratedTeams ( )

Definition at line 869 of file C4PlayerInfo.cpp.

870 {
871  // ensure all teams specified in the list exist
872  C4ClientPlayerInfos *pPlrInfos; int32_t j=0;
873  while ((pPlrInfos = GetIndexedInfo(j++)))
874  {
875  C4PlayerInfo *pPlrInfo; int32_t i=0;
876  while ((pPlrInfo = pPlrInfos->GetPlayerInfo(i++)))
877  {
878  int32_t idTeam = pPlrInfo->GetTeam();
879  if (idTeam) Game.Teams.GetGenerateTeamByID(idTeam);
880  }
881  }
882 }

References Game, C4TeamList::GetGenerateTeamByID(), GetIndexedInfo(), C4ClientPlayerInfos::GetPlayerInfo(), C4PlayerInfo::GetTeam(), and C4Game::Teams.

Here is the call graph for this function:

◆ RecreatePlayerFiles()

bool C4PlayerInfoList::RecreatePlayerFiles ( )

Definition at line 1448 of file C4PlayerInfo.cpp.

1449 {
1450  // Note that this method will be called on the main list for savegame resumes (even in network) or regular games with RecreateInfos,
1451  // and on RestorePlayerInfos for runtime network joins
1452  // check all player files that need to be recreated
1453  for (int32_t i=0; i<iClientCount; ++i)
1454  {
1455  C4ClientPlayerInfos *pkInfo = ppClients[i];
1456  int32_t j=0; C4PlayerInfo *pInfo;
1457  while ((pInfo = pkInfo->GetPlayerInfo(j++)))
1458  if (pInfo->IsJoined())
1459  {
1460  // all players in replays and runtime joins; script players even in savegames need to be restored from the scenario goup
1462  {
1463  // in this case, a filename must have been assigned while saving
1464  // and mark a file inside the scenario file
1465  // get filename of joined player - this should always be valid!
1466  const char *szCurrPlrFile;
1467  StdStrBuf sFilenameInRecord;
1468  if (Game.C4S.Head.Replay)
1469  {
1470  // replay of resumed savegame: RecreatePlayers saves used player files into the record group in this manner
1471  sFilenameInRecord.Format("Recreate-%d.ocp", pInfo->GetID());
1472  szCurrPlrFile = sFilenameInRecord.getData();
1473  }
1474  else
1475  szCurrPlrFile = pInfo->GetFilename();
1476  const char *szPlrName = pInfo->GetName(); if (!szPlrName) szPlrName = "???";
1477  if (!szCurrPlrFile || !*szCurrPlrFile)
1478  {
1479  // that's okay for script players, because those may join w/o recreation files
1480  if (pInfo->GetType() != C4PT_Script)
1481  {
1482  LogF(LoadResStr("IDS_ERR_LOAD_RECR_NOFILE"), szPlrName);
1483  }
1484  continue;
1485  }
1486  // join from temp file
1487  StdCopyStrBuf szJoinPath;
1488  szJoinPath = Config.AtTempPath(GetFilename(szCurrPlrFile));
1489  // extract player there
1490  if (!Game.ScenarioFile.FindEntry(GetFilename(szCurrPlrFile)) || !Game.ScenarioFile.Extract(GetFilename(szCurrPlrFile), szJoinPath.getData()))
1491  {
1492  // that's okay for script players, because those may join w/o recreation files
1493  if (pInfo->GetType() != C4PT_Script)
1494  {
1495  LogF(LoadResStr("IDS_ERR_LOAD_RECR_NOEXTRACT"), szPlrName, GetFilename(szCurrPlrFile));
1496  }
1497  continue;
1498  }
1499  // set join source
1500  pInfo->SetFilename(szJoinPath.getData());
1501  pInfo->DiscardResource();
1502  // setting a temp file here will cause the player file to be deleted directly after recreation
1503  // if recreation fails (e.g. the game gets aborted due to invalid files), the info dtor will delete the file
1504  pInfo->SetTempFile();
1505  }
1506  else
1507  {
1508  // regular player in savegame being resumed in network or normal mode:
1509  // the filenames and/or resources should have been assigned
1510  // a) either in lobby mode during player re-acquisition
1511  // b) or when players from rSavegamePlayers were taken over
1512  }
1513  }
1514  else if (!pInfo->HasJoinIssued())
1515  {
1516  // new players to be joined into the game:
1517  // regular control queue join can be done; no special handling needed
1518  }
1519  }
1520  // done, success
1521  return true;
1522 }
C4Config Config
Definition: C4Config.cpp:930
const char * AtTempPath(const char *filename)
Definition: C4Config.cpp:600
C4Group ScenarioFile
Definition: C4Game.h:86
bool Extract(const char *files, const char *destination=nullptr, const char *exclude=nullptr)
Definition: C4Group.cpp:1808
bool FindEntry(const char *wildcard, StdStrBuf *filename=nullptr, size_t *size=nullptr)
Definition: C4Group.cpp:2211
void SetTempFile()
Definition: C4PlayerInfo.h:119
void SetFilename(const char *szToFilename)
void DiscardResource()
bool NetworkRuntimeJoin
Definition: C4Scenario.h:79
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174

References C4Config::AtTempPath(), C4PT_Script, C4Game::C4S, Config, C4PlayerInfo::DiscardResource(), C4Group::Extract(), C4Group::FindEntry(), StdStrBuf::Format(), Game, StdStrBuf::getData(), C4PlayerInfo::GetFilename(), GetFilename(), C4PlayerInfo::GetID(), C4PlayerInfo::GetName(), C4ClientPlayerInfos::GetPlayerInfo(), C4PlayerInfo::GetType(), C4PlayerInfo::HasJoinIssued(), C4Scenario::Head, C4PlayerInfo::IsJoined(), LoadResStr(), LogF(), C4SHead::NetworkRuntimeJoin, C4SHead::Replay, C4Game::ScenarioFile, C4PlayerInfo::SetFilename(), and C4PlayerInfo::SetTempFile().

Referenced by C4Game::InitPlayers().

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

◆ RecreatePlayers()

bool C4PlayerInfoList::RecreatePlayers ( C4ValueNumbers numbers)

Definition at line 1524 of file C4PlayerInfo.cpp.

1525 {
1526  // check all player infos
1527  for (int32_t i=0; i<iClientCount; ++i)
1528  {
1529  C4ClientPlayerInfos *pkInfo = ppClients[i];
1530  // skip clients without joined players
1531  if (!pkInfo->GetJoinedPlayerCount()) continue;
1532  // determine client ID and name
1533  // client IDs must be set correctly even in replays,
1534  // so client-removal packets are executed correctly
1535  int32_t idAtClient = pkInfo->GetClientID();
1536  const char *szAtClientName;
1537  if (Game.C4S.Head.Replay)
1538  // the client name can currently not really be retrieved in replays
1539  // but it's not used anyway
1540  szAtClientName = "Replay";
1541  else
1542  // local non-network non-replay games set local name
1543  if (!::Network.isEnabled())
1544  {
1545  assert(idAtClient == ::Control.ClientID());
1546  szAtClientName = "Local";
1547  }
1548  else
1549  {
1550  // network non-replay games: find client and set name by it
1551  const C4Client *pClient = Game.Clients.getClientByID(idAtClient);
1552  if (pClient)
1553  szAtClientName = pClient->getName();
1554  else
1555  {
1556  // this shouldn't happen - remove the player info
1557  LogF(LoadResStr("IDS_PRC_RESUMENOCLIENT"), idAtClient, pkInfo->GetPlayerCount());
1558  continue;
1559  }
1560  }
1561  // rejoin all joined players of that client
1562  int32_t j=0; C4PlayerInfo *pInfo;
1563  while ((pInfo = pkInfo->GetPlayerInfo(j++)))
1564  if (pInfo->IsJoined())
1565  {
1566  // get filename to join from
1567  const char *szFilename = pInfo->GetLocalJoinFilename();
1568  // ensure resource is loaded, if joining from resource
1569  // this may display a waiting dialog and block the thread for a while
1570  C4Network2Res *pJoinRes = pInfo->GetRes();
1571  if (szFilename && pJoinRes && pJoinRes->isLoading())
1572  {
1573  const char *szName = pInfo->GetName();
1574  if (!::Network.RetrieveRes(pJoinRes->getCore(), C4NetResRetrieveTimeout,
1575  FormatString(LoadResStr("IDS_NET_RES_PLRFILE"), szName).getData()))
1576  szFilename=nullptr;
1577  }
1578  // file present?
1579  if (!szFilename || !*szFilename)
1580  {
1581  if (pInfo->GetType() == C4PT_User)
1582  {
1583  // for user players, this could happen only if the user cancelled the resource
1584  const char *szPlrName = pInfo->GetName(); if (!szPlrName) szPlrName = "???";
1585  LogF(LoadResStr("IDS_ERR_LOAD_RECR_NOFILEFROMNET"), szPlrName);
1586  continue;
1587  }
1588  else
1589  {
1590  // for script players: Recreation without filename OK
1591  szFilename = nullptr;
1592  }
1593  }
1594  // record file handling: Save to the record file in the manner it's expected by C4PlayerInfoList::RecreatePlayers
1595  if (::Control.isRecord() && szFilename)
1596  {
1597  StdStrBuf sFilenameInRecord;
1598  sFilenameInRecord.Format("Recreate-%d.ocp", pInfo->GetID());
1599  ::Control.RecAddFile(szFilename, sFilenameInRecord.getData());
1600  }
1601  // recreate join directly
1602  ::Players.Join(szFilename, false, idAtClient, szAtClientName, pInfo, numbers);
1603  // delete temporary files immediately
1604  if (pInfo->IsTempFile()) pInfo->DeleteTempFile();
1605  }
1606  }
1607  // done!
1608  return true;
1609 }
@ C4PT_User
Definition: C4Constants.h:154
const int C4NetResRetrieveTimeout
Definition: C4Network2.h:37
C4PlayerList Players
const char * getName() const
Definition: C4Client.h:107
C4Client * getClientByID(int32_t iID) const
Definition: C4Client.cpp:200
int32_t GetJoinedPlayerCount() const
bool RecAddFile(const char *szLocalFilename, const char *szAddAs)
bool isRecord() const
C4ClientList & Clients
Definition: C4Game.h:69
C4Network2Res::Ref RetrieveRes(const C4Network2ResCore &Core, int32_t iTimeout, const char *szResName, bool fWaitForCore=false)
const C4Network2ResCore & getCore() const
bool isLoading() const
bool IsTempFile() const
Definition: C4PlayerInfo.h:196
const char * GetLocalJoinFilename() const
C4Network2Res * GetRes() const
Definition: C4PlayerInfo.h:163
void DeleteTempFile()
C4Player * Join(const char *szFilename, bool fScenarioInit, int iAtClient, const char *szAtClientName, class C4PlayerInfo *pInfo, C4ValueNumbers *)

References C4NetResRetrieveTimeout, C4PT_User, C4Game::C4S, C4GameControl::ClientID(), C4Game::Clients, Control, C4PlayerInfo::DeleteTempFile(), StdStrBuf::Format(), FormatString(), Game, C4ClientList::getClientByID(), C4ClientPlayerInfos::GetClientID(), C4Network2Res::getCore(), StdStrBuf::getData(), C4PlayerInfo::GetID(), C4ClientPlayerInfos::GetJoinedPlayerCount(), C4PlayerInfo::GetLocalJoinFilename(), C4PlayerInfo::GetName(), C4Client::getName(), C4ClientPlayerInfos::GetPlayerCount(), C4ClientPlayerInfos::GetPlayerInfo(), C4PlayerInfo::GetRes(), C4PlayerInfo::GetType(), C4Scenario::Head, C4Network2::isEnabled(), C4PlayerInfo::IsJoined(), C4Network2Res::isLoading(), C4GameControl::isRecord(), C4PlayerInfo::IsTempFile(), C4PlayerList::Join(), LoadResStr(), LogF(), Network, Players, C4GameControl::RecAddFile(), C4SHead::Replay, and C4Network2::RetrieveRes().

Referenced by C4Game::InitPlayers().

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

◆ RemoveInfo()

void C4PlayerInfoList::RemoveInfo ( C4ClientPlayerInfos **  ppRemoveInfo)
inline

Definition at line 386 of file C4PlayerInfo.h.

387  { *ppRemoveInfo = ppClients[--iClientCount]; /* maybe redundant self-assignment; no vector shrink */ }

Referenced by C4Network2Players::OnClientPart(), and SetAsRestoreInfos().

Here is the caller graph for this function:

◆ RemoveUnassociatedPlayers()

void C4PlayerInfoList::RemoveUnassociatedPlayers ( C4PlayerInfoList rSavegamePlayers)

Definition at line 1611 of file C4PlayerInfo.cpp.

1612 {
1613  // check all joined infos
1614  C4ClientPlayerInfos *pClient; int iClient=0;
1615  while ((pClient = rSavegamePlayers.GetIndexedInfo(iClient++)))
1616  {
1617  C4PlayerInfo *pInfo; int iInfo = 0;
1618  while ((pInfo = pClient->GetPlayerInfo(iInfo++)))
1619  {
1620  // remove players that were in the game but are not associated
1621  if (pInfo->IsJoined() && !GetPlayerInfoBySavegameID(pInfo->GetID()))
1622  {
1623  if (::Players.RemoveUnjoined(pInfo->GetInGameNumber()))
1624  {
1625  LogF(LoadResStr("IDS_PRC_REMOVEPLR"), pInfo->GetName());
1626  }
1627  }
1628  pInfo->SetRemoved();
1629  }
1630  }
1631 }
int32_t GetInGameNumber() const
Definition: C4PlayerInfo.h:189
bool RemoveUnjoined(int32_t iPlayer)

References C4PlayerInfo::GetID(), GetIndexedInfo(), C4PlayerInfo::GetInGameNumber(), C4PlayerInfo::GetName(), C4ClientPlayerInfos::GetPlayerInfo(), GetPlayerInfoBySavegameID(), C4PlayerInfo::IsJoined(), LoadResStr(), LogF(), Players, C4PlayerList::RemoveUnjoined(), and C4PlayerInfo::SetRemoved().

Referenced by RestoreSavegameInfos().

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

◆ ResetLeagueProjectedGain()

void C4PlayerInfoList::ResetLeagueProjectedGain ( bool  fSetUpdated)

Definition at line 1716 of file C4PlayerInfo.cpp.

1717 {
1718  C4ClientPlayerInfos *pClient; int iClient=0;
1719  while ((pClient = GetIndexedInfo(iClient++)))
1720  {
1721  C4PlayerInfo *pInfo; int iInfo = 0;
1722  while ((pInfo = pClient->GetPlayerInfo(iInfo++)))
1723  if (pInfo->IsLeagueProjectedGainValid())
1724  {
1725  pInfo->ResetLeagueProjectedGain();
1726  if (fSetUpdated)
1727  pClient->SetUpdated();
1728  }
1729  }
1730 }
void ResetLeagueProjectedGain()
Definition: C4PlayerInfo.h:145
bool IsLeagueProjectedGainValid() const
Definition: C4PlayerInfo.h:190

References GetIndexedInfo(), C4ClientPlayerInfos::GetPlayerInfo(), C4PlayerInfo::IsLeagueProjectedGainValid(), C4PlayerInfo::ResetLeagueProjectedGain(), and C4ClientPlayerInfos::SetUpdated().

Referenced by C4Network2Players::HandlePlayerInfoUpdRequest(), and C4Network2Players::OnClientPart().

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

◆ ResolvePlayerAttributeConflicts()

void C4PlayerInfoList::ResolvePlayerAttributeConflicts ( C4ClientPlayerInfos pSecPacket)

Definition at line 106 of file C4PlayerInfoConflicts.cpp.

References Game, C4PlayerInfoListAttributeConflictResolver::Resolve(), and C4Game::RestorePlayerInfos.

Referenced by UpdatePlayerAttributes().

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

◆ RestoreSavegameInfos()

bool C4PlayerInfoList::RestoreSavegameInfos ( C4PlayerInfoList rSavegamePlayers)

Definition at line 1360 of file C4PlayerInfo.cpp.

1361 {
1362  // any un-associated players?
1363  if (rSavegamePlayers.GetPlayerCount())
1364  {
1365  // for runtime network joins, this should never happen!
1366  assert(!Game.C4S.Head.NetworkRuntimeJoin);
1367 
1368  // do savegame player association of real players
1369  // for non-lobby games do automatic association first
1370  int32_t iNumGrabbed = 0, i;
1371  if (!::Network.isEnabled() && Game.C4S.Head.SaveGame)
1372  {
1373  // do several passes: First passes using regular player matching; following passes matching anything but with a warning message
1374  for (int eMatchingLevel = 0; eMatchingLevel <= PML_Any; ++eMatchingLevel)
1375  for (int32_t i=0; i<iClientCount; ++i)
1376  {
1377  C4ClientPlayerInfos *pkInfo = GetIndexedInfo(i);
1378  int32_t j=0, id; C4PlayerInfo *pInfo, *pSavegameInfo;
1379  while ((pInfo = pkInfo->GetPlayerInfo(j++)))
1380  if (!(id = pInfo->GetAssociatedSavegamePlayerID()))
1381  if ((pSavegameInfo = rSavegamePlayers.FindSavegameResumePlayerInfo(pInfo, (MatchingLevel)eMatchingLevel, (MatchingLevel)eMatchingLevel)))
1382  {
1383  pInfo->SetAssociatedSavegamePlayer(pSavegameInfo->GetID());
1384  if (eMatchingLevel > PML_PlrName)
1385  {
1386  // this is a "wild" match: Warn the player (but not in replays)
1387  StdStrBuf sMsg; sMsg.Format(LoadResStr("IDS_MSG_PLAYERASSIGNMENT"), pInfo->GetName(), pSavegameInfo->GetName());
1388  Log(sMsg.getData());
1389  if (::pGUI && FullScreen.Active && !Game.C4S.Head.Replay)
1391  }
1392  }
1393  }
1394  }
1395  // association complete: evaluate it
1396  for (i=0; i<iClientCount; ++i)
1397  {
1398  C4ClientPlayerInfos *pkInfo = GetIndexedInfo(i);
1399  int32_t j=0, id; C4PlayerInfo *pInfo, *pSavegameInfo;
1400  while ((pInfo = pkInfo->GetPlayerInfo(j++)))
1401  if ((id = pInfo->GetAssociatedSavegamePlayerID()))
1402  {
1403  if ((pSavegameInfo = rSavegamePlayers.GetPlayerInfoByID(id)))
1404  {
1405  // pInfo continues for pSavegameInfo
1406  pInfo->SetSavegameResume(pSavegameInfo);
1407  ++iNumGrabbed;
1408  }
1409  else
1410  {
1411  // shouldn't happen
1412  assert(!"Invalid savegame association");
1413  }
1414  }
1415  else
1416  {
1417  // no association for this info: Joins as new player
1418  // in savegames, this is unusual. For regular script player restore, it's not
1419  if (Game.C4S.Head.SaveGame) LogF(LoadResStr("IDS_PRC_RESUMENOPLRASSOCIATION"), (const char *)pInfo->GetName());
1420  }
1421  }
1422  // otherwise any remaining players
1423  int32_t iCountRemaining = rSavegamePlayers.GetPlayerCount() - iNumGrabbed;
1424  if (iCountRemaining)
1425  {
1426  // in replay mode, if there are no regular player joins, it must have been a runtime record
1427  // i.e., a record that was started during the game
1428  // in this case, the savegame player infos equal the real player infos to be used
1429  if (::Control.isReplay() && !GetInfoCount())
1430  {
1431  *this = rSavegamePlayers;
1432  }
1433  else
1434  {
1435  // in regular mode, these players must be removed
1436  LogF(LoadResStr("IDS_PRC_RESUMEREMOVEPLRS"), iCountRemaining);
1437  // remove them directly from the game
1438  RemoveUnassociatedPlayers(rSavegamePlayers);
1439  }
1440  }
1441  }
1442  // now that players are restored, restore teams
1444  // done, success
1445  return true;
1446 }
C4FullScreen FullScreen
Definition: C4Globals.cpp:46
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1191
C4ConfigStartup Startup
Definition: C4Config.h:264
int32_t HideMsgPlrTakeOver
Definition: C4Config.h:189
bool ShowMessageModal(const char *szMessage, const char *szCaption, DWORD dwButtons, Icons icoIcon, int32_t *piConfigDontShowAgainSetting=nullptr)
bool isReplay() const
Definition: C4GameControl.h:98
bool SetSavegameResume(C4PlayerInfo *pSavegameInfo)
void RemoveUnassociatedPlayers(C4PlayerInfoList &rSavegamePlayers)
C4PlayerInfo * FindSavegameResumePlayerInfo(const C4PlayerInfo *pMatchInfo, MatchingLevel mlMatchStart, MatchingLevel mlMatchEnd) const
bool SaveGame
Definition: C4Scenario.h:71
bool Active
Definition: C4Window.h:274
@ Ico_Notify
Definition: C4Gui.h:642

References C4Window::Active, C4GUI::MessageDialog::btnOK, C4Game::C4S, Config, Control, FindSavegameResumePlayerInfo(), StdStrBuf::Format(), FullScreen, Game, C4PlayerInfo::GetAssociatedSavegamePlayerID(), StdStrBuf::getData(), C4PlayerInfo::GetID(), GetIndexedInfo(), GetInfoCount(), C4PlayerInfo::GetName(), GetPlayerCount(), C4ClientPlayerInfos::GetPlayerInfo(), GetPlayerInfoByID(), C4Scenario::Head, C4ConfigStartup::HideMsgPlrTakeOver, C4GUI::Ico_Notify, C4Network2::isEnabled(), C4GameControl::isReplay(), LoadResStr(), Log(), LogF(), Network, C4SHead::NetworkRuntimeJoin, pGUI, C4TeamList::RecheckPlayers(), RemoveUnassociatedPlayers(), C4SHead::Replay, C4SHead::SaveGame, C4PlayerInfo::SetAssociatedSavegamePlayer(), C4PlayerInfo::SetSavegameResume(), C4GUI::Screen::ShowMessageModal(), C4Config::Startup, and C4Game::Teams.

Referenced by C4Game::InitPlayers().

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

◆ Save()

bool C4PlayerInfoList::Save ( C4Group hGroup,
const char *  szToFile 
)

Definition at line 1250 of file C4PlayerInfo.cpp.

1251 {
1252  // remove previous entry from group
1253  hGroup.DeleteEntry(szToFile);
1254  // anything to save?
1255  if (!iClientCount) return true;
1256  // save it
1257  try
1258  {
1259  // decompile
1260  StdStrBuf Buf = DecompileToBuf<StdCompilerINIWrite>(
1261  mkNamingAdapt(*this, "PlayerInfoList"));
1262  // save buffer to group
1263  hGroup.Add(szToFile, Buf, false, true);
1264  }
1265  catch (StdCompiler::Exception *)
1266  { return false; }
1267  // done, success
1268  return true;
1269 }
bool DeleteEntry(const char *filename, bool do_recycle=false)
Definition: C4Group.cpp:1695
bool Add(const char *filename, const char *entry_name)
Definition: C4Group.cpp:1621

References C4Group::Add(), C4Group::DeleteEntry(), and mkNamingAdapt().

Referenced by C4GameSaveRecord::SaveComponents(), and C4Record::Stop().

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

◆ SetAsRestoreInfos()

bool C4PlayerInfoList::SetAsRestoreInfos ( C4PlayerInfoList rFromPlayers,
bool  fSaveUserPlrs,
bool  fSaveScriptPlrs,
bool  fSetUserPlrRefToLocalGroup,
bool  fSetScriptPlrRefToLocalGroup 
)

Definition at line 1633 of file C4PlayerInfo.cpp.

1634 {
1635  // copy everything
1636  *this = rFromPlayers;
1637  // then remove everything that's no longer joined and update the rest
1638  C4ClientPlayerInfos *pClient; int iClient=0;
1639  while ((pClient = GetIndexedInfo(iClient++)))
1640  {
1641  // update all players for this client
1642  C4PlayerInfo *pInfo; int iInfo = 0;
1643  while ((pInfo = pClient->GetPlayerInfo(iInfo++)))
1644  {
1645  bool fKeepInfo = false;
1646  // remove players that are not in the game
1647  if (pInfo->IsJoined())
1648  {
1649  // pre-reset filename
1650  pInfo->SetFilename(nullptr);
1651  if (pInfo->GetType() == C4PT_User)
1652  {
1653  fKeepInfo = fSaveUserPlrs;
1654  if (fSetUserPlrRefToLocalGroup)
1655  {
1656  // in the game: Set filename for inside savegame file
1657  StdStrBuf sNewName;
1658  if (::Network.isEnabled())
1659  {
1660  C4Client *pGameClient = Game.Clients.getClientByID(pClient->GetClientID());
1661  const char *szName = pGameClient ? pGameClient->getName() : "Unknown";
1662  sNewName.Format("%s-%s", szName, (const char *) GetFilename(pInfo->GetLocalJoinFilename()));
1663  }
1664  else
1665  sNewName.Copy(GetFilename(pInfo->GetFilename()));
1666 
1667  // O(n) is fast.
1668  // If not, blame whoever wrote Replace! ;)
1669  sNewName.Replace("%", "%25", 0);
1670  for (int ch = 128; ch < 256; ++ch)
1671  {
1672  const char* hexChars = "0123456789abcdef";
1673  char old[] = { char(ch), 0 };
1674  char safe[] = { '%', 'x', 'x', 0 };
1675  safe[1] = hexChars[ch / 16];
1676  safe[2] = hexChars[ch % 16];
1677  sNewName.Replace(old, safe, 0);
1678  }
1679 
1680  pInfo->SetFilename(sNewName.getData());
1681  }
1682  }
1683  else if (pInfo->GetType() == C4PT_Script)
1684  {
1685  // Save only if either all players should be saved (fSaveScriptPlrs && fSaveUserPlrs)
1686  // or if script players are saved and general scenario saving for this script player is desired
1687  fKeepInfo = fSaveScriptPlrs && (fSaveUserPlrs || pInfo->IsScenarioSaveDesired());
1688  if (fSetScriptPlrRefToLocalGroup)
1689  {
1690  // just compose a unique filename for script player
1691  pInfo->SetFilename(FormatString("ScriptPlr-%d.ocp", (int)pInfo->GetID()).getData());
1692  }
1693  }
1694  }
1695  if (!fKeepInfo)
1696  {
1697  pClient->RemoveIndexedInfo(--iInfo);
1698  }
1699  else
1700  {
1701  pInfo->DiscardResource();
1702  }
1703  }
1704  // remove empty clients
1705  if (!pClient->GetPlayerCount())
1706  {
1708  delete pClient;
1709  --iClient;
1710  }
1711  }
1712  // done
1713  return true;
1714 }
bool IsScenarioSaveDesired() const
Definition: C4PlayerInfo.h:177
void RemoveInfo(C4ClientPlayerInfos **ppRemoveInfo)
Definition: C4PlayerInfo.h:386
int Replace(const char *szOld, const char *szNew, size_t iStartSearch=0)
Definition: StdBuf.cpp:284
void Copy()
Definition: StdBuf.h:467

References C4PT_Script, C4PT_User, C4Game::Clients, StdStrBuf::Copy(), C4PlayerInfo::DiscardResource(), StdStrBuf::Format(), FormatString(), Game, C4ClientList::getClientByID(), C4ClientPlayerInfos::GetClientID(), StdStrBuf::getData(), C4PlayerInfo::GetFilename(), GetFilename(), C4PlayerInfo::GetID(), GetIndexedInfo(), GetInfoPtrByClientID(), C4PlayerInfo::GetLocalJoinFilename(), C4Client::getName(), C4ClientPlayerInfos::GetPlayerCount(), C4ClientPlayerInfos::GetPlayerInfo(), C4PlayerInfo::GetType(), C4Network2::isEnabled(), C4PlayerInfo::IsJoined(), C4PlayerInfo::IsScenarioSaveDesired(), Network, C4ClientPlayerInfos::RemoveIndexedInfo(), RemoveInfo(), StdStrBuf::Replace(), and C4PlayerInfo::SetFilename().

Here is the call graph for this function:

◆ SetIDCounter()

void C4PlayerInfoList::SetIDCounter ( int32_t  idNewCounter)
inline

Definition at line 394 of file C4PlayerInfo.h.

394 { iLastPlayerID = idNewCounter; }

Referenced by C4GameParameters::Load().

Here is the caller graph for this function:

◆ UpdatePlayerAttributes() [1/2]

void C4PlayerInfoList::UpdatePlayerAttributes ( )

Definition at line 822 of file C4PlayerInfo.cpp.

823 {
824  // update attributes of all packets
825  int32_t iIdx=0;
826  C4ClientPlayerInfos *pForInfo;
827  while ((pForInfo = GetIndexedInfo(iIdx++))) UpdatePlayerAttributes(pForInfo, false);
828  // now resole all conflicts
830 }
void ResolvePlayerAttributeConflicts(C4ClientPlayerInfos *pSecPacket)

References GetIndexedInfo(), and ResolvePlayerAttributeConflicts().

Referenced by DoLocalNonNetworkPlayerInfoUpdate().

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

◆ UpdatePlayerAttributes() [2/2]

void C4PlayerInfoList::UpdatePlayerAttributes ( C4ClientPlayerInfos pForInfo,
bool  fResolveConflicts 
)

Definition at line 780 of file C4PlayerInfo.cpp.

781 {
782  assert(pForInfo);
783  // update colors of all players of this packet
784  C4PlayerInfo *pInfo, *pInfo2; int32_t i=0;
785  while ((pInfo = pForInfo->GetPlayerInfo(i++)))
786  if (!pInfo->HasJoined())
787  {
788  // assign savegame colors
789  int32_t idSavegameID; bool fHasForcedColor = false; DWORD dwForceClr;
790  if ((idSavegameID = pInfo->GetAssociatedSavegamePlayerID()))
791  if ((pInfo2 = Game.RestorePlayerInfos.GetPlayerInfoByID(idSavegameID)))
792  {
793  dwForceClr = pInfo2->GetColor();
794  fHasForcedColor = true;
795  }
796  // assign team colors
797  if (!fHasForcedColor && Game.Teams.IsTeamColors())
798  {
799  C4Team *pPlrTeam = Game.Teams.GetTeamByID(pInfo->GetTeam());
800  if (pPlrTeam)
801  {
802  dwForceClr = pPlrTeam->GetColor();
803  fHasForcedColor = true;
804  }
805  }
806  // do color change
807  if (fHasForcedColor && (dwForceClr != pInfo->GetColor()))
808  {
809  pInfo->SetColor(dwForceClr);
810  pForInfo->SetUpdated();
811  }
812  // make sure colors have correct alpha (modified engines might send malformed packages of transparent colors)
813  if ((pInfo->GetColor() & 0xff000000u) != 0xff000000u)
814  {
815  pInfo->SetColor(pInfo->GetColor() | 0xff000000u);
816  pForInfo->SetUpdated();
817  }
818  }
819  if (fResolveConflicts) ResolvePlayerAttributeConflicts(pForInfo);
820 }
uint32_t DWORD
uint32_t GetColor() const
Definition: C4PlayerInfo.h:153
bool HasJoined() const
Definition: C4PlayerInfo.h:165
void SetColor(DWORD dwUseClr)
Definition: C4PlayerInfo.h:115
Definition: C4Teams.h:31
uint32_t GetColor() const
Definition: C4Teams.h:70
C4Team * GetTeamByID(int32_t iID) const
Definition: C4Teams.cpp:383
bool IsTeamColors() const
Definition: C4Teams.h:169

References Game, C4PlayerInfo::GetAssociatedSavegamePlayerID(), C4PlayerInfo::GetColor(), C4Team::GetColor(), C4ClientPlayerInfos::GetPlayerInfo(), GetPlayerInfoByID(), C4PlayerInfo::GetTeam(), C4TeamList::GetTeamByID(), C4PlayerInfo::HasJoined(), C4TeamList::IsTeamColors(), ResolvePlayerAttributeConflicts(), C4Game::RestorePlayerInfos, C4PlayerInfo::SetColor(), C4ClientPlayerInfos::SetUpdated(), and C4Game::Teams.

Referenced by C4Network2Players::HandlePlayerInfoUpdRequest(), C4Network2Players::OnClientPart(), and C4TeamList::SetTeamColors().

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: