//
// DetachCommand.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.Client;
using NosSmooth.Packets.Enums;
using NosSmooth.Packets.Enums.Chat;
using NosSmooth.Packets.Packets.Server.Chat;
using Remora.Results;
namespace WalkCommands.Commands;
///
/// Group for detaching command that detaches the dll.
///
public class DetachCommand
{
private readonly CancellationTokenSource _dllStop;
private readonly INostaleClient _client;
///
/// Initializes a new instance of the class.
///
/// The cancellation token source to stop the client.
/// The nostale client.
public DetachCommand(CancellationTokenSource dllStop, INostaleClient client)
{
_dllStop = dllStop;
_client = client;
}
///
/// Detach the dll.
///
/// A result that may or may not have succeeded.
public async Task HandleDetach()
{
var receiveResult = await _client.ReceivePacketAsync
(new SayPacket(EntityType.Map, 1, SayColor.Green, "Going to detach!"));
if (!receiveResult.IsSuccess)
{
return receiveResult;
}
_dllStop.Cancel();
return Result.FromSuccess();
}
}