add int overflow protection for achievement values

This commit is contained in:
Robert Paciorek 2023-09-05 11:36:53 +00:00 committed by Spirtix
parent 9b1609c6ad
commit e57e5ad44b

View File

@ -54,6 +54,11 @@ namespace sodoff.Services {
public AchievementReward? AddDragonAchievementPoints(Dragon dragon, int? value) {
dragon.PetXP = (dragon.PetXP ?? 0) + (value ?? 0);
if (dragon.PetXP < 0) {
dragon.PetXP = int.MaxValue;
value = 0;
}
return new AchievementReward{
// NOTE: RewardID and EntityTypeID are not used by client
EntityID = Guid.Parse(dragon.EntityId),
@ -76,6 +81,11 @@ namespace sodoff.Services {
}
xpPoints.Value += value ?? 0;
if (xpPoints.Value < 0) {
xpPoints.Value = int.MaxValue;
value = 0;
}
return new AchievementReward{
EntityID = Guid.Parse(viking.Id),
PointTypeID = type,