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 ()=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::C4ControlJoinPlayer ( )
default
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 }
C4Network2ResCore ResCore
Definition: C4Control.h:432
StdStrBuf Filename
Definition: C4Control.h:427
C4ControlJoinPlayer::C4ControlJoinPlayer ( const char *  szFilename,
int32_t  iAtClient,
int32_t  iIDInfo 
)

Definition at line 1009 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().

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 }
const char * getData() const
Definition: StdBuf.h:442
C4Config Config
Definition: C4Config.cpp:833
bool LoadFromFile(const char *szFile)
Definition: StdBuf.cpp:32
StdStrBuf Filename
Definition: C4Control.h:427
const char * GetFilenameOnly(const char *strFilename)
Definition: StdFile.cpp:60
bool C4Group_PackDirectoryTo(const char *szFilename, const char *szFilenameTo)
Definition: C4Group.cpp:221
void Take(char *pnData)
Definition: StdBuf.h:457
bool EraseFile(const char *szFileName)
C4Reloc Reloc
Definition: C4Reloc.cpp:21
bool DirectoryExists(const char *szFilename)
Definition: StdFile.cpp:684
const char * AtTempPath(const char *szFilename)
Definition: C4Config.cpp:540
void MakeTempFilename(char *szFilename)
Definition: StdFile.cpp:323
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:250
void Copy()
Definition: StdBuf.h:467
bool LocateItem(const char *filename, StdStrBuf &str) const
Definition: C4Reloc.cpp:93

Here is the call graph for this function:

Member Function Documentation

void C4ControlPacket::CompileFunc ( StdCompiler pComp)
overridevirtualinherited

Implements C4PacketBase.

Definition at line 70 of file C4Control.cpp.

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

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

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 60 of file C4Control.cpp.

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

61 {
62  return iByClient == ::Control.ClientID();
63 }
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 149 of file C4Packet2.cpp.

Referenced by MkC4NetIOPacket().

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

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 154 of file C4Packet2.cpp.

References mkDecompileAdapt(), and mkInsertAdapt().

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

Here is the call graph for this function:

bool C4ControlJoinPlayer::PreExecute ( ) const
overridevirtual

Reimplemented from C4ControlPacket.

Definition at line 1150 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.

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 }
C4Network2Res::Ref AddByCore(const C4Network2ResCore &Core, bool fLoad=true)
C4Network2ResCore ResCore
Definition: C4Control.h:432
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:200
C4ClientList & Clients
Definition: C4Game.h:69

Here is the call graph for this function:

void C4ControlJoinPlayer::PreRec ( C4Record pRecord)
overridevirtual

Reimplemented from C4ControlPacket.

Definition at line 1167 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.

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 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:45
const char * getData() const
Definition: StdBuf.h:442
C4Network2ResCore ResCore
Definition: C4Control.h:432
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:323
bool AddFile(const char *szLocalFilename, const char *szAddAs, bool fDelete=false)
Definition: C4Record.cpp:266
void Copy()
Definition: StdBuf.h:467
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

Here is the call graph for this function:

void C4ControlPacket::SetByClient ( int32_t  iByClient)
inherited

Definition at line 65 of file C4Control.cpp.

References C4ControlPacket::iByClient.

66 {
67  iByClient = inByClient;
68 }
int32_t iByClient
Definition: C4Control.h:39
void C4ControlJoinPlayer::Strip ( )

Definition at line 1120 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().

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 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:45
const char * getData() const
Definition: StdBuf.h:442
bool FindEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr)
Definition: C4Group.cpp:1774
C4Config Config
Definition: C4Config.cpp:833
Definition: StdBuf.h:29
bool LoadFromFile(const char *szFile)
Definition: StdBuf.cpp:32
StdStrBuf Filename
Definition: C4Control.h:427
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 EraseFile(const char *szFileName)
bool SaveToFile(const char *szFile) const
Definition: StdBuf.cpp:53
#define C4CFN_BigIcon
Definition: C4Components.h:111
const char * AtTempPath(const char *szFilename)
Definition: C4Config.cpp:540
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 159 of file C4Packet2.cpp.

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

bool C4ControlJoinPlayer::fByRes {false}
protected

Definition at line 430 of file C4Control.h.

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

StdStrBuf C4ControlJoinPlayer::Filename
protected

Definition at line 427 of file C4Control.h.

Referenced by Strip().

int32_t C4ControlJoinPlayer::iAtClient {-1}
protected

Definition at line 428 of file C4Control.h.

Referenced by PreExecute().

int32_t C4ControlPacket::iByClient
protectedinherited
int32_t C4ControlJoinPlayer::idInfo {-1}
protected

Definition at line 429 of file C4Control.h.

StdBuf C4ControlJoinPlayer::PlrData
protected

Definition at line 431 of file C4Control.h.

Referenced by C4ControlJoinPlayer(), and Strip().

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: