Ejemplo n.º 1
0
        protected void HandleResponseSelectCharacter(LiteNetLibMessageHandler messageHandler)
        {
            TransportHandler transportHandler      = messageHandler.transportHandler;
            ResponseSelectCharacterMessage message = messageHandler.ReadMessage <ResponseSelectCharacterMessage>();

            transportHandler.TriggerAck(message.ackId, message.responseCode, message);
        }
Ejemplo n.º 2
0
        private void OnRequestSelectCharacter(AckResponseCode responseCode, BaseAckMessage messageData, string characterId, AckMessageCallback callback)
        {
            if (callback != null)
            {
                callback(responseCode, messageData);
            }

            SelectCharacterId = string.Empty;
            ResponseSelectCharacterMessage castedMessage = messageData as ResponseSelectCharacterMessage;

            if (castedMessage.responseCode == AckResponseCode.Success)
            {
                SelectCharacterId = characterId;
            }
        }
        protected async UniTaskVoid HandleRequestSelectCharacter(
            RequestHandlerData requestHandler,
            RequestSelectCharacterMessage request,
            RequestProceedResultDelegate <ResponseSelectCharacterMessage> result)
        {
            long connectionId = requestHandler.ConnectionId;

            ResponseSelectCharacterMessage.Error error = ResponseSelectCharacterMessage.Error.None;
            CentralServerPeerInfo mapServerPeerInfo    = default;
            CentralUserPeerInfo   userPeerInfo;

            if (!userPeers.TryGetValue(connectionId, out userPeerInfo))
            {
                error = ResponseSelectCharacterMessage.Error.NotLoggedin;
            }
            else
            {
                CharacterResp characterResp = await DbServiceClient.ReadCharacterAsync(new ReadCharacterReq()
                {
                    UserId      = userPeerInfo.userId,
                    CharacterId = request.characterId
                });

                PlayerCharacterData character = characterResp.CharacterData.FromByteString <PlayerCharacterData>();
                if (character == null)
                {
                    error = ResponseSelectCharacterMessage.Error.InvalidCharacterData;
                }
                else if (!mapServerPeersBySceneName.TryGetValue(character.CurrentMapName, out mapServerPeerInfo))
                {
                    error = ResponseSelectCharacterMessage.Error.MapNotReady;
                }
            }
            AckResponseCode responseCode            = error == ResponseSelectCharacterMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error;
            ResponseSelectCharacterMessage response = new ResponseSelectCharacterMessage();

            response.error = error;
            if (error != ResponseSelectCharacterMessage.Error.MapNotReady)
            {
                response.sceneName      = mapServerPeerInfo.extra;
                response.networkAddress = mapServerPeerInfo.networkAddress;
                response.networkPort    = mapServerPeerInfo.networkPort;
            }
            // Response
            result.Invoke(responseCode, response);
        }
Ejemplo n.º 4
0
        protected async UniTaskVoid HandleRequestSelectCharacter(
            RequestHandlerData requestHandler,
            RequestSelectCharacterMessage request,
            RequestProceedResultDelegate <ResponseSelectCharacterMessage> result)
        {
#if UNITY_STANDALONE && !CLIENT_BUILD
            long                  connectionId      = requestHandler.ConnectionId;
            UITextKeys            message           = UITextKeys.NONE;
            CentralServerPeerInfo mapServerPeerInfo = default;
            CentralUserPeerInfo   userPeerInfo;
            if (!userPeers.TryGetValue(connectionId, out userPeerInfo))
            {
                message = UITextKeys.UI_ERROR_NOT_LOGGED_IN;
            }
            else
            {
                CharacterResp characterResp = await DbServiceClient.ReadCharacterAsync(new ReadCharacterReq()
                {
                    UserId      = userPeerInfo.userId,
                    CharacterId = request.characterId
                });

                PlayerCharacterData character = characterResp.CharacterData;
                if (character == null)
                {
                    message = UITextKeys.UI_ERROR_INVALID_CHARACTER_DATA;
                }
                else if (!mapServerPeersBySceneName.TryGetValue(character.CurrentMapName, out mapServerPeerInfo))
                {
                    message = UITextKeys.UI_ERROR_MAP_SERVER_NOT_READY;
                }
            }
            AckResponseCode responseCode            = message == UITextKeys.NONE ? AckResponseCode.Success : AckResponseCode.Error;
            ResponseSelectCharacterMessage response = new ResponseSelectCharacterMessage();
            response.message = message;
            if (message != UITextKeys.UI_ERROR_MAP_SERVER_NOT_READY)
            {
                response.sceneName      = mapServerPeerInfo.extra;
                response.networkAddress = mapServerPeerInfo.networkAddress;
                response.networkPort    = mapServerPeerInfo.networkPort;
            }
            // Response
            result.Invoke(responseCode, response);
#endif
        }
Ejemplo n.º 5
0
        private async UniTaskVoid HandleRequestSelectCharacterRoutine(LiteNetLibMessageHandler messageHandler)
        {
            long connectionId = messageHandler.connectionId;
            RequestSelectCharacterMessage message = messageHandler.ReadMessage <RequestSelectCharacterMessage>();

            ResponseSelectCharacterMessage.Error error = ResponseSelectCharacterMessage.Error.None;
            CentralServerPeerInfo mapServerPeerInfo    = default(CentralServerPeerInfo);
            CentralUserPeerInfo   userPeerInfo;

            if (!userPeers.TryGetValue(connectionId, out userPeerInfo))
            {
                error = ResponseSelectCharacterMessage.Error.NotLoggedin;
            }
            else
            {
                CharacterResp characterResp = await DbServiceClient.ReadCharacterAsync(new ReadCharacterReq()
                {
                    UserId      = userPeerInfo.userId,
                    CharacterId = message.characterId
                });

                PlayerCharacterData character = characterResp.CharacterData.FromByteString <PlayerCharacterData>();
                if (character == null)
                {
                    error = ResponseSelectCharacterMessage.Error.InvalidCharacterData;
                }
                else if (!mapServerPeersBySceneName.TryGetValue(character.CurrentMapName, out mapServerPeerInfo))
                {
                    error = ResponseSelectCharacterMessage.Error.MapNotReady;
                }
            }
            ResponseSelectCharacterMessage responseMessage = new ResponseSelectCharacterMessage();

            responseMessage.ackId        = message.ackId;
            responseMessage.responseCode = error == ResponseSelectCharacterMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error;
            responseMessage.error        = error;
            if (error != ResponseSelectCharacterMessage.Error.MapNotReady)
            {
                responseMessage.sceneName      = mapServerPeerInfo.extra;
                responseMessage.networkAddress = mapServerPeerInfo.networkAddress;
                responseMessage.networkPort    = mapServerPeerInfo.networkPort;
            }
            ServerSendResponse(connectionId, MMOMessageTypes.ResponseSelectCharacter, responseMessage);
        }
