]> git.deb.at Git - rhonda/impostor.git/commitdiff
Implement host chat commands
authorminiduikboot <mini@duikbo.at>
Tue, 27 Jan 2026 21:17:03 +0000 (22:17 +0100)
committerminiduikboot <mini@duikbo.at>
Tue, 27 Jan 2026 21:17:03 +0000 (22:17 +0100)
On January 21 Innersloth released a document that details a few new
features. One of these are host chat commands: any chat message that
starts with "/cmd" is forwarded to the host and to the host only.

Implement this feature in Impostor too for implementation parity.

For more info, see their GitHub page:
https://github.com/Innersloth-LLC/AmongUsModdingInformation

src/Impostor.Api/Events/Game/Player/IPlayerChatEvent.cs
src/Impostor.Server/Events/Game/Player/PlayerChatEvent.cs
src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.cs

index 914701025c264d1005c93ff46756df1785faae61..c3143e18157ab13c871769846966ca6c5ed20ae7 100644 (file)
@@ -1,4 +1,4 @@
-namespace Impostor.Api.Events.Player
+namespace Impostor.Api.Events.Player
 {
     public interface IPlayerChatEvent : IPlayerEvent, IEventCancelable
     {
@@ -6,5 +6,12 @@
         ///     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; }
     }
 }
index 34ec95ed2b53588599dedf1ea6bd89f4cf72ed8b..44ce179d4f5ea2662a536994f83b643120f5f99f 100644 (file)
@@ -1,4 +1,4 @@
-using Impostor.Api.Events.Player;
+using Impostor.Api.Events.Player;
 using Impostor.Api.Games;
 using Impostor.Api.Net;
 using Impostor.Api.Net.Inner.Objects;
@@ -24,5 +24,7 @@ namespace Impostor.Server.Events.Player
         public string Message { get; }
 
         public bool IsCancelled { get; set; }
+
+        public bool SendToAllPlayers { get; set; } = true;
     }
 }
index fb49b74b7b6442e7b1ccbf9c5b7e8fe00abfca68..c4cab7c6cede206a27378951db6620cdc9744808 100644 (file)
@@ -1183,9 +1183,35 @@ namespace Impostor.Server.Net.Inner.Objects
         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)