OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4ControlJoinPlayer Struct Referenceabstract

#include <C4Control.h>

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

Public Member Functions

 C4ControlJoinPlayer ()
 
 C4ControlJoinPlayer (const char *szFilename, int32_t iAtClient, int32_t iIDInfo, const C4Network2ResCore &ResCore)
 
 C4ControlJoinPlayer (const char *szFilename, int32_t iAtClient, int32_t iIDInfo)
 
virtual
DECLARE_C4CONTROL_VIRTUALS
bool 
PreExecute () const
 
virtual void PreRec (C4Record *pRecord)
 
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
 
virtual void CompileFunc (StdCompiler *pComp)
 
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
 
int32_t idInfo
 
bool fByRes
 
StdBuf PlrData
 
C4Network2ResCore ResCore
 
int32_t iByClient
 

Detailed Description

Definition at line 427 of file C4Control.h.

Constructor & Destructor Documentation

C4ControlJoinPlayer::C4ControlJoinPlayer ( )
inline

Definition at line 430 of file C4Control.h.

430 : iAtClient(-1), idInfo(-1), fByRes(false) { }
C4ControlJoinPlayer::C4ControlJoinPlayer ( const char *  szFilename,
int32_t  iAtClient,
int32_t  iIDInfo,
const C4Network2ResCore ResCore 
)

Definition at line 1015 of file C4Control.cpp.

1016  : Filename(szFilename, true), iAtClient(iAtClient),
1017  idInfo(iIDInfo), fByRes(true), ResCore(ResCore)
1018 {
1019 }
C4Network2ResCore ResCore
Definition: C4Control.h:439
StdStrBuf Filename
Definition: C4Control.h:434
C4ControlJoinPlayer::C4ControlJoinPlayer ( const char *  szFilename,
int32_t  iAtClient,
int32_t  iIDInfo 
)

Definition at line 1021 of file C4Control.cpp.

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

1022  : Filename(szFilename, true), iAtClient(iAtClient),
1023  idInfo(iIDInfo), fByRes(false)
1024 {
1025  // load from file if filename is given - which may not be the case for script players
1026  StdStrBuf filename;
1027  if (szFilename && Reloc.LocateItem(szFilename, filename))
1028  {
1029  bool file_is_temp = false;
1030  if (DirectoryExists(filename.getData()))
1031  {
1032  // the player file is unpacked - temp pack and read
1033  StdStrBuf filename_buf;
1034  filename_buf.Copy(Config.AtTempPath(GetFilenameOnly(filename.getData())));
1035  MakeTempFilename(&filename_buf);
1036  if (C4Group_PackDirectoryTo(filename.getData(), filename_buf.getData()))
1037  {
1038  filename.Take(filename_buf);
1039  file_is_temp = true;
1040  }
1041  else
1042  {
1043  // pack failed
1044  LogF("[!]Error packing player file %s to %s for join: Pack failed.", filename.getData(), filename_buf.getData());
1045  assert(false);
1046  }
1047  }
1048  bool fSuccess = PlrData.LoadFromFile(filename.getData());
1049  if (!fSuccess)
1050  {
1051  LogF("[!]Error loading player file from %s.", filename.getData());
1052  assert(false);
1053  }
1054  if (file_is_temp) EraseFile(filename.getData());
1055  }
1056  else if(szFilename)
1057  {
1058  LogF("[!]Error loading player file from %s.", szFilename);
1059  assert(false);
1060  }
1061 }
const char * getData() const
Definition: StdBuf.h:450
C4Config Config
Definition: C4Config.cpp:831
bool EraseFile(const char *szFilename)
Definition: StdFile.cpp:495
bool LoadFromFile(const char *szFile)
Definition: StdBuf.cpp:39
StdStrBuf Filename
Definition: C4Control.h:434
const char * GetFilenameOnly(const char *strFilename)
Definition: StdFile.cpp:70
bool C4Group_PackDirectoryTo(const char *szFilename, const char *szFilenameTo)
Definition: C4Group.cpp:221
void Take(char *pnData)
Definition: StdBuf.h:465
C4Reloc Reloc
Definition: C4Reloc.cpp:22
bool DirectoryExists(const char *szFilename)
Definition: StdFile.cpp:694
const char * AtTempPath(const char *szFilename)
Definition: C4Config.cpp:538
void MakeTempFilename(char *szFilename)
Definition: StdFile.cpp:333
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253
void Copy()
Definition: StdBuf.h:475
bool LocateItem(const char *filename, StdStrBuf &str) const
Definition: C4Reloc.cpp:80

Here is the call graph for this function:

Member Function Documentation

void C4ControlPacket::CompileFunc ( StdCompiler pComp)
virtualinherited

Implements C4PacketBase.

Definition at line 77 of file C4Control.cpp.

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

78 {
79  // Section must be set by caller
80  pComp->Value(mkNamingAdapt(mkIntPackAdapt(iByClient), "ByClient", -1));
81 }
int32_t iByClient
Definition: C4Control.h:39
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
void Value(const T &rStruct)
Definition: StdCompiler.h:171
StdIntPackAdapt< T > mkIntPackAdapt(T &rVal)
Definition: StdAdaptors.h:757

