Files
TCPlayerbotCore/src/server/game/Tools/PlayerDump.cpp
T

623 lines
21 KiB
C++
Raw Normal View History

2008-10-02 16:23:55 -05:00
/*
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
2008-10-14 11:57:03 -05:00
*
2010-01-16 20:19:18 +03:00
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
2008-10-02 16:23:55 -05:00
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2008-10-02 16:23:55 -05:00
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2008-10-02 16:23:55 -05:00
*/
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#include "Common.h"
#include "PlayerDump.h"
#include "DatabaseEnv.h"
#include "SQLStorage.h"
2008-10-02 16:23:55 -05:00
#include "UpdateFields.h"
#include "ObjectMgr.h"
#include "AccountMgr.h"
2009-10-17 15:51:44 -07:00
#define DUMP_TABLE_COUNT 26
2008-10-02 16:23:55 -05:00
struct DumpTable
{
char const* name;
DumpTableType type;
};
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
static DumpTable dumpTables[DUMP_TABLE_COUNT] =
{
{ "characters", DTT_CHARACTER },
{ "character_account_data", DTT_CHAR_TABLE },
{ "character_achievement", DTT_CHAR_TABLE },
{ "character_achievement_progress", DTT_CHAR_TABLE },
{ "character_action", DTT_CHAR_TABLE },
{ "character_aura", DTT_CHAR_TABLE },
{ "character_declinedname", DTT_CHAR_TABLE },
{ "character_equipmentsets", DTT_EQSET_TABLE},
{ "character_gifts", DTT_ITEM_GIFT },
{ "character_glyphs", DTT_CHAR_TABLE },
{ "character_homebind", DTT_CHAR_TABLE },
{ "character_inventory", DTT_INVENTORY },
{ "character_pet", DTT_PET },
{ "character_pet_declinedname", DTT_PET },
{ "character_queststatus", DTT_CHAR_TABLE },
{ "character_reputation", DTT_CHAR_TABLE },
{ "character_skills", DTT_CHAR_TABLE },
{ "character_spell", DTT_CHAR_TABLE },
{ "character_spell_cooldown", DTT_CHAR_TABLE },
{ "character_talent", DTT_CHAR_TABLE },
{ "item_instance", DTT_ITEM },
{ "mail", DTT_MAIL },
{ "mail_items", DTT_MAIL_ITEM },
{ "pet_aura", DTT_PET_TABLE },
{ "pet_spell", DTT_PET_TABLE },
{ "pet_spell_cooldown", DTT_PET_TABLE },
2008-10-02 16:23:55 -05:00
};
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// Low level functions
static bool findtoknth(std::string &str, int n, std::string::size_type &s, std::string::size_type &e)
{
int i; s = e = 0;
std::string::size_type size = str.size();
2010-04-07 19:14:10 +02:00
for (i = 1; s < size && i < n; s++) if (str[s] == ' ') ++i;
2008-10-02 16:23:55 -05:00
if (i < n)
return false;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
e = str.find(' ', s);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
return e != std::string::npos;
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
std::string gettoknth(std::string &str, int n)
{
std::string::size_type s = 0, e = 0;
2010-04-07 19:14:10 +02:00
if (!findtoknth(str, n, s, e))
2008-10-02 16:23:55 -05:00
return "";
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
return str.substr(s, e-s);
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
bool findnth(std::string &str, int n, std::string::size_type &s, std::string::size_type &e)
{
s = str.find("VALUES ('")+9;
if (s == std::string::npos) return false;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
do
{
e = str.find("'",s);
if (e == std::string::npos) return false;
2010-04-07 19:13:19 +02:00
} while (str[e-1] == '\\');
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for (int i = 1; i < n; ++i)
2008-10-02 16:23:55 -05:00
{
do
{
s = e+4;
e = str.find("'",s);
if (e == std::string::npos) return false;
} while (str[e-1] == '\\');
}
return true;
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
std::string gettablename(std::string &str)
{
std::string::size_type s = 13;
std::string::size_type e = str.find(_TABLE_SIM_, s);
if (e == std::string::npos)
return "";
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
return str.substr(s, e-s);
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
bool changenth(std::string &str, int n, const char *with, bool insert = false, bool nonzero = false)
{
std::string::size_type s, e;
2010-04-07 19:14:10 +02:00
if (!findnth(str,n,s,e))
2008-10-02 16:23:55 -05:00
return false;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (nonzero && str.substr(s,e-s) == "0")
2008-10-02 16:23:55 -05:00
return true; // not an error
2010-04-07 19:14:10 +02:00
if (!insert)
2008-10-02 16:23:55 -05:00
str.replace(s,e-s, with);
else
str.insert(s, with);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
return true;
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
std::string getnth(std::string &str, int n)
{
std::string::size_type s, e;
2010-04-07 19:14:10 +02:00
if (!findnth(str,n,s,e))
2008-10-02 16:23:55 -05:00
return "";
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
return str.substr(s, e-s);
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
bool changetoknth(std::string &str, int n, const char *with, bool insert = false, bool nonzero = false)
{
std::string::size_type s = 0, e = 0;
2010-04-07 19:14:10 +02:00
if (!findtoknth(str, n, s, e))
2008-10-02 16:23:55 -05:00
return false;
2010-04-07 19:14:10 +02:00
if (nonzero && str.substr(s,e-s) == "0")
2008-10-02 16:23:55 -05:00
return true; // not an error
2010-04-07 19:14:10 +02:00
if (!insert)
2008-10-02 16:23:55 -05:00
str.replace(s, e-s, with);
else
str.insert(s, with);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
return true;
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
uint32 registerNewGuid(uint32 oldGuid, std::map<uint32, uint32> &guidMap, uint32 hiGuid)
{
std::map<uint32, uint32>::const_iterator itr = guidMap.find(oldGuid);
2010-04-07 19:14:10 +02:00
if (itr != guidMap.end())
2008-10-02 16:23:55 -05:00
return itr->second;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
uint32 newguid = hiGuid + guidMap.size();
guidMap[oldGuid] = newguid;
return newguid;
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
bool changeGuid(std::string &str, int n, std::map<uint32, uint32> &guidMap, uint32 hiGuid, bool nonzero = false)
{
char chritem[20];
uint32 oldGuid = atoi(getnth(str, n).c_str());
if (nonzero && oldGuid == 0)
return true; // not an error
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
uint32 newGuid = registerNewGuid(oldGuid, guidMap, hiGuid);
snprintf(chritem, 20, "%d", newGuid);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
return changenth(str, n, chritem, false, nonzero);
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
bool changetokGuid(std::string &str, int n, std::map<uint32, uint32> &guidMap, uint32 hiGuid, bool nonzero = false)
{
char chritem[20];
uint32 oldGuid = atoi(gettoknth(str, n).c_str());
if (nonzero && oldGuid == 0)
return true; // not an error
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
uint32 newGuid = registerNewGuid(oldGuid, guidMap, hiGuid);
snprintf(chritem, 20, "%d", newGuid);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
return changetoknth(str, n, chritem, false, nonzero);
}
2009-10-17 15:51:44 -07:00
std::string CreateDumpString(char const* tableName, QueryResult_AutoPtr result)
2008-10-02 16:23:55 -05:00
{
2010-04-07 19:14:10 +02:00
if (!tableName || !result) return "";
2008-10-02 16:23:55 -05:00
std::ostringstream ss;
ss << "INSERT INTO "<< _TABLE_SIM_ << tableName << _TABLE_SIM_ << " VALUES (";
Field *fields = result->Fetch();
2009-10-17 16:20:24 -07:00
for (uint32 i = 0; i < result->GetFieldCount(); ++i)
2008-10-02 16:23:55 -05:00
{
if (i == 0) ss << "'";
else ss << ", '";
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
std::string s = fields[i].GetCppString();
CharacterDatabase.escape_string(s);
ss << s;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
ss << "'";
}
ss << ");";
return ss.str();
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
std::string PlayerDumpWriter::GenerateWhereStr(char const* field, uint32 guid)
{
std::ostringstream wherestr;
wherestr << field << " = '" << guid << "'";
return wherestr.str();
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
std::string PlayerDumpWriter::GenerateWhereStr(char const* field, GUIDs const& guids, GUIDs::const_iterator& itr)
{
std::ostringstream wherestr;
wherestr << field << " IN ('";
2009-10-17 16:20:24 -07:00
for (; itr != guids.end(); ++itr)
2008-10-02 16:23:55 -05:00
{
wherestr << *itr;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (wherestr.str().size() > MAX_QUERY_LEN - 50) // near to max query
2008-10-02 16:23:55 -05:00
{
++itr;
break;
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
GUIDs::const_iterator itr2 = itr;
2010-04-07 19:14:10 +02:00
if (++itr2 != guids.end())
2008-10-02 16:23:55 -05:00
wherestr << "','";
}
wherestr << "')";
return wherestr.str();
}
2009-10-17 15:51:44 -07:00
void StoreGUID(QueryResult_AutoPtr result,uint32 field,std::set<uint32>& guids)
2008-10-02 16:23:55 -05:00
{
Field* fields = result->Fetch();
uint32 guid = fields[field].GetUInt32();
2010-04-07 19:14:10 +02:00
if (guid)
2008-10-02 16:23:55 -05:00
guids.insert(guid);
}
2009-10-17 15:51:44 -07:00
void StoreGUID(QueryResult_AutoPtr result,uint32 data,uint32 field, std::set<uint32>& guids)
2008-10-02 16:23:55 -05:00
{
Field* fields = result->Fetch();
std::string dataStr = fields[data].GetCppString();
uint32 guid = atoi(gettoknth(dataStr, field).c_str());
2010-04-07 19:14:10 +02:00
if (guid)
2008-10-02 16:23:55 -05:00
guids.insert(guid);
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// Writing - High-level functions
void PlayerDumpWriter::DumpTable(std::string& dump, uint32 guid, char const*tableFrom, char const*tableTo, DumpTableType type)
2008-10-02 16:23:55 -05:00
{
GUIDs const* guids = NULL;
char const* fieldname = NULL;
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
switch (type)
2008-10-02 16:23:55 -05:00
{
case DTT_ITEM: fieldname = "guid"; guids = &items; break;
case DTT_ITEM_GIFT: fieldname = "item_guid"; guids = &items; break;
case DTT_PET: fieldname = "owner"; break;
case DTT_PET_TABLE: fieldname = "guid"; guids = &pets; break;
case DTT_MAIL: fieldname = "receiver"; break;
case DTT_MAIL_ITEM: fieldname = "mail_id"; guids = &mails; break;
default: fieldname = "guid"; break;
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// for guid set stop if set is empty
2010-04-07 19:14:10 +02:00
if (guids && guids->empty())
return; // nothing to do
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// setup for guids case start position
GUIDs::const_iterator guids_itr;
2010-04-07 19:14:10 +02:00
if (guids)
2008-10-02 16:23:55 -05:00
guids_itr = guids->begin();
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
do
{
std::string wherestr;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (guids) // set case, get next guids string
2008-10-02 16:23:55 -05:00
wherestr = GenerateWhereStr(fieldname,*guids,guids_itr);
else // not set case, get single guid string
wherestr = GenerateWhereStr(fieldname,guid);
2009-10-17 15:51:44 -07:00
QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT * FROM %s WHERE %s", tableFrom, wherestr.c_str());
2010-04-07 19:14:10 +02:00
if (!result)
return;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
do
{
// collect guids
2010-04-07 22:59:46 +02:00
switch (type)
2008-10-02 16:23:55 -05:00
{
case DTT_INVENTORY:
StoreGUID(result,3,items); break; // item guid collection (character_inventory.item)
case DTT_PET:
StoreGUID(result,0,pets); break; // pet petnumber collection (character_pet.id)
case DTT_MAIL:
StoreGUID(result,0,mails); // mail id collection (mail.id)
case DTT_MAIL_ITEM:
StoreGUID(result,1,items); break; // item guid collection (mail_items.item_guid)
default: break;
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
dump += CreateDumpString(tableTo, result);
dump += "\n";
}
while (result->NextRow());
}
2010-04-07 19:13:19 +02:00
while (guids && guids_itr != guids->end()); // not set case iterate single time, set case iterate for all guids
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
std::string PlayerDumpWriter::GetDump(uint32 guid)
{
std::string dump;
2009-10-17 15:51:44 -07:00
dump += "IMPORTANT NOTE: THIS DUMPFILE IS MADE FOR USE WITH THE 'PDUMP' COMMAND ONLY - EITHER THROUGH INGAME CHAT OR ON CONSOLE!\n";
dump += "IMPORTANT NOTE: DO NOT apply it directly - it will irreversibly DAMAGE and CORRUPT your database! You have been warned!\n\n";
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for (int i = 0; i < DUMP_TABLE_COUNT; ++i)
2008-10-02 16:23:55 -05:00
DumpTable(dump, guid, dumpTables[i].name, dumpTables[i].name, dumpTables[i].type);
2009-10-17 15:51:44 -07:00
// TODO: Add instance/group..
2008-10-02 16:23:55 -05:00
// TODO: Add a dump level option to skip some non-important tables
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
return dump;
}
2009-10-17 15:51:44 -07:00
2008-12-12 11:21:28 -06:00
DumpReturn PlayerDumpWriter::WriteDump(const std::string& file, uint32 guid)
2008-10-02 16:23:55 -05:00
{
FILE *fout = fopen(file.c_str(), "w");
if (!fout)
return DUMP_FILE_OPEN_ERROR;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
std::string dump = GetDump(guid);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
fprintf(fout,"%s\n",dump.c_str());
fclose(fout);
return DUMP_SUCCESS;
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// Reading - High-level functions
#define ROLLBACK(DR) {CharacterDatabase.RollbackTransaction(); fclose(fin); return (DR);}
2009-10-17 15:51:44 -07:00
2008-12-12 11:21:28 -06:00
DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, std::string name, uint32 guid)
2008-10-02 16:23:55 -05:00
{
uint32 charcount = accmgr.GetCharactersCount(account);
if (charcount >= 10)
return DUMP_TOO_MANY_CHARS;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
FILE *fin = fopen(file.c_str(), "r");
if (!fin)
return DUMP_FILE_OPEN_ERROR;
2009-10-17 15:51:44 -07:00
QueryResult_AutoPtr result = QueryResult_AutoPtr(NULL);
2008-10-02 16:23:55 -05:00
char newguid[20], chraccount[20], newpetid[20], currpetid[20], lastpetid[20];
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// make sure the same guid doesn't already exist and is safe to use
bool incHighest = true;
if (guid != 0 && guid < objmgr.m_hiCharGuid)
2008-10-02 16:23:55 -05:00
{
result = CharacterDatabase.PQuery("SELECT 1 FROM characters WHERE guid = '%d'", guid);
2008-10-02 16:23:55 -05:00
if (result)
guid = objmgr.m_hiCharGuid; // use first free if exists
else incHighest = false;
}
else
guid = objmgr.m_hiCharGuid;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// normalize the name if specified and check if it exists
if (!normalizePlayerName(name))
2008-10-02 16:23:55 -05:00
name = "";
2009-10-17 15:51:44 -07:00
if (ObjectMgr::CheckPlayerName(name,true) == CHAR_NAME_SUCCESS)
2008-10-02 16:23:55 -05:00
{
CharacterDatabase.escape_string(name); // for safe, we use name only for sql quearies anyway
result = CharacterDatabase.PQuery("SELECT 1 FROM characters WHERE name = '%s'", name.c_str());
2008-10-02 16:23:55 -05:00
if (result)
name = ""; // use the one from the dump
}
else
name = "";
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// name encoded or empty
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
snprintf(newguid, 20, "%d", guid);
snprintf(chraccount, 20, "%d", account);
snprintf(newpetid, 20, "%d", objmgr.GeneratePetNumber());
snprintf(lastpetid, 20, "%s", "");
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
std::map<uint32,uint32> items;
std::map<uint32,uint32> mails;
char buf[32000] = "";
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
typedef std::map<uint32, uint32> PetIds; // old->new petid relation
typedef PetIds::value_type PetIdsPair;
PetIds petids;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
CharacterDatabase.BeginTransaction();
2010-04-07 19:13:19 +02:00
while (!feof(fin))
2008-10-02 16:23:55 -05:00
{
2010-04-07 19:14:10 +02:00
if (!fgets(buf, 32000, fin))
2008-10-02 16:23:55 -05:00
{
2010-04-07 19:14:10 +02:00
if (feof(fin)) break;
ROLLBACK(DUMP_FILE_BROKEN);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
std::string line; line.assign(buf);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// skip empty strings
size_t nw_pos = line.find_first_not_of(" \t\n\r\7");
2010-04-07 23:25:02 +02:00
if (nw_pos == std::string::npos)
2008-10-02 16:23:55 -05:00
continue;
2009-10-17 15:51:44 -07:00
// skip logfile-side dump start notice, the important notes and dump end notices
if ((line.substr(nw_pos,16) == "== START DUMP ==") ||
(line.substr(nw_pos,15) == "IMPORTANT NOTE:") ||
(line.substr(nw_pos,14) == "== END DUMP =="))
continue;
2009-10-17 15:51:44 -07:00
// add required_ check
/*
2010-04-07 23:25:02 +02:00
if (line.substr(nw_pos,41) == "UPDATE character_db_version SET required_")
{
2010-04-07 19:14:10 +02:00
if (!CharacterDatabase.Execute(line.c_str()))
ROLLBACK(DUMP_FILE_BROKEN);
2009-10-17 15:51:44 -07:00
continue;
}
*/
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// determine table name and load type
std::string tn = gettablename(line);
2010-04-07 19:14:10 +02:00
if (tn.empty())
2008-10-02 16:23:55 -05:00
{
sLog.outError("LoadPlayerDump: Can't extract table name from line: '%s'!", line.c_str());
ROLLBACK(DUMP_FILE_BROKEN);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
DumpTableType type;
uint8 i;
2009-10-17 16:20:24 -07:00
for (i = 0; i < DUMP_TABLE_COUNT; ++i)
2008-10-02 16:23:55 -05:00
{
if (tn == dumpTables[i].name)
{
type = dumpTables[i].type;
break;
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if (i == DUMP_TABLE_COUNT)
{
sLog.outError("LoadPlayerDump: Unknown table: '%s'!", tn.c_str());
ROLLBACK(DUMP_FILE_BROKEN);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// change the data to server values
switch(type)
{
case DTT_CHAR_TABLE:
if (!changenth(line, 1, newguid)) // character_*.guid update
ROLLBACK(DUMP_FILE_BROKEN);
2008-10-02 16:23:55 -05:00
break;
2009-10-17 15:51:44 -07:00
case DTT_CHARACTER:
2008-10-02 16:23:55 -05:00
{
if (!changenth(line, 1, newguid)) // characters.guid update
ROLLBACK(DUMP_FILE_BROKEN);
2009-10-17 15:51:44 -07:00
if (!changenth(line, 2, chraccount)) // characters.account update
ROLLBACK(DUMP_FILE_BROKEN);
2008-10-02 16:23:55 -05:00
if (name == "")
{
// check if the original name already exists
name = getnth(line, 3);
2008-10-02 16:23:55 -05:00
CharacterDatabase.escape_string(name);
2009-10-17 15:51:44 -07:00
result = CharacterDatabase.PQuery("SELECT 1 FROM characters WHERE name = '%s'", name.c_str());
2008-10-02 16:23:55 -05:00
if (result)
{
if (!changenth(line, 36, "1")) // characters.at_login set to "rename on login"
ROLLBACK(DUMP_FILE_BROKEN);
2008-10-02 16:23:55 -05:00
}
}
else if (!changenth(line, 3, name.c_str())) // characters.name
ROLLBACK(DUMP_FILE_BROKEN);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
break;
}
case DTT_INVENTORY:
2008-10-02 16:23:55 -05:00
{
if (!changenth(line, 1, newguid)) // character_inventory.guid update
ROLLBACK(DUMP_FILE_BROKEN);
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (!changeGuid(line, 2, items, objmgr.m_hiItemGuid, true))
ROLLBACK(DUMP_FILE_BROKEN); // character_inventory.bag update
2010-04-07 19:14:10 +02:00
if (!changeGuid(line, 4, items, objmgr.m_hiItemGuid))
ROLLBACK(DUMP_FILE_BROKEN); // character_inventory.item update
2008-10-02 16:23:55 -05:00
break;
}
case DTT_ITEM:
2008-10-02 16:23:55 -05:00
{
// item, owner, data field:item, owner guid
2010-04-07 19:14:10 +02:00
if (!changeGuid(line, 1, items, objmgr.m_hiItemGuid))
ROLLBACK(DUMP_FILE_BROKEN); // item_instance.guid update
if (!changenth(line, 2, newguid)) // item_instance.owner_guid update
ROLLBACK(DUMP_FILE_BROKEN);
std::string vals = getnth(line,3); // item_instance.data get
2010-04-07 19:14:10 +02:00
if (!changetokGuid(vals, OBJECT_FIELD_GUID+1, items, objmgr.m_hiItemGuid))
ROLLBACK(DUMP_FILE_BROKEN); // item_instance.data.OBJECT_FIELD_GUID update
2010-04-07 19:14:10 +02:00
if (!changetoknth(vals, ITEM_FIELD_OWNER+1, newguid))
ROLLBACK(DUMP_FILE_BROKEN); // item_instance.data.ITEM_FIELD_OWNER update
if (!changenth(line, 3, vals.c_str())) // item_instance.data update
ROLLBACK(DUMP_FILE_BROKEN);
2008-10-02 16:23:55 -05:00
break;
}
case DTT_ITEM_GIFT:
2008-10-02 16:23:55 -05:00
{
if (!changenth(line, 1, newguid)) // character_gifts.guid update
ROLLBACK(DUMP_FILE_BROKEN);
2010-04-07 19:14:10 +02:00
if (!changeGuid(line, 2, items, objmgr.m_hiItemGuid))
ROLLBACK(DUMP_FILE_BROKEN); // character_gifts.item_guid update
2008-10-02 16:23:55 -05:00
break;
}
case DTT_PET:
2008-10-02 16:23:55 -05:00
{
//store a map of old pet id to new inserted pet id for use by type 5 tables
snprintf(currpetid, 20, "%s", getnth(line, 1).c_str());
2010-04-07 23:25:02 +02:00
if (strlen(lastpetid) == 0) snprintf(lastpetid, 20, "%s", currpetid);
2010-04-08 08:20:08 +02:00
if (strcmp(lastpetid,currpetid) != 0)
2008-10-02 16:23:55 -05:00
{
snprintf(newpetid, 20, "%d", objmgr.GeneratePetNumber());
snprintf(lastpetid, 20, "%s", currpetid);
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
std::map<uint32, uint32> :: const_iterator petids_iter = petids.find(atoi(currpetid));
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (petids_iter == petids.end())
2008-10-02 16:23:55 -05:00
{
petids.insert(PetIdsPair(atoi(currpetid), atoi(newpetid)));
}
2009-10-17 15:51:44 -07:00
if (!changenth(line, 1, newpetid)) // character_pet.id update
ROLLBACK(DUMP_FILE_BROKEN);
if (!changenth(line, 3, newguid)) // character_pet.owner update
ROLLBACK(DUMP_FILE_BROKEN);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
break;
}
case DTT_PET_TABLE: // pet_aura, pet_spell, pet_spell_cooldown
2008-10-02 16:23:55 -05:00
{
snprintf(currpetid, 20, "%s", getnth(line, 1).c_str());
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// lookup currpetid and match to new inserted pet id
std::map<uint32, uint32> :: const_iterator petids_iter = petids.find(atoi(currpetid));
2010-04-07 19:14:10 +02:00
if (petids_iter == petids.end()) // couldn't find new inserted id
ROLLBACK(DUMP_FILE_BROKEN);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
snprintf(newpetid, 20, "%d", petids_iter->second);
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (!changenth(line, 1, newpetid))
ROLLBACK(DUMP_FILE_BROKEN);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
break;
}
case DTT_MAIL: // mail
{
2010-04-07 19:14:10 +02:00
if (!changeGuid(line, 1, mails, objmgr.m_mailid))
ROLLBACK(DUMP_FILE_BROKEN); // mail.id update
if (!changenth(line, 6, newguid)) // mail.receiver update
ROLLBACK(DUMP_FILE_BROKEN);
2008-10-02 16:23:55 -05:00
break;
}
case DTT_MAIL_ITEM: // mail_items
{
2010-04-07 19:14:10 +02:00
if (!changeGuid(line, 1, mails, objmgr.m_mailid))
ROLLBACK(DUMP_FILE_BROKEN); // mail_items.id
2010-04-07 19:14:10 +02:00
if (!changeGuid(line, 2, items, objmgr.m_hiItemGuid))
ROLLBACK(DUMP_FILE_BROKEN); // mail_items.item_guid
if (!changenth(line, 4, newguid)) // mail_items.receiver
ROLLBACK(DUMP_FILE_BROKEN);
2008-10-02 16:23:55 -05:00
break;
}
default:
sLog.outError("Unknown dump table type: %u",type);
break;
}
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (!CharacterDatabase.Execute(line.c_str()))
ROLLBACK(DUMP_FILE_BROKEN);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
CharacterDatabase.CommitTransaction();
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
objmgr.m_hiItemGuid += items.size();
objmgr.m_mailid += mails.size();
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (incHighest)
2008-10-02 16:23:55 -05:00
++objmgr.m_hiCharGuid;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
fclose(fin);
2009-10-17 15:51:44 -07:00
return DUMP_SUCCESS;
2008-10-02 16:23:55 -05:00
}
2009-02-17 20:07:49 -06:00