示例#1
0
        public uint RequestAppServerAddress(CentralServerPeerType peerType, string extra, AckMessageCallback callback)
        {
            RequestAppServerAddressMessage message = new RequestAppServerAddressMessage();

            message.peerType = peerType;
            message.extra    = extra;
            return(Client.ClientSendAckPacket(DeliveryMethod.ReliableOrdered, MMOMessageTypes.RequestAppServerAddress, message, callback));
        }
示例#2
0
        public uint RequestAppServerAddress(CentralServerPeerType peerType, string extra, AckMessageCallback callback)
        {
            RequestAppServerAddressMessage message = new RequestAppServerAddressMessage();

            message.peerType = peerType;
            message.extra    = extra;
            return(ClientSendRequest(MMOMessageTypes.RequestAppServerAddress, message, callback));
        }
示例#3
0
        private async UniTaskVoid HandleRequestAppServerAddress(
            RequestHandlerData requestHandler,
            RequestAppServerAddressMessage request,
            RequestProceedResultDelegate <ResponseAppServerAddressMessage> result)
        {
            long                  connectionId = requestHandler.ConnectionId;
            UITextKeys            message      = UITextKeys.NONE;
            CentralServerPeerInfo peerInfo     = new CentralServerPeerInfo();

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

            case CentralServerPeerType.MapServer:
                string mapName = request.extra;
                if (!MapServerPeersByMapId.TryGetValue(mapName, out peerInfo))
                {
                    message = UITextKeys.UI_ERROR_SERVER_NOT_FOUND;
                    Logging.Log(LogTag, "Request Map Address: [" + connectionId + "] [" + mapName + "] [" + message + "]");
                }
                break;

            case CentralServerPeerType.InstanceMapServer:
                string instanceId = request.extra;
                if (!MapServerPeersByInstanceId.TryGetValue(instanceId, out peerInfo))
                {
                    message = UITextKeys.UI_ERROR_SERVER_NOT_FOUND;
                    Logging.Log(LogTag, "Request Map Address: [" + connectionId + "] [" + instanceId + "] [" + message + "]");
                }
                break;
            }
            // Response
            result.Invoke(
                message == UITextKeys.NONE ? AckResponseCode.Success : AckResponseCode.Error,
                new ResponseAppServerAddressMessage()
            {
                message  = message,
                peerInfo = peerInfo,
            });
            await UniTask.Yield();
        }
示例#4
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)
                    {
                        Debug.Log("[Central] Request Map Spawn Address: [" + connectionId + "]");
                    }
                }
                else
                {
                    error = ResponseAppServerAddressMessage.Error.ServerNotFound;
                    if (LogInfo)
                    {
                        Debug.Log("[Central] 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)
                    {
                        Debug.Log("[Central] Request Map Address: [" + connectionId + "] [" + mapName + "] [" + error + "]");
                    }
                }
                break;

            case CentralServerPeerType.Chat:
                if (chatServerPeers.Count > 0)
                {
                    peerInfo = chatServerPeers.Values.First();
                    if (LogInfo)
                    {
                        Debug.Log("[Central] Request Chat Address: [" + connectionId + "]");
                    }
                }
                else
                {
                    error = ResponseAppServerAddressMessage.Error.ServerNotFound;
                    if (LogInfo)
                    {
                        Debug.Log("[Central] 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;
            ServerSendPacket(connectionId, DeliveryMethod.ReliableOrdered, MMOMessageTypes.ResponseAppServerAddress, responseMessage);
        }