OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Network2Res Class Reference

#include <C4Network2Res.h>

Collaboration diagram for C4Network2Res:
[legend]

Classes

struct  ClientChunks
 
class  Ref
 

Public Member Functions

 C4Network2Res (C4Network2ResList *pnParent)
 
 ~C4Network2Res ()
 
C4Network2ResType getType () const
 
const C4Network2ResCoregetCore () const
 
bool isDirty () const
 
bool isAnonymous () const
 
int32_t getResID () const
 
int32_t getResClient () const
 
const char * getFile () const
 
CStdCSecgetFileCSec ()
 
int32_t getLastReqTime () const
 
bool isRemoved () const
 
bool isLoading () const
 
bool isComplete () const
 
int32_t getPresentPercent () const
 
bool isTempFile () const
 
bool SetByFile (const char *strFilePath, bool fTemp, C4Network2ResType eType, int32_t iResID, const char *szResName=nullptr, bool fSilent=false)
 
bool SetByGroup (C4Group *pGrp, bool fTemp, C4Network2ResType eType, int32_t iResID, const char *szResName=nullptr, bool fSilent=false)
 
bool SetByCore (const C4Network2ResCore &nCore, bool fSilent=false, const char *szAsFilename=nullptr, int32_t iRecursion=0)
 
bool SetLoad (const C4Network2ResCore &nCore)
 
bool SetDerived (const char *strName, const char *strFilePath, bool fTemp, C4Network2ResType eType, int32_t iDResID)
 
void ChangeID (int32_t inID)
 
bool IsBinaryCompatible ()
 
bool GetStandalone (char *pTo, int32_t iMaxL, bool fSetOfficial, bool fAllowUnloadable=false, bool fSilent=false)
 
bool CalculateSHA ()
 
bool SaveBackFile ()
 
C4Network2Res::Ref Derive ()
 
bool FinishDerive ()
 
bool FinishDerive (const C4Network2ResCore &nCore)
 
bool SendStatus (C4Network2IOConnection *pTo=nullptr)
 
bool SendChunk (uint32_t iChunk, int32_t iToClient)
 
void AddRef ()
 
void DelRef ()
 
void OnDiscover (C4Network2IOConnection *pBy)
 
void OnStatus (const C4Network2ResChunkData &rChunkData, C4Network2IOConnection *pBy)
 
void OnChunk (const C4Network2ResChunk &rChunk)
 
bool DoLoad ()
 
bool NeedsDiscover ()
 
C4GroupOpenAsGrp () const
 
void Remove ()
 
void Clear ()
 

Protected Member Functions

int32_t OpenFileRead ()
 
int32_t OpenFileWrite ()
 
void StartNewLoads ()
 
bool StartLoad (int32_t iFromClient, const C4Network2ResChunkData &Chunks)
 
void EndLoad ()
 
void ClearLoad ()
 
void RemoveLoad (C4Network2ResLoad *pLoad)
 
void RemoveCChunks (ClientChunks *pChunks)
 
bool OptimizeStandalone (bool fSilent)
 

Protected Attributes

C4Network2ResCore Core
 
C4Network2ResChunkData Chunks
 
bool fDirty
 
CStdCSec FileCSec
 
char szFile [_MAX_PATH+1]
 
char szStandalone [_MAX_PATH+1]
 
bool fTempFile
 
bool fStandaloneFailed
 
std::atomic_long iRefCnt
 
bool fRemoved
 
int32_t iLastReqTime
 
bool fLoading
 
struct
C4Network2Res::ClientChunks
pCChunks
 
time_t iDiscoverStartTime
 
C4Network2ResLoadpLoads
 
int32_t iLoadCnt
 
C4Network2RespNext
 
C4Network2ResListpParent
 

Friends

class C4Network2ResList
 
class C4Network2ResChunk
 

Detailed Description

Definition at line 178 of file C4Network2Res.h.


Class Documentation

struct C4Network2Res::ClientChunks

Definition at line 227 of file C4Network2Res.h.

Collaboration diagram for C4Network2Res::ClientChunks:
[legend]
Class Members
C4Network2ResChunkData Chunks
int32_t ClientID
ClientChunks * Next

Constructor & Destructor Documentation

C4Network2Res::C4Network2Res ( C4Network2ResList pnParent)

Definition at line 356 of file C4Network2Res.cpp.

References szFile, and szStandalone.

Referenced by Derive().

357  : fDirty(false),
358  fTempFile(false), fStandaloneFailed(false),
359  iRefCnt(0), fRemoved(false),
360  iLastReqTime(0),
361  fLoading(false),
362  pCChunks(nullptr), iDiscoverStartTime(0), pLoads(nullptr), iLoadCnt(0),
363  pNext(nullptr),
364  pParent(pnParent)
365 {
366  szFile[0] = szStandalone[0] = '\0';
367 }
bool fStandaloneFailed
int32_t iLastReqTime
time_t iDiscoverStartTime
int32_t iLoadCnt
struct C4Network2Res::ClientChunks * pCChunks
char szStandalone[_MAX_PATH+1]
C4Network2ResList * pParent
char szFile[_MAX_PATH+1]
C4Network2ResLoad * pLoads
std::atomic_long iRefCnt
C4Network2Res * pNext

Here is the caller graph for this function:

C4Network2Res::~C4Network2Res ( )

Definition at line 369 of file C4Network2Res.cpp.

References Clear(), and pNext.

370 {
371  assert(!pNext);
372  Clear();
373 }
C4Network2Res * pNext

Here is the call graph for this function:

Member Function Documentation

void C4Network2Res::AddRef ( )

Definition at line 848 of file C4Network2Res.cpp.

References iRefCnt.

Referenced by C4Network2ResList::Add(), C4Network2Res::Ref::Ref(), and C4Network2Res::Ref::Set().

849 {
850  ++iRefCnt;
851 }
std::atomic_long iRefCnt

Here is the caller graph for this function:

bool C4Network2Res::CalculateSHA ( )

Definition at line 673 of file C4Network2Res.cpp.

References _MAX_PATH, Core, GetFileSHA1(), GetStandalone(), C4Network2ResCore::hasFileSHA(), SCopy(), C4Network2ResCore::SetFileSHA(), SHA_DIGEST_LENGTH, szFile, and szStandalone.

Referenced by C4GameRes::CalcHash().

674 {
675  // already present?
676  if (Core.hasFileSHA()) return true;
677  // get the file
678  char szStandalone[_MAX_PATH + 1];
679  if (!GetStandalone(szStandalone, _MAX_PATH, false))
680  SCopy(szFile, szStandalone, _MAX_PATH);
681  // get the hash
682  BYTE hash[SHA_DIGEST_LENGTH];
683  if (!GetFileSHA1(szStandalone, hash))
684  return false;
685  // save it back
686  Core.SetFileSHA(hash);
687  // okay
688  return true;
689 }
#define SHA_DIGEST_LENGTH
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
bool GetFileSHA1(const char *szFilename, BYTE *pSHA1)
Definition: CStdFile.cpp:385
uint8_t BYTE
void SetFileSHA(BYTE *pSHA)
#define _MAX_PATH
C4Network2ResCore Core
bool GetStandalone(char *pTo, int32_t iMaxL, bool fSetOfficial, bool fAllowUnloadable=false, bool fSilent=false)
bool hasFileSHA() const
Definition: C4Network2Res.h:92
char szStandalone[_MAX_PATH+1]
char szFile[_MAX_PATH+1]

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2Res::ChangeID ( int32_t  inID)

Definition at line 547 of file C4Network2Res.cpp.

References Core, and C4Network2ResCore::SetID().

548 {
549  Core.SetID(inID);
550 }
C4Network2ResCore Core
void SetID(int32_t inID)
Definition: C4Network2Res.h:99

Here is the call graph for this function:

void C4Network2Res::Clear ( )

Definition at line 972 of file C4Network2Res.cpp.

References Chunks, C4Network2ResCore::Clear(), C4Network2ResChunkData::Clear(), ClearLoad(), Core, EraseFile(), fDirty, FileCSec, FileExists(), fRemoved, fTempFile, LogSilentF(), SEqual(), szFile, and szStandalone.

Referenced by SetByGroup(), SetDerived(), SetLoad(), and ~C4Network2Res().

973 {
974  CStdLock FileLock(&FileCSec);
975  // delete files
976  if (fTempFile)
977  if (FileExists(szFile))
978  if (!EraseFile(szFile))
979  LogSilentF("Network: Could not delete temporary resource file (%s)", strerror(errno));
980  if (szStandalone[0] && !SEqual(szFile, szStandalone))
982  if (!EraseFile(szStandalone))
983  LogSilentF("Network: Could not delete temporary resource file (%s)", strerror(errno));
984  szFile[0] = szStandalone[0] = '\0';
985  fDirty = false;
986  fTempFile = false;
987  Core.Clear();
988  Chunks.Clear();
989  fRemoved = false;
990  ClearLoad();
991 }
bool EraseFile(const char *szFilename)
Definition: StdFile.cpp:495
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97
bool LogSilentF(const char *strMessage,...)
Definition: C4Log.cpp:263
C4Network2ResCore Core
char szStandalone[_MAX_PATH+1]
char szFile[_MAX_PATH+1]
bool FileExists(const char *szFilename)
Definition: StdFile.cpp:439
C4Network2ResChunkData Chunks
CStdCSec FileCSec

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2Res::ClearLoad ( )
protected

