OpenClonk
C4ControlJoinPlayer Struct Referenceabstract

#include <C4Control.h>

Inheritance diagram for C4ControlJoinPlayer:
[legend]
Collaboration diagram for C4ControlJoinPlayer:
[legend]

Public Member Functions

 C4ControlJoinPlayer ()=default
 
 C4ControlJoinPlayer (const char *szFilename, int32_t iAtClient, int32_t iIDInfo, C4Network2ResCore ResCore)
 
 C4ControlJoinPlayer (const char *szFilename, int32_t iAtClient, int32_t iIDInfo)
 
DECLARE_C4CONTROL_VIRTUALS bool PreExecute () const override
 
void PreRec (C4Record *pRecord) override
 
void Strip ()
 
int32_t getByClient () const
 
bool LocalControl () const
 
bool HostControl () const
 
void SetByClient (int32_t iByClient)
 
virtual void Execute () const =0
 
virtual bool Lobby () const
 
virtual bool Sync () const
 
void CompileFunc (StdCompiler *pComp) override
 
C4NetIOPacket pack (const C4NetIO::addr_t &addr=C4NetIO::addr_t()) const
 
C4NetIOPacket pack (uint8_t cStatus, const C4NetIO::addr_t &addr=C4NetIO::addr_t()) const
 
void unpack (const C4NetIOPacket &Pkt, char *pStatus=nullptr)
 

Protected Attributes

StdStrBuf Filename
 
int32_t iAtClient {-1}
 
int32_t idInfo {-1}
 
bool fByRes {false}
 
StdBuf PlrData
 
C4Network2ResCore ResCore
 
int32_t iByClient
 

Detailed Description

Definition at line 420 of file C4Control.h.

Constructor & Destructor Documentation

◆ C4ControlJoinPlayer() [1/3]

C4ControlJoinPlayer::C4ControlJoinPlayer ( )
default

◆ C4ControlJoinPlayer() [2/3]

C4ControlJoinPlayer::C4ControlJoinPlayer ( const char *  szFilename,
int32_t  iAtClient,
int32_t  iIDInfo,
C4Network2ResCore  ResCore 
)

Definition at line 1003 of file C4Control.cpp.

1004  : Filename(szFilename, true), iAtClient(iAtClient),
1005  idInfo(iIDInfo), fByRes(true), ResCore(std::move(ResCore))
1006 {
1007 }
StdStrBuf Filename
Definition: C4Control.h:427
C4Network2ResCore ResCore
Definition: C4Control.h:432

◆ C4ControlJoinPlayer() [3/3]

C4ControlJoinPlayer::C4ControlJoinPlayer ( const char *  szFilename,
int32_t  iAtClient,
int32_t  iIDInfo 
)

Definition at line 1009 of file C4Control.cpp.

1010  : Filename(szFilename, true), iAtClient(iAtClient),
1011  idInfo(iIDInfo)
1012 {
1013  // load from file if filename is given - which may not be the case for script players
1014  StdStrBuf filename;
1015  if (szFilename && Reloc.LocateItem(szFilename, filename))
1016  {
1017  bool file_is_temp = false;
1018  if (DirectoryExists(filename.getData()))
1019  {
1020  // the player file is unpacked - temp pack and read
1021  StdStrBuf filename_buf;
1022  filename_buf.Copy(Config.AtTempPath(GetFilenameOnly(filename.getData())));
1023  MakeTempFilename(&filename_buf);
1024  if (C4Group_PackDirectoryTo(filename.getData(), filename_buf.getData()))
1025  {
1026  filename.Take(filename_buf);
1027  file_is_temp = true;
1028  }
1029  else
1030  {
1031  // pack failed
1032  LogF("[!]Error packing player file %s to %s for join: Pack failed.", filename.getData(), filename_buf.getData());
1033  assert(false);
1034  }
1035  }
1036  bool fSuccess = PlrData.LoadFromFile(filename.getData());
1037  if (!fSuccess)
1038  {
1039  LogF("[!]Error loading player file from %s.", filename.getData());
1040  assert(false);
1041  }
1042  if (file_is_temp) EraseFile(filename.getData());
1043  }
1044  else if(szFilename)
1045  {
1046  LogF("[!]Error loading player file from %s.", szFilename);
1047  assert(false);
1048  }
1049 }
C4Config Config
Definition: C4Config.cpp:930
bool C4Group_PackDirectoryTo(const char *filename, const char *to_filename)
Definition: C4Group.cpp:292
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:262
C4Reloc Reloc
Definition: C4Reloc.cpp:21
bool DirectoryExists(const char *szFilename)
Definition: StdFile.cpp:708
const char * GetFilenameOnly(const char *strFilename)
Definition: StdFile.cpp:57
void MakeTempFilename(char *szFilename)
Definition: StdFile.cpp:320
bool EraseFile(const char *szFileName)
const char * AtTempPath(const char *filename)
Definition: C4Config.cpp:600
bool LocateItem(const char *filename, StdStrBuf &str) const
Definition: C4Reloc.cpp:174
bool LoadFromFile(const char *szFile)
Definition: StdBuf.cpp:32
const char * getData() const
Definition: StdBuf.h:442
void Copy()
Definition: StdBuf.h:467
void Take(char *pnData)
Definition: StdBuf.h:457

