private void SpawnMap(
     RequestSpawnMapMessage message,
     RequestProceedResultDelegate <ResponseSpawnMapMessage> result,
     bool autoRestart)
 {
     SpawnMap(message.mapId, autoRestart, message, result);
 }
        internal async UniTaskVoid HandleRequestSpawnMap(
            RequestHandlerData requestHandler,
            RequestSpawnMapMessage request,
            RequestProceedResultDelegate <ResponseSpawnMapMessage> result)
        {
            UITextKeys message = UITextKeys.NONE;

            if (!ClusterClient.IsAppRegistered)
            {
                message = UITextKeys.UI_ERROR_APP_NOT_READY;
            }
            else if (string.IsNullOrEmpty(request.mapId))
            {
                message = UITextKeys.UI_ERROR_EMPTY_SCENE_NAME;
            }

            if (message != UITextKeys.NONE)
            {
                result.Invoke(AckResponseCode.Error, new ResponseSpawnMapMessage()
                {
                    message = message
                });
            }
            else
            {
                SpawnMap(request, result, false);
            }
            await UniTask.Yield();
        }
Exemplo n.º 3
0
        private UniTaskVoid HandleRequestSpawnMap(
            RequestHandlerData requestHandler,
            RequestSpawnMapMessage request,
            RequestProceedResultDelegate <ResponseSpawnMapMessage> result)
        {
            UITextKeys message = UITextKeys.NONE;

            if (!CentralAppServerRegister.IsRegisteredToCentralServer)
            {
                message = UITextKeys.UI_ERROR_APP_NOT_READY;
            }
            else if (string.IsNullOrEmpty(request.mapId))
            {
                message = UITextKeys.UI_ERROR_EMPTY_SCENE_NAME;
            }

            if (message != UITextKeys.NONE)
            {
                result.Invoke(AckResponseCode.Error, new ResponseSpawnMapMessage()
                {
                    message = message
                });
            }
            else
            {
                SpawnMap(request, result, false);
            }
            return(default);
        public uint RequestSpawnMap(long connectionId, string sceneName, AckMessageCallback callback)
        {
            var message = new RequestSpawnMapMessage();

            message.sceneName = sceneName;
            return(Server.ServerSendAckPacket(connectionId, SendOptions.ReliableOrdered, MMOMessageTypes.RequestSpawnMap, message, callback));
        }
Exemplo n.º 5
0
        private UniTaskVoid HandleRequestSpawnMap(
            RequestHandlerData requestHandler,
            RequestSpawnMapMessage request,
            RequestProceedResultDelegate <ResponseSpawnMapMessage> result)
        {
            ResponseSpawnMapMessage.Error error = ResponseSpawnMapMessage.Error.None;
            if (!CentralAppServerRegister.IsRegisteredToCentralServer)
            {
                error = ResponseSpawnMapMessage.Error.NotReady;
            }
            else if (string.IsNullOrEmpty(request.mapId))
            {
                error = ResponseSpawnMapMessage.Error.EmptySceneName;
            }

            if (error != ResponseSpawnMapMessage.Error.None)
            {
                result.Invoke(AckResponseCode.Error, new ResponseSpawnMapMessage()
                {
                    error = error
                });
            }
            else
            {
                SpawnMap(request, result, false);
            }
            return(default);
Exemplo n.º 6
0
        public uint RequestSpawnMap(long connectionId, string sceneName, string instanceId, AckMessageCallback callback)
        {
            RequestSpawnMapMessage message = new RequestSpawnMapMessage();

            message.mapId      = sceneName;
            message.instanceId = instanceId;
            return(RequestSpawnMap(connectionId, message, callback));
        }
Exemplo n.º 7
0
        public uint RequestSpawnMap(long connectionId, string sceneName, string instanceId, Vector3 instanceWarpPosition, bool instanceWarpOverrideRotation, Vector3 instanceWarpRotation, AckMessageCallback callback)
        {
            RequestSpawnMapMessage message = new RequestSpawnMapMessage();

            message.mapId                        = sceneName;
            message.instanceId                   = instanceId;
            message.instanceWarpPosition         = instanceWarpPosition;
            message.instanceWarpOverrideRotation = instanceWarpOverrideRotation;
            message.instanceWarpRotation         = instanceWarpRotation;
            return(RequestSpawnMap(connectionId, message, callback));
        }
Exemplo n.º 8
0
        /// <summary>
        /// This is function which read request from map server to spawn another map servers
        /// Then it will response back when requested map server is ready
        /// </summary>
        /// <param name="messageHandler"></param>
        protected void HandleRequestSpawnMap(LiteNetLibMessageHandler messageHandler)
        {
            RequestSpawnMapMessage message       = messageHandler.ReadMessage <RequestSpawnMapMessage>();
            List <long>            connectionIds = new List <long>(mapSpawnServerPeers.Keys);
            // Random map-spawn server to spawn map, will use returning ackId as reference to map-server's transport handler and ackId
            uint ackId = RequestSpawnMap(connectionIds[Random.Range(0, connectionIds.Count)], message, OnRequestSpawnMap);

            // Add ack Id / transport handler to dictionary which will be used in OnRequestSpawnMap() function
            // To send map spawn response to map-server
            requestSpawnMapHandlers.Add(ackId, new KeyValuePair <TransportHandler, uint>(messageHandler.transportHandler, message.ackId));
        }
        /// <summary>
        /// This is function which read request from map server to spawn another map servers
        /// Then it will response back when requested map server is ready
        /// </summary>
        /// <param name="messageHandler"></param>
        protected UniTaskVoid HandleRequestSpawnMap(
            RequestHandlerData requestHandler,
            RequestSpawnMapMessage request,
            RequestProceedResultDelegate <ResponseSpawnMapMessage> result)
        {
            string requestId = GenericUtils.GetUniqueId();

            request.requestId = requestId;
            List <long> connectionIds = new List <long>(mapSpawnServerPeers.Keys);

            // Random map-spawn server to spawn map, will use returning ackId as reference to map-server's transport handler and ackId
            RequestSpawnMap(connectionIds[Random.Range(0, connectionIds.Count)], request);
            // Add ack Id / transport handler to dictionary which will be used in OnRequestSpawnMap() function
            // To send map spawn response to map-server
            requestSpawnMapHandlers.Add(requestId, result);
            return(default);
Exemplo n.º 10
0
        protected override void WarpCharacterToInstance(BasePlayerCharacterEntity playerCharacterEntity, string mapName, Vector3 position)
        {
            if (!CanWarpCharacter(playerCharacterEntity))
            {
                return;
            }
            // Generate instance id
            string instanceId = GenericUtils.GetUniqueId();
            RequestSpawnMapMessage requestSpawnMapMessage = new RequestSpawnMapMessage();

            requestSpawnMapMessage.mapId      = mapName;
            requestSpawnMapMessage.instanceId = instanceId;
            // Prepare data for warp character later when instance map server registered to this map server
            HashSet <uint> instanceMapWarpingCharacters = new HashSet <uint>();
            PartyData      party;

            if (parties.TryGetValue(playerCharacterEntity.PartyId, out party))
            {
                // If character is party member, will bring party member to join instance
                if (party.IsLeader(playerCharacterEntity))
                {
                    List <BasePlayerCharacterEntity> aliveAllies = playerCharacterEntity.FindAliveCharacters <BasePlayerCharacterEntity>(gameInstance.joinInstanceMapDistance, true, false, false);
                    foreach (BasePlayerCharacterEntity aliveAlly in aliveAllies)
                    {
                        if (!party.IsMember(aliveAlly))
                        {
                            continue;
                        }
                        instanceMapWarpingCharacters.Add(aliveAlly.ObjectId);
                        aliveAlly.IsWarping = true;
                    }
                    instanceMapWarpingCharacters.Add(playerCharacterEntity.ObjectId);
                    playerCharacterEntity.IsWarping = true;
                }
            }
            else
            {
                // If no party enter instance alone
                instanceMapWarpingCharacters.Add(playerCharacterEntity.ObjectId);
                playerCharacterEntity.IsWarping = true;
            }
            instanceMapWarpingCharactersByInstanceId.Add(instanceId, instanceMapWarpingCharacters);
            instanceMapWarpingLocations.Add(instanceId, new KeyValuePair <string, Vector3>(mapName, position));
            CentralAppServerRegister.ClientSendAckPacket(DeliveryMethod.ReliableOrdered, MMOMessageTypes.RequestSpawnMap, requestSpawnMapMessage, OnRequestSpawnMap);
        }
Exemplo n.º 11
0
        private void HandleRequestSpawnMap(LiteNetLibMessageHandler messageHandler)
        {
            RequestSpawnMapMessage message = messageHandler.ReadMessage <RequestSpawnMapMessage>();

            ResponseSpawnMapMessage.Error error = ResponseSpawnMapMessage.Error.None;
            if (!CentralAppServerRegister.IsRegisteredToCentralServer)
            {
                error = ResponseSpawnMapMessage.Error.NotReady;
            }
            else if (string.IsNullOrEmpty(message.mapId))
            {
                error = ResponseSpawnMapMessage.Error.EmptySceneName;
            }

            if (error != ResponseSpawnMapMessage.Error.None)
            {
                ReponseMapSpawn(message.ackId, error);
            }
            else
            {
                SpawnMap(message, false);
            }
        }
Exemplo n.º 12
0
 private void SpawnMap(RequestSpawnMapMessage message, bool autoRestart)
 {
     SpawnMap(message.sceneName, autoRestart, message);
 }
Exemplo n.º 13
0
 public uint RequestSpawnMap(long connectionId, RequestSpawnMapMessage message, AckMessageCallback callback)
 {
     return(ServerSendRequest(connectionId, MMOMessageTypes.RequestSpawnMap, message, callback));
 }
 public bool RequestSpawnMap(long connectionId, RequestSpawnMapMessage message)
 {
     return(ServerSendRequest(connectionId, MMORequestTypes.RequestSpawnMap, message, millisecondsTimeout: mapSpawnMillisecondsTimeout));
 }
Exemplo n.º 15
0
        private void SpawnMap(string mapId, bool autoRestart, RequestSpawnMapMessage message = null)
        {
            // Port to run map server
            if (freePorts.Count > 0)
            {
                spawningPort = freePorts.Dequeue();
            }
            else
            {
                spawningPort = portCounter++;
            }
            int port = spawningPort;

            // Path to executable
            string path = ExePath;

            if (string.IsNullOrEmpty(path))
            {
                path = File.Exists(Environment.GetCommandLineArgs()[0])
                    ? Environment.GetCommandLineArgs()[0]
                    : Process.GetCurrentProcess().MainModule.FileName;
            }

            if (LogInfo)
            {
                UnityEngine.Debug.Log("Starting process from: " + path);
            }

            // Spawning Process Info
            ProcessStartInfo startProcessInfo = new ProcessStartInfo(path)
            {
                CreateNoWindow  = false,
                UseShellExecute = false,
                Arguments       = " " +
                                  (!NotSpawnInBatchMode ? "-batchmode -nographics " : "") +
                                  string.Format("{0} {1} ", MMOServerInstance.ARG_MAP_ID, mapId) +
                                  (message != null ? string.Format("{0} {1} ", MMOServerInstance.ARG_INSTANCE_ID, message.instanceId) : "") +
                                  string.Format("{0} {1} ", MMOServerInstance.ARG_CENTRAL_ADDRESS, centralNetworkAddress) +
                                  string.Format("{0} {1} ", MMOServerInstance.ARG_CENTRAL_PORT, centralNetworkPort) +
                                  string.Format("{0} {1} ", MMOServerInstance.ARG_MACHINE_ADDRESS, machineAddress) +
                                  string.Format("{0} {1} ", MMOServerInstance.ARG_MAP_PORT, port) +
                                  " " + MMOServerInstance.ARG_START_MAP_SERVER,
            };

            if (LogInfo)
            {
                UnityEngine.Debug.Log("Starting process with args: " + startProcessInfo.Arguments);
            }

            uint processId      = ++processIdCounter;
            bool processStarted = false;

            try
            {
                new Thread(() =>
                {
                    try
                    {
                        using (Process process = Process.Start(startProcessInfo))
                        {
                            lock (processLock)
                            {
                                // Save the process
                                processes[processId] = process;
                            }

                            processStarted = true;

                            ExecuteOnMainThread(() =>
                            {
                                if (LogInfo)
                                {
                                    UnityEngine.Debug.Log("Process started. Spawn Id: " + processId + ", pid: " + process.Id);
                                }
                                // Notify server that it's successfully handled the request
                                if (message != null)
                                {
                                    ReponseMapSpawn(message.ackId, ResponseSpawnMapMessage.Error.None);
                                }
                            });
                            process.WaitForExit();
                        }
                    }
                    catch (Exception e)
                    {
                        if (!processStarted)
                        {
                            ExecuteOnMainThread(() =>
                            {
                                if (LogFatal)
                                {
                                    UnityEngine.Debug.LogError("Tried to start a process at: '" + path + "' but it failed. Make sure that you have set correct the 'exePath' in 'MapSpawnNetworkManager' component");
                                    UnityEngine.Debug.LogException(e);
                                }

                                // Notify server that it failed to spawn map scene handled the request
                                if (message != null)
                                {
                                    ReponseMapSpawn(message.ackId, ResponseSpawnMapMessage.Error.CannotExecute);
                                }
                            });
                        }
                    }
                    finally
                    {
                        lock (processLock)
                        {
                            // Remove the process
                            processes.Remove(processId);

                            // Restarting scene
                            if (autoRestart)
                            {
                                restartingScenes.Add(mapId);
                            }
                        }

                        ExecuteOnMainThread(() =>
                        {
                            // Release the port number
                            FreePort(port);

                            if (LogInfo)
                            {
                                UnityEngine.Debug.Log("Process spawn id: " + processId + " killed.");
                            }
                        });
                    }
                }).Start();
            }
            catch (Exception e)
            {
                if (message != null)
                {
                    ReponseMapSpawn(message.ackId, ResponseSpawnMapMessage.Error.Unknow);
                }

                // Restarting scene
                if (autoRestart)
                {
                    restartingScenes.Add(mapId);
                }

                if (LogFatal)
                {
                    UnityEngine.Debug.LogException(e);
                }
            }
        }
Exemplo n.º 16
0
 private void SpawnMap(RequestSpawnMapMessage message, bool autoRestart)
 {
     SpawnMap(message.mapId, autoRestart, message);
 }
Exemplo n.º 17
0
        private void SpawnMap(string mapId, bool autoRestart, RequestSpawnMapMessage message = null)
        {
            // Port to run map server
            if (freePorts.Count > 0)
            {
                freePorts.TryDequeue(out spawningPort);
            }
            else
            {
                spawningPort = portCounter++;
            }
            int port = spawningPort;

            // Path to executable
            string path = ExePath;

            if (string.IsNullOrEmpty(path))
            {
                path = File.Exists(Environment.GetCommandLineArgs()[0])
                    ? Environment.GetCommandLineArgs()[0]
                    : Process.GetCurrentProcess().MainModule.FileName;
            }

            if (LogInfo)
            {
                Logging.Log(LogTag, "Starting process from: " + path);
            }

            // Spawning Process Info
            ProcessStartInfo startProcessInfo = new ProcessStartInfo(path)
            {
                CreateNoWindow  = false,
                UseShellExecute = false,
                Arguments       = (!NotSpawnInBatchMode ? "-batchmode -nographics " : string.Empty) +
                                  $"{MMOServerInstance.ARG_MAP_ID} {mapId} " +
                                  (message != null ?
                                   $"{MMOServerInstance.ARG_INSTANCE_ID} {message.instanceId} " +
                                   $"{MMOServerInstance.ARG_INSTANCE_POSITION_X} {message.instanceWarpPosition.x} " +
                                   $"{MMOServerInstance.ARG_INSTANCE_POSITION_Y} {message.instanceWarpPosition.y} " +
                                   $"{MMOServerInstance.ARG_INSTANCE_POSITION_Z} {message.instanceWarpPosition.z} " +
                                   $"{(message.instanceWarpOverrideRotation ? MMOServerInstance.ARG_INSTANCE_OVERRIDE_ROTATION : string.Empty)} " +
                                   $"{MMOServerInstance.ARG_INSTANCE_ROTATION_X} {message.instanceWarpRotation.x} " +
                                   $"{MMOServerInstance.ARG_INSTANCE_ROTATION_Y} {message.instanceWarpRotation.y} " +
                                   $"{MMOServerInstance.ARG_INSTANCE_ROTATION_Z} {message.instanceWarpRotation.z} "
                        : string.Empty) +
                                  $"{MMOServerInstance.ARG_CENTRAL_ADDRESS} {centralNetworkAddress} " +
                                  $"{MMOServerInstance.ARG_CENTRAL_PORT} {centralNetworkPort} " +
                                  $"{MMOServerInstance.ARG_MACHINE_ADDRESS} {machineAddress} " +
                                  $"{MMOServerInstance.ARG_MAP_PORT} {port} " +
                                  $"{MMOServerInstance.ARG_START_MAP_SERVER} ",
            };

            if (LogInfo)
            {
                Logging.Log(LogTag, "Starting process with args: " + startProcessInfo.Arguments);
            }

            int  processId      = 0;
            bool processStarted = false;

            try
            {
                new Thread(() =>
                {
                    try
                    {
                        using (Process process = Process.Start(startProcessInfo))
                        {
                            processId = process.Id;
                            processes.Add(processId);

                            processStarted = true;

                            mainThreadActions.Enqueue(() =>
                            {
                                if (LogInfo)
                                {
                                    Logging.Log(LogTag, "Process started. Id: " + processId);
                                }
                                // Notify server that it's successfully handled the request
                                if (message != null)
                                {
                                    ReponseMapSpawn(message.ackId, ResponseSpawnMapMessage.Error.None);
                                }
                            });
                            process.WaitForExit();
                        }
                    }
                    catch (Exception e)
                    {
                        if (!processStarted)
                        {
                            mainThreadActions.Enqueue(() =>
                            {
                                if (LogFatal)
                                {
                                    Logging.LogError(LogTag, "Tried to start a process at: '" + path + "' but it failed. Make sure that you have set correct the 'exePath' in 'MapSpawnNetworkManager' component");
                                    Logging.LogException(LogTag, e);
                                }

                                // Notify server that it failed to spawn map scene handled the request
                                if (message != null)
                                {
                                    ReponseMapSpawn(message.ackId, ResponseSpawnMapMessage.Error.CannotExecute);
                                }
                            });
                        }
                    }
                    finally
                    {
                        // Remove the process
                        processes.TryRemove(processId);

                        // Restarting scene
                        if (autoRestart)
                        {
                            restartingScenes.Enqueue(mapId);
                        }

                        mainThreadActions.Enqueue(() =>
                        {
                            // Release the port number
                            FreePort(port);

                            if (LogInfo)
                            {
                                Logging.Log(LogTag, "Process spawn id: " + processId + " killed.");
                            }
                        });
                    }
                }).Start();
            }
            catch (Exception e)
            {
                if (message != null)
                {
                    ReponseMapSpawn(message.ackId, ResponseSpawnMapMessage.Error.Unknow);
                }

                // Restarting scene
                if (autoRestart)
                {
                    restartingScenes.Enqueue(mapId);
                }

                if (LogFatal)
                {
                    Logging.LogException(LogTag, e);
                }
            }
        }
 public bool RequestSpawnMap(long connectionId, RequestSpawnMapMessage message)
 {
     return(ServerSendRequest(connectionId, MMORequestTypes.RequestSpawnMap, message, duration: mapSpawnDuration));
 }
Exemplo n.º 19
0
 public bool RequestSpawnMap(long connectionId, RequestSpawnMapMessage message)
 {
     return(SendRequest(connectionId, MMORequestTypes.RequestSpawnMap, message, millisecondsTimeout: centralNetworkManager.mapSpawnMillisecondsTimeout));
 }
Exemplo n.º 20
0
 private void SpawnMap(RequestSpawnMapMessage message)
 {
     SpawnMap(message.sceneName, message);
 }
 public uint RequestSpawnMap(long connectionId, RequestSpawnMapMessage message, AckMessageCallback callback)
 {
     return(Server.ServerSendAckPacket(connectionId, DeliveryMethod.ReliableOrdered, MMOMessageTypes.RequestSpawnMap, message, callback));
 }