codeAPI Reference

s&box BanSystem: Player ban management

calendar_today May 12, 2026 schedule ~2 min read person PatrickJr verified 50

BanSystem GameObjectSystem API Reference

BanSystem holds a banlist and can ban users. Implements INetworkListener to reject banned connections. Bans are persisted to LocalData.

Type Signature

CSHARP
public sealed class BanSystem : GameObjectSystem<BanSystem>, Component.INetworkListener
{
    public record struct BanEntry(string DisplayName, string Reason);

    public void Ban(Connection connection, string reason);
    public void Ban(SteamId steamId, string reason);
    public void Unban(SteamId steamId);
    public bool IsBanned(SteamId steamId);
    public IReadOnlyDictionary<SteamId, BanEntry> GetBannedList();

    [Rpc.Host] public static void RpcBanPlayer(Connection target, string reason = "Banned");
    [ConCmd("ban")] public static void BanCommand(string target, string reason = "Banned");
}

Methods

Ban(Connection connection, string reason)

Bans a connected player and kicks them immediately. Host-only.

Ban(SteamId steamId, string reason)

Bans a Steam ID by value. Use for pre-banning or banning players who are not currently connected. Display name falls back to the Steam ID string. Host-only.

Unban(SteamId steamId)

Removes the ban for the given Steam ID. Host-only.

IsBanned(SteamId steamId)

Returns true if the given Steam ID is currently banned.

GetBannedList()

Returns a read-only view of all active bans.

INetworkListener Implementation

RPC

RpcBanPlayer(Connection target, string reason = "Banned")

RPC to ban a connected player. Caller must be host or have admin permission.

Console Command

ban [name|steamid] [reason]

Bans a player by name or Steam ID. Optionally provide a reason. Host-only. Tries parsing as Steam ID first, falls back to partial name match.

Behavior

  • Bans are persisted to LocalData under "bans" key
  • Chat notification when a player is banned
  • Connection rejection with reason message for banned players

Usage

CSHARP
// Ban a connected player
BanSystem.Current.Ban(connection, "Griefing");

// Ban by Steam ID
BanSystem.Current.Ban(steamId, "Pre-banned");

// Unban
BanSystem.Current.Unban(steamId);

// Check if banned
if (BanSystem.Current.IsBanned(steamId))
{
    // Handle banned player
}

// Console command
// ban "PlayerName" "Reason"
// ban 76561198000000000 "Reason"

Notes

  • Host-only operations (enforced via Assert)
  • Uses LocalData for persistence
  • Supports both connected and offline banning
  • Partial name matching for console command
Was this helpful?