AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
PlayerDumpWriter Class Reference

#include "PlayerDump.h"

Inheritance diagram for PlayerDumpWriter:
PlayerDump

Public Member Functions

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

Private Member Functions

bool AppendTable (StringTransaction &trans, ObjectGuid::LowType guid, TableStruct const &tableStruct, DumpTable const &dumpTable)
 
void PopulateGuids (ObjectGuid::LowType guid)
 

Private Attributes

std::set< ObjectGuid::LowType_pets
 
std::set< ObjectGuid::LowType_mails
 
std::set< ObjectGuid::LowType_items
 
std::set< uint64_itemSets
 

Additional Inherited Members

- Static Public Member Functions inherited from PlayerDump
static void InitializeTables ()
 
- Protected Member Functions inherited from PlayerDump
 PlayerDump ()
 

Detailed Description

Constructor & Destructor Documentation

◆ PlayerDumpWriter()

PlayerDumpWriter::PlayerDumpWriter ( )
inline
80{ }

Member Function Documentation

◆ AppendTable()

bool PlayerDumpWriter::AppendTable ( StringTransaction trans,
ObjectGuid::LowType  guid,
TableStruct const &  tableStruct,
DumpTable const &  dumpTable 
)
private
640{
641 std::string whereStr;
642 switch (dumpTable.Type)
643 {
644 case DTT_ITEM:
645 case DTT_ITEM_GIFT:
646 if (_items.empty())
647 return true;
648
649 whereStr = GenerateWhereStr(tableStruct.WhereFieldName, _items);
650 break;
651 case DTT_PET_TABLE:
652 if (_pets.empty())
653 return true;
654
655 whereStr = GenerateWhereStr(tableStruct.WhereFieldName, _pets);
656 break;
657 case DTT_MAIL_ITEM:
658 if (_mails.empty())
659 return true;
660
661 whereStr = GenerateWhereStr(tableStruct.WhereFieldName, _mails);
662 break;
663 case DTT_EQSET_TABLE:
664 if (_itemSets.empty())
665 return true;
666
667 whereStr = GenerateWhereStr(tableStruct.WhereFieldName, _itemSets);
668 break;
669 default:
670 // not set case, get single guid string
671 whereStr = GenerateWhereStr(tableStruct.WhereFieldName, guid);
672 break;
673 }
674
675 QueryResult result = CharacterDatabase.Query("SELECT * FROM {} WHERE {}", dumpTable.Name, whereStr);
676 switch (dumpTable.Type)
677 {
678 case DTT_CHARACTER:
679 if (result)
680 {
681 // characters.deleteInfos_Account - if filled error
682 int32 index = GetColumnIndexByName(tableStruct, "deleteInfos_Account");
683 ASSERT(index != -1); // checked at startup
684
685 if ((*result)[index].Get<uint32>())
686 return false;
687 }
688 break;
689 default:
690 break;
691 }
692
693 AppendTableDump(trans, tableStruct, result);
694 return true;
695}
std::int32_t int32
Definition: Define.h:103
#define ASSERT
Definition: Errors.h:68
@ DTT_EQSET_TABLE
Definition: PlayerDump.h:36
@ DTT_PET_TABLE
Definition: PlayerDump.h:52
@ DTT_MAIL_ITEM
Definition: PlayerDump.h:43
@ DTT_ITEM
Definition: PlayerDump.h:46
@ DTT_ITEM_GIFT
Definition: PlayerDump.h:49
@ DTT_CHARACTER
Definition: PlayerDump.h:29
void AppendTableDump(StringTransaction &trans, TableStruct const &tableStruct, QueryResult result)
Definition: PlayerDump.cpp:518
int32 GetColumnIndexByName(TableStruct const &tableStruct, std::string const &columnName)
Definition: PlayerDump.cpp:189
std::string GenerateWhereStr(std::string const &field, ObjectGuid::LowType guid)
Definition: PlayerDump.cpp:564
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:28
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
std::set< ObjectGuid::LowType > _mails
Definition: PlayerDump.h:91
std::set< ObjectGuid::LowType > _pets
Definition: PlayerDump.h:90
std::set< uint64 > _itemSets
Definition: PlayerDump.h:94
std::set< ObjectGuid::LowType > _items
Definition: PlayerDump.h:92

