Skip to content

Commit

Permalink
fix: stamina boost overflow (#1763)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
luan authored Nov 1, 2023
1 parent e54b9c7 commit 2a3a028
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
10 changes: 9 additions & 1 deletion data-otservbr-global/migrations/41.lua
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions data-otservbr-global/migrations/42.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function onUpdateDatabase()
return false -- true = There are others migrations file | false = this is the last migration file
end
4 changes: 2 additions & 2 deletions schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 5 additions & 0 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 2a3a028

Please sign in to comment.