codeAPI Reference
s&box BanSystem: Ban list management with persistence
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.INetworkListenerKey Methods
- void Ban(Connection connection, string reason) - Bans a connected player and kicks them immediately. Host only.
- void Ban(SteamId steamId, string reason) - Bans a Steam ID by value (for pre-banning or offline players). Host only.
- void Unban(SteamId steamId) - Removes the ban for the given Steam ID. Host only.
- bool IsBanned(SteamId steamId) - Returns true if the given Steam ID is currently banned.
- IReadOnlyDictionary<SteamId, BanEntry> GetBannedList() - Returns a read-only view of all active bans.
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")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?