References C4Config::AtTempPath(), C4Group_PackDirectoryTo(), Config, StdStrBuf::Copy(), DirectoryExists(), EraseFile(), StdStrBuf::getData(), GetFilenameOnly(), StdBuf::LoadFromFile(), C4Reloc::LocateItem(), LogF(), MakeTempFilename(), PlrData, Reloc, and StdStrBuf::Take().

Here is the call graph for this function:

Member Function Documentation

◆ CompileFunc()

void C4ControlPacket::CompileFunc ( StdCompiler pComp)
overridevirtualinherited

Implements C4PacketBase.

Definition at line 70 of file C4Control.cpp.

71 {
72  // Section must be set by caller
73  pComp->Value(mkNamingAdapt(mkIntPackAdapt(iByClient), "ByClient", -1));
74 }
StdIntPackAdapt< T > mkIntPackAdapt(T &rVal)
Definition: StdAdaptors.h:791
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
int32_t iByClient
Definition: C4Control.h:39
void Value(const T &rStruct)
Definition: StdCompiler.h:161

References C4ControlPacket::iByClient, mkIntPackAdapt(), mkNamingAdapt(), and StdCompiler::Value().

Here is the call graph for this function:

◆ Execute()

virtual void C4ControlPacket::Execute ( ) const
pure virtualinherited

Referenced by C4GameControl::DoSyncCheck(), C4GameControl::ExecControlPacket(), and C4Control::Execute().

Here is the caller graph for this function:

◆ getByClient()

int32_t C4ControlPacket::getByClient ( ) const
inlineinherited

Definition at line 42 of file C4Control.h.

42 { return iByClient; }

References C4ControlPacket::iByClient.

Referenced by C4Network2::GetVote(), C4GameControlNetwork::HandlePacket(), and C4Network2::OpenVoteDialog().

Here is the caller graph for this function:

◆ HostControl()

bool C4ControlPacket::HostControl ( ) const
inlineinherited

Definition at line 44 of file C4Control.h.

44 { return iByClient == C4ClientIDHost; }
const int32_t C4ClientIDHost
Definition: C4Client.h:25

References C4ClientIDHost, and C4ControlPacket::iByClient.

◆ Lobby()

virtual bool C4ControlPacket::Lobby ( ) const
inlinevirtualinherited

Reimplemented in C4ControlMessage, C4ControlPlayerInfo, C4ControlClientRemove, C4ControlClientUpdate, C4ControlClientJoin, and C4ControlSet.

Definition at line 53 of file C4Control.h.

53 { return false; }

Referenced by C4GameControl::DoInput().

Here is the caller graph for this function:

◆ LocalControl()

bool C4ControlPacket::LocalControl ( ) const
inherited

Definition at line 60 of file C4Control.cpp.

61 {
62  return iByClient == ::Control.ClientID();
63 }
C4GameControl Control
int32_t ClientID() const

References C4GameControl::ClientID(), Control, and C4ControlPacket::iByClient.

Here is the call graph for this function:

◆ pack() [1/2]

C4NetIOPacket C4PacketBase::pack ( const C4NetIO::addr_t addr = C4NetIO::addr_t()) const
inherited

Definition at line 150 of file C4Packet2.cpp.

151 {
152  return C4NetIOPacket(DecompileToBuf<StdCompilerBinWrite>(*this), addr);
153 }

Referenced by MkC4NetIOPacket().

Here is the caller graph for this function:

◆ pack() [2/2]

C4NetIOPacket C4PacketBase::pack ( uint8_t  cStatus,
const C4NetIO::addr_t addr = C4NetIO::addr_t() 
) const
inherited

Definition at line 155 of file C4Packet2.cpp.

156 {
157  return C4NetIOPacket(DecompileToBuf<StdCompilerBinWrite>(mkInsertAdapt(mkDecompileAdapt(*this), cStatus)), addr);
158 }
StdInsertAdapt< T, I > mkInsertAdapt(T &&rObj, I &&rIns, bool fBefore=true)
Definition: StdAdaptors.h:469
StdDecompileAdapt< T > mkDecompileAdapt(const T &rValue)
Definition: StdAdaptors.h:153

