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

#include <C4Network2Res.h>

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

Public Member Functions

 C4Network2ResList ()
 
 ~C4Network2ResList () override
 
bool Init (int32_t iClientID, C4Network2IO *pIOClass)
 
void SetLocalID (int32_t iClientID)
 
C4Network2Res::Ref getRefRes (int32_t iResID)
 
C4Network2Res::Ref getRefRes (const char *szFile, bool fLocalOnly=false)
 
C4Network2Res::Ref getRefNextRes (int32_t iResID)
 
void Add (C4Network2Res *pRes)
 
C4Network2Res::Ref AddByFile (const char *strFilePath, bool fTemp, C4Network2ResType eType, int32_t iResID=-1, const char *szResName=nullptr, bool fAllowUnloadable=false)
 
C4Network2Res::Ref AddByGroup (C4Group *pGrp, bool fTemp, C4Network2ResType eType, int32_t iResID=-1, const char *szResName=nullptr, bool fAllowUnloadable=false)
 
C4Network2Res::Ref AddByCore (const C4Network2ResCore &Core, bool fLoad=true)
 
C4Network2Res::Ref AddLoad (const C4Network2ResCore &Core)
 
void RemoveAtClient (int32_t iClientID)
 
void Clear ()
 
bool SendDiscover (C4Network2IOConnection *pTo=nullptr)
 
void OnClientConnect (C4Network2IOConnection *pConn)
 
void HandlePacket (char cStatus, const C4PacketBase *pPacket, C4Network2IOConnection *pConn)
 
void OnTimer ()
 
void OnShareFree (CStdCSecEx *pCSec) override
 
C4Network2IOgetIOClass ()
 

Protected Member Functions

int32_t nextResID ()
 
C4Network2ResgetRes (int32_t iResID)
 
C4Network2ResgetRes (const char *szFile, bool fLocalOnly)
 
void OnResComplete (C4Network2Res *pRes)
 
bool CreateNetworkFolder ()
 
bool FindTempResFileName (const char *szFilename, char *pTarget)
 

Protected Attributes

C4Network2RespFirst {nullptr}
 
CStdCSecEx ResListCSec
 
CStdCSec ResListAddCSec
 
int32_t iClientID {-1}
 
int32_t iNextResID
 
CStdCSec ResIDCSec
 
int32_t iLastDiscover {0}
 
int32_t iLastStatus {0}
 
C4Network2IOpIO {nullptr}
 

Friends

class C4Network2Res
 
class C4Network2
 

Detailed Description

Definition at line 326 of file C4Network2Res.h.

Constructor & Destructor Documentation

C4Network2ResList::C4Network2ResList ( )

Definition at line 1271 of file C4Network2Res.cpp.

1272  : ResListCSec(this),
1273  iNextResID((-1) << 16)
1274 {
1275 
1276 }
CStdCSecEx ResListCSec
C4Network2ResList::~C4Network2ResList ( )
override

Definition at line 1278 of file C4Network2Res.cpp.

References Clear().

1279 {
1280  Clear();
1281 }

Here is the call graph for this function:

Member Function Documentation

void C4Network2ResList::Add ( C4Network2Res pRes)

Definition at line 1368 of file C4Network2Res.cpp.

References C4Network2Res::AddRef(), pFirst, C4Network2Res::pNext, ResListAddCSec, and ResListCSec.

Referenced by AddByCore(), AddByFile(), AddByGroup(), AddLoad(), and C4Network2Res::Derive().

1369 {
1370  // get locks
1371  CStdShareLock ResListLock(&ResListCSec);
1372  CStdLock ResListAddLock(&ResListAddCSec);
1373  // reference
1374  pRes->AddRef();
1375  // add
1376  pRes->pNext = pFirst;
1377  pFirst = pRes;
1378 }
C4Network2Res * pFirst
CStdCSec ResListAddCSec
CStdCSecEx ResListCSec
C4Network2Res * pNext

Here is the call graph for this function:

Here is the caller graph for this function:

C4Network2Res::Ref C4Network2ResList::AddByCore ( const C4Network2ResCore Core,
bool  fLoad = true 
)

Definition at line 1431 of file C4Network2Res.cpp.

References Add(), AddLoad(), Application, C4Network2Res, C4Network2Res::Ref::Clear(), C4Network2Res::getCore(), C4Network2ResCore::getFileName(), C4Network2ResCore::getID(), getRefRes(), C4Application::InteractiveThread, C4Network2ResCore::isLoadable(), C4Network2Res::SetByCore(), and C4InteractiveThread::ThreadLogS().

