diff options
Diffstat (limited to 'src')
7 files changed, 72 insertions, 14 deletions
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 |