diff options
| author | Machiavelli <none@none> | 2010-09-24 22:16:21 +0200 |
|---|---|---|
| committer | Machiavelli <none@none> | 2010-09-24 22:16:21 +0200 |
| commit | 3c6dc320308880bde4ef9eddd695db28a74aa0d9 (patch) | |
| tree | f209e6c487e436fc1cd978487dddf3604ce2b594 /src/server/game/Server | |
| parent | b46b498141cc167163c6112e8e2bfa32fec2d7dc (diff) | |
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
Diffstat (limited to 'src/server/game/Server')
6 files changed, 24 insertions, 21 deletions
diff --git a/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp b/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp index c62e8d6a833..c9831f926d9 100644 --- a/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp @@ -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()); } diff --git a/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp b/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp index 0ed2a90b25c..935fe523621 100644 --- a/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp @@ -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"; diff --git a/src/server/game/Server/Protocol/Handlers/PetitionsHandler.cpp b/src/server/game/Server/Protocol/Handlers/PetitionsHandler.cpp index 482ea587d8d..4b57d6d2292 100644 --- a/src/server/game/Server/Protocol/Handlers/PetitionsHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/PetitionsHandler.cpp @@ -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 diff --git a/src/server/game/Server/Protocol/Handlers/QueryHandler.cpp b/src/server/game/Server/Protocol/Handlers/QueryHandler.cpp index f8e9342b49d..85aa0e55e64 100644 --- a/src/server/game/Server/Protocol/Handlers/QueryHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/QueryHandler.cpp @@ -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 diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index 1f278fd63fd..cdd8470854d 100644 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -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) diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp index 90a969bc99d..e43ab13d2c0 100644 --- a/src/server/game/Server/WorldSocket.cpp +++ b/src/server/game/Server/WorldSocket.cpp @@ -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()); |
