~ruther/NosSmooth

ref: ee85ca052e70652940d11c7fe3d5b45622342c52 NosSmooth/Extensions/NosSmooth.Extensions.Pathfinding/Responders/CMapResponder.cs -rw-r--r-- 1.4 KiB
ee85ca05 — František Boháček chore(packets): update version 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//
//  CMapResponder.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.Core.Packets;
using NosSmooth.Data.Abstractions;
using NosSmooth.Packets.Server.Maps;
using Remora.Results;

namespace NosSmooth.Extensions.Pathfinding.Responders;

/// <inheritdoc />
internal class CMapResponder : IPacketResponder<CMapPacket>
{
    private readonly PathfinderState _state;
    private readonly IInfoService _infoService;

    /// <summary>
    /// Initializes a new instance of the <see cref="CMapResponder"/> class.
    /// </summary>
    /// <param name="state">The state.</param>
    /// <param name="infoService">The info service.</param>
    public CMapResponder(PathfinderState state, IInfoService infoService)
    {
        _state = state;
        _infoService = infoService;
    }

    /// <inheritdoc />
    public async Task<Result> Respond(PacketEventArgs<CMapPacket> packetArgs, CancellationToken ct = default)
    {
        var packet = packetArgs.Packet;

        _state.MapId = packet.Id;
        var mapInfoResult = await _infoService.GetMapInfoAsync(packet.Id, ct);

        if (!mapInfoResult.IsSuccess)
        {
            return Result.FromError(mapInfoResult);
        }

        _state.MapInfo = mapInfoResult.Entity;
        return Result.FromSuccess();
    }
}
Do not follow this link