mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 04:37:00 +00:00
[9849] Implement character database clean up.
This can be disabled by config option. Flag for clean up can be set for example on client version change. Signed-off-by: hunuza <hunuza@gmail.com>
This commit is contained in:
parent
2c6d48b912
commit
d1130af777
14 changed files with 228 additions and 4 deletions
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
DROP TABLE IF EXISTS `character_db_version`;
|
||||
CREATE TABLE `character_db_version` (
|
||||
`required_9767_03_characters_characters` bit(1) default NULL
|
||||
`required_9849_01_characters_saved_variables` bit(1) default NULL
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Last applied sql update to DB';
|
||||
|
||||
--
|
||||
|
|
@ -1567,7 +1567,8 @@ DROP TABLE IF EXISTS `saved_variables`;
|
|||
CREATE TABLE `saved_variables` (
|
||||
`NextArenaPointDistributionTime` bigint(40) UNSIGNED NOT NULL DEFAULT '0',
|
||||
`NextDailyQuestResetTime` bigint(40) unsigned NOT NULL default '0',
|
||||
`NextWeeklyQuestResetTime` bigint(40) unsigned NOT NULL default '0'
|
||||
`NextWeeklyQuestResetTime` bigint(40) unsigned NOT NULL default '0',
|
||||
`cleaning_flags` int(11) unsigned NOT NULL default '0'
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Variable Saves';
|
||||
|
||||
--
|
||||
|
|
|
|||
4
sql/updates/9849_01_characters_saved_variables.sql
Normal file
4
sql/updates/9849_01_characters_saved_variables.sql
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
ALTER TABLE character_db_version CHANGE COLUMN required_9767_03_characters_characters required_9849_01_characters_saved_variables bit;
|
||||
|
||||
ALTER TABLE saved_variables ADD cleaning_flags int(11) unsigned NOT NULL default '0' AFTER NextWeeklyQuestResetTime;
|
||||
UPDATE saved_variables SET cleaning_flags = 0xF;
|
||||
|
|
@ -56,6 +56,7 @@ pkgdata_DATA = \
|
|||
9794_02_mangos_command.sql \
|
||||
9803_01_mangos_spell_bonus_data.sql \
|
||||
9826_01_mangos_spell_script_target.sql \
|
||||
9849_01_characters_saved_variables.sql \
|
||||
README
|
||||
|
||||
## Additional files to include when running 'make dist'
|
||||
|
|
@ -92,4 +93,5 @@ EXTRA_DIST = \
|
|||
9794_02_mangos_command.sql \
|
||||
9803_01_mangos_spell_bonus_data.sql \
|
||||
9826_01_mangos_spell_script_target.sql \
|
||||
9849_01_characters_saved_variables.sql \
|
||||
README
|
||||
|
|
|
|||
139
src/game/CharacterDatabaseCleaner.cpp
Normal file
139
src/game/CharacterDatabaseCleaner.cpp
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "Common.h"
|
||||
#include "CharacterDatabaseCleaner.h"
|
||||
#include "World.h"
|
||||
#include "Database/DatabaseEnv.h"
|
||||
#include "DBCStores.h"
|
||||
#include "ProgressBar.h"
|
||||
|
||||
void CharacterDatabaseCleaner::CleanDatabase()
|
||||
{
|
||||
// config to disable
|
||||
if(!sWorld.getConfig(CONFIG_BOOL_CLEAN_CHARACTER_DB))
|
||||
return;
|
||||
|
||||
sLog.outString("Cleaning character database...");
|
||||
|
||||
// check flags which clean ups are necessary
|
||||
QueryResult* result = CharacterDatabase.PQuery("SELECT cleaning_flags FROM saved_variables");
|
||||
if(!result)
|
||||
return;
|
||||
uint32 flags = (*result)[0].GetUInt32();
|
||||
delete result;
|
||||
|
||||
// clean up
|
||||
if(flags & CLEANING_FLAG_ACHIEVEMENT_PROGRESS)
|
||||
CleanCharacterAchievementProgress();
|
||||
if(flags & CLEANING_FLAG_SKILLS)
|
||||
CleanCharacterSkills();
|
||||
if(flags & CLEANING_FLAG_SPELLS)
|
||||
CleanCharacterSpell();
|
||||
if(flags & CLEANING_FLAG_TALENTS)
|
||||
CleanCharacterTalent();
|
||||
CharacterDatabase.Execute("UPDATE saved_variables SET cleaning_flags = 0");
|
||||
}
|
||||
|
||||
void CharacterDatabaseCleaner::CheckUnique(const char* column, const char* table, bool (*check)(uint32))
|
||||
{
|
||||
QueryResult* result = CharacterDatabase.PQuery("SELECT DISTINCT %s FROM %s", column, table);
|
||||
if(!result)
|
||||
{
|
||||
sLog.outString( "Table %s is empty.", table );
|
||||
return;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
std::ostringstream ss;
|
||||
barGoLink bar( (int)result->GetRowCount() );
|
||||
do
|
||||
{
|
||||
bar.step();
|
||||
|
||||
Field *fields = result->Fetch();
|
||||
|
||||
uint32 id = fields[0].GetUInt32();
|
||||
|
||||
if(!check(id))
|
||||
{
|
||||
if(!found)
|
||||
{
|
||||
ss << "DELETE FROM " << table << " WHERE " << column << " IN (";
|
||||
found = true;
|
||||
}
|
||||
else
|
||||
ss << ",";
|
||||
ss << id;
|
||||
}
|
||||
}
|
||||
while( result->NextRow() );
|
||||
delete result;
|
||||
|
||||
if (found)
|
||||
{
|
||||
ss << ")";
|
||||
CharacterDatabase.Execute( ss.str().c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
bool CharacterDatabaseCleaner::AchievementProgressCheck(uint32 criteria)
|
||||
{
|
||||
return sAchievementCriteriaStore.LookupEntry(criteria);
|
||||
}
|
||||
|
||||
void CharacterDatabaseCleaner::CleanCharacterAchievementProgress()
|
||||
{
|
||||
CheckUnique("criteria", "character_achievement_progress", &AchievementProgressCheck);
|
||||
}
|
||||
|
||||
bool CharacterDatabaseCleaner::SkillCheck(uint32 skill)
|
||||
{
|
||||
return sSkillLineStore.LookupEntry(skill);
|
||||
}
|
||||
|
||||
void CharacterDatabaseCleaner::CleanCharacterSkills()
|
||||
{
|
||||
CheckUnique("skill", "character_skills", &SkillCheck);
|
||||
}
|
||||
|
||||
bool CharacterDatabaseCleaner::SpellCheck(uint32 spell_id)
|
||||
{
|
||||
return sSpellStore.LookupEntry(spell_id) && !GetTalentSpellPos(spell_id);
|
||||
}
|
||||
|
||||
void CharacterDatabaseCleaner::CleanCharacterSpell()
|
||||
{
|
||||
CheckUnique("spell", "character_spell", &SpellCheck);
|
||||
}
|
||||
|
||||
bool CharacterDatabaseCleaner::TalentCheck(uint32 talent_id)
|
||||
{
|
||||
TalentEntry const *talentInfo = sTalentStore.LookupEntry( talent_id );
|
||||
if(!talentInfo)
|
||||
return false;
|
||||
|
||||
return sTalentTabStore.LookupEntry( talentInfo->TalentTab );
|
||||
}
|
||||
|
||||
void CharacterDatabaseCleaner::CleanCharacterTalent()
|
||||
{
|
||||
CharacterDatabase.DirectPExecute("DELETE FROM character_talent WHERE spec > %u OR current_rank > %u", MAX_TALENT_SPEC_COUNT, MAX_TALENT_RANK);
|
||||
|
||||
CheckUnique("talent_id", "character_talent", &TalentCheck);
|
||||
}
|
||||
48
src/game/CharacterDatabaseCleaner.h
Normal file
48
src/game/CharacterDatabaseCleaner.h
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef CHARACTERDATABASECLEANER_H
|
||||
#define CHARACTERDATABASECLEANER_H
|
||||
|
||||
namespace CharacterDatabaseCleaner
|
||||
{
|
||||
enum CleaningFlags
|
||||
{
|
||||
CLEANING_FLAG_ACHIEVEMENT_PROGRESS = 0x1,
|
||||
CLEANING_FLAG_SKILLS = 0x2,
|
||||
CLEANING_FLAG_SPELLS = 0x4,
|
||||
CLEANING_FLAG_TALENTS = 0x8
|
||||
};
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -83,6 +83,8 @@ libmangosgame_a_SOURCES = \
|
|||
ChannelHandler.cpp \
|
||||
ChannelMgr.cpp \
|
||||
ChannelMgr.h \
|
||||
CharacterDatabaseCleaner.cpp \
|
||||
CharacterDatabaseCleaner.h \
|
||||
CharacterHandler.cpp \
|
||||
Chat.cpp \
|
||||
Chat.h \
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@
|
|||
#include "WaypointManager.h"
|
||||
#include "GMTicketMgr.h"
|
||||
#include "Util.h"
|
||||
#include "CharacterDatabaseCleaner.h"
|
||||
|
||||
INSTANTIATE_SINGLETON_1( World );
|
||||
|
||||
|
|
@ -516,6 +517,7 @@ void World::LoadConfigSettings(bool reload)
|
|||
///- Read other configuration items from the config file
|
||||
setConfigMinMax(CONFIG_UINT32_COMPRESSION, "Compression", 1, 1, 9);
|
||||
setConfig(CONFIG_BOOL_ADDON_CHANNEL, "AddonChannel", true);
|
||||
setConfig(CONFIG_BOOL_CLEAN_CHARACTER_DB, "CleanCharacterDB", true);
|
||||
setConfig(CONFIG_BOOL_GRID_UNLOAD, "GridUnload", true);
|
||||
setConfigPos(CONFIG_UINT32_INTERVAL_SAVE, "PlayerSave.Interval", 15 * MINUTE * IN_MILLISECONDS);
|
||||
setConfigMinMax(CONFIG_UINT32_MIN_LEVEL_STAT_SAVE, "PlayerSave.Stats.MinLevel", 0, 0, MAX_LEVEL);
|
||||
|
|
@ -1093,6 +1095,8 @@ void World::SetInitialWorldSettings()
|
|||
sLog.outString( "Loading Pet Name Parts..." );
|
||||
sObjectMgr.LoadPetNames();
|
||||
|
||||
CharacterDatabaseCleaner::CleanDatabase();
|
||||
|
||||
sLog.outString( "Loading the max pet number..." );
|
||||
sObjectMgr.LoadPetNumber();
|
||||
|
||||
|
|
|
|||
|
|
@ -311,6 +311,7 @@ enum eConfigBoolValues
|
|||
CONFIG_BOOL_ARENA_QUEUE_ANNOUNCER_EXIT,
|
||||
CONFIG_BOOL_KICK_PLAYER_ON_BAD_PACKET,
|
||||
CONFIG_BOOL_STATS_SAVE_ONLY_ON_LOGOUT,
|
||||
CONFIG_BOOL_CLEAN_CHARACTER_DB,
|
||||
CONFIG_BOOL_VALUE_COUNT
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -169,6 +169,10 @@ BindIP = "0.0.0.0"
|
|||
# Default: 1 (permit addon channel)
|
||||
# 0 (do not permit addon channel)
|
||||
#
|
||||
# CleanCharacterDB
|
||||
# Perform character db clean ups on start up
|
||||
# Default: 1 (Enable)
|
||||
# 0 (Disabled)
|
||||
#
|
||||
###################################################################################################################
|
||||
|
||||
|
|
@ -195,6 +199,7 @@ TargetPosRecalculateRange = 1.5
|
|||
UpdateUptimeInterval = 10
|
||||
MaxCoreStuckTime = 0
|
||||
AddonChannel = 1
|
||||
CleanCharacterDB = 1
|
||||
|
||||
###################################################################################################################
|
||||
# SERVER LOGGING
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "9848"
|
||||
#define REVISION_NR "9849"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#ifndef __REVISION_SQL_H__
|
||||
#define __REVISION_SQL_H__
|
||||
#define REVISION_DB_CHARACTERS "required_9767_03_characters_characters"
|
||||
#define REVISION_DB_CHARACTERS "required_9849_01_characters_saved_variables"
|
||||
#define REVISION_DB_MANGOS "required_9826_01_mangos_spell_script_target"
|
||||
#define REVISION_DB_REALMD "required_9748_01_realmd_realmlist"
|
||||
#endif // __REVISION_SQL_H__
|
||||
|
|
|
|||
|
|
@ -373,6 +373,7 @@
|
|||
<ClCompile Include="..\..\src\game\Channel.cpp" />
|
||||
<ClCompile Include="..\..\src\game\ChannelHandler.cpp" />
|
||||
<ClCompile Include="..\..\src\game\ChannelMgr.cpp" />
|
||||
<ClCompile Include="..\..\src\game\CharacterDatabaseCleaner.cpp" />
|
||||
<ClCompile Include="..\..\src\game\CharacterHandler.cpp" />
|
||||
<ClCompile Include="..\..\src\game\Chat.cpp" />
|
||||
<ClCompile Include="..\..\src\game\ChatHandler.cpp" />
|
||||
|
|
@ -519,6 +520,7 @@
|
|||
<ClInclude Include="..\..\src\game\CellImpl.h" />
|
||||
<ClInclude Include="..\..\src\game\Channel.h" />
|
||||
<ClInclude Include="..\..\src\game\ChannelMgr.h" />
|
||||
<ClInclude Include="..\..\src\game\CharacterDatabaseCleaner.h" />
|
||||
<ClInclude Include="..\..\src\game\Chat.h" />
|
||||
<ClInclude Include="..\..\src\game\ConfusedMovementGenerator.h" />
|
||||
<ClInclude Include="..\..\src\game\Corpse.h" />
|
||||
|
|
|
|||
|
|
@ -697,6 +697,14 @@
|
|||
RelativePath="..\..\src\game\ChannelMgr.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\game\CharacterDatabaseCleaner.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\game\CharacterDatabaseCleaner.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\game\CharacterHandler.cpp"
|
||||
>
|
||||
|
|
|
|||
|
|
@ -698,6 +698,14 @@
|
|||
RelativePath="..\..\src\game\ChannelMgr.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\game\CharacterDatabaseCleaner.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\game\CharacterDatabaseCleaner.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\game\CharacterHandler.cpp"
|
||||
>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue