コード例 #1
0
        protected void HandleResponseCreateCharacter(LiteNetLibMessageHandler messageHandler)
        {
            TransportHandler transportHandler      = messageHandler.transportHandler;
            ResponseCreateCharacterMessage message = messageHandler.ReadMessage <ResponseCreateCharacterMessage>();

            transportHandler.TriggerAck(message.ackId, message.responseCode, message);
        }
コード例 #2
0
        private async UniTaskVoid HandleRequestCreateCharacterRoutine(LiteNetLibMessageHandler messageHandler)
        {
            long connectionId = messageHandler.connectionId;
            RequestCreateCharacterMessage message = messageHandler.ReadMessage <RequestCreateCharacterMessage>();

            ResponseCreateCharacterMessage.Error error = ResponseCreateCharacterMessage.Error.None;
            string characterName = message.characterName;
            int    dataId        = message.dataId;
            int    entityId      = message.entityId;
            int    factionId     = message.factionId;
            CentralUserPeerInfo   userPeerInfo;
            FindCharacterNameResp findCharacterNameResp = await DbServiceClient.FindCharacterNameAsync(new FindCharacterNameReq()
            {
                CharacterName = characterName
            });

            if (findCharacterNameResp.FoundAmount > 0)
            {
                error = ResponseCreateCharacterMessage.Error.CharacterNameAlreadyExisted;
            }
            else if (!userPeers.TryGetValue(connectionId, out userPeerInfo))
            {
                error = ResponseCreateCharacterMessage.Error.NotLoggedin;
            }
            else if (string.IsNullOrEmpty(characterName) || characterName.Length < minCharacterNameLength)
            {
                error = ResponseCreateCharacterMessage.Error.TooShortCharacterName;
            }
            else if (characterName.Length > maxCharacterNameLength)
            {
                error = ResponseCreateCharacterMessage.Error.TooLongCharacterName;
            }
            else if (!GameInstance.PlayerCharacters.ContainsKey(dataId) ||
                     !GameInstance.PlayerCharacterEntities.ContainsKey(entityId) ||
                     (GameInstance.Factions.Count > 0 && !GameInstance.Factions.ContainsKey(factionId)))
            {
                // If there is factions, it must have faction with the id stored in faction dictionary
                error = ResponseCreateCharacterMessage.Error.InvalidData;
            }
            else
            {
                string characterId = GenericUtils.GetUniqueId();
                PlayerCharacterData characterData = new PlayerCharacterData();
                characterData.Id = characterId;
                characterData.SetNewPlayerCharacterData(characterName, dataId, entityId);
                characterData.FactionId = factionId;
                DeserializeCreateCharacterExtra(characterData, messageHandler.reader);
                await DbServiceClient.CreateCharacterAsync(new CreateCharacterReq()
                {
                    UserId        = userPeerInfo.userId,
                    CharacterData = characterData.ToByteString()
                });
            }
            ResponseCreateCharacterMessage responseMessage = new ResponseCreateCharacterMessage();

            responseMessage.ackId        = message.ackId;
            responseMessage.responseCode = error == ResponseCreateCharacterMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error;
            responseMessage.error        = error;
            ServerSendResponse(connectionId, MMOMessageTypes.ResponseCreateCharacter, responseMessage);
        }
コード例 #3
0
        private IEnumerator HandleRequestCreateCharacterRoutine(LiteNetLibMessageHandler messageHandler)
        {
            long connectionId = messageHandler.connectionId;
            RequestCreateCharacterMessage message = messageHandler.ReadMessage <RequestCreateCharacterMessage>();

            ResponseCreateCharacterMessage.Error error = ResponseCreateCharacterMessage.Error.None;
            string characterName = message.characterName;
            int    dataId        = message.dataId;
            int    entityId      = message.entityId;
            int    factionId     = message.factionId;
            CentralUserPeerInfo  userPeerInfo;
            FindCharacterNameJob findCharacterNameJob = new FindCharacterNameJob(Database, characterName);

            findCharacterNameJob.Start();
            yield return(StartCoroutine(findCharacterNameJob.WaitFor()));

            if (findCharacterNameJob.result > 0)
            {
                error = ResponseCreateCharacterMessage.Error.CharacterNameAlreadyExisted;
            }
            else if (!userPeers.TryGetValue(connectionId, out userPeerInfo))
            {
                error = ResponseCreateCharacterMessage.Error.NotLoggedin;
            }
            else if (string.IsNullOrEmpty(characterName) || characterName.Length < minCharacterNameLength)
            {
                error = ResponseCreateCharacterMessage.Error.TooShortCharacterName;
            }
            else if (characterName.Length > maxCharacterNameLength)
            {
                error = ResponseCreateCharacterMessage.Error.TooLongCharacterName;
            }
            else if (!GameInstance.PlayerCharacters.ContainsKey(dataId) ||
                     !GameInstance.PlayerCharacterEntities.ContainsKey(entityId) ||
                     (GameInstance.Factions.Count > 0 && !GameInstance.Factions.ContainsKey(factionId)))
            {
                // If there is factions, it must have faction with the id stored in faction dictionary
                error = ResponseCreateCharacterMessage.Error.InvalidData;
            }
            else
            {
                string characterId = GenericUtils.GetUniqueId();
                PlayerCharacterData characterData = new PlayerCharacterData();
                characterData.Id = characterId;
                characterData.SetNewPlayerCharacterData(characterName, dataId, entityId);
                characterData.FactionId = factionId;
                DeserializeCreateCharacterExtra(characterData, messageHandler.reader);
                CreateCharacterJob createCharacterJob = new CreateCharacterJob(Database, userPeerInfo.userId, characterData);
                createCharacterJob.Start();
                yield return(StartCoroutine(createCharacterJob.WaitFor()));
            }
            ResponseCreateCharacterMessage responseMessage = new ResponseCreateCharacterMessage();

            responseMessage.ackId        = message.ackId;
            responseMessage.responseCode = error == ResponseCreateCharacterMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error;
            responseMessage.error        = error;
            ServerSendPacket(connectionId, DeliveryMethod.ReliableOrdered, MMOMessageTypes.ResponseCreateCharacter, responseMessage);
        }