Ejemplo n.º 6
0
        private IEnumerator HandleRequestSelectCharacterRoutine(LiteNetLibMessageHandler messageHandler)
        {
            long connectionId = messageHandler.connectionId;
            RequestSelectCharacterMessage message = messageHandler.ReadMessage <RequestSelectCharacterMessage>();

            ResponseSelectCharacterMessage.Error error = ResponseSelectCharacterMessage.Error.None;
            CentralServerPeerInfo mapServerPeerInfo    = null;
            CentralUserPeerInfo   userPeerInfo;

            if (!userPeers.TryGetValue(connectionId, out userPeerInfo))
            {
                error = ResponseSelectCharacterMessage.Error.NotLoggedin;
            }
            else
            {
                ReadCharacterJob job = new ReadCharacterJob(Database, userPeerInfo.userId, message.characterId, false, false, false, false, false, false, false, false, false);
                job.Start();
                yield return(StartCoroutine(job.WaitFor()));

                PlayerCharacterData character = job.result;
                if (character == null)
                {
                    error = ResponseSelectCharacterMessage.Error.InvalidCharacterData;
                }
                else if (!mapServerPeersBySceneName.TryGetValue(character.CurrentMapName, out mapServerPeerInfo))
                {
                    error = ResponseSelectCharacterMessage.Error.MapNotReady;
                }
            }
            ResponseSelectCharacterMessage responseMessage = new ResponseSelectCharacterMessage();

            responseMessage.ackId        = message.ackId;
            responseMessage.responseCode = error == ResponseSelectCharacterMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error;
            responseMessage.error        = error;
            if (mapServerPeerInfo != null)
            {
                responseMessage.sceneName      = mapServerPeerInfo.extra;
                responseMessage.networkAddress = mapServerPeerInfo.networkAddress;
                responseMessage.networkPort    = mapServerPeerInfo.networkPort;
                responseMessage.connectKey     = mapServerPeerInfo.connectKey;
            }
            ServerSendPacket(connectionId, DeliveryMethod.ReliableOrdered, MMOMessageTypes.ResponseSelectCharacter, responseMessage);
        }
        private void OnRequestedSelectCharacter(ResponseHandlerData responseHandler, AckResponseCode responseCode, INetSerializable response)
        {
            if (responseCode == AckResponseCode.Timeout)
            {
                UISceneGlobal.Singleton.ShowMessageDialog(LanguageManager.GetText(UITextKeys.UI_LABEL_ERROR.ToString()), LanguageManager.GetText(UITextKeys.UI_ERROR_CONNECTION_TIMEOUT.ToString()));
                return;
            }
            // Proceed response
            ResponseSelectCharacterMessage castedResponse = response as ResponseSelectCharacterMessage;

            switch (responseCode)
            {
            case AckResponseCode.Error:
                string errorMessage = string.Empty;
                switch (castedResponse.error)
                {
                case ResponseSelectCharacterMessage.Error.NotLoggedin:
                    errorMessage = LanguageManager.GetText(UITextKeys.UI_ERROR_NOT_LOGGED_IN.ToString());
                    break;

                case ResponseSelectCharacterMessage.Error.AlreadySelectCharacter:
                    errorMessage = LanguageManager.GetText(UITextKeys.UI_ERROR_ALREADY_SELECT_CHARACTER.ToString());
                    break;

                case ResponseSelectCharacterMessage.Error.InvalidCharacterData:
                    errorMessage = LanguageManager.GetText(UITextKeys.UI_ERROR_INVALID_CHARACTER_DATA.ToString());
                    break;

                case ResponseSelectCharacterMessage.Error.MapNotReady:
                    errorMessage = LanguageManager.GetText(UITextKeys.UI_ERROR_MAP_SERVER_NOT_READY.ToString());
                    break;
                }
                UISceneGlobal.Singleton.ShowMessageDialog(LanguageManager.GetText(UITextKeys.UI_LABEL_ERROR.ToString()), errorMessage);
                break;

            default:
                MMOClientInstance.Singleton.StartMapClient(castedResponse.sceneName, castedResponse.networkAddress, castedResponse.networkPort);
                break;
            }
        }
        private void OnRequestedSelectCharacter(AckResponseCode responseCode, BaseAckMessage message)
        {
            ResponseSelectCharacterMessage castedMessage = (ResponseSelectCharacterMessage)message;

            switch (responseCode)
            {
            case AckResponseCode.Error:
                string errorMessage = string.Empty;
                switch (castedMessage.error)
                {
                case ResponseSelectCharacterMessage.Error.NotLoggedin:
                    errorMessage = LanguageManager.GetText(UILocaleKeys.UI_ERROR_NOT_LOGGED_IN.ToString());
                    break;

                case ResponseSelectCharacterMessage.Error.AlreadySelectCharacter:
                    errorMessage = LanguageManager.GetText(UILocaleKeys.UI_ERROR_ALREADY_SELECT_CHARACTER.ToString());
                    break;

                case ResponseSelectCharacterMessage.Error.InvalidCharacterData:
                    errorMessage = LanguageManager.GetText(UILocaleKeys.UI_ERROR_INVALID_CHARACTER_DATA.ToString());
                    break;

                case ResponseSelectCharacterMessage.Error.MapNotReady:
                    errorMessage = LanguageManager.GetText(UILocaleKeys.UI_ERROR_MAP_SERVER_NOT_READY.ToString());
                    break;
                }
                UISceneGlobal.Singleton.ShowMessageDialog(LanguageManager.GetText(UILocaleKeys.UI_LABEL_ERROR.ToString()), errorMessage);
                break;

            case AckResponseCode.Timeout:
                UISceneGlobal.Singleton.ShowMessageDialog(LanguageManager.GetText(UILocaleKeys.UI_LABEL_ERROR.ToString()), LanguageManager.GetText(UILocaleKeys.UI_ERROR_CONNECTION_TIMEOUT.ToString()));
                break;

            default:
                MMOClientInstance.Singleton.StartMapClient(castedMessage.sceneName, castedMessage.networkAddress, castedMessage.networkPort, castedMessage.connectKey);
                break;
            }
        }
