~ruther/NosSmooth

3d95287f3c292fb68e1fa217ad15108e0adfdac7 — František Boháček 3 years ago 348da2c
feat: implement cinfo packet
2 files changed, 68 insertions(+), 55 deletions(-)

D Core/NosSmooth.Game/PacketHandlers/Login/CListPacketResponder.cs
M Packets/NosSmooth.Packets/Server/Players/CInfoPacket.cs
D Core/NosSmooth.Game/PacketHandlers/Login/CListPacketResponder.cs => Core/NosSmooth.Game/PacketHandlers/Login/CListPacketResponder.cs +0 -50
@@ 1,50 0,0 @@
//
//  CListPacketResponder.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.Game.Events.Core;
using NosSmooth.Game.Events.Login;
using Remora.Results;

namespace NosSmooth.Game.PacketHandlers.Login;

/// <summary>
/// Handles FStashEnd packet to remove game data.
/// </summary>
public class CListPacketResponder : IPacketResponder<ClistPacket>
{
    private readonly EventDispatcher _eventDispatcher;
    private readonly Game _game;

    /// <summary>
    /// Initializes a new instance of the <see cref="CListPacketResponder"/> class.
    /// </summary>
    /// <param name="eventDispatcher">The events dispatcher.</param>
    /// <param name="game">The nostale game.</param>
    public CListPacketResponder(EventDispatcher eventDispatcher, Game game)
    {
        _eventDispatcher = eventDispatcher;
        _game = game;
    }

    /// <inheritdoc />
    public async Task<Result> Respond(PacketEventArgs<ClistPacket> packetArgs, CancellationToken ct = default)
    {
        await _game.SetSemaphore.WaitAsync(ct);
        bool logout = _game.Character is not null || _game.CurrentMap is not null;
        _game.Character = null;
        _game.CurrentMap = null;
        _game.CurrentRaid = null;
        _game.SetSemaphore.Release();

        if (logout)
        {
            return await _eventDispatcher.DispatchEvent(new LogoutEvent(), ct);
        }

        return Result.FromSuccess();
    }
}
\ No newline at end of file

M Packets/NosSmooth.Packets/Server/Players/CInfoPacket.cs => Packets/NosSmooth.Packets/Server/Players/CInfoPacket.cs +68 -5
@@ 4,11 4,74 @@
//  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.

namespace NosSmooth.Packets.Server.Players;
using NosSmooth.Packets.Attributes;
using NosSmooth.Packets.Enums;
using NosSmooth.Packets.Enums.Players;

namespace NosSmooth.Packets.Packets.Server.Players;

/// <summary>
/// Character information.
/// Information about the playing character.
/// </summary>
// [PacketHeader()]
// [GenerateSerializer(true)]
public record CInfoPacket();
\ No newline at end of file
/// <remarks>
/// Sent on login and when changing map.
/// </remarks>
/// <param name="Name">The name of the character.</param>
/// <param name="Unknown">Unknown TODO</param>
/// <param name="GroupId">The id of the group the player is in, if any.</param>
/// <param name="FamilyId">The id of the family the player is in, if any.</param>
/// <param name="FamilyName">The name of the family the player is in, if any.</param>
/// <param name="CharacterId">The id of the character.</param>
/// <param name="Authority">The authority of the character.</param>
/// <param name="Sex">The sex of the character.</param>
/// <param name="HairStyle">The hair style of the character.</param>
/// <param name="HairColor">The hair color of the character.</param>
/// <param name="Class">The class of the character.</param>
/// <param name="Icon">Unknown TODO</param>
/// <param name="Compliment">Unknown TODO</param>
/// <param name="MorphVNum">The vnum of the morph (used for special cards, vehicles and such).</param>
/// <param name="IsInvisible">Whether the character is invisible.</param>
/// <param name="FamilyLevel">The level of the family, if any.</param>
/// <param name="MorphUpgrade">The upgrade of the morph (wings)</param>
/// <param name="ArenaWinner">Whether the character is an arena winner.</param>
[PacketHeader("c_info", PacketSource.Server)]
[GenerateSerializer(true)]
public record CInfoPacket
(
    [PacketIndex(0)]
    string Name,
    [PacketIndex(1)]
    string? Unknown,
    [PacketIndex(2)]
    short? GroupId,
    [PacketIndex(3)]
    string? FamilyId,
    [PacketIndex(4)]
    string? FamilyName,
    [PacketIndex(5)]
    long CharacterId,
    [PacketIndex(6)]
    AuthorityType Authority,
    [PacketIndex(7)]
    SexType Sex,
    [PacketIndex(8)]
    HairStyle HairStyle,
    [PacketIndex(9)]
    HairColor HairColor,
    [PacketIndex(10)]
    PlayerClass Class,
    [PacketIndex(11)]
    byte Icon,
    [PacketIndex(12)]
    short Compliment,
    [PacketIndex(13)]
    short MorphVNum,
    [PacketIndex(14)]
    bool IsInvisible,
    [PacketIndex(15)]
    byte? FamilyLevel,
    [PacketIndex(16)]
    byte MorphUpgrade,
    [PacketIndex(17)]
    bool ArenaWinner
) : IPacket;

Do not follow this link