Ejemplo n.º 1
0
        protected virtual void OnCreateNetworkSceneInNode_ServerClient(RpcArgs pArgs)
        {
            byte[]             data        = pArgs.GetNext <byte[]>();
            RPCServiceCallback callbackRPC = data.ByteArrayToObject <RPCServiceCallback>();
            NetworkSceneItem   item;

            if (NodeManager.IsInitialized)
            {
                RPCCreateNetworkSceneInNode createNetworkSceneInNodeRPC = callbackRPC.data.ByteArrayToObject <RPCCreateNetworkSceneInNode>();
                NetworkSceneTemplate        template = new NetworkSceneTemplate(createNetworkSceneInNodeRPC.template);
                if (createNetworkSceneInNodeRPC.autoAssignIp)
                {
                    template.Settings.ServerAddress.Ip = NodeManager.Instance.MasterManager.Settings.ServerAddress.Ip;
                    template.Settings.ClientAddress.Ip = NodeManager.Instance.MasterManager.Settings.ClientAddress.Ip;
                }

                if (createNetworkSceneInNodeRPC.autoAssignPort)
                {
                    template.Settings.ServerAddress.Port = NodeManager.Instance.UsedDynamicPorts.PeekNext();
                    template.Settings.ClientAddress.Port = template.Settings.ServerAddress.Port;
                }

                item = NodeManager.Instance.CreateNetworkScene(template, false, createNetworkSceneInNodeRPC.networkSceneMetaData);
            }
            else
            {
                item = null;
            }

            callbackRPC.state = (item != null) ? ServiceCallbackStateEnum.RESPONSE_SUCCESS : ServiceCallbackStateEnum.RESPONSE_FAILED;
            callbackRPC.data  = null;
            networkObject.SendRpc(RPC_RELAY_CONFIRM_CREATE_NETWORK_SCENE_IN_NODE, Receivers.Server, callbackRPC.ObjectToByteArray());
        }
Ejemplo n.º 2
0
        public virtual void FromRPC(RPCNode pNetworkSceneNodeRPC)
        {
            _nodeId            = pNetworkSceneNodeRPC.nodeId;
            _nodeName          = pNetworkSceneNodeRPC.nodeName;
            _isMasterNode      = pNetworkSceneNodeRPC.isMasterNode;
            _dynamicPortMin    = pNetworkSceneNodeRPC.portRangeMin;
            _dynamicPortMax    = pNetworkSceneNodeRPC.portRangeMax;
            _masterNodeSetting = new NetworkSceneManagerSetting();
            _masterNodeSetting.FromRPC(pNetworkSceneNodeRPC.masterNodeSettingRPC);
            if (pNetworkSceneNodeRPC.networkSceneTemplatesRPC == null)
            {
                Init(null);
            }

            List <NetworkSceneTemplate> networkSceneTemplates = new List <NetworkSceneTemplate>(pNetworkSceneNodeRPC.networkSceneTemplatesRPC.Length);

            for (int i = 0; i < pNetworkSceneNodeRPC.networkSceneTemplatesRPC.Length; i++)
            {
                NetworkSceneTemplate networkSceneTemplate = new NetworkSceneTemplate();
                networkSceneTemplate.FromRPC(pNetworkSceneNodeRPC.networkSceneTemplatesRPC[i]);
                networkSceneTemplates.Add(networkSceneTemplate);
            }

            Init(networkSceneTemplates.ToArray());
        }
