-namespace Impostor.Api.Events.Player
+namespace Impostor.Api.Events.Player
{
public interface IPlayerChatEvent : IPlayerEvent, IEventCancelable
{
/// Gets the message sent by the player.
/// </summary>
string Message { get; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether the message is sent to
+ /// all players (true) or only to the host (false).
+ /// To not send this message at all, cancel this event instead.
+ /// </summary>
+ bool SendToAllPlayers { get; set; }
}
}
-using Impostor.Api.Events.Player;
+using Impostor.Api.Events.Player;
using Impostor.Api.Games;
using Impostor.Api.Net;
using Impostor.Api.Net.Inner.Objects;
public string Message { get; }
public bool IsCancelled { get; set; }
+
+ public bool SendToAllPlayers { get; set; } = true;
}
}
private async ValueTask<bool> HandleSendChat(ClientPlayer sender, string message)
{
var @event = new PlayerChatEvent(Game, sender, this, message);
+
+ // See https://github.com/Innersloth-LLC/AmongUsModdingInformation?tab=readme-ov-file#chat-commands
+ // Details not mentioned:
+ // - If the host sends a message that starts with /cmd, it is sent to all players
+ // - If the message starts with " /cmd" (note the space) it is sent to all players
+ if (Game.IsHostAuthoritive && !sender.IsHost && message.StartsWith("/cmd"))
+ {
+ @event.SendToAllPlayers = false;
+ }
+
await _eventManager.CallAsync(@event);
- return !@event.IsCancelled;
+ if (@event.IsCancelled)
+ {
+ return false;
+ }
+ else if (@event.SendToAllPlayers == false)
+ {
+ if (Game.Host != null)
+ {
+ await SendChatToPlayerAsync(message, Game.Host.Character);
+ }
+
+ return false;
+ }
+ else
+ {
+ return true;
+ }
}
private async ValueTask HandleStartMeeting(byte targetId)