Definition at line 1113 of file C4Network2Res.cpp.

References fLoading, iDiscoverStartTime, iLoadCnt, pCChunks, pLoads, RemoveCChunks(), and RemoveLoad().

Referenced by Clear(), and EndLoad().

1114 {
1115  // remove client chunks and loads
1116  fLoading = false;
1117  while (pCChunks) RemoveCChunks(pCChunks);
1118  while (pLoads) RemoveLoad(pLoads);
1120 }
void RemoveLoad(C4Network2ResLoad *pLoad)
time_t iDiscoverStartTime
int32_t iLoadCnt
struct C4Network2Res::ClientChunks * pCChunks
void RemoveCChunks(ClientChunks *pChunks)
C4Network2ResLoad * pLoads

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2Res::DelRef ( )

Definition at line 853 of file C4Network2Res.cpp.

References iRefCnt.

Referenced by C4Network2Res::Ref::Clear().

854 {
855  if (--iRefCnt == 0)
856  delete this;
857 }
std::atomic_long iRefCnt

Here is the caller graph for this function:

C4Network2Res::Ref C4Network2Res::Derive ( )

Definition at line 692 of file C4Network2Res.cpp.

References _MAX_PATH, C4Network2ResList::Add(), Application, C4Group_CopyItem(), C4Network2Res(), Core, FileCSec, C4Network2ResList::FindTempResFileName(), fTempFile, C4Network2ResCore::getFileName(), getResID(), getType(), C4Application::InteractiveThread, isLoading(), Log(), pParent, SCopy(), SEqual(), SetDerived(), szFile, szStandalone, and C4InteractiveThread::ThreadLogS().

Referenced by C4Player::Save().