Ejemplo n.º 3
0
        public virtual NetworkSceneItem CreateNetworkScene(NetworkSceneTemplate pSceneTemplate, bool pIsSceneStatic, byte[] pNetworkSceneMetaData = null)
        {
            ushort port = GetPortFromSetting(pSceneTemplate.Settings);

            if (!pIsSceneStatic && _usedDynamicPorts.Contains(port))
            {
                return(null);
            }

            // Check if we already have created a scene with that name
            NetworkSceneTemplate existingScene = FindNetworkSceneTemplate(pSceneTemplate.SceneName, false, true, true, true);

            if (existingScene != null)
            {
                return(null);
            }

            // Create an empty Scene and put a new NetworkSceneManager in it
            NetworkSceneManager manager = CreateEmptyNetworkScene(pSceneTemplate);

            manager.NetworkSceneMetaData = pNetworkSceneMetaData;

            // Create the Scene with the 'BuildIndex' and queue it up to be merged with our empty Scene
            NetworkSceneItem newItem = new NetworkSceneItem(pSceneTemplate, manager);

            if (pSceneTemplate.BuildIndex > 0)
            {
                SceneManager.LoadScene(pSceneTemplate.BuildIndex, LoadSceneMode.Additive);
                _pendingScenes.Add(newItem);
            }
            else
            {
                newItem.IsCreated = true;
            }

            // Add the newItem to the respective collection
            if (pIsSceneStatic)
            {
                _scenesStatic.Add(pSceneTemplate.SceneName, newItem);
            }
            else
            {
                _usedDynamicPorts.Add(port);
                _scenesDynamic.Add(pSceneTemplate.SceneName, newItem);
            }

            // If the scene is 'dynamic' we need to register it so other Nodes know the scene is taken
            if (_isServer && !pIsSceneStatic && _enableRegisterDynamicScenes)
            {
                RegisterDynamicScene(_registerDynamicScenesRequireConfirmation, pSceneTemplate);
                newItem.IsRegistered = !_registerDynamicScenesRequireConfirmation;
            }
            else
            {
                newItem.IsRegistered = true;
            }

            ReadyNetworkScene(newItem);
            return(newItem);
        }
        protected virtual void ReadBinaryClient(NetworkingPlayer pPlayer, Binary pFrame, NetWorker pSender)
        {
            if (pFrame.GroupId == CustomMessageGroupIds.PLAYER_CHANGE_NETWORK_SCENE)
            {
                byte[] data = pFrame.StreamData.byteArr;
                RPCPlayerChangeNetworkScene changeSceneRPC = data.ByteArrayToObject <RPCPlayerChangeNetworkScene>();
                NetworkSceneTemplate        sceneTemplate  = RPCPlayerChangeNetworkScene.ToNetworkSceneTemplate(changeSceneRPC);
                MainThreadManager.Run(() => {
                    if (NodeManager.IsInitialized)
                    {
                        NodeManager.Instance.UnloadNetworkScenes(true, true);
                        NodeManager.Instance.RaisePlayerChangingNetworkScene(sceneTemplate);
                        NetworkSceneItem item = NodeManager.Instance.CreateNetworkScene(sceneTemplate, true);
                        if (item == null)
                        {
                            NodeManager.Instance.PlayerChangingSceneFailed(item);
                            return;
                        }

                        if (item.IsReady)
                        {
                            NodeManager.Instance.PlayerChangingSceneSucceeded(item);
                        }
                        else
                        {
                            item.OnReady    += NodeManager.Instance.PlayerChangingSceneSucceeded;
                            item.OnUnloaded += NodeManager.Instance.PlayerChangingSceneFailed;
                        }
                    }
                });

                return;
            }
        }
Ejemplo n.º 5
0
 public virtual void RaisePlayerChangingNetworkScene(NetworkSceneTemplate pTemplate)
 {
     if (OnPlayerChangingNetworkScene != null)
     {
         OnPlayerChangingNetworkScene(pTemplate);
     }
 }
        public static NetworkSceneTemplate ToNetworkSceneTemplate(RPCPlayerChangeNetworkScene pChangeSceneRPC)
        {
            NetworkSceneTemplate template = new NetworkSceneTemplate(pChangeSceneRPC.buildIndex, pChangeSceneRPC.sceneName, pChangeSceneRPC.sceneOffset, new NetworkSceneManagerSetting());

            template.Settings.UseTCP = pChangeSceneRPC.useTCP;
            template.Settings.UseMainThreadManagerForRPCs = pChangeSceneRPC.useMainThreadManagerForRPCs;
            template.Settings.ClientAddress.FromRPC(pChangeSceneRPC.clientAddress);
            template.Settings.ClientNATAddress.FromRPC(pChangeSceneRPC.clientNATAddress);
            return(template);
        }
