Example #1
0
        /// <summary>
        /// Client attempts to create a new character.
        /// </summary>
        /// <param name="packet"></param>
        void OnCreateCharacter(PacketReader packet)
        {
            if (!IsAuthenticated)
            {
                return;
            }

            string characterName  = packet.ReadUTF16();
            int    characterClass = packet.ReadInt32();

            if (Server.Database.IsCharacterNameAvailable(characterName))
            {
                Character newCharacter;
                if (Server.Database.CreateCharacter(Account.Name, characterName, (short)characterClass, out newCharacter))
                {
                    Account.Characters.Add(newCharacter);

                    Send(PacketGenerator.CharacterCreate(0, newCharacter));
                }
                else
                {
                    Send(PacketGenerator.CharacterCreate(4, null));
                }
            }
            else
            {
                Send(PacketGenerator.CharacterCreate(1, null));
            }
        }