codeAPI Reference

s&box BanSystem: Ban list management with persistence

calendar_today May 12, 2026 schedule ~1 min read person patrickjr verified 50

BanSystem API Reference

BanSystem is a GameObjectSystem that manages a ban list with LocalData persistence and connection blocking.

Type Signature

CSHARP
public sealed class BanSystem : GameObjectSystem<BanSystem>, Component.INetworkListener

Key Methods

INetworkListener Implementation

CSHARP
bool Component.INetworkListener.AcceptConnection(Connection connection, ref string reason)
{
    if (!_bans.TryGetValue(connection.SteamId, out var entry))
        return true;
    
    reason = $"You're banned from this server: {entry.Reason}";
    return false;
}

BanEntry Record

CSHARP
public record struct BanEntry(string DisplayName, string Reason);

Console Command

CSHARP
[ConCmd("ban")]
public static void BanCommand(string target, string reason = "Banned")
Bans a player by name or Steam ID. Usage: ban [name|steamid] [reason]

Notes

  • Ban list is persisted using LocalData.Set("bans", _bans) and loaded in constructor.
  • AcceptConnection hook blocks banned players before they fully connect.
  • Supports both name matching (partial) and Steam ID (64-bit integer) targeting.
Was this helpful?