From 7052fbf5cc7dea0f9f287ef641e80df87478cb12 Mon Sep 17 00:00:00 2001 From: leak Date: Sun, 18 Dec 2011 20:55:59 +0100 Subject: Core/DBLayer: Convert callback queries to prepared statements --- src/server/shared/Database/Implementation/CharacterDatabase.cpp | 6 ++++++ src/server/shared/Database/Implementation/CharacterDatabase.h | 6 ++++++ 2 files changed, 12 insertions(+) (limited to 'src/server/shared/Database/Implementation') diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.cpp b/src/server/shared/Database/Implementation/CharacterDatabase.cpp index f93c4a70d7c..c0f05d19161 100755 --- a/src/server/shared/Database/Implementation/CharacterDatabase.cpp +++ b/src/server/shared/Database/Implementation/CharacterDatabase.cpp @@ -36,6 +36,10 @@ void CharacterDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(CHAR_GET_GUID_BY_NAME_FILTER, "SELECT guid, name FROM characters WHERE name LIKE CONCAT('%', ?, '%')", CONNECTION_SYNCH) PREPARE_STATEMENT(CHAR_GET_BANINFO_LIST, "SELECT bandate, unbandate, bannedby, banreason FROM character_banned WHERE guid = ? ORDER BY unbandate", CONNECTION_SYNCH) PREPARE_STATEMENT(CHAR_GET_BANNED_NAME, "SELECT characters.name FROM characters, character_banned WHERE character_banned.guid = ? AND character_banned.guid = characters.guid", CONNECTION_SYNCH) + PREPARE_STATEMENT(CHAR_GET_ENUM, "SELECT c.guid, c.name, c.race, c.class, c.gender, c.playerBytes, c.playerBytes2, c.level, c.zone, c.map, c.position_x, c.position_y, c.position_z, gm.guildid, c.playerFlags, c.at_login, cp.entry, cp.modelid, cp.level, c.equipmentCache, cb.guid FROM characters AS c LEFT JOIN character_pet AS cp ON c.guid = cp.owner AND cp.slot = ? LEFT JOIN guild_member AS gm ON c.guid = gm.guid LEFT JOIN character_banned AS cb ON c.guid = cb.guid AND cb.active = 1 WHERE c.account = ? ORDER BY c.guid", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_GET_ENUM_DECLINED_NAME, "SELECT c.guid, c.name, c.race, c.class, c.gender, c.playerBytes, c.playerBytes2, c.level, c.zone, c.map, c.position_x, c.position_y, c.position_z, gm.guildid, c.playerFlags, c.at_login, cp.entry, cp.modelid, cp.level, c.equipmentCache, cb.guid, cd.genitive FROM characters AS c LEFT JOIN character_pet AS cp ON c.guid = cp.owner AND cp.slot = ? LEFT JOIN character_declinedname AS cd ON c.guid = cd.guid LEFT JOIN guild_member AS gm ON c.guid = gm.guid LEFT JOIN character_banned AS cb ON c.guid = cb.guid AND cb.active = 1 WHERE c.account = ? ORDER BY c.guid", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_GET_PET_SLOTS, "SELECT owner, slot FROM character_pet WHERE owner = ? AND slot >= ? AND slot <= ? ORDER BY slot", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_GET_FREE_NAME, "SELECT guid, name FROM characters WHERE guid = ? AND account = ? AND (at_login & ?) = ? AND NOT EXISTS (SELECT NULL FROM characters WHERE name = ?)", CONNECTION_ASYNC); // Start LoginQueryHolder content PREPARE_STATEMENT(CHAR_LOAD_PLAYER, "SELECT guid, account, name, race, class, gender, level, xp, money, playerBytes, playerBytes2, playerFlags, " @@ -111,6 +115,8 @@ void CharacterDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(CHAR_LOAD_PLAYER_NAME_CLASS, "SELECT name, class FROM characters WHERE guid = ?", CONNECTION_SYNCH); PREPARE_STATEMENT(CHAR_LOAD_MATCH_MAKER_RATING, "SELECT matchMakerRating FROM character_arena_stats WHERE guid = ? AND slot = ?", CONNECTION_SYNCH); PREPARE_STATEMENT(CHAR_GET_CHARACTER_COUNT, "SELECT account, COUNT(guid) FROM characters WHERE account = ? GROUP BY account", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPDATE_NAME, "UPDATE characters set name = ?, at_login = at_login & ~ ? WHERE guid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_DEL_DECLINED_NAME, "DELETE FROM character_declinedname WHERE guid = ?", CONNECTION_ASYNC); // Guild handling // 0: uint32, 1: string, 2: uint32, 3: string, 4: string, 5: uint64, 6-10: uint32, 11: uint64 diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.h b/src/server/shared/Database/Implementation/CharacterDatabase.h index f06a17aa924..adaa9d2709c 100755 --- a/src/server/shared/Database/Implementation/CharacterDatabase.h +++ b/src/server/shared/Database/Implementation/CharacterDatabase.h @@ -56,6 +56,10 @@ enum CharacterDatabaseStatements CHAR_GET_GUID_BY_NAME_FILTER, CHAR_GET_BANINFO_LIST, CHAR_GET_BANNED_NAME, + CHAR_GET_ENUM, + CHAR_GET_ENUM_DECLINED_NAME, + CHAR_GET_PET_SLOTS, + CHAR_GET_FREE_NAME, CHAR_LOAD_PLAYER, CHAR_LOAD_PLAYER_GROUP, CHAR_LOAD_PLAYER_BOUNDINSTANCES, @@ -120,6 +124,8 @@ enum CharacterDatabaseStatements CHAR_LOAD_PLAYER_NAME_CLASS, CHAR_LOAD_MATCH_MAKER_RATING, CHAR_GET_CHARACTER_COUNT, + CHAR_UPDATE_NAME, + CHAR_DEL_DECLINED_NAME, CHAR_ADD_GUILD, CHAR_DEL_GUILD, -- cgit v1.2.3 From 4069e45c5d004ae4d4c5948d829dbf268e6ed204 Mon Sep 17 00:00:00 2001 From: Machiavelli Date: Mon, 19 Dec 2011 11:05:56 +0100 Subject: Core/DBLayer: Fix crash caused in 7052fbf --- src/server/shared/Database/Implementation/CharacterDatabase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/server/shared/Database/Implementation') diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.cpp b/src/server/shared/Database/Implementation/CharacterDatabase.cpp index c0f05d19161..248c39018b2 100755 --- a/src/server/shared/Database/Implementation/CharacterDatabase.cpp +++ b/src/server/shared/Database/Implementation/CharacterDatabase.cpp @@ -26,7 +26,7 @@ void CharacterDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(CHAR_ADD_QUEST_POOL_SAVE, "INSERT INTO pool_quest_save (pool_id, quest_id) VALUES (?, ?)", CONNECTION_ASYNC) PREPARE_STATEMENT(CHAR_DEL_NONEXISTENT_GUILD_BANK_ITEM, "DELETE FROM guild_bank_item WHERE guildid = ? AND TabId = ? AND SlotId = ?", CONNECTION_ASYNC) PREPARE_STATEMENT(CHAR_DEL_EXPIRED_BANS, "UPDATE character_banned SET active = 0 WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate <> bandate", CONNECTION_ASYNC) - PREPARE_STATEMENT(CHAR_GET_GUID_BY_NAME, "SELECT guid FROM characters WHERE name = ?", CONNECTION_SYNCH); + PREPARE_STATEMENT(CHAR_GET_GUID_BY_NAME, "SELECT guid FROM characters WHERE name = ?", CONNECTION_SYNCH | CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_GET_CHECK_NAME, "SELECT 1 FROM characters WHERE name = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_GET_SUM_CHARS, "SELECT COUNT(guid) FROM characters WHERE account = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_GET_CHAR_CREATE_INFO, "SELECT level, race, class FROM characters WHERE account = ? LIMIT 0, ?", CONNECTION_ASYNC); -- cgit v1.2.3 From a1683f20dc91851af2b85c5b4f4f82dbc2eb877b Mon Sep 17 00:00:00 2001 From: Machiavelli Date: Mon, 19 Dec 2011 11:17:52 +0100 Subject: Fix SQL file name after pull request, and fix compile on linux. --- sql/updates/world/2011_12_18_04_world_conditions.sql | 7 ------- sql/updates/world/2011_12_19_00_world_conditions.sql | 7 +++++++ src/server/shared/Database/Implementation/CharacterDatabase.cpp | 2 +- src/server/shared/Database/MySQLConnection.h | 1 + 4 files changed, 9 insertions(+), 8 deletions(-) delete mode 100644 sql/updates/world/2011_12_18_04_world_conditions.sql create mode 100644 sql/updates/world/2011_12_19_00_world_conditions.sql (limited to 'src/server/shared/Database/Implementation') diff --git a/sql/updates/world/2011_12_18_04_world_conditions.sql b/sql/updates/world/2011_12_18_04_world_conditions.sql deleted file mode 100644 index a56151a9f8f..00000000000 --- a/sql/updates/world/2011_12_18_04_world_conditions.sql +++ /dev/null @@ -1,7 +0,0 @@ -UPDATE spell_dbc SET EffectImplicitTargetA1 = 22, EffectImplicitTargetB1 = 7 WHERE Id = 58630; - -DELETE FROM conditions WHERE SourceTypeOrReferenceId = 13 AND SourceEntry IN (61863, 68663); -INSERT INTO conditions (SourceTypeOrReferenceId, SourceEntry, ConditionTypeOrReference, ConditionValue1, Comment) VALUES -(13, 61863, 18, 1, 'The Prophet Tharon''ja - Achievement Check'), -(13, 68663, 18, 1, 'The Black Knight - Kill Credit'), -(13, 58630, 18, 1, 'Mal''Ganis - Kill Credit'); diff --git a/sql/updates/world/2011_12_19_00_world_conditions.sql b/sql/updates/world/2011_12_19_00_world_conditions.sql new file mode 100644 index 00000000000..a56151a9f8f --- /dev/null +++ b/sql/updates/world/2011_12_19_00_world_conditions.sql @@ -0,0 +1,7 @@ +UPDATE spell_dbc SET EffectImplicitTargetA1 = 22, EffectImplicitTargetB1 = 7 WHERE Id = 58630; + +DELETE FROM conditions WHERE SourceTypeOrReferenceId = 13 AND SourceEntry IN (61863, 68663); +INSERT INTO conditions (SourceTypeOrReferenceId, SourceEntry, ConditionTypeOrReference, ConditionValue1, Comment) VALUES +(13, 61863, 18, 1, 'The Prophet Tharon''ja - Achievement Check'), +(13, 68663, 18, 1, 'The Black Knight - Kill Credit'), +(13, 58630, 18, 1, 'Mal''Ganis - Kill Credit'); diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.cpp b/src/server/shared/Database/Implementation/CharacterDatabase.cpp index 248c39018b2..b6af9da6e46 100755 --- a/src/server/shared/Database/Implementation/CharacterDatabase.cpp +++ b/src/server/shared/Database/Implementation/CharacterDatabase.cpp @@ -26,7 +26,7 @@ void CharacterDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(CHAR_ADD_QUEST_POOL_SAVE, "INSERT INTO pool_quest_save (pool_id, quest_id) VALUES (?, ?)", CONNECTION_ASYNC) PREPARE_STATEMENT(CHAR_DEL_NONEXISTENT_GUILD_BANK_ITEM, "DELETE FROM guild_bank_item WHERE guildid = ? AND TabId = ? AND SlotId = ?", CONNECTION_ASYNC) PREPARE_STATEMENT(CHAR_DEL_EXPIRED_BANS, "UPDATE character_banned SET active = 0 WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate <> bandate", CONNECTION_ASYNC) - PREPARE_STATEMENT(CHAR_GET_GUID_BY_NAME, "SELECT guid FROM characters WHERE name = ?", CONNECTION_SYNCH | CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_GET_GUID_BY_NAME, "SELECT guid FROM characters WHERE name = ?", CONNECTION_BOTH); PREPARE_STATEMENT(CHAR_GET_CHECK_NAME, "SELECT 1 FROM characters WHERE name = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_GET_SUM_CHARS, "SELECT COUNT(guid) FROM characters WHERE account = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_GET_CHAR_CREATE_INFO, "SELECT level, race, class FROM characters WHERE account = ? LIMIT 0, ?", CONNECTION_ASYNC); diff --git a/src/server/shared/Database/MySQLConnection.h b/src/server/shared/Database/MySQLConnection.h index 03846c47ecd..e444afd6f58 100755 --- a/src/server/shared/Database/MySQLConnection.h +++ b/src/server/shared/Database/MySQLConnection.h @@ -33,6 +33,7 @@ enum ConnectionFlags { CONNECTION_ASYNC = 0x1, CONNECTION_SYNCH = 0x2, + CONNECTION_BOTH = CONNECTION_ASYNC | CONNECTION_SYNCH; }; struct MySQLConnectionInfo -- cgit v1.2.3 From e1afd79b1ee2bceef56c8c768fdd984d5f03967c Mon Sep 17 00:00:00 2001 From: leak Date: Tue, 20 Dec 2011 09:12:19 +0100 Subject: Core/DBLayer: Convert callback queries to prepared statements #2 --- .../game/Server/Protocol/Handlers/MiscHandler.cpp | 25 +++++++++++----------- src/server/game/Server/WorldSession.cpp | 4 ++-- src/server/game/Server/WorldSession.h | 4 ++-- .../Database/Implementation/CharacterDatabase.cpp | 1 + .../Database/Implementation/CharacterDatabase.h | 1 + 5 files changed, 19 insertions(+), 16 deletions(-) (limited to 'src/server/shared/Database/Implementation') diff --git a/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp b/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp index 702c3c29982..aef3bf03bd9 100755 --- a/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp @@ -531,24 +531,23 @@ void WorldSession::HandleAddFriendOpcode(WorldPacket & recv_data) if (!normalizePlayerName(friendName)) return; - CharacterDatabase.EscapeString(friendName); // prevent SQL injection - normal name must not be changed by this call + sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: %s asked to add friend : '%s'", GetPlayer()->GetName(), friendName.c_str()); - sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: %s asked to add friend : '%s'", - GetPlayer()->GetName(), friendName.c_str()); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_GET_GUID_RACE_ACC_BY_NAME); + + stmt->setString(0, friendName); _addFriendCallback.SetParam(friendNote); - _addFriendCallback.SetFutureResult( - CharacterDatabase.AsyncPQuery("SELECT guid, race, account FROM characters WHERE name = '%s'", friendName.c_str()) - ); + _addFriendCallback.SetFutureResult(CharacterDatabase.AsyncQuery(stmt)); } -void WorldSession::HandleAddFriendOpcodeCallBack(QueryResult result, std::string friendNote) +void WorldSession::HandleAddFriendOpcodeCallBack(PreparedQueryResult result, std::string friendNote) { if (!GetPlayer()) return; uint64 friendGuid; - uint32 friendAcctid; + uint32 friendAccountId; uint32 team; FriendsResult friendResult; @@ -557,11 +556,13 @@ void WorldSession::HandleAddFriendOpcodeCallBack(QueryResult result, std::string if (result) { - friendGuid = MAKE_NEW_GUID((*result)[0].GetUInt32(), 0, HIGHGUID_PLAYER); - team = Player::TeamForRace((*result)[1].GetUInt8()); - friendAcctid = (*result)[2].GetUInt32(); + Field* fields = result->Fetch(); + + friendGuid = MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER); + team = Player::TeamForRace(fields[1].GetUInt8()); + friendAccountId = fields[2].GetUInt32(); - if (!AccountMgr::IsPlayerAccount(GetSecurity()) || sWorld->getBoolConfig(CONFIG_ALLOW_GM_FRIEND) || AccountMgr::IsPlayerAccount(AccountMgr::GetSecurity(friendAcctid, realmID))) + if (!AccountMgr::IsPlayerAccount(GetSecurity()) || sWorld->getBoolConfig(CONFIG_ALLOW_GM_FRIEND) || AccountMgr::IsPlayerAccount(AccountMgr::GetSecurity(friendAccountId, realmID))) { if (friendGuid) { diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index 058ef875b0d..54d477abf69 100755 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -1040,8 +1040,8 @@ void WorldSession::ProcessQueryCallbacks() if (_addFriendCallback.IsReady()) { std::string param = _addFriendCallback.GetParam(); - _addFriendCallback.GetResult(result); - HandleAddFriendOpcodeCallBack(result, param); + _addFriendCallback.GetResult(result2); + HandleAddFriendOpcodeCallBack(result2, param); _addFriendCallback.FreeResult(); } diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h index 0763602e9c1..5f36dbc9547 100755 --- a/src/server/game/Server/WorldSession.h +++ b/src/server/game/Server/WorldSession.h @@ -469,7 +469,7 @@ class WorldSession void HandleEmoteOpcode(WorldPacket& recvPacket); void HandleContactListOpcode(WorldPacket& recvPacket); void HandleAddFriendOpcode(WorldPacket& recvPacket); - void HandleAddFriendOpcodeCallBack(QueryResult result, std::string friendNote); + void HandleAddFriendOpcodeCallBack(PreparedQueryResult result, std::string friendNote); void HandleDelFriendOpcode(WorldPacket& recvPacket); void HandleAddIgnoreOpcode(WorldPacket& recvPacket); void HandleAddIgnoreOpcodeCallBack(PreparedQueryResult result); @@ -900,7 +900,7 @@ class WorldSession PreparedQueryResultFuture _addIgnoreCallback; PreparedQueryResultFuture _stablePetCallback; QueryCallback _charRenameCallback; - QueryCallback _addFriendCallback; + QueryCallback _addFriendCallback; QueryCallback _unstablePetCallback; QueryCallback _stableSwapCallback; QueryCallback _sendStabledPetCallback; diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.cpp b/src/server/shared/Database/Implementation/CharacterDatabase.cpp index b6af9da6e46..0cbf4f8f4b4 100755 --- a/src/server/shared/Database/Implementation/CharacterDatabase.cpp +++ b/src/server/shared/Database/Implementation/CharacterDatabase.cpp @@ -40,6 +40,7 @@ void CharacterDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(CHAR_GET_ENUM_DECLINED_NAME, "SELECT c.guid, c.name, c.race, c.class, c.gender, c.playerBytes, c.playerBytes2, c.level, c.zone, c.map, c.position_x, c.position_y, c.position_z, gm.guildid, c.playerFlags, c.at_login, cp.entry, cp.modelid, cp.level, c.equipmentCache, cb.guid, cd.genitive FROM characters AS c LEFT JOIN character_pet AS cp ON c.guid = cp.owner AND cp.slot = ? LEFT JOIN character_declinedname AS cd ON c.guid = cd.guid LEFT JOIN guild_member AS gm ON c.guid = gm.guid LEFT JOIN character_banned AS cb ON c.guid = cb.guid AND cb.active = 1 WHERE c.account = ? ORDER BY c.guid", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_GET_PET_SLOTS, "SELECT owner, slot FROM character_pet WHERE owner = ? AND slot >= ? AND slot <= ? ORDER BY slot", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_GET_FREE_NAME, "SELECT guid, name FROM characters WHERE guid = ? AND account = ? AND (at_login & ?) = ? AND NOT EXISTS (SELECT NULL FROM characters WHERE name = ?)", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_GET_GUID_RACE_ACC_BY_NAME, "SELECT guid, race, account FROM characters WHERE name = ?", CONNECTION_ASYNC); // Start LoginQueryHolder content PREPARE_STATEMENT(CHAR_LOAD_PLAYER, "SELECT guid, account, name, race, class, gender, level, xp, money, playerBytes, playerBytes2, playerFlags, " diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.h b/src/server/shared/Database/Implementation/CharacterDatabase.h index adaa9d2709c..a9464aed34f 100755 --- a/src/server/shared/Database/Implementation/CharacterDatabase.h +++ b/src/server/shared/Database/Implementation/CharacterDatabase.h @@ -60,6 +60,7 @@ enum CharacterDatabaseStatements CHAR_GET_ENUM_DECLINED_NAME, CHAR_GET_PET_SLOTS, CHAR_GET_FREE_NAME, + CHAR_GET_GUID_RACE_ACC_BY_NAME, CHAR_LOAD_PLAYER, CHAR_LOAD_PLAYER_GROUP, CHAR_LOAD_PLAYER_BOUNDINSTANCES, -- cgit v1.2.3 From 08bd2f1a54c1041f9f090462e12492a116650da8 Mon Sep 17 00:00:00 2001 From: leak Date: Sun, 25 Dec 2011 01:27:15 +0100 Subject: Core/DBLayer: Convert callback queries to prepared statements No. 3 --- .../game/Server/Protocol/Handlers/NPCHandler.cpp | 58 +++++++++++++--------- src/server/game/Server/WorldSession.cpp | 30 ++++++----- src/server/game/Server/WorldSession.h | 12 ++--- .../Database/Implementation/CharacterDatabase.cpp | 3 ++ .../Database/Implementation/CharacterDatabase.h | 3 ++ 5 files changed, 60 insertions(+), 46 deletions(-) (limited to 'src/server/shared/Database/Implementation') diff --git a/src/server/game/Server/Protocol/Handlers/NPCHandler.cpp b/src/server/game/Server/Protocol/Handlers/NPCHandler.cpp index 92f4a0380f9..28724d630bd 100755 --- a/src/server/game/Server/Protocol/Handlers/NPCHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/NPCHandler.cpp @@ -519,14 +519,17 @@ void WorldSession::HandleListStabledPetsOpcode(WorldPacket & recv_data) void WorldSession::SendStablePet(uint64 guid) { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_GET_PET_SLOTS_DETAIL); + + stmt->setUInt32(0, _player->GetGUIDLow()); + stmt->setUInt8(1, PET_SAVE_FIRST_STABLE_SLOT); + stmt->setUInt8(2, PET_SAVE_LAST_STABLE_SLOT); + _sendStabledPetCallback.SetParam(guid); - _sendStabledPetCallback.SetFutureResult( - CharacterDatabase.AsyncPQuery("SELECT owner, id, entry, level, name FROM character_pet WHERE owner = '%u' AND slot >= '%u' AND slot <= '%u' ORDER BY slot", - _player->GetGUIDLow(), PET_SAVE_FIRST_STABLE_SLOT, PET_SAVE_LAST_STABLE_SLOT) - ); + _sendStabledPetCallback.SetFutureResult(CharacterDatabase.AsyncQuery(stmt)); } -void WorldSession::SendStablePetCallback(QueryResult result, uint64 guid) +void WorldSession::SendStablePetCallback(PreparedQueryResult result, uint64 guid) { if (!GetPlayer()) return; @@ -679,14 +682,18 @@ void WorldSession::HandleUnstablePet(WorldPacket & recv_data) if (GetPlayer()->HasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_GET_PET_ENTRY); + + stmt->setUInt32(0, _player->GetGUIDLow()); + stmt->setUInt32(1, petnumber); + stmt->setUInt8(2, PET_SAVE_FIRST_STABLE_SLOT); + stmt->setUInt8(3, PET_SAVE_LAST_STABLE_SLOT); + _unstablePetCallback.SetParam(petnumber); - _unstablePetCallback.SetFutureResult( - CharacterDatabase.AsyncPQuery("SELECT entry FROM character_pet WHERE owner = '%u' AND id = '%u' AND slot >='%u' AND slot <= '%u'", - _player->GetGUIDLow(), petnumber, PET_SAVE_FIRST_STABLE_SLOT, PET_SAVE_LAST_STABLE_SLOT) - ); + _unstablePetCallback.SetFutureResult(CharacterDatabase.AsyncQuery(stmt)); } -void WorldSession::HandleUnstablePetCallback(QueryResult result, uint32 petnumber) +void WorldSession::HandleUnstablePetCallback(PreparedQueryResult result, uint32 petnumber) { if (!GetPlayer()) return; @@ -780,9 +787,9 @@ void WorldSession::HandleStableSwapPet(WorldPacket & recv_data) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Recv CMSG_STABLE_SWAP_PET."); uint64 npcGUID; - uint32 pet_number; + uint32 petId; - recv_data >> npcGUID >> pet_number; + recv_data >> npcGUID >> petId; if (!CheckStableMaster(npcGUID)) { @@ -802,15 +809,18 @@ void WorldSession::HandleStableSwapPet(WorldPacket & recv_data) return; } - // find swapped pet slot in stable - _stableSwapCallback.SetParam(pet_number); - _stableSwapCallback.SetFutureResult( - CharacterDatabase.AsyncPQuery("SELECT slot, entry FROM character_pet WHERE owner = '%u' AND id = '%u'", - _player->GetGUIDLow(), pet_number) - ); + // Find swapped pet slot in stable + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_GET_PET_SLOT_BY_ID); + + stmt->setUInt32(0, _player->GetGUIDLow()); + stmt->setUInt32(1, petId); + + _stableSwapCallback.SetParam(petId); + _stableSwapCallback.SetFutureResult(CharacterDatabase.AsyncQuery(stmt)); } -void WorldSession::HandleStableSwapPetCallback(QueryResult result, uint32 petnumber) +void WorldSession::HandleStableSwapPetCallback(PreparedQueryResult result, uint32 petId) { if (!GetPlayer()) return; @@ -823,16 +833,16 @@ void WorldSession::HandleStableSwapPetCallback(QueryResult result, uint32 petnum Field* fields = result->Fetch(); - uint32 slot = fields[0].GetUInt8(); - uint32 creature_id = fields[1].GetUInt32(); + uint32 slot = fields[0].GetUInt8(); + uint32 petEntry = fields[1].GetUInt32(); - if (!creature_id) + if (!petEntry) { SendStableResult(STABLE_ERR_STABLE); return; } - CreatureTemplate const* creatureInfo = sObjectMgr->GetCreatureTemplate(creature_id); + CreatureTemplate const* creatureInfo = sObjectMgr->GetCreatureTemplate(petEntry); if (!creatureInfo || !creatureInfo->isTameable(_player->CanTameExoticPets())) { // if problem in exotic pet @@ -850,7 +860,7 @@ void WorldSession::HandleStableSwapPetCallback(QueryResult result, uint32 petnum // summon unstabled pet Pet* newpet = new Pet(_player); - if (!newpet->LoadPetFromDB(_player, creature_id, petnumber)) + if (!newpet->LoadPetFromDB(_player, petEntry, petId)) { delete newpet; SendStableResult(STABLE_ERR_STABLE); diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index 54d477abf69..35173387839 100755 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -231,7 +231,7 @@ bool WorldSession::Update(uint32 diff, PacketFilter& updater) //! delayed packets that were re-enqueued due to improper timing. To prevent an infinite //! loop caused by re-enqueueing the same packets over and over again, we stop updating this session //! and continue updating others. The re-enqueued packets will be handled in the next Update call for this session. - while (m_Socket && !m_Socket->IsClosed() && + while (m_Socket && !m_Socket->IsClosed() && !_recvQueue.empty() && _recvQueue.peek(true) != firstDelayedPacket && _recvQueue.next(packet, updater)) { @@ -1008,22 +1008,20 @@ void WorldSession::InitializeQueryCallbackParameters() void WorldSession::ProcessQueryCallbacks() { - QueryResult result; - PreparedQueryResult result2; + PreparedQueryResult result; //! HandleCharEnumOpcode if (_charEnumCallback.ready()) { - _charEnumCallback.get(result2); - HandleCharEnum(result2); + _charEnumCallback.get(result); + HandleCharEnum(result); _charEnumCallback.cancel(); } if (_charCreateCallback.IsReady()) { - PreparedQueryResult pResult; - _charCreateCallback.GetResult(pResult); - HandleCharCreateCallback(pResult, _charCreateCallback.GetParam()); + _charCreateCallback.GetResult(result); + HandleCharCreateCallback(result, _charCreateCallback.GetParam()); // Don't call FreeResult() here, the callback handler will do that depending on the events in the callback chain } @@ -1040,8 +1038,8 @@ void WorldSession::ProcessQueryCallbacks() if (_addFriendCallback.IsReady()) { std::string param = _addFriendCallback.GetParam(); - _addFriendCallback.GetResult(result2); - HandleAddFriendOpcodeCallBack(result2, param); + _addFriendCallback.GetResult(result); + HandleAddFriendOpcodeCallBack(result, param); _addFriendCallback.FreeResult(); } @@ -1049,16 +1047,16 @@ void WorldSession::ProcessQueryCallbacks() if (_charRenameCallback.IsReady()) { std::string param = _charRenameCallback.GetParam(); - _charRenameCallback.GetResult(result2); - HandleChangePlayerNameOpcodeCallBack(result2, param); + _charRenameCallback.GetResult(result); + HandleChangePlayerNameOpcodeCallBack(result, param); _charRenameCallback.FreeResult(); } //- HandleCharAddIgnoreOpcode if (_addIgnoreCallback.ready()) { - _addIgnoreCallback.get(result2); - HandleAddIgnoreOpcodeCallBack(result2); + _addIgnoreCallback.get(result); + HandleAddIgnoreOpcodeCallBack(result); _addIgnoreCallback.cancel(); } @@ -1074,8 +1072,8 @@ void WorldSession::ProcessQueryCallbacks() //- HandleStablePet if (_stablePetCallback.ready()) { - _stablePetCallback.get(result2); - HandleStablePetCallback(result2); + _stablePetCallback.get(result); + HandleStablePetCallback(result); _stablePetCallback.cancel(); } diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h index d1f607704b9..45cb5b64e43 100755 --- a/src/server/game/Server/WorldSession.h +++ b/src/server/game/Server/WorldSession.h @@ -301,7 +301,7 @@ class WorldSession // Pet void SendPetNameQuery(uint64 guid, uint32 petnumber); void SendStablePet(uint64 guid); - void SendStablePetCallback(QueryResult result, uint64 guid); + void SendStablePetCallback(PreparedQueryResult result, uint64 guid); void SendStableResult(uint8 guid); bool CheckStableMaster(uint64 guid); @@ -587,11 +587,11 @@ class WorldSession void HandleStablePet(WorldPacket& recvPacket); void HandleStablePetCallback(PreparedQueryResult result); void HandleUnstablePet(WorldPacket& recvPacket); - void HandleUnstablePetCallback(QueryResult result, uint32 petnumber); + void HandleUnstablePetCallback(PreparedQueryResult result, uint32 petnumber); void HandleBuyStableSlot(WorldPacket& recvPacket); void HandleStableRevivePet(WorldPacket& recvPacket); void HandleStableSwapPet(WorldPacket& recvPacket); - void HandleStableSwapPetCallback(QueryResult result, uint32 petnumber); + void HandleStableSwapPetCallback(PreparedQueryResult result, uint32 petId); void HandleDuelAcceptedOpcode(WorldPacket& recvPacket); void HandleDuelCancelledOpcode(WorldPacket& recvPacket); @@ -898,9 +898,9 @@ class WorldSession PreparedQueryResultFuture _stablePetCallback; QueryCallback _charRenameCallback; QueryCallback _addFriendCallback; - QueryCallback _unstablePetCallback; - QueryCallback _stableSwapCallback; - QueryCallback _sendStabledPetCallback; + QueryCallback _unstablePetCallback; + QueryCallback _stableSwapCallback; + QueryCallback _sendStabledPetCallback; QueryCallback _charCreateCallback; QueryResultHolderFuture _charLoginCallback; diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.cpp b/src/server/shared/Database/Implementation/CharacterDatabase.cpp index 0cbf4f8f4b4..2cc850f7f1d 100755 --- a/src/server/shared/Database/Implementation/CharacterDatabase.cpp +++ b/src/server/shared/Database/Implementation/CharacterDatabase.cpp @@ -39,6 +39,9 @@ void CharacterDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(CHAR_GET_ENUM, "SELECT c.guid, c.name, c.race, c.class, c.gender, c.playerBytes, c.playerBytes2, c.level, c.zone, c.map, c.position_x, c.position_y, c.position_z, gm.guildid, c.playerFlags, c.at_login, cp.entry, cp.modelid, cp.level, c.equipmentCache, cb.guid FROM characters AS c LEFT JOIN character_pet AS cp ON c.guid = cp.owner AND cp.slot = ? LEFT JOIN guild_member AS gm ON c.guid = gm.guid LEFT JOIN character_banned AS cb ON c.guid = cb.guid AND cb.active = 1 WHERE c.account = ? ORDER BY c.guid", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_GET_ENUM_DECLINED_NAME, "SELECT c.guid, c.name, c.race, c.class, c.gender, c.playerBytes, c.playerBytes2, c.level, c.zone, c.map, c.position_x, c.position_y, c.position_z, gm.guildid, c.playerFlags, c.at_login, cp.entry, cp.modelid, cp.level, c.equipmentCache, cb.guid, cd.genitive FROM characters AS c LEFT JOIN character_pet AS cp ON c.guid = cp.owner AND cp.slot = ? LEFT JOIN character_declinedname AS cd ON c.guid = cd.guid LEFT JOIN guild_member AS gm ON c.guid = gm.guid LEFT JOIN character_banned AS cb ON c.guid = cb.guid AND cb.active = 1 WHERE c.account = ? ORDER BY c.guid", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_GET_PET_SLOTS, "SELECT owner, slot FROM character_pet WHERE owner = ? AND slot >= ? AND slot <= ? ORDER BY slot", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_GET_PET_SLOTS_DETAIL, "SELECT owner, id, entry, level, name FROM character_pet WHERE owner = ? AND slot >= ? AND slot <= ? ORDER BY slot", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_GET_PET_ENTRY, "SELECT entry FROM character_pet WHERE owner = ? AND id = ? AND slot >= ? AND slot <= ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_GET_PET_SLOT_BY_ID, "SELECT slot, entry FROM character_pet WHERE owner = ? AND id = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_GET_FREE_NAME, "SELECT guid, name FROM characters WHERE guid = ? AND account = ? AND (at_login & ?) = ? AND NOT EXISTS (SELECT NULL FROM characters WHERE name = ?)", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_GET_GUID_RACE_ACC_BY_NAME, "SELECT guid, race, account FROM characters WHERE name = ?", CONNECTION_ASYNC); diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.h b/src/server/shared/Database/Implementation/CharacterDatabase.h index a9464aed34f..9d2fb4204f3 100755 --- a/src/server/shared/Database/Implementation/CharacterDatabase.h +++ b/src/server/shared/Database/Implementation/CharacterDatabase.h @@ -59,6 +59,9 @@ enum CharacterDatabaseStatements CHAR_GET_ENUM, CHAR_GET_ENUM_DECLINED_NAME, CHAR_GET_PET_SLOTS, + CHAR_GET_PET_SLOTS_DETAIL, + CHAR_GET_PET_ENTRY, + CHAR_GET_PET_SLOT_BY_ID, CHAR_GET_FREE_NAME, CHAR_GET_GUID_RACE_ACC_BY_NAME, CHAR_LOAD_PLAYER, -- cgit v1.2.3 From 64a2a29506591f09eeaef86ecf839e49a07e69d3 Mon Sep 17 00:00:00 2001 From: leak Date: Sun, 25 Dec 2011 02:21:46 +0100 Subject: Core/DBLayer: Convert Execute() queries to prepared statements --- src/server/game/Accounts/AccountMgr.cpp | 12 ++++++++++-- src/server/game/Chat/Commands/Level3.cpp | 6 ++++-- src/server/game/World/World.cpp | 5 ++++- src/server/shared/Database/DatabaseWorkerPool.h | 2 +- .../shared/Database/Implementation/CharacterDatabase.cpp | 1 + .../shared/Database/Implementation/CharacterDatabase.h | 1 + src/server/shared/Database/Implementation/LoginDatabase.cpp | 4 ++++ src/server/shared/Database/Implementation/LoginDatabase.h | 4 ++++ 8 files changed, 29 insertions(+), 6 deletions(-) (limited to 'src/server/shared/Database/Implementation') diff --git a/src/server/game/Accounts/AccountMgr.cpp b/src/server/game/Accounts/AccountMgr.cpp index ebe9a9af36b..9ae80ca2919 100755 --- a/src/server/game/Accounts/AccountMgr.cpp +++ b/src/server/game/Accounts/AccountMgr.cpp @@ -37,8 +37,16 @@ AccountOpResult CreateAccount(std::string username, std::string password) if (GetId(username)) return AOR_NAME_ALREDY_EXIST; // username does already exist - LoginDatabase.PExecute("INSERT INTO account(username, sha_pass_hash, joindate) VALUES('%s', '%s', NOW())", username.c_str(), CalculateShaPassHash(username, password).c_str()); - LoginDatabase.Execute("INSERT INTO realmcharacters (realmid, acctid, numchars) SELECT realmlist.id, account.id, 0 FROM realmlist, account LEFT JOIN realmcharacters ON acctid=account.id WHERE acctid IS NULL"); + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_ADD_ACCOUNT); + + stmt->setString(0, username); + stmt->setString(1, CalculateShaPassHash(username, password)); + + LoginDatabase.Execute(stmt); + + stmt = LoginDatabase.GetPreparedStatement(LOGIN_ADD_REALM_CHARS); + + LoginDatabase.Execute(stmt); return AOR_OK; // everything's fine } diff --git a/src/server/game/Chat/Commands/Level3.cpp b/src/server/game/Chat/Commands/Level3.cpp index f4f5892b587..43aa100e4b3 100755 --- a/src/server/game/Chat/Commands/Level3.cpp +++ b/src/server/game/Chat/Commands/Level3.cpp @@ -3280,7 +3280,8 @@ bool ChatHandler::HandleBanListCharacterCommand(const char *args) bool ChatHandler::HandleBanListAccountCommand(const char *args) { - LoginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate<>bandate"); + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_OLD_BANS); + LoginDatabase.Execute(stmt); char* cFilter = strtok((char*)args, " "); std::string filter = cFilter ? cFilter : ""; @@ -3385,7 +3386,8 @@ bool ChatHandler::HandleBanListHelper(QueryResult result) bool ChatHandler::HandleBanListIPCommand(const char *args) { - LoginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate<>bandate"); + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_OLD_IP_BANS); + LoginDatabase.Execute(stmt); char* cFilter = strtok((char*)args, " "); std::string filter = cFilter ? cFilter : ""; diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index a139c50fb3e..9ad847615d1 100755 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -2687,7 +2687,10 @@ void World::InitRandomBGResetTime() void World::ResetDailyQuests() { sLog->outDetail("Daily quests reset for all characters."); - CharacterDatabase.Execute("DELETE FROM character_queststatus_daily"); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_QUEST_STATUS_DAILY); + CharacterDatabase.Execute(stmt); + for (SessionMap::const_iterator itr = m_sessions.begin(); itr != m_sessions.end(); ++itr) if (itr->second->GetPlayer()) itr->second->GetPlayer()->ResetDailyQuestStatus(); diff --git a/src/server/shared/Database/DatabaseWorkerPool.h b/src/server/shared/Database/DatabaseWorkerPool.h index f1d01661210..a128eda3b70 100755 --- a/src/server/shared/Database/DatabaseWorkerPool.h +++ b/src/server/shared/Database/DatabaseWorkerPool.h @@ -92,7 +92,7 @@ class DatabaseWorkerPool ++m_connectionCount[IDX_SYNCH]; } - sLog->outSQLDriver("Databasepool opened succesfuly. %u total connections running.", (m_connectionCount[IDX_SYNCH] + m_connectionCount[IDX_ASYNC])); + sLog->outSQLDriver("Databasepool opened successfully. %u total connections running.", (m_connectionCount[IDX_SYNCH] + m_connectionCount[IDX_ASYNC])); return res; } diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.cpp b/src/server/shared/Database/Implementation/CharacterDatabase.cpp index 2cc850f7f1d..768ebd8a97a 100755 --- a/src/server/shared/Database/Implementation/CharacterDatabase.cpp +++ b/src/server/shared/Database/Implementation/CharacterDatabase.cpp @@ -44,6 +44,7 @@ void CharacterDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(CHAR_GET_PET_SLOT_BY_ID, "SELECT slot, entry FROM character_pet WHERE owner = ? AND id = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_GET_FREE_NAME, "SELECT guid, name FROM characters WHERE guid = ? AND account = ? AND (at_login & ?) = ? AND NOT EXISTS (SELECT NULL FROM characters WHERE name = ?)", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_GET_GUID_RACE_ACC_BY_NAME, "SELECT guid, race, account FROM characters WHERE name = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_DEL_QUEST_STATUS_DAILY, "DELETE FROM character_queststatus_daily", CONNECTION_ASYNC); // Start LoginQueryHolder content PREPARE_STATEMENT(CHAR_LOAD_PLAYER, "SELECT guid, account, name, race, class, gender, level, xp, money, playerBytes, playerBytes2, playerFlags, " diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.h b/src/server/shared/Database/Implementation/CharacterDatabase.h index 9d2fb4204f3..219ee525ae1 100755 --- a/src/server/shared/Database/Implementation/CharacterDatabase.h +++ b/src/server/shared/Database/Implementation/CharacterDatabase.h @@ -64,6 +64,7 @@ enum CharacterDatabaseStatements CHAR_GET_PET_SLOT_BY_ID, CHAR_GET_FREE_NAME, CHAR_GET_GUID_RACE_ACC_BY_NAME, + CHAR_DEL_QUEST_STATUS_DAILY, CHAR_LOAD_PLAYER, CHAR_LOAD_PLAYER_GROUP, CHAR_LOAD_PLAYER_BOUNDINSTANCES, diff --git a/src/server/shared/Database/Implementation/LoginDatabase.cpp b/src/server/shared/Database/Implementation/LoginDatabase.cpp index 13cfe09914d..5e47d5c8495 100755 --- a/src/server/shared/Database/Implementation/LoginDatabase.cpp +++ b/src/server/shared/Database/Implementation/LoginDatabase.cpp @@ -45,4 +45,8 @@ void LoginDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(LOGIN_DEL_REALMCHARACTERS, "DELETE FROM realmcharacters WHERE acctid = ? AND realmid = ?", CONNECTION_ASYNC) PREPARE_STATEMENT(LOGIN_ADD_REALMCHARACTERS, "INSERT INTO realmcharacters (numchars, acctid, realmid) VALUES (?, ?, ?)", CONNECTION_ASYNC) PREPARE_STATEMENT(LOGIN_GET_SUM_REALMCHARS, "SELECT SUM(numchars) FROM realmcharacters WHERE acctid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(LOGIN_ADD_ACCOUNT, "INSERT INTO account(username, sha_pass_hash, joindate) VALUES(?, ?, NOW())", CONNECTION_ASYNC); + PREPARE_STATEMENT(LOGIN_ADD_REALM_CHARS, "INSERT INTO realmcharacters (realmid, acctid, numchars) SELECT realmlist.id, account.id, 0 FROM realmlist, account LEFT JOIN realmcharacters ON acctid=account.id WHERE acctid IS NULL", CONNECTION_ASYNC); + PREPARE_STATEMENT(LOGIN_DEL_OLD_BANS, "DELETE FROM ip_banned WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate<>bandate", CONNECTION_ASYNC); + PREPARE_STATEMENT(LOGIN_DEL_OLD_IP_BANS, "DELETE FROM ip_banned WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate<>bandate", CONNECTION_ASYNC); } diff --git a/src/server/shared/Database/Implementation/LoginDatabase.h b/src/server/shared/Database/Implementation/LoginDatabase.h index b5f927ffe28..b8adfcabbee 100755 --- a/src/server/shared/Database/Implementation/LoginDatabase.h +++ b/src/server/shared/Database/Implementation/LoginDatabase.h @@ -65,6 +65,10 @@ enum LoginDatabaseStatements LOGIN_DEL_REALMCHARACTERS, LOGIN_ADD_REALMCHARACTERS, LOGIN_GET_SUM_REALMCHARS, + LOGIN_ADD_ACCOUNT, + LOGIN_ADD_REALM_CHARS, + LOGIN_DEL_OLD_BANS, + LOGIN_DEL_OLD_IP_BANS, MAX_LOGINDATABASE_STATEMENTS, }; -- cgit v1.2.3 From ef17c05dec23eed3a2dddc3697574155ad061079 Mon Sep 17 00:00:00 2001 From: leak Date: Sun, 25 Dec 2011 18:12:58 +0100 Subject: Core/DBLayer: Convert PExecute() queries to prepared statements No. 1 --- dep/g3dlite/source/Log.cpp | 14 +-- src/server/game/Accounts/AccountMgr.cpp | 19 ++-- src/server/game/Chat/Chat.h | 6 +- src/server/game/Chat/Commands/Level2.cpp | 126 ++++++++++++++------- .../game/Server/Protocol/Handlers/MiscHandler.cpp | 9 +- .../Server/Protocol/Handlers/PetitionsHandler.cpp | 85 +++++++------- .../game/Server/Protocol/Handlers/SpellHandler.cpp | 47 ++++---- src/server/game/Server/WorldSession.cpp | 8 +- src/server/scripts/Commands/cs_account.cpp | 35 ++++-- .../Database/Implementation/CharacterDatabase.cpp | 6 + .../Database/Implementation/CharacterDatabase.h | 6 + .../Database/Implementation/LoginDatabase.cpp | 6 + .../shared/Database/Implementation/LoginDatabase.h | 6 + src/server/shared/Logging/Log.cpp | 14 ++- 14 files changed, 249 insertions(+), 138 deletions(-) (limited to 'src/server/shared/Database/Implementation') diff --git a/dep/g3dlite/source/Log.cpp b/dep/g3dlite/source/Log.cpp index f437351cfbd..d44d88d0242 100644 --- a/dep/g3dlite/source/Log.cpp +++ b/dep/g3dlite/source/Log.cpp @@ -23,23 +23,23 @@ namespace G3D { void logPrintf(const char* fmt, ...) { - va_list arg_list; - va_start(arg_list, fmt); + va_list arg_list; + va_start(arg_list, fmt); Log::common()->vprintf(fmt, arg_list); va_end(arg_list); } void logLazyPrintf(const char* fmt, ...) { - va_list arg_list; - va_start(arg_list, fmt); + va_list arg_list; + va_start(arg_list, fmt); Log::common()->lazyvprintf(fmt, arg_list); va_end(arg_list); } Log* Log::commonLog = NULL; -Log::Log(const std::string& filename, int stripFromStackBottom) : +Log::Log(const std::string& filename, int stripFromStackBottom) : stripFromStackBottom(stripFromStackBottom) { this->filename = filename; @@ -50,7 +50,7 @@ Log::Log(const std::string& filename, int stripFromStackBottom) : std::string drive, base, ext; Array path; parseFilename(filename, drive, path, base, ext); - std::string logName = base + ((ext != "") ? ("." + ext) : ""); + std::string logName = base + ((ext != "") ? ("." + ext) : ""); // Write time is greater than 1ms. This may be a network drive.... try another file. #ifdef G3D_WIN32 @@ -80,7 +80,7 @@ Log::Log(const std::string& filename, int stripFromStackBottom) : Log::~Log() { section("Shutdown"); println("Closing log file"); - + // Make sure we don't leave a dangling pointer if (Log::commonLog == this) { Log::commonLog = NULL; diff --git a/src/server/game/Accounts/AccountMgr.cpp b/src/server/game/Accounts/AccountMgr.cpp index 9ae80ca2919..6c3dd69c0da 100755 --- a/src/server/game/Accounts/AccountMgr.cpp +++ b/src/server/game/Accounts/AccountMgr.cpp @@ -112,11 +112,13 @@ AccountOpResult ChangeUsername(uint32 accountId, std::string newUsername, std::s normalizeString(newUsername); normalizeString(newPassword); - std::string safeNewUsername = newUsername; - LoginDatabase.EscapeString(safeNewUsername); + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPDATE_USERNAME); - LoginDatabase.PExecute("UPDATE account SET v='0', s='0', username='%s', sha_pass_hash='%s' WHERE id='%d'", safeNewUsername.c_str(), - CalculateShaPassHash(newUsername, newPassword).c_str(), accountId); + stmt->setString(0, newUsername); + stmt->setString(1, CalculateShaPassHash(newUsername, newPassword)); + stmt->setUInt32(2, accountId); + + LoginDatabase.Execute(stmt); return AOR_OK; } @@ -134,9 +136,12 @@ AccountOpResult ChangePassword(uint32 accountId, std::string newPassword) normalizeString(username); normalizeString(newPassword); - // also reset s and v to force update at next realmd login - LoginDatabase.PExecute("UPDATE account SET v='0', s='0', sha_pass_hash='%s' WHERE id='%d'", - CalculateShaPassHash(username, newPassword).c_str(), accountId); + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPDATE_PASSWORD); + + stmt->setString(0, CalculateShaPassHash(username, newPassword)); + stmt->setUInt32(1, accountId); + + LoginDatabase.Execute(stmt); return AOR_OK; } diff --git a/src/server/game/Chat/Chat.h b/src/server/game/Chat/Chat.h index 24652fcc6d5..95c244167f6 100755 --- a/src/server/game/Chat/Chat.h +++ b/src/server/game/Chat/Chat.h @@ -154,8 +154,8 @@ class ChatHandler bool HandleCastTargetCommand(const char *args); bool HandleCastDestCommand(const char *args); - bool HandleCharacterCustomizeCommand(const char * args); - bool HandleCharacterChangeFactionCommand(const char * args); + bool HandleCharacterCustomizeCommand(const char* args); + bool HandleCharacterChangeFactionCommand(const char* args); bool HandleCharacterChangeRaceCommand(const char * args); bool HandleCharacterDeletedDeleteCommand(const char* args); bool HandleCharacterDeletedListCommand(const char* args); @@ -163,7 +163,7 @@ class ChatHandler bool HandleCharacterDeletedOldCommand(const char* args); bool HandleCharacterEraseCommand(const char* args); bool HandleCharacterLevelCommand(const char* args); - bool HandleCharacterRenameCommand(const char * args); + bool HandleCharacterRenameCommand(const char* args); bool HandleCharacterReputationCommand(const char* args); bool HandleCharacterTitlesCommand(const char* args); diff --git a/src/server/game/Chat/Commands/Level2.cpp b/src/server/game/Chat/Commands/Level2.cpp index 41bc564759c..5411b1364c0 100755 --- a/src/server/game/Chat/Commands/Level2.cpp +++ b/src/server/game/Chat/Commands/Level2.cpp @@ -63,11 +63,11 @@ bool ChatHandler::HandleMuteCommand(const char* args) if (!extractPlayerTarget(nameStr, &target, &target_guid, &target_name)) return false; - uint32 account_id = target ? target->GetSession()->GetAccountId() : sObjectMgr->GetPlayerAccountIdByGUID(target_guid); + uint32 accountId = target ? target->GetSession()->GetAccountId() : sObjectMgr->GetPlayerAccountIdByGUID(target_guid); // find only player from same account if any if (!target) - if (WorldSession* session = sWorld->FindSession(account_id)) + if (WorldSession* session = sWorld->FindSession(accountId)) target = session->GetPlayer(); uint32 notspeaktime = (uint32) atoi(delayStr); @@ -76,21 +76,30 @@ bool ChatHandler::HandleMuteCommand(const char* args) if (HasLowerSecurity (target, target_guid, true)) return false; + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPDATE_MUTE_TIME); + if (target) { - //! Target is online, mute will be in effect right away. - int64 mutetime = time(NULL) + notspeaktime * MINUTE; - target->GetSession()->m_muteTime = mutetime; - LoginDatabase.PExecute("UPDATE account SET mutetime = " SI64FMTD " WHERE id = '%u'", mutetime, account_id); + // Target is online, mute will be in effect right away. + int64 muteTime = time(NULL) + notspeaktime * MINUTE; + target->GetSession()->m_muteTime = muteTime; + + stmt->setInt64(0, muteTime); + ChatHandler(target).PSendSysMessage(LANG_YOUR_CHAT_DISABLED, notspeaktime, mutereasonstr.c_str()); } else { - //! Target is offline, mute will be in effect starting from the next login. + // Target is offline, mute will be in effect starting from the next login. int32 muteTime = -int32(notspeaktime * MINUTE); - LoginDatabase.PExecute("UPDATE account SET mutetime = %d WHERE id = %u", muteTime, account_id); + + stmt->setInt64(0, muteTime); } + stmt->setUInt32(1, accountId); + + LoginDatabase.Execute(stmt); + std::string nameLink = playerLink(target_name); PSendSysMessage(target ? LANG_YOU_DISABLE_CHAT : LANG_COMMAND_DISABLE_CHAT_DELAYED, nameLink.c_str(), notspeaktime, mutereasonstr.c_str()); @@ -107,11 +116,11 @@ bool ChatHandler::HandleUnmuteCommand(const char* args) if (!extractPlayerTarget((char*)args, &target, &target_guid, &target_name)) return false; - uint32 account_id = target ? target->GetSession()->GetAccountId() : sObjectMgr->GetPlayerAccountIdByGUID(target_guid); + uint32 accountId = target ? target->GetSession()->GetAccountId() : sObjectMgr->GetPlayerAccountIdByGUID(target_guid); // find only player from same account if any if (!target) - if (WorldSession* session = sWorld->FindSession(account_id)) + if (WorldSession* session = sWorld->FindSession(accountId)) target = session->GetPlayer(); // must have strong lesser security level @@ -130,7 +139,12 @@ bool ChatHandler::HandleUnmuteCommand(const char* args) target->GetSession()->m_muteTime = 0; } - LoginDatabase.PExecute("UPDATE account SET mutetime = '0' WHERE id = '%u'", account_id); + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPDATE_MUTE_TIME); + + stmt->setInt64(0, 0); + stmt->setUInt32(1, accountId); + + LoginDatabase.Execute(stmt); if (target) ChatHandler(target).PSendSysMessage(LANG_YOUR_CHAT_ENABLED); @@ -441,9 +455,9 @@ bool ChatHandler::HandlePInfoCommand(const char* args) bool ChatHandler::HandleCharacterRenameCommand(const char* args) { Player* target; - uint64 target_guid; - std::string target_name; - if (!extractPlayerTarget((char*)args, &target, &target_guid, &target_name)) + uint64 targetGuid; + std::string targetName; + if (!extractPlayerTarget((char*)args, &target, &targetGuid, &targetName)) return false; if (target) @@ -458,13 +472,19 @@ bool ChatHandler::HandleCharacterRenameCommand(const char* args) else { // check offline security - if (HasLowerSecurity(NULL, target_guid)) + if (HasLowerSecurity(NULL, targetGuid)) return false; - std::string oldNameLink = playerLink(target_name); + std::string oldNameLink = playerLink(targetName); + + PSendSysMessage(LANG_RENAME_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(targetGuid)); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_AT_LOGIN_FLAG); - PSendSysMessage(LANG_RENAME_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(target_guid)); - CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '1' WHERE guid = '%u'", GUID_LOPART(target_guid)); + stmt->setUInt16(0, uint16(AT_LOGIN_RENAME)); + stmt->setUInt32(1, GUID_LOPART(targetGuid)); + + CharacterDatabase.Execute(stmt); } return true; @@ -474,80 +494,102 @@ bool ChatHandler::HandleCharacterRenameCommand(const char* args) bool ChatHandler::HandleCharacterCustomizeCommand(const char* args) { Player* target; - uint64 target_guid; - std::string target_name; - if (!extractPlayerTarget((char*)args, &target, &target_guid, &target_name)) + uint64 targetGuid; + std::string targetName; + if (!extractPlayerTarget((char*)args, &target, &targetGuid, &targetName)) return false; + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_AT_LOGIN_FLAG); + + stmt->setUInt16(0, uint16(AT_LOGIN_CUSTOMIZE)); + if (target) { PSendSysMessage(LANG_CUSTOMIZE_PLAYER, GetNameLink(target).c_str()); target->SetAtLoginFlag(AT_LOGIN_CUSTOMIZE); - CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '8' WHERE guid = '%u'", target->GetGUIDLow()); + + stmt->setUInt32(1, target->GetGUIDLow()); } else { - std::string oldNameLink = playerLink(target_name); + std::string oldNameLink = playerLink(targetName); - PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(target_guid)); - CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '8' WHERE guid = '%u'", GUID_LOPART(target_guid)); + stmt->setUInt32(1, GUID_LOPART(targetGuid)); + + PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(targetGuid)); } + CharacterDatabase.Execute(stmt); + return true; } -bool ChatHandler::HandleCharacterChangeFactionCommand(const char * args) +bool ChatHandler::HandleCharacterChangeFactionCommand(const char* args) { Player* target; - uint64 target_guid; - std::string target_name; + uint64 targetGuid; + std::string targetName; - if (!extractPlayerTarget((char*)args, &target, &target_guid, &target_name)) + if (!extractPlayerTarget((char*)args, &target, &targetGuid, &targetName)) return false; + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_AT_LOGIN_FLAG); + + stmt->setUInt16(0, uint16(AT_LOGIN_CHANGE_FACTION)); + if (target) { - // TODO : add text into database PSendSysMessage(LANG_CUSTOMIZE_PLAYER, GetNameLink(target).c_str()); target->SetAtLoginFlag(AT_LOGIN_CHANGE_FACTION); - CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '64' WHERE guid = %u", target->GetGUIDLow()); + + stmt->setUInt32(1, target->GetGUIDLow()); } else { - std::string oldNameLink = playerLink(target_name); + std::string oldNameLink = playerLink(targetName); - // TODO : add text into database - PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(target_guid)); - CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '64' WHERE guid = %u", GUID_LOPART(target_guid)); + PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(targetGuid)); + + stmt->setUInt32(1, GUID_LOPART(targetGuid)); } + CharacterDatabase.Execute(stmt); + return true; } bool ChatHandler::HandleCharacterChangeRaceCommand(const char * args) { Player* target; - uint64 target_guid; - std::string target_name; - if (!extractPlayerTarget((char*)args, &target, &target_guid, &target_name)) + uint64 targetGuid; + std::string targetName; + if (!extractPlayerTarget((char*)args, &target, &targetGuid, &targetName)) return false; + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_AT_LOGIN_FLAG); + + stmt->setUInt16(0, uint16(AT_LOGIN_CHANGE_FACTION)); + if (target) { // TODO : add text into database PSendSysMessage(LANG_CUSTOMIZE_PLAYER, GetNameLink(target).c_str()); target->SetAtLoginFlag(AT_LOGIN_CHANGE_RACE); - CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '128' WHERE guid = %u", target->GetGUIDLow()); + + stmt->setUInt32(1, target->GetGUIDLow()); } else { - std::string oldNameLink = playerLink(target_name); + std::string oldNameLink = playerLink(targetName); // TODO : add text into database - PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(target_guid)); - CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '128' WHERE guid = %u", GUID_LOPART(target_guid)); + PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(targetGuid)); + + stmt->setUInt32(1, GUID_LOPART(targetGuid)); } + CharacterDatabase.Execute(stmt); + return true; } diff --git a/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp b/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp index aef3bf03bd9..6b972f94dd5 100755 --- a/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp @@ -709,9 +709,12 @@ void WorldSession::HandleBugOpcode(WorldPacket & recv_data) sLog->outDebug(LOG_FILTER_NETWORKIO, "%s", type.c_str()); sLog->outDebug(LOG_FILTER_NETWORKIO, "%s", content.c_str()); - CharacterDatabase.EscapeString(type); - CharacterDatabase.EscapeString(content); - CharacterDatabase.PExecute ("INSERT INTO bugreport (type, content) VALUES('%s', '%s')", type.c_str(), content.c_str()); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_ADD_BUG_REPORT); + + stmt->setString(0, type); + stmt->setString(1, content); + + CharacterDatabase.Execute(stmt); } void WorldSession::HandleReclaimCorpseOpcode(WorldPacket &recv_data) diff --git a/src/server/game/Server/Protocol/Handlers/PetitionsHandler.cpp b/src/server/game/Server/Protocol/Handlers/PetitionsHandler.cpp index 2e9b88bd3f0..fed84728efd 100755 --- a/src/server/game/Server/Protocol/Handlers/PetitionsHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/PetitionsHandler.cpp @@ -372,18 +372,18 @@ void WorldSession::HandlePetitionRenameOpcode(WorldPacket & recv_data) { sLog->outDebug(LOG_FILTER_NETWORKIO, "Received opcode MSG_PETITION_RENAME"); // ok - uint64 petitionguid; + uint64 petitionGuid; uint32 type; - std::string newname; + std::string newName; - recv_data >> petitionguid; // guid - recv_data >> newname; // new name + recv_data >> petitionGuid; // guid + recv_data >> newName; // new name - Item* item = _player->GetItemByGuid(petitionguid); + Item* item = _player->GetItemByGuid(petitionGuid); if (!item) return; - QueryResult result = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid)); + QueryResult result = CharacterDatabase.PQuery("SELECT type FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionGuid)); if (result) { @@ -392,46 +392,48 @@ void WorldSession::HandlePetitionRenameOpcode(WorldPacket & recv_data) } else { - sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_PETITION_QUERY failed for petition (GUID: %u)", GUID_LOPART(petitionguid)); + sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_PETITION_QUERY failed for petition (GUID: %u)", GUID_LOPART(petitionGuid)); return; } if (type == GUILD_CHARTER_TYPE) { - if (sGuildMgr->GetGuildByName(newname)) + if (sGuildMgr->GetGuildByName(newName)) { - Guild::SendCommandResult(this, GUILD_CREATE_S, ERR_GUILD_NAME_EXISTS_S, newname); + Guild::SendCommandResult(this, GUILD_CREATE_S, ERR_GUILD_NAME_EXISTS_S, newName); return; } - if (sObjectMgr->IsReservedName(newname) || !ObjectMgr::IsValidCharterName(newname)) + if (sObjectMgr->IsReservedName(newName) || !ObjectMgr::IsValidCharterName(newName)) { - Guild::SendCommandResult(this, GUILD_CREATE_S, ERR_GUILD_NAME_INVALID, newname); + Guild::SendCommandResult(this, GUILD_CREATE_S, ERR_GUILD_NAME_INVALID, newName); return; } } else { - if (sArenaTeamMgr->GetArenaTeamByName(newname)) + if (sArenaTeamMgr->GetArenaTeamByName(newName)) { - SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, newname, "", ERR_ARENA_TEAM_NAME_EXISTS_S); + SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, newName, "", ERR_ARENA_TEAM_NAME_EXISTS_S); return; } - if (sObjectMgr->IsReservedName(newname) || !ObjectMgr::IsValidCharterName(newname)) + if (sObjectMgr->IsReservedName(newName) || !ObjectMgr::IsValidCharterName(newName)) { - SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, newname, "", ERR_ARENA_TEAM_NAME_INVALID); + SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, newName, "", ERR_ARENA_TEAM_NAME_INVALID); return; } } - std::string db_newname = newname; - CharacterDatabase.EscapeString(db_newname); - CharacterDatabase.PExecute("UPDATE petition SET name = '%s' WHERE petitionguid = '%u'", - db_newname.c_str(), GUID_LOPART(petitionguid)); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_PETITION_NAME); + + stmt->setString(0, newName); + stmt->setUInt32(1, GUID_LOPART(petitionGuid)); + + CharacterDatabase.Execute(stmt); - sLog->outDebug(LOG_FILTER_NETWORKIO, "Petition (GUID: %u) renamed to '%s'", GUID_LOPART(petitionguid), newname.c_str()); - WorldPacket data(MSG_PETITION_RENAME, (8+newname.size()+1)); - data << uint64(petitionguid); - data << newname; + sLog->outDebug(LOG_FILTER_NETWORKIO, "Petition (GUID: %u) renamed to '%s'", GUID_LOPART(petitionGuid), newName.c_str()); + WorldPacket data(MSG_PETITION_RENAME, (8+newName.size()+1)); + data << uint64(petitionGuid); + data << newName; SendPacket(&data); } @@ -440,34 +442,34 @@ void WorldSession::HandlePetitionSignOpcode(WorldPacket & recv_data) sLog->outDebug(LOG_FILTER_NETWORKIO, "Received opcode CMSG_PETITION_SIGN"); // ok Field* fields; - uint64 petitionguid; + uint64 petitionGuid; uint8 unk; - recv_data >> petitionguid; // petition guid + recv_data >> petitionGuid; // petition guid recv_data >> unk; QueryResult result = CharacterDatabase.PQuery( "SELECT ownerguid, " " (SELECT COUNT(playerguid) FROM petition_sign WHERE petition_sign.petitionguid = '%u') AS signs, " " type " - "FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionguid), GUID_LOPART(petitionguid)); + "FROM petition WHERE petitionguid = '%u'", GUID_LOPART(petitionGuid), GUID_LOPART(petitionGuid)); if (!result) { - sLog->outError("Petition %u is not found for player %u %s", GUID_LOPART(petitionguid), GetPlayer()->GetGUIDLow(), GetPlayer()->GetName()); + sLog->outError("Petition %u is not found for player %u %s", GUID_LOPART(petitionGuid), GetPlayer()->GetGUIDLow(), GetPlayer()->GetName()); return; } fields = result->Fetch(); - uint64 ownerguid = MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER); + uint64 ownerGuid = MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER); uint8 signs = fields[1].GetUInt8(); uint32 type = fields[2].GetUInt32(); - uint32 plguidlo = _player->GetGUIDLow(); - if (GUID_LOPART(ownerguid) == plguidlo) + uint32 playerGuid = _player->GetGUIDLow(); + if (GUID_LOPART(ownerGuid) == playerGuid) return; // not let enemies sign guild charter - if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) && GetPlayer()->GetTeam() != sObjectMgr->GetPlayerTeamByGUID(ownerguid)) + if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) && GetPlayer()->GetTeam() != sObjectMgr->GetPlayerTeamByGUID(ownerGuid)) { if (type != GUILD_CHARTER_TYPE) SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", "", ERR_ARENA_TEAM_NOT_ALLIED); @@ -519,12 +521,12 @@ void WorldSession::HandlePetitionSignOpcode(WorldPacket & recv_data) //client doesn't allow to sign petition two times by one character, but not check sign by another character from same account //not allow sign another player from already sign player account - result = CharacterDatabase.PQuery("SELECT playerguid FROM petition_sign WHERE player_account = '%u' AND petitionguid = '%u'", GetAccountId(), GUID_LOPART(petitionguid)); + result = CharacterDatabase.PQuery("SELECT playerguid FROM petition_sign WHERE player_account = '%u' AND petitionguid = '%u'", GetAccountId(), GUID_LOPART(petitionGuid)); if (result) { WorldPacket data(SMSG_PETITION_SIGN_RESULTS, (8+8+4)); - data << uint64(petitionguid); + data << uint64(petitionGuid); data << uint64(_player->GetGUID()); data << (uint32)PETITION_SIGN_ALREADY_SIGNED; @@ -532,17 +534,24 @@ void WorldSession::HandlePetitionSignOpcode(WorldPacket & recv_data) SendPacket(&data); // update for owner if online - if (Player* owner = ObjectAccessor::FindPlayer(ownerguid)) + if (Player* owner = ObjectAccessor::FindPlayer(ownerGuid)) owner->GetSession()->SendPacket(&data); return; } - CharacterDatabase.PExecute("INSERT INTO petition_sign (ownerguid, petitionguid, playerguid, player_account) VALUES ('%u', '%u', '%u', '%u')", GUID_LOPART(ownerguid), GUID_LOPART(petitionguid), plguidlo, GetAccountId()); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_ADD_PETITION_SIGNATURE); + + stmt->setUInt32(0, GUID_LOPART(ownerGuid)); + stmt->setUInt32(1, GUID_LOPART(petitionGuid)); + stmt->setUInt32(2, playerGuid); + stmt->setUInt32(3, GetAccountId()); + + CharacterDatabase.Execute(stmt); - sLog->outDebug(LOG_FILTER_NETWORKIO, "PETITION SIGN: GUID %u by player: %s (GUID: %u Account: %u)", GUID_LOPART(petitionguid), _player->GetName(), plguidlo, GetAccountId()); + sLog->outDebug(LOG_FILTER_NETWORKIO, "PETITION SIGN: GUID %u by player: %s (GUID: %u Account: %u)", GUID_LOPART(petitionGuid), _player->GetName(), playerGuid, GetAccountId()); WorldPacket data(SMSG_PETITION_SIGN_RESULTS, (8+8+4)); - data << uint64(petitionguid); + data << uint64(petitionGuid); data << uint64(_player->GetGUID()); data << uint32(PETITION_SIGN_OK); @@ -555,7 +564,7 @@ void WorldSession::HandlePetitionSignOpcode(WorldPacket & recv_data) // item->SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1+1, signs); // update for owner if online - if (Player* owner = ObjectAccessor::FindPlayer(ownerguid)) + if (Player* owner = ObjectAccessor::FindPlayer(ownerGuid)) owner->GetSession()->SendPacket(&data); } diff --git a/src/server/game/Server/Protocol/Handlers/SpellHandler.cpp b/src/server/game/Server/Protocol/Handlers/SpellHandler.cpp index 269576a5696..ffe205304e3 100755 --- a/src/server/game/Server/Protocol/Handlers/SpellHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/SpellHandler.cpp @@ -213,26 +213,26 @@ void WorldSession::HandleOpenItemOpcode(WorldPacket& recvPacket) sLog->outDetail("bagIndex: %u, slot: %u", bagIndex, slot); - Item* pItem = pUser->GetItemByPos(bagIndex, slot); - if (!pItem) + Item* item = pUser->GetItemByPos(bagIndex, slot); + if (!item) { pUser->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL); return; } - ItemTemplate const* proto = pItem->GetTemplate(); + ItemTemplate const* proto = item->GetTemplate(); if (!proto) { - pUser->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, pItem, NULL); + pUser->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, item, NULL); return; } // Verify that the bag is an actual bag or wrapped item that can be used "normally" - if (!(proto->Flags & ITEM_PROTO_FLAG_OPENABLE) && !pItem->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_WRAPPED)) + if (!(proto->Flags & ITEM_PROTO_FLAG_OPENABLE) && !item->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_WRAPPED)) { - pUser->SendEquipError(EQUIP_ERR_CANT_DO_RIGHT_NOW, pItem, NULL); + pUser->SendEquipError(EQUIP_ERR_CANT_DO_RIGHT_NOW, item, NULL); sLog->outError("Possible hacking attempt: Player %s [guid: %u] tried to open item [guid: %u, entry: %u] which is not openable!", - pUser->GetName(), pUser->GetGUIDLow(), pItem->GetGUIDLow(), proto->ItemId); + pUser->GetName(), pUser->GetGUIDLow(), item->GetGUIDLow(), proto->ItemId); return; } @@ -244,43 +244,48 @@ void WorldSession::HandleOpenItemOpcode(WorldPacket& recvPacket) if (!lockInfo) { - pUser->SendEquipError(EQUIP_ERR_ITEM_LOCKED, pItem, NULL); - sLog->outError("WORLD::OpenItem: item [guid = %u] has an unknown lockId: %u!", pItem->GetGUIDLow(), lockId); + pUser->SendEquipError(EQUIP_ERR_ITEM_LOCKED, item, NULL); + sLog->outError("WORLD::OpenItem: item [guid = %u] has an unknown lockId: %u!", item->GetGUIDLow(), lockId); return; } // was not unlocked yet - if (pItem->IsLocked()) + if (item->IsLocked()) { - pUser->SendEquipError(EQUIP_ERR_ITEM_LOCKED, pItem, NULL); + pUser->SendEquipError(EQUIP_ERR_ITEM_LOCKED, item, NULL); return; } } - if (pItem->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_WRAPPED))// wrapped? + if (item->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_WRAPPED))// wrapped? { - QueryResult result = CharacterDatabase.PQuery("SELECT entry, flags FROM character_gifts WHERE item_guid = '%u'", pItem->GetGUIDLow()); + QueryResult result = CharacterDatabase.PQuery("SELECT entry, flags FROM character_gifts WHERE item_guid = '%u'", item->GetGUIDLow()); if (result) { Field* fields = result->Fetch(); uint32 entry = fields[0].GetUInt32(); uint32 flags = fields[1].GetUInt32(); - pItem->SetUInt64Value(ITEM_FIELD_GIFTCREATOR, 0); - pItem->SetEntry(entry); - pItem->SetUInt32Value(ITEM_FIELD_FLAGS, flags); - pItem->SetState(ITEM_CHANGED, pUser); + item->SetUInt64Value(ITEM_FIELD_GIFTCREATOR, 0); + item->SetEntry(entry); + item->SetUInt32Value(ITEM_FIELD_FLAGS, flags); + item->SetState(ITEM_CHANGED, pUser); } else { - sLog->outError("Wrapped item %u don't have record in character_gifts table and will deleted", pItem->GetGUIDLow()); - pUser->DestroyItem(pItem->GetBagSlot(), pItem->GetSlot(), true); + sLog->outError("Wrapped item %u don't have record in character_gifts table and will deleted", item->GetGUIDLow()); + pUser->DestroyItem(item->GetBagSlot(), item->GetSlot(), true); return; } - CharacterDatabase.PExecute("DELETE FROM character_gifts WHERE item_guid = '%u'", pItem->GetGUIDLow()); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GIFT); + + stmt->setUInt32(0, item->GetGUIDLow()); + + CharacterDatabase.Execute(stmt); } else - pUser->SendLoot(pItem->GetGUID(), LOOT_CORPSE); + pUser->SendLoot(item->GetGUID(), LOOT_CORPSE); } void WorldSession::HandleGameObjectUseOpcode(WorldPacket & recv_data) diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index 35173387839..3288224e1f2 100755 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -529,7 +529,13 @@ void WorldSession::LogoutPlayer(bool Save) ///- Since each account can only have one online character at any given time, ensure all characters for active account are marked as offline //No SQL injection as AccountId is uint32 - CharacterDatabase.PExecute("UPDATE characters SET online = 0 WHERE account = '%u'", GetAccountId()); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ACCOUNT_ONLINE); + + stmt->setUInt32(0, GetAccountId()); + + CharacterDatabase.Execute(stmt); + sLog->outDebug(LOG_FILTER_NETWORKIO, "SESSION: Sent SMSG_LOGOUT_COMPLETE Message"); } diff --git a/src/server/scripts/Commands/cs_account.cpp b/src/server/scripts/Commands/cs_account.cpp index ae3250ad7b7..bcef7ac9ba9 100644 --- a/src/server/scripts/Commands/cs_account.cpp +++ b/src/server/scripts/Commands/cs_account.cpp @@ -81,8 +81,13 @@ public: return false; } - // No SQL injection - LoginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'", expansion, accountId); + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPDATE_EXPANSION); + + stmt->setUInt8(0, uint8(expansion)); + stmt->setUInt32(1, accountId); + + LoginDatabase.Execute(stmt); + handler->PSendSysMessage(LANG_ACCOUNT_ADDON, expansion); return true; } @@ -242,17 +247,25 @@ public: } std::string param = (char*)args; - if (param == "on") - { - LoginDatabase.PExecute("UPDATE account SET locked = '1' WHERE id = '%d'", handler->GetSession()->GetAccountId()); - handler->PSendSysMessage(LANG_COMMAND_ACCLOCKLOCKED); - return true; - } - if (param == "off") + if (!param.empty()) { - LoginDatabase.PExecute("UPDATE account SET locked = '0' WHERE id = '%d'", handler->GetSession()->GetAccountId()); - handler->PSendSysMessage(LANG_COMMAND_ACCLOCKUNLOCKED); + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPDATE_ACCOUNT_LOCK); + + if (param == "on") + { + stmt->setBool(0, true); // locked + handler->PSendSysMessage(LANG_COMMAND_ACCLOCKLOCKED); + } + else if (param == "off") + { + stmt->setBool(0, false); // unlocked + handler->PSendSysMessage(LANG_COMMAND_ACCLOCKUNLOCKED); + } + + stmt->setUInt32(1, handler->GetSession()->GetAccountId()); + + LoginDatabase.Execute(stmt); return true; } diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.cpp b/src/server/shared/Database/Implementation/CharacterDatabase.cpp index 768ebd8a97a..02ff2dc5fb3 100755 --- a/src/server/shared/Database/Implementation/CharacterDatabase.cpp +++ b/src/server/shared/Database/Implementation/CharacterDatabase.cpp @@ -327,4 +327,10 @@ void CharacterDatabaseConnection::DoPrepareStatements() "arenaPoints=?,totalHonorPoints=?,todayHonorPoints=?,yesterdayHonorPoints=?,totalKills=?,todayKills=?,yesterdayKills=?,chosenTitle=?,knownCurrencies=?," "watchedFaction=?,drunk=?,health=?,power1=?,power2=?,power3=?,power4=?,power5=?,power6=?,power7=?,latency=?,speccount=?,activespec=?,exploredZones=?," "equipmentCache=?,ammoId=?,knownTitles=?,actionBars=?,grantableLevels=?,online=? WHERE guid=?", CONNECTION_ASYNC); + + PREPARE_STATEMENT(CHAR_UPDATE_AT_LOGIN_FLAG, "UPDATE characters SET at_login = at_login | ? WHERE guid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_ADD_BUG_REPORT, "INSERT INTO bugreport (type, content) VALUES(?, ?)", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPD_PETITION_NAME, "UPDATE petition SET name = ? WHERE petitionguid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_ADD_PETITION_SIGNATURE, "INSERT INTO petition_sign (ownerguid, petitionguid, playerguid, player_account) VALUES (?, ?, ?, ?)", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPD_ACCOUNT_ONLINE, "UPDATE characters SET online = 0 WHERE account = ?", CONNECTION_ASYNC); } diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.h b/src/server/shared/Database/Implementation/CharacterDatabase.h index 219ee525ae1..636a8221d85 100755 --- a/src/server/shared/Database/Implementation/CharacterDatabase.h +++ b/src/server/shared/Database/Implementation/CharacterDatabase.h @@ -289,6 +289,12 @@ enum CharacterDatabaseStatements CHAR_ADD_CHARACTER, CHAR_UPD_CHARACTER, + CHAR_UPDATE_AT_LOGIN_FLAG, + CHAR_ADD_BUG_REPORT, + CHAR_UPD_PETITION_NAME, + CHAR_ADD_PETITION_SIGNATURE, + CHAR_UPD_ACCOUNT_ONLINE, + MAX_CHARACTERDATABASE_STATEMENTS, }; diff --git a/src/server/shared/Database/Implementation/LoginDatabase.cpp b/src/server/shared/Database/Implementation/LoginDatabase.cpp index 5e47d5c8495..9a7514ff053 100755 --- a/src/server/shared/Database/Implementation/LoginDatabase.cpp +++ b/src/server/shared/Database/Implementation/LoginDatabase.cpp @@ -49,4 +49,10 @@ void LoginDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(LOGIN_ADD_REALM_CHARS, "INSERT INTO realmcharacters (realmid, acctid, numchars) SELECT realmlist.id, account.id, 0 FROM realmlist, account LEFT JOIN realmcharacters ON acctid=account.id WHERE acctid IS NULL", CONNECTION_ASYNC); PREPARE_STATEMENT(LOGIN_DEL_OLD_BANS, "DELETE FROM ip_banned WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate<>bandate", CONNECTION_ASYNC); PREPARE_STATEMENT(LOGIN_DEL_OLD_IP_BANS, "DELETE FROM ip_banned WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate<>bandate", CONNECTION_ASYNC); + PREPARE_STATEMENT(LOGIN_UPDATE_EXPANSION, "UPDATE account SET expansion = ? WHERE id = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(LOGIN_UPDATE_ACCOUNT_LOCK, "UPDATE account SET locked = ? WHERE id = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(LOGIN_ADD_LOG, "INSERT INTO logs (time, realm, type, string) VALUES (UNIX_TIMESTAMP(), ? , ?, ?)", CONNECTION_ASYNC); + PREPARE_STATEMENT(LOGIN_UPDATE_USERNAME, "UPDATE account SET v = 0, s = 0, username = ?, sha_pass_hash = ? WHERE id = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(LOGIN_UPDATE_PASSWORD, "UPDATE account SET v = 0, s = 0, sha_pass_hash = ? WHERE id = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(LOGIN_UPDATE_MUTE_TIME, "UPDATE account SET mutetime = ? WHERE id = ?", CONNECTION_ASYNC); } diff --git a/src/server/shared/Database/Implementation/LoginDatabase.h b/src/server/shared/Database/Implementation/LoginDatabase.h index b8adfcabbee..96b437372d6 100755 --- a/src/server/shared/Database/Implementation/LoginDatabase.h +++ b/src/server/shared/Database/Implementation/LoginDatabase.h @@ -69,6 +69,12 @@ enum LoginDatabaseStatements LOGIN_ADD_REALM_CHARS, LOGIN_DEL_OLD_BANS, LOGIN_DEL_OLD_IP_BANS, + LOGIN_UPDATE_EXPANSION, + LOGIN_UPDATE_ACCOUNT_LOCK, + LOGIN_ADD_LOG, + LOGIN_UPDATE_USERNAME, + LOGIN_UPDATE_PASSWORD, + LOGIN_UPDATE_MUTE_TIME, MAX_LOGINDATABASE_STATEMENTS, }; diff --git a/src/server/shared/Logging/Log.cpp b/src/server/shared/Logging/Log.cpp index 697e7616c40..11f2fc090b1 100755 --- a/src/server/shared/Logging/Log.cpp +++ b/src/server/shared/Logging/Log.cpp @@ -370,13 +370,17 @@ void Log::outDB(LogTypes type, const char * str) if (!str || type >= MAX_LOG_TYPES) return; - std::string new_str(str); - if (new_str.empty()) + std::string logStr(str); + if (logStr.empty()) return; - LoginDatabase.EscapeString(new_str); - LoginDatabase.PExecute("INSERT INTO logs (time, realm, type, string) " - "VALUES (" UI64FMTD ", %u, %u, '%s');", uint64(time(0)), realm, type, new_str.c_str()); + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_ADD_LOG); + + stmt->setInt32(0, realm); + stmt->setInt32(1, type); + stmt->setString(2, logStr); + + LoginDatabase.Execute(stmt); } void Log::outString(const char * str, ...) -- cgit v1.2.3 From e646dbb3cdae041ae1ead8e5bdd456ce600ee9a5 Mon Sep 17 00:00:00 2001 From: leak Date: Tue, 27 Dec 2011 00:29:17 +0100 Subject: Core/DBLayer: Convert PExecute() queries to prepared statements No. 2 --- src/server/game/Achievements/AchievementMgr.cpp | 26 ++- src/server/game/Addons/AddonMgr.cpp | 9 +- src/server/game/Chat/Chat.h | 6 +- src/server/game/Chat/Commands/Level3.cpp | 66 +++++--- src/server/game/Entities/GameObject/GameObject.cpp | 14 +- src/server/game/Entities/Pet/Pet.cpp | 27 ++-- src/server/game/Entities/Pet/Pet.h | 2 +- src/server/game/Entities/Player/Player.cpp | 157 +++++++++++------- src/server/game/Entities/Player/Player.h | 4 +- src/server/game/Groups/Group.cpp | 180 +++++++++++++++++---- src/server/game/Instances/InstanceSaveMgr.cpp | 21 ++- src/server/game/Server/WorldSocket.cpp | 21 ++- src/server/game/Tickets/TicketMgr.cpp | 5 +- .../Database/Implementation/CharacterDatabase.cpp | 26 +++ .../Database/Implementation/CharacterDatabase.h | 26 +++ .../Database/Implementation/LoginDatabase.cpp | 1 + .../shared/Database/Implementation/LoginDatabase.h | 1 + .../Database/Implementation/WorldDatabase.cpp | 6 +- .../shared/Database/Implementation/WorldDatabase.h | 2 + 19 files changed, 447 insertions(+), 153 deletions(-) (limited to 'src/server/shared/Database/Implementation') diff --git a/src/server/game/Achievements/AchievementMgr.cpp b/src/server/game/Achievements/AchievementMgr.cpp index d22f4b94caa..030837b2649 100755 --- a/src/server/game/Achievements/AchievementMgr.cpp +++ b/src/server/game/Achievements/AchievementMgr.cpp @@ -619,7 +619,13 @@ void AchievementMgr::LoadFromDB(PreparedQueryResult achievementResult, PreparedQ { // we will remove not existed criteria for all characters sLog->outError("Non-existing achievement criteria %u data removed from table `character_achievement_progress`.", id); - CharacterDatabase.PExecute("DELETE FROM character_achievement_progress WHERE criteria = %u", id); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_INVALID_ACHIEV_PROGRESS_CRITERIA); + + stmt->setUInt16(0, uint16(id)); + + CharacterDatabase.Execute(stmt); + continue; } @@ -2375,17 +2381,23 @@ void AchievementGlobalMgr::LoadCompletedAchievements() { Field* fields = result->Fetch(); - uint32 achievement_id = fields[0].GetUInt32(); - const AchievementEntry* achievement = sAchievementStore.LookupEntry(achievement_id); + uint32 achievementId = fields[0].GetUInt32(); + const AchievementEntry* achievement = sAchievementStore.LookupEntry(achievementId); if (!achievement) { - // we will remove not existed achievement for all characters - sLog->outError("Non-existing achievement %u data removed from table `character_achievement`.", achievement_id); - CharacterDatabase.PExecute("DELETE FROM character_achievement WHERE achievement = %u", achievement_id); + // Remove non existent achievements from all characters + sLog->outError("Non-existing achievement %u data removed from table `character_achievement`.", achievementId); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_INVALID_ACHIEVMENT); + + stmt->setUInt16(0, uint16(achievementId)); + + CharacterDatabase.Execute(stmt); + continue; } else if (achievement->flags & (ACHIEVEMENT_FLAG_REALM_FIRST_REACH | ACHIEVEMENT_FLAG_REALM_FIRST_KILL)) - m_allCompletedAchievements.insert(achievement_id); + m_allCompletedAchievements.insert(achievementId); } while (result->NextRow()); sLog->outString(">> Loaded %lu completed achievements in %u ms", (unsigned long)m_allCompletedAchievements.size(), GetMSTimeDiffToNow(oldMSTime)); diff --git a/src/server/game/Addons/AddonMgr.cpp b/src/server/game/Addons/AddonMgr.cpp index 9d5bdd159f7..ff6d16bef4d 100755 --- a/src/server/game/Addons/AddonMgr.cpp +++ b/src/server/game/Addons/AddonMgr.cpp @@ -70,8 +70,13 @@ void LoadFromDB() void SaveAddon(AddonInfo const& addon) { std::string name = addon.Name; - CharacterDatabase.EscapeString(name); - CharacterDatabase.PExecute("INSERT INTO addons (name, crc) VALUES ('%s', %u)", name.c_str(), addon.CRC); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_ADD_ADDON); + + stmt->setString(0, name); + stmt->setUInt32(1, addon.CRC); + + CharacterDatabase.Execute(stmt); m_knownAddons.push_back(SavedAddon(addon.Name, addon.CRC)); } diff --git a/src/server/game/Chat/Chat.h b/src/server/game/Chat/Chat.h index 95c244167f6..d9190265bbb 100755 --- a/src/server/game/Chat/Chat.h +++ b/src/server/game/Chat/Chat.h @@ -215,9 +215,9 @@ class ChatHandler bool HandleResetAllCommand(const char * args); bool HandleResetHonorCommand(const char * args); bool HandleResetLevelCommand(const char * args); - bool HandleResetSpellsCommand(const char * args); + bool HandleResetSpellsCommand(const char* args); bool HandleResetStatsCommand(const char * args); - bool HandleResetTalentsCommand(const char * args); + bool HandleResetTalentsCommand(const char* args); bool HandleSendItemsCommand(const char* args); bool HandleSendMailCommand(const char* args); @@ -355,7 +355,7 @@ class ChatHandler bool HandleBanHelper(BanMode mode, char const* args); bool HandleBanInfoHelper(uint32 accountid, char const* accountname); bool HandleUnBanHelper(BanMode mode, char const* args); - void HandleCharacterLevel(Player* player, uint64 player_guid, uint32 oldlevel, uint32 newlevel); + void HandleCharacterLevel(Player* player, uint64 playerGuid, uint32 oldLevel, uint32 newLevel); void HandleLearnSkillRecipesHelper(Player* player, uint32 skill_id); // Stores informations about a deleted character diff --git a/src/server/game/Chat/Commands/Level3.cpp b/src/server/game/Chat/Commands/Level3.cpp index 43aa100e4b3..9b29483bcb4 100755 --- a/src/server/game/Chat/Commands/Level3.cpp +++ b/src/server/game/Chat/Commands/Level3.cpp @@ -2177,28 +2177,33 @@ bool ChatHandler::HandleHoverCommand(const char *args) return true; } -void ChatHandler::HandleCharacterLevel(Player* player, uint64 player_guid, uint32 oldlevel, uint32 newlevel) +void ChatHandler::HandleCharacterLevel(Player* player, uint64 playerGuid, uint32 oldLevel, uint32 newLevel) { if (player) { - player->GiveLevel(newlevel); + player->GiveLevel(newLevel); player->InitTalentForLevel(); player->SetUInt32Value(PLAYER_XP, 0); if (needReportToTarget(player)) { - if (oldlevel == newlevel) + if (oldLevel == newLevel) ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET, GetNameLink().c_str()); - else if (oldlevel < newlevel) - ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_UP, GetNameLink().c_str(), newlevel); + else if (oldLevel < newLevel) + ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_UP, GetNameLink().c_str(), newLevel); else // if (oldlevel > newlevel) - ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_DOWN, GetNameLink().c_str(), newlevel); + ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_DOWN, GetNameLink().c_str(), newLevel); } } else { - // update level and XP at level, all other will be updated at loading - CharacterDatabase.PExecute("UPDATE characters SET level = '%u', xp = 0 WHERE guid = '%u'", newlevel, GUID_LOPART(player_guid)); + // Update level and reset XP, everything else will be updated at login + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_LEVEL); + + stmt->setUInt8(0, uint8(newLevel)); + stmt->setUInt32(1, GUID_LOPART(playerGuid)); + + CharacterDatabase.Execute(stmt); } } @@ -2562,12 +2567,12 @@ bool ChatHandler::HandleResetStatsCommand(const char * args) return true; } -bool ChatHandler::HandleResetSpellsCommand(const char * args) +bool ChatHandler::HandleResetSpellsCommand(const char* args) { Player* target; - uint64 target_guid; - std::string target_name; - if (!extractPlayerTarget((char*)args, &target, &target_guid, &target_name)) + uint64 targetGuid; + std::string targetName; + if (!extractPlayerTarget((char*)args, &target, &targetGuid, &targetName)) return false; if (target) @@ -2580,19 +2585,25 @@ bool ChatHandler::HandleResetSpellsCommand(const char * args) } else { - CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'", uint32(AT_LOGIN_RESET_SPELLS), GUID_LOPART(target_guid)); - PSendSysMessage(LANG_RESET_SPELLS_OFFLINE, target_name.c_str()); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_AT_LOGIN_FLAG); + + stmt->setUInt16(0, uint16(AT_LOGIN_RESET_SPELLS)); + stmt->setUInt32(1, GUID_LOPART(targetGuid)); + + CharacterDatabase.Execute(stmt); + + PSendSysMessage(LANG_RESET_SPELLS_OFFLINE, targetName.c_str()); } return true; } -bool ChatHandler::HandleResetTalentsCommand(const char * args) +bool ChatHandler::HandleResetTalentsCommand(const char* args) { Player* target; - uint64 target_guid; - std::string target_name; - if (!extractPlayerTarget((char*)args, &target, &target_guid, &target_name)) + uint64 targetGuid; + std::string targetName; + if (!extractPlayerTarget((char*)args, &target, &targetGuid, &targetName)) { // Try reset talents as Hunter Pet Creature* creature = getSelectedCreature(); @@ -2630,11 +2641,16 @@ bool ChatHandler::HandleResetTalentsCommand(const char * args) target->SendTalentsInfoData(true); return true; } - else if (target_guid) + else if (targetGuid) { - uint32 at_flags = AT_LOGIN_NONE | AT_LOGIN_RESET_PET_TALENTS; - CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'", at_flags, GUID_LOPART(target_guid)); - std::string nameLink = playerLink(target_name); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_AT_LOGIN_FLAG); + + stmt->setUInt16(0, uint16(AT_LOGIN_NONE | AT_LOGIN_RESET_PET_TALENTS)); + stmt->setUInt32(1, GUID_LOPART(targetGuid)); + + CharacterDatabase.Execute(stmt); + + std::string nameLink = playerLink(targetName); PSendSysMessage(LANG_RESET_TALENTS_OFFLINE, nameLink.c_str()); return true; } @@ -2675,7 +2691,11 @@ bool ChatHandler::HandleResetAllCommand(const char * args) return false; } - CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'", atLogin, atLogin); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_ALL_AT_LOGIN_FLAGS); + + stmt->setUInt16(0, uint16(atLogin)); + + CharacterDatabase.Execute(stmt); TRINITY_READ_GUARD(HashMapHolder::LockType, *HashMapHolder::GetLock()); HashMapHolder::MapType const& plist = sObjectAccessor->GetPlayers(); diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index 036664a2760..df7aa90982e 100755 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -770,8 +770,18 @@ void GameObject::DeleteFromDB() { sObjectMgr->RemoveGORespawnTime(m_DBTableGuid, GetInstanceId()); sObjectMgr->DeleteGOData(m_DBTableGuid); - WorldDatabase.PExecute("DELETE FROM gameobject WHERE guid = '%u'", m_DBTableGuid); - WorldDatabase.PExecute("DELETE FROM game_event_gameobject WHERE guid = '%u'", m_DBTableGuid); + + PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_GAMEOBJECT); + + stmt->setUInt32(0, m_DBTableGuid); + + WorldDatabase.Execute(stmt); + + stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_EVENT_GAMEOBJECT); + + stmt->setUInt32(0, m_DBTableGuid); + + WorldDatabase.Execute(stmt); } GameObject* GameObject::GetGameObject(WorldObject& object, uint64 guid) diff --git a/src/server/game/Entities/Pet/Pet.cpp b/src/server/game/Entities/Pet/Pet.cpp index 4e33142f5ce..eb590e7b82f 100755 --- a/src/server/game/Entities/Pet/Pet.cpp +++ b/src/server/game/Entities/Pet/Pet.cpp @@ -1247,24 +1247,29 @@ void Pet::_SaveAuras(SQLTransaction& trans) } } -bool Pet::addSpell(uint32 spell_id, ActiveStates active /*= ACT_DECIDE*/, PetSpellState state /*= PETSPELL_NEW*/, PetSpellType type /*= PETSPELL_NORMAL*/) +bool Pet::addSpell(uint32 spellId, ActiveStates active /*= ACT_DECIDE*/, PetSpellState state /*= PETSPELL_NEW*/, PetSpellType type /*= PETSPELL_NORMAL*/) { - SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spell_id); + SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId); if (!spellInfo) { // do pet spell book cleanup if (state == PETSPELL_UNCHANGED) // spell load case { - sLog->outError("Pet::addSpell: Non-existed in SpellStore spell #%u request, deleting for all pets in `pet_spell`.", spell_id); - CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE spell = '%u'", spell_id); + sLog->outError("Pet::addSpell: Non-existed in SpellStore spell #%u request, deleting for all pets in `pet_spell`.", spellId); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_INVALID_PET_SPELL); + + stmt->setUInt32(0, spellId); + + CharacterDatabase.Execute(stmt); } else - sLog->outError("Pet::addSpell: Non-existed in SpellStore spell #%u request.", spell_id); + sLog->outError("Pet::addSpell: Non-existed in SpellStore spell #%u request.", spellId); return false; } - PetSpellMap::iterator itr = m_spells.find(spell_id); + PetSpellMap::iterator itr = m_spells.find(spellId); if (itr != m_spells.end()) { if (itr->second.state == PETSPELL_REMOVED) @@ -1303,7 +1308,7 @@ bool Pet::addSpell(uint32 spell_id, ActiveStates active /*= ACT_DECIDE*/, PetSpe newspell.active = active; // talent: unlearn all other talent ranks (high and low) - if (TalentSpellPos const* talentPos = GetTalentSpellPos(spell_id)) + if (TalentSpellPos const* talentPos = GetTalentSpellPos(spellId)) { if (TalentEntry const* talentInfo = sTalentStore.LookupEntry(talentPos->talent_id)) { @@ -1311,7 +1316,7 @@ bool Pet::addSpell(uint32 spell_id, ActiveStates active /*= ACT_DECIDE*/, PetSpe { // skip learning spell and no rank spell case uint32 rankSpellId = talentInfo->RankID[i]; - if (!rankSpellId || rankSpellId == spell_id) + if (!rankSpellId || rankSpellId == spellId) continue; // skip unknown ranks @@ -1352,17 +1357,17 @@ bool Pet::addSpell(uint32 spell_id, ActiveStates active /*= ACT_DECIDE*/, PetSpe } } - m_spells[spell_id] = newspell; + m_spells[spellId] = newspell; if (spellInfo->IsPassive() && (!spellInfo->CasterAuraState || HasAuraState(AuraStateType(spellInfo->CasterAuraState)))) - CastSpell(this, spell_id, true); + CastSpell(this, spellId, true); else m_charmInfo->AddSpellToActionBar(spellInfo); if (newspell.active == ACT_ENABLED) ToggleAutocast(spellInfo, true); - uint32 talentCost = GetTalentSpellCost(spell_id); + uint32 talentCost = GetTalentSpellCost(spellId); if (talentCost) { int32 free_points = GetMaxTalentPointsForLevel(getLevel()); diff --git a/src/server/game/Entities/Pet/Pet.h b/src/server/game/Entities/Pet/Pet.h index 973e5e99bee..ac86c061b31 100755 --- a/src/server/game/Entities/Pet/Pet.h +++ b/src/server/game/Entities/Pet/Pet.h @@ -192,7 +192,7 @@ class Pet : public Guardian void _LoadSpells(); void _SaveSpells(SQLTransaction& trans); - bool addSpell(uint32 spell_id, ActiveStates active = ACT_DECIDE, PetSpellState state = PETSPELL_NEW, PetSpellType type = PETSPELL_NORMAL); + bool addSpell(uint32 spellId, ActiveStates active = ACT_DECIDE, PetSpellState state = PETSPELL_NEW, PetSpellType type = PETSPELL_NORMAL); bool learnSpell(uint32 spell_id); void learnSpellHighRank(uint32 spellid); void InitLevelupSpellsForLevel(); diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 510813a4e56..235613c11c4 100755 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -3416,19 +3416,24 @@ void Player::AddNewMailDeliverTime(time_t deliver_time) } } -bool Player::AddTalent(uint32 spell_id, uint8 spec, bool learning) +bool Player::AddTalent(uint32 spellId, uint8 spec, bool learning) { - SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spell_id); + SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId); if (!spellInfo) { // do character spell book cleanup (all characters) if (!IsInWorld() && !learning) // spell load case { - sLog->outError("Player::addSpell: Non-existed in SpellStore spell #%u request, deleting for all characters in `character_spell`.", spell_id); - CharacterDatabase.PExecute("DELETE FROM character_talent WHERE spell = '%u'", spell_id); + sLog->outError("Player::addSpell: Non-existed in SpellStore spell #%u request, deleting for all characters in `character_spell`.", spellId); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_INVALID_SPELL); + + stmt->setUInt32(0, spellId); + + CharacterDatabase.Execute(stmt); } else - sLog->outError("Player::addSpell: Non-existed in SpellStore spell #%u request.", spell_id); + sLog->outError("Player::addSpell: Non-existed in SpellStore spell #%u request.", spellId); return false; } @@ -3438,19 +3443,24 @@ bool Player::AddTalent(uint32 spell_id, uint8 spec, bool learning) // do character spell book cleanup (all characters) if (!IsInWorld() && !learning) // spell load case { - sLog->outError("Player::addTalent: Broken spell #%u learning not allowed, deleting for all characters in `character_talent`.", spell_id); - CharacterDatabase.PExecute("DELETE FROM character_talent WHERE spell = '%u'", spell_id); + sLog->outError("Player::addTalent: Broken spell #%u learning not allowed, deleting for all characters in `character_talent`.", spellId); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_INVALID_SPELL); + + stmt->setUInt32(0, spellId); + + CharacterDatabase.Execute(stmt); } else - sLog->outError("Player::addTalent: Broken spell #%u learning not allowed.", spell_id); + sLog->outError("Player::addTalent: Broken spell #%u learning not allowed.", spellId); return false; } - PlayerTalentMap::iterator itr = m_talents[spec]->find(spell_id); + PlayerTalentMap::iterator itr = m_talents[spec]->find(spellId); if (itr != m_talents[spec]->end()) itr->second->state = PLAYERSPELL_UNCHANGED; - else if (TalentSpellPos const* talentPos = GetTalentSpellPos(spell_id)) + else if (TalentSpellPos const* talentPos = GetTalentSpellPos(spellId)) { if (TalentEntry const* talentInfo = sTalentStore.LookupEntry(talentPos->talent_id)) { @@ -3458,7 +3468,7 @@ bool Player::AddTalent(uint32 spell_id, uint8 spec, bool learning) { // skip learning spell and no rank spell case uint32 rankSpellId = talentInfo->RankID[rank]; - if (!rankSpellId || rankSpellId == spell_id) + if (!rankSpellId || rankSpellId == spellId) continue; itr = m_talents[spec]->find(rankSpellId); @@ -3473,25 +3483,30 @@ bool Player::AddTalent(uint32 spell_id, uint8 spec, bool learning) newtalent->state = state; newtalent->spec = spec; - (*m_talents[spec])[spell_id] = newtalent; + (*m_talents[spec])[spellId] = newtalent; return true; } return false; } -bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependent, bool disabled, bool loading /*=false*/) +bool Player::addSpell(uint32 spellId, bool active, bool learning, bool dependent, bool disabled, bool loading /*= false*/) { - SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spell_id); + SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId); if (!spellInfo) { // do character spell book cleanup (all characters) if (!IsInWorld() && !learning) // spell load case { - sLog->outError("Player::addSpell: Non-existed in SpellStore spell #%u request, deleting for all characters in `character_spell`.", spell_id); - CharacterDatabase.PExecute("DELETE FROM character_spell WHERE spell = '%u'", spell_id); + sLog->outError("Player::addSpell: Non-existed in SpellStore spell #%u request, deleting for all characters in `character_spell`.", spellId); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_INVALID_SPELL); + + stmt->setUInt32(0, spellId); + + CharacterDatabase.Execute(stmt); } else - sLog->outError("Player::addSpell: Non-existed in SpellStore spell #%u request.", spell_id); + sLog->outError("Player::addSpell: Non-existed in SpellStore spell #%u request.", spellId); return false; } @@ -3501,11 +3516,16 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen // do character spell book cleanup (all characters) if (!IsInWorld() && !learning) // spell load case { - sLog->outError("Player::addSpell: Broken spell #%u learning not allowed, deleting for all characters in `character_spell`.", spell_id); - CharacterDatabase.PExecute("DELETE FROM character_spell WHERE spell = '%u'", spell_id); + sLog->outError("Player::addSpell: Broken spell #%u learning not allowed, deleting for all characters in `character_spell`.", spellId); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_INVALID_SPELL); + + stmt->setUInt32(0, spellId); + + CharacterDatabase.Execute(stmt); } else - sLog->outError("Player::addSpell: Broken spell #%u learning not allowed.", spell_id); + sLog->outError("Player::addSpell: Broken spell #%u learning not allowed.", spellId); return false; } @@ -3516,18 +3536,18 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen bool disabled_case = false; bool superceded_old = false; - PlayerSpellMap::iterator itr = m_spells.find(spell_id); + PlayerSpellMap::iterator itr = m_spells.find(spellId); // Remove temporary spell if found to prevent conflicts if (itr != m_spells.end() && itr->second->state == PLAYERSPELL_TEMPORARY) - RemoveTemporarySpell(spell_id); + RemoveTemporarySpell(spellId); else if (itr != m_spells.end()) { uint32 next_active_spell_id = 0; // fix activate state for non-stackable low rank (and find next spell for !active case) if (!spellInfo->IsStackableWithRanks() && spellInfo->IsRanked()) { - if (uint32 next = sSpellMgr->GetNextSpellInChain(spell_id)) + if (uint32 next = sSpellMgr->GetNextSpellInChain(spellId)) { if (HasSpell(next)) { @@ -3570,7 +3590,7 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen if (active) { if (spellInfo->IsPassive() && IsNeedCastPassiveSpellAtLearn(spellInfo)) - CastSpell (this, spell_id, true); + CastSpell (this, spellId, true); } else if (IsInWorld()) { @@ -3578,14 +3598,14 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen { // update spell ranks in spellbook and action bar WorldPacket data(SMSG_SUPERCEDED_SPELL, 4 + 4); - data << uint32(spell_id); + data << uint32(spellId); data << uint32(next_active_spell_id); GetSession()->SendPacket(&data); } else { WorldPacket data(SMSG_REMOVED_SPELL, 4); - data << uint32(spell_id); + data << uint32(spellId); GetSession()->SendPacket(&data); } } @@ -3629,7 +3649,7 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen if (!disabled_case) // skip new spell adding if spell already known (disabled spells case) { // talent: unlearn all other talent ranks (high and low) - if (TalentSpellPos const* talentPos = GetTalentSpellPos(spell_id)) + if (TalentSpellPos const* talentPos = GetTalentSpellPos(spellId)) { if (TalentEntry const* talentInfo = sTalentStore.LookupEntry(talentPos->talent_id)) { @@ -3637,7 +3657,7 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen { // skip learning spell and no rank spell case uint32 rankSpellId = talentInfo->RankID[rank]; - if (!rankSpellId || rankSpellId == spell_id) + if (!rankSpellId || rankSpellId == spellId) continue; removeSpell(rankSpellId, false, false); @@ -3645,7 +3665,7 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen } } // non talent spell: learn low ranks (recursive call) - else if (uint32 prev_spell = sSpellMgr->GetPrevSpellInChain(spell_id)) + else if (uint32 prev_spell = sSpellMgr->GetPrevSpellInChain(spellId)) { if (!IsInWorld() || disabled) // at spells loading, no output, but allow save addSpell(prev_spell, active, true, true, disabled); @@ -3678,7 +3698,7 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen { WorldPacket data(SMSG_SUPERCEDED_SPELL, 4 + 4); data << uint32(itr2->first); - data << uint32(spell_id); + data << uint32(spellId); GetSession()->SendPacket(&data); } @@ -3693,7 +3713,7 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen if (IsInWorld()) // not send spell (re-/over-)learn packets at loading { WorldPacket data(SMSG_SUPERCEDED_SPELL, 4 + 4); - data << uint32(spell_id); + data << uint32(spellId); data << uint32(itr2->first); GetSession()->SendPacket(&data); } @@ -3708,31 +3728,31 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen } } - m_spells[spell_id] = newspell; + m_spells[spellId] = newspell; // return false if spell disabled if (newspell->disabled) return false; } - uint32 talentCost = GetTalentSpellCost(spell_id); + uint32 talentCost = GetTalentSpellCost(spellId); // cast talents with SPELL_EFFECT_LEARN_SPELL (other dependent spells will learned later as not auto-learned) // note: all spells with SPELL_EFFECT_LEARN_SPELL isn't passive if (!loading && talentCost > 0 && spellInfo->HasEffect(SPELL_EFFECT_LEARN_SPELL)) { // ignore stance requirement for talent learn spell (stance set for spell only for client spell description show) - CastSpell(this, spell_id, true); + CastSpell(this, spellId, true); } // also cast passive spells (including all talents without SPELL_EFFECT_LEARN_SPELL) with additional checks else if (spellInfo->IsPassive()) { if (IsNeedCastPassiveSpellAtLearn(spellInfo)) - CastSpell(this, spell_id, true); + CastSpell(this, spellId, true); } else if (spellInfo->HasEffect(SPELL_EFFECT_SKILL_STEP)) { - CastSpell(this, spell_id, true); + CastSpell(this, spellId, true); return false; } @@ -3749,9 +3769,9 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen // add dependent skills uint16 maxskill = GetMaxSkillValueForLevel(); - SpellLearnSkillNode const* spellLearnSkill = sSpellMgr->GetSpellLearnSkill(spell_id); + SpellLearnSkillNode const* spellLearnSkill = sSpellMgr->GetSpellLearnSkill(spellId); - SkillLineAbilityMapBounds skill_bounds = sSpellMgr->GetSkillLineAbilityMapBounds(spell_id); + SkillLineAbilityMapBounds skill_bounds = sSpellMgr->GetSkillLineAbilityMapBounds(spellId); if (spellLearnSkill) { @@ -3809,7 +3829,7 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen } // learn dependent spells - SpellLearnSpellMapBounds spell_bounds = sSpellMgr->GetSpellLearnSpellMapBounds(spell_id); + SpellLearnSpellMapBounds spell_bounds = sSpellMgr->GetSpellLearnSpellMapBounds(spellId); for (SpellLearnSpellMap::const_iterator itr2 = spell_bounds.first; itr2 != spell_bounds.second; ++itr2) { @@ -3831,7 +3851,7 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILLLINE_SPELLS, _spell_idx->second->skillId); } - GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LEARN_SPELL, spell_id); + GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LEARN_SPELL, spellId); } // return true (for send learn packet) only if spell active (in case ranked spells) and not replace old spell @@ -4921,8 +4941,14 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC } // The character gets unlinked from the account, the name gets freed up and appears as deleted ingame case CHAR_DELETE_UNLINK: - CharacterDatabase.PExecute("UPDATE characters SET deleteInfos_Name=name, deleteInfos_Account=account, deleteDate='" UI64FMTD "', name='', account=0 WHERE guid=%u", uint64(time(NULL)), guid); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_DELETE_INFO); + + stmt->setUInt32(0, guid); + + CharacterDatabase.Execute(stmt); break; + } default: sLog->outError("Player::DeleteFromDB: Unsupported delete method: %u.", charDelete_method); } @@ -7317,7 +7343,14 @@ uint32 Player::GetZoneIdFromDB(uint64 guid) zone = sMapMgr->GetZoneId(map, posx, posy, posz); if (zone > 0) - CharacterDatabase.PExecute("UPDATE characters SET zone='%u' WHERE guid='%u'", zone, guidLow); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_ZONE); + + stmt->setUInt16(0, uint16(zone)); + stmt->setUInt32(1, guidLow); + + CharacterDatabase.Execute(stmt); + } } return zone; @@ -12348,7 +12381,13 @@ void Player::DestroyItem(uint8 bag, uint8 slot, bool update) DestroyItem(slot, i, update); if (pItem->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_WRAPPED)) - CharacterDatabase.PExecute("DELETE FROM character_gifts WHERE item_guid = '%u'", pItem->GetGUIDLow()); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GIFT); + + stmt->setUInt32(0, pItem->GetGUIDLow()); + + CharacterDatabase.Execute(stmt); + } RemoveEnchantmentDurations(pItem); RemoveItemDurations(pItem); @@ -16466,7 +16505,13 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) if (ObjectMgr::CheckPlayerName(m_name) != CHAR_NAME_SUCCESS || (AccountMgr::IsPlayerAccount(GetSession()->GetSecurity()) && sObjectMgr->IsReservedName(m_name))) { - CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid ='%u'", uint32(AT_LOGIN_RENAME), guid); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_AT_LOGIN_FLAG); + + stmt->setUInt16(0, uint16(AT_LOGIN_RENAME)); + stmt->setUInt32(1, guid); + + CharacterDatabase.Execute(stmt); + return false; } @@ -17487,29 +17532,33 @@ void Player::_LoadMailedItems(Mail* mail) { Field* fields = result->Fetch(); - uint32 item_guid_low = fields[11].GetUInt32(); - uint32 item_template = fields[12].GetUInt32(); + uint32 itemGuid = fields[11].GetUInt32(); + uint32 itemTemplate = fields[12].GetUInt32(); - mail->AddItem(item_guid_low, item_template); + mail->AddItem(itemGuid, itemTemplate); - ItemTemplate const* proto = sObjectMgr->GetItemTemplate(item_template); + ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemTemplate); if (!proto) { - sLog->outError("Player %u has unknown item_template (ProtoType) in mailed items(GUID: %u template: %u) in mail (%u), deleted.", GetGUIDLow(), item_guid_low, item_template, mail->messageID); - CharacterDatabase.PExecute("DELETE FROM mail_items WHERE item_guid = '%u'", item_guid_low); + sLog->outError("Player %u has unknown item_template (ProtoType) in mailed items(GUID: %u template: %u) in mail (%u), deleted.", GetGUIDLow(), itemGuid, itemTemplate, mail->messageID); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_INVALID_MAIL_ITEM); + stmt->setUInt32(0, itemGuid); + CharacterDatabase.Execute(stmt); + stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEM_INSTANCE); - stmt->setUInt32(0, item_guid_low); + stmt->setUInt32(0, itemGuid); CharacterDatabase.Execute(stmt); continue; } Item* item = NewItemOrBag(proto); - if (!item->LoadFromDB(item_guid_low, MAKE_NEW_GUID(fields[13].GetUInt32(), 0, HIGHGUID_PLAYER), fields, item_template)) + if (!item->LoadFromDB(itemGuid, MAKE_NEW_GUID(fields[13].GetUInt32(), 0, HIGHGUID_PLAYER), fields, itemTemplate)) { - sLog->outError("Player::_LoadMailedItems - Item in mail (%u) doesn't exist !!!! - item guid: %u, deleted from mail", mail->messageID, item_guid_low); - CharacterDatabase.PExecute("DELETE FROM mail_items WHERE item_guid = '%u'", item_guid_low); + sLog->outError("Player::_LoadMailedItems - Item in mail (%u) doesn't exist !!!! - item guid: %u, deleted from mail", mail->messageID, itemGuid); + CharacterDatabase.PExecute("DELETE FROM mail_items WHERE item_guid = '%u'", itemGuid); item->FSetState(ITEM_REMOVED); SQLTransaction temp = SQLTransaction(NULL); diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index 8ee7d1a417f..a9bba9cbdc4 100755 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -1650,7 +1650,7 @@ class Player : public Unit, public GridObject void SendProficiency(ItemClass itemClass, uint32 itemSubclassMask); void SendInitialSpells(); - bool addSpell(uint32 spell_id, bool active, bool learning, bool dependent, bool disabled, bool loading = false); + bool addSpell(uint32 spellId, bool active, bool learning, bool dependent, bool disabled, bool loading = false); void learnSpell(uint32 spell_id, bool dependent); void removeSpell(uint32 spell_id, bool disabled = false, bool learn_low_rank = true); void resetSpells(bool myClassOnly = false); @@ -1674,7 +1674,7 @@ class Player : public Unit, public GridObject void LearnTalent(uint32 talentId, uint32 talentRank); void LearnPetTalent(uint64 petGuid, uint32 talentId, uint32 talentRank); - bool AddTalent(uint32 spell, uint8 spec, bool learning); + bool AddTalent(uint32 spellId, uint8 spec, bool learning); bool HasTalent(uint32 spell_id, uint8 spec) const; uint32 CalculateTalentsPoints() const; diff --git a/src/server/game/Groups/Group.cpp b/src/server/game/Groups/Group.cpp index 11175b13114..ffb5e0ca1aa 100755 --- a/src/server/game/Groups/Group.cpp +++ b/src/server/game/Groups/Group.cpp @@ -123,12 +123,30 @@ bool Group::Create(Player* leader) sGroupMgr->RegisterGroupDbStoreId(m_dbStoreId, this); - // store group in database - CharacterDatabase.PExecute("INSERT INTO groups (guid, leaderGuid, lootMethod, looterGuid, lootThreshold, icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8, groupType, difficulty, raiddifficulty) " - "VALUES ('%u', '%u', '%u', '%u', '%u', '" UI64FMTD "', '" UI64FMTD "', '" UI64FMTD "', '" UI64FMTD "', '" UI64FMTD "', '" UI64FMTD "', '" UI64FMTD "', '" UI64FMTD "', '%u', '%u', '%u')", - m_dbStoreId, GUID_LOPART(m_leaderGuid), uint32(m_lootMethod), - GUID_LOPART(m_looterGuid), uint32(m_lootThreshold), m_targetIcons[0], m_targetIcons[1], m_targetIcons[2], m_targetIcons[3], m_targetIcons[4], m_targetIcons[5], m_targetIcons[6], - m_targetIcons[7], uint8(m_groupType), uint32(m_dungeonDifficulty), m_raidDifficulty); + // Store group in database + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_ADD_GROUP); + + uint8 index = 0; + + stmt->setUInt32(index++, m_dbStoreId); + stmt->setUInt32(index++, GUID_LOPART(m_leaderGuid)); + stmt->setUInt8(index++, uint8(m_lootMethod)); + stmt->setUInt32(index++, GUID_LOPART(m_looterGuid)); + stmt->setUInt8(index++, uint8(m_lootThreshold)); + stmt->setUInt32(index++, uint32(m_targetIcons[0])); + stmt->setUInt32(index++, uint32(m_targetIcons[1])); + stmt->setUInt32(index++, uint32(m_targetIcons[2])); + stmt->setUInt32(index++, uint32(m_targetIcons[3])); + stmt->setUInt32(index++, uint32(m_targetIcons[4])); + stmt->setUInt32(index++, uint32(m_targetIcons[5])); + stmt->setUInt32(index++, uint32(m_targetIcons[6])); + stmt->setUInt32(index++, uint32(m_targetIcons[7])); + stmt->setUInt8(index++, uint8(m_groupType)); + stmt->setUInt32(index++, uint8(m_dungeonDifficulty)); + stmt->setUInt32(index++, uint8(m_raidDifficulty)); + + CharacterDatabase.Execute(stmt); + ASSERT(AddMember(leader)); // If the leader can't be added to a new group because it appears full, something is clearly wrong. @@ -200,7 +218,15 @@ void Group::ConvertToLFG() m_groupType = GroupType(m_groupType | GROUPTYPE_LFG | GROUPTYPE_UNK1); m_lootMethod = NEED_BEFORE_GREED; if (!isBGGroup()) - CharacterDatabase.PExecute("UPDATE groups SET groupType='%u' WHERE guid='%u'", uint8(m_groupType), m_dbStoreId); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_GROUP_TYPE); + + stmt->setUInt8(0, uint8(m_groupType)); + stmt->setUInt32(1, m_dbStoreId); + + CharacterDatabase.Execute(stmt); + } + SendUpdate(); } @@ -211,7 +237,15 @@ void Group::ConvertToRaid() _initRaidSubGroupsCounter(); if (!isBGGroup()) - CharacterDatabase.PExecute("UPDATE groups SET groupType='%u' WHERE guid='%u'", uint8(m_groupType), m_dbStoreId); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_GROUP_TYPE); + + stmt->setUInt8(0, uint8(m_groupType)); + stmt->setUInt32(1, m_dbStoreId); + + CharacterDatabase.Execute(stmt); + } + SendUpdate(); // update quest related GO states (quest activity dependent from raid membership) @@ -343,8 +377,18 @@ bool Group::AddMember(Player* player) // insert into the table if we're not a battleground group if (!isBGGroup()) - CharacterDatabase.PExecute("INSERT INTO group_member (guid, memberGuid, memberFlags, subgroup, roles) VALUES(%u, %u, %u, %u, %u)", - m_dbStoreId, GUID_LOPART(member.guid), member.flags, member.group, member.roles); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_ADD_GROUP_MEMBER); + + stmt->setUInt32(0, m_dbStoreId); + stmt->setUInt32(1, GUID_LOPART(member.guid)); + stmt->setUInt8(2, member.flags); + stmt->setUInt8(3, member.group); + stmt->setUInt8(4, member.roles); + + CharacterDatabase.Execute(stmt); + + } SendUpdate(); sScriptMgr->OnGroupAddMember(this, player->GetGUID()); @@ -435,7 +479,11 @@ bool Group::RemoveMember(uint64 guid, const RemoveMethod &method /*= GROUP_REMOV } // Remove player from group in DB - CharacterDatabase.PExecute("DELETE FROM group_member WHERE memberGuid=%u", GUID_LOPART(guid)); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GROUP_MEMBER); + + stmt->setUInt32(0, GUID_LOPART(guid)); + + CharacterDatabase.Execute(stmt); // Reevaluate group enchanter if the leaving player had enchanting skill or the player is offline if ((player && player->GetSkillValue(SKILL_ENCHANTING)) || !player) @@ -530,14 +578,24 @@ void Group::ChangeLeader(uint64 guid) } // Same in the database - CharacterDatabase.PExecute("DELETE FROM group_instance WHERE guid=%u AND (permanent = 1 OR instance IN (SELECT instance FROM character_instance WHERE guid = '%u'))", - m_dbStoreId, player->GetGUIDLow()); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GROUP_INSTANCE_PERM_BINDING); + + stmt->setUInt32(0, m_dbStoreId); + stmt->setUInt32(1, player->GetGUIDLow()); + + CharacterDatabase.Execute(stmt); // Copy the permanent binds from the new leader to the group Player::ConvertInstancesToGroup(player, this, true); - // update the group leader - CharacterDatabase.PExecute("UPDATE groups SET leaderGuid='%u' WHERE guid='%u'", player->GetGUIDLow(), m_dbStoreId); + // Update the group leader + stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_GROUP_LEADER); + + stmt->setUInt32(0, player->GetGUIDLow()); + stmt->setUInt32(1, m_dbStoreId); + + CharacterDatabase.Execute(stmt); } m_leaderGuid = player->GetGUID(); @@ -1321,7 +1379,14 @@ bool Group::_setMembersGroup(uint64 guid, uint8 group) SubGroupCounterIncrease(group); if (!isBGGroup()) - CharacterDatabase.PExecute("UPDATE group_member SET subgroup='%u' WHERE memberGuid='%u'", group, GUID_LOPART(guid)); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_GROUP_MEMBER_SUBGROUP); + + stmt->setUInt8(0, group); + stmt->setUInt32(1, GUID_LOPART(guid)); + + CharacterDatabase.Execute(stmt); + } return true; } @@ -1365,7 +1430,14 @@ void Group::ChangeMembersGroup(uint64 guid, uint8 group) // Preserve new sub group in database for non-raid groups if (!isBGGroup()) - CharacterDatabase.PExecute("UPDATE group_member SET subgroup='%u' WHERE memberGuid='%u'", group, GUID_LOPART(guid)); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_GROUP_MEMBER_SUBGROUP); + + stmt->setUInt8(0, group); + stmt->setUInt32(1, GUID_LOPART(guid)); + + CharacterDatabase.Execute(stmt); + } // In case the moved player is online, update the player object with the new sub group references if (Player* player = ObjectAccessor::FindPlayer(guid)) @@ -1553,7 +1625,14 @@ void Group::SetDungeonDifficulty(Difficulty difficulty) { m_dungeonDifficulty = difficulty; if (!isBGGroup()) - CharacterDatabase.PExecute("UPDATE groups SET difficulty = %u WHERE guid ='%u'", m_dungeonDifficulty, m_dbStoreId); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_GROUP_DIFFICULTY); + + stmt->setUInt8(0, uint8(m_dungeonDifficulty)); + stmt->setUInt32(1, m_dbStoreId); + + CharacterDatabase.Execute(stmt); + } for (GroupReference* itr = GetFirstMember(); itr != NULL; itr = itr->next()) { @@ -1570,7 +1649,14 @@ void Group::SetRaidDifficulty(Difficulty difficulty) { m_raidDifficulty = difficulty; if (!isBGGroup()) - CharacterDatabase.PExecute("UPDATE groups SET raiddifficulty = %u WHERE guid ='%u'", m_raidDifficulty, m_dbStoreId); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_GROUP_RAID_DIFFICULTY); + + stmt->setUInt8(0, uint8(m_raidDifficulty)); + stmt->setUInt32(1, m_dbStoreId); + + CharacterDatabase.Execute(stmt); + } for (GroupReference* itr = GetFirstMember(); itr != NULL; itr = itr->next()) { @@ -1608,9 +1694,9 @@ void Group::ResetInstances(uint8 method, bool isRaid, Player* SendMsgTo) for (BoundInstancesMap::iterator itr = m_boundInstances[diff].begin(); itr != m_boundInstances[diff].end();) { - InstanceSave* p = itr->second.save; + InstanceSave* instanceSave = itr->second.save; const MapEntry* entry = sMapStore.LookupEntry(itr->first); - if (!entry || entry->IsRaid() != isRaid || (!p->CanReset() && method != INSTANCE_RESET_GROUP_DISBAND)) + if (!entry || entry->IsRaid() != isRaid || (!instanceSave->CanReset() && method != INSTANCE_RESET_GROUP_DISBAND)) { ++itr; continue; @@ -1628,10 +1714,10 @@ void Group::ResetInstances(uint8 method, bool isRaid, Player* SendMsgTo) bool isEmpty = true; // if the map is loaded, reset it - Map* map = sMapMgr->FindMap(p->GetMapId(), p->GetInstanceId()); - if (map && map->IsDungeon() && !(method == INSTANCE_RESET_GROUP_DISBAND && !p->CanReset())) + Map* map = sMapMgr->FindMap(instanceSave->GetMapId(), instanceSave->GetInstanceId()); + if (map && map->IsDungeon() && !(method == INSTANCE_RESET_GROUP_DISBAND && !instanceSave->CanReset())) { - if (p->CanReset()) + if (instanceSave->CanReset()) isEmpty = ((InstanceMap*)map)->Reset(method); else isEmpty = !map->HavePlayers(); @@ -1640,25 +1726,32 @@ void Group::ResetInstances(uint8 method, bool isRaid, Player* SendMsgTo) if (SendMsgTo) { if (isEmpty) - SendMsgTo->SendResetInstanceSuccess(p->GetMapId()); + SendMsgTo->SendResetInstanceSuccess(instanceSave->GetMapId()); else - SendMsgTo->SendResetInstanceFailed(0, p->GetMapId()); + SendMsgTo->SendResetInstanceFailed(0, instanceSave->GetMapId()); } if (isEmpty || method == INSTANCE_RESET_GROUP_DISBAND || method == INSTANCE_RESET_CHANGE_DIFFICULTY) { // do not reset the instance, just unbind if others are permanently bound to it - if (p->CanReset()) - p->DeleteFromDB(); + if (instanceSave->CanReset()) + instanceSave->DeleteFromDB(); else - CharacterDatabase.PExecute("DELETE FROM group_instance WHERE instance = '%u'", p->GetInstanceId()); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GROUP_INSTANCE_BY_INSTANCE); + + stmt->setUInt32(0, instanceSave->GetInstanceId()); + + CharacterDatabase.Execute(stmt); + } + // i don't know for sure if hash_map iterators m_boundInstances[diff].erase(itr); itr = m_boundInstances[diff].begin(); // this unloads the instance save unless online players are bound to it // (eg. permanent binds or GM solo binds) - p->RemoveGroup(this); + instanceSave->RemoveGroup(this); } else ++itr; @@ -1711,7 +1804,15 @@ InstanceGroupBind* Group::BindToInstance(InstanceSave* save, bool permanent, boo InstanceGroupBind& bind = m_boundInstances[save->GetDifficulty()][save->GetMapId()]; if (!load && (!bind.save || permanent != bind.perm || save != bind.save)) - CharacterDatabase.PExecute("REPLACE INTO group_instance (guid, instance, permanent) VALUES (%u, %u, %u)", m_dbStoreId, save->GetInstanceId(), permanent); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_ADD_GROUP_INSTANCE); + + stmt->setUInt32(0, m_dbStoreId); + stmt->setUInt32(1, save->GetInstanceId()); + stmt->setBool(2, permanent); + + CharacterDatabase.Execute(stmt); + } if (bind.save != save) { @@ -1735,7 +1836,15 @@ void Group::UnbindInstance(uint32 mapid, uint8 difficulty, bool unload) if (itr != m_boundInstances[difficulty].end()) { if (!unload) - CharacterDatabase.PExecute("DELETE FROM group_instance WHERE guid=%u AND instance=%u", m_dbStoreId, itr->second.save->GetInstanceId()); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GROUP_INSTANCE_BY_GUID); + + stmt->setUInt32(0, m_dbStoreId); + stmt->setUInt32(1, itr->second.save->GetInstanceId()); + + CharacterDatabase.Execute(stmt); + } + itr->second.save->RemoveGroup(this); // save can become invalid m_boundInstances[difficulty].erase(itr); } @@ -1964,7 +2073,12 @@ void Group::SetGroupMemberFlag(uint64 guid, bool apply, GroupMemberFlags flag) ToggleGroupMemberFlag(slot, flag, apply); // Preserve the new setting in the db - CharacterDatabase.PExecute("UPDATE group_member SET memberFlags='%u' WHERE memberGuid='%u'", slot->flags, GUID_LOPART(guid)); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_GROUP_MEMBER_FLAG); + + stmt->setUInt8(0, slot->flags); + stmt->setUInt32(0, GUID_LOPART(guid)); + + CharacterDatabase.Execute(stmt); // Broadcast the changes to the group SendUpdate(); diff --git a/src/server/game/Instances/InstanceSaveMgr.cpp b/src/server/game/Instances/InstanceSaveMgr.cpp index 7a2368161d8..9d5ffb6542a 100755 --- a/src/server/game/Instances/InstanceSaveMgr.cpp +++ b/src/server/game/Instances/InstanceSaveMgr.cpp @@ -138,7 +138,14 @@ void InstanceSaveManager::RemoveInstanceSave(uint32 InstanceId) { // save the resettime for normal instances only when they get unloaded if (time_t resettime = itr->second->GetResetTimeForDB()) - CharacterDatabase.PExecute("UPDATE instance SET resettime = '"UI64FMTD"' WHERE id = '%u'", (uint64)resettime, InstanceId); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_INSTANCE_RESETTIME); + + stmt->setUInt32(0, uint32(resettime)); + stmt->setUInt32(1, InstanceId); + + CharacterDatabase.Execute(stmt); + } delete itr->second; m_instanceSaveById.erase(itr); @@ -573,13 +580,19 @@ void InstanceSaveManager::_ResetOrWarnAll(uint32 mapid, Difficulty difficulty, b if (period < DAY) period = DAY; - uint64 next_reset = ((resetTime + MINUTE) / DAY * DAY) + period + diff; + uint32 next_reset = ((resetTime + MINUTE) / DAY * DAY) + period + diff; SetResetTimeFor(mapid, difficulty, next_reset); ScheduleReset(true, time_t(next_reset-3600), InstResetEvent(1, mapid, difficulty, 0)); - // update it in the DB - CharacterDatabase.PExecute("UPDATE instance_reset SET resettime = '%u' WHERE mapid = '%d' AND difficulty = '%d'", uint32(next_reset), mapid, difficulty); + // Update it in the DB + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_GLOBAL_INSTANCE_RESETTIME); + + stmt->setUInt32(0, next_reset); + stmt->setUInt16(1, uint16(mapid)); + stmt->setUInt8(2, uint8(difficulty)); + + CharacterDatabase.Execute(stmt); } // note: this isn't fast but it's meant to be executed very rarely diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp index 0ddc03e3d5c..e0ba9eaaaa4 100755 --- a/src/server/game/Server/WorldSocket.cpp +++ b/src/server/game/Server/WorldSocket.cpp @@ -889,7 +889,13 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket) if (mutetime < 0) { mutetime = time(NULL) + llabs(mutetime); - LoginDatabase.PExecute("UPDATE account SET mutetime = " SI64FMTD " WHERE id = '%u'", mutetime, id); + + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPDATE_MUTE_TIME); + + stmt->setInt64(0, mutetime); + stmt->setUInt32(1, id); + + LoginDatabase.Execute(stmt); } locale = LocaleConstant (fields[8].GetUInt8()); @@ -985,14 +991,13 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket) isRecruiter = true; // Update the last_ip in the database - // No SQL injection, username escaped. - LoginDatabase.EscapeString (address); - LoginDatabase.PExecute ("UPDATE account " - "SET last_ip = '%s' " - "WHERE username = '%s'", - address.c_str(), - safe_account.c_str()); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(LOGIN_UPDATE_LAST_IP); + + stmt->setString(0, address); + stmt->setString(1, account); + + CharacterDatabase.Execute(stmt); // NOTE ATM the socket is single-threaded, have this in mind ... ACE_NEW_RETURN (m_Session, WorldSession (id, this, AccountTypes(security), expansion, mutetime, locale, recruiter, isRecruiter), -1); diff --git a/src/server/game/Tickets/TicketMgr.cpp b/src/server/game/Tickets/TicketMgr.cpp index 10c1f4a1dfd..c657248c595 100755 --- a/src/server/game/Tickets/TicketMgr.cpp +++ b/src/server/game/Tickets/TicketMgr.cpp @@ -207,7 +207,10 @@ void TicketMgr::ResetTickets() sTicketMgr->RemoveTicket(itr->second->GetId()); _lastTicketId = 0; - CharacterDatabase.PExecute("TRUNCATE TABLE gm_tickets"); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ALL_GM_TICKETS); + + CharacterDatabase.Execute(stmt); } void TicketMgr::LoadTickets() diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.cpp b/src/server/shared/Database/Implementation/CharacterDatabase.cpp index 02ff2dc5fb3..fb43a7286dd 100755 --- a/src/server/shared/Database/Implementation/CharacterDatabase.cpp +++ b/src/server/shared/Database/Implementation/CharacterDatabase.cpp @@ -95,6 +95,7 @@ void CharacterDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(CHAR_ADD_MAIL, "INSERT INTO mail(id, messageType, stationery, mailTemplateId, sender, receiver, subject, body, has_items, expire_time, deliver_time, money, cod, checked) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC) PREPARE_STATEMENT(CHAR_DEL_MAIL, "DELETE FROM mail WHERE id = ?", CONNECTION_ASYNC) PREPARE_STATEMENT(CHAR_ADD_MAIL_ITEM, "INSERT INTO mail_items(mail_id, item_guid, receiver) VALUES (?, ?, ?)", CONNECTION_ASYNC) + PREPARE_STATEMENT(CHAR_DEL_INVALID_MAIL_ITEM, "DELETE FROM mail_items WHERE item_guid = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_DEL_EMPTY_EXPIRED_MAIL, "DELETE FROM mail WHERE expire_time < ? AND has_items = 0 AND body = ''", CONNECTION_ASYNC) PREPARE_STATEMENT(CHAR_GET_EXPIRED_MAIL, "SELECT id, messageType, sender, receiver, has_items, expire_time, cod, checked, mailTemplateId FROM mail WHERE expire_time < ?", CONNECTION_SYNCH) PREPARE_STATEMENT(CHAR_GET_EXPIRED_MAIL_ITEMS, "SELECT item_guid, itemEntry, mail_id FROM mail_items mi INNER JOIN item_instance ii ON ii.guid = mi.item_guid LEFT JOIN mail mm ON mi.mail_id = mm.id WHERE mm.id IS NOT NULL AND mm.expire_time < ?", CONNECTION_SYNCH) @@ -329,8 +330,33 @@ void CharacterDatabaseConnection::DoPrepareStatements() "equipmentCache=?,ammoId=?,knownTitles=?,actionBars=?,grantableLevels=?,online=? WHERE guid=?", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_UPDATE_AT_LOGIN_FLAG, "UPDATE characters SET at_login = at_login | ? WHERE guid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPDATE_ALL_AT_LOGIN_FLAGS, "UPDATE characters SET at_login = at_login | ?", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_ADD_BUG_REPORT, "INSERT INTO bugreport (type, content) VALUES(?, ?)", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_UPD_PETITION_NAME, "UPDATE petition SET name = ? WHERE petitionguid = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_ADD_PETITION_SIGNATURE, "INSERT INTO petition_sign (ownerguid, petitionguid, playerguid, player_account) VALUES (?, ?, ?, ?)", CONNECTION_ASYNC); PREPARE_STATEMENT(CHAR_UPD_ACCOUNT_ONLINE, "UPDATE characters SET online = 0 WHERE account = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_ADD_GROUP, "INSERT INTO groups (guid, leaderGuid, lootMethod, looterGuid, lootThreshold, icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8, groupType, difficulty, raiddifficulty) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_ADD_GROUP_MEMBER, "INSERT INTO group_member (guid, memberGuid, memberFlags, subgroup, roles) VALUES(?, ?, ?, ?, ?)", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_DEL_GROUP_MEMBER, "DELETE FROM group_member WHERE memberGuid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_DEL_GROUP_INSTANCE_PERM_BINDING, "DELETE FROM group_instance WHERE guid = ? AND (permanent = 1 OR instance IN (SELECT instance FROM character_instance WHERE guid = ?))", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPDATE_GROUP_LEADER, "UPDATE groups SET leaderGuid = ? WHERE guid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPDATE_GROUP_TYPE, "UPDATE groups SET groupType = ? WHERE guid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPDATE_GROUP_MEMBER_SUBGROUP, "UPDATE group_member SET subgroup = ? WHERE memberGuid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPDATE_GROUP_MEMBER_FLAG, "UPDATE group_member SET memberFlags = ? WHERE memberGuid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPDATE_GROUP_DIFFICULTY, "UPDATE groups SET difficulty = ? WHERE guid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPDATE_GROUP_RAID_DIFFICULTY, "UPDATE groups SET raiddifficulty = ? WHERE guid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_DEL_ALL_GM_TICKETS, "TRUNCATE TABLE gm_tickets", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_DEL_INVALID_SPELL, "DELETE FROM character_talent WHERE spell = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPDATE_DELETE_INFO, "UPDATE characters SET deleteInfos_Name = name, deleteInfos_Account = account, deleteDate = UNIX_TIMESTAMP(), name = '', account = 0 WHERE guid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPDATE_ZONE, "UPDATE characters SET zone = ? WHERE guid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPDATE_LEVEL, "UPDATE characters SET level = ?, xp = 0 WHERE guid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_DEL_INVALID_ACHIEV_PROGRESS_CRITERIA, "DELETE FROM character_achievement_progress WHERE criteria = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_DEL_INVALID_ACHIEVMENT, "DELETE FROM character_achievement WHERE achievement = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_ADD_ADDON, "INSERT INTO addons (name, crc) VALUES (?, ?)", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_DEL_INVALID_PET_SPELL, "DELETE FROM pet_spell WHERE spell = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_DEL_GROUP_INSTANCE_BY_INSTANCE, "DELETE FROM group_instance WHERE instance = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_DEL_GROUP_INSTANCE_BY_GUID, "DELETE FROM group_instance WHERE guid = ? AND instance = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_ADD_GROUP_INSTANCE, "REPLACE INTO group_instance (guid, instance, permanent) VALUES (?, ?, ?)", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPDATE_INSTANCE_RESETTIME, "UPDATE instance SET resettime = ? WHERE id = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(CHAR_UPDATE_GLOBAL_INSTANCE_RESETTIME, "UPDATE instance_reset SET resettime = ? WHERE mapid = ? AND difficulty = ?", CONNECTION_ASYNC); } diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.h b/src/server/shared/Database/Implementation/CharacterDatabase.h index 636a8221d85..691b1f61706 100755 --- a/src/server/shared/Database/Implementation/CharacterDatabase.h +++ b/src/server/shared/Database/Implementation/CharacterDatabase.h @@ -104,6 +104,7 @@ enum CharacterDatabaseStatements CHAR_ADD_MAIL, CHAR_DEL_MAIL, CHAR_ADD_MAIL_ITEM, + CHAR_DEL_INVALID_MAIL_ITEM, CHAR_DEL_EMPTY_EXPIRED_MAIL, CHAR_GET_EXPIRED_MAIL, CHAR_GET_EXPIRED_MAIL_ITEMS, @@ -278,6 +279,7 @@ enum CharacterDatabaseStatements CHAR_LOAD_GM_TICKETS, CHAR_ADD_GM_TICKET, CHAR_DEL_GM_TICKET, + CHAR_DEL_ALL_GM_TICKETS, CHAR_DEL_PLAYER_GM_TICKETS, CHAR_ADD_GM_SURVEY, @@ -290,10 +292,34 @@ enum CharacterDatabaseStatements CHAR_UPD_CHARACTER, CHAR_UPDATE_AT_LOGIN_FLAG, + CHAR_UPDATE_ALL_AT_LOGIN_FLAGS, CHAR_ADD_BUG_REPORT, CHAR_UPD_PETITION_NAME, CHAR_ADD_PETITION_SIGNATURE, CHAR_UPD_ACCOUNT_ONLINE, + CHAR_ADD_GROUP, + CHAR_ADD_GROUP_MEMBER, + CHAR_DEL_GROUP_MEMBER, + CHAR_DEL_GROUP_INSTANCE_PERM_BINDING, + CHAR_UPDATE_GROUP_LEADER, + CHAR_UPDATE_GROUP_TYPE, + CHAR_UPDATE_GROUP_MEMBER_SUBGROUP, + CHAR_UPDATE_GROUP_MEMBER_FLAG, + CHAR_UPDATE_GROUP_DIFFICULTY, + CHAR_UPDATE_GROUP_RAID_DIFFICULTY, + CHAR_DEL_INVALID_SPELL, + CHAR_UPDATE_DELETE_INFO, + CHAR_UPDATE_ZONE, + CHAR_UPDATE_LEVEL, + CHAR_DEL_INVALID_ACHIEV_PROGRESS_CRITERIA, + CHAR_DEL_INVALID_ACHIEVMENT, + CHAR_ADD_ADDON, + CHAR_DEL_INVALID_PET_SPELL, + CHAR_DEL_GROUP_INSTANCE_BY_INSTANCE, + CHAR_DEL_GROUP_INSTANCE_BY_GUID, + CHAR_ADD_GROUP_INSTANCE, + CHAR_UPDATE_INSTANCE_RESETTIME, + CHAR_UPDATE_GLOBAL_INSTANCE_RESETTIME, MAX_CHARACTERDATABASE_STATEMENTS, }; diff --git a/src/server/shared/Database/Implementation/LoginDatabase.cpp b/src/server/shared/Database/Implementation/LoginDatabase.cpp index 9a7514ff053..713d4a31e6d 100755 --- a/src/server/shared/Database/Implementation/LoginDatabase.cpp +++ b/src/server/shared/Database/Implementation/LoginDatabase.cpp @@ -55,4 +55,5 @@ void LoginDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(LOGIN_UPDATE_USERNAME, "UPDATE account SET v = 0, s = 0, username = ?, sha_pass_hash = ? WHERE id = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(LOGIN_UPDATE_PASSWORD, "UPDATE account SET v = 0, s = 0, sha_pass_hash = ? WHERE id = ?", CONNECTION_ASYNC); PREPARE_STATEMENT(LOGIN_UPDATE_MUTE_TIME, "UPDATE account SET mutetime = ? WHERE id = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(LOGIN_UPDATE_LAST_IP, "UPDATE account SET last_ip = ? WHERE username = ?", CONNECTION_ASYNC); } diff --git a/src/server/shared/Database/Implementation/LoginDatabase.h b/src/server/shared/Database/Implementation/LoginDatabase.h index 96b437372d6..98d9c505fa0 100755 --- a/src/server/shared/Database/Implementation/LoginDatabase.h +++ b/src/server/shared/Database/Implementation/LoginDatabase.h @@ -75,6 +75,7 @@ enum LoginDatabaseStatements LOGIN_UPDATE_USERNAME, LOGIN_UPDATE_PASSWORD, LOGIN_UPDATE_MUTE_TIME, + LOGIN_UPDATE_LAST_IP, MAX_LOGINDATABASE_STATEMENTS, }; diff --git a/src/server/shared/Database/Implementation/WorldDatabase.cpp b/src/server/shared/Database/Implementation/WorldDatabase.cpp index ebf60e3d20e..5df8299310f 100755 --- a/src/server/shared/Database/Implementation/WorldDatabase.cpp +++ b/src/server/shared/Database/Implementation/WorldDatabase.cpp @@ -26,6 +26,8 @@ void WorldDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(WORLD_DEL_CRELINKED_RESPAWN, "DELETE FROM linked_respawn WHERE guid = ?", CONNECTION_ASYNC) PREPARE_STATEMENT(WORLD_REP_CRELINKED_RESPAWN, "REPLACE INTO linked_respawn (guid, linkedGuid) VALUES (?, ?)", CONNECTION_ASYNC) PREPARE_STATEMENT(WORLD_LOAD_CRETEXT, "SELECT entry, groupid, id, text, type, language, probability, emote, duration, sound FROM creature_text", CONNECTION_SYNCH) - PREPARE_STATEMENT(WORLD_LOAD_SMART_SCRIPTS, "SELECT entryorguid, source_type, id, link, event_type, event_phase_mask, event_chance, event_flags, event_param1, event_param2, event_param3, event_param4, action_type, action_param1, action_param2, action_param3, action_param4, action_param5, action_param6, target_type, target_param1, target_param2, target_param3, target_x, target_y, target_z, target_o FROM smart_scripts ORDER BY entryorguid, source_type, id, link", CONNECTION_SYNCH) - PREPARE_STATEMENT(WORLD_LOAD_SMARTAI_WP, "SELECT entry, pointid, position_x, position_y, position_z FROM waypoints ORDER BY entry, pointid", CONNECTION_SYNCH) + PREPARE_STATEMENT(WORLD_LOAD_SMART_SCRIPTS, "SELECT entryorguid, source_type, id, link, event_type, event_phase_mask, event_chance, event_flags, event_param1, event_param2, event_param3, event_param4, action_type, action_param1, action_param2, action_param3, action_param4, action_param5, action_param6, target_type, target_param1, target_param2, target_param3, target_x, target_y, target_z, target_o FROM smart_scripts ORDER BY entryorguid, source_type, id, link", CONNECTION_SYNCH) + PREPARE_STATEMENT(WORLD_LOAD_SMARTAI_WP, "SELECT entry, pointid, position_x, position_y, position_z FROM waypoints ORDER BY entry, pointid", CONNECTION_SYNCH) + PREPARE_STATEMENT(WORLD_DEL_GAMEOBJECT, "DELETE FROM gameobject WHERE guid = ?", CONNECTION_ASYNC); + PREPARE_STATEMENT(WORLD_DEL_EVENT_GAMEOBJECT, "DELETE FROM game_event_gameobject WHERE guid = ?", CONNECTION_ASYNC); } diff --git a/src/server/shared/Database/Implementation/WorldDatabase.h b/src/server/shared/Database/Implementation/WorldDatabase.h index 274ea4350c9..94d6365c081 100755 --- a/src/server/shared/Database/Implementation/WorldDatabase.h +++ b/src/server/shared/Database/Implementation/WorldDatabase.h @@ -48,6 +48,8 @@ enum WorldDatabaseStatements WORLD_LOAD_CRETEXT, WORLD_LOAD_SMART_SCRIPTS, WORLD_LOAD_SMARTAI_WP, + WORLD_DEL_GAMEOBJECT, + WORLD_DEL_EVENT_GAMEOBJECT, MAX_WORLDDATABASE_STATEMENTS, }; -- cgit v1.2.3