コード例 #4
0
        private IEnumerator HandleRequestCreateCharacterRoutine(LiteNetLibMessageHandler messageHandler)
        {
            var connectionId  = messageHandler.connectionId;
            var message       = messageHandler.ReadMessage <RequestCreateCharacterMessage>();
            var error         = ResponseCreateCharacterMessage.Error.None;
            var characterName = message.characterName;
            var dataId        = message.dataId;
            var entityId      = message.entityId;
            CentralUserPeerInfo userPeerInfo;
            var findCharacterNameJob = new FindCharacterNameJob(Database, characterName);

            findCharacterNameJob.Start();
            yield return(StartCoroutine(findCharacterNameJob.WaitFor()));

            if (findCharacterNameJob.result > 0)
            {
                error = ResponseCreateCharacterMessage.Error.CharacterNameAlreadyExisted;
            }
            else if (!userPeers.TryGetValue(connectionId, out userPeerInfo))
            {
                error = ResponseCreateCharacterMessage.Error.NotLoggedin;
            }
            else if (string.IsNullOrEmpty(characterName) || characterName.Length < minCharacterNameLength)
            {
                error = ResponseCreateCharacterMessage.Error.TooShortCharacterName;
            }
            else if (characterName.Length > maxCharacterNameLength)
            {
                error = ResponseCreateCharacterMessage.Error.TooLongCharacterName;
            }
            else if (!GameInstance.PlayerCharacters.ContainsKey(dataId) ||
                     !GameInstance.PlayerCharacterEntities.ContainsKey(entityId))
            {
                error = ResponseCreateCharacterMessage.Error.InvalidData;
            }
            else
            {
                var characterId   = GenericUtils.GetUniqueId();
                var characterData = new PlayerCharacterData();
                characterData.Id = characterId;
                characterData.SetNewPlayerCharacterData(characterName, dataId, entityId);
                var createCharacterJob = new CreateCharacterJob(Database, userPeerInfo.userId, characterData);
                createCharacterJob.Start();
                yield return(StartCoroutine(createCharacterJob.WaitFor()));
            }
            var responseMessage = new ResponseCreateCharacterMessage();

            responseMessage.ackId        = message.ackId;
            responseMessage.responseCode = error == ResponseCreateCharacterMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error;
            responseMessage.error        = error;
            ServerSendPacket(connectionId, SendOptions.ReliableOrdered, MMOMessageTypes.ResponseCreateCharacter, responseMessage);
        }
コード例 #5
0
        private void OnRequestedCreateCharacter(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
            ResponseCreateCharacterMessage castedResponse = response as ResponseCreateCharacterMessage;

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

                case ResponseCreateCharacterMessage.Error.InvalidData:
                    errorMessage = LanguageManager.GetText(UITextKeys.UI_ERROR_INVALID_DATA.ToString());
                    break;

                case ResponseCreateCharacterMessage.Error.TooShortCharacterName:
                    errorMessage = LanguageManager.GetText(UITextKeys.UI_ERROR_CHARACTER_NAME_TOO_SHORT.ToString());
                    break;

                case ResponseCreateCharacterMessage.Error.TooLongCharacterName:
                    errorMessage = LanguageManager.GetText(UITextKeys.UI_ERROR_CHARACTER_NAME_TOO_LONG.ToString());
                    break;

                case ResponseCreateCharacterMessage.Error.CharacterNameAlreadyExisted:
                    errorMessage = LanguageManager.GetText(UITextKeys.UI_ERROR_CHARACTER_NAME_EXISTED.ToString());
                    break;
                }
                UISceneGlobal.Singleton.ShowMessageDialog(LanguageManager.GetText(UITextKeys.UI_LABEL_ERROR.ToString()), errorMessage);
                break;

            default:
                if (eventOnCreateCharacter != null)
                {
                    eventOnCreateCharacter.Invoke();
                }
                break;
            }
        }
コード例 #6
0
        private void OnRequestedCreateCharacter(AckResponseCode responseCode, BaseAckMessage message)
        {
            ResponseCreateCharacterMessage castedMessage = (ResponseCreateCharacterMessage)message;

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

                case ResponseCreateCharacterMessage.Error.InvalidData:
                    errorMessage = "Invalid data";
                    break;

                case ResponseCreateCharacterMessage.Error.TooShortCharacterName:
                    errorMessage = "Character name is too short";
                    break;

                case ResponseCreateCharacterMessage.Error.TooLongCharacterName:
                    errorMessage = "Character name is too long";
                    break;

                case ResponseCreateCharacterMessage.Error.CharacterNameAlreadyExisted:
                    errorMessage = "Character name is already existed";
                    break;
                }
                UISceneGlobal.Singleton.ShowMessageDialog("Cannot Create Characters", errorMessage);
                break;

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

            default:
                if (eventOnCreateCharacter != null)
                {
                    eventOnCreateCharacter.Invoke();
                }
                break;
            }
        }
コード例 #7
0
 private void OnRequestedCreateCharacter(ResponseHandlerData responseHandler, AckResponseCode responseCode, ResponseCreateCharacterMessage response)
 {
     if (responseCode.ShowUnhandledResponseMessageDialog(response.message))
     {
         return;
     }
     if (eventOnCreateCharacter != null)
     {
         eventOnCreateCharacter.Invoke();
     }
 }