diff options
author | megamage <none@none> | 2009-04-19 18:22:25 -0500 |
---|---|---|
committer | megamage <none@none> | 2009-04-19 18:22:25 -0500 |
commit | 3d62e6f07d956b515f681642a67a9efbf9a013f6 (patch) | |
tree | 230c7eb531bdceafc8b77cc0698a9dce408cbcd1 | |
parent | b190b51d4f2d801e7ea1e14961d71778f497ff1e (diff) |
[7687] Batter player dumps protection from not proper use. Author: VladimirMangos
* Prevent direct apply player dumps to DB
* Check expected character DB structure (revision) before apply.
--HG--
branch : trunk
-rw-r--r-- | src/game/PlayerDump.cpp | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/src/game/PlayerDump.cpp b/src/game/PlayerDump.cpp index f8f4a0f9f8a..d29bb184b09 100644 --- a/src/game/PlayerDump.cpp +++ b/src/game/PlayerDump.cpp @@ -332,6 +332,36 @@ void PlayerDumpWriter::DumpTable(std::string& dump, uint32 guid, char const*tabl std::string PlayerDumpWriter::GetDump(uint32 guid) { std::string dump; + + dump += "IMPORTANT NOTE: This sql queries not created for apply directly, use '.pdump load' command in console or client chat instead.\n"; + dump += "IMPORTANT NOTE: NOT APPLY ITS DIRECTLY to character DB or you will DAMAGE and CORRUPT character DB\n\n"; + + // revision check guard + QueryResult* result = CharacterDatabase.Query("SELECT * FROM character_db_version LIMIT 1"); + if(result) + { + QueryResult::FieldNames const& namesMap = result->GetFieldNames(); + std::string reqName; + for(QueryResult::FieldNames::const_iterator itr = namesMap.begin(); itr != namesMap.end(); ++itr) + { + if(itr->second.substr(0,9)=="required_") + { + reqName = itr->second; + break; + } + } + + if(!reqName.empty()) + { + // this will fail at wrong character DB version + dump += "UPDATE character_db_version SET "+reqName+" = 1 WHERE FALSE;\n\n"; + } + else + sLog.outError("Table 'character_db_version' not have revision guard field, revision guard query not added to pdump."); + } + else + sLog.outError("Character DB not have 'character_db_version' table, revision guard query not added to pdump."); + for(int i = 0; i < DUMP_TABLE_COUNT; i++) DumpTable(dump, guid, dumpTables[i].name, dumpTables[i].name, dumpTables[i].type); @@ -439,9 +469,23 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s std::string line; line.assign(buf); // skip empty strings - if(line.find_first_not_of(" \t\n\r\7")==std::string::npos) + size_t nw_pos = line.find_first_not_of(" \t\n\r\7"); + if(nw_pos==std::string::npos) + continue; + + // skip NOTE + if(line.substr(nw_pos,15)=="IMPORTANT NOTE:") continue; + // add required_ check + if(line.substr(nw_pos,41)=="UPDATE character_db_version SET required_") + { + if(!CharacterDatabase.Execute(line.c_str())) + ROLLBACK(DUMP_FILE_BROKEN); + + continue; + } + // determine table name and load type std::string tn = gettablename(line); if(tn.empty()) |