コード例 #1
0
        /**
         * Handle character deletion frame
         */
        public Task CharacterDeletion(GameClient client, CharacterDeletionRequestMessage characterDeletionRequestMessage)
        {
            var character = this._characterRepository.Entities().Values.FirstOrDefault(x =>
                                                                                       x.Id == characterDeletionRequestMessage.characterId && x.AccountId == 1);

            //check if accountid and characterId are linked
            if (character == null)
            {
                client.Disconnect();
                return(null);
            }

            //if level > 20 need valid answer for delete character
            var exceptedSecretAnswerHash = CryptographyHelper.Md5(character.Id.ToString() + "~000000000000000000");

            if (character.Level >= CharacterManager.CONFIRM_DELETION_LVL)
            {
                exceptedSecretAnswerHash = CryptographyHelper.Md5(character.Id.ToString() + "~" + "DELETE"); //@IPC in future
                if (exceptedSecretAnswerHash == characterDeletionRequestMessage.secretAnswerHash)
                {
                    this._characterRepository.DeleteEntity(character);
                }
            }
            else
            {
                if (exceptedSecretAnswerHash == characterDeletionRequestMessage.secretAnswerHash)
                {
                    this._characterRepository.DeleteEntity(character);
                }
            }


            ApproachFrames.SendCharactersListMessage(client);

            return(Task.CompletedTask);
        }
コード例 #2
0
        /**
         * Handle character creation frame
         */
        public Task CreateCharacter(GameClient client, CharacterCreationRequestMessage characterCreationRequestMessage)
        {
            var characterAlreadyExist = this._characterRepository.Entities().Values
                                        .FirstOrDefault(x => x.Name == characterCreationRequestMessage.name);

            //check if account with name already exist
            if (characterAlreadyExist != null)
            {
                client.Send(new CharacterCreationResultMessage((int)CharacterCreationResultEnum.ERR_NAME_ALREADY_EXISTS));
                return(null);
            }

            //check length of name
            if (!this.VerifCharacterName(characterCreationRequestMessage.name))
            {
                client.Send(new CharacterCreationResultMessage((int)CharacterCreationResultEnum.ERR_INVALID_NAME));
                return(null);
            }

            //check if valid colors
            if (!characterCreationRequestMessage.colors.All(x => x >= 0))
            {
                client.Send(new CharacterCreationResultMessage((int)CharacterCreationResultEnum.ERR_NOT_ALLOWED));
                return(null);
            }

            var numberOfCharacters = this._characterRepository.Entities().Values.Count(x => x.AccountId == 1);

            //check if account has too many characters created
            if (numberOfCharacters >= 6)
            {
                client.Send(new CharacterCreationResultMessage((int)CharacterCreationResultEnum.ERR_TOO_MANY_CHARACTERS));
                return(null);
            }

            //find head by cosmeticId
            this.HeadsData.TryGetValue(characterCreationRequestMessage.cosmeticId, out Heads head);

            //check if cosmeticId is correspond to sex + breed
            if (head == null || Convert.ToBoolean(head.Gender) != characterCreationRequestMessage.sex ||
                head.Breed != characterCreationRequestMessage.breed)
            {
                client.Send(new CharacterCreationResultMessage((int)CharacterCreationResultEnum.ERR_NOT_ALLOWED));
                return(null);
            }

            var character = new Character();

            //character.Id = this.GenerateId();
            character.AccountId      = client.Account.Id;
            character.Breed          = characterCreationRequestMessage.breed;
            character.Sex            = characterCreationRequestMessage.sex;
            character.Level          = 200; //from config
            character.MapId          = 81266690;
            character.CellId         = 298;
            character.Experiences    = 0;
            character.Name           = characterCreationRequestMessage.name;
            character.EntityLookData = JsonConvert.SerializeObject(new EntityLook()
            {
                bonesId       = 1,
                scales        = new int[] { 125 },
                indexedColors = characterCreationRequestMessage.colors,
                skins         = new int[] { Convert.ToInt32(head.AssetId.Split("_")[0]), (int)head.Skins },
                subentities   = new SubEntity[] {}
            });

            this._characterRepository.AddEntity(character);

            client.Send(new CharacterCreationResultMessage((int)CharacterCreationResultEnum.OK));

            ApproachFrames.SendCharactersListMessage(client);

            return(Task.CompletedTask);
        }