References mkDecompileAdapt(), and mkInsertAdapt().

Here is the call graph for this function:

◆ PreExecute()

bool C4ControlJoinPlayer::PreExecute ( ) const
overridevirtual

Reimplemented from C4ControlPacket.

Definition at line 1150 of file C4Control.cpp.

1151 {
1152  // all data included in control packet?
1153  if (!fByRes) return true;
1154  // client lost?
1155  if (!Game.Clients.getClientByID(iAtClient)) return true;
1156  // network only
1157  if (!::Control.isNetwork()) return true;
1158  // search resource
1160  // doesn't exist? start loading
1161  if (!pRes) { pRes = ::Network.ResList.AddByCore(ResCore, true); }
1162  if (!pRes) return true;
1163  // is loading or removed?
1164  return !pRes->isLoading();
1165 }
C4Game Game
Definition: C4Globals.cpp:52
C4Network2 Network
Definition: C4Globals.cpp:53
C4Client * getClientByID(int32_t iID) const
Definition: C4Client.cpp:200
bool isNetwork() const
Definition: C4GameControl.h:97
C4ClientList & Clients
Definition: C4Game.h:69
C4Network2ResList ResList
Definition: C4Network2.h:113
int32_t getID() const
Definition: C4Network2Res.h:86
bool isLoading() const
C4Network2Res::Ref getRefRes(int32_t iResID)
C4Network2Res::Ref AddByCore(const C4Network2ResCore &Core, bool fLoad=true)

References C4Network2ResList::AddByCore(), C4Game::Clients, Control, fByRes, Game, C4ClientList::getClientByID(), C4Network2ResCore::getID(), C4Network2ResList::getRefRes(), iAtClient, C4Network2Res::isLoading(), C4GameControl::isNetwork(), Network, ResCore, and C4Network2::ResList.

Here is the call graph for this function:

◆ PreRec()

void C4ControlJoinPlayer::PreRec ( C4Record pRecord)
overridevirtual

Reimplemented from C4ControlPacket.

Definition at line 1167 of file C4Control.cpp.

1168 {
1169  if (!pRecord) return;
1170  if (fByRes)
1171  {
1172  // get local file by id
1174  if (!pRes || pRes->isRemoved()) return;
1175  // create a copy of the resource
1176  StdStrBuf szTemp; szTemp.Copy(pRes->getFile());
1177  MakeTempFilename(&szTemp);
1178  if (C4Group_CopyItem(pRes->getFile(), szTemp.getData()))
1179  {
1180  // add to record
1181  StdStrBuf szTarget = FormatString("%d-%s", ResCore.getID(), GetFilename(ResCore.getFileName()));
1182  pRecord->AddFile(szTemp.getData(), szTarget.getData(), true);
1183  }
1184  }
1185  else
1186  {
1187  // player data raw within control: Will be used directly in record
1188  }
1189 }
bool C4Group_CopyItem(const char *source, const char *target, bool no_sorting, bool reset_attributes)
Definition: C4Group.cpp:115
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
char * GetFilename(char *szPath)
Definition: StdFile.cpp:42
const char * getFileName() const
Definition: C4Network2Res.h:94
const char * getFile() const
bool isRemoved() const
bool AddFile(const char *szLocalFilename, const char *szAddAs, bool fDelete=false)
Definition: C4Record.cpp:266

References C4Record::AddFile(), C4Group_CopyItem(), StdStrBuf::Copy(), fByRes, FormatString(), StdStrBuf::getData(), C4Network2Res::getFile(), C4Network2ResCore::getFileName(), GetFilename(), C4Network2ResCore::getID(), C4Network2ResList::getRefRes(), C4Network2Res::isRemoved(), MakeTempFilename(), Network, ResCore, and C4Network2::ResList.

Here is the call graph for this function:

◆ SetByClient()

void C4ControlPacket::SetByClient ( int32_t  iByClient)
inherited

Definition at line 65 of file C4Control.cpp.

66 {
67  iByClient = inByClient;
68 }

References C4ControlPacket::iByClient.

◆ Strip()

void C4ControlJoinPlayer::Strip ( )

Definition at line 1120 of file C4Control.cpp.