693 {
694  // Called before the file is changed. Rescues all files and creates a
695  // new resource for the file. This resource is flagged as "anonymous", as it
696  // has no official core (no res ID, to be exact).
697  // The resource gets its final core when FinishDerive() is called.
698 
699  // For security: This doesn't make much sense if the resource is currently being
700  // loaded. So better assume the caller doesn't know what he's doing and check.
701  if (isLoading()) return nullptr;
702 
703  CStdLock FileLock(&FileCSec);
704  // Save back original file name
705  char szOrgFile[_MAX_PATH+1];
706  SCopy(szFile, szOrgFile, _MAX_PATH);
707  bool fOrgTempFile = fTempFile;
708 
709  // Create a copy of the file, if neccessary
711  {
712  if (!pParent->FindTempResFileName(szOrgFile, szFile))
713  { Log("Derive: could not find free name for temporary file!"); return nullptr; }
714  if (!C4Group_CopyItem(szOrgFile, szFile))
715  { Log("Derive: could not copy to temporary file!"); return nullptr; }
716  // set standalone
717  if (*szStandalone)
719  fTempFile = true;
720  }
721  else
722  {
723  // Standlone exists: Just set szFile to point on the standlone. It's
724  // assumed that the original file isn't of intrest after this point anyway.
726  fTempFile = true;
727  }
728 
729  Application.InteractiveThread.ThreadLogS("Network: Resource: deriving from %d:%s, original at %s", getResID(), Core.getFileName(), szFile);
730 
731  // (note: should remove temp file if something fails after this point)
732 
733  // create new resource
735  if (!pDRes) return nullptr;
736 
737  // initialize
738  if (!pDRes->SetDerived(Core.getFileName(), szOrgFile, fOrgTempFile, getType(), getResID()))
739  return nullptr;
740 
741  // add to list
742  pParent->Add(pDRes);
743 
744  // return new resource
745  return pDRes;
746 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
bool ThreadLogS(const char *szMessage,...) GNUC_FORMAT_ATTRIBUTE_O
C4Network2ResType getType() const
void Add(C4Network2Res *pRes)
#define _MAX_PATH
bool SetDerived(const char *strName, const char *strFilePath, bool fTemp, C4Network2ResType eType, int32_t iDResID)
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97
const char * getFileName() const
Definition: C4Network2Res.h:94
C4Network2Res(C4Network2ResList *pnParent)
bool isLoading() const
C4Network2ResCore Core
bool C4Group_CopyItem(const char *szSource, const char *szTarget1, bool fNoSort, bool fResetAttributes)
Definition: C4Group.cpp:100
bool FindTempResFileName(const char *szFilename, char *pTarget)
char szStandalone[_MAX_PATH+1]
C4Network2ResList * pParent
char szFile[_MAX_PATH+1]
bool Log(const char *szMessage)
Definition: C4Log.cpp:195
CStdCSec FileCSec
C4Application Application
Definition: C4Globals.cpp:44
C4InteractiveThread InteractiveThread
Definition: C4Application.h:45
int32_t getResID() const

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2Res::DoLoad ( )

Definition at line 927 of file C4Network2Res.cpp.

References C4NetResDiscoverTimeout, fLoading, iDiscoverStartTime, iLoadCnt, pLoads, pNext, RemoveLoad(), and StartNewLoads().

Referenced by C4Network2ResList::OnTimer().

928 {
929  if (!fLoading) return true;
930  // any loads currently active?
931  if (iLoadCnt)
932  {
933  // check for load timeouts
934  int32_t iLoadsRemoved = 0;
935  for (C4Network2ResLoad *pLoad = pLoads, *pNext; pLoad; pLoad = pNext)
936  {
937  pNext = pLoad->Next();
938  if (pLoad->CheckTimeout())
939  {
940  RemoveLoad(pLoad);
941  iLoadsRemoved++;
942  }
943  }
944  // start new loads
945  if (iLoadsRemoved) StartNewLoads();
946  }
947  else
948  {
949  // discover timeout?
950  if (iDiscoverStartTime)
951  if (difftime(time(nullptr), iDiscoverStartTime) > C4NetResDiscoverTimeout)
952  return false;
953  }
954  // ok
955  return true;
956 }
void RemoveLoad(C4Network2ResLoad *pLoad)
time_t iDiscoverStartTime
const int32_t C4NetResDiscoverTimeout
Definition: C4Network2Res.h:30
int32_t iLoadCnt
C4Network2ResLoad * pLoads
C4Network2Res * pNext

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2Res::EndLoad ( )
protected

Definition at line 1102 of file C4Network2Res.cpp.

References ClearLoad(), fLoading, C4Network2ResList::OnResComplete(), and pParent.

Referenced by OnChunk().

1103 {
1104  // clear loading data
1105  ClearLoad();
1106  // set complete
1107  fLoading = false;
1108  // call handler
1109  assert(pParent);
1110  pParent->OnResComplete(this);
1111 }
void OnResComplete(C4Network2Res *pRes)
C4Network2ResList * pParent

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2Res::FinishDerive ( )

Definition at line 748 of file C4Network2Res.cpp.

References _MAX_PATH, C4Network2IO::BroadcastMsg(), Core, fDirty, FileCSec, fTempFile, C4Network2ResCore::getDerID(), C4Network2ResCore::getFileName(), C4Network2ResList::getIOClass(), GetStandalone(), getType(), isAnonymous(), MkC4NetIOPacket(), C4Network2ResList::nextResID(), PID_NetResDerive, pParent, SCopy(), SetByFile(), C4Network2ResCore::SetDerived(), and szFile.

749 {
750  // All changes have been made. Register this resource with a new ID.
751 
752  // security
753  if (!isAnonymous()) return false;
754 
755  CStdLock FileLock(&FileCSec);
756  // Save back data
757  int32_t iDerID = Core.getDerID();
758  char szName[_MAX_PATH+1]; SCopy(Core.getFileName(), szName, _MAX_PATH);
759  char szFileC[_MAX_PATH+1]; SCopy(szFile, szFileC, _MAX_PATH);
760  // Set by file
761  if (!SetByFile(szFileC, fTempFile, getType(), pParent->nextResID(), szName))
762  return false;
763  // create standalone
764  if (!GetStandalone(nullptr, 0, true))
765  return false;
766  // Set ID
767  Core.SetDerived(iDerID);
768  // announce derive
770  // derivation is dirty bussines
771  fDirty = true;
772  // ok
773  return true;
774 }
bool SetByFile(const char *strFilePath, bool fTemp, C4Network2ResType eType, int32_t iResID, const char *szResName=nullptr, bool fSilent=false)
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
bool isAnonymous() const
C4Network2ResType getType() const
#define _MAX_PATH
const char * getFileName() const
Definition: C4Network2Res.h:94
C4Network2IO * getIOClass()
C4Network2ResCore Core
int32_t getDerID() const
Definition: C4Network2Res.h:87
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
void SetDerived(int32_t inDerID)
bool BroadcastMsg(const C4NetIOPacket &rPkt)
bool GetStandalone(char *pTo, int32_t iMaxL, bool fSetOfficial, bool fAllowUnloadable=false, bool fSilent=false)
C4Network2ResList * pParent
char szFile[_MAX_PATH+1]
CStdCSec FileCSec

Here is the call graph for this function:

bool C4Network2Res::FinishDerive ( const C4Network2ResCore nCore)

Definition at line 776 of file C4Network2Res.cpp.

References Chunks, Core, C4Network2ResCore::getChunkCnt(), isAnonymous(), and C4Network2ResChunkData::SetComplete().

777 {
778  // security
779  if (!isAnonymous()) return false;
780  // Set core
781  Core = nCore;
782  // Set chunks (assume the resource is complete)
784 
785  // Note that the Contents-CRC is /not/ checked. Derivation needs to be
786  // synchronized outside of C4Network2Res.
787 
788  // But note that the resource /might/ be binary compatible (though very
789  // unlikely), so do not set fNotBinaryCompatible.
790 
791  // ok
792  return true;
793 }
bool isAnonymous() const
C4Network2ResCore Core
uint32_t getChunkCnt() const
Definition: C4Network2Res.h:96
C4Network2ResChunkData Chunks
void SetComplete(int32_t iChunkCnt)

Here is the call graph for this function:

const C4Network2ResCore& C4Network2Res::getCore ( ) const
inline

Definition at line 239 of file C4Network2Res.h.

References Core.

Referenced by C4Network2ResList::AddByCore(), C4Network2ResChunk::AddTo(), C4PlayerInfo::CompileFunc(), C4Network2::CreateDynamic(), C4PlayerInfo::LoadFromLocalFile(), C4Network2ResList::OnResComplete(), C4PlayerInfoList::RecreatePlayers(), C4Network2::RetrieveRes(), C4Network2ResChunk::Set(), and C4GameRes::SetNetRes().

239 { return Core; }
C4Network2ResCore Core

Here is the caller graph for this function:

const char* C4Network2Res::getFile ( ) const
inline

Definition at line 244 of file C4Network2Res.h.

References szFile.

Referenced by C4PlayerInfo::GetLocalJoinFilename(), C4PlayerInfo::LoadBigIcon(), C4ControlJoinPlayer::PreRec(), C4MessageInput::ProcessCommand(), C4Network2::RetrieveScenario(), C4Network2ResChunk::Set(), and C4GameRes::SetNetRes().

244 { return szFile; }
char szFile[_MAX_PATH+1]

Here is the caller graph for this function:

CStdCSec* C4Network2Res::getFileCSec ( )
inline

Definition at line 245 of file C4Network2Res.h.

References FileCSec.

245 { return &FileCSec; }
CStdCSec FileCSec
int32_t C4Network2Res::getLastReqTime ( ) const
inline

Definition at line 246 of file C4Network2Res.h.

References iLastReqTime.

246 { return iLastReqTime; }
int32_t iLastReqTime
int32_t C4Network2Res::getPresentPercent ( ) const
inline

Definition at line 250 of file C4Network2Res.h.

References C4Network2ResChunkData::getPresentPercent().

Referenced by C4Network2::RetrieveRes().

250 { return fLoading ? Chunks.getPresentPercent() : 100; }
C4Network2ResChunkData Chunks
int32_t getPresentPercent() const

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t C4Network2Res::getResClient ( ) const
inline

Definition at line 243 of file C4Network2Res.h.

References C4Network2ResCore::getID().

243 { return Core.getID() >> 16; }
int32_t getID() const
Definition: C4Network2Res.h:86
C4Network2ResCore Core

Here is the call graph for this function:

int32_t C4Network2Res::getResID ( ) const
inline

Definition at line 242 of file C4Network2Res.h.

References C4Network2ResCore::getID().

Referenced by C4Network2ResChunk::AddTo(), Derive(), C4ClientPlayerInfos::GetPlayerInfoByRes(), C4Network2ResList::getRefNextRes(), C4Network2Players::HandlePlayerInfoUpdRequest(), isAnonymous(), OnChunk(), C4Network2ResChunk::Set(), and C4Network2ResDlg::Update().

242 { return Core.getID(); }
int32_t getID() const
Definition: C4Network2Res.h:86
C4Network2ResCore Core

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2Res::GetStandalone ( char *  pTo,
int32_t  iMaxL,
bool  fSetOfficial,
bool  fAllowUnloadable = false,
bool  fSilent = false 
)

Definition at line 569 of file C4Network2Res.cpp.

References C4Group_CopyItem(), C4Group_PackDirectory(), C4Group_PackDirectoryTo(), Chunks, Config, Core, DirectoryExists(), EraseDirectory(), EraseItem(), FileCSec, FileExists(), FileSize(), C4Network2ResList::FindTempResFileName(), fStandaloneFailed, fTempFile, C4Network2ResCore::getChunkCnt(), DirSizeHelper::GetDirSize(), C4Network2ResCore::getFileCRC(), GetFileCRC(), GetFilename(), C4Network2ResCore::getFileSize(), iSize, C4Network2ResCore::isLoadable(), LoadResStr(), Log(), LogF(), LogSilentF(), C4ConfigNetwork::MaxLoadFileSize, C4Config::Network, OptimizeStandalone(), pParent, SCopy(), SEqual(), C4Network2ResChunkData::SetComplete(), C4Network2ResCore::SetLoadable(), szFile, and szStandalone.

Referenced by C4Network2ResList::AddByFile(), C4Network2ResList::AddByGroup(), CalculateSHA(), FinishDerive(), IsBinaryCompatible(), and OpenFileRead().

570 {
571  // already set?
572  if (szStandalone[0])
573  {
574  if (pTo) SCopy(szStandalone, pTo, iMaxL);
575  return true;
576  }
577  // already tried and failed? No point in retrying
578  if (fStandaloneFailed) return false;
579  // not loadable? Wo won't be able to check the standalone as the core will lack the needed information.
580  // the standalone won't be interesting in this case, anyway.
581  if (!fSetOfficial && !Core.isLoadable()) return false;
582  // set flag, so failure below will let future calls fail
583  fStandaloneFailed = true;
584  // lock file
585  CStdLock FileLock(&FileCSec);
586 
587  // directory?
588  SCopy(szFile, szStandalone, sizeof(szStandalone)-1);
589  if (DirectoryExists(szFile))
590  {
591  // size check for the directory, if allowed
592  if (fAllowUnloadable)
593  {
594  uint32_t iDirSize;
596  { if (!fSilent) LogF("Network: could not get directory size of %s!", szFile); szStandalone[0] = '\0'; return false; }
597  if (iDirSize > uint32_t(Config.Network.MaxLoadFileSize))
598  { if (!fSilent) LogSilentF("Network: %s over size limit, will be marked unloadable!", szFile); szStandalone[0] = '\0'; return false; }
599  }
600  // log - this may take a few seconds
601  if (!fSilent) LogF(LoadResStr("IDS_PRC_NETPACKING"), GetFilename(szFile));
602  // pack inplace?
603  if (!fTempFile)
604  {
606  { if (!fSilent) Log("GetStandalone: could not find free name for temporary file!"); szStandalone[0] = '\0'; return false; }
608  { if (!fSilent) Log("GetStandalone: could not pack directory!"); szStandalone[0] = '\0'; return false; }
609  }
611  { if (!fSilent) Log("GetStandalone: could not pack directory!"); if (!SEqual(szFile, szStandalone)) EraseDirectory(szStandalone); szStandalone[0] = '\0'; return false; }
612  // make sure directory is packed
614  { if (!fSilent) Log("GetStandalone: directory hasn't been packed!"); if (!SEqual(szFile, szStandalone)) EraseDirectory(szStandalone); szStandalone[0] = '\0'; return false; }
615  // fallthru
616  }
617 
618  // doesn't exist physically?
619  if (!FileExists(szStandalone))
620  {
621  // try C4Group (might be packed)
623  { if (!fSilent) Log("GetStandalone: could not find free name for temporary file!"); szStandalone[0] = '\0'; return false; }
625  { if (!fSilent) Log("GetStandalone: could not copy to temporary file!"); szStandalone[0] = '\0'; return false; }
626  }
627 
628  // remains missing? give up.
629  if (!FileExists(szStandalone))
630  { if (!fSilent) Log("GetStandalone: file not found!"); szStandalone[0] = '\0'; return false; }
631 
632  // do optimizations (delete unneeded entries)
633  if (!OptimizeStandalone(fSilent))
634  { if (!SEqual(szFile, szStandalone)) EraseItem(szStandalone); szStandalone[0] = '\0'; return false; }
635 
636  // get file size
637  size_t iSize = FileSize(szStandalone);
638  // size limit
639  if (fAllowUnloadable)
640  if (iSize > uint32_t(Config.Network.MaxLoadFileSize))
641  { if (!fSilent) LogSilentF("Network: %s over size limit, will be marked unloadable!", szFile); szStandalone[0] = '\0'; return false; }
642  // check
643  if (!fSetOfficial && iSize != Core.getFileSize())
644  {
645  // remove file
647  // sorry, this version isn't good enough :(
648  return false;
649  }
650 
651  // calc checksum
652  uint32_t iCRC32;
653  if (!GetFileCRC(szStandalone, &iCRC32))
654  { if (!fSilent) Log("GetStandalone: could not calculate checksum!"); return false; }
655  // set / check
656  if (!fSetOfficial && iCRC32 != Core.getFileCRC())
657  {
658  // remove file, return
660  return false;
661  }
662 
663  // we didn't fail
664  fStandaloneFailed = false;
665  // mark resource as loadable and safe file information
666  Core.SetLoadable(iSize, iCRC32);
667  // set up chunk data
669  // ok
670  return true;
671 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:55
bool fStandaloneFailed
C4Config Config
Definition: C4Config.cpp:837
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
uint32_t getFileSize() const
Definition: C4Network2Res.h:89
static bool GetDirSize(const char *szPath, uint32_t *pSize, uint32_t inMaxSize=~0)
bool isLoadable() const
Definition: C4Network2Res.h:88
int32_t MaxLoadFileSize
Definition: C4Config.h:158
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
bool C4Group_PackDirectoryTo(const char *szFilename, const char *szFilenameTo)
Definition: C4Group.cpp:221
bool GetFileCRC(const char *szFilename, uint32_t *pCRC32)
Definition: CStdFile.cpp:359
bool LogSilentF(const char *strMessage,...)
Definition: C4Log.cpp:263
C4Network2ResCore Core
bool C4Group_CopyItem(const char *szSource, const char *szTarget1, bool fNoSort, bool fResetAttributes)
Definition: C4Group.cpp:100
bool EraseDirectory(const char *szDirName)
Definition: StdFile.cpp:771
C4ConfigNetwork Network
Definition: C4Config.h:256
uint32_t getChunkCnt() const
Definition: C4Network2Res.h:96
bool FindTempResFileName(const char *szFilename, char *pTarget)
void SetLoadable(uint32_t iSize, uint32_t iCRC)
char szStandalone[_MAX_PATH+1]
bool DirectoryExists(const char *szFilename)
Definition: StdFile.cpp:694
C4Network2ResList * pParent
size_t FileSize(const char *szFilename)
Definition: StdFile.cpp:448
char szFile[_MAX_PATH+1]
bool EraseItem(const char *szItemName)
Definition: StdFile.cpp:819
bool FileExists(const char *szFilename)
Definition: StdFile.cpp:439
bool Log(const char *szMessage)
Definition: C4Log.cpp:195
C4Network2ResChunkData Chunks
bool OptimizeStandalone(bool fSilent)
void SetComplete(int32_t iChunkCnt)
CStdCSec FileCSec
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253
uint32_t getFileCRC() const
Definition: C4Network2Res.h:90
bool C4Group_PackDirectory(const char *szFilename)
Definition: C4Group.cpp:284
int iSize
Definition: TstC4NetIO.cpp:35

Here is the call graph for this function:

Here is the caller graph for this function:

C4Network2ResType C4Network2Res::getType ( ) const
inline

Definition at line 238 of file C4Network2Res.h.

References C4Network2ResCore::getType().

Referenced by Derive(), FinishDerive(), C4GameControlNetwork::OnResComplete(), and C4GameRes::SetNetRes().

238 { return Core.getType(); }
C4Network2ResCore Core
C4Network2ResType getType() const
Definition: C4Network2Res.h:84

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2Res::isAnonymous ( ) const
inline

Definition at line 241 of file C4Network2Res.h.

References C4NetResIDAnonymous, and getResID().

Referenced by FinishDerive().

241 { return getResID() == C4NetResIDAnonymous; }
const int32_t C4NetResIDAnonymous
Definition: C4Network2Res.h:38
int32_t getResID() const

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2Res::IsBinaryCompatible ( )

Definition at line 552 of file C4Network2Res.cpp.

References DirectoryExists(), FileCSec, GetStandalone(), szFile, and szStandalone.

Referenced by C4Network2ResList::HandlePacket(), and OnDiscover().

553 {
554  // returns wether the standalone of this resource is binary compatible
555  // to the official version (means: matches the file checksum)
556 
557  CStdLock FileLock(&FileCSec);
558  // standalone set? ok then (see GetStandalone)
559  if (szStandalone[0]) return true;
560  // is a directory?
561  if (DirectoryExists(szFile))
562  // forget it - if the file is packed now, the creation time and author
563  // won't match.
564  return false;
565  // try to create the standalone
566  return GetStandalone(nullptr, 0, false, false, true);
567 }
bool GetStandalone(char *pTo, int32_t iMaxL, bool fSetOfficial, bool fAllowUnloadable=false, bool fSilent=false)
char szStandalone[_MAX_PATH+1]
bool DirectoryExists(const char *szFilename)
Definition: StdFile.cpp:694
char szFile[_MAX_PATH+1]
CStdCSec FileCSec

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2Res::isComplete ( ) const
inline

Definition at line 249 of file C4Network2Res.h.

References fLoading.

Referenced by C4PlayerInfo::LoadBigIcon().

249 { return !fLoading; }

Here is the caller graph for this function:

bool C4Network2Res::isDirty ( ) const
inline

Definition at line 240 of file C4Network2Res.h.

References fDirty.

Referenced by C4Network2ResList::OnTimer().

240 { return fDirty; }

Here is the caller graph for this function:

bool C4Network2Res::isLoading ( ) const
inline

Definition at line 248 of file C4Network2Res.h.

References fLoading.

Referenced by Derive(), C4Network2ResList::OnTimer(), C4ControlJoinPlayer::PreExecute(), C4PlayerInfoList::RecreatePlayers(), and C4Network2::RetrieveRes().

248 { return fLoading; }

Here is the caller graph for this function:

bool C4Network2Res::isRemoved ( ) const
inline

Definition at line 247 of file C4Network2Res.h.

References fRemoved.

Referenced by C4Network2ResList::OnTimer(), and C4ControlJoinPlayer::PreRec().

247 { return fRemoved; }

Here is the caller graph for this function:

bool C4Network2Res::isTempFile ( ) const
inline

Definition at line 251 of file C4Network2Res.h.

References fTempFile.

251 { return fTempFile; }
bool C4Network2Res::NeedsDiscover ( )

Definition at line 958 of file C4Network2Res.cpp.

References fLoading, iDiscoverStartTime, and iLoadCnt.

Referenced by C4Network2ResList::OnTimer().

959 {
960  // loading, but no active load sources?
961  if (fLoading && !iLoadCnt)
962  {
963  // set timeout, if this is the first discover
964  if (!iDiscoverStartTime)
965  iDiscoverStartTime = time(nullptr);
966  // do discover
967  return true;
968  }
969  return false;
970 }
time_t iDiscoverStartTime
int32_t iLoadCnt

Here is the caller graph for this function:

void C4Network2Res::OnChunk ( const C4Network2ResChunk rChunk)

Definition at line 895 of file C4Network2Res.cpp.

References C4Network2ResChunk::AddTo(), Application, Chunks, Core, EndLoad(), fDirty, FileCSec, fLoading, C4Network2ResChunk::getChunkNr(), C4Network2ResCore::getFileName(), C4Network2ResList::getIOClass(), getResID(), C4Network2ResChunk::getResID(), C4Application::InteractiveThread, C4Network2ResChunkData::isComplete(), pLoads, pNext, pParent, RemoveLoad(), StartNewLoads(), szFile, and C4InteractiveThread::ThreadLogS().

Referenced by C4Network2ResList::HandlePacket().

896 {
897  if (!fLoading) return;
898  // correct resource?
899  if (rChunk.getResID() != getResID()) return;
900  // add resource data
901  CStdLock FileLock(&FileCSec);
902  bool fSuccess = rChunk.AddTo(this, pParent->getIOClass());
903 #ifdef C4NET2RES_DEBUG_LOG
904  // log
905  Application.InteractiveThread.ThreadLogS("Network: Res: %s chunk %d to resource %s (%s)%s", fSuccess ? "added" : "could not add", rChunk.getChunkNr(), Core.getFileName(), szFile, fSuccess ? "" : "!");
906 #endif
907  if (fSuccess)
908  {
909  // status changed
910  fDirty = true;
911  // remove load waits
912  for (C4Network2ResLoad *pLoad = pLoads, *pNext; pLoad; pLoad = pNext)
913  {
914  pNext = pLoad->Next();
915  if (static_cast<uint32_t>(pLoad->getChunk()) == rChunk.getChunkNr())
916  RemoveLoad(pLoad);
917  }
918  }
919  // complete?
920  if (Chunks.isComplete())
921  EndLoad();
922  // check: start new loads?
923  else
924  StartNewLoads();
925 }
void RemoveLoad(C4Network2ResLoad *pLoad)
bool ThreadLogS(const char *szMessage,...) GNUC_FORMAT_ATTRIBUTE_O
const char * getFileName() const
Definition: C4Network2Res.h:94
C4Network2IO * getIOClass()
int32_t getResID() const
C4Network2ResCore Core
uint32_t getChunkNr() const
bool isComplete() const
C4Network2ResList * pParent
char szFile[_MAX_PATH+1]
C4Network2ResChunkData Chunks
C4Network2ResLoad * pLoads
CStdCSec FileCSec
C4Application Application
Definition: C4Globals.cpp:44
C4InteractiveThread InteractiveThread
Definition: C4Application.h:45
bool AddTo(C4Network2Res *pRes, C4Network2IO *pIO) const
C4Network2Res * pNext
int32_t getResID() const

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2Res::OnDiscover ( C4Network2IOConnection pBy)

Definition at line 859 of file C4Network2Res.cpp.

References iLastReqTime, IsBinaryCompatible(), and SendStatus().

860 {
861  if (!IsBinaryCompatible()) return;
862  // discovered
863  iLastReqTime = time(nullptr);
864  // send status back
865  SendStatus(pBy);
866 }
int32_t iLastReqTime
bool IsBinaryCompatible()
bool SendStatus(C4Network2IOConnection *pTo=nullptr)

Here is the call graph for this function:

void C4Network2Res::OnStatus ( const C4Network2ResChunkData rChunkData,
C4Network2IOConnection pBy 
)

Definition at line 868 of file C4Network2Res.cpp.

References Chunks, C4Network2Res::ClientChunks::Chunks, C4Network2Res::ClientChunks::ClientID, fLoading, C4Network2ResChunkData::getChunkCnt(), C4Network2IOConnection::getClientID(), iDiscoverStartTime, C4Network2Res::ClientChunks::Next, pCChunks, RemoveCChunks(), and StartLoad().

Referenced by C4Network2ResList::HandlePacket().

869 {
870  if (!fLoading) return;
871  // discovered a source: reset timeout
872  iDiscoverStartTime = 0;
873  // check if the chunk data is valid
874  if (rChunkData.getChunkCnt() != Chunks.getChunkCnt())
875  return;
876  // add chunk data
877  ClientChunks *pChunks;
878  for (pChunks = pCChunks; pChunks; pChunks = pChunks->Next)
879  if (pChunks->ClientID == pBy->getClientID())
880  break;
881  // not found? add
882  if (!pChunks)
883  {
884  pChunks = new ClientChunks();
885  pChunks->Next = pCChunks;
886  pCChunks = pChunks;
887  }
888  pChunks->ClientID = pBy->getClientID();
889  pChunks->Chunks = rChunkData;
890  // check load
891  if (!StartLoad(pChunks->ClientID, pChunks->Chunks))
893 }
time_t iDiscoverStartTime
int32_t getChunkCnt() const
int getClientID() const
Definition: C4Network2IO.h:271
struct C4Network2Res::ClientChunks * pCChunks
bool StartLoad(int32_t iFromClient, const C4Network2ResChunkData &Chunks)
C4Network2ResChunkData Chunks
void RemoveCChunks(ClientChunks *pChunks)

Here is the call graph for this function:

Here is the caller graph for this function:

C4Group * C4Network2Res::OpenAsGrp ( ) const

Definition at line 795 of file C4Network2Res.cpp.

References C4Group::Open(), and szFile.

796 {
797  C4Group *pnGrp = new C4Group();
798  if (!pnGrp->Open(szFile))
799  {
800  delete pnGrp;
801  return nullptr;
802  }
803  return pnGrp;
804 }
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
char szFile[_MAX_PATH+1]

Here is the call graph for this function:

int32_t C4Network2Res::OpenFileRead ( )
protected

Definition at line 993 of file C4Network2Res.cpp.

References _O_BINARY, FileCSec, GetStandalone(), GetWideChar(), O_CLOEXEC, and szStandalone.

Referenced by C4Network2ResChunk::Set().

994 {
995  CStdLock FileLock(&FileCSec);
996  if (!GetStandalone(nullptr, 0, false, false, true)) return -1;
997  // FIXME: Use standard OC file access api here
998 #ifdef _WIN32
999  return _wopen(GetWideChar(szStandalone), _O_BINARY | O_RDONLY);
1000 #else
1001  return open(szStandalone, _O_BINARY | O_CLOEXEC | O_RDONLY);
1002 #endif
1003 }
StdStrBuf::wchar_t_holder GetWideChar(const char *utf8, bool double_null_terminate=false)
#define O_CLOEXEC
bool GetStandalone(char *pTo, int32_t iMaxL, bool fSetOfficial, bool fAllowUnloadable=false, bool fSilent=false)
char szStandalone[_MAX_PATH+1]
#define _O_BINARY
CStdCSec FileCSec

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t C4Network2Res::OpenFileWrite ( )
protected

Definition at line 1005 of file C4Network2Res.cpp.

References _O_BINARY, FileCSec, GetWideChar(), O_CLOEXEC, and szStandalone.

Referenced by C4Network2ResChunk::AddTo().

1006 {
1007  CStdLock FileLock(&FileCSec);
1008  // FIXME: Use standard OC file access api here
1009 #ifdef _WIN32
1010  return _wopen(GetWideChar(szStandalone), _O_BINARY | O_CREAT | O_WRONLY, S_IREAD | S_IWRITE);
1011 #else
1012  return open(szStandalone, _O_BINARY | O_CLOEXEC | O_CREAT | O_WRONLY, S_IREAD | S_IWRITE);
1013 #endif
1014 }
StdStrBuf::wchar_t_holder GetWideChar(const char *utf8, bool double_null_terminate=false)
#define O_CLOEXEC
char szStandalone[_MAX_PATH+1]
#define _O_BINARY
CStdCSec FileCSec

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2Res::OptimizeStandalone ( bool  fSilent)
protected

Definition at line 1157 of file C4Network2Res.cpp.

References _MAX_PATH, C4CFN_BigIcon, C4Group_CopyItem(), C4NetResMaxBigicon, C4Group::Close(), Core, C4Group::Delete(), FileCSec, C4Group::FindEntry(), C4Network2ResList::FindTempResFileName(), fTempFile, GetFilename(), C4Network2ResCore::getType(), LoadResStr(), Log(), LogF(), NRT_Player, C4Group::Open(), pParent, SCopy(), SEqual(), szFile, and szStandalone.

Referenced by GetStandalone().

1158 {
1159  CStdLock FileLock(&FileCSec);
1160  // for now: player files only
1161  if (Core.getType() == NRT_Player)
1162  {
1163  // log - this may take a few seconds
1164  if (!fSilent) LogF(LoadResStr("IDS_PRC_NETPREPARING"), GetFilename(szFile));
1165  // copy to temp file, if needed
1166  if (!fTempFile && SEqual(szFile, szStandalone))
1167  {
1168  char szNewStandalone[_MAX_PATH + 1];
1169  if (!pParent->FindTempResFileName(szStandalone, szNewStandalone))
1170  { if (!fSilent) Log("OptimizeStandalone: could not find free name for temporary file!"); return false; }
1171  if (!C4Group_CopyItem(szStandalone, szNewStandalone))
1172  { if (!fSilent) Log("OptimizeStandalone: could not copy to temporary file!"); return false; } /* TODO: Test failure */
1173  SCopy(szNewStandalone, szStandalone, sizeof(szStandalone) - 1);
1174  }
1175  // open as group
1176  C4Group Grp;
1177  if (!Grp.Open(szStandalone))
1178  { if (!fSilent) Log("OptimizeStandalone: could not open player file!"); return false; }
1179  // remove bigicon, if the file size is too large
1180  size_t iBigIconSize=0;
1181  if (Grp.FindEntry(C4CFN_BigIcon, nullptr, &iBigIconSize))
1182  if (iBigIconSize > C4NetResMaxBigicon*1024)
1183  Grp.Delete(C4CFN_BigIcon);
1184  Grp.Close();
1185  }
1186  return true;
1187 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:55
bool FindEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr)
Definition: C4Group.cpp:1774
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
bool Delete(const char *szFiles, bool fRecursive=false)
Definition: C4Group.cpp:1334
#define _MAX_PATH
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4Network2ResCore Core
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
bool C4Group_CopyItem(const char *szSource, const char *szTarget1, bool fNoSort, bool fResetAttributes)
Definition: C4Group.cpp:100
bool Close()
Definition: C4Group.cpp:755
bool FindTempResFileName(const char *szFilename, char *pTarget)
char szStandalone[_MAX_PATH+1]
C4Network2ResList * pParent
C4Network2ResType getType() const
Definition: C4Network2Res.h:84
#define C4CFN_BigIcon
Definition: C4Components.h:111
char szFile[_MAX_PATH+1]
bool Log(const char *szMessage)
Definition: C4Log.cpp:195
CStdCSec FileCSec
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253
const int32_t C4NetResMaxBigicon
Definition: C4Network2Res.h:36

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2Res::Remove ( )

Definition at line 806 of file C4Network2Res.cpp.

References fRemoved.

Referenced by C4Network2ResList::OnTimer(), C4Network2::RemoveDynamic(), and C4Network2::RetrieveScenario().

807 {
808  // schedule for removal
809  fRemoved = true;
810 }

Here is the caller graph for this function:

void C4Network2Res::RemoveCChunks ( ClientChunks pChunks)
protected

Definition at line 1140 of file C4Network2Res.cpp.

References C4Network2Res::ClientChunks::Next, and pCChunks.

Referenced by ClearLoad(), OnStatus(), and StartNewLoads().

1141 {
1142  if (pChunks == pCChunks)
1143  pCChunks = pChunks->Next;
1144  else
1145  {
1146  // find previous entry
1147  ClientChunks *pPrev;
1148  for (pPrev = pCChunks; pPrev && pPrev->Next != pChunks; pPrev = pPrev->Next) {}
1149  // remove
1150  if (pPrev)
1151  pPrev->Next = pChunks->Next;
1152  }
1153  // delete
1154  delete pChunks;
1155 }
struct C4Network2Res::ClientChunks * pCChunks

Here is the caller graph for this function:

void C4Network2Res::RemoveLoad ( C4Network2ResLoad pLoad)
protected

Definition at line 1122 of file C4Network2Res.cpp.

References iLoadCnt, C4Network2ResLoad::Next(), pLoads, and C4Network2ResLoad::pNext.

Referenced by ClearLoad(), DoLoad(), and OnChunk().

1123 {
1124  if (pLoad == pLoads)
1125  pLoads = pLoad->Next();
1126  else
1127  {
1128  // find previous entry
1129  C4Network2ResLoad *pPrev;
1130  for (pPrev = pLoads; pPrev && pPrev->Next() != pLoad; pPrev = pPrev->Next()) {}
1131  // remove
1132  if (pPrev)
1133  pPrev->pNext = pLoad->Next();
1134  }
1135  // delete
1136  delete pLoad;
1137  iLoadCnt--;
1138 }
C4Network2ResLoad * Next() const
int32_t iLoadCnt
C4Network2ResLoad * pNext
C4Network2ResLoad * pLoads

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2Res::SaveBackFile ( )
bool C4Network2Res::SendChunk ( uint32_t  iChunk,
int32_t  iToClient 
)

Definition at line 829 of file C4Network2Res.cpp.

References Core, C4Network2IOConnection::DelRef(), FileCSec, C4Network2ResCore::getChunkCnt(), C4Network2IO::GetDataConnection(), C4Network2ResList::getIOClass(), iLastReqTime, MkC4NetIOPacket(), PID_NetResData, pParent, C4Network2IOConnection::Send(), C4Network2ResChunk::Set(), and szStandalone.

Referenced by C4Network2ResList::HandlePacket().

830 {
831  assert(pParent && pParent->getIOClass());
832  if (!szStandalone[0] || iChunk >= Core.getChunkCnt()) return false;
833  // find connection for given client (one of the rare uses of the data connection)
835  if (!pConn) return false;
836  // save last request time
837  iLastReqTime = time(nullptr);
838  // create packet
839  CStdLock FileLock(&FileCSec);
840  C4Network2ResChunk ResChunk;
841  ResChunk.Set(this, iChunk);
842  // send
843  bool fSuccess = pConn->Send(MkC4NetIOPacket(PID_NetResData, ResChunk));
844  pConn->DelRef();
845  return fSuccess;
846 }
int32_t iLastReqTime
bool Send(const C4NetIOPacket &rPkt)
C4Network2IO * getIOClass()
C4Network2ResCore Core
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
uint32_t getChunkCnt() const
Definition: C4Network2Res.h:96
bool Set(C4Network2Res *pRes, uint32_t iChunk)
char szStandalone[_MAX_PATH+1]
C4Network2ResList * pParent
C4Network2IOConnection * GetDataConnection(int iClientID)
CStdCSec FileCSec

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2Res::SendStatus ( C4Network2IOConnection pTo = nullptr)

Definition at line 812 of file C4Network2Res.cpp.

References C4Network2IO::BroadcastMsg(), Chunks, Core, fDirty, C4Network2ResCore::getID(), C4Network2ResList::getIOClass(), MkC4NetIOPacket(), PID_NetResStat, pParent, and C4Network2IOConnection::Send().

Referenced by OnDiscover(), and C4Network2ResList::OnTimer().

813 {
814  // pack status
816  // to one client?
817  if (pTo)
818  return pTo->Send(Pkt);
819  else
820  {
821  // reset dirty flag
822  fDirty = false;
823  // broadcast status
824  assert(pParent && pParent->getIOClass());
825  return pParent->getIOClass()->BroadcastMsg(Pkt);
826  }
827 }
bool Send(const C4NetIOPacket &rPkt)
int32_t getID() const
Definition: C4Network2Res.h:86
C4Network2IO * getIOClass()
C4Network2ResCore Core
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
bool BroadcastMsg(const C4NetIOPacket &rPkt)
C4Network2ResList * pParent
C4Network2ResChunkData Chunks

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2Res::SetByCore ( const C4Network2ResCore nCore,
bool  fSilent = false,
const char *  szAsFilename = nullptr,
int32_t  iRecursion = 0 
)

Definition at line 440 of file C4Network2Res.cpp.

References StdStrBuf::Append(), Config, StdStrBuf::Copy(), Core, DirectoryExists(), DirectorySeparator, C4ConfigGeneral::ExePath, fDirty, StdStrBuf::Format(), C4Config::General, GetC4Filename(), C4Network2ResCore::getContentsCRC(), StdStrBuf::getData(), GetExtension(), GetFilename(), C4Network2ResCore::getFileName(), C4Network2ResCore::getID(), C4Network2ResCore::getType(), StdStrBuf::GrabPointer(), ItemIdentical(), C4ConfigNetwork::MaxResSearchRecursion, C4Config::Network, SetByFile(), SLen(), StdStrBuf::Take(), TruncateBackslash(), and C4ConfigNetwork::WorkPath.

Referenced by C4Network2ResList::AddByCore().

441 {
442  StdStrBuf sFilename;
443  // try open local file
444  const char *szFilename = szAsFilename ? szAsFilename : GetC4Filename(nCore.getFileName());
445  if (SetByFile(szFilename, false, nCore.getType(), nCore.getID(), nCore.getFileName(), fSilent))
446  {
447  // check contents checksum
448  if (Core.getContentsCRC() == nCore.getContentsCRC())
449  {
450  // set core
451  fDirty = true;
452  Core = nCore;
453  // ok then
454  return true;
455  }
456  }
457  // get and search for filename without specified folder (e.g., Castle.ocs when the opened game is Easy.ocf\Castle.ocs)
458  const char *szFilenameOnly = GetFilename(szFilename);
459  const char *szFilenameC4 = GetC4Filename(szFilename);
460  if (szFilenameOnly != szFilenameC4)
461  {
462  sFilename.Copy(szFilename, SLen(szFilename) - SLen(szFilenameC4));
463  sFilename.Append(szFilenameOnly);
464  if (SetByCore(nCore, fSilent, szFilenameOnly, Config.Network.MaxResSearchRecursion)) return true;
465  }
466  // if it could still not be set, try within all folders of root (ignoring special folders), and try as file outside the folder
467  // but do not recurse any deeper than set by config (default: One folder)
468  if (iRecursion >= Config.Network.MaxResSearchRecursion) return false;
469  StdStrBuf sSearchPath; const char *szSearchPath;
470  if (!iRecursion)
471  szSearchPath = Config.General.ExePath.getData();
472  else
473  {
474  sSearchPath.Copy(szFilename, SLen(szFilename) - SLen(szFilenameC4));
475  szSearchPath = sSearchPath.getData();
476  }
477  StdStrBuf sNetPath; sNetPath.Copy(Config.Network.WorkPath);
478  char *szNetPath = sNetPath.GrabPointer();
479  TruncateBackslash(szNetPath);
480  sNetPath.Take(szNetPath);
481  for (DirectoryIterator i(szSearchPath); *i; ++i)
482  if (DirectoryExists(*i))
483  if (!*GetExtension(*i)) // directories without extension only
484  if (!szNetPath || !*szNetPath || !ItemIdentical(*i, szNetPath)) // ignore network path
485  {
486  // search for complete name at subpath (e.g. MyFolder\Easy.ocf\Castle.ocs)
487  sFilename.Format("%s%c%s", *i, DirectorySeparator, szFilenameC4);
488  if (SetByCore(nCore, fSilent, sFilename.getData(), iRecursion + 1))
489  return true;
490  }
491  // file could not be found locally
492  return false;
493 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:55
const char * getData() const
Definition: StdBuf.h:450
int32_t MaxResSearchRecursion
Definition: C4Config.h:145
bool SetByFile(const char *strFilePath, bool fTemp, C4Network2ResType eType, int32_t iResID, const char *szResName=nullptr, bool fSilent=false)
C4Config Config
Definition: C4Config.cpp:837
char * GrabPointer()
Definition: StdBuf.h:467
void TruncateBackslash(char *szFilename)
Definition: StdFile.cpp:276
bool ItemIdentical(const char *szFilename1, const char *szFilename2)
Definition: StdFile.cpp:865
uint32_t getContentsCRC() const
Definition: C4Network2Res.h:91
C4ConfigGeneral General
Definition: C4Config.h:252
const char * GetC4Filename(const char *szPath)
Definition: StdFile.cpp:81
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:181
size_t SLen(const char *sptr)
Definition: Standard.h:78
bool SetByCore(const C4Network2ResCore &nCore, bool fSilent=false, const char *szAsFilename=nullptr, int32_t iRecursion=0)
const char * getFileName() const
Definition: C4Network2Res.h:94
int32_t getID() const
Definition: C4Network2Res.h:86
C4Network2ResCore Core
void Take(char *pnData)
Definition: StdBuf.h:465
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:527
C4ConfigNetwork Network
Definition: C4Config.h:256
char * GetExtension(char *szFilename)
Definition: StdFile.cpp:131
char WorkPath[CFG_MaxString+1]
Definition: C4Config.h:146
bool DirectoryExists(const char *szFilename)
Definition: StdFile.cpp:694
C4Network2ResType getType() const
Definition: C4Network2Res.h:84
StdCopyStrBuf ExePath
Definition: C4Config.h:53
#define DirectorySeparator
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2Res::SetByFile ( const char *  strFilePath,
bool  fTemp,
C4Network2ResType  eType,
int32_t  iResID,
const char *  szResName = nullptr,
bool  fSilent = false 
)

Definition at line 375 of file C4Network2Res.cpp.

References C4Config::AtRelativePath(), Config, Core, fDirty, FileCSec, fLoading, fRemoved, fStandaloneFailed, fTempFile, StdStrBuf::getData(), GetFileCRC(), iLastReqTime, C4Reloc::LocateItem(), LogF(), LogSilentF(), C4Reloc::Open(), Reloc, SCopy(), C4Network2ResCore::Set(), SetByGroup(), and szFile.

Referenced by C4Network2ResList::AddByFile(), FinishDerive(), and SetByCore().

376 {
377  CStdLock FileLock(&FileCSec);
378  // default resource name: relative path
379  if (!szResName) szResName = Config.AtRelativePath(strFilePath);
380  SCopy(strFilePath, szFile, sizeof(szFile)-1);
381  // group?
382  C4Group Grp;
383  if (Reloc.Open(Grp, strFilePath))
384  return SetByGroup(&Grp, fTemp, eType, iResID, szResName, fSilent);
385  // so it needs to be a file
386  StdStrBuf szFullFile;
387  if (!Reloc.LocateItem(szFile, szFullFile))
388  { if (!fSilent) LogF("SetByFile: file %s not found!", strFilePath); return false; }
389  // calc checksum
390  uint32_t iCRC32;
391  if (!GetFileCRC(szFullFile.getData(), &iCRC32)) return false;
392 #ifdef C4NET2RES_DEBUG_LOG
393  // log
394  LogSilentF("Network: Resource: complete %d:%s is file %s (%s)", iResID, szResName, szFile, fTemp ? "temp" : "static");
395 #endif
396  // set core
397  Core.Set(eType, iResID, Config.AtRelativePath(szFullFile.getData()), iCRC32);
398  // set own data
399  fDirty = true;
400  fTempFile = fTemp;
401  fStandaloneFailed = false;
402  fRemoved = false;
403  iLastReqTime = time(nullptr);
404  fLoading = false;
405  // ok
406  return true;
407 }
const char * getData() const
Definition: StdBuf.h:450
bool fStandaloneFailed
int32_t iLastReqTime
C4Config Config
Definition: C4Config.cpp:837
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
bool GetFileCRC(const char *szFilename, uint32_t *pCRC32)
Definition: CStdFile.cpp:359
bool LogSilentF(const char *strMessage,...)
Definition: C4Log.cpp:263
C4Network2ResCore Core
void Set(C4Network2ResType eType, int32_t iResID, const char *strFileName, uint32_t iContentsCRC)
bool Open(C4Group &hGroup, const char *filename) const
Definition: C4Reloc.cpp:69
bool SetByGroup(C4Group *pGrp, bool fTemp, C4Network2ResType eType, int32_t iResID, const char *szResName=nullptr, bool fSilent=false)
C4Reloc Reloc
Definition: C4Reloc.cpp:22
char szFile[_MAX_PATH+1]
const char * AtRelativePath(const char *szFilename)
Definition: C4Config.cpp:660
CStdCSec FileCSec
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253
bool LocateItem(const char *filename, StdStrBuf &str) const
Definition: C4Reloc.cpp:80

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2Res::SetByGroup ( C4Group pGrp,
bool  fTemp,
C4Network2ResType  eType,
int32_t  iResID,
const char *  szResName = nullptr,
bool  fSilent = false 
)

Definition at line 409 of file C4Network2Res.cpp.

References C4Config::AtRelativePath(), Clear(), Config, StdStrBuf::Copy(), Core, C4Group::EntryCRC32(), fDirty, FileCSec, fLoading, fRemoved, fStandaloneFailed, fTempFile, StdStrBuf::getData(), C4Group::GetFullName(), iLastReqTime, LogSilentF(), SCopy(), C4Network2ResCore::Set(), and szFile.

Referenced by C4Network2ResList::AddByGroup(), and SetByFile().

410 {
411  Clear();
412  CStdLock FileLock(&FileCSec);
413  // default resource name: relative path
414  StdStrBuf sResName;
415  if (szResName)
416  sResName = szResName;
417  else
418  {
419  StdStrBuf sFullName = pGrp->GetFullName();
420  sResName.Copy(Config.AtRelativePath(sFullName.getData()));
421  }
422  SCopy(pGrp->GetFullName().getData(), szFile, sizeof(szFile)-1);
423  // set core
424  Core.Set(eType, iResID, sResName.getData(), pGrp->EntryCRC32());
425 #ifdef C4NET2RES_DEBUG_LOG
426  // log
427  LogSilentF("Network: Resource: complete %d:%s is file %s (%s)", iResID, sResName.getData(), szFile, fTemp ? "temp" : "static");
428 #endif
429  // set data
430  fDirty = true;
431  fTempFile = fTemp;
432  fStandaloneFailed = false;
433  fRemoved = false;
434  iLastReqTime = time(nullptr);
435  fLoading = false;
436  // ok
437  return true;
438 }
const char * getData() const
Definition: StdBuf.h:450
bool fStandaloneFailed
int32_t iLastReqTime
C4Config Config
Definition: C4Config.cpp:837
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
bool LogSilentF(const char *strMessage,...)
Definition: C4Log.cpp:263
C4Network2ResCore Core
void Set(C4Network2ResType eType, int32_t iResID, const char *strFileName, uint32_t iContentsCRC)
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2078
unsigned int EntryCRC32(const char *szWildCard=nullptr)
Definition: C4Group.cpp:1877
char szFile[_MAX_PATH+1]
const char * AtRelativePath(const char *szFilename)
Definition: C4Config.cpp:660
CStdCSec FileCSec
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2Res::SetDerived ( const char *  strName,
const char *  strFilePath,
bool  fTemp,
C4Network2ResType  eType,
int32_t  iDResID 
)

Definition at line 525 of file C4Network2Res.cpp.

References _MAX_PATH, C4NetResIDAnonymous, Clear(), Core, fDirty, FileCSec, fLoading, fRemoved, fStandaloneFailed, fTempFile, iLastReqTime, SCopy(), C4Network2ResCore::Set(), C4Network2ResCore::SetDerived(), szFile, and szStandalone.

Referenced by Derive().

526 {
527  Clear();
528  CStdLock FileLock(&FileCSec);
529  // set core
530  Core.Set(eType, C4NetResIDAnonymous, strName, ~0);
531  Core.SetDerived(iDResID);
532  // save file path
533  SCopy(strFilePath, szFile, _MAX_PATH);
534  *szStandalone = '\0';
535  // set flags
536  fDirty = false;
537  fTempFile = fTemp;
538  fStandaloneFailed = false;
539  fRemoved = false;
540  iLastReqTime = time(nullptr);
541  fLoading = false;
542  // Do not set any chunk data - anonymous resources are very likely to change.
543  // Wait for FinishDerived()-call.
544  return true;
545 }
bool fStandaloneFailed
int32_t iLastReqTime
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
#define _MAX_PATH
const int32_t C4NetResIDAnonymous
Definition: C4Network2Res.h:38
C4Network2ResCore Core
void Set(C4Network2ResType eType, int32_t iResID, const char *strFileName, uint32_t iContentsCRC)
void SetDerived(int32_t inDerID)
char szStandalone[_MAX_PATH+1]
char szFile[_MAX_PATH+1]
CStdCSec FileCSec

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2Res::SetLoad ( const C4Network2ResCore nCore)

Definition at line 495 of file C4Network2Res.cpp.

References Application, Chunks, Clear(), Core, fDirty, FileCSec, C4Network2ResList::FindTempResFileName(), fLoading, fRemoved, fStandaloneFailed, fTempFile, C4Network2ResCore::getChunkCnt(), C4Network2ResCore::getFileName(), C4Network2ResCore::getID(), iDiscoverStartTime, iLastReqTime, C4Application::InteractiveThread, C4Network2ResCore::isLoadable(), pParent, SCopy(), C4Network2ResChunkData::SetIncomplete(), szFile, szStandalone, and C4InteractiveThread::ThreadLogS().

Referenced by C4Network2ResList::AddLoad().

496 {
497  Clear();
498  CStdLock FileLock(&FileCSec);
499  // must be loadable
500  if (!nCore.isLoadable()) return false;
501  // save core, set chunks
502  Core = nCore;
504  // create temporary file
506  return false;
507 #ifdef C4NET2RES_DEBUG_LOG
508  // log
509  Application.InteractiveThread.ThreadLogS("Network: Resource: loading %d:%s to file %s", Core.getID(), Core.getFileName(), szFile);
510 #endif
511  // set standalone (result is going to be binary-compatible)
512  SCopy(szFile, szStandalone, sizeof(szStandalone) - 1);
513  // set flags
514  fDirty = false;
515  fTempFile = true;
516  fStandaloneFailed = false;
517  fRemoved = false;
518  iLastReqTime = time(nullptr);
519  fLoading = true;
520  // No discovery yet
521  iDiscoverStartTime = 0;
522  return true;
523 }
bool fStandaloneFailed
int32_t iLastReqTime
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
bool ThreadLogS(const char *szMessage,...) GNUC_FORMAT_ATTRIBUTE_O
bool isLoadable() const
Definition: C4Network2Res.h:88
const char * getFileName() const
Definition: C4Network2Res.h:94
time_t iDiscoverStartTime
int32_t getID() const
Definition: C4Network2Res.h:86
C4Network2ResCore Core
uint32_t getChunkCnt() const
Definition: C4Network2Res.h:96
bool FindTempResFileName(const char *szFilename, char *pTarget)
char szStandalone[_MAX_PATH+1]
C4Network2ResList * pParent
char szFile[_MAX_PATH+1]
C4Network2ResChunkData Chunks
void SetIncomplete(int32_t iChunkCnt)
CStdCSec FileCSec
C4Application Application
Definition: C4Globals.cpp:44
C4InteractiveThread InteractiveThread
Definition: C4Application.h:45

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2Res::StartLoad ( int32_t  iFromClient,
const C4Network2ResChunkData Chunks 
)
protected

Definition at line 1063 of file C4Network2Res.cpp.

References Application, C4NetResMaxLoad, Chunks, Core, C4Network2IOConnection::DelRef(), C4Network2ResCore::getChunkCnt(), C4Network2ResChunkData::GetChunkToRetrieve(), C4Network2ResCore::getFileName(), C4Network2ResCore::getID(), C4Network2ResList::getIOClass(), C4Network2IO::GetMsgConnection(), iLoadCnt, C4Application::InteractiveThread, MkC4NetIOPacket(), C4Network2ResLoad::Next(), PID_NetResReq, pLoads, C4Network2ResLoad::pNext, pParent, C4Network2IOConnection::Send(), szFile, and C4InteractiveThread::ThreadLogS().

Referenced by OnStatus(), and StartNewLoads().

1064 {
1065  assert(pParent && pParent->getIOClass());
1066  // all slots used? ignore
1067  if (iLoadCnt + 1 >= C4NetResMaxLoad) return true;
1068  // is there already a load by this client? ignore
1069  for (C4Network2ResLoad *pPos = pLoads; pPos; pPos = pPos->Next())
1070  if (pPos->getByClient() == iFromClient)
1071  return true;
1072  // find chunk to retrieve
1073  int32_t iLoads[C4NetResMaxLoad]; int32_t i = 0;
1074  for (C4Network2ResLoad *pLoad = pLoads; pLoad; pLoad = pLoad->Next())
1075  iLoads[i++] = pLoad->getChunk();
1076  int32_t iRetrieveChunk = Chunks.GetChunkToRetrieve(Available, i, iLoads);
1077  // nothing? ignore
1078  if (iRetrieveChunk < 0 || (uint32_t)iRetrieveChunk >= Core.getChunkCnt())
1079  return true;
1080  // search message connection for client
1081  C4Network2IOConnection *pConn = pParent->getIOClass()->GetMsgConnection(iFromClient);
1082  if (!pConn) return false;
1083  // send request
1084  if (!pConn->Send(MkC4NetIOPacket(PID_NetResReq, C4PacketResRequest(Core.getID(), iRetrieveChunk))))
1085  { pConn->DelRef(); return false; }
1086  pConn->DelRef();
1087 #ifdef C4NET2RES_DEBUG_LOG
1088  // log
1089  Application.InteractiveThread.ThreadLogS("Network: Res: requesting chunk %d of %d:%s (%s) from client %d",
1090  iRetrieveChunk, Core.getID(), Core.getFileName(), szFile, iFromClient);
1091 #endif
1092  // create load class
1093  C4Network2ResLoad *pnLoad = new C4Network2ResLoad(iRetrieveChunk, iFromClient);
1094  // add to list
1095  pnLoad->pNext = pLoads;
1096  pLoads = pnLoad;
1097  iLoadCnt++;
1098  // ok
1099  return true;
1100 }
const int32_t C4NetResMaxLoad
Definition: C4Network2Res.h:33
C4Network2ResLoad * Next() const
bool ThreadLogS(const char *szMessage,...) GNUC_FORMAT_ATTRIBUTE_O
C4Network2IOConnection * GetMsgConnection(int iClientID)
bool Send(const C4NetIOPacket &rPkt)
const char * getFileName() const
Definition: C4Network2Res.h:94
int32_t GetChunkToRetrieve(const C4Network2ResChunkData &Available, int32_t iLoadingCnt, int32_t *pLoading) const
int32_t getID() const
Definition: C4Network2Res.h:86
C4Network2IO * getIOClass()
C4Network2ResCore Core
C4NetIOPacket MkC4NetIOPacket(char cStatus, const class C4PacketBase &Pkt, const C4NetIO::addr_t &addr=C4NetIO::addr_t())
Definition: C4PacketBase.h:40
int32_t iLoadCnt
uint32_t getChunkCnt() const
Definition: C4Network2Res.h:96
C4Network2ResLoad * pNext
C4Network2ResList * pParent
char szFile[_MAX_PATH+1]
C4Network2ResLoad * pLoads
C4Application Application
Definition: C4Globals.cpp:44
C4InteractiveThread InteractiveThread
Definition: C4Application.h:45

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2Res::StartNewLoads ( )
protected

Definition at line 1016 of file C4Network2Res.cpp.

References C4NetResMaxLoad, Chunks, iLoadCnt, C4Network2Res::ClientChunks::Next, pCChunks, RemoveCChunks(), StartLoad(), and UnsyncedRandom().

Referenced by DoLoad(), and OnChunk().

1017 {
1018  if (!pCChunks) return;
1019  // count clients
1020  int32_t iCChunkCnt = 0; ClientChunks *pChunks;
1021  for (pChunks = pCChunks; pChunks; pChunks = pChunks->Next)
1022  iCChunkCnt++;
1023  // create array
1024  ClientChunks **pC = new ClientChunks *[iCChunkCnt];
1025  // initialize
1026  int32_t i;
1027  for (i = 0; i < iCChunkCnt; i++) pC[i] = nullptr;
1028  // create shuffled order
1029  for (pChunks = pCChunks, i = 0; i < iCChunkCnt; i++, pChunks = pChunks->Next)
1030  {
1031  // determine position
1032  int32_t iPos = UnsyncedRandom(iCChunkCnt - i);
1033  // find & set
1034  for (int32_t j = 0; ; j++)
1035  if (!pC[j] && !iPos--)
1036  {
1037  pC[j] = pChunks;
1038  break;
1039  }
1040  }
1041  // start new load until maximum count reached
1042  while (iLoadCnt + 1 <= C4NetResMaxLoad)
1043  {
1044  int32_t ioLoadCnt = iLoadCnt;
1045  // search someone
1046  for (i = 0; i < iCChunkCnt; i++)
1047  if (pC[i])
1048  {
1049  // try to start load
1050  if (!StartLoad(pC[i]->ClientID, pC[i]->Chunks))
1051  { RemoveCChunks(pC[i]); pC[i] = nullptr; continue; }
1052  // success?
1053  if (iLoadCnt > ioLoadCnt) break;
1054  }
1055  // not found?
1056  if (i >= iCChunkCnt)
1057  break;
1058  }
1059  // clear up
1060  delete [] pC;
1061 }
const int32_t C4NetResMaxLoad
Definition: C4Network2Res.h:33
uint32_t UnsyncedRandom()
Definition: C4Random.cpp:58
int32_t iLoadCnt
struct C4Network2Res::ClientChunks * pCChunks
bool StartLoad(int32_t iFromClient, const C4Network2ResChunkData &Chunks)
C4Network2ResChunkData Chunks
void RemoveCChunks(ClientChunks *pChunks)

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4Network2ResChunk
friend

Definition at line 181 of file C4Network2Res.h.

friend class C4Network2ResList
friend

Definition at line 180 of file C4Network2Res.h.

Member Data Documentation

bool C4Network2Res::fDirty
protected
bool C4Network2Res::fLoading
protected
bool C4Network2Res::fRemoved
protected

Definition at line 220 of file C4Network2Res.h.

Referenced by Clear(), isRemoved(), Remove(), SetByFile(), SetByGroup(), SetDerived(), and SetLoad().

bool C4Network2Res::fStandaloneFailed
protected

Definition at line 216 of file C4Network2Res.h.

Referenced by GetStandalone(), SetByFile(), SetByGroup(), SetDerived(), and SetLoad().

bool C4Network2Res::fTempFile
protected
time_t C4Network2Res::iDiscoverStartTime
protected

Definition at line 229 of file C4Network2Res.h.

Referenced by ClearLoad(), DoLoad(), NeedsDiscover(), OnStatus(), and SetLoad().

int32_t C4Network2Res::iLastReqTime
protected
int32_t C4Network2Res::iLoadCnt
protected

Definition at line 231 of file C4Network2Res.h.

Referenced by ClearLoad(), DoLoad(), NeedsDiscover(), RemoveLoad(), StartLoad(), and StartNewLoads().

std::atomic_long C4Network2Res::iRefCnt
protected

Definition at line 219 of file C4Network2Res.h.

Referenced by AddRef(), and DelRef().

struct C4Network2Res::ClientChunks * C4Network2Res::pCChunks
protected
C4Network2ResLoad* C4Network2Res::pLoads
protected

Definition at line 230 of file C4Network2Res.h.

Referenced by ClearLoad(), DoLoad(), OnChunk(), RemoveLoad(), and StartLoad().

C4Network2ResList* C4Network2Res::pParent
protected

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