diff --git a/sql/migrations/20241108102245_characters.sql b/sql/migrations/20241108102245_characters.sql new file mode 100644 index 00000000000..38c1d38820f --- /dev/null +++ b/sql/migrations/20241108102245_characters.sql @@ -0,0 +1,23 @@ +DROP PROCEDURE IF EXISTS add_migration; +DELIMITER ?? +CREATE PROCEDURE `add_migration`() +BEGIN +DECLARE v INT DEFAULT 1; +SET v = (SELECT COUNT(*) FROM `migrations` WHERE `id`='20241108102245'); +IF v = 0 THEN +INSERT INTO `migrations` VALUES ('20241108102245'); +-- Add your query below. + +DROP TABLE IF EXISTS `world_persistent_variables`; +CREATE TABLE `world_persistent_variables` ( + `index` int(10) unsigned NOT NULL DEFAULT 0, + `value` int(10) unsigned NOT NULL DEFAULT 0, + PRIMARY KEY (`index`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Wareffort, Stranglethorn Vale Fishing , ...'; + +-- End of migration. +END IF; +END?? +DELIMITER ; +CALL add_migration(); +DROP PROCEDURE IF EXISTS add_migration; diff --git a/sql/migrations/20241108102245_world.sql b/sql/migrations/20241108102245_world.sql new file mode 100644 index 00000000000..3f894f29d5a --- /dev/null +++ b/sql/migrations/20241108102245_world.sql @@ -0,0 +1,19 @@ +DROP PROCEDURE IF EXISTS add_migration; +DELIMITER ?? +CREATE PROCEDURE `add_migration`() +BEGIN +DECLARE v INT DEFAULT 1; +SET v = (SELECT COUNT(*) FROM `migrations` WHERE `id`='20241108102245'); +IF v = 0 THEN +INSERT INTO `migrations` VALUES ('20241108102245'); +-- Add your query below. + +-- Moved to characters db (world_persistent_variables) +DROP TABLE IF EXISTS `variables`; + +-- End of migration. +END IF; +END?? +DELIMITER ; +CALL add_migration(); +DROP PROCEDURE IF EXISTS add_migration; diff --git a/src/game/Commands/ServerCommands.cpp b/src/game/Commands/ServerCommands.cpp index 321cd74a029..5cd9364b18c 100644 --- a/src/game/Commands/ServerCommands.cpp +++ b/src/game/Commands/ServerCommands.cpp @@ -1875,7 +1875,7 @@ bool ChatHandler::HandleReloadPetitions(char*) bool ChatHandler::HandleReloadVariablesCommand(char*) { sObjectMgr.LoadSavedVariable(); - SendSysMessage("Table `variables` has been reloaded."); + SendSysMessage("Table `world_persistent_variables` has been reloaded."); return true; } diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 8a9d16d7432..ea72430c0e7 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -544,10 +544,10 @@ void ObjectMgr::_SaveVariable(SavedVariable const& toSave) { // Must do this in a transaction, else if worker threads > 1 we could do one before the other // when order is important... - WorldDatabase.BeginTransaction(); - WorldDatabase.PExecute("DELETE FROM `variables` WHERE `index` = %u", toSave.uiIndex); - WorldDatabase.PExecute("INSERT INTO `variables` (`index`, `value`) VALUES (%u, %u)", toSave.uiIndex, toSave.uiValue); - WorldDatabase.CommitTransaction(); + CharacterDatabase.BeginTransaction(); + CharacterDatabase.PExecute("DELETE FROM `world_persistent_variables` WHERE `index` = %u", toSave.uiIndex); + CharacterDatabase.PExecute("INSERT INTO `world_persistent_variables` (`index`, `value`) VALUES (%u, %u)", toSave.uiIndex, toSave.uiValue); + CharacterDatabase.CommitTransaction(); } void ObjectMgr::InitSavedVariable(uint32 index, uint32 value) @@ -587,20 +587,6 @@ void ObjectMgr::SetSavedVariable(uint32 index, uint32 value, bool autoSave) _SaveVariable(variable); } -void ObjectMgr::LoadVariable(uint32 index, uint32* variable, uint32 defaultValue, uint32 maxValue, uint32 minValue) -{ - bool inIndex = false; - (*variable) = GetSavedVariable(index, defaultValue, &inIndex); - uint32 originalValue = (*variable); - if (maxValue != 0 && (*variable) > maxValue) - (*variable) = defaultValue; - if ((*variable) < minValue) - (*variable) = defaultValue; - if (!inIndex) - _InsertVariable(index, (*variable), true); - if (originalValue != (*variable)) - SetSavedVariable(index, (*variable), true); -} void ObjectMgr::SaveVariables() { SavedVariablesVector::iterator it; @@ -615,7 +601,7 @@ void ObjectMgr::LoadSavedVariable() { m_SavedVariables.clear(); - std::unique_ptr result(WorldDatabase.Query("SELECT `index`, `value` FROM `variables`")); + std::unique_ptr result(CharacterDatabase.Query("SELECT `index`, `value` FROM `world_persistent_variables`")); uint32 total_count = 0; @@ -625,7 +611,7 @@ void ObjectMgr::LoadSavedVariable() bar.step(); sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, ""); - sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, ">> Loaded %u saved variables", total_count); + sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, ">> Loaded %u world persistent variables", total_count); return; } @@ -641,7 +627,7 @@ void ObjectMgr::LoadSavedVariable() while (result->NextRow()); sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, ""); - sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, ">> Loaded %u saved variables", total_count); + sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, ">> Loaded %u world persistent variables", total_count); } // Caching player data diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h index 5544ab72772..07c60791616 100644 --- a/src/game/ObjectMgr.h +++ b/src/game/ObjectMgr.h @@ -1281,7 +1281,6 @@ class ObjectMgr void InitSavedVariable(uint32 index, uint32 value); uint32 GetSavedVariable(uint32 index, uint32 defaultValue = 0, bool* exist = nullptr); void SetSavedVariable(uint32 index, uint32 value, bool SaveToDb = false); - void LoadVariable(uint32 index, uint32* variable, uint32 defaultValue, uint32 maxValue=0, uint32 minValue=0); void LoadSavedVariable(); void SaveVariables(); diff --git a/src/game/World.cpp b/src/game/World.cpp index 22bb50b6192..9e11ecd45cf 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -1331,8 +1331,8 @@ void World::SetInitialWorldSettings() sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, ""); sInstanceStatistics.LoadFromDB(); - // Chargements des variables (necessaire pour le OutdoorJcJ) - sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, "Loading saved variables ..."); + // Loads world persistent variables (Wareffort, Stranglethorn Vale Fishing , ...) + sLog.Out(LOG_BASIC, LOG_LVL_MINIMAL, "Loading world_persistent_variables..."); sObjectMgr.LoadSavedVariable();