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

#include "PlayerDump.h"

Inheritance diagram for PlayerDump:
PlayerDumpReader PlayerDumpWriter

Static Public Member Functions

static void InitializeTables ()
 

Protected Member Functions

 PlayerDump ()
 

Detailed Description

Constructor & Destructor Documentation

◆ PlayerDump()

PlayerDump::PlayerDump ( )
inlineprotected
71{ }

Member Function Documentation

◆ InitializeTables()

void PlayerDump::InitializeTables ( )
static
254{
255 uint32 oldMSTime = getMSTime();
256
257 for (DumpTable const& dumpTable : DumpTables)
258 {
259 TableStruct t;
260 t.TableName = dumpTable.Name;
261
262 QueryResult result = CharacterDatabase.Query("DESC {}", dumpTable.Name);
263 // prepared statement is correct (checked at startup) so table must exist
264 ASSERT(result);
265
266 int32 i = 0;
267 do
268 {
269 std::string columnName = (*result)[0].Get<std::string>();
270 t.FieldIndices.emplace(columnName, i++);
271
272 TableField f;
273 f.FieldName = columnName;
274
275 bool toUpperResult = Utf8ToUpperOnlyLatin(columnName);
276 ASSERT(toUpperResult);
277
278 t.TableFields.emplace_back(std::move(f));
279 } while (result->NextRow());
280
281 switch (dumpTable.Type)
282 {
283 case DTT_CHARACTER:
284 MarkWhereField(t, "guid");
285
288
289 MarkDependentColumn(t, "deleteInfos_Account", GUID_TYPE_NULL);
290 MarkDependentColumn(t, "deleteInfos_Name", GUID_TYPE_NULL);
291 MarkDependentColumn(t, "deleteDate", GUID_TYPE_NULL);
292 break;
293 case DTT_CHAR_TABLE:
294 MarkWhereField(t, "guid");
295
297 break;
298 case DTT_EQSET_TABLE:
299 MarkWhereField(t, "guid");
300
303
304 // item0 - item18
305 for (uint32 j = 0; j < EQUIPMENT_SLOT_END; ++j)
306 {
307 std::string itColumn = Acore::StringFormat("item{}", j);
309 }
310 break;
311 case DTT_INVENTORY:
312 MarkWhereField(t, "guid");
313
317 break;
318 case DTT_MAIL:
319 MarkWhereField(t, "receiver");
320
322 MarkDependentColumn(t, "receiver", GUID_TYPE_CHAR);
323 break;
324 case DTT_MAIL_ITEM:
325 MarkWhereField(t, "mail_id");
326
327 MarkDependentColumn(t, "mail_id", GUID_TYPE_MAIL);
328 MarkDependentColumn(t, "item_guid", GUID_TYPE_ITEM);
329 MarkDependentColumn(t, "receiver", GUID_TYPE_CHAR);
330 break;
331 case DTT_ITEM:
332 MarkWhereField(t, "guid");
333
335 MarkDependentColumn(t, "owner_guid", GUID_TYPE_CHAR);
336 break;
337 case DTT_ITEM_GIFT:
338 MarkWhereField(t, "item_guid");
339
341 MarkDependentColumn(t, "item_guid", GUID_TYPE_ITEM);
342 break;
343 case DTT_PET:
344 MarkWhereField(t, "owner");
345
348 break;
349 case DTT_PET_TABLE:
350 MarkWhereField(t, "guid");
351
353 break;
354 default:
355 LOG_FATAL("server.loading", "Wrong dump table type {}, probably added a new table type without updating code", uint32(dumpTable.Type));
356 ABORT();
357 return;
358 }
359
360 CharacterTables.emplace_back(std::move(t));
361 }
362
363 // perform some sanity checks
364 for (TableStruct const& tableStruct : CharacterTables)
365 {
366 if (tableStruct.WhereFieldName.empty())
367 {
368 LOG_FATAL("server.loading", "Table `{}` defined in player dump doesn't have a WHERE query field", tableStruct.TableName);
369 ABORT();
370 }
371 }
372
373 for (BaseTable const& baseTable : BaseTables)
374 AssertBaseTable(baseTable);
375
377
378 LOG_INFO("server.loading", ">> Initialized Tables For PlayerDump in {} ms.", GetMSTimeDiffToNow(oldMSTime));
379 LOG_INFO("server.loading", " ");
380}
#define ABORT
Definition: Errors.h:76
#define ASSERT
Definition: Errors.h:68
#define LOG_FATAL(filterType__,...)
Definition: Log.h:153
#define LOG_INFO(filterType__,...)
Definition: Log.h:165
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:131
uint32 getMSTime()
Definition: Timer.h:103
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:532
std::int32_t int32
Definition: Define.h:103
std::uint32_t uint32
Definition: Define.h:107
@ EQUIPMENT_SLOT_END
Definition: Player.h:699
void MarkDependentColumn(TableStruct &tableStruct, std::string const &columnName, GuidType dependentType)
Definition: PlayerDump.cpp:198
void AssertBaseTable(BaseTable const &baseTable)
Definition: PlayerDump.cpp:237
uint32 const DUMP_TABLE_COUNT
Definition: PlayerDump.cpp:123
@ GUID_TYPE_NULL
Definition: PlayerDump.cpp:45
@ GUID_TYPE_MAIL
Definition: PlayerDump.cpp:38
@ GUID_TYPE_PET
Definition: PlayerDump.cpp:37
@ GUID_TYPE_EQUIPMENT_SET
Definition: PlayerDump.cpp:42
@ GUID_TYPE_CHAR
Definition: PlayerDump.cpp:36
@ GUID_TYPE_ITEM
Definition: PlayerDump.cpp:39
@ GUID_TYPE_ACCOUNT
Definition: PlayerDump.cpp:35
DumpTable const DumpTables[]
Definition: PlayerDump.cpp:88
BaseTable const BaseTables[]
Definition: PlayerDump.cpp:73
void MarkWhereField(TableStruct &tableStruct, std::string const &whereField)
Definition: PlayerDump.cpp:221
std::vector< TableStruct > CharacterTables
Definition: PlayerDump.cpp:166
@ DTT_EQSET_TABLE
Definition: PlayerDump.h:33
@ DTT_INVENTORY
Definition: PlayerDump.h:35
@ DTT_CHAR_TABLE
Definition: PlayerDump.h:28
@ DTT_PET_TABLE
Definition: PlayerDump.h:49
@ DTT_MAIL
Definition: PlayerDump.h:37
@ DTT_MAIL_ITEM
Definition: PlayerDump.h:40
@ DTT_PET
Definition: PlayerDump.h:48
@ DTT_ITEM
Definition: PlayerDump.h:43
@ DTT_ITEM_GIFT
Definition: PlayerDump.h:46
@ DTT_CHARACTER
Definition: PlayerDump.h:26
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:27
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default AC string format function.
Definition: StringFormat.h:34
Definition: PlayerDump.cpp:65
Definition: PlayerDump.cpp:83
Definition: PlayerDump.cpp:149
std::string FieldName
Definition: PlayerDump.cpp:150
Definition: PlayerDump.cpp:157
std::unordered_map< std::string, int32 > FieldIndices
Definition: PlayerDump.cpp:163
std::string TableName
Definition: PlayerDump.cpp:158
std::vector< TableField > TableFields
Definition: PlayerDump.cpp:160

References ABORT, ASSERT, AssertBaseTable(), BaseTables, CharacterDatabase, CharacterTables, DTT_CHAR_TABLE, DTT_CHARACTER, DTT_EQSET_TABLE, DTT_INVENTORY, DTT_ITEM, DTT_ITEM_GIFT, DTT_MAIL, DTT_MAIL_ITEM, DTT_PET, DTT_PET_TABLE, DUMP_TABLE_COUNT, DumpTables, EQUIPMENT_SLOT_END, TableStruct::FieldIndices, TableField::FieldName, getMSTime(), GetMSTimeDiffToNow(), GUID_TYPE_ACCOUNT, GUID_TYPE_CHAR, GUID_TYPE_EQUIPMENT_SET, GUID_TYPE_ITEM, GUID_TYPE_MAIL, GUID_TYPE_NULL, GUID_TYPE_PET, LOG_FATAL, LOG_INFO, MarkDependentColumn(), MarkWhereField(), Acore::StringFormat(), TableStruct::TableFields, TableStruct::TableName, and Utf8ToUpperOnlyLatin().

Referenced by World::SetInitialWorldSettings().