Ejemplo n.º 7
0
        public virtual NetworkSceneManager CreateEmptyNetworkScene(NetworkSceneTemplate pTemplate, NetworkBehaviorListSO pBehaviorListSO)
        {
            Scene      newScene = SceneManager.CreateScene(pTemplate.SceneName);
            GameObject go       = GameObject.Instantiate(_networkSceneManagerPrefab);

            go.name = newScene.name + "_NetworkSceneManager";
            NetworkSceneManager manager = go.GetComponent <NetworkSceneManager>();

            manager.NetworkBehaviorListSO = pBehaviorListSO;
            manager.Settings = pTemplate.Settings;
            SceneManager.MoveGameObjectToScene(go, newScene);
            return(manager);
        }
        public virtual bool ChangePlayerNetworkScene(NetworkSceneTemplate pTemplate, NetworkingPlayer pPlayer)
        {
            if (pTemplate == null)
            {
                return(false);
            }

            RPCPlayerChangeNetworkScene changeSceneRPC = RPCPlayerChangeNetworkScene.FromNetworkSceneTemplate(pTemplate);
            Binary sceneTemplateFrame = new Binary(_networker.Time.Timestep, false, changeSceneRPC.ObjectToByteArray(), Receivers.Target, CustomMessageGroupIds.PLAYER_CHANGE_NETWORK_SCENE, pPlayer.Networker is BaseTCP);

            SendFrame(sceneTemplateFrame, pPlayer);
            return(true);
        }
 //Functions
 public static RPCPlayerChangeNetworkScene FromNetworkSceneTemplate(NetworkSceneTemplate pTemplate)
 {
     return(new RPCPlayerChangeNetworkScene()
     {
         buildIndex = pTemplate.BuildIndex,
         sceneName = pTemplate.SceneName,
         sceneOffset = pTemplate.SceneOffset,
         useTCP = pTemplate.Settings.UseTCP,
         useMainThreadManagerForRPCs = pTemplate.Settings.UseMainThreadManagerForRPCs,
         clientAddress = pTemplate.Settings.ClientAddress.ToRPC(),
         clientNATAddress = pTemplate.Settings.ClientNATAddress.ToRPC()
     });
 }
        public virtual void FindNetworkSceneTemplate(string pSceneName)
        {
            if (!NodeManager.IsInitialized || !NodeManager.Instance.IsServer || _currentLookup != null || !_findSceneDelay.HasPassed)
            {
                return;
            }

            // Lookup if the scene resides on our Node
            if (_nodeTemplate == null)
            {
                NetworkSceneTemplate foundTemplate = NodeManager.Instance.FindNetworkSceneTemplate(pSceneName, false, true, true, false);
                if (foundTemplate != null)
                {
                    _nodeTemplate = new NodeNetworkSceneTemplate(NodeManager.Instance.CurrentNode.NodeId, foundTemplate);
                    return;
                }
            }

            // Lookup the NodeMap if there is a static NetworkScene we can find on another Node
            if (_nodeTemplate == null && NodeManager.Instance.NodeMapSO != null)
            {
                _nodeTemplate = NodeManager.Instance.NodeMapSO.nodeMap.GetNodeTemplateBySceneName(pSceneName);
                if (_nodeTemplate != null)
                {
                    return;
                }
            }

            // Lookup if the scene is a dynamic NetworkScene on another Node
            if (_nodeTemplate == null && _enableLookup && _currentLookup == null)
            {
                _currentLookup = NodeManager.Instance.LookUpNetworkSceneTemplate(pSceneName);
                if (_currentLookup.State == ServiceCallbackStateEnum.RESPONSE_SUCCESS)
                {
                    _nodeTemplate  = _currentLookup.ResponseDataOfT;
                    _currentLookup = null;
                }
                else if (_currentLookup.State == ServiceCallbackStateEnum.AWAITING_RESPONSE)
                {
                    _currentLookup.OnResponseOfT += CurrentLookup_OnResponseOfT;
                    _currentLookup.OnTimeout     += CurrentLookup_OnTimeout;
                }
                else
                {
                    _pendingObjects.Clear();
                    _currentLookup = null;
                }
            }

            _findSceneDelay.Start(_findSceneInterval);
        }
Ejemplo n.º 11
0
        public virtual Node GetNodeWithTemplateOnly(string pSceneName)
        {
            //This creates a new and independent NetworkSceneNode with only the NetworkSceneTemplate in it.
            Node node = GetBySceneName(pSceneName);

            if (node == null)
            {
                return(null);
            }

            NetworkSceneTemplate networkSceneTemplate = node.GetBySceneName(pSceneName);
            RPCNode nodeRPC = node.ToRPC();

            nodeRPC.networkSceneTemplatesRPC = new RPCNetworkSceneTemplate[] { networkSceneTemplate.ToRPC() };
            return(new Node(nodeRPC));
        }