1121 {
1122  // By resource? Can't touch player file, then.
1123  if (fByRes) return;
1124  // create temp file
1125  StdStrBuf PlayerFilename; PlayerFilename = GetFilename(Filename.getData());
1126  PlayerFilename = Config.AtTempPath(PlayerFilename.getData());
1127  // Copy to it
1128  if (PlrData.SaveToFile(PlayerFilename.getData()))
1129  {
1130  // open as group
1131  C4Group Grp;
1132  if (!Grp.Open(PlayerFilename.getData()))
1133  { EraseFile(PlayerFilename.getData()); return; }
1134  // remove bigicon, if the file size is too large
1135  size_t iBigIconSize=0;
1136  if (Grp.FindEntry(C4CFN_BigIcon, nullptr, &iBigIconSize))
1137  if (iBigIconSize > C4NetResMaxBigicon*1024)
1138  Grp.Delete(C4CFN_BigIcon);
1139  Grp.Close();
1140  // Set new data
1141  StdBuf NewPlrData;
1142  if (!NewPlrData.LoadFromFile(PlayerFilename.getData()))
1143  { EraseFile(PlayerFilename.getData()); return; }
1144  PlrData = std::move(NewPlrData);
1145  // Done
1146  EraseFile(PlayerFilename.getData());
1147  }
1148 }
#define C4CFN_BigIcon
Definition: C4Components.h:111
const int32_t C4NetResMaxBigicon
Definition: C4Network2Res.h:36
bool Close()
Definition: C4Group.cpp:971
bool Delete(const char *files, bool recursive=false)
Definition: C4Group.cpp:1645
bool FindEntry(const char *wildcard, StdStrBuf *filename=nullptr, size_t *size=nullptr)
Definition: C4Group.cpp:2211
bool Open(const char *group_name, bool do_create=false)
Definition: C4Group.cpp:660
Definition: StdBuf.h:30
bool SaveToFile(const char *szFile) const
Definition: StdBuf.cpp:53

References C4Config::AtTempPath(), C4CFN_BigIcon, C4NetResMaxBigicon, C4Group::Close(), Config, C4Group::Delete(), EraseFile(), fByRes, Filename, C4Group::FindEntry(), StdStrBuf::getData(), GetFilename(), StdBuf::LoadFromFile(), C4Group::Open(), PlrData, and StdBuf::SaveToFile().

Referenced by C4Playback::Strip().

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

◆ Sync()

virtual bool C4ControlPacket::Sync ( ) const
inlinevirtualinherited

Reimplemented in C4ControlVoteEnd, C4ControlVote, C4ControlMessage, C4ControlPlayerInfo, C4ControlClientRemove, C4ControlClientUpdate, C4ControlClientJoin, and C4ControlSyncCheck.

Definition at line 55 of file C4Control.h.

55 { return true; }

Referenced by C4Playback::Check(), and C4GameControl::DoInput().

Here is the caller graph for this function:

◆ unpack()

void C4PacketBase::unpack ( const C4NetIOPacket Pkt,
char *  pStatus = nullptr 
)
inherited

Definition at line 160 of file C4Packet2.cpp.

161 {
162  if (pStatus) *pStatus = Pkt.getStatus();
163  CompileFromBuf<StdCompilerBinRead>(*this, pStatus ? Pkt.getPBuf() : Pkt.getRef());
164 }
uint8_t getStatus() const
Definition: C4NetIO.h:319
StdBuf getPBuf() const
Definition: C4NetIO.h:322
C4NetIOPacket getRef() const
Definition: C4NetIO.h:325

References C4NetIOPacket::getPBuf(), C4NetIOPacket::getRef(), and C4NetIOPacket::getStatus().

Referenced by C4IDPacket::C4IDPacket(), and C4Network2IO::HandlePacket().

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

Member Data Documentation

◆ fByRes

bool C4ControlJoinPlayer::fByRes {false}
protected

Definition at line 430 of file C4Control.h.

Referenced by PreExecute(), PreRec(), and Strip().

◆ Filename

StdStrBuf C4ControlJoinPlayer::Filename
protected

Definition at line 427 of file C4Control.h.

Referenced by Strip().

◆ iAtClient

int32_t C4ControlJoinPlayer::iAtClient {-1}
protected

Definition at line 428 of file C4Control.h.

Referenced by PreExecute().

◆ iByClient

◆ idInfo

int32_t C4ControlJoinPlayer::idInfo {-1}
protected

Definition at line 429 of file C4Control.h.

◆ PlrData

StdBuf C4ControlJoinPlayer::PlrData
protected

Definition at line 431 of file C4Control.h.

Referenced by C4ControlJoinPlayer(), and Strip().

◆ ResCore

C4Network2ResCore C4ControlJoinPlayer::ResCore
protected

Definition at line 432 of file C4Control.h.

Referenced by PreExecute(), and PreRec().


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