diff options
-rw-r--r-- | sql/base/auth_database.sql | 32 | ||||
-rw-r--r-- | sql/updates/auth/master/2021_10_15_01_auth.sql | 11 | ||||
-rw-r--r-- | src/server/database/Database/Implementation/LoginDatabase.cpp | 4 | ||||
-rw-r--r-- | src/server/database/Database/Implementation/LoginDatabase.h | 2 | ||||
-rw-r--r-- | src/server/game/BattlePets/BattlePetMgr.cpp | 61 | ||||
-rw-r--r-- | src/server/game/BattlePets/BattlePetMgr.h | 2 | ||||
-rw-r--r-- | src/server/game/Handlers/BattlePetHandler.cpp | 8 | ||||
-rw-r--r-- | src/server/game/Server/Packets/BattlePetPackets.cpp | 7 | ||||
-rw-r--r-- | src/server/game/Server/Packets/BattlePetPackets.h | 2 |
9 files changed, 114 insertions, 15 deletions
diff --git a/sql/base/auth_database.sql b/sql/base/auth_database.sql index 5c3f6b59337..5ca1ccfac57 100644 --- a/sql/base/auth_database.sql +++ b/sql/base/auth_database.sql @@ -200,6 +200,35 @@ LOCK TABLES `autobroadcast` WRITE; UNLOCK TABLES; -- +-- Table structure for table `battle_pet_declinedname` +-- + +DROP TABLE IF EXISTS `battle_pet_declinedname`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `battle_pet_declinedname` ( + `guid` bigint NOT NULL, + `genitive` varchar(12) NOT NULL DEFAULT '', + `dative` varchar(12) NOT NULL DEFAULT '', + `accusative` varchar(12) NOT NULL DEFAULT '', + `instrumental` varchar(12) NOT NULL DEFAULT '', + `prepositional` varchar(12) NOT NULL DEFAULT '', + PRIMARY KEY (`guid`), + CONSTRAINT `fk_battle_pet__battle_pet_declinedname` FOREIGN KEY (`guid`) REFERENCES `battle_pets` (`guid`) ON DELETE RESTRICT ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `battle_pet_declinedname` +-- + +LOCK TABLES `battle_pet_declinedname` WRITE; +/*!40000 ALTER TABLE `battle_pet_declinedname` DISABLE KEYS */; +/*!40000 ALTER TABLE `battle_pet_declinedname` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +-- -- Table structure for table `battle_pet_slots` -- @@ -2428,7 +2457,8 @@ INSERT INTO `updates` VALUES ('2021_09_10_00_auth.sql','DE94812ABC7B395C6C3405FB6718A8AF2C9F8FEC','ARCHIVED','2021-09-10 12:18:54',0), ('2021_10_07_00_auth.sql','45F2D92E28382F0CBE1F9B3A97693C0CC69E50BC','ARCHIVED','2021-10-07 10:32:05',0), ('2021_10_13_00_auth.sql','220E63385CACCBCEC36C57717DE369F2FCABCAAF','ARCHIVED','2021-10-13 21:15:05',0), -('2021_10_15_00_auth.sql','C8AA212AB2BB2DB5B3C2C9622A3874475AEFBD7B','ARCHIVED','2021-10-15 10:11:47',0); +('2021_10_15_00_auth.sql','C8AA212AB2BB2DB5B3C2C9622A3874475AEFBD7B','ARCHIVED','2021-10-15 10:11:47',0), +('2021_10_15_01_auth.sql','72A0437F0ADEC59FF9D6839DF845C473F693CA5B','RELEASED','2021-10-16 00:15:25',0); /*!40000 ALTER TABLE `updates` ENABLE KEYS */; UNLOCK TABLES; diff --git a/sql/updates/auth/master/2021_10_15_01_auth.sql b/sql/updates/auth/master/2021_10_15_01_auth.sql new file mode 100644 index 00000000000..53dafc768eb --- /dev/null +++ b/sql/updates/auth/master/2021_10_15_01_auth.sql @@ -0,0 +1,11 @@ +DROP TABLE IF EXISTS `battle_pet_declinedname`; +CREATE TABLE `battle_pet_declinedname` ( + `guid` bigint(20) NOT NULL, + `genitive` varchar(12) NOT NULL DEFAULT '', + `dative` varchar(12) NOT NULL DEFAULT '', + `accusative` varchar(12) NOT NULL DEFAULT '', + `instrumental` varchar(12) NOT NULL DEFAULT '', + `prepositional` varchar(12) NOT NULL DEFAULT '', + PRIMARY KEY (`guid`), + CONSTRAINT fk_battle_pet__battle_pet_declinedname FOREIGN KEY (`guid`) REFERENCES `battle_pets` (`guid`) ON DELETE RESTRICT ON UPDATE RESTRICT +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/src/server/database/Database/Implementation/LoginDatabase.cpp b/src/server/database/Database/Implementation/LoginDatabase.cpp index cee885a67c3..8d3c46af3d2 100644 --- a/src/server/database/Database/Implementation/LoginDatabase.cpp +++ b/src/server/database/Database/Implementation/LoginDatabase.cpp @@ -155,13 +155,15 @@ void LoginDatabaseConnection::DoPrepareStatements() PrepareStatement(LOGIN_REP_ACCOUNT_TOYS, "REPLACE INTO battlenet_account_toys (accountId, itemId, isFavourite, hasFanfare) VALUES (?, ?, ?, ?)", CONNECTION_ASYNC); // Battle Pets - PrepareStatement(LOGIN_SEL_BATTLE_PETS, "SELECT guid, species, breed, level, exp, health, quality, flags, name FROM battle_pets WHERE battlenetAccountId = ?", CONNECTION_ASYNC); + PrepareStatement(LOGIN_SEL_BATTLE_PETS, "SELECT bp.guid, bp.species, bp.breed, bp.level, bp.exp, bp.health, bp.quality, bp.flags, bp.name, dn.genitive, dn.dative, dn.accusative, dn.instrumental, dn.prepositional FROM battle_pets bp LEFT JOIN battle_pet_declinedname dn ON bp.guid = dn.guid WHERE bp.battlenetAccountId = ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_INS_BATTLE_PETS, "INSERT INTO battle_pets (guid, battlenetAccountId, species, breed, level, exp, health, quality, flags, name) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC); PrepareStatement(LOGIN_DEL_BATTLE_PETS, "DELETE FROM battle_pets WHERE battlenetAccountId = ? AND guid = ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_UPD_BATTLE_PETS, "UPDATE battle_pets SET level = ?, exp = ?, health = ?, quality = ?, flags = ?, name = ? WHERE battlenetAccountId = ? AND guid = ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_SEL_BATTLE_PET_SLOTS, "SELECT id, battlePetGuid, locked FROM battle_pet_slots WHERE battlenetAccountId = ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_INS_BATTLE_PET_SLOTS, "INSERT INTO battle_pet_slots (id, battlenetAccountId, battlePetGuid, locked) VALUES (?, ?, ?, ?)", CONNECTION_ASYNC); PrepareStatement(LOGIN_DEL_BATTLE_PET_SLOTS, "DELETE FROM battle_pet_slots WHERE battlenetAccountId = ?", CONNECTION_ASYNC); + PrepareStatement(LOGIN_INS_BATTLE_PET_DECLINED_NAME, "INSERT INTO battle_pet_declinedname (guid, genitive, dative, accusative, instrumental, prepositional) VALUES (?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC); + PrepareStatement(LOGIN_DEL_BATTLE_PET_DECLINED_NAME, "DELETE FROM battle_pet_declinedname WHERE guid = ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_SEL_ACCOUNT_HEIRLOOMS, "SELECT itemId, flags FROM battlenet_account_heirlooms WHERE accountId = ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_REP_ACCOUNT_HEIRLOOMS, "REPLACE INTO battlenet_account_heirlooms (accountId, itemId, flags) VALUES (?, ?, ?)", CONNECTION_ASYNC); diff --git a/src/server/database/Database/Implementation/LoginDatabase.h b/src/server/database/Database/Implementation/LoginDatabase.h index 2373265c5df..4713600e970 100644 --- a/src/server/database/Database/Implementation/LoginDatabase.h +++ b/src/server/database/Database/Implementation/LoginDatabase.h @@ -151,6 +151,8 @@ enum LoginDatabaseStatements : uint32 LOGIN_SEL_BATTLE_PET_SLOTS, LOGIN_INS_BATTLE_PET_SLOTS, LOGIN_DEL_BATTLE_PET_SLOTS, + LOGIN_INS_BATTLE_PET_DECLINED_NAME, + LOGIN_DEL_BATTLE_PET_DECLINED_NAME, LOGIN_SEL_ACCOUNT_HEIRLOOMS, LOGIN_REP_ACCOUNT_HEIRLOOMS, diff --git a/src/server/game/BattlePets/BattlePetMgr.cpp b/src/server/game/BattlePets/BattlePetMgr.cpp index 9a22df4ee08..e660cf336c3 100644 --- a/src/server/game/BattlePets/BattlePetMgr.cpp +++ b/src/server/game/BattlePets/BattlePetMgr.cpp @@ -224,9 +224,17 @@ void BattlePetMgr::LoadFromDB(PreparedQueryResult pets, PreparedQueryResult slot pet.PacketInfo.Flags = fields[7].GetUInt16(); pet.PacketInfo.Name = fields[8].GetString(); pet.PacketInfo.CreatureID = speciesEntry->CreatureID; + + if (!fields[9].IsNull()) + { + pet.DeclinedName.reset(new DeclinedName); + for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i) + pet.DeclinedName->name[i] = fields[9 + i].GetString(); + } + pet.SaveInfo = BATTLE_PET_UNCHANGED; pet.CalculateStats(); - _pets[pet.PacketInfo.Guid.GetCounter()] = pet; + _pets[pet.PacketInfo.Guid.GetCounter()] = std::move(pet); } } while (pets->NextRow()); } @@ -269,6 +277,18 @@ void BattlePetMgr::SaveToDB(LoginDatabaseTransaction& trans) stmt->setUInt16(8, itr->second.PacketInfo.Flags); stmt->setString(9, itr->second.PacketInfo.Name); trans->Append(stmt); + + if (itr->second.DeclinedName) + { + stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_BATTLE_PET_DECLINED_NAME); + stmt->setUInt64(0, itr->first); + + for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; i++) + stmt->setString(i + 1, itr->second.DeclinedName->name[i]); + + trans->Append(stmt); + } + itr->second.SaveInfo = BATTLE_PET_UNCHANGED; ++itr; break; @@ -283,14 +303,35 @@ void BattlePetMgr::SaveToDB(LoginDatabaseTransaction& trans) stmt->setUInt32(6, _owner->GetBattlenetAccountId()); stmt->setUInt64(7, itr->first); trans->Append(stmt); + + stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_BATTLE_PET_DECLINED_NAME); + stmt->setUInt64(0, itr->first); + trans->Append(stmt); + + if (itr->second.DeclinedName) + { + stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_BATTLE_PET_DECLINED_NAME); + stmt->setUInt64(0, itr->first); + + for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; i++) + stmt->setString(i + 1, itr->second.DeclinedName->name[i]); + + trans->Append(stmt); + } + itr->second.SaveInfo = BATTLE_PET_UNCHANGED; ++itr; break; case BATTLE_PET_REMOVED: + stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_BATTLE_PET_DECLINED_NAME); + stmt->setUInt64(0, itr->first); + trans->Append(stmt); + stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_BATTLE_PETS); stmt->setUInt32(0, _owner->GetBattlenetAccountId()); stmt->setUInt64(1, itr->first); trans->Append(stmt); + itr = _pets.erase(itr); break; default: @@ -342,7 +383,7 @@ void BattlePetMgr::AddPet(uint32 species, uint32 creatureId, uint16 breed, Battl pet.PacketInfo.Health = pet.PacketInfo.MaxHealth; pet.SaveInfo = BATTLE_PET_NEW; - _pets[pet.PacketInfo.Guid.GetCounter()] = pet; + _pets[pet.PacketInfo.Guid.GetCounter()] = std::move(pet); std::vector<std::reference_wrapper<BattlePet>> updates; updates.push_back(std::ref(pet)); @@ -377,6 +418,22 @@ void BattlePetMgr::ClearFanfare(ObjectGuid guid) pet->SaveInfo = BATTLE_PET_CHANGED; } +void BattlePetMgr::ModifyName(ObjectGuid guid, std::string const& name, DeclinedName* declinedName) +{ + BattlePet* pet = GetPet(guid); + if (!pet) + return; + + pet->PacketInfo.Name = name; + + pet->DeclinedName.reset(); + if (declinedName) + pet->DeclinedName = std::make_unique<DeclinedName>(*declinedName); + + if (pet->SaveInfo != BATTLE_PET_NEW) + pet->SaveInfo = BATTLE_PET_CHANGED; +} + bool BattlePetMgr::IsPetInSlot(ObjectGuid guid) { for (WorldPackets::BattlePet::BattlePetSlot const& slot : _slots) diff --git a/src/server/game/BattlePets/BattlePetMgr.h b/src/server/game/BattlePets/BattlePetMgr.h index d1da973dc00..275d591b59b 100644 --- a/src/server/game/BattlePets/BattlePetMgr.h +++ b/src/server/game/BattlePets/BattlePetMgr.h @@ -127,6 +127,7 @@ public: void CalculateStats(); WorldPackets::BattlePet::BattlePet PacketInfo; + std::unique_ptr<DeclinedName> DeclinedName; BattlePetSaveInfo SaveInfo = BATTLE_PET_UNCHANGED; }; @@ -144,6 +145,7 @@ public: void AddPet(uint32 species, uint32 creatureId, uint16 breed, BattlePetBreedQuality quality, uint16 level = 1); void RemovePet(ObjectGuid guid); void ClearFanfare(ObjectGuid guid); + void ModifyName(ObjectGuid guid, std::string const& name, DeclinedName* declinedName); bool IsPetInSlot(ObjectGuid guid); uint8 GetPetCount(uint32 species) const; diff --git a/src/server/game/Handlers/BattlePetHandler.cpp b/src/server/game/Handlers/BattlePetHandler.cpp index af088ba000f..9d8583e5cc9 100644 --- a/src/server/game/Handlers/BattlePetHandler.cpp +++ b/src/server/game/Handlers/BattlePetHandler.cpp @@ -34,13 +34,7 @@ void WorldSession::HandleBattlePetSetBattleSlot(WorldPackets::BattlePet::BattleP void WorldSession::HandleBattlePetModifyName(WorldPackets::BattlePet::BattlePetModifyName& battlePetModifyName) { - if (BattlePetMgr::BattlePet* pet = GetBattlePetMgr()->GetPet(battlePetModifyName.PetGuid)) - { - pet->PacketInfo.Name = battlePetModifyName.Name; - - if (pet->SaveInfo != BATTLE_PET_NEW) - pet->SaveInfo = BATTLE_PET_CHANGED; - } + GetBattlePetMgr()->ModifyName(battlePetModifyName.PetGuid, battlePetModifyName.Name, battlePetModifyName.DeclinedName.get_ptr()); } void WorldSession::HandleBattlePetDeletePet(WorldPackets::BattlePet::BattlePetDeletePet& battlePetDeletePet) diff --git a/src/server/game/Server/Packets/BattlePetPackets.cpp b/src/server/game/Server/Packets/BattlePetPackets.cpp index e241e985367..d1a7b9eebbf 100644 --- a/src/server/game/Server/Packets/BattlePetPackets.cpp +++ b/src/server/game/Server/Packets/BattlePetPackets.cpp @@ -116,13 +116,14 @@ void WorldPackets::BattlePet::BattlePetModifyName::Read() if (hasDeclinedNames) { + DeclinedName.emplace(); uint8 declinedNameLengths[MAX_DECLINED_NAME_CASES]; - for (uint8 i = 0; i < 5; ++i) + for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i) declinedNameLengths[i] = _worldPacket.ReadBits(7); - for (uint8 i = 0; i < 5; ++i) - Declined.name[i] = _worldPacket.ReadString(declinedNameLengths[i]); + for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i) + DeclinedName->name[i] = _worldPacket.ReadString(declinedNameLengths[i]); } Name = _worldPacket.ReadString(nameLength); diff --git a/src/server/game/Server/Packets/BattlePetPackets.h b/src/server/game/Server/Packets/BattlePetPackets.h index 9ad402a16fa..3dce500d0cc 100644 --- a/src/server/game/Server/Packets/BattlePetPackets.h +++ b/src/server/game/Server/Packets/BattlePetPackets.h @@ -133,7 +133,7 @@ namespace WorldPackets ObjectGuid PetGuid; std::string Name; - DeclinedName Declined; + Optional<DeclinedName> DeclinedName; }; class BattlePetDeletePet final : public ClientPacket |