mirror of
https://github.com/mangosfour/server.git
synced 2025-12-16 04:37:00 +00:00
[6907] Make DB access on char rename async.
Signed-off-by: hunuza <hunuza@gmail.com>
This commit is contained in:
parent
6f8f621626
commit
08a3105312
3 changed files with 36 additions and 39 deletions
|
|
@ -899,40 +899,14 @@ void WorldSession::HandleToggleCloakOpcode( WorldPacket & /*recv_data*/ )
|
||||||
|
|
||||||
void WorldSession::HandleChangePlayerNameOpcode(WorldPacket& recv_data)
|
void WorldSession::HandleChangePlayerNameOpcode(WorldPacket& recv_data)
|
||||||
{
|
{
|
||||||
CHECK_PACKET_SIZE(recv_data,8+1);
|
|
||||||
|
|
||||||
uint64 guid;
|
uint64 guid;
|
||||||
std::string newname;
|
std::string newname;
|
||||||
std::string oldname;
|
|
||||||
|
|
||||||
CHECK_PACKET_SIZE(recv_data, 8+1);
|
CHECK_PACKET_SIZE(recv_data, 8+1);
|
||||||
|
|
||||||
recv_data >> guid;
|
recv_data >> guid;
|
||||||
recv_data >> newname;
|
recv_data >> newname;
|
||||||
|
|
||||||
QueryResult *result = CharacterDatabase.PQuery("SELECT at_login, name FROM characters WHERE guid ='%u'", GUID_LOPART(guid));
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
WorldPacket data(SMSG_CHAR_RENAME, 1);
|
|
||||||
data << (uint8)CHAR_CREATE_ERROR;
|
|
||||||
SendPacket( &data );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32 at_loginFlags;
|
|
||||||
Field *fields = result->Fetch();
|
|
||||||
at_loginFlags = fields[0].GetUInt32();
|
|
||||||
oldname = fields[1].GetCppString();
|
|
||||||
delete result;
|
|
||||||
|
|
||||||
if (!(at_loginFlags & AT_LOGIN_RENAME))
|
|
||||||
{
|
|
||||||
WorldPacket data(SMSG_CHAR_RENAME, 1);
|
|
||||||
data << (uint8)CHAR_CREATE_ERROR;
|
|
||||||
SendPacket( &data );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// prevent character rename to invalid name
|
// prevent character rename to invalid name
|
||||||
if(!normalizePlayerName(newname))
|
if(!normalizePlayerName(newname))
|
||||||
{
|
{
|
||||||
|
|
@ -959,36 +933,58 @@ void WorldSession::HandleChangePlayerNameOpcode(WorldPacket& recv_data)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(objmgr.GetPlayerGUIDByName(newname)) // character with this name already exist
|
CharacterDatabase.escape_string(newname);
|
||||||
|
|
||||||
|
CharacterDatabase.AsyncPQuery(&WorldSession::HandleChangePlayerNameOpcodeCallBack, GUID_LOPART(guid), newname, "SELECT guid, at_login, name FROM characters WHERE guid = '%u' XOR name = '%s'", GUID_LOPART(guid), newname.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldSession::HandleChangePlayerNameOpcodeCallBack(QueryResult *result, uint32 accountId, std::string newname)
|
||||||
|
{
|
||||||
|
WorldSession * session = sWorld.FindSession(accountId);
|
||||||
|
if(!session)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!result || result->GetRowCount() != 1)
|
||||||
{
|
{
|
||||||
WorldPacket data(SMSG_CHAR_RENAME, 1);
|
WorldPacket data(SMSG_CHAR_RENAME, 1);
|
||||||
data << (uint8)CHAR_CREATE_ERROR;
|
data << (uint8)CHAR_CREATE_ERROR;
|
||||||
SendPacket( &data );
|
session->SendPacket( &data );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newname == oldname) // checked by client
|
Field *fields = result->Fetch();
|
||||||
|
uint32 guidLow = fields[0].GetUInt32();
|
||||||
|
uint64 guid = MAKE_NEW_GUID(guidLow, 0, HIGHGUID_PLAYER);
|
||||||
|
uint32 at_loginFlags = fields[1].GetUInt32();
|
||||||
|
std::string oldname = fields[2].GetCppString();
|
||||||
|
delete result;
|
||||||
|
if(oldname == newname)
|
||||||
{
|
{
|
||||||
WorldPacket data(SMSG_CHAR_RENAME, 1);
|
WorldPacket data(SMSG_CHAR_RENAME, 1);
|
||||||
data << (uint8)CHAR_NAME_FAILURE;
|
data << (uint8)CHAR_CREATE_ERROR;
|
||||||
SendPacket( &data );
|
session->SendPacket( &data );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// we have to check character at_login_flag & AT_LOGIN_RENAME also (fake packets hehe)
|
// we have to check character at_login_flag & AT_LOGIN_RENAME also (fake packets hehe)
|
||||||
|
if (!(at_loginFlags & AT_LOGIN_RENAME))
|
||||||
|
{
|
||||||
|
WorldPacket data(SMSG_CHAR_RENAME, 1);
|
||||||
|
data << (uint8)CHAR_CREATE_ERROR;
|
||||||
|
session->SendPacket( &data );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CharacterDatabase.escape_string(newname);
|
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("UPDATE characters set name = '%s', at_login = at_login & ~ %u WHERE guid ='%u'", newname.c_str(), uint32(AT_LOGIN_RENAME),GUID_LOPART(guid));
|
CharacterDatabase.PExecute("DELETE FROM character_declinedname WHERE guid ='%u'", guidLow);
|
||||||
CharacterDatabase.PExecute("DELETE FROM character_declinedname WHERE guid ='%u'", GUID_LOPART(guid));
|
|
||||||
|
|
||||||
std::string IP_str = GetRemoteAddress();
|
sLog.outChar("Account: %d (IP: %s) Character:[%s] (guid:%u) Changed name to: %s",session->GetAccountId(),session->GetRemoteAddress(),oldname.c_str(),guidLow,newname.c_str());
|
||||||
sLog.outChar("Account: %d (IP: %s) Character:[%s] (guid:%u) Changed name to: %s",GetAccountId(),IP_str.c_str(),oldname.c_str(),GUID_LOPART(guid),newname.c_str());
|
|
||||||
|
|
||||||
WorldPacket data(SMSG_CHAR_RENAME,1+8+(newname.size()+1));
|
WorldPacket data(SMSG_CHAR_RENAME,1+8+(newname.size()+1));
|
||||||
data << (uint8)RESPONSE_SUCCESS;
|
data << (uint8)RESPONSE_SUCCESS;
|
||||||
data << guid;
|
data << guid;
|
||||||
data << newname;
|
data << newname;
|
||||||
SendPacket(&data);
|
session->SendPacket(&data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldSession::HandleDeclinedPlayerNameOpcode(WorldPacket& recv_data)
|
void WorldSession::HandleDeclinedPlayerNameOpcode(WorldPacket& recv_data)
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ class MANGOS_DLL_SPEC WorldSession
|
||||||
Player* GetPlayer() const { return _player; }
|
Player* GetPlayer() const { return _player; }
|
||||||
char const* GetPlayerName() const;
|
char const* GetPlayerName() const;
|
||||||
void SetSecurity(uint32 security) { _security = security; }
|
void SetSecurity(uint32 security) { _security = security; }
|
||||||
std::string& GetRemoteAddress() { return m_Address; }
|
std::string const& GetRemoteAddress() { return m_Address; }
|
||||||
void SetPlayer(Player *plr) { _player = plr; }
|
void SetPlayer(Player *plr) { _player = plr; }
|
||||||
uint8 Expansion() const { return m_expansion; }
|
uint8 Expansion() const { return m_expansion; }
|
||||||
|
|
||||||
|
|
@ -541,6 +541,7 @@ class MANGOS_DLL_SPEC WorldSession
|
||||||
void HandleSetActionBar(WorldPacket& recv_data);
|
void HandleSetActionBar(WorldPacket& recv_data);
|
||||||
|
|
||||||
void HandleChangePlayerNameOpcode(WorldPacket& recv_data);
|
void HandleChangePlayerNameOpcode(WorldPacket& recv_data);
|
||||||
|
static void HandleChangePlayerNameOpcodeCallBack(QueryResult *result, uint32 accountId, std::string newname);
|
||||||
void HandleDeclinedPlayerNameOpcode(WorldPacket& recv_data);
|
void HandleDeclinedPlayerNameOpcode(WorldPacket& recv_data);
|
||||||
|
|
||||||
void HandleTotemDestroy(WorldPacket& recv_data);
|
void HandleTotemDestroy(WorldPacket& recv_data);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "6906"
|
#define REVISION_NR "6907"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue