Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Core/Characters): Cleanup character item_instance and character_… #21473

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/server/apps/worldserver/worldserver.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -1745,16 +1745,27 @@ PlayerSave.Stats.SaveOnlyOnLogout = 1

CleanCharacterDB = 0

#
# CleanCharacterDB.OrderItems
# Description: Requires CleanCharacterDB = 1
# Reoder item guids in item_instance and character_inventory
#
# Default: 0 - (Disabled)
# 1 - (Enable)

CleanCharacterDB.OrderItems = 0

#
# PersistentCharacterCleanFlags
# Description: Determines the character clean flags that remain set after cleanups.
# Description: Requires CleanCharacterDB = 1
# Determines the character clean flags that remain set after cleanups.
# This is a bitmask value, you can use one of the following values:
#
# CLEANING_FLAG_ACHIEVEMENT_PROGRESS = 0x1
# CLEANING_FLAG_SKILLS = 0x2
# CLEANING_FLAG_SPELLS = 0x4
# CLEANING_FLAG_TALENTS = 0x8
# CLEANING_FLAG_QUESTSTATUS = 0x10
# CLEANING_FLAG_ACHIEVEMENT_PROGRESS = 1
# CLEANING_FLAG_SKILLS = 2
# CLEANING_FLAG_SPELLS = 4
# CLEANING_FLAG_TALENTS = 8
# CLEANING_FLAG_QUESTSTATUS = 16
#
# Before use this feature, make a backup of your database.
#
Expand Down
11 changes: 11 additions & 0 deletions src/server/game/Tools/CharacterDatabaseCleaner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ void CharacterDatabaseCleaner::CleanDatabase()
if (flags & CLEANING_FLAG_QUESTSTATUS)
CleanCharacterQuestStatus();

if (sWorld->getBoolConfig(CONFIG_CLEAN_CHARACTER_DB_ORDER_ITEMS))
CleanCharacterItem();

// NOTE: In order to have persistentFlags be set in worldstates for the next cleanup,
// you need to define them at least once in worldstates.
flags &= sWorld->getIntConfig(CONFIG_PERSISTENT_CHARACTER_CLEAN_FLAGS);
Expand Down Expand Up @@ -154,3 +157,11 @@ void CharacterDatabaseCleaner::CleanCharacterQuestStatus()
{
CharacterDatabase.DirectExecute("DELETE FROM character_queststatus WHERE status = 0");
}

void CharacterDatabaseCleaner::CleanCharacterItem()
{
CharacterDatabase.DirectExecute("CREATE TEMPORARY TABLE temp_guid_mapping AS SELECT guid AS old_guid, ROW_NUMBER() OVER (ORDER BY guid) AS new_guid FROM item_instance;");
CharacterDatabase.DirectExecute("UPDATE item_instance i JOIN temp_guid_mapping m ON i.guid = m.old_guid SET i.guid = m.new_guid;");
CharacterDatabase.DirectExecute("UPDATE character_inventory ci JOIN temp_guid_mapping m ON ci.item = m.old_guid SET ci.item = m.new_guid;");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to do the same for mail_items, guild_bank_item, recovery_item, auctionhouse and probably some more tables (use a collective brain?).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah true they would all hava record in item_instance

CharacterDatabase.DirectExecute("DROP TEMPORARY TABLE temp_guid_mapping;");
}
1 change: 1 addition & 0 deletions src/server/game/Tools/CharacterDatabaseCleaner.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace CharacterDatabaseCleaner
void CleanCharacterSpell();
void CleanCharacterTalent();
void CleanCharacterQuestStatus();
void CleanCharacterItem();
}

#endif
1 change: 1 addition & 0 deletions src/server/game/World/IWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ enum WorldBoolConfigs
CONFIG_ADDON_CHANNEL,
CONFIG_ALLOW_PLAYER_COMMANDS,
CONFIG_CLEAN_CHARACTER_DB,
CONFIG_CLEAN_CHARACTER_DB_ORDER_ITEMS,
CONFIG_STATS_SAVE_ONLY_ON_LOGOUT,
CONFIG_ALLOW_TWO_SIDE_ACCOUNTS,
CONFIG_ALLOW_TWO_SIDE_INTERACTION_CALENDAR,
Expand Down
1 change: 1 addition & 0 deletions src/server/game/World/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ void World::LoadConfigSettings(bool reload)
}
_bool_configs[CONFIG_ADDON_CHANNEL] = sConfigMgr->GetOption<bool>("AddonChannel", true);
_bool_configs[CONFIG_CLEAN_CHARACTER_DB] = sConfigMgr->GetOption<bool>("CleanCharacterDB", false);
_bool_configs[CONFIG_CLEAN_CHARACTER_DB_ORDER_ITEMS] = sConfigMgr->GetOption<bool>("CleanCharacterDB.OrderItems", false);
_int_configs[CONFIG_PERSISTENT_CHARACTER_CLEAN_FLAGS] = sConfigMgr->GetOption<int32>("PersistentCharacterCleanFlags", 0);
_int_configs[CONFIG_CHAT_CHANNEL_LEVEL_REQ] = sConfigMgr->GetOption<int32>("ChatLevelReq.Channel", 1);
_int_configs[CONFIG_CHAT_WHISPER_LEVEL_REQ] = sConfigMgr->GetOption<int32>("ChatLevelReq.Whisper", 1);
Expand Down
Loading