Referenced by C4Network2::HandleJoinData(), C4GameRes::Load(), C4PlayerInfo::LoadResource(), C4ControlJoinPlayer::PreExecute(), and C4Network2::RetrieveRes().

1432 {
1433  // already in list?
1434  C4Network2Res::Ref pRes = getRefRes(Core.getID());
1435  if (pRes) return pRes;
1436 #ifdef C4NET2RES_LOAD_ALL
1437  // load without check (if possible)
1438  if (Core.isLoadable()) return AddLoad(Core);
1439 #endif
1440  // create new
1441  pRes = new C4Network2Res(this);
1442  // try set by core
1443  if (!pRes->SetByCore(Core, true))
1444  {
1445  pRes.Clear();
1446  // try load (if specified)
1447  return fLoad ? AddLoad(Core) : nullptr;
1448  }
1449  // log
1450  Application.InteractiveThread.ThreadLogS("Network: Found identical %s. Not loading.", pRes->getCore().getFileName());
1451  // add to list
1452  Add(pRes);
1453  // ok
1454  return pRes;
1455 }
friend class C4Network2Res
bool ThreadLogS(const char *szMessage,...) GNUC_FORMAT_ATTRIBUTE_O
bool isLoadable() const
Definition: C4Network2Res.h:88
void Add(C4Network2Res *pRes)
C4Network2Res::Ref AddLoad(const C4Network2ResCore &Core)
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
const C4Network2ResCore & getCore() const
C4Network2Res::Ref getRefRes(int32_t iResID)
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:

C4Network2Res::Ref C4Network2ResList::AddByFile ( const char *  strFilePath,
bool  fTemp,
C4Network2ResType  eType,
int32_t  iResID = -1,
const char *  szResName = nullptr,
bool  fAllowUnloadable = false 
)

Definition at line 1380 of file C4Network2Res.cpp.

References Add(), C4Network2Res, getRefRes(), C4Network2Res::GetStandalone(), Log(), nextResID(), NRT_System, and C4Network2Res::SetByFile().

Referenced by C4Network2::CreateDynamic(), and C4GameRes::Publish().

1381 {
1382  // already in list?
1383  C4Network2Res::Ref pRes = getRefRes(strFilePath);
1384  if (pRes) return pRes;
1385  // get resource ID
1386  if (iResID < 0) iResID = nextResID();
1387  if (iResID < 0) { Log("AddByFile: no more resource IDs available!"); return nullptr; }
1388  // create new
1389  pRes = new C4Network2Res(this);
1390  // initialize
1391  if (!pRes->SetByFile(strFilePath, fTemp, eType, iResID, szResName)) { return nullptr; }
1392  // create standalone for non-system files
1393  // system files shouldn't create a standalone; they should never be marked loadable!
1394  if (eType != NRT_System)
1395  if (!pRes->GetStandalone(nullptr, 0, true, fAllowUnloadable))
1396  if (!fAllowUnloadable)
1397  {
1398  delete pRes;
1399  return nullptr;
1400  }
1401  // add to list
1402  Add(pRes);
1403  return pRes;
1404 }
friend class C4Network2Res
bool SetByFile(const char *strFilePath, bool fTemp, C4Network2ResType eType, int32_t iResID, const char *szResName=nullptr, bool fSilent=false)
void Add(C4Network2Res *pRes)
C4Network2Res::Ref getRefRes(int32_t iResID)
bool GetStandalone(char *pTo, int32_t iMaxL, bool fSetOfficial, bool fAllowUnloadable=false, bool fSilent=false)
bool Log(const char *szMessage)
Definition: C4Log.cpp:192

Here is the call graph for this function:

Here is the caller graph for this function:

C4Network2Res::Ref C4Network2ResList::AddByGroup ( C4Group pGrp,
bool  fTemp,
C4Network2ResType  eType,
int32_t  iResID = -1,
const char *  szResName = nullptr,
bool  fAllowUnloadable = false 
)

Definition at line 1406 of file C4Network2Res.cpp.

References Add(), C4Network2Res, C4Network2Res::GetStandalone(), Log(), nextResID(), and C4Network2Res::SetByGroup().

Referenced by C4PlayerInfo::LoadFromLocalFile().

