// // NostaleChatPacketApi.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.Chat; using NosSmooth.Packets.Enums.Entities; using NosSmooth.Packets.Server.Chat; using Remora.Results; namespace NosSmooth.Game.Apis; /// /// Packet api for sending and receiving messages. /// public class NostaleChatPacketApi { // TODO: check length of the messages private readonly INostaleClient _client; /// /// Initializes a new instance of the class. /// /// The nostale client. public NostaleChatPacketApi(INostaleClient client) { _client = client; } /// /// Receive the given system message on the client. /// /// /// Won't send anything to the server, it's just the client who will see the message. /// /// The content of the message. /// The color of the message. /// The cancellation token for cancelling the operation. /// A result that may or may not have succeeded. public Task ReceiveSystemMessageAsync(string content, SayColor color = SayColor.Yellow, CancellationToken ct = default) => _client.ReceivePacketAsync(new SayPacket(EntityType.Map, 0, color, content), ct); /// /// Sends the given message to the public chat. /// /// The content of the message. /// The cancellation token for cancelling the operation. /// A result that may or may not have succeeded. public Task SendMessageAsync(string content, CancellationToken ct = default) => _client.SendPacketAsync(new Packets.Client.Chat.SayPacket(content), ct); /// /// Sends the given message to the family chat. /// /// /// Should be used only if the user is in a family. /// /// The content of the message. /// The cancellation token for cancelling the operation. /// A result that may or may not have succeeded. public Task SendFamilyMessage(string content, CancellationToken ct = default) => _client.SendPacketAsync(":" + content, ct); /// /// Sends the given message to the group chat. /// /// /// Should be used only if the user is in a group. (with people, not only pets). /// /// The content of the message. /// The cancellation token for cancelling the operation. /// A result that may or may not have succeeded. public Task SendGroupMessage(string content, CancellationToken ct = default) => _client.SendPacketAsync(";" + content, ct); /// /// Sends the given message to the target only. /// /// /// Won't return if the whisper has actually came through, event has to be hooked /// up to know if the whisper has went through (and you can know only for messages that are sufficiently long). /// /// The name of the user you want to whisper to. /// The content of the message. /// The cancellation token for cancelling the operation. /// A result that may or may not have succeeded. public Task SendWhisper(string targetName, string content, CancellationToken ct = default) => _client.SendPacketAsync($"/{targetName} {content}", ct); }