AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
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

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

Enumeration Type Documentation

◆ CleaningFlags

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

Function Documentation

◆ AchievementProgressCheck()

bool CharacterDatabaseCleaner::AchievementProgressCheck ( uint32  criteria)
110{
111 return sAchievementCriteriaStore.LookupEntry(criteria);
112}
DBCStorage< AchievementCriteriaEntry > sAchievementCriteriaStore(AchievementCriteriafmt)

References sAchievementCriteriaStore.

Referenced by CleanCharacterAchievementProgress().

◆ CheckUnique()

void CharacterDatabaseCleaner::CheckUnique ( const char *  column,
const char *  table,
bool(*)(uint32 check 
)
72{
73 QueryResult result = CharacterDatabase.Query("SELECT DISTINCT {} FROM {}", column, table);
74 if (!result)
75 {
76 LOG_INFO("sql.sql", "Table {} 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].Get<uint32>();
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 } while (result->NextRow());
101
102 if (found)
103 {
104 ss << ')';
105 CharacterDatabase.Execute(ss.str().c_str());
106 }
107}
std::shared_ptr< ResultSet > QueryResult
Definition DatabaseEnvFwd.h:27
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition DatabaseEnv.cpp:21
std::uint32_t uint32
Definition Define.h:107
#define LOG_INFO(filterType__,...)
Definition Log.h:165
Class used to access individual fields of database query result.
Definition Field.h:98
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition Field.h:112

References CharacterDatabase, Field::Get(), and LOG_INFO.

Referenced by CleanCharacterAchievementProgress(), CleanCharacterSkills(), CleanCharacterSpell(), and CleanCharacterTalent().

◆ CleanCharacterAchievementProgress()

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

References AchievementProgressCheck(), and CheckUnique().

Referenced by CleanDatabase().

◆ CleanCharacterQuestStatus()

void CharacterDatabaseCleaner::CleanCharacterQuestStatus ( )
155{
156 CharacterDatabase.DirectExecute("DELETE FROM character_queststatus WHERE status = 0");
157}

References CharacterDatabase.

Referenced by CleanDatabase().

◆ CleanCharacterSkills()

void CharacterDatabaseCleaner::CleanCharacterSkills ( )
125{
126 CheckUnique("skill", "character_skills", &SkillCheck);
127}

References CheckUnique(), and SkillCheck().

Referenced by CleanDatabase().

◆ CleanCharacterSpell()

void CharacterDatabaseCleaner::CleanCharacterSpell ( )
135{
136 CheckUnique("spell", "character_spell", &SpellCheck);
137}

References CheckUnique(), and SpellCheck().

Referenced by CleanDatabase().

◆ CleanCharacterTalent()

void CharacterDatabaseCleaner::CleanCharacterTalent ( )
149{
150 CharacterDatabase.DirectExecute("DELETE FROM character_talent WHERE specMask >= {}", 1 << MAX_TALENT_SPECS);
151 CheckUnique("spell", "character_talent", &TalentCheck);
152}
#define MAX_TALENT_SPECS
Definition SharedDefines.h:675

References CharacterDatabase, CheckUnique(), MAX_TALENT_SPECS, and TalentCheck().

Referenced by CleanDatabase().

◆ CleanDatabase()

void CharacterDatabaseCleaner::CleanDatabase ( )
28{
29 // config to disable
30 if (!sWorld->getBoolConfig(CONFIG_CLEAN_CHARACTER_DB))
31 return;
32
33 LOG_INFO("misc", "Cleaning character database...");
34
35 uint32 oldMSTime = getMSTime();
36
37 // check flags which clean ups are necessary
38 QueryResult result = CharacterDatabase.Query("SELECT value FROM worldstates WHERE entry = {}", WORLD_STATE_CUSTOM_CLEANING_FLAGS);
39 if (!result)
40 return;
41
42 uint32 flags = (*result)[0].Get<uint32>();
43
44 // clean up
45 if (flags & CLEANING_FLAG_ACHIEVEMENT_PROGRESS)
47
48 if (flags & CLEANING_FLAG_SKILLS)
50
51 if (flags & CLEANING_FLAG_SPELLS)
53
54 if (flags & CLEANING_FLAG_TALENTS)
56
57 if (flags & CLEANING_FLAG_QUESTSTATUS)
59
60 // NOTE: In order to have persistentFlags be set in worldstates for the next cleanup,
61 // you need to define them at least once in worldstates.
62 flags &= sWorld->getIntConfig(CONFIG_PERSISTENT_CHARACTER_CLEAN_FLAGS);
63 CharacterDatabase.DirectExecute("UPDATE worldstates SET value = {} WHERE entry = {}", flags, WORLD_STATE_CUSTOM_CLEANING_FLAGS);
64
65 sWorld->SetCleaningFlags(flags);
66
67 LOG_INFO("server.loading", ">> Cleaned character database in {} ms", GetMSTimeDiffToNow(oldMSTime));
68 LOG_INFO("server.loading", " ");
69}
@ CONFIG_PERSISTENT_CHARACTER_CLEAN_FLAGS
Definition IWorld.h:365
@ CONFIG_CLEAN_CHARACTER_DB
Definition IWorld.h:67
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition Timer.h:131
uint32 getMSTime()
Definition Timer.h:103
@ WORLD_STATE_CUSTOM_CLEANING_FLAGS
Definition WorldStateDefines.h:615
#define sWorld
Definition World.h:363
void CleanCharacterTalent()
Definition CharacterDatabaseCleaner.cpp:148
void CleanCharacterQuestStatus()
Definition CharacterDatabaseCleaner.cpp:154
void CleanCharacterSpell()
Definition CharacterDatabaseCleaner.cpp:134
void CleanCharacterAchievementProgress()
Definition CharacterDatabaseCleaner.cpp:114
void CleanCharacterSkills()
Definition CharacterDatabaseCleaner.cpp:124

References CharacterDatabase, CleanCharacterAchievementProgress(), CleanCharacterQuestStatus(), CleanCharacterSkills(), CleanCharacterSpell(), CleanCharacterTalent(), CLEANING_FLAG_ACHIEVEMENT_PROGRESS, CLEANING_FLAG_QUESTSTATUS, CLEANING_FLAG_SKILLS, CLEANING_FLAG_SPELLS, CLEANING_FLAG_TALENTS, CONFIG_CLEAN_CHARACTER_DB, CONFIG_PERSISTENT_CHARACTER_CLEAN_FLAGS, getMSTime(), GetMSTimeDiffToNow(), LOG_INFO, sWorld, and WORLD_STATE_CUSTOM_CLEANING_FLAGS.

Referenced by World::SetInitialWorldSettings().

◆ SkillCheck()

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

References sSkillLineStore.

Referenced by CleanCharacterSkills().

◆ SpellCheck()

bool CharacterDatabaseCleaner::SpellCheck ( uint32  spell_id)
130{
131 return sSpellMgr->GetSpellInfo(spell_id) && !GetTalentSpellPos(spell_id);
132}
TalentSpellPos const * GetTalentSpellPos(uint32 spellId)
Definition DBCStores.cpp:677
#define sSpellMgr
Definition SpellMgr.h:825

References GetTalentSpellPos(), and sSpellMgr.

Referenced by CleanCharacterSpell().

◆ TalentCheck()

bool CharacterDatabaseCleaner::TalentCheck ( uint32  talent_id)
140{
141 TalentEntry const* talentInfo = sTalentStore.LookupEntry(talent_id);
142 if (!talentInfo)
143 return false;
144
145 return sTalentTabStore.LookupEntry(talentInfo->TalentTab);
146}
DBCStorage< TalentTabEntry > sTalentTabStore(TalentTabEntryfmt)
DBCStorage< TalentEntry > sTalentStore(TalentEntryfmt)
Definition DBCStructure.h:1922
uint32 TalentTab
Definition DBCStructure.h:1924

References sTalentStore, sTalentTabStore, and TalentEntry::TalentTab.

Referenced by CleanCharacterTalent().