1407 {
1408  // get resource ID
1409  if (iResID < 0) iResID = nextResID();
1410  if (iResID < 0) { Log("AddByGroup: no more resource IDs available!"); return nullptr; }
1411  // create new
1412  C4Network2Res::Ref pRes = new C4Network2Res(this);
1413  // initialize
1414  if (!pRes->SetByGroup(pGrp, fTemp, eType, iResID, szResName))
1415  {
1416  delete pRes;
1417  return nullptr;
1418  }
1419  // create standalone
1420  if (!pRes->GetStandalone(nullptr, 0, true, fAllowUnloadable))
1421  if (!fAllowUnloadable)
1422  {
1423  delete pRes;
1424  return nullptr;
1425  }
1426  // add to list
1427  Add(pRes);
1428  return pRes;
1429 }
friend class C4Network2Res
void Add(C4Network2Res *pRes)
bool SetByGroup(C4Group *pGrp, bool fTemp, C4Network2ResType eType, int32_t iResID, const char *szResName=nullptr, bool fSilent=false)
bool GetStandalone(char *pTo, int32_t iMaxL, bool fSetOfficial, bool fAllowUnloadable=false, bool fSilent=false)
bool Log(const char *szMessage)
Definition: C4Log.cpp:192

Here is the call graph for this function:

Here is the caller graph for this function:

C4Network2Res::Ref C4Network2ResList::AddLoad ( const C4Network2ResCore Core)

Definition at line 1457 of file C4Network2Res.cpp.

References Add(), Application, C4Network2Res, C4Network2ResCore::getFileName(), C4Application::InteractiveThread, C4Network2ResCore::isLoadable(), C4Network2Res::SetLoad(), C4InteractiveThread::ThreadLog(), and C4InteractiveThread::ThreadLogS().

Referenced by AddByCore().

1458 {
1459  // marked unloadable by creator?
1460  if (!Core.isLoadable())
1461  {
1462  // show error msg
1463  Application.InteractiveThread.ThreadLog("Network: Cannot load %s (marked unloadable)", Core.getFileName());
1464  return nullptr;
1465  }
1466  // create new
1467  C4Network2Res::Ref pRes = new C4Network2Res(this);
1468  // initialize
1469  pRes->SetLoad(Core);
1470  // log
1471  Application.InteractiveThread.ThreadLogS("Network: loading %s...", Core.getFileName());
1472  // add to list
1473  Add(pRes);
1474  return pRes;
1475 }
friend class C4Network2Res
bool ThreadLogS(const char *szMessage,...) GNUC_FORMAT_ATTRIBUTE_O
bool isLoadable() const
Definition: C4Network2Res.h:88
void Add(C4Network2Res *pRes)
bool SetLoad(const C4Network2ResCore &nCore)
const char * getFileName() const
Definition: C4Network2Res.h:94
bool ThreadLog(const char *szMessage,...) GNUC_FORMAT_ATTRIBUTE_O
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 C4Network2ResList::Clear ( )

Definition at line 1485 of file C4Network2Res.cpp.

References C4ClientIDUnknown, iClientID, iLastDiscover, iLastStatus, pFirst, C4Network2Res::pNext, and ResListCSec.

Referenced by C4Network2::Clear(), Init(), and ~C4Network2ResList().

1486 {
1487  CStdShareLock ResListLock(&ResListCSec);
1488  for (C4Network2Res *pRes = pFirst; pRes; pRes = pRes->pNext)
1489  {
1490  pRes->Remove();
1491  pRes->iLastReqTime = 0;
1492  }
1494  iLastDiscover = iLastStatus = 0;
1495 }
C4Network2Res * pFirst
const int32_t C4ClientIDUnknown
Definition: C4Client.h:24
CStdCSecEx ResListCSec
C4Network2Res * pNext

Here is the caller graph for this function:

bool C4Network2ResList::CreateNetworkFolder ( )
protected

Definition at line 1668 of file C4Network2Res.cpp.

References _MAX_PATH, AppendBackslash(), C4Config::AtNetworkPath(), Config, CreatePath(), DirectoryExists(), LogFatal(), C4Config::Network, SCopy(), TruncateBackslash(), and C4ConfigNetwork::WorkPath.

Referenced by Init().

1669 {
1670  // get network path without trailing backslash
1671  char szNetworkPath[_MAX_PATH+1];
1672  SCopy(Config.AtNetworkPath(""), szNetworkPath, _MAX_PATH);
1673  TruncateBackslash(szNetworkPath);
1674  // but make sure that the configured path has one
1676  // does not exist?
1677  if (!DirectoryExists(szNetworkPath))
1678  {
1679  if (!CreatePath(szNetworkPath))
1680  { LogFatal("Network: could not create network path!"); return false; }
1681  return true;
1682  }
1683  return true;
1684 }
C4Config Config
Definition: C4Config.cpp:833
void TruncateBackslash(char *szFilename)
Definition: StdFile.cpp:266
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:130
bool CreatePath(const std::string &path)
Definition: StdFile.cpp:632
#define _MAX_PATH
void AppendBackslash(char *szFilename)
Definition: StdFile.cpp:257
const char * AtNetworkPath(const char *szFilename)
Definition: C4Config.cpp:547
C4ConfigNetwork Network
Definition: C4Config.h:255
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:227
char WorkPath[CFG_MaxString+1]
Definition: C4Config.h:145
bool DirectoryExists(const char *szFilename)
Definition: StdFile.cpp:684

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2ResList::FindTempResFileName ( const char *  szFilename,
char *  pTarget 
)
protected

