BVB Source Codes

CRYENGINE Show ScriptBind_Network.cpp Source code

Return Download CRYENGINE: download ScriptBind_Network.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /*************************************************************************
  4.    -------------------------------------------------------------------------
  5.    $Id$
  6.    $DateTime$
  7.    Description: Binding of network functions into script
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    - 24:11:2004   11:30 : Created by Craig Tiller
  12.  
  13. *************************************************************************/
  14. #include "StdAfx.h"
  15. #include "ScriptBind_Network.h"
  16. #include "GameContext.h"
  17. #include "ScriptSerialize.h"
  18. #include "CryAction.h"
  19. #include "GameChannel.h"
  20. #include "GameClientNub.h"
  21. #include "GameClientChannel.h"
  22. #include "GameServerNub.h"
  23. #include "GameServerChannel.h"
  24. #include "GameServerNub.h"
  25.  
  26. #include <CryEntitySystem/IEntitySystem.h>
  27. #include <CryEntitySystem/IEntityClass.h>
  28. #include <CrySystem/IConsole.h>
  29. #include <CryPhysics/IPhysics.h>
  30.  
  31. //------------------------------------------------------------------------
  32. CScriptBind_Network::CScriptBind_Network(ISystem* pSystem, CCryAction* pFW)
  33. {
  34.         m_pSystem = pSystem;
  35.         m_pFW = pFW;
  36.  
  37.         Init(gEnv->pScriptSystem, m_pSystem);
  38.         SetGlobalName("Net");
  39.  
  40.         RegisterGlobals();
  41.         RegisterMethods();
  42. }
  43.  
  44. //------------------------------------------------------------------------
  45. CScriptBind_Network::~CScriptBind_Network()
  46. {
  47. }
  48.  
  49. //------------------------------------------------------------------------
  50. void CScriptBind_Network::RegisterGlobals()
  51. {
  52.         gEnv->pScriptSystem->SetGlobalValue("UNRELIABLE_ORDERED", eNRT_UnreliableOrdered);
  53.         gEnv->pScriptSystem->SetGlobalValue("RELIABLE_ORDERED", eNRT_ReliableOrdered);
  54.         gEnv->pScriptSystem->SetGlobalValue("RELIABLE_UNORDERED", eNRT_ReliableUnordered);
  55.  
  56.         gEnv->pScriptSystem->SetGlobalValue("NO_ATTACH", eRAT_NoAttach);
  57.         gEnv->pScriptSystem->SetGlobalValue("PRE_ATTACH", eRAT_PreAttach);
  58.         gEnv->pScriptSystem->SetGlobalValue("POST_ATTACH", eRAT_PostAttach);
  59.  
  60.         gEnv->pScriptSystem->SetGlobalValue("BOOL", eSST_Bool);
  61.         gEnv->pScriptSystem->SetGlobalValue("FLOAT", eSST_Float);
  62.         gEnv->pScriptSystem->SetGlobalValue("INT8", eSST_Int8);
  63.         gEnv->pScriptSystem->SetGlobalValue("INT16", eSST_Int16);
  64.         gEnv->pScriptSystem->SetGlobalValue("INT32", eSST_Int32);
  65.         gEnv->pScriptSystem->SetGlobalValue("STRING", eSST_String);
  66.         gEnv->pScriptSystem->SetGlobalValue("STRINGTABLE", eSST_StringTable);
  67.         gEnv->pScriptSystem->SetGlobalValue("ENTITYID", eSST_EntityId);
  68.         gEnv->pScriptSystem->SetGlobalValue("VEC3", eSST_Vec3);
  69. }
  70.  
  71. //------------------------------------------------------------------------
  72. void CScriptBind_Network::RegisterMethods()
  73. {
  74. #undef SCRIPT_REG_CLASSNAME
  75. #define SCRIPT_REG_CLASSNAME &CScriptBind_Network::
  76.  
  77.         SCRIPT_REG_FUNC(Expose);
  78.         SCRIPT_REG_TEMPLFUNC(DelegateAuthority, "entity, channel");
  79. }
  80.  
  81. //------------------------------------------------------------------------
  82. int CScriptBind_Network::Expose(IFunctionHandler* pFH)
  83. {
  84.         return m_pFW->NetworkExposeClass(pFH);
  85. }
  86.  
  87. //------------------------------------------------------------------------
  88. int CScriptBind_Network::DelegateAuthority(IFunctionHandler* pFH, ScriptHandle ent, int channel)
  89. {
  90.         CGameContext* pCtx = m_pFW->GetGameContext();
  91.         if (!pCtx)
  92.         {
  93.                 pFH->GetIScriptSystem()->RaiseError("No game started");
  94.                 return pFH->EndFunction();
  95.         }
  96.         INetContext* pNetContext = pCtx->GetNetContext();
  97.         CGameServerNub* pServerNub = m_pFW->GetGameServerNub();
  98.         if (!pServerNub)
  99.         {
  100.                 pFH->GetIScriptSystem()->RaiseError("Not a server");
  101.                 return pFH->EndFunction();
  102.         }
  103.         INetChannel* pChannel = NULL;
  104.         CGameChannel* pGameChannel = NULL;
  105.         if (channel)
  106.         {
  107.                 if (!(pGameChannel = pServerNub->GetChannel(channel)))
  108.                         GameWarning("No such server channel %d", channel);
  109.                 else
  110.                         pChannel = pGameChannel->GetNetChannel();
  111.         }
  112.  
  113.         pNetContext->DelegateAuthority((EntityId)ent.n, pChannel);
  114.  
  115.         if ((pFH->GetParamCount() > 2) && (pFH->GetParamType(3) == svtFunction))
  116.         {
  117.                 HSCRIPTFUNCTION func;
  118.  
  119.                 if (pFH->GetParam(3, func))
  120.                 {
  121.                         pCtx->AddControlObjectCallback((EntityId)ent.n, !channel, func);
  122.                 }
  123.         }
  124.  
  125.         return pFH->EndFunction();
  126. }
  127.  
downloadScriptBind_Network.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