TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CharacterDatabaseCleaner Namespace Reference

Enumerations

enum  CleaningFlags {
  CLEANING_FLAG_ACHIEVEMENT_PROGRESS = 0x1, CLEANING_FLAG_SKILLS = 0x2, CLEANING_FLAG_SPELLS = 0x4, CLEANING_FLAG_TALENTS = 0x8,
  CLEANING_FLAG_QUESTSTATUS = 0x10
}
 

Functions

TC_GAME_API void CleanDatabase ()
 
TC_GAME_API void CheckUnique (const char *column, const char *table, bool(*check)(uint32))
 
TC_GAME_API bool AchievementProgressCheck (uint32 criteria)
 
TC_GAME_API bool SkillCheck (uint32 skill)
 
TC_GAME_API bool SpellCheck (uint32 spell_id)
 
TC_GAME_API bool TalentCheck (uint32 talent_id)
 
TC_GAME_API void CleanCharacterAchievementProgress ()
 
TC_GAME_API void CleanCharacterSkills ()
 
TC_GAME_API void CleanCharacterSpell ()
 
TC_GAME_API void CleanCharacterTalent ()
 
TC_GAME_API void CleanCharacterQuestStatus ()
 

Enumeration Type Documentation

Enumerator
CLEANING_FLAG_ACHIEVEMENT_PROGRESS 
CLEANING_FLAG_SKILLS 
CLEANING_FLAG_SPELLS 
CLEANING_FLAG_TALENTS 
CLEANING_FLAG_QUESTSTATUS 
25  {
31  };
Definition: CharacterDatabaseCleaner.h:30
Definition: CharacterDatabaseCleaner.h:28
Definition: CharacterDatabaseCleaner.h:27
Definition: CharacterDatabaseCleaner.h:26
Definition: CharacterDatabaseCleaner.h:29

Function Documentation

bool CharacterDatabaseCleaner::AchievementProgressCheck ( uint32  criteria)
111 {
112  return sAchievementMgr->GetAchievementCriteria(criteria) != nullptr;
113 }
#define sAchievementMgr
Definition: AchievementMgr.h:501

+ Here is the caller graph for this function:

void CharacterDatabaseCleaner::CheckUnique ( const char *  column,
const char *  table,
bool(*)(uint32 check 
)
72 {
73  QueryResult result = CharacterDatabase.PQuery("SELECT DISTINCT %s FROM %s", column, table);
74  if (!result)
75  {
76  TC_LOG_INFO("misc", "Table %s is empty.", table);
77  return;
78  }
79 
80  bool found = false;
81  std::ostringstream ss;
82  do
83  {
84  Field* fields = result->Fetch();
85 
86  uint32 id = fields[0].GetUInt32();
87 
88  if (!check(id))
89  {
90  if (!found)
91  {
92  ss << "DELETE FROM " << table << " WHERE " << column << " IN (";
93  found = true;
94  }
95  else
96  ss << ',';
97 
98  ss << id;
99  }
100  }
101  while (result->NextRow());
102 
103  if (found)
104  {
105  ss << ')';
106  CharacterDatabase.Execute(ss.str().c_str());
107  }
108 }
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
QueryResult PQuery(Format &&sql, T *conn, Args &&...args)
Definition: DatabaseWorkerPool.h:165
Class used to access individual fields of database query result.
Definition: Field.h:56
uint32_t uint32
Definition: Define.h:150
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
uint32 GetUInt32() const
Definition: Field.h:146
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
T check(T value)
Definition: format.h:305

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CharacterDatabaseCleaner::CleanCharacterAchievementProgress ( )
116 {
117  CheckUnique("criteria", "character_achievement_progress", &AchievementProgressCheck);
118 }
TC_GAME_API void CheckUnique(const char *column, const char *table, bool(*check)(uint32))
Definition: CharacterDatabaseCleaner.cpp:71
TC_GAME_API bool AchievementProgressCheck(uint32 criteria)
Definition: CharacterDatabaseCleaner.cpp:110

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CharacterDatabaseCleaner::CleanCharacterQuestStatus ( )
157 {
158  CharacterDatabase.DirectExecute("DELETE FROM character_queststatus WHERE status = 0");
159 }
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
void DirectExecute(const char *sql)
Definition: DatabaseWorkerPool.h:121

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CharacterDatabaseCleaner::CleanCharacterSkills ( )
126 {
127  CheckUnique("skill", "character_skills", &SkillCheck);
128 }
TC_GAME_API bool SkillCheck(uint32 skill)
Definition: CharacterDatabaseCleaner.cpp:120
TC_GAME_API void CheckUnique(const char *column, const char *table, bool(*check)(uint32))
Definition: CharacterDatabaseCleaner.cpp:71

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CharacterDatabaseCleaner::CleanCharacterSpell ( )
137 {
138  CheckUnique("spell", "character_spell", &SpellCheck);
139 }
TC_GAME_API void CheckUnique(const char *column, const char *table, bool(*check)(uint32))
Definition: CharacterDatabaseCleaner.cpp:71
TC_GAME_API bool SpellCheck(uint32 spell_id)
Definition: CharacterDatabaseCleaner.cpp:130

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CharacterDatabaseCleaner::CleanCharacterTalent ( )
151 {
152  CharacterDatabase.DirectPExecute("DELETE FROM character_talent WHERE spec > %u", MAX_TALENT_GROUPS);
153  CheckUnique("spell", "character_talent", &TalentCheck);
154 }
#define MAX_TALENT_GROUPS
Definition: SharedDefines.h:853
void DirectPExecute(Format &&sql, Args &&...args)
Definition: DatabaseWorkerPool.h:134
TC_GAME_API void CheckUnique(const char *column, const char *table, bool(*check)(uint32))
Definition: CharacterDatabaseCleaner.cpp:71
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
TC_GAME_API bool TalentCheck(uint32 talent_id)
Definition: CharacterDatabaseCleaner.cpp:141

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CharacterDatabaseCleaner::CleanDatabase ( )
29 {
30  // config to disable
31  if (!sWorld->getBoolConfig(CONFIG_CLEAN_CHARACTER_DB))
32  return;
33 
34  TC_LOG_INFO("misc", "Cleaning character database...");
35 
36  uint32 oldMSTime = getMSTime();
37 
38  // check flags which clean ups are necessary
39  QueryResult result = CharacterDatabase.PQuery("SELECT value FROM worldstates WHERE entry = %d", WS_CLEANING_FLAGS);
40  if (!result)
41  return;
42 
43  uint32 flags = (*result)[0].GetUInt32();
44 
45  // clean up
48 
49  if (flags & CLEANING_FLAG_SKILLS)
51 
52  if (flags & CLEANING_FLAG_SPELLS)
54 
55  if (flags & CLEANING_FLAG_TALENTS)
57 
58  if (flags & CLEANING_FLAG_QUESTSTATUS)
60 
61  // NOTE: In order to have persistentFlags be set in worldstates for the next cleanup,
62  // you need to define them at least once in worldstates.
63  flags &= sWorld->getIntConfig(CONFIG_PERSISTENT_CHARACTER_CLEAN_FLAGS);
64  CharacterDatabase.DirectPExecute("UPDATE worldstates SET value = %u WHERE entry = %d", flags, WS_CLEANING_FLAGS);
65 
66  sWorld->SetCleaningFlags(flags);
67 
68  TC_LOG_INFO("server.loading", ">> Cleaned character database in %u ms", GetMSTimeDiffToNow(oldMSTime));
69 }
TC_GAME_API void CleanCharacterQuestStatus()
Definition: CharacterDatabaseCleaner.cpp:156
QueryResult PQuery(Format &&sql, T *conn, Args &&...args)
Definition: DatabaseWorkerPool.h:165
Definition: CharacterDatabaseCleaner.h:30
uint32 getMSTime()
Definition: Timer.h:24
#define sWorld
Definition: World.h:887
TC_GAME_API void CleanCharacterTalent()
Definition: CharacterDatabaseCleaner.cpp:150
Definition: CharacterDatabaseCleaner.h:28
TC_GAME_API void CleanCharacterAchievementProgress()
Definition: CharacterDatabaseCleaner.cpp:115
void DirectPExecute(Format &&sql, Args &&...args)
Definition: DatabaseWorkerPool.h:134
TC_GAME_API void CleanCharacterSkills()
Definition: CharacterDatabaseCleaner.cpp:125
Definition: World.h:103
uint32_t uint32
Definition: Define.h:150
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
TC_GAME_API void CleanCharacterSpell()
Definition: CharacterDatabaseCleaner.cpp:136
Definition: CharacterDatabaseCleaner.h:27
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:42
Definition: World.h:497
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
uint8 flags
Definition: DisableMgr.cpp:44
Definition: CharacterDatabaseCleaner.h:26
Definition: CharacterDatabaseCleaner.h:29

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool CharacterDatabaseCleaner::SkillCheck ( uint32  skill)
121 {
122  return sSkillLineStore.LookupEntry(skill) != nullptr;
123 }
DBCStorage< SkillLineEntry > sSkillLineStore(SkillLinefmt)

+ Here is the caller graph for this function:

bool CharacterDatabaseCleaner::SpellCheck ( uint32  spell_id)
131 {
132  SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spell_id);
133  return spellInfo && !spellInfo->HasAttribute(SPELL_ATTR0_CU_IS_TALENT);
134 }
Definition: SpellInfo.h:326
bool HasAttribute(SpellAttr0 attribute) const
Definition: SpellInfo.h:462
#define sSpellMgr
Definition: SpellMgr.h:756
Definition: SpellInfo.h:189

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool CharacterDatabaseCleaner::TalentCheck ( uint32  talent_id)
142 {
143  TalentEntry const* talentInfo = sTalentStore.LookupEntry(talent_id);
144  if (!talentInfo)
145  return false;
146 
147  return sChrSpecializationStore.LookupEntry(talentInfo->SpecID) != nullptr;
148 }
uint32 SpecID
Definition: DBCStructure.h:1258
DBCStorage< TalentEntry > sTalentStore(Talentfmt)
DBCStorage< ChrSpecializationEntry > sChrSpecializationStore(ChrSpecializationfmt)
Definition: DBCStructure.h:1255

+ Here is the caller graph for this function: