14#define DUMP_TABLE_COUNT 29
60static bool findtoknth(std::string& str,
int n, std::string::size_type& s, std::string::size_type& e)
63 std::string::size_type size = str.size();
64 for (i = 1; s < size && i < n; s++)
if (str[s] ==
' ') ++i;
70 return e != std::string::npos;
75 std::string::size_type s = 0, e = 0;
79 return str.substr(s, e - s);
82bool findnth(std::string& str,
int n, std::string::size_type& s, std::string::size_type& e)
84 s = str.find(
"VALUES ('") + 9;
85 if (s == std::string::npos)
return false;
89 e = str.find(
'\'', s);
90 if (e == std::string::npos)
return false;
91 }
while (str[e - 1] ==
'\\');
93 for (
int i = 1; i < n; ++i)
98 e = str.find(
'\'', s);
99 if (e == std::string::npos)
return false;
100 }
while (str[e - 1] ==
'\\');
107 std::string::size_type s = 13;
108 std::string::size_type e = str.find(
_TABLE_SIM_, s);
109 if (e == std::string::npos)
112 return str.substr(s, e - s);
115bool changenth(std::string& str,
int n,
char const* with,
bool insert =
false,
bool nonzero =
false)
117 std::string::size_type s, e;
121 if (nonzero && str.substr(s, e - s) ==
"0")
124 str.replace(s, e - s, with);
131std::string
getnth(std::string& str,
int n)
133 std::string::size_type s, e;
137 return str.substr(s, e - s);
140bool changetoknth(std::string& str,
int n,
char const* with,
bool insert =
false,
bool nonzero =
false)
142 std::string::size_type s = 0, e = 0;
145 if (nonzero && str.substr(s, e - s) ==
"0")
148 str.replace(s, e - s, with);
157 std::map<uint32, uint32>::const_iterator itr = guidMap.find(oldGuid);
158 if (itr != guidMap.end())
161 uint32 newguid = hiGuid + guidMap.size();
162 guidMap[oldGuid] = newguid;
166bool changeGuid(std::string& str,
int n, std::map<uint32, uint32>& guidMap,
uint32 hiGuid,
bool nonzero =
false)
170 if (nonzero && oldGuid == 0)
174 snprintf(chritem, 20,
"%u", newGuid);
176 return changenth(str, n, chritem,
false, nonzero);
179bool changetokGuid(std::string& str,
int n, std::map<uint32, uint32>& guidMap,
uint32 hiGuid,
bool nonzero =
false)
183 if (nonzero && oldGuid == 0)
187 snprintf(chritem, 20,
"%u", newGuid);
194 if (!tableName || !result)
return "";
195 std::ostringstream ss;
197 Field* fields = result->Fetch();
198 for (
uint32 i = 0; i < result->GetFieldCount(); ++i)
200 if (i == 0) ss <<
'\'';
215 std::ostringstream wherestr;
216 wherestr << field <<
" = '" << guid <<
'\'';
217 return wherestr.str();
222 std::ostringstream wherestr;
223 wherestr << field <<
" IN ('";
224 for (; itr != guids.end(); ++itr)
234 GUIDs::const_iterator itr2 = itr;
235 if (++itr2 != guids.end())
239 return wherestr.str();
244 Field* fields = result->Fetch();
252 Field* fields = result->Fetch();
253 std::string dataStr = fields[data].
GetString();
262 GUIDs const* guids = NULL;
263 char const* fieldname = NULL;
269 case DTT_PET: fieldname =
"owner";
break;
271 fieldname =
"owner";
break;
273 case DTT_MAIL: fieldname =
"receiver";
break;
275 default: fieldname =
"guid";
break;
279 if (guids && guids->empty())
283 GUIDs::const_iterator guids_itr;
285 guids_itr = guids->begin();
289 std::string wherestr;
320 if (result->GetFieldCount() <= deleteInfosAccountIndex)
322 SF_LOG_FATAL(
"misc",
"PlayerDumpWriter::DumpTable - Trying to access non-existing or wrong positioned field (`deleteInfos_Account`) in `characters` table.");
326 if (result->Fetch()[deleteInfosAccountIndex].GetUInt32())
336 }
while (result->NextRow());
337 }
while (guids && guids_itr != guids->end());
345 dump +=
"IMPORTANT NOTE: THIS DUMPFILE IS MADE FOR USE WITH THE 'PDUMP' COMMAND ONLY - EITHER THROUGH INGAME CHAT OR ON CONSOLE!\n";
346 dump +=
"IMPORTANT NOTE: DO NOT apply it directly - it will irreversibly DAMAGE and CORRUPT your database! You have been warned!\n\n";
361 if (strstr(file.c_str(),
"\\") || strstr(file.c_str(),
"/"))
364 if (FILE* f = fopen(file.c_str(),
"r"))
369 FILE* fout = fopen(file.c_str(),
"w");
378 fprintf(fout,
"%s\n", dump.c_str());
384#define ROLLBACK(DR) {fclose(fin); return (DR);}
388 std::string nullString(
"'NULL'");
389 size_t pos = line.find(nullString);
390 while (pos != std::string::npos)
392 line.replace(pos, nullString.length(),
"NULL");
393 pos = line.find(nullString);
403 FILE* fin = fopen(file.c_str(),
"r");
407 char newguid[20], chraccount[20], newpetid[20], currpetid[20], lastpetid[20];
410 bool incHighest =
true;
411 if (guid != 0 && guid < sObjectMgr->_hiCharGuid)
419 else incHighest =
false;
442 snprintf(newguid, 20,
"%u", guid);
443 snprintf(chraccount, 20,
"%u", account);
444 snprintf(newpetid, 20,
"%u",
sObjectMgr->GeneratePetNumber());
445 snprintf(lastpetid, 20,
"%s",
"");
447 std::map<uint32, uint32> items;
448 std::map<uint32, uint32> mails;
449 char buf[32000] =
"";
451 typedef std::map<uint32, uint32> PetIds;
452 typedef PetIds::value_type PetIdsPair;
457 uint8 playerClass = 0;
463 if (!fgets(buf, 32000, fin))
470 std::string line; line.assign(buf);
473 size_t nw_pos = line.find_first_not_of(
" \t\n\r\7");
474 if (nw_pos == std::string::npos)
478 if ((line.substr(nw_pos, 16) ==
"== START DUMP ==") ||
479 (line.substr(nw_pos, 15) ==
"IMPORTANT NOTE:") ||
480 (line.substr(nw_pos, 14) ==
"== END DUMP =="))
498 SF_LOG_ERROR(
"misc",
"LoadPlayerDump: Can't extract table name from line: '%s'!", line.c_str());
515 SF_LOG_ERROR(
"misc",
"LoadPlayerDump: Unknown table: '%s'!", tn.c_str());
550 const char null[5] =
"NULL";
626 if (*lastpetid ==
'\0')
627 snprintf(lastpetid, 20,
"%s", currpetid);
628 if (strcmp(lastpetid, currpetid) != 0)
630 snprintf(newpetid, 20,
"%d",
sObjectMgr->GeneratePetNumber());
631 snprintf(lastpetid, 20,
"%s", currpetid);
634 std::map<uint32, uint32> ::const_iterator petids_iter = petids.find(atoi(currpetid));
636 if (petids_iter == petids.end())
638 petids.insert(PetIdsPair(atoi(currpetid), atoi(newpetid)));
652 std::map<uint32, uint32> ::const_iterator petids_iter = petids.find(atoi(currpetid));
653 if (petids_iter == petids.end())
656 snprintf(newpetid, 20,
"%d", petids_iter->second);
667 snprintf(currpetid, 20,
"%s",
getnth(line, 1).c_str());
670 std::map<uint32, uint32> ::const_iterator petids_iter = petids.find(atoi(currpetid));
671 if (petids_iter == petids.end())
674 snprintf(newpetid, 20,
"%d", petids_iter->second);
682 SF_LOG_ERROR(
"misc",
"Unknown dump table type: %u", type);
688 trans->Append(line.c_str());
695 sWorld->AddCharacterNameData(guid, name, gender, race, playerClass, level, realm);
#define SF_LOG_FATAL(filterType__,...)
#define SF_LOG_ERROR(filterType__,...)
bool normalizePlayerName(std::string &name)
static bool findtoknth(std::string &str, int n, std::string::size_type &s, std::string::size_type &e)
void fixNULLfields(std::string &line)
std::string CreateDumpString(char const *tableName, QueryResult result)
bool findnth(std::string &str, int n, std::string::size_type &s, std::string::size_type &e)
std::string gettablename(std::string &str)
bool changetoknth(std::string &str, int n, char const *with, bool insert=false, bool nonzero=false)
void StoreGUID(QueryResult result, uint32 field, std::set< uint32 > &guids)
static DumpTable dumpTables[DUMP_TABLE_COUNT]
uint32 registerNewGuid(uint32 oldGuid, std::map< uint32, uint32 > &guidMap, uint32 hiGuid)
std::string gettoknth(std::string &str, int n)
bool changetokGuid(std::string &str, int n, std::map< uint32, uint32 > &guidMap, uint32 hiGuid, bool nonzero=false)
bool changeGuid(std::string &str, int n, std::map< uint32, uint32 > &guidMap, uint32 hiGuid, bool nonzero=false)
bool changenth(std::string &str, int n, char const *with, bool insert=false, bool nonzero=false)
std::string getnth(std::string &str, int n)
Skyfire::AutoPtr< PreparedResultSet, Skyfire::Mutex > PreparedQueryResult
Skyfire::AutoPtr< ResultSet, Skyfire::Mutex > QueryResult
Skyfire::AutoPtr< Transaction, Skyfire::Mutex > SQLTransaction
static uint32 GetCharactersCount(uint32 accountId)
std::string GetString() const
static ResponseCodes CheckPlayerName(std::string const &name, bool create=false)
DumpReturn LoadDump(std::string const &file, uint32 account, std::string name, uint32 guid)
bool GetDump(uint32 guid, std::string &dump)
bool DumpTable(std::string &dump, uint32 guid, char const *tableFrom, char const *tableTo, DumpTableType type)
DumpReturn WriteDump(std::string const &file, uint32 guid)
std::string GenerateWhereStr(char const *field, GUIDs const &guids, GUIDs::const_iterator &itr)
void setString(const uint8 index, const std::string &value)
void setUInt32(const uint8 index, const uint32 value)
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
@ CONFIG_PDUMP_NO_OVERWRITE
uint32 const DeleteInfosAccount
uint32 const DeleteInfosName