Change AddAchievementPoints to account for overflow and underflow (#8)

This is for minisaurs in WoJ, but I think it would be a good idea in general, so I didn't limit it to WoJ.

The issue happens because if you buy medicine for minisaurs. It takes away one coin, and so if you already have 0 coins, the server currently returns your coin count as int.MaxValue.

This is tested in WoJ 1.1.0 and 1.21.0. I tested buying, overflowing, underflowing, using commands with big and negative values and playing games.
This commit is contained in:
YesntSoup 2024-11-19 16:50:19 -05:00 committed by GitHub
parent 6423fec54f
commit 2c4d99a84c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -81,10 +81,16 @@ namespace sodoff.Services {
}; };
viking.AchievementPoints.Add(xpPoints); viking.AchievementPoints.Add(xpPoints);
} }
int initialPoints = xpPoints.Value;
xpPoints.Value += value ?? 0; xpPoints.Value += value ?? 0;
if (xpPoints.Value < 0) { if (value > 0 && initialPoints > xpPoints.Value) {
xpPoints.Value = int.MaxValue; xpPoints.Value = int.MaxValue;
value = int.MaxValue - initialPoints;
}
if (xpPoints.Value < 0) {
xpPoints.Value = 0;
value = 0; value = 0;
} }