Core/DBLayer: Convert callback queries to prepared statements
This commit is contained in:
@@ -1850,7 +1850,7 @@ void Player::setDeathState(DeathState s)
|
||||
SetUInt32Value(PLAYER_SELF_RES_SPELL, 0);
|
||||
}
|
||||
|
||||
bool Player::BuildEnumData(QueryResult result, WorldPacket* data)
|
||||
bool Player::BuildEnumData(PreparedQueryResult result, WorldPacket* data)
|
||||
{
|
||||
// 0 1 2 3 4 5 6 7
|
||||
// "SELECT characters.guid, characters.name, characters.race, characters.class, characters.gender, characters.playerBytes, characters.playerBytes2, characters.level, "
|
||||
@@ -1894,8 +1894,8 @@ bool Player::BuildEnumData(QueryResult result, WorldPacket* data)
|
||||
*data << uint8(playerBytes2 & 0xFF); // facial hair
|
||||
|
||||
*data << uint8(fields[7].GetUInt8()); // level
|
||||
*data << uint32(fields[8].GetUInt32()); // zone
|
||||
*data << uint32(fields[9].GetUInt32()); // map
|
||||
*data << uint32(fields[8].GetUInt16()); // zone
|
||||
*data << uint32(fields[9].GetUInt16()); // map
|
||||
|
||||
*data << fields[10].GetFloat(); // x
|
||||
*data << fields[11].GetFloat(); // y
|
||||
|
||||
@@ -1111,7 +1111,7 @@ class Player : public Unit, public GridObject<Player>
|
||||
|
||||
void Update(uint32 time);
|
||||
|
||||
static bool BuildEnumData(QueryResult result, WorldPacket* data);
|
||||
static bool BuildEnumData(PreparedQueryResult result, WorldPacket* data);
|
||||
|
||||
void SetInWater(bool apply);
|
||||
|
||||
@@ -2500,7 +2500,7 @@ class Player : public Unit, public GridObject<Player>
|
||||
CreatureDisplayInfoEntry const* mountDisplayInfo = sCreatureDisplayInfoStore.LookupEntry(GetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID));
|
||||
if (!mountDisplayInfo)
|
||||
return GetCollisionHeight(false);
|
||||
|
||||
|
||||
CreatureModelDataEntry const* mountModelData = sCreatureModelDataStore.LookupEntry(mountDisplayInfo->ModelId);
|
||||
if (!mountModelData)
|
||||
return GetCollisionHeight(false);
|
||||
|
||||
@@ -196,7 +196,7 @@ bool LoginQueryHolder::Initialize()
|
||||
return res;
|
||||
}
|
||||
|
||||
void WorldSession::HandleCharEnum(QueryResult result)
|
||||
void WorldSession::HandleCharEnum(PreparedQueryResult result)
|
||||
{
|
||||
WorldPacket data(SMSG_CHAR_ENUM, 100); // we guess size
|
||||
|
||||
@@ -232,35 +232,16 @@ void WorldSession::HandleCharEnumOpcode(WorldPacket & /*recv_data*/)
|
||||
CharacterDatabase.Execute(stmt);
|
||||
|
||||
/// get all the data necessary for loading all characters (along with their pets) on the account
|
||||
_charEnumCallback =
|
||||
CharacterDatabase.AsyncPQuery(
|
||||
!sWorld->getBoolConfig(CONFIG_DECLINED_NAMES_USED) ?
|
||||
// ------- Query Without Declined Names --------
|
||||
// 0 1 2 3 4 5 6 7
|
||||
"SELECT characters.guid, characters.name, characters.race, characters.class, characters.gender, characters.playerBytes, characters.playerBytes2, characters.level, "
|
||||
// 8 9 10 11 12 13 14
|
||||
"characters.zone, characters.map, characters.position_x, characters.position_y, characters.position_z, guild_member.guildid, characters.playerFlags, "
|
||||
// 15 16 17 18 19 20
|
||||
"characters.at_login, character_pet.entry, character_pet.modelid, character_pet.level, characters.equipmentCache, character_banned.guid "
|
||||
"FROM characters LEFT JOIN character_pet ON characters.guid=character_pet.owner AND character_pet.slot='%u' "
|
||||
"LEFT JOIN guild_member ON characters.guid = guild_member.guid "
|
||||
"LEFT JOIN character_banned ON characters.guid = character_banned.guid AND character_banned.active = 1 "
|
||||
"WHERE characters.account = '%u' ORDER BY characters.guid"
|
||||
:
|
||||
// --------- Query With Declined Names ---------
|
||||
// 0 1 2 3 4 5 6 7
|
||||
"SELECT characters.guid, characters.name, characters.race, characters.class, characters.gender, characters.playerBytes, characters.playerBytes2, characters.level, "
|
||||
// 8 9 10 11 12 13 14
|
||||
"characters.zone, characters.map, characters.position_x, characters.position_y, characters.position_z, guild_member.guildid, characters.playerFlags, "
|
||||
// 15 16 17 18 19 20 21
|
||||
"characters.at_login, character_pet.entry, character_pet.modelid, character_pet.level, characters.equipmentCache, character_banned.guid, character_declinedname.genitive "
|
||||
"FROM characters LEFT JOIN character_pet ON characters.guid = character_pet.owner AND character_pet.slot='%u' "
|
||||
"LEFT JOIN character_declinedname ON characters.guid = character_declinedname.guid "
|
||||
"LEFT JOIN guild_member ON characters.guid = guild_member.guid "
|
||||
"LEFT JOIN character_banned ON characters.guid = character_banned.guid AND character_banned.active = 1 "
|
||||
"WHERE characters.account = '%u' ORDER BY characters.guid",
|
||||
PET_SAVE_AS_CURRENT, GetAccountId()
|
||||
);
|
||||
|
||||
if (sWorld->getBoolConfig(CONFIG_DECLINED_NAMES_USED))
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_GET_ENUM_DECLINED_NAME);
|
||||
else
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_GET_ENUM);
|
||||
|
||||
stmt->setUInt8(0, PET_SAVE_AS_CURRENT);
|
||||
stmt->setUInt32(1, GetAccountId());
|
||||
|
||||
_charEnumCallback = CharacterDatabase.AsyncQuery(stmt);
|
||||
}
|
||||
|
||||
void WorldSession::HandleCharCreateOpcode(WorldPacket & recv_data)
|
||||
@@ -1102,13 +1083,13 @@ void WorldSession::HandleShowingCloakOpcode(WorldPacket& recv_data)
|
||||
void WorldSession::HandleCharRenameOpcode(WorldPacket& recv_data)
|
||||
{
|
||||
uint64 guid;
|
||||
std::string newname;
|
||||
std::string newName;
|
||||
|
||||
recv_data >> guid;
|
||||
recv_data >> newname;
|
||||
recv_data >> newName;
|
||||
|
||||
// prevent character rename to invalid name
|
||||
if (!normalizePlayerName(newname))
|
||||
if (!normalizePlayerName(newName))
|
||||
{
|
||||
WorldPacket data(SMSG_CHAR_RENAME, 1);
|
||||
data << uint8(CHAR_NAME_NO_NAME);
|
||||
@@ -1116,7 +1097,7 @@ void WorldSession::HandleCharRenameOpcode(WorldPacket& recv_data)
|
||||
return;
|
||||
}
|
||||
|
||||
uint8 res = ObjectMgr::CheckPlayerName(newname, true);
|
||||
uint8 res = ObjectMgr::CheckPlayerName(newName, true);
|
||||
if (res != CHAR_NAME_SUCCESS)
|
||||
{
|
||||
WorldPacket data(SMSG_CHAR_RENAME, 1);
|
||||
@@ -1126,7 +1107,7 @@ void WorldSession::HandleCharRenameOpcode(WorldPacket& recv_data)
|
||||
}
|
||||
|
||||
// check name limitations
|
||||
if (AccountMgr::IsPlayerAccount(GetSecurity()) && sObjectMgr->IsReservedName(newname))
|
||||
if (AccountMgr::IsPlayerAccount(GetSecurity()) && sObjectMgr->IsReservedName(newName))
|
||||
{
|
||||
WorldPacket data(SMSG_CHAR_RENAME, 1);
|
||||
data << uint8(CHAR_NAME_RESERVED);
|
||||
@@ -1134,21 +1115,22 @@ void WorldSession::HandleCharRenameOpcode(WorldPacket& recv_data)
|
||||
return;
|
||||
}
|
||||
|
||||
std::string escaped_newname = newname;
|
||||
CharacterDatabase.EscapeString(escaped_newname);
|
||||
|
||||
// make sure that the character belongs to the current account, that rename at login is enabled
|
||||
// Ensure that the character belongs to the current account, that rename at login is enabled
|
||||
// and that there is no character with the desired new name
|
||||
_charRenameCallback.SetParam(newname);
|
||||
_charRenameCallback.SetFutureResult(
|
||||
CharacterDatabase.AsyncPQuery(
|
||||
"SELECT guid, name FROM characters WHERE guid = %d AND account = %d AND (at_login & %d) = %d AND NOT EXISTS (SELECT NULL FROM characters WHERE name = '%s')",
|
||||
GUID_LOPART(guid), GetAccountId(), AT_LOGIN_RENAME, AT_LOGIN_RENAME, escaped_newname.c_str()
|
||||
)
|
||||
);
|
||||
_charRenameCallback.SetParam(newName);
|
||||
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_GET_FREE_NAME);
|
||||
|
||||
stmt->setUInt32(0, GUID_LOPART(guid));
|
||||
stmt->setUInt32(1, GetAccountId());
|
||||
stmt->setUInt16(2, AT_LOGIN_RENAME);
|
||||
stmt->setUInt16(3, AT_LOGIN_RENAME);
|
||||
stmt->setString(4, newName);
|
||||
|
||||
_charRenameCallback.SetFutureResult(CharacterDatabase.AsyncQuery(stmt));
|
||||
}
|
||||
|
||||
void WorldSession::HandleChangePlayerNameOpcodeCallBack(QueryResult result, std::string newname)
|
||||
void WorldSession::HandleChangePlayerNameOpcodeCallBack(PreparedQueryResult result, std::string newName)
|
||||
{
|
||||
if (!result)
|
||||
{
|
||||
@@ -1158,22 +1140,38 @@ void WorldSession::HandleChangePlayerNameOpcodeCallBack(QueryResult result, std:
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 guidLow = result->Fetch()[0].GetUInt32();
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 guidLow = fields[0].GetUInt32();
|
||||
std::string oldName = fields[1].GetString();
|
||||
|
||||
uint64 guid = MAKE_NEW_GUID(guidLow, 0, HIGHGUID_PLAYER);
|
||||
std::string oldname = result->Fetch()[1].GetString();
|
||||
|
||||
CharacterDatabase.PExecute("UPDATE characters set name = '%s', at_login = at_login & ~ %u WHERE guid ='%u'", newname.c_str(), uint32(AT_LOGIN_RENAME), guidLow);
|
||||
CharacterDatabase.PExecute("DELETE FROM character_declinedname WHERE guid ='%u'", guidLow);
|
||||
// Update name and at_login flag in the db
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_NAME);
|
||||
|
||||
sLog->outChar("Account: %d (IP: %s) Character:[%s] (guid:%u) Changed name to: %s", GetAccountId(), GetRemoteAddress().c_str(), oldname.c_str(), guidLow, newname.c_str());
|
||||
stmt->setString(0, newName);
|
||||
stmt->setUInt16(1, AT_LOGIN_RENAME);
|
||||
stmt->setUInt32(2, guidLow);
|
||||
|
||||
WorldPacket data(SMSG_CHAR_RENAME, 1+8+(newname.size()+1));
|
||||
CharacterDatabase.Execute(stmt);
|
||||
|
||||
// Removed declined name from db
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_DECLINED_NAME);
|
||||
|
||||
stmt->setUInt32(0, guidLow);
|
||||
|
||||
CharacterDatabase.Execute(stmt);
|
||||
|
||||
sLog->outChar("Account: %d (IP: %s) Character:[%s] (guid:%u) Changed name to: %s", GetAccountId(), GetRemoteAddress().c_str(), oldName.c_str(), guidLow, newName.c_str());
|
||||
|
||||
WorldPacket data(SMSG_CHAR_RENAME, 1+8+(newName.size()+1));
|
||||
data << uint8(RESPONSE_SUCCESS);
|
||||
data << uint64(guid);
|
||||
data << newname;
|
||||
data << newName;
|
||||
SendPacket(&data);
|
||||
|
||||
sWorld->UpdateCharacterNameData(guidLow, newname);
|
||||
sWorld->UpdateCharacterNameData(guidLow, newName);
|
||||
}
|
||||
|
||||
void WorldSession::HandleSetPlayerDeclinedNames(WorldPacket& recv_data)
|
||||
|
||||
@@ -613,22 +613,24 @@ void WorldSession::HandleAddIgnoreOpcode(WorldPacket & recv_data)
|
||||
{
|
||||
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Received CMSG_ADD_IGNORE");
|
||||
|
||||
std::string IgnoreName = GetTrinityString(LANG_FRIEND_IGNORE_UNKNOWN);
|
||||
std::string ignoreName = GetTrinityString(LANG_FRIEND_IGNORE_UNKNOWN);
|
||||
|
||||
recv_data >> IgnoreName;
|
||||
recv_data >> ignoreName;
|
||||
|
||||
if (!normalizePlayerName(IgnoreName))
|
||||
if (!normalizePlayerName(ignoreName))
|
||||
return;
|
||||
|
||||
CharacterDatabase.EscapeString(IgnoreName); // prevent SQL injection - normal name must not be changed by this call
|
||||
|
||||
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: %s asked to Ignore: '%s'",
|
||||
GetPlayer()->GetName(), IgnoreName.c_str());
|
||||
GetPlayer()->GetName(), ignoreName.c_str());
|
||||
|
||||
_addIgnoreCallback = CharacterDatabase.AsyncPQuery("SELECT guid FROM characters WHERE name = '%s'", IgnoreName.c_str());
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_GET_GUID_BY_NAME);
|
||||
|
||||
stmt->setString(0, ignoreName);
|
||||
|
||||
_addIgnoreCallback = CharacterDatabase.AsyncQuery(stmt);
|
||||
}
|
||||
|
||||
void WorldSession::HandleAddIgnoreOpcodeCallBack(QueryResult result)
|
||||
void WorldSession::HandleAddIgnoreOpcodeCallBack(PreparedQueryResult result)
|
||||
{
|
||||
if (!GetPlayer())
|
||||
return;
|
||||
|
||||
@@ -618,39 +618,43 @@ void WorldSession::HandleStablePet(WorldPacket & recv_data)
|
||||
return;
|
||||
}
|
||||
|
||||
_stablePetCallback = CharacterDatabase.AsyncPQuery("SELECT owner, slot, id 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);
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_GET_PET_SLOTS);
|
||||
|
||||
stmt->setUInt32(0, _player->GetGUIDLow());
|
||||
stmt->setUInt8(1, PET_SAVE_FIRST_STABLE_SLOT);
|
||||
stmt->setUInt8(2, PET_SAVE_LAST_STABLE_SLOT);
|
||||
|
||||
_stablePetCallback = CharacterDatabase.AsyncQuery(stmt);
|
||||
}
|
||||
|
||||
void WorldSession::HandleStablePetCallback(QueryResult result)
|
||||
void WorldSession::HandleStablePetCallback(PreparedQueryResult result)
|
||||
{
|
||||
if (!GetPlayer())
|
||||
return;
|
||||
|
||||
uint32 free_slot = 1;
|
||||
uint8 freeSlot = 1;
|
||||
if (result)
|
||||
{
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 slot = fields[1].GetUInt32();
|
||||
uint8 slot = fields[1].GetUInt8();
|
||||
|
||||
// slots ordered in query, and if not equal then free
|
||||
if (slot != free_slot)
|
||||
if (slot != freeSlot)
|
||||
break;
|
||||
|
||||
// this slot not free, skip
|
||||
++free_slot;
|
||||
++freeSlot;
|
||||
}
|
||||
while (result->NextRow());
|
||||
}
|
||||
|
||||
WorldPacket data(SMSG_STABLE_RESULT, 1);
|
||||
if (free_slot > 0 && free_slot <= GetPlayer()->m_stableSlots)
|
||||
if (freeSlot > 0 && freeSlot <= GetPlayer()->m_stableSlots)
|
||||
{
|
||||
_player->RemovePet(_player->GetPet(), PetSaveMode(free_slot));
|
||||
_player->RemovePet(_player->GetPet(), PetSaveMode(freeSlot));
|
||||
SendStableResult(STABLE_SUCCESS_STABLE);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -983,12 +983,13 @@ void WorldSession::InitializeQueryCallbackParameters()
|
||||
void WorldSession::ProcessQueryCallbacks()
|
||||
{
|
||||
QueryResult result;
|
||||
PreparedQueryResult result2;
|
||||
|
||||
//! HandleCharEnumOpcode
|
||||
if (_charEnumCallback.ready())
|
||||
{
|
||||
_charEnumCallback.get(result);
|
||||
HandleCharEnum(result);
|
||||
_charEnumCallback.get(result2);
|
||||
HandleCharEnum(result2);
|
||||
_charEnumCallback.cancel();
|
||||
}
|
||||
|
||||
@@ -1022,16 +1023,16 @@ void WorldSession::ProcessQueryCallbacks()
|
||||
if (_charRenameCallback.IsReady())
|
||||
{
|
||||
std::string param = _charRenameCallback.GetParam();
|
||||
_charRenameCallback.GetResult(result);
|
||||
HandleChangePlayerNameOpcodeCallBack(result, param);
|
||||
_charRenameCallback.GetResult(result2);
|
||||
HandleChangePlayerNameOpcodeCallBack(result2, param);
|
||||
_charRenameCallback.FreeResult();
|
||||
}
|
||||
|
||||
//- HandleCharAddIgnoreOpcode
|
||||
if (_addIgnoreCallback.ready())
|
||||
{
|
||||
_addIgnoreCallback.get(result);
|
||||
HandleAddIgnoreOpcodeCallBack(result);
|
||||
_addIgnoreCallback.get(result2);
|
||||
HandleAddIgnoreOpcodeCallBack(result2);
|
||||
_addIgnoreCallback.cancel();
|
||||
}
|
||||
|
||||
@@ -1047,8 +1048,8 @@ void WorldSession::ProcessQueryCallbacks()
|
||||
//- HandleStablePet
|
||||
if (_stablePetCallback.ready())
|
||||
{
|
||||
_stablePetCallback.get(result);
|
||||
HandleStablePetCallback(result);
|
||||
_stablePetCallback.get(result2);
|
||||
HandleStablePetCallback(result2);
|
||||
_stablePetCallback.cancel();
|
||||
}
|
||||
|
||||
|
||||
@@ -400,7 +400,7 @@ class WorldSession
|
||||
void HandleCharCreateOpcode(WorldPacket& recvPacket);
|
||||
void HandleCharCreateCallback(PreparedQueryResult result, CharacterCreateInfo* createInfo);
|
||||
void HandlePlayerLoginOpcode(WorldPacket& recvPacket);
|
||||
void HandleCharEnum(QueryResult result);
|
||||
void HandleCharEnum(PreparedQueryResult result);
|
||||
void HandlePlayerLogin(LoginQueryHolder * holder);
|
||||
void HandleCharFactionOrRaceChange(WorldPacket& recv_data);
|
||||
|
||||
@@ -472,7 +472,7 @@ class WorldSession
|
||||
void HandleAddFriendOpcodeCallBack(QueryResult result, std::string friendNote);
|
||||
void HandleDelFriendOpcode(WorldPacket& recvPacket);
|
||||
void HandleAddIgnoreOpcode(WorldPacket& recvPacket);
|
||||
void HandleAddIgnoreOpcodeCallBack(QueryResult result);
|
||||
void HandleAddIgnoreOpcodeCallBack(PreparedQueryResult result);
|
||||
void HandleDelIgnoreOpcode(WorldPacket& recvPacket);
|
||||
void HandleSetContactNotesOpcode(WorldPacket& recvPacket);
|
||||
void HandleBugOpcode(WorldPacket& recvPacket);
|
||||
@@ -588,7 +588,7 @@ class WorldSession
|
||||
void HandleBinderActivateOpcode(WorldPacket& recvPacket);
|
||||
void HandleListStabledPetsOpcode(WorldPacket& recvPacket);
|
||||
void HandleStablePet(WorldPacket& recvPacket);
|
||||
void HandleStablePetCallback(QueryResult result);
|
||||
void HandleStablePetCallback(PreparedQueryResult result);
|
||||
void HandleUnstablePet(WorldPacket& recvPacket);
|
||||
void HandleUnstablePetCallback(QueryResult result, uint32 petnumber);
|
||||
void HandleBuyStableSlot(WorldPacket& recvPacket);
|
||||
@@ -747,7 +747,7 @@ class WorldSession
|
||||
void HandleSetActionBarToggles(WorldPacket& recv_data);
|
||||
|
||||
void HandleCharRenameOpcode(WorldPacket& recv_data);
|
||||
void HandleChangePlayerNameOpcodeCallBack(QueryResult result, std::string newname);
|
||||
void HandleChangePlayerNameOpcodeCallBack(PreparedQueryResult result, std::string newName);
|
||||
void HandleSetPlayerDeclinedNames(WorldPacket& recv_data);
|
||||
|
||||
void HandleTotemDestroyed(WorldPacket& recv_data);
|
||||
@@ -896,11 +896,10 @@ class WorldSession
|
||||
void InitializeQueryCallbackParameters();
|
||||
void ProcessQueryCallbacks();
|
||||
|
||||
ACE_Future_Set<QueryResult> _nameQueryCallbacks;
|
||||
QueryResultFuture _charEnumCallback;
|
||||
QueryResultFuture _addIgnoreCallback;
|
||||
QueryResultFuture _stablePetCallback;
|
||||
QueryCallback<QueryResult, std::string> _charRenameCallback;
|
||||
PreparedQueryResultFuture _charEnumCallback;
|
||||
PreparedQueryResultFuture _addIgnoreCallback;
|
||||
PreparedQueryResultFuture _stablePetCallback;
|
||||
QueryCallback<PreparedQueryResult, std::string> _charRenameCallback;
|
||||
QueryCallback<QueryResult, std::string> _addFriendCallback;
|
||||
QueryCallback<QueryResult, uint32> _unstablePetCallback;
|
||||
QueryCallback<QueryResult, uint32> _stableSwapCallback;
|
||||
|
||||
Reference in New Issue
Block a user