Ejemplo n.º 12
0
        public virtual NetworkSceneTemplate FindNetworkSceneTemplate(string pSceneName, bool pSearchNodeMap, bool pSearchStaticScenes, bool pSearchDynamicScenes, bool pSearchCachedScenes)
        {
            //check in our static NodeMap
            if (pSearchNodeMap)
            {
                NetworkSceneTemplate template = FindNetworkSceneTemplateInNodeMap(pSceneName);
                if (template != null)
                {
                    return(template);
                }
            }

            //check our static scenes
            if (pSearchStaticScenes)
            {
                NetworkSceneTemplate template = FindNetworkSceneTemplateInStaticScenes(pSceneName);
                if (template != null)
                {
                    return(template);
                }
            }

            //check our dynamic scenes
            if (pSearchDynamicScenes)
            {
                NetworkSceneTemplate template = FindNetworkSceneTemplateInDynamicScenes(pSceneName);
                if (template != null)
                {
                    return(template);
                }
            }

            //check in our cached scenes
            if (pSearchCachedScenes)
            {
                NetworkSceneTemplate template = FindNetworkSceneTemplateInCachedScenes(pSceneName);
                if (template != null)
                {
                    return(template);
                }
            }

            return(null);
        }
Ejemplo n.º 13
0
 public virtual ServiceCallback <RPCCreateNetworkSceneInNode, ServiceCallbackStateEnum> CreateNetworkSceneInNode(uint pSourceNodeId, uint pTargetNodeId, NetworkSceneTemplate pTemplate, bool pAutoAssignIp = false, bool pAutoAssignPort = false, byte[] pNetworkSceneMetaData = null)
 {
     return(NodeService.CreateNetworkSceneInNode(pSourceNodeId, pTargetNodeId, pTemplate, pAutoAssignIp, pAutoAssignPort, pNetworkSceneMetaData));
 }
Ejemplo n.º 14
0
 public virtual NetworkSceneManager CreateEmptyNetworkScene(NetworkSceneTemplate pTemplate)
 {
     return(CreateEmptyNetworkScene(pTemplate, _networkSceneBehaviorListSO));
 }
Ejemplo n.º 15
0
        public static ServiceCallback <RPCCreateNetworkSceneInNode, ServiceCallbackStateEnum> CreateNetworkSceneInNode(uint pSourceNodeId, uint pTargetNodeId, NetworkSceneTemplate pTemplate, bool pAutoAssignIp, bool pAutoAssignPort, byte[] pNetworkSceneMetaData)
        {
            ServiceCallback <RPCCreateNetworkSceneInNode, ServiceCallbackStateEnum> callback = new ServiceCallback <RPCCreateNetworkSceneInNode, ServiceCallbackStateEnum>(0, pSourceNodeId, GameTime.fixedTime);

            if (pTemplate == null)
            {
                callback.State = ServiceCallbackStateEnum.ERROR_NO_DATA;
                return(callback);
            }

            if (!IsInitialized)
            {
                callback.State = ServiceCallbackStateEnum.ERROR_SERVICE_NOT_INITIALIZED;
                return(callback);
            }

            if (Instance.Manager == null || !Instance.Manager.HasNetworker || !Instance.Manager.Networker.IsConnected)
            {
                callback.State = ServiceCallbackStateEnum.ERROR_NO_CONNECTION;
                return(callback);
            }

            RPCCreateNetworkSceneInNode requestData = new RPCCreateNetworkSceneInNode()
            {
                targetNodeId = pTargetNodeId, template = pTemplate.ToRPC(), autoAssignIp = pAutoAssignIp, autoAssignPort = pAutoAssignPort, networkSceneMetaData = pNetworkSceneMetaData
            };

            callback.RequestDataOfT = requestData;
            callback.State          = ServiceCallbackStateEnum.AWAITING_RESPONSE;
            Instance.AddPendingServiceCallback(callback);
            MainThreadManager.Run(() => {
                if (!IsInitialized || Instance.networkObject == null)
                {
                    return;
                }

                Instance.networkObject.SendRpc(RPC_RELAY_CREATE_NETWORK_SCENE_IN_NODE, Receivers.Server, callback.ToByteArray());
            });

            return(callback);
        }
Ejemplo n.º 16
0
        public static ServiceCallback <RPCNetworkSceneTemplate, ServiceCallbackStateEnum> RegisterScene(uint pSourceodeId, bool pRequireConfirmation, NetworkSceneTemplate pTemplate)
        {
            ServiceCallback <RPCNetworkSceneTemplate, ServiceCallbackStateEnum> callback = new ServiceCallback <RPCNetworkSceneTemplate, ServiceCallbackStateEnum>(0, pSourceodeId, GameTime.fixedTime);

            if (pTemplate == null)
            {
                callback.State = ServiceCallbackStateEnum.ERROR_NO_DATA;
                return(callback);
            }

            if (!IsInitialized)
            {
                callback.State = ServiceCallbackStateEnum.ERROR_SERVICE_NOT_INITIALIZED;
                return(callback);
            }

            if (Instance.Manager == null || !Instance.Manager.HasNetworker || !Instance.Manager.Networker.IsConnected)
            {
                callback.State = ServiceCallbackStateEnum.ERROR_NO_CONNECTION;
                return(callback);
            }

            callback.RequestDataOfT = pTemplate.ToRPC();
            if (pRequireConfirmation)
            {
                callback.State = ServiceCallbackStateEnum.AWAITING_RESPONSE;
                Instance.AddPendingServiceCallback(callback);
            }
            else
            {
                callback.State           = ServiceCallbackStateEnum.RESPONSE_SUCCESS;
                callback.ResponseTime    = GameTime.fixedTime;
                callback.ResponseDataOfT = callback.State;
            }

            MainThreadManager.Run(() => {
                if (!IsInitialized || Instance.networkObject == null)
                {
                    return;
                }

                Instance.networkObject.SendRpc(RPC_REGISTER_SCENE, Receivers.Server, pRequireConfirmation, callback.ToByteArray());
            });

            return(callback);
        }
Ejemplo n.º 17
0
 public virtual ServiceCallback <RPCNetworkSceneTemplate, ServiceCallbackStateEnum> RegisterDynamicScene(NetworkSceneTemplate pTemplate)
 {
     return(RegisterDynamicScene(_registerDynamicScenesRequireConfirmation, pTemplate));
 }
Ejemplo n.º 18
0
 public NetworkSceneTemplate(NetworkSceneTemplate pTemplate)
     : this(pTemplate.BuildIndex, pTemplate.SceneName, pTemplate.SceneOffset, new NetworkSceneManagerSetting(pTemplate.Settings))
 {
 }
Ejemplo n.º 19
0
 public virtual NetworkSceneItem CreateNetworkScene(NetworkSceneTemplate pSceneTemplate, byte[] pNetworkSceneMetaData = null)
 {
     return(CreateNetworkScene(pSceneTemplate, IsStaticScene(pSceneTemplate.SceneName), pNetworkSceneMetaData));
 }
Ejemplo n.º 20
0
 public virtual ServiceCallback <RPCNetworkSceneTemplate, ServiceCallbackStateEnum> RegisterDynamicScene(bool pRequireConfirmation, NetworkSceneTemplate pTemplate)
 {
     return(RegisterDynamicScene(_currentNode.NodeId, pRequireConfirmation, pTemplate));
 }
Ejemplo n.º 21
0
        public virtual ServiceCallback <RPCNetworkSceneTemplate, ServiceCallbackStateEnum> RegisterDynamicScene(uint pSourceNodeId, bool pRequireConfirmation, NetworkSceneTemplate pTemplate)
        {
            ServiceCallback <RPCNetworkSceneTemplate, ServiceCallbackStateEnum> callback = NodeService.RegisterScene(pSourceNodeId, pRequireConfirmation, pTemplate);

            if (callback.State == ServiceCallbackStateEnum.AWAITING_RESPONSE)
            {
                callback.OnResponse += (pResponseTime, pResponseData, pSender) => {
                    ConfirmRegisterDynamicScene(callback);
                };
            }

            return(callback);
        }
Ejemplo n.º 22
0
 public NodeNetworkSceneTemplate(uint pNodeId, NetworkSceneTemplate pNetworkSceneTemplate) : base(pNetworkSceneTemplate)
 {
     _nodeId = pNodeId;
 }
Ejemplo n.º 23
0
 public virtual void StartAsClient(NetworkSceneTemplate pTemplate)
 {
     _isServer = false;
     CreateNetworkScene(pTemplate, true);
 }