Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
CharacterDatabaseCleaner.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#include "AchievementMgr.h"
8#include "Common.h"
10#include "DBCStores.h"
11#include "SpellMgr.h"
12#include "World.h"
13
15{
16 // config to disable
18 return;
19
20 SF_LOG_INFO("misc", "Cleaning character database...");
21
22 uint32 oldMSTime = getMSTime();
23
24 // check flags which clean ups are necessary
25 QueryResult result = CharacterDatabase.PQuery("SELECT value FROM worldstates WHERE entry = %d", WS_CLEANING_FLAGS);
26 if (!result)
27 return;
28
29 uint32 flags = (*result)[0].GetUInt32();
30
31 // clean up
34
35 if (flags & CLEANING_FLAG_SKILLS)
37
38 if (flags & CLEANING_FLAG_SPELLS)
40
41 if (flags & CLEANING_FLAG_TALENTS)
43
44 if (flags & CLEANING_FLAG_QUESTSTATUS)
46
47 // NOTE: In order to have persistentFlags be set in worldstates for the next cleanup,
48 // you need to define them at least once in worldstates.
50 CharacterDatabase.DirectPExecute("UPDATE worldstates SET value = %u WHERE entry = %d", flags, WS_CLEANING_FLAGS);
51
52 sWorld->SetCleaningFlags(flags);
53
54 SF_LOG_INFO("server.loading", ">> Cleaned character database in %u ms", GetMSTimeDiffToNow(oldMSTime));
55}
56
57void CharacterDatabaseCleaner::CheckUnique(const char* column, const char* table, bool (*check)(uint32))
58{
59 QueryResult result = CharacterDatabase.PQuery("SELECT DISTINCT %s FROM %s", column, table);
60 if (!result)
61 {
62 SF_LOG_INFO("misc", "Table %s is empty.", table);
63 return;
64 }
65
66 bool found = false;
67 std::ostringstream ss;
68 do
69 {
70 Field* fields = result->Fetch();
71
72 uint32 id = fields[0].GetUInt32();
73
74 if (!check(id))
75 {
76 if (!found)
77 {
78 ss << "DELETE FROM " << table << " WHERE " << column << " IN (";
79 found = true;
80 }
81 else
82 ss << ',';
83
84 ss << id;
85 }
86 } while (result->NextRow());
87
88 if (found)
89 {
90 ss << ')';
91 CharacterDatabase.Execute(ss.str().c_str());
92 }
93}
94
96{
97 return sAchievementMgr->GetAchievementCriteria(criteria);
98}
99
101{
102 CheckUnique("criteria", "character_achievement_progress", &AchievementProgressCheck);
103}
104
106{
107 return sSkillLineStore.LookupEntry(skill);
108}
109
111{
112 CheckUnique("skill", "character_skills", &SkillCheck);
113}
114
116{
117 return sSpellMgr->GetSpellInfo(spell_id) && !GetTalentSpellPos(spell_id);
118}
119
121{
122 CheckUnique("spell", "character_spell", &SpellCheck);
123}
124
126{
127 TalentEntry const* talentInfo = sTalentStore.LookupEntry(talent_id);
128 if (!talentInfo)
129 return false;
130
131 return true;
132}
133
135{
136 CharacterDatabase.DirectPExecute("DELETE FROM character_talent WHERE spec > %u", MAX_TALENT_SPECS);
137 CheckUnique("spell", "character_talent", &TalentCheck);
138}
139
141{
142 CharacterDatabase.DirectExecute("DELETE FROM character_queststatus WHERE status = 0");
143}
#define sAchievementMgr
const AuthHandler table[]
TalentSpellPos const * GetTalentSpellPos(uint32 spellId)
DBCStorage< SkillLineEntry > sSkillLineStore(SkillLinefmt)
DBCStorage< TalentEntry > sTalentStore(TalentEntryfmt)
std::uint32_t uint32
Definition Define.h:77
#define SF_LOG_INFO(filterType__,...)
Definition Log.h:137
Skyfire::AutoPtr< ResultSet, Skyfire::Mutex > QueryResult
Definition QueryResult.h:48
#define MAX_TALENT_SPECS
#define sSpellMgr
Definition SpellMgr.h:744
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition Timer.h:22
uint32 getMSTime()
Definition Timer.h:12
Definition Field.h:16
uint32 GetUInt32() const
Definition Field.h:105
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition Main.cpp:41
#define sWorld
Definition World.h:910
@ WS_CLEANING_FLAGS
Definition World.h:515
@ CONFIG_PERSISTENT_CHARACTER_CLEAN_FLAGS
Definition World.h:330
@ CONFIG_CLEAN_CHARACTER_DB
Definition World.h:93
void CheckUnique(const char *column, const char *table, bool(*check)(uint32))
bool AchievementProgressCheck(uint32 criteria)