Definition at line 1686 of file C4Network2Res.cpp.

References _MAX_PATH, C4Config::AtNetworkPath(), Config, GetExtension(), GetFilename(), ItemExists(), SAppend(), and SCopy().

Referenced by C4Network2::CreateDynamic(), C4Network2Res::Derive(), C4Network2Res::GetStandalone(), C4Network2Res::OptimizeStandalone(), C4Network2::RetrieveScenario(), and C4Network2Res::SetLoad().

1687 {
1688  char safeFilename[_MAX_PATH];
1689  char* safePos = safeFilename;
1690  while (*szFilename)
1691  {
1692  if ((*szFilename >= 'a' && *szFilename <= 'z') ||
1693  (*szFilename >= 'A' && *szFilename <= 'Z') ||
1694  (*szFilename >= '0' && *szFilename <= '9') ||
1695  (*szFilename == '.') || (*szFilename == '/'))
1696  *safePos = *szFilename;
1697  else
1698  *safePos = '_';
1699 
1700  ++safePos;
1701  ++szFilename;
1702  }
1703  *safePos = 0;
1704  szFilename = safeFilename;
1705 
1706  // create temporary file
1707  SCopy(Config.AtNetworkPath(GetFilename(szFilename)), pTarget, _MAX_PATH);
1708  // file name is free?
1709  if (!ItemExists(pTarget)) return true;
1710  // find another file name
1711  char szFileMask[_MAX_PATH+1];
1712  SCopy(pTarget, szFileMask, GetExtension(pTarget)-1-pTarget);
1713  SAppend("_%d", szFileMask, _MAX_PATH);
1714  SAppend(GetExtension(pTarget)-1, szFileMask, _MAX_PATH);
1715  for (int32_t i = 2; i < 1000; i++)
1716  {
1717  snprintf(pTarget, _MAX_PATH, szFileMask, i);
1718  // doesn't exist?
1719  if (!ItemExists(pTarget))
1720  return true;
1721  }
1722  // not found
1723  return false;
1724 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:45
C4Config Config
Definition: C4Config.cpp:833
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:130
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:235
#define _MAX_PATH
const char * AtNetworkPath(const char *szFilename)
Definition: C4Config.cpp:547
char * GetExtension(char *szFilename)
Definition: StdFile.cpp:121
bool ItemExists(const char *szItemName)
Definition: StdFile.h:75

Here is the call graph for this function:

Here is the caller graph for this function:

C4Network2IO* C4Network2ResList::getIOClass ( )
inline

Definition at line 387 of file C4Network2Res.h.

References pIO.

Referenced by C4Network2Res::FinishDerive(), C4Network2Res::OnChunk(), C4Network2Res::SendChunk(), C4Network2Res::SendStatus(), and C4Network2Res::StartLoad().

387 { return pIO; }
C4Network2IO * pIO

Here is the caller graph for this function:

C4Network2Res::Ref C4Network2ResList::getRefNextRes ( int32_t  iResID)

Definition at line 1357 of file C4Network2Res.cpp.

References C4Network2Res::getResID(), pFirst, C4Network2Res::pNext, and ResListCSec.

Referenced by C4Network2ResDlg::Update().

1358 {
1359  CStdShareLock ResListLock(&ResListCSec);
1360  C4Network2Res *pRes = nullptr;
1361  for (C4Network2Res *pCur = pFirst; pCur; pCur = pCur->pNext)
1362  if (!pCur->isRemoved() && pCur->getResID() >= iResID)
1363  if (!pRes || pRes->getResID() > pCur->getResID())
1364  pRes = pCur;
1365  return pRes;
1366 }
C4Network2Res * pFirst
CStdCSecEx ResListCSec
C4Network2Res * pNext
int32_t getResID() const

Here is the call graph for this function:

Here is the caller graph for this function:

C4Network2Res::Ref C4Network2ResList::getRefRes ( int32_t  iResID)

Definition at line 1345 of file C4Network2Res.cpp.

References getRes(), and ResListCSec.

Referenced by AddByCore(), AddByFile(), C4PlayerInfo::LoadFromLocalFile(), C4ControlJoinPlayer::PreExecute(), C4ControlJoinPlayer::PreRec(), C4MessageInput::ProcessCommand(), C4Network2::RemoveDynamic(), C4Network2::RetrieveRes(), and C4Player::Save().

1346 {
1347  CStdShareLock ResListLock(&ResListCSec);
1348  return getRes(iResID);
1349 }
C4Network2Res * getRes(int32_t iResID)
CStdCSecEx ResListCSec

Here is the call graph for this function:

Here is the caller graph for this function:

C4Network2Res::Ref C4Network2ResList::getRefRes ( const char *  szFile,
bool  fLocalOnly = false 
)

Definition at line 1351 of file C4Network2Res.cpp.

References getRes(), and ResListCSec.

1352 {
1353  CStdShareLock ResListLock(&ResListCSec);
1354  return getRes(szFile, fLocalOnly);
1355 }
C4Network2Res * getRes(int32_t iResID)
CStdCSecEx ResListCSec

Here is the call graph for this function:

C4Network2Res * C4Network2ResList::getRes ( int32_t  iResID)
protected

Definition at line 1325 of file C4Network2Res.cpp.

References pFirst, C4Network2Res::pNext, and ResListCSec.

Referenced by getRefRes(), HandlePacket(), and nextResID().

1326 {
1327  CStdShareLock ResListLock(&ResListCSec);
1328  for (C4Network2Res *pCur = pFirst; pCur; pCur = pCur->pNext)
1329  if (pCur->getResID() == iResID)
1330  return pCur;
1331  return nullptr;
1332 }
C4Network2Res * pFirst
CStdCSecEx ResListCSec
C4Network2Res * pNext

Here is the caller graph for this function:

C4Network2Res * C4Network2ResList::getRes ( const char *  szFile,
bool  fLocalOnly 
)
protected

Definition at line 1334 of file C4Network2Res.cpp.

References iClientID, pFirst, C4Network2Res::pNext, ResListCSec, and SEqual().

1335 {
1336  CStdShareLock ResListLock(&ResListCSec);
1337  for (C4Network2Res *pCur = pFirst; pCur; pCur = pCur->pNext)
1338  if (!pCur->isAnonymous())
1339  if (SEqual(pCur->getFile(), szFile))
1340  if (!fLocalOnly || pCur->getResClient()==iClientID)
1341  return pCur;
1342  return nullptr;
1343 }
C4Network2Res * pFirst
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93
CStdCSecEx ResListCSec
C4Network2Res * pNext

Here is the call graph for this function:

void C4Network2ResList::HandlePacket ( char  cStatus,
const C4PacketBase pPacket,
C4Network2IOConnection pConn 
)

Definition at line 1503 of file C4Network2Res.cpp.

References C4Network2IOConnection::getClientID(), GETPKT, getRes(), C4Network2Res::IsBinaryCompatible(), C4Network2IOConnection::isOpen(), C4Network2Res::OnChunk(), C4Network2Res::OnStatus(), pFirst, PID_NetResData, PID_NetResDerive, PID_NetResDis, PID_NetResReq, PID_NetResStat, C4Network2Res::pNext, ResListCSec, and C4Network2Res::SendChunk().

Referenced by C4Network2IO::CallHandlers().

1504 {
1505  // security
1506  if (!pConn) return;
1507 
1508 #define GETPKT(type, name) \
1509  assert(pPacket); const type &name = \
1510  static_cast<const type &>(*pPacket);
1511 
1512  switch (cStatus)
1513  {
1514 
1515  case PID_NetResDis: // resource discover
1516  {
1517  if (!pConn->isOpen()) break;
1519  // search matching resources
1520  CStdShareLock ResListLock(&ResListCSec);
1521  for (C4Network2Res *pRes = pFirst; pRes; pRes = pRes->pNext)
1522  if (Pkt.isIDPresent(pRes->getResID()))
1523  // must be binary compatible
1524  if (pRes->IsBinaryCompatible())
1525  pRes->OnDiscover(pConn);
1526  }
1527  break;
1528 
1529  case PID_NetResStat: // resource status
1530  {
1531  if (!pConn->isOpen()) break;
1532  GETPKT(C4PacketResStatus, Pkt);
1533  // matching resource?
1534  CStdShareLock ResListLock(&ResListCSec);
1535  C4Network2Res *pRes = getRes(Pkt.getResID());
1536  // present / being loaded? call handler
1537  if (pRes)
1538  pRes->OnStatus(Pkt.getChunks(), pConn);
1539  }
1540  break;
1541 
1542  case PID_NetResDerive: // resource derive
1543  {
1544  GETPKT(C4Network2ResCore, Core);
1545  if (Core.getDerID() < 0) break;
1546  // Check if there is a anonymous derived resource with matching parent.
1547  CStdShareLock ResListLock(&ResListCSec);
1548  for (C4Network2Res *pRes = pFirst; pRes; pRes = pRes->pNext)
1549  if (pRes->isAnonymous() && pRes->getCore().getDerID() == Core.getDerID())
1550  pRes->FinishDerive(Core);
1551  }
1552  break;
1553 
1554  case PID_NetResReq: // resource request
1555  {
1556  GETPKT(C4PacketResRequest, Pkt);
1557  // find resource
1558  CStdShareLock ResListLock(&ResListCSec);
1559  C4Network2Res *pRes = getRes(Pkt.getReqID());
1560  // send requested chunk
1561  if (pRes && pRes->IsBinaryCompatible()) pRes->SendChunk(Pkt.getReqChunk(), pConn->getClientID());
1562  }
1563  break;
1564 
1565  case PID_NetResData: // a chunk of data is coming in
1566  {
1567  GETPKT(C4Network2ResChunk, Chunk);
1568  // find resource
1569  CStdShareLock ResListLock(&ResListCSec);
1570  C4Network2Res *pRes = getRes(Chunk.getResID());
1571  // send requested chunk
1572  if (pRes) pRes->OnChunk(Chunk);
1573  }
1574  break;
1575  }
1576 #undef GETPKT
1577 }
C4Network2Res * pFirst
bool isAnonymous() const
bool SendChunk(uint32_t iChunk, int32_t iToClient)
#define GETPKT(type, name)
bool IsBinaryCompatible()
const C4Network2ResCore & getCore() const
int32_t getDerID() const
Definition: C4Network2Res.h:87
int getClientID() const
Definition: C4Network2IO.h:271
C4Network2Res * getRes(int32_t iResID)
CStdCSecEx ResListCSec
void OnStatus(const C4Network2ResChunkData &rChunkData, C4Network2IOConnection *pBy)
C4Network2Res * pNext
bool isOpen() const
Definition: C4Network2IO.h:285
void OnChunk(const C4Network2ResChunk &rChunk)

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Network2ResList::Init ( int32_t  iClientID,
C4Network2IO pIOClass 
)

Definition at line 1283 of file C4Network2Res.cpp.

References Clear(), CreateNetworkFolder(), iClientID, iNextResID, pIO, and SetLocalID().

Referenced by C4Network2::InitHost().

1284 {
1285  // clear old list
1286  Clear();
1287  // safe IO class
1288  pIO = pIOClass;
1289  // set client id
1290  iNextResID = iClientID = 0;
1291  SetLocalID(inClientID);
1292  // create network path
1293  if (!CreateNetworkFolder()) return false;
1294  // ok
1295  return true;
1296 }
C4Network2IO * pIO
void SetLocalID(int32_t iClientID)

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t C4Network2ResList::nextResID ( )
protected

Definition at line 1313 of file C4Network2Res.cpp.

References getRes(), iClientID, iNextResID, and ResIDCSec.

Referenced by AddByFile(), AddByGroup(), and C4Network2Res::FinishDerive().

1314 {
1315  CStdLock ResIDLock(&ResIDCSec);
1316  assert(iNextResID >= (iClientID << 16));
1317  if (iNextResID >= ((iClientID+1) << 16) - 1)
1318  iNextResID = std::max<int32_t>(0, iClientID) << 16;
1319  // find free
1320  while (getRes(iNextResID))
1321  iNextResID++;
1322  return iNextResID++;
1323 }
C4Network2Res * getRes(int32_t iResID)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2ResList::OnClientConnect ( C4Network2IOConnection pConn)

Definition at line 1497 of file C4Network2Res.cpp.

References SendDiscover().

Referenced by C4Network2::OnClientConnect().

1498 {
1499  // discover resources
1500  SendDiscover(pConn);
1501 }
bool SendDiscover(C4Network2IOConnection *pTo=nullptr)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2ResList::OnResComplete ( C4Network2Res pRes)
protected

Definition at line 1660 of file C4Network2Res.cpp.

References Application, Control, C4Network2Res::getCore(), C4Network2ResCore::getFileName(), C4Application::InteractiveThread, C4GameControl::Network, C4GameControlNetwork::OnResComplete(), and C4InteractiveThread::ThreadLogS().

Referenced by C4Network2Res::EndLoad().

1661 {
1662  // log (network thread -> ThreadLog)
1663  Application.InteractiveThread.ThreadLogS("Network: %s received.", pRes->getCore().getFileName());
1664  // call handler (ctrl might wait for this resource)
1666 }
bool ThreadLogS(const char *szMessage,...) GNUC_FORMAT_ATTRIBUTE_O
const char * getFileName() const
Definition: C4Network2Res.h:94
const C4Network2ResCore & getCore() const
C4GameControl Control
C4GameControlNetwork Network
Definition: C4GameControl.h:67
void OnResComplete(C4Network2Res *pRes)
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 C4Network2ResList::OnShareFree ( CStdCSecEx pCSec)
overridevirtual

Implements CStdCSecExCallback.

Definition at line 1613 of file C4Network2Res.cpp.

References C4NetResDeleteTime, pFirst, and ResListCSec.

1614 {
1615  if (pCSec == &ResListCSec)
1616  {
1617  // remove entries
1618  for (C4Network2Res *pRes = pFirst, *pNext, *pPrev = nullptr; pRes; pRes = pNext)
1619  {
1620  pNext = pRes->pNext;
1621  if (pRes->isRemoved() && (!pRes->getLastReqTime() || difftime(time(nullptr), pRes->getLastReqTime()) > C4NetResDeleteTime))
1622  {
1623  // unlink
1624  (pPrev ? pPrev->pNext : pFirst) = pNext;
1625  // remove
1626  pRes->pNext = nullptr;
1627  pRes->DelRef();
1628  }
1629  else
1630  pPrev = pRes;
1631  }
1632  }
1633 }
C4Network2Res * pFirst
const int32_t C4NetResDeleteTime
Definition: C4Network2Res.h:35
CStdCSecEx ResListCSec
void C4Network2ResList::OnTimer ( )

Definition at line 1579 of file C4Network2Res.cpp.

References C4NetResDiscoverInterval, C4NetResStatusInterval, C4Network2Res::DoLoad(), iLastDiscover, iLastStatus, C4Network2Res::isDirty(), C4Network2Res::isLoading(), C4Network2Res::isRemoved(), C4Network2Res::NeedsDiscover(), pFirst, C4Network2Res::pNext, C4Network2Res::Remove(), ResListCSec, SendDiscover(), and C4Network2Res::SendStatus().

Referenced by C4Network2IO::Execute().

1580 {
1581  CStdShareLock ResListLock(&ResListCSec);
1582  C4Network2Res *pRes;
1583  // do loads, check timeouts
1584  for (pRes = pFirst; pRes; pRes = pRes->pNext)
1585  if (pRes->isLoading() && !pRes->isRemoved())
1586  if (!pRes->DoLoad())
1587  pRes->Remove();
1588  // discovery time?
1589  if (!iLastDiscover || difftime(time(nullptr), iLastDiscover) >= C4NetResDiscoverInterval)
1590  {
1591  // needed?
1592  bool fSendDiscover = false;
1593  for (C4Network2Res *pRes = pFirst; pRes; pRes = pRes->pNext)
1594  if (pRes->isLoading() && !pRes->isRemoved())
1595  fSendDiscover |= pRes->NeedsDiscover();
1596  // send
1597  if (fSendDiscover)
1598  SendDiscover();
1599  }
1600  // status update?
1601  if (!iLastStatus || difftime(time(nullptr), iLastStatus) >= C4NetResStatusInterval)
1602  {
1603  // any?
1604  bool fStatusUpdates = false;
1605  for (pRes = pFirst; pRes; pRes = pRes->pNext)
1606  if (pRes->isDirty() && !pRes->isRemoved())
1607  fStatusUpdates |= pRes->SendStatus();
1608  // set time accordingly
1609  iLastStatus = fStatusUpdates ? time(nullptr) : 0;
1610  }
1611 }
C4Network2Res * pFirst
const int32_t C4NetResStatusInterval
Definition: C4Network2Res.h:32
bool isLoading() const
bool SendStatus(C4Network2IOConnection *pTo=nullptr)
bool SendDiscover(C4Network2IOConnection *pTo=nullptr)
bool isRemoved() const
const int32_t C4NetResDiscoverInterval
Definition: C4Network2Res.h:31
bool isDirty() const
CStdCSecEx ResListCSec
C4Network2Res * pNext

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2ResList::RemoveAtClient ( int32_t  iClientID)

Definition at line 1477 of file C4Network2Res.cpp.

References iClientID, pFirst, C4Network2Res::pNext, and ResListCSec.

1478 {
1479  CStdShareLock ResListLock(&ResListCSec);
1480  for (C4Network2Res *pRes = pFirst; pRes; pRes = pRes->pNext)
1481  if (pRes->getResClient() == iClientID)
1482  pRes->Remove();
1483 }
C4Network2Res * pFirst
CStdCSecEx ResListCSec
C4Network2Res * pNext
bool C4Network2ResList::SendDiscover ( C4Network2IOConnection pTo = nullptr)

Definition at line 1635 of file C4Network2Res.cpp.

References C4PacketResDiscover::AddDisID(), C4Network2IO::BroadcastMsg(), CStdShareLock::Clear(), C4PacketResDiscover::getDisIDCnt(), iLastDiscover, MkC4NetIOPacket(), pFirst, PID_NetResDis, pIO, C4Network2Res::pNext, ResListCSec, and C4Network2IOConnection::Send().

Referenced by OnClientConnect(), and OnTimer().

1636 {
1637  // make packet
1638  C4PacketResDiscover Pkt;
1639  // add special retrieves
1640  CStdShareLock ResListLock(&ResListCSec);
1641  for (C4Network2Res *pRes = pFirst; pRes; pRes = pRes->pNext)
1642  if (!pRes->isRemoved())
1643  if (pRes->isLoading())
1644  Pkt.AddDisID(pRes->getResID());
1645  ResListLock.Clear();
1646  // empty?
1647  if (!Pkt.getDisIDCnt()) return false;
1648  // broadcast?
1649  if (!pTo)
1650  {
1651  // save time
1652  iLastDiscover = time(nullptr);
1653  // send
1655  }
1656  else
1657  return pTo->Send(MkC4NetIOPacket(PID_NetResDis, Pkt));
1658 }
C4Network2Res * pFirst
bool AddDisID(int32_t iID)
Definition: C4Packet2.cpp:536
bool Send(const C4NetIOPacket &rPkt)
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)
C4Network2IO * pIO
CStdCSecEx ResListCSec
int32_t getDisIDCnt() const
C4Network2Res * pNext

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Network2ResList::SetLocalID ( int32_t  iClientID)

Definition at line 1298 of file C4Network2Res.cpp.

References iClientID, iNextResID, pFirst, C4Network2Res::pNext, ResIDCSec, and ResListCSec.

Referenced by C4Network2::HandleJoinData(), and Init().

1299 {
1300  CStdLock ResIDLock(&ResIDCSec);
1301  int32_t iOldClientID = iClientID;
1302  int32_t iIDDiff = (inClientID - iClientID) << 16;
1303  // set new counter
1304  iClientID = inClientID;
1305  iNextResID += iIDDiff;
1306  // change resource ids
1307  CStdLock ResListLock(&ResListCSec);
1308  for (C4Network2Res *pRes = pFirst; pRes; pRes = pRes->pNext)
1309  if (pRes->getResClient() == iOldClientID)
1310  pRes->ChangeID(pRes->getResID() + iIDDiff);
1311 }
C4Network2Res * pFirst
CStdCSecEx ResListCSec
C4Network2Res * pNext

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4Network2
friend

Definition at line 329 of file C4Network2Res.h.

friend class C4Network2Res
friend

Definition at line 328 of file C4Network2Res.h.

Referenced by AddByCore(), AddByFile(), AddByGroup(), and AddLoad().

Member Data Documentation

int32_t C4Network2ResList::iClientID {-1}
protected

