BVB Source Codes

CRYENGINE Show CET_CVars.cpp Source code

Return Download CRYENGINE: download CET_CVars.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4. #include "CET_CVars.h"
  5. #include "GameServerChannel.h"
  6. #include <CryNetwork/NetHelpers.h>
  7.  
  8. class CConsoleVarSender : public ICVarDumpSink
  9. {
  10. public:
  11.         CConsoleVarSender(IConsoleVarSink* pSink) : m_pSink(pSink) {}
  12.  
  13.         virtual void OnElementFound(ICVar* pCVar)
  14.         {
  15.                 int flags = pCVar->GetFlags();
  16.                 if ((flags & VF_REQUIRE_APP_RESTART) || ((flags & VF_NET_SYNCED) == 0))
  17.                 {
  18.                         return;
  19.                 }
  20.                 m_pSink->OnAfterVarChange(pCVar);
  21.         }
  22.  
  23. private:
  24.         IConsoleVarSink* m_pSink;
  25. };
  26.  
  27. class CCET_CVarSync : public CCET_Base
  28. {
  29. public:
  30.         CCET_CVarSync(CGameServerChannel* pChannel) : m_pChannel(pChannel) {}
  31.  
  32.         const char*                 GetName() { return "CVarSync"; }
  33.  
  34.         EContextEstablishTaskResult OnStep(SContextEstablishState& state)
  35.         {
  36.                 CBatchSyncVarsSink pSink(m_pChannel);
  37.                 CConsoleVarSender cvarSender(&pSink);
  38.                 gEnv->pConsole->DumpCVars(&cvarSender, 0);
  39.                 pSink.OnAfterVarChange(0);
  40.                 return eCETR_Ok;
  41.         }
  42.  
  43. private:
  44.         CGameServerChannel* m_pChannel;
  45. };
  46.  
  47. void AddCVarSync(IContextEstablisher* pEst, EContextViewState state, CGameServerChannel* pChannel)
  48. {
  49.         pEst->AddTask(state, new CCET_CVarSync(pChannel));
  50. }
  51.  
  52. CBatchSyncVarsSink::CBatchSyncVarsSink(CGameServerChannel* pChannel)
  53. {
  54.         m_pChannel = pChannel;
  55. }
  56.  
  57. // IConsoleVarSink
  58. bool CBatchSyncVarsSink::OnBeforeVarChange(ICVar* pVar, const char* sNewValue)
  59. {
  60. #if LOG_CVAR_USAGE
  61.         CryLog("[CVARS]: [CHANGED] CBatchSyncVarsSink::OnBeforeVarChange(): variable [%s] with a value of [%s]; %s changing to [%s]",
  62.                pVar->GetName(),
  63.                pVar->GetString(),
  64.                (gEnv->bServer) ? "SERVER" : "CLIENT",
  65.                sNewValue);
  66. #endif // LOG_CVAR_USAGE
  67.         return true;
  68. }
  69.  
  70. void CBatchSyncVarsSink::OnAfterVarChange(ICVar* pVar)
  71. {
  72.         if (!pVar || (pVar->GetFlags() & VF_NET_SYNCED))
  73.         {
  74.                 if (m_pChannel->GetNetChannel() && !m_pChannel->GetNetChannel()->IsLocal())
  75.                 {
  76.                         if (!pVar || !m_params.Add(pVar->GetName(), pVar->GetString()))
  77.                         {
  78.                                 INetSendablePtr pSendable = new CSimpleNetMessage<SClientBatchConsoleVariablesParams>(m_params, CGameClientChannel::SetBatchConsoleVariables);
  79.                                 pSendable->SetGroup('cvar');
  80.                                 m_pChannel->GetNetChannel()->AddSendable(pSendable, 1, &m_consoleVarSendable, &m_consoleVarSendable);
  81.  
  82.                                 m_params.Reset();
  83.                                 if (pVar)
  84.                                         m_params.Add(pVar->GetName(), pVar->GetString());
  85.                         }
  86.                 }
  87.         }
  88. }
  89.  
downloadCET_CVars.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top