~ruther/NosSmooth

373b2c3d9ca571f09979c88b9f1e23be6445c3ed — Rutherther 2 years ago 01d9b23
fix(game): make skills api safer by treating dash correctly and allowing only player skills
M Core/NosSmooth.Game/Apis/Safe/NostaleSkillsApi.cs => Core/NosSmooth.Game/Apis/Safe/NostaleSkillsApi.cs +29 -0
@@ 80,6 80,16 @@ public class NostaleSkillsApi
            return Task.FromResult<Result>(new WrongSkillTargetError(skill, character));
        }

        if (skill.Info.SkillType != SkillType.Player)
        {
            return Task.FromResult<Result>(new WrongSkillTypeError(SkillType.Player, skill.Info.SkillType));
        }

        if (skill.Info.AttackType == AttackType.Dash)
        {
            return Task.FromResult<Result>(new WrongSkillPositionError(skill.Info.AttackType));
        }

        return _client.SendPacketAsync
        (
            new UseSkillPacket


@@ 143,6 153,20 @@ public class NostaleSkillsApi
            return Task.FromResult<Result>(new WrongSkillTargetError(skill, entity));
        }

        if (skill.Info.SkillType != SkillType.Player)
        {
            return Task.FromResult<Result>(new WrongSkillTypeError(SkillType.Player, skill.Info.SkillType));
        }

        if (skill.Info.AttackType == AttackType.Dash && (mapX is null || mapY is null))
        {
            return Task.FromResult<Result>(new WrongSkillPositionError(skill.Info.AttackType));
        }
        else if (skill.Info.AttackType != AttackType.Dash && (mapX is not null || mapY is not null))
        {
            return Task.FromResult<Result>(new WrongSkillPositionError(skill.Info.AttackType));
        }

        var entityPosition = entity.Position;
        if (entityPosition is null)
        {


@@ 285,6 309,11 @@ public class NostaleSkillsApi
            return Task.FromResult<Result>(new WrongSkillTargetError(skill, null));
        }

        if (skill.Info.SkillType != SkillType.Player)
        {
            return Task.FromResult<Result>(new WrongSkillTypeError(SkillType.Player, skill.Info.SkillType));
        }

        var characterPosition = _game.Character?.Position;
        if (characterPosition is null)
        {

A Core/NosSmooth.Game/Errors/WrongSkillPositionError.cs => Core/NosSmooth.Game/Errors/WrongSkillPositionError.cs +13 -0
@@ 0,0 1,13 @@
//
//  WrongSkillPositionError.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.

using NosSmooth.Data.Abstractions.Enums;
using Remora.Results;

namespace NosSmooth.Game.Errors;

public record WrongSkillPositionError(AttackType AttackType)
    : ResultError($"The skill with an attack type {AttackType} has to have a map position specified.");
\ No newline at end of file

A Core/NosSmooth.Game/Errors/WrongSkillTypeError.cs => Core/NosSmooth.Game/Errors/WrongSkillTypeError.cs +13 -0
@@ 0,0 1,13 @@
//
//  WrongSkillTypeError.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.

using NosSmooth.Data.Abstractions.Enums;
using Remora.Results;

namespace NosSmooth.Game.Errors;

public record WrongSkillTypeError(SkillType ExpectedType, SkillType ActualType)
    : ResultError($"Cannot use a skill of type {ActualType}, only type {ExpectedType} is allowed.");
\ No newline at end of file