Core/DBLayer:
- Rewrite Field class to be able to store both binary prepared statement data and data from adhoc query resultsets
- Buffer the data of prepared statements using ResultSet and Field classes and let go of mysql c api structures after PreparedResultSet constructor. Fixes a race condition and thus a possible crash/data corruption (issue pointed out to Derex, basic suggestion by raczman)
- Conform PreparedResultSet and ResultSet to the same design standards, and using Field class as data buffer class for both
* NOTE: This means the fetching methods are uniform again, using ¨Field* fields = result->Fetch();¨ and access to elements trough fields[x].
* NOTE: for access to the correct row in prepared statements, ¨Field* fields = result->Fetch();¨ must ALWAYS be called inside the do { }while(result->NextRow()) loop.
* NOTE: This means that Field::GetString() returns std::string object and Field::GetCString() returns const char* pointer.
Still experimental and all that jazz, not recommended for production servers until feedback is given.
--HG--
branch : trunk
This commit is contained in:
@@ -607,7 +607,7 @@ void WorldSession::HandleCharDeleteOpcode(WorldPacket & recv_data)
|
||||
{
|
||||
Field *fields = result->Fetch();
|
||||
accountId = fields[0].GetUInt32();
|
||||
name = fields[1].GetCppString();
|
||||
name = fields[1].GetString();
|
||||
}
|
||||
|
||||
// prevent deleting other players' characters using cheating tools
|
||||
@@ -741,8 +741,9 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder * holder)
|
||||
//QueryResult *result = CharacterDatabase.PQuery("SELECT guildid,rank FROM guild_member WHERE guid = '%u'",pCurrChar->GetGUIDLow());
|
||||
if (PreparedQueryResult resultGuild = holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOADGUILD))
|
||||
{
|
||||
pCurrChar->SetInGuild(resultGuild->GetUInt32(0));
|
||||
pCurrChar->SetRank(resultGuild->GetUInt8(1));
|
||||
Field* fields = resultGuild->Fetch();
|
||||
pCurrChar->SetInGuild(fields[0].GetUInt32());
|
||||
pCurrChar->SetRank(fields[1].GetUInt8());
|
||||
}
|
||||
else if (pCurrChar->GetGuildId()) // clear guild related fields in case wrong data about non existed membership
|
||||
{
|
||||
@@ -1067,7 +1068,7 @@ void WorldSession::HandleChangePlayerNameOpcodeCallBack(QueryResult result, std:
|
||||
|
||||
uint32 guidLow = result->Fetch()[0].GetUInt32();
|
||||
uint64 guid = MAKE_NEW_GUID(guidLow, 0, HIGHGUID_PLAYER);
|
||||
std::string oldname = result->Fetch()[1].GetCppString();
|
||||
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);
|
||||
@@ -1318,7 +1319,7 @@ void WorldSession::HandleCharCustomize(WorldPacket& recv_data)
|
||||
CharacterDatabase.escape_string(newname);
|
||||
if (QueryResult result = CharacterDatabase.PQuery("SELECT name FROM characters WHERE guid ='%u'", GUID_LOPART(guid)))
|
||||
{
|
||||
std::string oldname = result->Fetch()[0].GetCppString();
|
||||
std::string oldname = result->Fetch()[0].GetString();
|
||||
std::string IP_str = GetRemoteAddress();
|
||||
sLog.outChar("Account: %d (IP: %s), Character[%s] (guid:%u) Customized to: %s", GetAccountId(), IP_str.c_str(), oldname.c_str(), GUID_LOPART(guid), newname.c_str());
|
||||
}
|
||||
|
||||
@@ -1331,13 +1331,13 @@ void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data)
|
||||
}
|
||||
|
||||
Field *fields = result->Fetch();
|
||||
std::string acc = fields[0].GetCppString();
|
||||
std::string acc = fields[0].GetString();
|
||||
if (acc.empty())
|
||||
acc = "Unknown";
|
||||
std::string email = fields[1].GetCppString();
|
||||
std::string email = fields[1].GetString();
|
||||
if (email.empty())
|
||||
email = "Unknown";
|
||||
std::string lastip = fields[2].GetCppString();
|
||||
std::string lastip = fields[2].GetString();
|
||||
if (lastip.empty())
|
||||
lastip = "Unknown";
|
||||
|
||||
|
||||
@@ -334,7 +334,7 @@ void WorldSession::SendPetitionQueryOpcode(uint64 petitionguid)
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
ownerguid = MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER);
|
||||
name = fields[1].GetCppString();
|
||||
name = fields[1].GetString();
|
||||
signs = fields[2].GetUInt8();
|
||||
type = fields[3].GetUInt32();
|
||||
}
|
||||
@@ -725,7 +725,7 @@ void WorldSession::HandleTurnInPetitionOpcode(WorldPacket & recv_data)
|
||||
{
|
||||
Field *fields = result->Fetch();
|
||||
ownerguidlo = fields[0].GetUInt32();
|
||||
name = fields[1].GetCppString();
|
||||
name = fields[1].GetString();
|
||||
type = fields[2].GetUInt32();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -89,7 +89,7 @@ void WorldSession::SendNameQueryOpcodeFromDBCallBack(QueryResult result)
|
||||
|
||||
Field *fields = result->Fetch();
|
||||
uint32 guid = fields[0].GetUInt32();
|
||||
std::string name = fields[1].GetCppString();
|
||||
std::string name = fields[1].GetString();
|
||||
uint8 pRace = 0, pGender = 0, pClass = 0;
|
||||
if (name == "")
|
||||
name = GetTrinityString(LANG_NON_EXIST_CHARACTER);
|
||||
@@ -110,11 +110,11 @@ void WorldSession::SendNameQueryOpcodeFromDBCallBack(QueryResult result)
|
||||
data << uint8(pClass); // class
|
||||
|
||||
// if the first declined name field (5) is empty, the rest must be too
|
||||
if (sWorld.getBoolConfig(CONFIG_DECLINED_NAMES_USED) && fields[5].GetCppString() != "")
|
||||
if (sWorld.getBoolConfig(CONFIG_DECLINED_NAMES_USED) && fields[5].GetString() != "")
|
||||
{
|
||||
data << uint8(1); // is declined
|
||||
for (int i = 5; i < MAX_DECLINED_NAME_CASES+5; ++i)
|
||||
data << fields[i].GetCppString();
|
||||
data << fields[i].GetString();
|
||||
}
|
||||
else
|
||||
data << uint8(0); // is not declined
|
||||
|
||||
@@ -600,7 +600,8 @@ void WorldSession::LoadAccountData(PreparedQueryResult result, uint32 mask)
|
||||
|
||||
do
|
||||
{
|
||||
uint32 type = result->GetUInt32(0);
|
||||
Field* fields = result->Fetch();
|
||||
uint32 type = fields[0].GetUInt32();
|
||||
if (type >= NUM_ACCOUNT_DATA_TYPES)
|
||||
{
|
||||
sLog.outError("Table `%s` have invalid account data type (%u), ignore.",
|
||||
@@ -615,10 +616,11 @@ void WorldSession::LoadAccountData(PreparedQueryResult result, uint32 mask)
|
||||
continue;
|
||||
}
|
||||
|
||||
m_accountData[type].Time = result->GetUInt32(1);
|
||||
m_accountData[type].Data = result->GetString(2);
|
||||
m_accountData[type].Time = fields[1].GetUInt32();
|
||||
m_accountData[type].Data = fields[2].GetString();
|
||||
|
||||
} while (result->NextRow());
|
||||
}
|
||||
while (result->NextRow());
|
||||
}
|
||||
|
||||
void WorldSession::SetAccountData(AccountDataType type, time_t time_, std::string data)
|
||||
|
||||
@@ -851,8 +851,8 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
||||
N.SetHexStr ("894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7");
|
||||
g.SetDword (7);
|
||||
|
||||
v.SetHexStr(fields[4].GetString());
|
||||
s.SetHexStr (fields[5].GetString());
|
||||
v.SetHexStr(fields[4].GetCString());
|
||||
s.SetHexStr (fields[5].GetCString());
|
||||
|
||||
const char* sStr = s.AsHexStr(); //Must be freed by OPENSSL_free()
|
||||
const char* vStr = v.AsHexStr(); //Must be freed by OPENSSL_free()
|
||||
@@ -867,7 +867,7 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
||||
///- Re-check ip locking (same check as in realmd).
|
||||
if (fields[3].GetUInt8() == 1) // if ip is locked
|
||||
{
|
||||
if (strcmp (fields[2].GetString(), GetRemoteAddress().c_str()))
|
||||
if (strcmp (fields[2].GetCString(), GetRemoteAddress().c_str()))
|
||||
{
|
||||
packet.Initialize (SMSG_AUTH_RESPONSE, 1);
|
||||
packet << uint8 (AUTH_FAILED);
|
||||
@@ -884,7 +884,7 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
||||
security = SEC_ADMINISTRATOR;
|
||||
*/
|
||||
|
||||
K.SetHexStr (fields[1].GetString());
|
||||
K.SetHexStr (fields[1].GetCString());
|
||||
|
||||
time_t mutetime = time_t (fields[7].GetUInt64());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user