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)
109{
110 return sAchievementCriteriaStore.LookupEntry(criteria);
111}
DBCStorage< AchievementCriteriaEntry > sAchievementCriteriaStore(AchievementCriteriafmt)

References sAchievementCriteriaStore.

Referenced by CleanCharacterAchievementProgress().

◆ CheckUnique()

void CharacterDatabaseCleaner::CheckUnique ( const char *  column,
const char *  table,
bool(*)(uint32 check 
)
71{
72 QueryResult result = CharacterDatabase.Query("SELECT DISTINCT {} FROM {}", column, table);
73 if (!result)
74 {
75 LOG_INFO("sql.sql", "Table {} is empty.", table);
76 return;
77 }
78
79 bool found = false;
80 std::ostringstream ss;
81 do
82 {
83 Field* fields = result->Fetch();
84
85 uint32 id = fields[0].Get<uint32>();
86
87 if (!check(id))
88 {
89 if (!found)
90 {
91 ss << "DELETE FROM " << table << " WHERE " << column << " IN (";
92 found = true;
93 }
94 else
95 ss << ',';
96
97 ss << id;
98 }
99 } while (result->NextRow());
100
101 if (found)
102 {
103 ss << ')';
104 CharacterDatabase.Execute(ss.str().c_str());
105 }
106}
#define LOG_INFO(filterType__,...)
Definition: Log.h:165
std::uint32_t uint32
Definition: Define.h:107
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:27
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
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 ( )
114{
115 CheckUnique("criteria", "character_achievement_progress", &AchievementProgressCheck);
116}
void CheckUnique(const char *column, const char *table, bool(*check)(uint32))
Definition: CharacterDatabaseCleaner.cpp:70

References AchievementProgressCheck(), and CheckUnique().

Referenced by CleanDatabase().

◆ CleanCharacterQuestStatus()

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

References CharacterDatabase.

Referenced by CleanDatabase().

◆ CleanCharacterSkills()

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

References CheckUnique(), and SkillCheck().

Referenced by CleanDatabase().

◆ CleanCharacterSpell()

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

References CheckUnique(), and SpellCheck().

Referenced by CleanDatabase().

◆ CleanCharacterTalent()

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

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

Referenced by CleanDatabase().

◆ CleanDatabase()

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

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 WS_CLEANING_FLAGS.

Referenced by World::SetInitialWorldSettings().

◆ SkillCheck()

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

References sSkillLineStore.

Referenced by CleanCharacterSkills().

◆ SpellCheck()

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

References GetTalentSpellPos(), and sSpellMgr.

Referenced by CleanCharacterSpell().

◆ TalentCheck()

bool CharacterDatabaseCleaner::TalentCheck ( uint32  talent_id)
139{
140 TalentEntry const* talentInfo = sTalentStore.LookupEntry(talent_id);
141 if (!talentInfo)
142 return false;
143
144 return sTalentTabStore.LookupEntry(talentInfo->TalentTab);
145}
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().