BVB Source Codes

CRYENGINE Show CET_NetConfig.cpp Source code

Return Download CRYENGINE: download CET_NetConfig.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_NetConfig.h"
  5. #include "GameContext.h"
  6. #include "GameClientChannel.h"
  7. #include "GameClientNub.h"
  8. #include "GameServerChannel.h"
  9. #include "GameServerNub.h"
  10. #include <CryNetwork/NetHelpers.h>
  11.  
  12. /*
  13.  * Established context
  14.  */
  15.  
  16. class CCET_EstablishedContext : public CCET_Base
  17. {
  18. public:
  19.         CCET_EstablishedContext(int token) : m_token(token) {}
  20.  
  21.         const char*                 GetName() { return "EstablishedContext"; }
  22.  
  23.         EContextEstablishTaskResult OnStep(SContextEstablishState& state)
  24.         {
  25.                 CCryAction::GetCryAction()->GetGameContext()->GetNetContext()->EstablishedContext(m_token);
  26.                 return eCETR_Ok;
  27.         }
  28.  
  29. private:
  30.         int m_token;
  31. };
  32.  
  33. void AddEstablishedContext(IContextEstablisher* pEst, EContextViewState state, int token)
  34. {
  35.         pEst->AddTask(state, new CCET_EstablishedContext(token));
  36. }
  37.  
  38. /*
  39.  * Declare witness
  40.  */
  41.  
  42. class CCET_DeclareWitness : public CCET_Base
  43. {
  44. public:
  45.         const char*                 GetName() { return "DeclareWitness"; }
  46.  
  47.         EContextEstablishTaskResult OnStep(SContextEstablishState& state)
  48.         {
  49.                 if (CGameClientNub* pNub = CCryAction::GetCryAction()->GetGameClientNub())
  50.                 {
  51.                         if (CGameClientChannel* pChannel = pNub->GetGameClientChannel())
  52.                         {
  53.                                 if (IActor* pActor = CCryAction::GetCryAction()->GetClientActor())
  54.                                 {
  55.                                         pChannel->GetNetChannel()->DeclareWitness(pActor->GetEntityId());
  56.                                         return eCETR_Ok;
  57.                                 }
  58.                         }
  59.                 }
  60.                 return eCETR_Failed;
  61.         }
  62. };
  63.  
  64. void AddDeclareWitness(IContextEstablisher* pEst, EContextViewState state)
  65. {
  66.         pEst->AddTask(state, new CCET_DeclareWitness);
  67. }
  68.  
  69. /*
  70.  * Delegate authority to player
  71.  */
  72.  
  73. class CCET_DelegateAuthority_ToClientActor : public CCET_Base
  74. {
  75. public:
  76.         const char* GetName() { return "DelegateAuthorityToClientActor"; }
  77.  
  78. public:
  79.         EContextEstablishTaskResult OnStep(SContextEstablishState& state)
  80.         {
  81.                 EntityId entityId = GetEntity(state);
  82.                 if (!entityId || !gEnv->pEntitySystem->GetEntity(entityId))
  83.                         return eCETR_Ok; // Proceed even if there is no Actor
  84.                 CCryAction::GetCryAction()->GetGameContext()->GetNetContext()->DelegateAuthority(entityId, state.pSender);
  85.                 return eCETR_Ok;
  86.         }
  87.  
  88. private:
  89.         EntityId GetEntity(SContextEstablishState& state)
  90.         {
  91.                 if (!state.pSender)
  92.                         return 0;
  93.                 CGameChannel* pGameChannel = static_cast<CGameChannel*>(state.pSender->GetGameChannel());
  94.                 if (pGameChannel)
  95.                         return pGameChannel->GetPlayerId();
  96.                 return 0;
  97.         }
  98. };
  99.  
  100. void AddDelegateAuthorityToClientActor(IContextEstablisher* pEst, EContextViewState state)
  101. {
  102.         pEst->AddTask(state, new CCET_DelegateAuthority_ToClientActor());
  103. }
  104.  
  105. /*
  106.  * Clear player ids
  107.  */
  108.  
  109. class CCET_ClearPlayerIds : public CCET_Base
  110. {
  111. public:
  112.         const char*                 GetName() { return "ClearPlayerIds"; }
  113.  
  114.         EContextEstablishTaskResult OnStep(SContextEstablishState& state)
  115.         {
  116.                 if (CGameServerNub* pNub = CCryAction::GetCryAction()->GetGameServerNub())
  117.                 {
  118.                         TServerChannelMap* pMap = pNub->GetServerChannelMap();
  119.                         for (TServerChannelMap::iterator it = pMap->begin(); it != pMap->end(); ++it)
  120.                                 it->second->ResetPlayerId();
  121.                 }
  122.                 if (CGameClientNub* pCNub = CCryAction::GetCryAction()->GetGameClientNub())
  123.                 {
  124.                         if (CGameChannel* pChannel = pCNub->GetGameClientChannel())
  125.                                 pChannel->ResetPlayerId();
  126.                 }
  127.                 return eCETR_Ok;
  128.         }
  129. };
  130.  
  131. void AddClearPlayerIds(IContextEstablisher* pEst, EContextViewState state)
  132. {
  133.         pEst->AddTask(state, new CCET_ClearPlayerIds());
  134. }
  135.  
downloadCET_NetConfig.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