protected virtual void OnInstantiateInNode_ServerClient(RpcArgs pArgs) { byte[] data = pArgs.GetNext <byte[]>(); RPCServiceCallback callbackRPC = data.ByteArrayToObject <RPCServiceCallback>(); NetworkBehavior behavior; if (NodeManager.IsInitialized) { RPCInstantiateInNode instantiateInNodeRPC = callbackRPC.data.ByteArrayToObject <RPCInstantiateInNode>(); behavior = NodeManager.Instance.InstantiateInScene(instantiateInNodeRPC.sceneName, instantiateInNodeRPC.createCode, null, instantiateInNodeRPC.position.ToVector3(), instantiateInNodeRPC.rotation.ToQuaternion(), instantiateInNodeRPC.sendTransform); if (behavior != null) { IRPCSerializable behaviorData = behavior as IRPCSerializable; if (behaviorData != null && instantiateInNodeRPC.behaviorData != null) { behaviorData.FromByteArray(instantiateInNodeRPC.behaviorData); } } } else { behavior = null; } callbackRPC.state = (behavior != null) ? ServiceCallbackStateEnum.RESPONSE_SUCCESS : ServiceCallbackStateEnum.RESPONSE_FAILED; callbackRPC.data = null; networkObject.SendRpc(RPC_RELAY_CONFIRM_INSTANTIATE_IN_NODE, Receivers.Server, callbackRPC.ObjectToByteArray()); }
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()); }
protected virtual void OnLookupScene_Server(RpcArgs pArgs) { byte[] data = pArgs.GetNext <byte[]>(); RPCServiceCallback callbackRPC = data.ByteArrayToObject <RPCServiceCallback>(); string sceneName = callbackRPC.data.ByteArrayToObject <string>(); NodeNetworkSceneTemplate nodeTemplate = (GetRegisteredScene(sceneName) ?? new NodeNetworkSceneTemplate(0, -1, String.Empty, RPCVector3.zero, null)); callbackRPC.data = nodeTemplate.ToByteArray(); networkObject.SendRpc(pArgs.Info.SendingPlayer, RPC_RECEIVE_LOOKUP_SCENE, nodeTemplate.NodeId, callbackRPC.ObjectToByteArray()); }
protected virtual void OnRelayConfirmCreateNetworkSceneInNode_Server(RpcArgs pArgs) { // We relay the message to the sourceNodeId byte[] data = pArgs.GetNext <byte[]>(); RPCServiceCallback callbackRPC = data.ByteArrayToObject <RPCServiceCallback>(); NetworkingPlayer networkingPlayer; if (!_nodeToNetworkingPlayer.TryGetValue(callbackRPC.sourceNodeId, out networkingPlayer)) { return; } networkObject.SendRpc(networkingPlayer, RPC_CONFIRM_CREATE_NETWORK_SCENE_IN_NODE, data); }
protected virtual void OnConfirmCreateNetworkSceneInNode_ServerClient(RpcArgs pArgs) { byte[] data = pArgs.GetNext <byte[]>(); RPCServiceCallback callbackRPC = data.ByteArrayToObject <RPCServiceCallback>(); ServiceCallback callback; if (!_pendingServiceCallbacks.TryGetValue(callbackRPC.callbackId, out callback)) { return; } RemovePendingServiceCallback(callback.CallbackId); callback.State = callbackRPC.state; callback.RaiseResponse(GameTime.fixedTime, callbackRPC.state.ObjectToByteArray()); }
protected virtual void OnUnregisterScene_Server(RpcArgs pArgs) { bool requireConfirmation = pArgs.GetNext <bool>(); byte[] data = pArgs.GetNext <byte[]>(); RPCServiceCallback callbackRPC = data.ByteArrayToObject <RPCServiceCallback>(); string sceneName = callbackRPC.data.ByteArrayToObject <string>(); bool removeSuccess = RemoveRegisteredScene(callbackRPC.sourceNodeId, sceneName); if (requireConfirmation) { //Only the callbackRPC.state is important for RPC_CONFIRM callbackRPC.state = (removeSuccess) ? ServiceCallbackStateEnum.RESPONSE_SUCCESS : ServiceCallbackStateEnum.RESPONSE_FAILED; callbackRPC.data = null; networkObject.SendRpc(pArgs.Info.SendingPlayer, RPC_CONFIRM_SCENE, callbackRPC.ObjectToByteArray()); } }
protected virtual void OnRelayCreateNetworkSceneInNode_Server(RpcArgs pArgs) { // We relay the message to the right Node if possible byte[] data = pArgs.GetNext <byte[]>(); RPCServiceCallback callbackRPC = data.ByteArrayToObject <RPCServiceCallback>(); RPCCreateNetworkSceneInNode createNetworkSceneInNodeRPC = callbackRPC.data.ByteArrayToObject <RPCCreateNetworkSceneInNode>(); NetworkingPlayer networkingPlayer; if (!_nodeToNetworkingPlayer.TryGetValue(createNetworkSceneInNodeRPC.targetNodeId, out networkingPlayer)) { callbackRPC.state = ServiceCallbackStateEnum.RESPONSE_FAILED; callbackRPC.data = null; networkObject.SendRpc(pArgs.Info.SendingPlayer, RPC_CONFIRM_CREATE_NETWORK_SCENE_IN_NODE, callbackRPC.ObjectToByteArray()); return; } networkObject.SendRpc(networkingPlayer, RPC_CREATE_NETWORK_SCENE_IN_NODE, data); }
protected virtual void OnRegisterScene_Server(RpcArgs pArgs) { bool requireConfirmation = pArgs.GetNext <bool>(); byte[] data = pArgs.GetNext <byte[]>(); RPCServiceCallback callbackRPC = data.ByteArrayToObject <RPCServiceCallback>(); RPCNetworkSceneTemplate templateRPC = callbackRPC.data.ByteArrayToObject <RPCNetworkSceneTemplate>(); NodeNetworkSceneTemplate registeredTemplate = GetRegisteredScene(templateRPC.sceneName); bool addSuccess = (registeredTemplate != null && registeredTemplate.NodeId == callbackRPC.sourceNodeId) || AddRegisteredScene(callbackRPC.sourceNodeId, new NodeNetworkSceneTemplate(callbackRPC.sourceNodeId, templateRPC)); if (requireConfirmation) { //Only the callbackRPC.state is important for RPC_CONFIRM callbackRPC.state = (addSuccess) ? ServiceCallbackStateEnum.RESPONSE_SUCCESS : ServiceCallbackStateEnum.RESPONSE_FAILED; callbackRPC.data = null; networkObject.SendRpc(pArgs.Info.SendingPlayer, RPC_CONFIRM_SCENE, callbackRPC.ObjectToByteArray()); } }
protected virtual void OnReceiveLookupScene_ServerClient(RpcArgs pArgs) { uint nodeId = pArgs.GetNext <uint>(); byte[] data = pArgs.GetNext <byte[]>(); RPCServiceCallback callbackRPC = data.ByteArrayToObject <RPCServiceCallback>(); RPCNetworkSceneTemplate templateRPC = callbackRPC.data.ByteArrayToObject <RPCNetworkSceneTemplate>(); NodeNetworkSceneTemplate nodeTemplate = new NodeNetworkSceneTemplate(nodeId, templateRPC); ServiceCallback callback; if (!_pendingServiceCallbacks.TryGetValue(callbackRPC.callbackId, out callback)) { return; } if (_enableLookupCaching && nodeTemplate.BuildIndex >= 0) { AddCacheLookup(nodeTemplate); } RemovePendingServiceCallback(callback.CallbackId); callback.RaiseResponse(GameTime.fixedTime, nodeTemplate.ObjectToByteArray()); }