Here is the call graph for this function:

virtual void C4ControlPacket::Execute ( ) const
pure virtualinherited

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

Here is the caller graph for this function:

int32_t C4ControlPacket::getByClient ( ) const
inlineinherited

Definition at line 42 of file C4Control.h.

References C4ControlPacket::iByClient.

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

42 { return iByClient; }
int32_t iByClient
Definition: C4Control.h:39

Here is the caller graph for this function:

bool C4ControlPacket::HostControl ( ) const
inlineinherited

Definition at line 44 of file C4Control.h.

References C4ClientIDHost.

44 { return iByClient == C4ClientIDHost; }
int32_t iByClient
Definition: C4Control.h:39
const int32_t C4ClientIDHost
Definition: C4Client.h:25
virtual bool C4ControlPacket::Lobby ( ) const
inlinevirtualinherited

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

Definition at line 53 of file C4Control.h.

Referenced by C4GameControl::DoInput().

53 { return false; }

Here is the caller graph for this function:

bool C4ControlPacket::LocalControl ( ) const
inherited

Definition at line 67 of file C4Control.cpp.

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

68 {
69  return iByClient == ::Control.ClientID();
70 }
int32_t iByClient
Definition: C4Control.h:39
C4GameControl Control
int32_t ClientID() const

Here is the call graph for this function:

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

Definition at line 156 of file C4Packet2.cpp.

Referenced by MkC4NetIOPacket().

157 {
158  return C4NetIOPacket(DecompileToBuf<StdCompilerBinWrite>(*this), addr);
159 }

Here is the caller graph for this function:

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

Definition at line 161 of file C4Packet2.cpp.

References mkDecompileAdapt(), and mkInsertAdapt().

162 {
163  return C4NetIOPacket(DecompileToBuf<StdCompilerBinWrite>(mkInsertAdapt(mkDecompileAdapt(*this), cStatus)), addr);
164 }
StdDecompileAdapt< T > mkDecompileAdapt(const T &rValue)
Definition: StdAdaptors.h:154
StdInsertAdapt< T, I > mkInsertAdapt(T &&rObj, I &&rIns, bool fBefore=true)
Definition: StdAdaptors.h:435

Here is the call graph for this function:

bool C4ControlJoinPlayer::PreExecute ( ) const
virtual

Reimplemented from C4ControlPacket.

Definition at line 1162 of file C4Control.cpp.

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

1163 {
1164  // all data included in control packet?
1165  if (!fByRes) return true;
1166  // client lost?
1167  if (!Game.Clients.getClientByID(iAtClient)) return true;
1168  // network only
1169  if (!::Control.isNetwork()) return true;
1170  // search resource
1172  // doesn't exist? start loading
1173  if (!pRes) { pRes = ::Network.ResList.AddByCore(ResCore, true); }
1174  if (!pRes) return true;
1175  // is loading or removed?
1176  return !pRes->isLoading();
1177 }
C4Network2Res::Ref AddByCore(const C4Network2ResCore &Core, bool fLoad=true)
C4Network2ResCore ResCore
Definition: C4Control.h:439
C4Game Game
Definition: C4Globals.cpp:52
bool isLoading() const
int32_t getID() const
Definition: C4Network2Res.h:86
bool isNetwork() const
Definition: C4GameControl.h:97
C4Network2 Network
Definition: C4Globals.cpp:53
C4GameControl Control
C4Network2Res::Ref getRefRes(int32_t iResID)
C4Network2ResList ResList
Definition: C4Network2.h:113
C4Client * getClientByID(int32_t iID) const
Definition: C4Client.cpp:217
C4ClientList & Clients
Definition: C4Game.h:71

Here is the call graph for this function:

void C4ControlJoinPlayer::PreRec ( C4Record pRecord)
virtual

Reimplemented from C4ControlPacket.

Definition at line 1179 of file C4Control.cpp.

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

1180 {
1181  if (!pRecord) return;
1182  if (fByRes)
1183  {
1184  // get local file by id
1186  if (!pRes || pRes->isRemoved()) return;
1187  // create a copy of the resource
1188  StdStrBuf szTemp; szTemp.Copy(pRes->getFile());
1189  MakeTempFilename(&szTemp);
1190  if (C4Group_CopyItem(pRes->getFile(), szTemp.getData()))
1191  {
1192  // add to record
1193  StdStrBuf szTarget = FormatString("%d-%s", ResCore.getID(), GetFilename(ResCore.getFileName()));
1194  pRecord->AddFile(szTemp.getData(), szTarget.getData(), true);
1195  }
1196  }
1197  else
1198  {
1199  // player data raw within control: Will be used directly in record
1200  }
1201 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:55
const char * getData() const
Definition: StdBuf.h:450
C4Network2ResCore ResCore
Definition: C4Control.h:439
const char * getFileName() const
Definition: C4Network2Res.h:94
const char * getFile() const
int32_t getID() const
Definition: C4Network2Res.h:86
C4Network2 Network
Definition: C4Globals.cpp:53
bool C4Group_CopyItem(const char *szSource, const char *szTarget1, bool fNoSort, bool fResetAttributes)
Definition: C4Group.cpp:100
C4Network2Res::Ref getRefRes(int32_t iResID)
C4Network2ResList ResList
Definition: C4Network2.h:113
bool isRemoved() const
void MakeTempFilename(char *szFilename)
Definition: StdFile.cpp:333
bool AddFile(const char *szLocalFilename, const char *szAddAs, bool fDelete=false)
Definition: C4Record.cpp:275
void Copy()
Definition: StdBuf.h:475
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277

Here is the call graph for this function:

void C4ControlPacket::SetByClient ( int32_t  iByClient)
inherited

Definition at line 72 of file C4Control.cpp.

References C4ControlPacket::iByClient.

73 {
74  iByClient = inByClient;
75 }
int32_t iByClient
Definition: C4Control.h:39
void C4ControlJoinPlayer::Strip ( )

Definition at line 1132 of file C4Control.cpp.

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

1133 {
1134  // By resource? Can't touch player file, then.
1135  if (fByRes) return;
1136  // create temp file
1137  StdStrBuf PlayerFilename; PlayerFilename = GetFilename(Filename.getData());
1138  PlayerFilename = Config.AtTempPath(PlayerFilename.getData());
1139  // Copy to it
1140  if (PlrData.SaveToFile(PlayerFilename.getData()))
1141  {
1142  // open as group
1143  C4Group Grp;
1144  if (!Grp.Open(PlayerFilename.getData()))
1145  { EraseFile(PlayerFilename.getData()); return; }
1146  // remove bigicon, if the file size is too large
1147  size_t iBigIconSize=0;
1148  if (Grp.FindEntry(C4CFN_BigIcon, nullptr, &iBigIconSize))
1149  if (iBigIconSize > C4NetResMaxBigicon*1024)
1150  Grp.Delete(C4CFN_BigIcon);
1151  Grp.Close();
1152  // Set new data
1153  StdBuf NewPlrData;
1154  if (!NewPlrData.LoadFromFile(PlayerFilename.getData()))
1155  { EraseFile(PlayerFilename.getData()); return; }
1156  PlrData = std::move(NewPlrData);
1157  // Done
1158  EraseFile(PlayerFilename.getData());
1159  }
1160 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:55
const char * getData() const
Definition: StdBuf.h:450
bool FindEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr)
Definition: C4Group.cpp:1774
C4Config Config
Definition: C4Config.cpp:831
Definition: StdBuf.h:37
bool EraseFile(const char *szFilename)
Definition: StdFile.cpp:495
bool LoadFromFile(const char *szFile)
Definition: StdBuf.cpp:39
StdStrBuf Filename
Definition: C4Control.h:434
bool Delete(const char *szFiles, bool fRecursive=false)
Definition: C4Group.cpp:1334
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
bool Close()
Definition: C4Group.cpp:755
bool SaveToFile(const char *szFile) const
Definition: StdBuf.cpp:60
#define C4CFN_BigIcon
Definition: C4Components.h:111
const char * AtTempPath(const char *szFilename)
Definition: C4Config.cpp:538
const int32_t C4NetResMaxBigicon
Definition: C4Network2Res.h:36

Here is the call graph for this function:

Here is the caller graph for this function:

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.

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

55 { return true; }

Here is the caller graph for this function:

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

Definition at line 166 of file C4Packet2.cpp.

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

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

167 {
168  if (pStatus) *pStatus = Pkt.getStatus();
169  CompileFromBuf<StdCompilerBinRead>(*this, pStatus ? Pkt.getPBuf() : Pkt.getRef());
170 }
StdBuf getPBuf() const
Definition: C4NetIO.h:321
C4NetIOPacket getRef() const
Definition: C4NetIO.h:324
uint8_t getStatus() const
Definition: C4NetIO.h:318

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

bool C4ControlJoinPlayer::fByRes
protected

Definition at line 437 of file C4Control.h.

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

StdStrBuf C4ControlJoinPlayer::Filename
protected

Definition at line 434 of file C4Control.h.

Referenced by Strip().

int32_t C4ControlJoinPlayer::iAtClient
protected

Definition at line 435 of file C4Control.h.

Referenced by PreExecute().

int32_t C4ControlPacket::iByClient
protectedinherited
int32_t C4ControlJoinPlayer::idInfo
protected

Definition at line 436 of file C4Control.h.

StdBuf C4ControlJoinPlayer::PlrData
protected

Definition at line 438 of file C4Control.h.

Referenced by C4ControlJoinPlayer(), and Strip().

C4Network2ResCore C4ControlJoinPlayer::ResCore
protected

Definition at line 439 of file C4Control.h.

Referenced by PreExecute(), and PreRec().


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