Exemple #1
0
        protected void HandleResponseAppServerAddress(LiteNetLibMessageHandler messageHandler)
        {
            TransportHandler transportHandler       = messageHandler.transportHandler;
            ResponseAppServerAddressMessage message = messageHandler.ReadMessage <ResponseAppServerAddressMessage>();

            transportHandler.TriggerAck(message.ackId, message.responseCode, message);
        }
Exemple #2
0
        private void HandleResponseAppServerAddress(LiteNetLibMessageHandler messageHandler)
        {
            ResponseAppServerAddressMessage message = messageHandler.ReadMessage <ResponseAppServerAddressMessage>();

            if (message.responseCode == AckResponseCode.Success)
            {
                CentralServerPeerInfo peerInfo = message.peerInfo;
                switch (peerInfo.peerType)
                {
                case CentralServerPeerType.MapServer:
                    if (!string.IsNullOrEmpty(peerInfo.extra))
                    {
                        if (LogInfo)
                        {
                            Debug.Log("Register map server: " + peerInfo.extra);
                        }
                        mapServerConnectionIdsBySceneName[peerInfo.extra] = peerInfo;
                    }
                    break;

                case CentralServerPeerType.Chat:
                    if (!ChatNetworkManager.IsClientConnected)
                    {
                        if (LogInfo)
                        {
                            Debug.Log("Connecting to chat server");
                        }
                        ChatNetworkManager.StartClient(this, peerInfo.networkAddress, peerInfo.networkPort, peerInfo.connectKey);
                    }
                    break;
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// This function will be used to send connection information to connected map servers and chat servers
 /// </summary>
 /// <param name="connectionId"></param>
 /// <param name="peerInfo"></param>
 protected void BroadcastAppServers(long connectionId, CentralServerPeerInfo peerInfo)
 {
     // Send map peer info to other map server
     foreach (CentralServerPeerInfo mapServerPeer in mapServerPeers.Values)
     {
         // Send other info to current peer
         ResponseAppServerAddressMessage responseMapAddressMessage = new ResponseAppServerAddressMessage();
         responseMapAddressMessage.responseCode = AckResponseCode.Success;
         responseMapAddressMessage.error        = ResponseAppServerAddressMessage.Error.None;
         responseMapAddressMessage.peerInfo     = mapServerPeer;
         ServerSendPacket(connectionId, DeliveryMethod.ReliableOrdered, MMOMessageTypes.ResponseAppServerAddress, responseMapAddressMessage);
         // Send current info to other peer
         responseMapAddressMessage = new ResponseAppServerAddressMessage();
         responseMapAddressMessage.responseCode = AckResponseCode.Success;
         responseMapAddressMessage.error        = ResponseAppServerAddressMessage.Error.None;
         responseMapAddressMessage.peerInfo     = peerInfo;
         ServerSendPacket(mapServerPeer.connectionId, DeliveryMethod.ReliableOrdered, MMOMessageTypes.ResponseAppServerAddress, responseMapAddressMessage);
     }
     // Send chat peer info to new map server
     if (chatServerPeers.Count > 0)
     {
         CentralServerPeerInfo           chatPeerInfo = chatServerPeers.Values.First();
         ResponseAppServerAddressMessage responseChatAddressMessage = new ResponseAppServerAddressMessage();
         responseChatAddressMessage.responseCode = AckResponseCode.Success;
         responseChatAddressMessage.error        = ResponseAppServerAddressMessage.Error.None;
         responseChatAddressMessage.peerInfo     = chatPeerInfo;
         ServerSendPacket(connectionId, DeliveryMethod.ReliableOrdered, MMOMessageTypes.ResponseAppServerAddress, responseChatAddressMessage);
     }
 }
Exemple #4
0
        /// <summary>
        /// This function will be used to send connection information to connected map servers and chat servers
        /// </summary>
        /// <param name="connectionId"></param>
        /// <param name="peerInfo"></param>
        protected void BroadcastAppServers(long connectionId, CentralServerPeerInfo peerInfo)
        {
            ResponseAppServerAddressMessage appServerAddressMessage;

            // Send map peer info to other map server
            foreach (CentralServerPeerInfo mapServerPeer in mapServerPeers.Values)
            {
                // Send other info to current peer
                appServerAddressMessage = new ResponseAppServerAddressMessage();
                appServerAddressMessage.responseCode = AckResponseCode.Success;
                appServerAddressMessage.error        = ResponseAppServerAddressMessage.Error.None;
                appServerAddressMessage.peerInfo     = mapServerPeer;
                ServerSendResponse(connectionId, MMOMessageTypes.ResponseAppServerAddress, appServerAddressMessage);
                // Send current info to other peer
                appServerAddressMessage = new ResponseAppServerAddressMessage();
                appServerAddressMessage.responseCode = AckResponseCode.Success;
                appServerAddressMessage.error        = ResponseAppServerAddressMessage.Error.None;
                appServerAddressMessage.peerInfo     = peerInfo;
                ServerSendResponse(mapServerPeer.connectionId, MMOMessageTypes.ResponseAppServerAddress, appServerAddressMessage);
            }
            // Send chat peer info to new map server
            if (chatServerPeers.Count > 0)
            {
                CentralServerPeerInfo chatPeerInfo = chatServerPeers.Values.First();
                appServerAddressMessage = new ResponseAppServerAddressMessage();
                appServerAddressMessage.responseCode = AckResponseCode.Success;
                appServerAddressMessage.error        = ResponseAppServerAddressMessage.Error.None;
                appServerAddressMessage.peerInfo     = chatPeerInfo;
                ServerSendResponse(connectionId, MMOMessageTypes.ResponseAppServerAddress, appServerAddressMessage);
            }
        }
Exemple #5
0
        private void HandleAppServerAddress(MessageHandlerData messageHandler)
        {
            ResponseAppServerAddressMessage response = messageHandler.ReadMessage <ResponseAppServerAddressMessage>();

            if (onResponseAppServerAddress != null)
            {
                onResponseAppServerAddress.Invoke(AckResponseCode.Success, response.peerInfo);
            }
        }
Exemple #6
0
 private void HandleResponseAppServerAddress(
     ResponseHandlerData responseHandler,
     AckResponseCode responseCode,
     ResponseAppServerAddressMessage response)
 {
     if (onResponseAppServerAddress != null)
     {
         onResponseAppServerAddress.Invoke(responseCode, response.peerInfo);
     }
 }
        private void HandleResponseAppServerAddress(MessageHandlerData messageHandler)
        {
            ResponseAppServerAddressMessage message  = messageHandler.ReadMessage <ResponseAppServerAddressMessage>();
            CentralServerPeerInfo           peerInfo = message.peerInfo;

            switch (peerInfo.peerType)
            {
            case CentralServerPeerType.MapServer:
                if (!string.IsNullOrEmpty(peerInfo.extra))
                {
                    if (LogInfo)
                    {
                        Logging.Log(LogTag, "Register map server: " + peerInfo.extra);
                    }
                    mapServerConnectionIdsBySceneName[peerInfo.extra] = peerInfo;
                }
                break;

            case CentralServerPeerType.InstanceMapServer:
                if (!string.IsNullOrEmpty(peerInfo.extra))
                {
                    if (LogInfo)
                    {
                        Logging.Log(LogTag, "Register instance map server: " + peerInfo.extra);
                    }
                    instanceMapServerConnectionIdsByInstanceId[peerInfo.extra] = peerInfo;
                    // Warp characters
                    HashSet <uint> warpingCharacters;
                    if (instanceMapWarpingCharactersByInstanceId.TryGetValue(peerInfo.extra, out warpingCharacters))
                    {
                        BasePlayerCharacterEntity warpingCharacterEntity;
                        foreach (uint warpingCharacter in warpingCharacters)
                        {
                            if (!Assets.TryGetSpawnedObject(warpingCharacter, out warpingCharacterEntity))
                            {
                                continue;
                            }
                            WarpCharacterToInstanceRoutine(warpingCharacterEntity, peerInfo.extra).Forget();
                        }
                    }
                }
                break;

            case CentralServerPeerType.Chat:
                if (!ChatNetworkManager.IsClientConnected)
                {
                    if (LogInfo)
                    {
                        Logging.Log(LogTag, "Connecting to chat server");
                    }
                    ChatNetworkManager.StartClient(this, peerInfo.networkAddress, peerInfo.networkPort);
                }
                break;
            }
        }
        protected void HandleRequestAppServerAddress(LiteNetLibMessageHandler messageHandler)
        {
            var connectionId = messageHandler.connectionId;
            var message      = messageHandler.ReadMessage <RequestAppServerAddressMessage>();
            var error        = ResponseAppServerAddressMessage.Error.None;
            var peerInfo     = new CentralServerPeerInfo();

            switch (message.peerType)
            {
            // TODO: Balancing servers when there are multiple servers with same type
            case CentralServerPeerType.MapSpawnServer:
                if (mapSpawnServerPeers.Count > 0)
                {
                    peerInfo = mapSpawnServerPeers.Values.First();
                    Debug.Log("[Central] Request Map Spawn Address: [" + connectionId + "]");
                }
                else
                {
                    error = ResponseAppServerAddressMessage.Error.ServerNotFound;
                    Debug.Log("[Central] Request Map Spawn Address: [" + connectionId + "] [" + error + "]");
                }
                break;

            case CentralServerPeerType.MapServer:
                var mapName = message.extra;
                if (!mapServerPeersBySceneName.TryGetValue(mapName, out peerInfo))
                {
                    error = ResponseAppServerAddressMessage.Error.ServerNotFound;
                    Debug.Log("[Central] Request Map Address: [" + connectionId + "] [" + mapName + "] [" + error + "]");
                }
                break;

            case CentralServerPeerType.Chat:
                if (chatServerPeers.Count > 0)
                {
                    peerInfo = chatServerPeers.Values.First();
                    Debug.Log("[Central] Request Chat Address: [" + connectionId + "]");
                }
                else
                {
                    error = ResponseAppServerAddressMessage.Error.ServerNotFound;
                    Debug.Log("[Central] Request Chat Address: [" + connectionId + "] [" + error + "]");
                }
                break;
            }
            var responseMessage = new ResponseAppServerAddressMessage();

            responseMessage.ackId        = message.ackId;
            responseMessage.responseCode = error == ResponseAppServerAddressMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error;
            responseMessage.error        = error;
            responseMessage.peerInfo     = peerInfo;
            ServerSendPacket(connectionId, SendOptions.ReliableOrdered, MMOMessageTypes.ResponseAppServerAddress, responseMessage);
        }
Exemple #9
0
        protected void HandleRequestAppServerRegister(LiteNetLibMessageHandler messageHandler)
        {
            long connectionId = messageHandler.connectionId;
            RequestAppServerRegisterMessage message = messageHandler.ReadMessage <RequestAppServerRegisterMessage>();

            ResponseAppServerRegisterMessage.Error error = ResponseAppServerRegisterMessage.Error.None;
            if (message.ValidateHash())
            {
                CentralServerPeerInfo peerInfo = message.peerInfo;
                peerInfo.connectionId = connectionId;
                switch (message.peerInfo.peerType)
                {
                case CentralServerPeerType.MapSpawnServer:
                    mapSpawnServerPeers[connectionId] = peerInfo;
                    if (LogInfo)
                    {
                        Debug.Log("[Central] Register Map Spawn Server: [" + connectionId + "]");
                    }
                    break;

                case CentralServerPeerType.MapServer:
                    string sceneName = peerInfo.extra;
                    if (!mapServerPeersBySceneName.ContainsKey(sceneName))
                    {
                        BroadcastAppServers(connectionId, peerInfo);
                        // Collects server data
                        mapServerPeersBySceneName[sceneName] = peerInfo;
                        mapServerPeers[connectionId]         = peerInfo;
                        mapUserIds[connectionId]             = new HashSet <string>();
                        if (LogInfo)
                        {
                            Debug.Log("[Central] Register Map Server: [" + connectionId + "] [" + sceneName + "]");
                        }
                    }
                    else
                    {
                        error = ResponseAppServerRegisterMessage.Error.MapAlreadyExisted;
                        if (LogInfo)
                        {
                            Debug.Log("[Central] Register Map Server Failed: [" + connectionId + "] [" + sceneName + "] [" + error + "]");
                        }
                    }
                    break;

                case CentralServerPeerType.InstanceMapServer:
                    string instanceId = peerInfo.extra;
                    if (!instanceMapServerPeersByInstanceId.ContainsKey(instanceId))
                    {
                        BroadcastAppServers(connectionId, peerInfo);
                        // Collects server data
                        instanceMapServerPeersByInstanceId[instanceId] = peerInfo;
                        instanceMapServerPeers[connectionId]           = peerInfo;
                        mapUserIds[connectionId] = new HashSet <string>();
                        if (LogInfo)
                        {
                            Debug.Log("[Central] Register Instance Map Server: [" + connectionId + "] [" + instanceId + "]");
                        }
                    }
                    else
                    {
                        error = ResponseAppServerRegisterMessage.Error.EventAlreadyExisted;
                        if (LogInfo)
                        {
                            Debug.Log("[Central] Register Instance Map Server Failed: [" + connectionId + "] [" + instanceId + "] [" + error + "]");
                        }
                    }
                    break;

                case CentralServerPeerType.Chat:
                    chatServerPeers[connectionId] = peerInfo;
                    // Send chat peer info to map servers
                    foreach (CentralServerPeerInfo mapServerPeer in mapServerPeers.Values)
                    {
                        ResponseAppServerAddressMessage responseChatAddressMessage = new ResponseAppServerAddressMessage();
                        responseChatAddressMessage.responseCode = AckResponseCode.Success;
                        responseChatAddressMessage.error        = ResponseAppServerAddressMessage.Error.None;
                        responseChatAddressMessage.peerInfo     = peerInfo;
                        ServerSendPacket(mapServerPeer.connectionId, DeliveryMethod.ReliableOrdered, MMOMessageTypes.ResponseAppServerAddress, responseChatAddressMessage);
                    }
                    if (LogInfo)
                    {
                        Debug.Log("[Central] Register Chat Server: [" + connectionId + "]");
                    }
                    break;
                }
            }
            else
            {
                error = ResponseAppServerRegisterMessage.Error.InvalidHash;
                if (LogInfo)
                {
                    Debug.Log("[Central] Register Server Failed: [" + connectionId + "] [" + error + "]");
                }
            }

            ResponseAppServerRegisterMessage responseMessage = new ResponseAppServerRegisterMessage();

            responseMessage.ackId        = message.ackId;
            responseMessage.responseCode = error == ResponseAppServerRegisterMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error;
            responseMessage.error        = error;
            ServerSendPacket(connectionId, DeliveryMethod.ReliableOrdered, MMOMessageTypes.ResponseAppServerRegister, responseMessage);
        }
Exemple #10
0
        protected UniTaskVoid HandleRequestAppServerRegister(
            RequestHandlerData requestHandler,
            RequestAppServerRegisterMessage request,
            RequestProceedResultDelegate <ResponseAppServerRegisterMessage> result)
        {
#if UNITY_STANDALONE && !CLIENT_BUILD
            long       connectionId = requestHandler.ConnectionId;
            UITextKeys message      = UITextKeys.NONE;
            if (request.ValidateHash())
            {
                ResponseAppServerAddressMessage responseAppServerAddressMessage;
                CentralServerPeerInfo           peerInfo = request.peerInfo;
                peerInfo.connectionId = connectionId;
                switch (request.peerInfo.peerType)
                {
                case CentralServerPeerType.MapSpawnServer:
                    mapSpawnServerPeers[connectionId] = peerInfo;
                    if (LogInfo)
                    {
                        Logging.Log(LogTag, "Register Map Spawn Server: [" + connectionId + "]");
                    }
                    break;

                case CentralServerPeerType.MapServer:
                    string sceneName = peerInfo.extra;
                    if (!mapServerPeersBySceneName.ContainsKey(sceneName))
                    {
                        BroadcastAppServers(connectionId, peerInfo);
                        // Collects server data
                        mapServerPeersBySceneName[sceneName] = peerInfo;
                        mapServerPeers[connectionId]         = peerInfo;
                        mapUserIds[connectionId]             = new HashSet <string>();
                        if (LogInfo)
                        {
                            Logging.Log(LogTag, "Register Map Server: [" + connectionId + "] [" + sceneName + "]");
                        }
                    }
                    else
                    {
                        message = UITextKeys.UI_ERROR_MAP_EXISTED;
                        if (LogInfo)
                        {
                            Logging.Log(LogTag, "Register Map Server Failed: [" + connectionId + "] [" + sceneName + "] [" + message + "]");
                        }
                    }
                    break;

                case CentralServerPeerType.InstanceMapServer:
                    string instanceId = peerInfo.extra;
                    if (!instanceMapServerPeersByInstanceId.ContainsKey(instanceId))
                    {
                        BroadcastAppServers(connectionId, peerInfo);
                        // Collects server data
                        instanceMapServerPeersByInstanceId[instanceId] = peerInfo;
                        instanceMapServerPeers[connectionId]           = peerInfo;
                        mapUserIds[connectionId] = new HashSet <string>();
                        if (LogInfo)
                        {
                            Logging.Log(LogTag, "Register Instance Map Server: [" + connectionId + "] [" + instanceId + "]");
                        }
                    }
                    else
                    {
                        message = UITextKeys.UI_ERROR_EVENT_EXISTED;
                        if (LogInfo)
                        {
                            Logging.Log(LogTag, "Register Instance Map Server Failed: [" + connectionId + "] [" + instanceId + "] [" + message + "]");
                        }
                    }
                    break;

                case CentralServerPeerType.Chat:
                    chatServerPeers[connectionId] = peerInfo;
                    // Send chat peer info to map servers
                    responseAppServerAddressMessage = new ResponseAppServerAddressMessage()
                    {
                        message  = UITextKeys.NONE,
                        peerInfo = peerInfo,
                    };
                    foreach (CentralServerPeerInfo mapServerPeer in mapServerPeers.Values)
                    {
                        ServerSendPacket(mapServerPeer.connectionId, DeliveryMethod.ReliableOrdered, MMOMessageTypes.AppServerAddress, responseAppServerAddressMessage);
                    }
                    if (LogInfo)
                    {
                        Logging.Log(LogTag, "Register Chat Server: [" + connectionId + "]");
                    }
                    break;
                }
            }
            else
            {
                message = UITextKeys.UI_ERROR_INVALID_SERVER_HASH;
                if (LogInfo)
                {
                    Logging.Log(LogTag, "Register Server Failed: [" + connectionId + "] [" + message + "]");
                }
            }
            // Response
            result.Invoke(
                message == UITextKeys.NONE ? AckResponseCode.Success : AckResponseCode.Error,
                new ResponseAppServerRegisterMessage()
            {
                message = message,
            });
#endif
            return(default);
Exemple #11
0
        protected void HandleRequestAppServerAddress(LiteNetLibMessageHandler messageHandler)
        {
            long connectionId = messageHandler.connectionId;
            RequestAppServerAddressMessage message = messageHandler.ReadMessage <RequestAppServerAddressMessage>();

            ResponseAppServerAddressMessage.Error error = ResponseAppServerAddressMessage.Error.None;
            CentralServerPeerInfo peerInfo = new CentralServerPeerInfo();

            switch (message.peerType)
            {
            // TODO: Balancing servers when there are multiple servers with same type
            case CentralServerPeerType.MapSpawnServer:
                if (mapSpawnServerPeers.Count > 0)
                {
                    peerInfo = mapSpawnServerPeers.Values.First();
                    if (LogInfo)
                    {
                        Logging.Log(LogTag, "Request Map Spawn Address: [" + connectionId + "]");
                    }
                }
                else
                {
                    error = ResponseAppServerAddressMessage.Error.ServerNotFound;
                    if (LogInfo)
                    {
                        Logging.Log(LogTag, "Request Map Spawn Address: [" + connectionId + "] [" + error + "]");
                    }
                }
                break;

            case CentralServerPeerType.MapServer:
                string mapName = message.extra;
                if (!mapServerPeersBySceneName.TryGetValue(mapName, out peerInfo))
                {
                    error = ResponseAppServerAddressMessage.Error.ServerNotFound;
                    if (LogInfo)
                    {
                        Logging.Log(LogTag, "Request Map Address: [" + connectionId + "] [" + mapName + "] [" + error + "]");
                    }
                }
                break;

            case CentralServerPeerType.Chat:
                if (chatServerPeers.Count > 0)
                {
                    peerInfo = chatServerPeers.Values.First();
                    if (LogInfo)
                    {
                        Logging.Log(LogTag, "Request Chat Address: [" + connectionId + "]");
                    }
                }
                else
                {
                    error = ResponseAppServerAddressMessage.Error.ServerNotFound;
                    if (LogInfo)
                    {
                        Logging.Log(LogTag, "Request Chat Address: [" + connectionId + "] [" + error + "]");
                    }
                }
                break;
            }
            ResponseAppServerAddressMessage responseMessage = new ResponseAppServerAddressMessage();

            responseMessage.ackId        = message.ackId;
            responseMessage.responseCode = error == ResponseAppServerAddressMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error;
            responseMessage.error        = error;
            responseMessage.peerInfo     = peerInfo;
            ServerSendResponse(connectionId, MMOMessageTypes.ResponseAppServerAddress, responseMessage);
        }
        protected void HandleRequestAppServerRegister(LiteNetLibMessageHandler messageHandler)
        {
            var connectionId = messageHandler.connectionId;
            var message      = messageHandler.ReadMessage <RequestAppServerRegisterMessage>();
            var error        = ResponseAppServerRegisterMessage.Error.None;

            if (message.ValidateHash())
            {
                var peerInfo = message.peerInfo;
                peerInfo.connectionId = connectionId;
                switch (message.peerInfo.peerType)
                {
                case CentralServerPeerType.MapSpawnServer:
                    mapSpawnServerPeers[connectionId] = peerInfo;
                    Debug.Log("[Central] Register Map Spawn Server: [" + connectionId + "]");
                    break;

                case CentralServerPeerType.MapServer:
                    var sceneName = peerInfo.extra;
                    if (!mapServerPeersBySceneName.ContainsKey(sceneName))
                    {
                        // Send map peer info to other map server
                        foreach (var mapServerPeer in mapServerPeers.Values)
                        {
                            // Send other info to current peer
                            var responseMapAddressMessage = new ResponseAppServerAddressMessage();
                            responseMapAddressMessage.responseCode = AckResponseCode.Success;
                            responseMapAddressMessage.error        = ResponseAppServerAddressMessage.Error.None;
                            responseMapAddressMessage.peerInfo     = mapServerPeer;
                            ServerSendPacket(connectionId, SendOptions.ReliableOrdered, MMOMessageTypes.ResponseAppServerAddress, responseMapAddressMessage);
                            // Send current info to other peer
                            responseMapAddressMessage = new ResponseAppServerAddressMessage();
                            responseMapAddressMessage.responseCode = AckResponseCode.Success;
                            responseMapAddressMessage.error        = ResponseAppServerAddressMessage.Error.None;
                            responseMapAddressMessage.peerInfo     = peerInfo;
                            ServerSendPacket(mapServerPeer.connectionId, SendOptions.ReliableOrdered, MMOMessageTypes.ResponseAppServerAddress, responseMapAddressMessage);
                        }
                        // Send chat peer info to new map server
                        if (chatServerPeers.Count > 0)
                        {
                            var chatPeerInfo = chatServerPeers.Values.First();
                            var responseChatAddressMessage = new ResponseAppServerAddressMessage();
                            responseChatAddressMessage.responseCode = AckResponseCode.Success;
                            responseChatAddressMessage.error        = ResponseAppServerAddressMessage.Error.None;
                            responseChatAddressMessage.peerInfo     = chatPeerInfo;
                            ServerSendPacket(connectionId, SendOptions.ReliableOrdered, MMOMessageTypes.ResponseAppServerAddress, responseChatAddressMessage);
                        }
                        // Collects server data
                        mapServerPeersBySceneName[sceneName] = peerInfo;
                        mapServerPeers[connectionId]         = peerInfo;
                        mapUserIds[connectionId]             = new HashSet <string>();
                        Debug.Log("[Central] Register Map Server: [" + connectionId + "] [" + sceneName + "]");
                    }
                    else
                    {
                        error = ResponseAppServerRegisterMessage.Error.MapAlreadyExisted;
                        Debug.Log("[Central] Register Map Server Failed: [" + connectionId + "] [" + sceneName + "] [" + error + "]");
                    }
                    break;

                case CentralServerPeerType.Chat:
                    chatServerPeers[connectionId] = peerInfo;
                    // Send chat peer info to map servers
                    foreach (var mapServerPeer in mapServerPeers.Values)
                    {
                        var responseChatAddressMessage = new ResponseAppServerAddressMessage();
                        responseChatAddressMessage.responseCode = AckResponseCode.Success;
                        responseChatAddressMessage.error        = ResponseAppServerAddressMessage.Error.None;
                        responseChatAddressMessage.peerInfo     = peerInfo;
                        ServerSendPacket(mapServerPeer.connectionId, SendOptions.ReliableOrdered, MMOMessageTypes.ResponseAppServerAddress, responseChatAddressMessage);
                    }
                    Debug.Log("[Central] Register Chat Server: [" + connectionId + "]");
                    break;
                }
            }
            else
            {
                error = ResponseAppServerRegisterMessage.Error.InvalidHash;
                Debug.Log("[Central] Register Server Failed: [" + connectionId + "] [" + error + "]");
            }

            var responseMessage = new ResponseAppServerRegisterMessage();

            responseMessage.ackId        = message.ackId;
            responseMessage.responseCode = error == ResponseAppServerRegisterMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error;
            responseMessage.error        = error;
            ServerSendPacket(connectionId, SendOptions.ReliableOrdered, MMOMessageTypes.ResponseAppServerRegister, responseMessage);
        }
        protected UniTaskVoid HandleRequestAppServerRegister(
            RequestHandlerData requestHandler,
            RequestAppServerRegisterMessage request,
            RequestProceedResultDelegate <ResponseAppServerRegisterMessage> result)
        {
            long connectionId = requestHandler.ConnectionId;

            ResponseAppServerRegisterMessage.Error error = ResponseAppServerRegisterMessage.Error.None;
            if (request.ValidateHash())
            {
                ResponseAppServerAddressMessage responseAppServerAddressMessage;
                CentralServerPeerInfo           peerInfo = request.peerInfo;
                peerInfo.connectionId = connectionId;
                switch (request.peerInfo.peerType)
                {
                case CentralServerPeerType.MapSpawnServer:
                    mapSpawnServerPeers[connectionId] = peerInfo;
                    if (LogInfo)
                    {
                        Logging.Log(LogTag, "Register Map Spawn Server: [" + connectionId + "]");
                    }
                    break;

                case CentralServerPeerType.MapServer:
                    string sceneName = peerInfo.extra;
                    if (!mapServerPeersBySceneName.ContainsKey(sceneName))
                    {
                        BroadcastAppServers(connectionId, peerInfo);
                        // Collects server data
                        mapServerPeersBySceneName[sceneName] = peerInfo;
                        mapServerPeers[connectionId]         = peerInfo;
                        mapUserIds[connectionId]             = new HashSet <string>();
                        if (LogInfo)
                        {
                            Logging.Log(LogTag, "Register Map Server: [" + connectionId + "] [" + sceneName + "]");
                        }
                    }
                    else
                    {
                        error = ResponseAppServerRegisterMessage.Error.MapAlreadyExisted;
                        if (LogInfo)
                        {
                            Logging.Log(LogTag, "Register Map Server Failed: [" + connectionId + "] [" + sceneName + "] [" + error + "]");
                        }
                    }
                    break;

                case CentralServerPeerType.InstanceMapServer:
                    string instanceId = peerInfo.extra;
                    if (!instanceMapServerPeersByInstanceId.ContainsKey(instanceId))
                    {
                        BroadcastAppServers(connectionId, peerInfo);
                        // Collects server data
                        instanceMapServerPeersByInstanceId[instanceId] = peerInfo;
                        instanceMapServerPeers[connectionId]           = peerInfo;
                        mapUserIds[connectionId] = new HashSet <string>();
                        if (LogInfo)
                        {
                            Logging.Log(LogTag, "Register Instance Map Server: [" + connectionId + "] [" + instanceId + "]");
                        }
                    }
                    else
                    {
                        error = ResponseAppServerRegisterMessage.Error.EventAlreadyExisted;
                        if (LogInfo)
                        {
                            Logging.Log(LogTag, "Register Instance Map Server Failed: [" + connectionId + "] [" + instanceId + "] [" + error + "]");
                        }
                    }
                    break;

                case CentralServerPeerType.Chat:
                    chatServerPeers[connectionId] = peerInfo;
                    // Send chat peer info to map servers
                    responseAppServerAddressMessage = new ResponseAppServerAddressMessage()
                    {
                        error    = ResponseAppServerAddressMessage.Error.None,
                        peerInfo = peerInfo,
                    };
                    foreach (CentralServerPeerInfo mapServerPeer in mapServerPeers.Values)
                    {
                        ServerSendPacket(mapServerPeer.connectionId, DeliveryMethod.ReliableOrdered, MMOMessageTypes.AppServerAddress, responseAppServerAddressMessage);
                    }
                    if (LogInfo)
                    {
                        Logging.Log(LogTag, "Register Chat Server: [" + connectionId + "]");
                    }
                    break;
                }
            }
            else
            {
                error = ResponseAppServerRegisterMessage.Error.InvalidHash;
                if (LogInfo)
                {
                    Logging.Log(LogTag, "Register Server Failed: [" + connectionId + "] [" + error + "]");
                }
            }
            // Response
            result.Invoke(
                error == ResponseAppServerRegisterMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error,
                new ResponseAppServerRegisterMessage()
            {
                error = error,
            });
            return(default);