aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Server/Protocol
diff options
context:
space:
mode:
authorleak <leakzx@googlemail.com>2011-12-25 18:12:58 +0100
committerleak <leakzx@googlemail.com>2011-12-25 18:13:21 +0100
commitef17c05dec23eed3a2dddc3697574155ad061079 (patch)
tree566f9f3a6ab2565032f02dcf2a65a6001212dd43 /src/server/game/Server/Protocol
parent9b8d18e7cd09625ba5b24355a3ca88b83125fd11 (diff)
Core/DBLayer: Convert PExecute() queries to prepared statements No. 1
Diffstat (limited to 'src/server/game/Server/Protocol')
-rwxr-xr-xsrc/server/game/Server/Protocol/Handlers/MiscHandler.cpp9
-rwxr-xr-xsrc/server/game/Server/Protocol/Handlers/PetitionsHandler.cpp85
-rwxr-xr-xsrc/server/game/Server/Protocol/Handlers/SpellHandler.cpp47
3 files changed, 79 insertions, 62 deletions
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)