Definition at line 340 of file C4Network2Res.h.

Referenced by Clear(), getRes(), Init(), nextResID(), RemoveAtClient(), and SetLocalID().

int32_t C4Network2ResList::iLastDiscover {0}
protected

Definition at line 344 of file C4Network2Res.h.

Referenced by Clear(), OnTimer(), and SendDiscover().

int32_t C4Network2ResList::iLastStatus {0}
protected

Definition at line 344 of file C4Network2Res.h.

Referenced by Clear(), and OnTimer().

int32_t C4Network2ResList::iNextResID
protected

Definition at line 340 of file C4Network2Res.h.

Referenced by Init(), nextResID(), and SetLocalID().

C4Network2Res* C4Network2ResList::pFirst {nullptr}
protected
C4Network2IO* C4Network2ResList::pIO {nullptr}
protected

Definition at line 347 of file C4Network2Res.h.

Referenced by getIOClass(), Init(), and SendDiscover().

CStdCSec C4Network2ResList::ResIDCSec
protected

Definition at line 341 of file C4Network2Res.h.

Referenced by nextResID(), and SetLocalID().

CStdCSec C4Network2ResList::ResListAddCSec
protected

Definition at line 338 of file C4Network2Res.h.

Referenced by Add().

CStdCSecEx C4Network2ResList::ResListCSec
protected

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