References _items, _itemSets, _mails, _pets, AppendTableDump(), ASSERT, CharacterDatabase, DTT_CHARACTER, DTT_EQSET_TABLE, DTT_ITEM, DTT_ITEM_GIFT, DTT_MAIL_ITEM, DTT_PET_TABLE, GenerateWhereStr(), GetColumnIndexByName(), DumpTable::Name, DumpTable::Type, and TableStruct::WhereFieldName.

Referenced by GetDump().

◆ GetDump()

bool PlayerDumpWriter::GetDump ( ObjectGuid::LowType  guid,
std::string &  dump 
)
Todo:
Add instance/group..
Todo:
Todo:
Add a dump level option to skip some non-important tables
698{
699 dump = "IMPORTANT NOTE: THIS DUMPFILE IS MADE FOR USE WITH THE 'PDUMP' COMMAND ONLY - EITHER THROUGH INGAME CHAT OR ON CONSOLE!\n";
700 dump += "IMPORTANT NOTE: DO NOT apply it directly - it will irreversibly DAMAGE and CORRUPT your database! You have been warned!\n\n";
701
702 StringTransaction trans;
703
704 // collect guids
705 PopulateGuids(guid);
706 for (uint32 i = 0; i < DUMP_TABLE_COUNT; ++i)
707 if (!AppendTable(trans, guid, CharacterTables[i], DumpTables[i]))
708 return false;
709
710 dump += trans.GetBuffer();
711
714
715 return true;
716}
std::uint32_t uint32
Definition: Define.h:107
uint32 const DUMP_TABLE_COUNT
Definition: PlayerDump.cpp:123
DumpTable const DumpTables[]
Definition: PlayerDump.cpp:88
std::vector< TableStruct > CharacterTables
Definition: PlayerDump.cpp:166
Definition: PlayerDump.cpp:127
char const * GetBuffer() const
Definition: PlayerDump.cpp:138
bool AppendTable(StringTransaction &trans, ObjectGuid::LowType guid, TableStruct const &tableStruct, DumpTable const &dumpTable)
Definition: PlayerDump.cpp:639
void PopulateGuids(ObjectGuid::LowType guid)
Definition: PlayerDump.cpp:592

References AppendTable(), CharacterTables, DUMP_TABLE_COUNT, DumpTables, StringTransaction::GetBuffer(), and PopulateGuids().

Referenced by WriteDumpToFile(), and WriteDumpToString().

◆ PopulateGuids()

void PlayerDumpWriter::PopulateGuids ( ObjectGuid::LowType  guid)
private
593{
594 for (BaseTable const& baseTable : BaseTables)
595 {
596 switch (baseTable.StoredType)
597 {
598 case GUID_TYPE_ITEM:
599 case GUID_TYPE_MAIL:
600 case GUID_TYPE_PET:
602 break;
603 default:
604 return;
605 }
606
607 std::string whereStr = GenerateWhereStr(baseTable.PlayerGuid, guid);
608 QueryResult result = CharacterDatabase.Query("SELECT {} FROM {} WHERE {}", baseTable.PrimaryKey, baseTable.TableName, whereStr);
609 if (!result)
610 continue;
611
612 do
613 {
614 switch (baseTable.StoredType)
615 {
616 case GUID_TYPE_ITEM:
617 if (ObjectGuid::LowType itemLowGuid = (*result)[0].Get<uint32>())
618 _items.insert(itemLowGuid);
619 break;
620 case GUID_TYPE_MAIL:
621 if (ObjectGuid::LowType mailLowGuid = (*result)[0].Get<uint32>())
622 _mails.insert(mailLowGuid);
623 break;
624 case GUID_TYPE_PET:
625 if (ObjectGuid::LowType petLowGuid = (*result)[0].Get<uint32>())
626 _pets.insert(petLowGuid);
627 break;
629 if (uint64 eqSetId = (*result)[0].Get<uint64>())
630 _itemSets.insert(eqSetId);
631 break;
632 default:
633 break;
634 }
635 } while (result->NextRow());
636 }
637}
std::uint64_t uint64
Definition: Define.h:106
@ GUID_TYPE_MAIL
Definition: PlayerDump.cpp:38
@ GUID_TYPE_PET
Definition: PlayerDump.cpp:37
@ GUID_TYPE_EQUIPMENT_SET
Definition: PlayerDump.cpp:42
@ GUID_TYPE_ITEM
Definition: PlayerDump.cpp:39
BaseTable const BaseTables[]
Definition: PlayerDump.cpp:73
uint32 LowType
Definition: ObjectGuid.h:122
Definition: PlayerDump.cpp:65

References _items, _itemSets, _mails, _pets, BaseTables, CharacterDatabase, GenerateWhereStr(), GUID_TYPE_EQUIPMENT_SET, GUID_TYPE_ITEM, GUID_TYPE_MAIL, and GUID_TYPE_PET.

Referenced by GetDump().

◆ WriteDumpToFile()

DumpReturn PlayerDumpWriter::WriteDumpToFile ( std::string const &  file,
ObjectGuid::LowType  guid 
)
719{
720 if (sWorld->getBoolConfig(CONFIG_PDUMP_NO_PATHS))
721 if (strchr(file.c_str(), '\\') || strchr(file.c_str(), '/'))
723
724 if (sWorld->getBoolConfig(CONFIG_PDUMP_NO_OVERWRITE))
725 {
726 // check if file exists already
727 if (GetFileHandle(file.c_str(), "r"))
729 }
730
731 FileHandle fout = GetFileHandle(file.c_str(), "w");
732 if (!fout)
734
736 std::string dump;
737 if (!GetDump(guid, dump))
739
740 fprintf(fout.get(), "%s", dump.c_str());
741 return ret;
742}
DumpReturn
Definition: PlayerDump.h:56
@ DUMP_FILE_OPEN_ERROR
Definition: PlayerDump.h:58
@ DUMP_CHARACTER_DELETED
Definition: PlayerDump.h:61
@ DUMP_SUCCESS
Definition: PlayerDump.h:57
FileHandle GetFileHandle(char const *path, char const *mode)
Definition: PlayerDump.cpp:59
std::unique_ptr< FILE, FileCloser > FileHandle
Definition: PlayerDump.cpp:57
@ CONFIG_PDUMP_NO_OVERWRITE
Definition: IWorld.h:146
@ CONFIG_PDUMP_NO_PATHS
Definition: IWorld.h:145
#define sWorld
Definition: World.h:444
bool GetDump(ObjectGuid::LowType guid, std::string &dump)
Definition: PlayerDump.cpp:697

References CONFIG_PDUMP_NO_OVERWRITE, CONFIG_PDUMP_NO_PATHS, DUMP_CHARACTER_DELETED, DUMP_FILE_OPEN_ERROR, DUMP_SUCCESS, GetDump(), GetFileHandle(), and sWorld.

◆ WriteDumpToString()

DumpReturn PlayerDumpWriter::WriteDumpToString ( std::string &  dump,
ObjectGuid::LowType  guid 
)
745{
747 if (!GetDump(guid, dump))
749 return ret;
750}

References DUMP_CHARACTER_DELETED, DUMP_SUCCESS, and GetDump().

Member Data Documentation

◆ _items

std::set<ObjectGuid::LowType> PlayerDumpWriter::_items
private

Referenced by AppendTable(), and PopulateGuids().

◆ _itemSets

std::set<uint64> PlayerDumpWriter::_itemSets
private

Referenced by AppendTable(), and PopulateGuids().

◆ _mails

std::set<ObjectGuid::LowType> PlayerDumpWriter::_mails
private

Referenced by AppendTable(), and PopulateGuids().

◆ _pets

std::set<ObjectGuid::LowType> PlayerDumpWriter::_pets
private

Referenced by AppendTable(), and PopulateGuids().