Impostor has an Anticheat that makes it possible to kick cheaters from games automatically. Note that the anticheat is tuned on the vanilla version of the game, so client-side modifications could trigger the Anticheat if you're playing with them.
-| Key | Default | Value |
-| ----------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| **Enabled** | `true` | Whether the anticheat should be enabled. |
-| **BanIpFromGame** | `true` | When anticheat is enabled and a player is caught hacking, they will be kicked from the server. If this value is set to `true`, the player will be banned instead and will not be able to rejoin that specific game. |
+| Key | Default | Value |
+|----------------------------|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| **Enabled** | `true` | Whether the anticheat should be enabled. |
+| **BanIpFromGame** | `true` | When anticheat is enabled and a player is caught hacking, they will be kicked from the server. If this value is set to `true`, the player will be banned instead and will not be able to rejoin that specific game. |
+| **AllowCheatingHosts** | `"Never"` | Configure whether hosts are allowed to cheat. "Never" forbids it, "Always" allows it. "IfRequested" allows hosts to cheat if they connect with the DisableServerAuthorityFlag set. |
+| **EnableGameFlowChecks** | `true` | Enable checks that check if certain actions are done in the appropriate order or at the appropriate moment in the game. This includes changing cosmetics while in game or murdering too fast. |
+| **EnableMustBeHostChecks** | `true` | Enables checks that check if players are the host before they can do actions that require them to be host of the game. This includes starting the game and spawning objects. |
+| **EnableColorLimitChecks** | `true` | Enables checks that checks if players request colors that are already in use. |
+| **EnableNameLimitChecks** | `true` | Enables checks that checks if player names have a length that is possible to set using the user interface. |
+| **EnableOwnershipChecks** | `true` | Enables checks that check if players are allowed to perform a certain action on themself or another player. |
+| **EnableRoleChecks** | `true` | Enables checks that check if players have the correct role when performing certain role abilities like venting or murdering. |
+| **EnableTargetChecks** | `true` | Enables checks that check if certain packets to everyone that should only have been sent to certain players or vice versa. This includes sending votes or network objects. |
+
+| **ForbidProtocolExtensions** | `true` | If disabled allows players to send network packets that go beyond the network packets sent by the vanilla game. This is necessary for most mods that need all players to install it. |
### Compatibility
--- /dev/null
+namespace Impostor.Api;
+
+public enum CheatCategory
+{
+ /// <summary>A packet used a part of the network protocol that is unknown to Impostor, like a custom RPC.</summary>
+ ProtocolExtension,
+
+ /// <summary>A packet was sent at an inappropriate moment.</summary>
+ GameFlow,
+
+ /// <summary>A packet was sent by a non-host player that should normally only be sent by the host.</summary>
+ MustBeHost,
+
+ /// <summary>A packet was sent that violated limits on the selection of player colors.</summary>
+ ColorLimits,
+
+ /// <summary>A packet was sent that exceeded the limits of possible nicknames to enter ingame.</summary>
+ NameLimits,
+
+ /// <summary>A packet was sent on behalf of another player.</summary>
+ Ownership,
+
+ /// <summary>An ability was used that the current role cannot access.</summary>
+ Role,
+
+ /// <summary>A packet was sent to a player that should be broadcasted, or vice versa.</summary>
+ Target,
+
+ /// <summary>Legacy category for unsorted anticheat checks.</summary>
+ Other,
+}
public bool Enabled { get; set; } = true;
public bool BanIpFromGame { get; set; } = true;
+
+ public CheatingHostMode AllowCheatingHosts { get; set; } = CheatingHostMode.Never;
+
+ public bool EnableGameFlowChecks { get; set; } = true;
+
+ public bool EnableMustBeHostChecks { get; set; } = true;
+
+ public bool EnableColorLimitChecks { get; set; } = true;
+
+ public bool EnableNameLimitChecks { get; set; } = true;
+
+ public bool EnableOwnershipChecks { get; set; } = true;
+
+ public bool EnableRoleChecks { get; set; } = true;
+
+ public bool EnableTargetChecks { get; set; } = true;
+
+ public bool ForbidProtocolExtensions { get; set; } = true;
}
}
--- /dev/null
+namespace Impostor.Api.Config
+{
+ /// <summary>
+ /// Details if exceptions are made for hosts that are cheating.
+ /// </summary>
+ public enum CheatingHostMode
+ {
+ /// <summary>
+ /// Hosts follow the same policies as other players.
+ /// </summary>
+ Never,
+
+ /// <summary>
+ /// Hosts are allowed to cheat if they request HostAuthority. If they
+ /// do not request this, the same policies as for other players applies.
+ /// </summary>
+ /// <para>
+ /// HostAuthority can be requested by hosts by adding 25 to their patch
+ /// version when connecting. This flag is used by a lot of (host-only)
+ /// mods and also disable server authority over MurderPlayer packets.
+ /// </para>
+ IfRequested,
+
+ /// <summary>
+ /// Hosts are always allowed to cheat.
+ /// </summary>
+ Always,
+ }
+}
+using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Impostor.Api.Innersloth;
/// </summary>
PlatformSpecificData PlatformSpecificData { get; }
+ ValueTask<bool> ReportCheatAsync(CheatContext context, CheatCategory category, string message);
+
+ [Obsolete("Please use the overload that adds a cheat category")]
ValueTask<bool> ReportCheatAsync(CheatContext context, string message);
ValueTask HandleMessageAsync(IMessageReader message, MessageType messageType);
_customMessageManager = customMessageManager;
}
- public override async ValueTask<bool> ReportCheatAsync(CheatContext context, string message)
+ public override async ValueTask<bool> ReportCheatAsync(CheatContext context, CheatCategory category, string message)
{
if (!_antiCheatConfig.Enabled)
{
return false;
}
- _logger.LogWarning("Client {Name} ({Id}) was caught cheating: [{Context}] {Message}", Name, Id, context.Name, message);
+ if (Player != null && Player.IsHost)
+ {
+ var isHostCheatingAllowed = _antiCheatConfig.AllowCheatingHosts switch {
+ CheatingHostMode.Always => true,
+ CheatingHostMode.IfRequested => GameVersion.HasDisableServerAuthorityFlag,
+ CheatingHostMode.Never => false,
+ _ => false,
+ };
+
+ if (isHostCheatingAllowed)
+ {
+ return false;
+ }
+ }
+
+ bool LogUnknownCategory(CheatCategory category)
+ {
+ _logger.LogWarning("Unknown cheat category {Category} was used when reporting", category);
+ return true;
+ }
+
+ var isCategoryEnabled = category switch
+ {
+ CheatCategory.ProtocolExtension => _antiCheatConfig.ForbidProtocolExtensions,
+ CheatCategory.GameFlow => _antiCheatConfig.EnableGameFlowChecks,
+ CheatCategory.MustBeHost => _antiCheatConfig.EnableMustBeHostChecks,
+ CheatCategory.ColorLimits => _antiCheatConfig.EnableColorLimitChecks,
+ CheatCategory.NameLimits => _antiCheatConfig.EnableNameLimitChecks,
+ CheatCategory.Ownership => _antiCheatConfig.EnableOwnershipChecks,
+ CheatCategory.Role => _antiCheatConfig.EnableRoleChecks,
+ CheatCategory.Target => _antiCheatConfig.EnableTargetChecks,
+ CheatCategory.Other => true,
+ _ => LogUnknownCategory(category),
+ };
+
+ if (!isCategoryEnabled)
+ {
+ return false;
+ }
+
+ _logger.LogWarning("Client {Name} ({Id}) was caught cheating: [{Context}-{Category}] {Message}", Name, Id, context.Name, category, message);
if (_antiCheatConfig.BanIpFromGame)
{
IClientPlayer? IClient.Player => Player;
- public virtual ValueTask<bool> ReportCheatAsync(CheatContext context, string message)
+ public virtual ValueTask<bool> ReportCheatAsync(CheatContext context, CheatCategory category, string message)
{
return new ValueTask<bool>(false);
}
+ public ValueTask<bool> ReportCheatAsync(CheatContext context, string message)
+ {
+ return ReportCheatAsync(context, CheatCategory.Other, message);
+ }
+
public abstract ValueTask HandleMessageAsync(IMessageReader message, MessageType messageType);
public abstract ValueTask HandleDisconnectAsync(string reason);
{
if (!sender.IsOwner(this))
{
- if (await sender.Client.ReportCheatAsync(context, $"Failed ownership check on {GetType().Name}"))
+ if (await sender.Client.ReportCheatAsync(context, CheatCategory.Ownership, $"Failed ownership check on {GetType().Name}"))
{
return false;
}
{
if (!sender.IsHost)
{
- if (await sender.Client.ReportCheatAsync(context, "Failed host check"))
+ if (await sender.Client.ReportCheatAsync(context, CheatCategory.MustBeHost, "Failed host check"))
{
return false;
}
{
if (target == null)
{
- if (await sender.Client.ReportCheatAsync(context, "Failed target check"))
+ if (await sender.Client.ReportCheatAsync(context, CheatCategory.Target, "Failed target check"))
{
return false;
}
{
if (target != null)
{
- if (await sender.Client.ReportCheatAsync(context, "Failed broadcast check"))
+ if (await sender.Client.ReportCheatAsync(context, CheatCategory.Target, "Failed broadcast check"))
{
return false;
}
{
if (target == null || !target.IsHost)
{
- if (await sender.Client.ReportCheatAsync(context, "Failed cmd check"))
+ if (await sender.Client.ReportCheatAsync(context, CheatCategory.Target, "Failed cmd check"))
{
return false;
}
{
if (playerInfo.IsImpostor != value)
{
- if (await sender.Client.ReportCheatAsync(context, "Failed impostor check"))
+ if (await sender.Client.ReportCheatAsync(context, CheatCategory.Role, "Failed impostor check"))
{
return false;
}
{
if (playerInfo.CanVent != value)
{
- if (await sender.Client.ReportCheatAsync(context, "Failed can vent check"))
+ if (await sender.Client.ReportCheatAsync(context, CheatCategory.Role, "Failed can vent check"))
{
return false;
}
{
if (playerInfo.RoleType != role)
{
- if (await sender.Client.ReportCheatAsync(context, $"Failed role = {role} check"))
+ if (await sender.Client.ReportCheatAsync(context, CheatCategory.Role, $"Failed role = {role} check"))
{
return false;
}
protected async ValueTask<bool> UnregisteredCall(CheatContext context, IClientPlayer sender)
{
- if (await sender.Client.ReportCheatAsync(context, "Client sent unregistered call"))
+ if (await sender.Client.ReportCheatAsync(context, CheatCategory.ProtocolExtension, "Client sent unregistered call"))
{
return false;
}
using System;
using System.Threading.Tasks;
+using Impostor.Api;
using Impostor.Api.Events.Managers;
using Impostor.Api.Net;
using Impostor.Api.Net.Custom;
if (Game.GameNet.ShipStatus == null)
{
- if (await sender.Client.ReportCheatAsync(call, "Client interacted with vent on unknown map"))
+ if (await sender.Client.ReportCheatAsync(call, CheatCategory.ProtocolExtension, "Client interacted with vent on unknown map"))
{
return false;
}
if (!Game.GameNet.ShipStatus.Data.Vents.TryGetValue(ventId, out var vent))
{
- if (await sender.Client.ReportCheatAsync(call, "Client interacted with nonexistent vent"))
+ if (await sender.Client.ReportCheatAsync(call, CheatCategory.ProtocolExtension, "Client interacted with nonexistent vent"))
{
return false;
}
if (clientId != sender.Client.Id)
{
- if (await sender.Client.ReportCheatAsync(RpcCalls.AddVote, $"Client sent {nameof(RpcCalls.AddVote)} as other client"))
+ if (await sender.Client.ReportCheatAsync(RpcCalls.AddVote, CheatCategory.Ownership, $"Client sent {nameof(RpcCalls.AddVote)} as other client"))
{
return false;
}
if (playerId != sender.Character!.PlayerId)
{
- if (await sender.Client.ReportCheatAsync(RpcCalls.CastVote, $"Client sent {nameof(RpcCalls.CastVote)} to an unowned {nameof(InnerPlayerControl)}"))
+ if (await sender.Client.ReportCheatAsync(RpcCalls.CastVote, CheatCategory.Ownership, $"Client sent {nameof(RpcCalls.CastVote)} to an unowned {nameof(InnerPlayerControl)}"))
{
return false;
}
}
Rpc39SetHatStr.Deserialize(reader, out var hat);
- return true;
+ return await HandleSetHat(sender, hat);
}
case RpcCalls.SetSkinStr:
}
Rpc40SetSkinStr.Deserialize(reader, out var skin);
- return true;
+ return await HandleSetSkin(sender, skin);
}
case RpcCalls.SetVisorStr:
}
Rpc42SetVisorStr.Deserialize(reader, out var visor);
- return true;
+ return await HandleSetVisor(sender, visor);
}
case RpcCalls.SetNamePlateStr:
}
Rpc43SetNamePlateStr.Deserialize(reader, out var namePlate);
- return true;
+ return await HandleSetNamePlate(sender, namePlate);
}
case RpcCalls.SetLevel:
{
if (name.Length > 10)
{
- if (await sender.Client.ReportCheatAsync(RpcCalls.CheckName, "Client sent name exceeding 10 characters"))
+ if (await sender.Client.ReportCheatAsync(RpcCalls.CheckName, CheatCategory.NameLimits, "Client sent name exceeding 10 characters"))
{
return false;
}
if (string.IsNullOrWhiteSpace(name) || !name.All(TextBox.IsCharAllowed))
{
- if (await sender.Client.ReportCheatAsync(RpcCalls.CheckName, "Client sent name containing illegal characters"))
+ if (await sender.Client.ReportCheatAsync(RpcCalls.CheckName, CheatCategory.NameLimits, "Client sent name containing illegal characters"))
{
return false;
}
if (sender.Client.Name != name)
{
- if (await sender.Client.ReportCheatAsync(RpcCalls.CheckName, "Client sent name not matching his name from handshake"))
+ if (await sender.Client.ReportCheatAsync(RpcCalls.CheckName, CheatCategory.GameFlow, "Client sent name not matching his name from handshake"))
{
return false;
}
{
if (Game.GameState == GameStates.Started)
{
- if (await sender.Client.ReportCheatAsync(RpcCalls.SetColor, "Client tried to set a name midgame"))
+ if (await sender.Client.ReportCheatAsync(RpcCalls.SetColor, CheatCategory.GameFlow, "Client tried to set a name midgame"))
{
return false;
}
{
if (Game.Players.Any(x => x.Character != null && x.Character != this && x.Character.PlayerInfo.PlayerName == name))
{
- if (await sender.Client.ReportCheatAsync(RpcCalls.SetName, "Client sent name that is already used"))
+ if (await sender.Client.ReportCheatAsync(RpcCalls.SetName, CheatCategory.NameLimits, "Client sent name that is already used"))
{
return false;
}
if (sender.Client.Name != name)
{
- if (await sender.Client.ReportCheatAsync(RpcCalls.SetName, "Client sent name not matching his name from handshake"))
+ if (await sender.Client.ReportCheatAsync(RpcCalls.SetName, CheatCategory.GameFlow, "Client sent name not matching his name from handshake"))
{
return false;
}
}
else
{
- if (await sender.Client.ReportCheatAsync(RpcCalls.SetName, $"Client sent {nameof(RpcCalls.SetName)} for a player that didn't request it"))
+ if (await sender.Client.ReportCheatAsync(RpcCalls.SetName, CheatCategory.GameFlow, $"Client sent {nameof(RpcCalls.SetName)} for a player that didn't request it"))
{
return false;
}
private async ValueTask<bool> HandleCheckColor(ClientPlayer sender, ColorType color)
{
+ if (Game.GameState == GameStates.Started)
+ {
+ if (await sender.Client.ReportCheatAsync(RpcCalls.CheckColor, CheatCategory.GameFlow, "Client tried to ask for a color midgame"))
+ {
+ return false;
+ }
+ }
+
if ((byte)color > ColorsCount)
{
- if (await sender.Client.ReportCheatAsync(RpcCalls.CheckColor, "Client sent invalid color"))
+ if (await sender.Client.ReportCheatAsync(RpcCalls.CheckColor, CheatCategory.ProtocolExtension, "Client sent invalid color"))
{
return false;
}
{
if (Game.GameState == GameStates.Started)
{
- if (await sender.Client.ReportCheatAsync(RpcCalls.SetColor, "Client tried to set a color midgame"))
+ if (await sender.Client.ReportCheatAsync(RpcCalls.SetColor, CheatCategory.GameFlow, "Client tried to set a color midgame"))
{
return false;
}
{
if (Game.Players.Any(x => x.Character != null && x.Character != this && x.Character.PlayerInfo.CurrentOutfit.Color == color))
{
- if (await sender.Client.ReportCheatAsync(RpcCalls.SetColor, "Client sent a color that is already used"))
+ if (await sender.Client.ReportCheatAsync(RpcCalls.SetColor, CheatCategory.ColorLimits, "Client sent a color that is already used"))
{
return false;
}
private async ValueTask<bool> HandleSetHat(ClientPlayer sender, string hat)
{
- if (Game.GameState == GameStates.Started && await sender.Client.ReportCheatAsync(RpcCalls.SetHat, "Client tried to change hat while not in lobby"))
+ if (Game.GameState == GameStates.Started &&
+ await sender.Client.ReportCheatAsync(RpcCalls.SetHat, CheatCategory.GameFlow, "Client tried to change hat while not in lobby"))
{
return false;
}
private async ValueTask<bool> HandleSetSkin(ClientPlayer sender, string skin)
{
- if (Game.GameState == GameStates.Started && await sender.Client.ReportCheatAsync(RpcCalls.SetSkin, "Client tried to change skin while not in lobby"))
+ if (Game.GameState == GameStates.Started &&
+ await sender.Client.ReportCheatAsync(RpcCalls.SetSkin, CheatCategory.GameFlow, "Client tried to change skin while not in lobby"))
{
return false;
}
return true;
}
+ private async ValueTask<bool> HandleSetVisor(ClientPlayer sender, string visor)
+ {
+ if (Game.GameState == GameStates.Started &&
+ await sender.Client.ReportCheatAsync(RpcCalls.SetVisor, CheatCategory.GameFlow, "Client tried to change visor while not in lobby"))
+ {
+ return false;
+ }
+
+ PlayerInfo.CurrentOutfit.VisorId = visor;
+
+ return true;
+ }
+
+ private async ValueTask<bool> HandleSetNamePlate(ClientPlayer sender, string skin)
+ {
+ if (Game.GameState == GameStates.Started &&
+ await sender.Client.ReportCheatAsync(RpcCalls.SetNamePlate, CheatCategory.GameFlow, "Client tried to change skin while not in lobby"))
+ {
+ return false;
+ }
+
+ PlayerInfo.CurrentOutfit.NamePlateId = skin;
+
+ return true;
+ }
+
private async ValueTask<bool> HandleCheckMurder(ClientPlayer sender, InnerPlayerControl? target)
{
if (!PlayerInfo.CanMurder(Game, _dateTimeProvider))
// This request was made too quickly by spamming the kill button, cancel it if we're in server authoritive mode
return _game.IsHostAuthoritive;
}
- else if (await sender.Client.ReportCheatAsync(RpcCalls.CheckMurder, "Client tried to murder too fast"))
+ else if (await sender.Client.ReportCheatAsync(RpcCalls.CheckMurder, CheatCategory.GameFlow, "Client tried to murder too fast"))
{
return false;
}
if (target == null || target.PlayerInfo.IsImpostor)
{
- if (await sender.Client.ReportCheatAsync(RpcCalls.CheckMurder, "Client tried to murder invalid target"))
+ if (await sender.Client.ReportCheatAsync(RpcCalls.CheckMurder, CheatCategory.GameFlow, "Client tried to murder invalid target"))
{
return false;
}
{
if (!_game.IsHostAuthoritive)
{
- if (await sender.Client.ReportCheatAsync(RpcCalls.MurderPlayer, "Client tried to murder directly"))
+ if (await sender.Client.ReportCheatAsync(RpcCalls.MurderPlayer, CheatCategory.GameFlow, "Client tried to murder directly"))
{
return false;
}
if (target == null || target.PlayerInfo.IsImpostor)
{
- if (await sender.Client.ReportCheatAsync(RpcCalls.MurderPlayer, "Client tried to murder invalid target"))
+ if (await sender.Client.ReportCheatAsync(RpcCalls.MurderPlayer, CheatCategory.GameFlow, "Client tried to murder invalid target"))
{
return false;
}
// If the host is also the impostor that committed the murder, CheckMurder is actually sent *after* the MurderPlayer RPC
if (sender.Character != this && target != IsMurdering)
{
- if (await sender.Client.ReportCheatAsync(RpcCalls.MurderPlayer, "Host tried to murder incorrect target"))
+ if (await sender.Client.ReportCheatAsync(RpcCalls.MurderPlayer, CheatCategory.GameFlow, "Host tried to murder incorrect target"))
{
return false;
}
{
if (target == null)
{
- if (await sender.Client.ReportCheatAsync(RpcCalls.CheckProtect, "Client tried to protect invalid target"))
+ if (await sender.Client.ReportCheatAsync(RpcCalls.CheckProtect, CheatCategory.Target, "Client tried to protect invalid target"))
{
return false;
}
return true;
}
- if (PlayerInfo.RoleType != RoleTypes.GuardianAngel)
+ if (await ValidateRole(RpcCalls.ProtectPlayer, sender, PlayerInfo, RoleTypes.GuardianAngel))
{
- if (await sender.Client.ReportCheatAsync(RpcCalls.CheckProtect, "Client tried to protect but it wasn't a guardian angel"))
- {
return false;
- }
}
((InnerPlayerControl)target).Protect(this);
private async ValueTask<bool> HandleSetPet(ClientPlayer sender, string pet)
{
- if (Game.GameState == GameStates.Started && await sender.Client.ReportCheatAsync(RpcCalls.SetPet, "Client tried to change pet while not in lobby"))
+ if (Game.GameState == GameStates.Started &&
+ await sender.Client.ReportCheatAsync(RpcCalls.SetPet, CheatCategory.GameFlow, "Client tried to change pet while not in lobby"))
{
return false;
}
{
if (!sender.IsHost && startCounter != -1)
{
- if (await sender.Client.ReportCheatAsync(RpcCalls.MurderPlayer, "Client tried to set start counter as a non-host"))
+ if (await sender.Client.ReportCheatAsync(RpcCalls.SetStartCounter, CheatCategory.MustBeHost, "Client tried to set start counter as a non-host"))
{
return false;
}
case GameDataTag.SpawnFlag:
{
- // Only the host is allowed to despawn objects.
+ // Only the host is allowed to spawn objects.
if (!sender.IsHost)
{
- if (await sender.Client.ReportCheatAsync(new CheatContext(nameof(GameDataTag.SpawnFlag)), "Tried to send SpawnFlag as non-host."))
+ if (await sender.Client.ReportCheatAsync(new CheatContext(nameof(GameDataTag.SpawnFlag)), CheatCategory.MustBeHost, "Tried to send SpawnFlag as non-host."))
{
return false;
}
if (clientId != sender.Client.Id)
{
- if (await sender.Client.ReportCheatAsync(new CheatContext(nameof(GameDataTag.ConsoleDeclareClientPlatformFlag)), "Client sent info with wrong client id"))
+ if (await sender.Client.ReportCheatAsync(new CheatContext(nameof(GameDataTag.ConsoleDeclareClientPlatformFlag)), CheatCategory.Ownership, "Client sent info with wrong client id"))
{
return false;
}
}
else
{
- await sender.Client.ReportCheatAsync(new CheatContext(nameof(GameDataTag.SpawnFlag)), "Failed to find player that spawned the InnerPlayerControl");
+ await sender.Client.ReportCheatAsync(new CheatContext(nameof(GameDataTag.SpawnFlag)), CheatCategory.GameFlow, "Failed to find player that spawned the InnerPlayerControl");
}
// Hook up InnerPlayerControl <-> InnerPlayerControl.PlayerInfo.