Example #1
0
        private void PerformCharacterCreate(SubPacket subPacket)
        {
            Database db = new Database();
            CharacterCreatePacket cp = new CharacterCreatePacket(subPacket.data);
            int error = db.AddCharacterToDb(ap.userName, cp);

            if (error == -1)
            {
                SubPacket  success    = new SubPacket(GamePacketOpCode.CreateCharacterSuccess, 0, 0, System.Text.Encoding.Unicode.GetBytes("Character created successfully"), SubPacketTypes.GamePacket);
                BasePacket basePacket = BasePacket.CreatePacket(success, client.authenticated, false);
                client.QueuePacket(basePacket);
                //created successfully
            }
            else
            {
                ErrorPacket ep = new ErrorPacket();
                if (error == (int)ErrorCodes.DuplicateCharacter)
                {
                    var packetToSend = ep.buildPacket(GamePacketOpCode.CreateCharacterError, ErrorCodes.DuplicateCharacter, "Character with that name already exists");
                }
                if (error == (int)ErrorCodes.UnknownDatabaseError)
                {
                    var packetToSend = ep.buildPacket(GamePacketOpCode.CreateCharacterError, ErrorCodes.UnknownDatabaseError, "Unknown database error occurred");
                    QueueErrorPacket(packetToSend);
                }
            }
        }
Example #2
0
        private void PerformCharacterCreate(SubPacket subPacket)
        {
            LoginDatabase         db = new LoginDatabase();
            CharacterCreatePacket cp = new CharacterCreatePacket(subPacket.data);

            try
            {
                db.AddCharacterToDb(ap.userName, cp);
                SubPacket  success    = new SubPacket(GamePacketOpCode.CreateCharacterSuccess, 0, 0, System.Text.Encoding.Unicode.GetBytes("Character created successfully"), SubPacketTypes.GamePacket);
                BasePacket basePacket = BasePacket.CreatePacket(success, client.authenticated, false);
                client.QueuePacket(basePacket);
            }
            catch (MySqlException e)
            {
                ErrorPacket ep = new ErrorPacket();
                SubPacket   packetToSend;
                if (e.Number == (int)ErrorCodes.DuplicateCharacter)
                {
                    packetToSend = ep.buildPacket(GamePacketOpCode.CreateCharacterError, ErrorCodes.DuplicateCharacter, "Character with that name already exists");
                }
                else
                {
                    packetToSend = ep.buildPacket(GamePacketOpCode.CreateCharacterError, ErrorCodes.UnknownDatabaseError, "Unknown database error occurred");
                }

                QueueErrorPacket(packetToSend);
            }
        }
Example #3
0
        private bool CheckCharacterCreatePacket(SubPacket subPacket)
        {
            Database db = new Database();
            CharacterCreatePacket cp = new CharacterCreatePacket(subPacket.data);
            var summedStats          = cp.GetStr() + cp.GetAgi() + cp.GetInt() + cp.GetVit() + cp.GetDex();

            Console.WriteLine(ap.userName);
            if (summedStats != cp.statsAllowed)
            {
                Console.WriteLine("summed stats: {0} was different from packet: {1}", summedStats, cp.statsAllowed);
                Console.WriteLine("Someone is trying to hack the client for stat character creation. Username was {0}", ap.userName);
                return(false);
            }
            Console.WriteLine("Received new character creation request for character name: {0}", cp.GetCharacterName());
            if (db.GetNumberOfCharactersForAccount(ap.userName) <= MAX_AMOUNT_OF_CHARACTERS_ALLOWED)
            {
                if (db.EnsuredThatCharacterSlotIsUniqueValue(cp.selectedSlot, ap.userName))
                {
                    return(true);
                }
                else
                {
                    Console.WriteLine("Somone is trying to hack character slots. Username was {0}", ap.userName);
                    return(false);
                }
            }
            return(false);
        }
Example #4
0
        /// <summary>
        /// Adds a new character to the database
        /// </summary>
        /// <param name="accountName"></param>
        /// <param name="cp"></param>
        public void AddCharacterToDb(string accountName, CharacterCreatePacket cp)
        {
            conn.Open();
            MySqlCommand command = conn.CreateCommand();

            command.CommandText = "INSERT INTO `characters`(`characterSlot`, `accountId`, `name`)" +
                                  "SELECT @selectedSlot, account.id, @characterName FROM account WHERE username = @user; " +
                                  "INSERT INTO `character_info`(`charId`, `strength`, `agility`, `intellect`, `vitality`, `dexterity`)" +
                                  "SELECT characters.id, @str,@agi,@int,@vit,@dex FROM characters WHERE characters.name = @characterName;";
            command.Parameters.AddWithValue("@user", accountName);
            command.Parameters.AddWithValue("@characterName", cp.characterName);
            command.Parameters.AddWithValue("@selectedSlot", cp.selectedSlot);
            command.Parameters.AddWithValue("@str", cp.str);
            command.Parameters.AddWithValue("@agi", cp.agi);
            command.Parameters.AddWithValue("@int", cp.inte);
            command.Parameters.AddWithValue("@vit", cp.vit);
            command.Parameters.AddWithValue("@dex", cp.dex);

            command.ExecuteNonQuery();
            conn.Close();
        }
Example #5
0
        /// <summary>
        /// Adds a new character to the database
        /// </summary>
        /// <param name="accountName"></param>
        /// <param name="cp"></param>
        /// <returns>Returns an int corresponding to ErrorCodes. If no error found will return -1</returns>
        public int AddCharacterToDb(string accountName, CharacterCreatePacket cp)
        {
            try
            {
                conn.Open();
                MySqlCommand command = conn.CreateCommand();
                command.CommandText = "INSERT INTO  `chars` (`AccountID`,`CharacterSlot`,`Name`,`Strength`,`Agility`,`Intellect`,`Vitality`,`Dexterity`)"
                                      + "SELECT id, @selectedSlot, @characterName, @str,@agi,@int,@vit,@dex FROM account WHERE username = @user";
                command.Parameters.AddWithValue("@user", accountName);
                command.Parameters.AddWithValue("@characterName", cp.characterName);
                command.Parameters.AddWithValue("@selectedSlot", cp.selectedSlot);
                command.Parameters.AddWithValue("@str", cp.str);
                command.Parameters.AddWithValue("@agi", cp.agi);
                command.Parameters.AddWithValue("@int", cp.inte);
                command.Parameters.AddWithValue("@vit", cp.vit);
                command.Parameters.AddWithValue("@dex", cp.dex);

                MySqlDataReader rdr = command.ExecuteReader();
                rdr.Close();
                conn.Close();
                return(-1);
            }
            catch (MySqlException e)
            {
                conn.Close();
                switch (e.Number)
                {
                case (1062):
                    Console.WriteLine("Duplicate character name attempted to be created");
                    return((int)ErrorCodes.DuplicateCharacter);

                default:
                    Console.WriteLine("Got a MySQL error and not sure how to handle it");
                    Console.WriteLine("Error code is " + e.Number);
                    return((int)ErrorCodes.UnknownDatabaseError);
                }
            }
        }