From 2a3a028da7f94200353e6022dbb3184ea024ee20 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Tue, 31 Oct 2023 21:20:01 -0700 Subject: [PATCH] fix: stamina boost overflow (#1763) This is a big one, players would stop saving correctly after getting exp boosts from daily rewards totally more than max tiny int. Fixes: - Change DB column to uint16 (same as the c++ variable type) - Programatically set the max value to 12 hours (or 43,200 seconds) --- data-otservbr-global/migrations/41.lua | 10 +++++++++- data-otservbr-global/migrations/42.lua | 3 +++ schema.sql | 4 ++-- src/creatures/players/player.hpp | 5 +++++ 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 data-otservbr-global/migrations/42.lua diff --git a/data-otservbr-global/migrations/41.lua b/data-otservbr-global/migrations/41.lua index 86a6d8ffec1..179ac18b574 100644 --- a/data-otservbr-global/migrations/41.lua +++ b/data-otservbr-global/migrations/41.lua @@ -1,3 +1,11 @@ function onUpdateDatabase() - return false -- true = There are others migrations file | false = this is the last migration file + logger.info("Updating database to version 42 (fix xpboost types)") + + db.query([[ + ALTER TABLE `players` + MODIFY `xpboost_stamina` smallint(5) UNSIGNED DEFAULT NULL, + MODIFY `xpboost_value` tinyint(4) UNSIGNED DEFAULT NULL + ]]) + + return true end diff --git a/data-otservbr-global/migrations/42.lua b/data-otservbr-global/migrations/42.lua new file mode 100644 index 00000000000..86a6d8ffec1 --- /dev/null +++ b/data-otservbr-global/migrations/42.lua @@ -0,0 +1,3 @@ +function onUpdateDatabase() + return false -- true = There are others migrations file | false = this is the last migration file +end diff --git a/schema.sql b/schema.sql index dc58d3a71ac..3ba4e35effc 100644 --- a/schema.sql +++ b/schema.sql @@ -129,8 +129,8 @@ CREATE TABLE IF NOT EXISTS `players` ( `skill_manaleech_amount` bigint(20) UNSIGNED NOT NULL DEFAULT '0', `manashield` SMALLINT UNSIGNED NOT NULL DEFAULT '0', `max_manashield` SMALLINT UNSIGNED NOT NULL DEFAULT '0', - `xpboost_stamina` smallint(5) DEFAULT NULL, - `xpboost_value` tinyint(4) DEFAULT NULL, + `xpboost_stamina` smallint(5) UNSIGNED DEFAULT NULL, + `xpboost_value` tinyint(4) UNSIGNED DEFAULT NULL, `marriage_status` bigint(20) UNSIGNED NOT NULL DEFAULT '0', `marriage_spouse` int(11) NOT NULL DEFAULT '-1', `bonus_rerolls` bigint(21) NOT NULL DEFAULT '0', diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index 791f696148c..840c257b4c1 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -1760,6 +1760,11 @@ class Player final : public Creature, public Cylinder, public Bankable { } void setExpBoostStamina(uint16_t stamina) { + // only allow stamina boosts of 12 hours or less + if (stamina > 12 * 3600) { + expBoostStamina = 12 * 3600; + return; + } expBoostStamina = stamina; }