diff --git a/VpSharp/src/VirtualParadiseClient.cs b/VpSharp/src/VirtualParadiseClient.cs index 6ffa290..cf0300a 100644 --- a/VpSharp/src/VirtualParadiseClient.cs +++ b/VpSharp/src/VirtualParadiseClient.cs @@ -581,6 +581,89 @@ public sealed partial class VirtualParadiseClient : IDisposable )); } + /// + /// Sends a console message to everyone in the current world. + /// + /// The message to send. + /// The font style of the message. + /// The text color of the message. + /// The message which was sent. + /// is . + /// + /// An attempt was made to send a message while not connected to a world. + /// + /// + /// is empty, or consists of only whitespace. + /// -or- + /// is too long to send. + /// + public Task SendMessageAsync(string message, FontStyle fontStyle, Color color) + { + return SendMessageAsync(null, message, fontStyle, color); + } + + /// + /// Sends a console message to everyone in the current world. + /// + /// The apparent author of the message. + /// The message to send. + /// The font style of the message. + /// The text color of the message. + /// The message which was sent. + /// is . + /// + /// An attempt was made to send a message while not connected to a world. + /// + /// + /// is empty, or consists of only whitespace. + /// -or- + /// is too long to send. + /// + public Task SendMessageAsync(string? name, string message, FontStyle fontStyle, Color color) + { + ArgumentNullException.ThrowIfNull(message); + if (string.IsNullOrWhiteSpace(message)) + { + throw new ArgumentException(ExceptionMessages.ValueCannotBeEmpty, nameof(message)); + } + + lock (Lock) + { + var reason = (ReasonCode)vp_console_message( + NativeInstanceHandle, + 0, + name ?? string.Empty, + message, + (int)fontStyle, + color.R, + color.G, + color.B + ); + + if (reason != ReasonCode.Success) + { + switch (reason) + { + case ReasonCode.NotInWorld: + throw new InvalidOperationException(ExceptionMessages.ConnectionToWorldServerRequired); + + case ReasonCode.StringTooLong: + throw new ArgumentException(ExceptionMessages.StringTooLong); + } + } + } + + VirtualParadiseAvatar avatar = CurrentAvatar!; + return Task.FromResult(new VirtualParadiseMessage( + MessageType.ConsoleMessage, + name, + message, + avatar, + fontStyle, + color + )); + } + internal TaskCompletionSource AddJoinCompletionSource(int reference) { var taskCompletionSource = new TaskCompletionSource();