TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PlayerDumpWriter Class Reference

#include <PlayerDump.h>

Public Member Functions

 PlayerDumpWriter ()
 
bool GetDump (ObjectGuid::LowType guid, std::string &dump)
 
DumpReturn WriteDump (std::string const &file, ObjectGuid::LowType guid)
 

Private Member Functions

bool DumpTable (std::string &dump, ObjectGuid::LowType guid, char const *tableFrom, char const *tableTo, DumpTableType type)
 
std::string GenerateWhereStr (char const *field, DumpGuidSet const &guids, DumpGuidSet::const_iterator &itr)
 
std::string GenerateWhereStr (char const *field, ObjectGuid::LowType guid)
 

Private Attributes

DumpGuidSet pets
 
DumpGuidSet mails
 
DumpGuidSet items
 

Additional Inherited Members

- Public Types inherited from PlayerDump
typedef std::set
< ObjectGuid::LowType
DumpGuidSet
 
typedef std::map
< ObjectGuid::LowType,
ObjectGuid::LowType
DumpGuidMap
 
- Protected Member Functions inherited from PlayerDump
 PlayerDump ()
 

Constructor & Destructor Documentation

PlayerDumpWriter::PlayerDumpWriter ( )
inline
81 { }

Member Function Documentation

bool PlayerDumpWriter::DumpTable ( std::string &  dump,
ObjectGuid::LowType  guid,
char const tableFrom,
char const tableTo,
DumpTableType  type 
)
private
270 {
271  DumpGuidSet const* guids = nullptr;
272  char const* fieldname = nullptr;
273 
274  switch (type)
275  {
276  case DTT_CURRENCY: fieldname = "CharacterGuid"; break;
277  case DTT_ITEM: fieldname = "guid"; guids = &items; break;
278  case DTT_ITEM_GIFT: fieldname = "item_guid"; guids = &items; break;
279  case DTT_PET: fieldname = "owner"; break;
280  case DTT_PET_TABLE: fieldname = "guid"; guids = &pets; break;
281  case DTT_MAIL: fieldname = "receiver"; break;
282  case DTT_MAIL_ITEM: fieldname = "mail_id"; guids = &mails; break;
283  default: fieldname = "guid"; break;
284  }
285 
286  // for guid set stop if set is empty
287  if (guids && guids->empty())
288  return true; // nothing to do
289 
290  // setup for guids case start position
291  DumpGuidSet::const_iterator guidsItr;
292  if (guids)
293  guidsItr = guids->begin();
294 
295  do
296  {
297  std::string wherestr;
298 
299  if (guids) // set case, get next guids string
300  wherestr = GenerateWhereStr(fieldname, *guids, guidsItr);
301  else // not set case, get single guid string
302  wherestr = GenerateWhereStr(fieldname, guid);
303 
304  QueryResult result = CharacterDatabase.PQuery("SELECT * FROM %s WHERE %s", tableFrom, wherestr.c_str());
305  if (!result)
306  return true;
307 
308  do
309  {
310  // collect guids
311  switch (type)
312  {
313  case DTT_INVENTORY:
314  StoreGUID(result, 3, items); // item guid collection (character_inventory.item)
315  break;
316  case DTT_PET:
317  StoreGUID(result, 0, pets); // pet petnumber collection (character_pet.id)
318  break;
319  case DTT_MAIL:
320  StoreGUID(result, 0, mails); // mail id collection (mail.id)
321  break;
322  case DTT_MAIL_ITEM:
323  StoreGUID(result, 1, items); // item guid collection (mail_items.item_guid)
324  break;
325  case DTT_CHARACTER:
326  {
327  if (result->GetFieldCount() <= 64) // avoid crashes on next check
328  {
329  TC_LOG_FATAL("misc", "PlayerDumpWriter::DumpTable - Trying to access non-existing or wrong positioned field (`deleteInfos_Account`) in `characters` table.");
330  return false;
331  }
332 
333  if (result->Fetch()[64].GetUInt32()) // characters.deleteInfos_Account - if filled error
334  return false;
335  break;
336  }
337  default:
338  break;
339  }
340 
341  dump += CreateDumpString(tableTo, result);
342  dump += "\n";
343  }
344  while (result->NextRow());
345  }
346  while (guids && guidsItr != guids->end()); // not set case iterate single time, set case iterate for all guids
347  return true;
348 }
Definition: PlayerDump.h:49
QueryResult PQuery(Format &&sql, T *conn, Args &&...args)
Definition: DatabaseWorkerPool.h:165
DumpGuidSet items
Definition: PlayerDump.h:94
DumpGuidSet pets
Definition: PlayerDump.h:92
Definition: PlayerDump.h:37
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
Definition: PlayerDump.h:46
void StoreGUID(QueryResult result, uint32 field, PlayerDump::DumpGuidSet &guids)
Definition: PlayerDump.cpp:251
Definition: PlayerDump.h:29
#define TC_LOG_FATAL(filterType__,...)
Definition: Log.h:210
Definition: PlayerDump.h:55
DumpGuidSet mails
Definition: PlayerDump.h:93
Definition: PlayerDump.h:52
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
std::string CreateDumpString(char const *tableName, QueryResult result)
Definition: PlayerDump.cpp:204
Definition: PlayerDump.h:54
std::set< ObjectGuid::LowType > DumpGuidSet
Definition: PlayerDump.h:71
std::string GenerateWhereStr(char const *field, DumpGuidSet const &guids, DumpGuidSet::const_iterator &itr)
Definition: PlayerDump.cpp:232
Definition: PlayerDump.h:41
Definition: PlayerDump.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string PlayerDumpWriter::GenerateWhereStr ( char const field,
DumpGuidSet const guids,
DumpGuidSet::const_iterator &  itr 
)
private
233 {
234  std::ostringstream wherestr;
235  wherestr << field << " IN ('";
236  for (; itr != guids.end();)
237  {
238  wherestr << *itr;
239  ++itr;
240 
241  if (wherestr.str().size() > MAX_QUERY_LEN - 50) // near to max query
242  break;
243 
244  if (itr != guids.end())
245  wherestr << "', '";
246  }
247  wherestr << "')";
248  return wherestr.str();
249 }
#define MAX_QUERY_LEN
Definition: Common.h:166

+ Here is the caller graph for this function:

std::string PlayerDumpWriter::GenerateWhereStr ( char const field,
ObjectGuid::LowType  guid 
)
private
226 {
227  std::ostringstream wherestr;
228  wherestr << field << " = '" << guid << '\'';
229  return wherestr.str();
230 }
bool PlayerDumpWriter::GetDump ( ObjectGuid::LowType  guid,
std::string &  dump 
)
Todo:
Add instance/group..
Todo:
Add a dump level option to skip some non-important tables
351 {
352  dump = "IMPORTANT NOTE: THIS DUMPFILE IS MADE FOR USE WITH THE 'PDUMP' COMMAND ONLY - EITHER THROUGH INGAME CHAT OR ON CONSOLE!\n";
353  dump += "IMPORTANT NOTE: DO NOT apply it directly - it will irreversibly DAMAGE and CORRUPT your database! You have been warned!\n\n";
354 
355  for (uint8 i = 0; i < DUMP_TABLE_COUNT; ++i)
356  if (!DumpTable(dump, guid, dumpTables[i].name, dumpTables[i].name, dumpTables[i].type))
357  return false;
358 
361 
362  return true;
363 }
#define DUMP_TABLE_COUNT
Definition: PlayerDump.cpp:28
bool DumpTable(std::string &dump, ObjectGuid::LowType guid, char const *tableFrom, char const *tableTo, DumpTableType type)
Definition: PlayerDump.cpp:269
static DumpTable dumpTables[DUMP_TABLE_COUNT]
Definition: PlayerDump.cpp:35
uint8_t uint8
Definition: Define.h:152

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DumpReturn PlayerDumpWriter::WriteDump ( std::string const file,
ObjectGuid::LowType  guid 
)
366 {
367  if (sWorld->getBoolConfig(CONFIG_PDUMP_NO_PATHS))
368  if (strstr(file.c_str(), "\\") || strstr(file.c_str(), "/"))
369  return DUMP_FILE_OPEN_ERROR;
370 
371  if (sWorld->getBoolConfig(CONFIG_PDUMP_NO_OVERWRITE))
372  if (FILE* f = fopen(file.c_str(), "r"))
373  {
374  fclose(f);
375  return DUMP_FILE_OPEN_ERROR;
376  }
377 
378  FILE* fout = fopen(file.c_str(), "w");
379  if (!fout)
380  return DUMP_FILE_OPEN_ERROR;
381 
382  DumpReturn ret = DUMP_SUCCESS;
383  std::string dump;
384  if (!GetDump(guid, dump))
386 
387  fprintf(fout, "%s\n", dump.c_str());
388  fclose(fout);
389  return ret;
390 }
DumpReturn
Definition: PlayerDump.h:58
Definition: World.h:162
FMT_API int fprintf(std::FILE *f, CStringRef format, ArgList args)
#define sWorld
Definition: World.h:887
Definition: PlayerDump.h:61
Definition: PlayerDump.h:60
Definition: World.h:161
bool GetDump(ObjectGuid::LowType guid, std::string &dump)
Definition: PlayerDump.cpp:350
Definition: PlayerDump.h:65

+ Here is the call graph for this function:

Member Data Documentation

DumpGuidSet PlayerDumpWriter::items
private
DumpGuidSet PlayerDumpWriter::mails
private
DumpGuidSet PlayerDumpWriter::pets
private

The documentation for this class was generated from the following files: