diff options
Diffstat (limited to 'src/game/PlayerDump.cpp')
-rw-r--r-- | src/game/PlayerDump.cpp | 103 |
1 files changed, 76 insertions, 27 deletions
diff --git a/src/game/PlayerDump.cpp b/src/game/PlayerDump.cpp index b061b63a06a..73939115211 100644 --- a/src/game/PlayerDump.cpp +++ b/src/game/PlayerDump.cpp @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,7 +26,7 @@ #include "ObjectMgr.h" // Character Dump tables -#define DUMP_TABLE_COUNT 18 +#define DUMP_TABLE_COUNT 20 struct DumpTable { @@ -36,24 +36,27 @@ struct DumpTable static DumpTable dumpTables[DUMP_TABLE_COUNT] = { - { "characters", DTT_CHARACTER }, - { "character_queststatus", DTT_CHAR_TABLE }, - { "character_reputation", DTT_CHAR_TABLE }, - { "character_spell", DTT_CHAR_TABLE }, - { "character_spell_cooldown", DTT_CHAR_TABLE }, - { "character_action", DTT_CHAR_TABLE }, - { "character_aura", DTT_CHAR_TABLE }, - { "character_homebind", DTT_CHAR_TABLE }, - { "character_inventory", DTT_INVENTORY }, - { "mail", DTT_MAIL }, - { "mail_items", DTT_MAIL_ITEM }, - { "item_instance", DTT_ITEM }, - { "character_gifts", DTT_ITEM_GIFT }, - { "item_text", DTT_ITEM_TEXT }, - { "character_pet", DTT_PET }, - { "pet_aura", DTT_PET_TABLE }, - { "pet_spell", DTT_PET_TABLE }, - { "pet_spell_cooldown", DTT_PET_TABLE }, + { "characters", DTT_CHARACTER }, + { "character_achievement", DTT_CHAR_TABLE }, + { "character_achievement_progress", DTT_CHAR_TABLE }, + { "character_queststatus", DTT_CHAR_TABLE }, + { "character_reputation", DTT_CHAR_TABLE }, + { "character_spell", DTT_CHAR_TABLE }, + { "character_spell_cooldown", DTT_CHAR_TABLE }, + { "character_action", DTT_CHAR_TABLE }, + { "character_aura", DTT_CHAR_TABLE }, + { "character_homebind", DTT_CHAR_TABLE }, +// { "character_ticket", DTT_CHAR_TABLE }, + { "character_inventory", DTT_INVENTORY }, + { "mail", DTT_MAIL }, + { "mail_items", DTT_MAIL_ITEM }, + { "item_instance", DTT_ITEM }, + { "character_gifts", DTT_ITEM_GIFT }, + { "item_text", DTT_ITEM_TEXT }, + { "character_pet", DTT_PET }, + { "pet_aura", DTT_PET_TABLE }, + { "pet_spell", DTT_PET_TABLE }, + { "pet_spell_cooldown", DTT_PET_TABLE }, }; // Low level functions @@ -90,7 +93,7 @@ bool findnth(std::string &str, int n, std::string::size_type &s, std::string::si if (e == std::string::npos) return false; } while(str[e-1] == '\\'); - for(int i = 1; i < n; i++) + for(int i = 1; i < n; ++i) { do { @@ -154,7 +157,7 @@ bool changetoknth(std::string &str, int n, const char *with, bool insert = false uint32 registerNewGuid(uint32 oldGuid, std::map<uint32, uint32> &guidMap, uint32 hiGuid) { - std::map<uint32, uint32>::iterator itr = guidMap.find(oldGuid); + std::map<uint32, uint32>::const_iterator itr = guidMap.find(oldGuid); if(itr != guidMap.end()) return itr->second; @@ -195,7 +198,7 @@ std::string CreateDumpString(char const* tableName, QueryResult *result) std::ostringstream ss; ss << "INSERT INTO "<< _TABLE_SIM_ << tableName << _TABLE_SIM_ << " VALUES ("; Field *fields = result->Fetch(); - for(uint32 i = 0; i < result->GetFieldCount(); i++) + for(uint32 i = 0; i < result->GetFieldCount(); ++i) { if (i == 0) ss << "'"; else ss << ", '"; @@ -329,7 +332,39 @@ void PlayerDumpWriter::DumpTable(std::string& dump, uint32 guid, char const*tabl std::string PlayerDumpWriter::GetDump(uint32 guid) { std::string dump; - for(int i = 0; i < DUMP_TABLE_COUNT; i++) + + 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 + QueryNamedResult* result = CharacterDatabase.QueryNamed("SELECT * FROM character_db_version LIMIT 1"); + if(result) + { + QueryFieldNames const& namesMap = result->GetFieldNames(); + std::string reqName; + for(QueryFieldNames::const_iterator itr = namesMap.begin(); itr != namesMap.end(); ++itr) + { + if(itr->substr(0,9)=="required_") + { + reqName = *itr; + 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."); + + delete result; + } + 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); // TODO: Add instance/group.. @@ -436,9 +471,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()) @@ -449,7 +498,7 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s DumpTableType type; uint8 i; - for(i = 0; i < DUMP_TABLE_COUNT; i++) + for(i = 0; i < DUMP_TABLE_COUNT; ++i) { if (tn == dumpTables[i].name) { |