Core/DBLayer: Convert PExecute() queries to prepared statements No. 1
This commit is contained in:
@@ -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(target_guid));
|
||||
CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '1' WHERE guid = '%u'", GUID_LOPART(target_guid));
|
||||
PSendSysMessage(LANG_RENAME_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(targetGuid));
|
||||
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_AT_LOGIN_FLAG);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user