Ejemplo n.º 9
0
        private void OnRequestedSelectCharacter(AckResponseCode responseCode, BaseAckMessage message)
        {
            ResponseSelectCharacterMessage castedMessage = (ResponseSelectCharacterMessage)message;

            switch (responseCode)
            {
            case AckResponseCode.Error:
                string errorMessage = string.Empty;
                switch (castedMessage.error)
                {
                case ResponseSelectCharacterMessage.Error.NotLoggedin:
                    errorMessage = "User not logged in";
                    break;

                case ResponseSelectCharacterMessage.Error.AlreadySelectCharacter:
                    errorMessage = "Already select character";
                    break;

                case ResponseSelectCharacterMessage.Error.InvalidCharacterData:
                    errorMessage = "Invalid character data";
                    break;

                case ResponseSelectCharacterMessage.Error.MapNotReady:
                    errorMessage = "Map server is not ready";
                    break;
                }
                UISceneGlobal.Singleton.ShowMessageDialog("Cannot Select Character", errorMessage);
                break;

            case AckResponseCode.Timeout:
                UISceneGlobal.Singleton.ShowMessageDialog("Cannot Select Character", "Connection timeout");
                break;

            default:
                MMOClientInstance.Singleton.StartMapClient(castedMessage.sceneName, castedMessage.networkAddress, castedMessage.networkPort, castedMessage.connectKey);
                break;
            }
        }
Ejemplo n.º 10
0
 private void OnRequestedSelectCharacter(ResponseHandlerData responseHandler, AckResponseCode responseCode, ResponseSelectCharacterMessage response)
 {
     if (responseCode.ShowUnhandledResponseMessageDialog(response.message))
     {
         return;
     }
     MMOClientInstance.Singleton.StartMapClient(response.sceneName, response.networkAddress, response.networkPort);
 }
        private async UniTaskVoid OnRequestSelectCharacter(ResponseHandlerData responseHandler, AckResponseCode responseCode, ResponseSelectCharacterMessage response, string characterId, ResponseDelegate <ResponseSelectCharacterMessage> callback)
        {
            await UniTask.Yield();

            if (callback != null)
            {
                callback.Invoke(responseHandler, responseCode, response);
            }

            GameInstance.SelectedCharacterId = string.Empty;
            if (responseCode == AckResponseCode.Success)
            {
                GameInstance.SelectedCharacterId = characterId;
            }
        }