Console Commands and Server Administration
The command system in Unturned consists of the Command base class, the Commander static registry that manages registered commands, and over 80 concrete command implementations that span server administration, gameplay manipulation, debug tooling, and configuration. This article covers the command infrastructure and the most important server administration commands.
Source code location: Unturned/Command/Command.cs, Commander.cs, CommandAdmin.cs, CommandBan.cs, CommandKick.cs, CommandSave.cs, CommandShutdown.cs, CommandSay.cs, CommandTeleport.cs, CommandGive.cs, CommandVehicle.cs, CommandWeather.cs
The Command Base Class
Command is defined in SDG.Unturned and implements IComparable<Command> for sorted registration:
csharp
public class Command : IComparable<Command>
{
protected Local localization;
protected string _command; // The command keyword (e.g. "ban")
protected string _info; // One-line description
protected string _help; // Usage help text
public string command => _command;
public string info => _info;
public string help => _help;
protected virtual void execute(CSteamID executorID, string parameter);
public virtual bool check(CSteamID executorID, string method, string parameter)
{
if (method.ToLower() == command.ToLower())
{
execute(executorID, parameter);
return true;
}
return false;
}
}The check method performs a case-insensitive match against the command keyword. If matched, it calls execute with the raw parameter string. Subclasses override execute to implement their behavior. The Localization instance provides translated command text, info, and help via formatted keys.
Commander — Registration and Dispatch
Commander is a static class that owns a List<Command> sorted alphabetically:
csharp
public static void register(Command command)
{
int insert = commands.BinarySearch(command);
if (insert < 0) insert = ~insert;
commands.Insert(insert, command);
}The execute method parses the input string into a method name (text before the first space) and a parameter string (text after), then iterates through registered commands calling check. If a command matches, dispatch stops:
csharp
public static bool execute(CSteamID executorID, string command)
{
string method = command;
string parameter = "";
int split = command.IndexOf(' ');
if (split != -1)
{
method = command.Substring(0, split);
parameter = command.Substring(split + 1);
}
for (int i = 0; i < commands.Count; i++)
if (commands[i].check(executorID, method, parameter))
return true;
return false;
}init() registers all built-in commands. Plugins use register and deregister to add or remove their own commands. execute_UnityEvent allows Unity event components to execute commands with permission checking via onCheckUnityEventPermissions.
Admin Command
CommandAdmin grants admin status to a player. It requires a dedicated server that is currently running. The command resolves the player by SteamID using PlayerTool.tryGetSteamID, then calls SteamAdminlist.admin(steamID, executorID) to add the player to the admin list:
csharp
SteamAdminlist.admin(steamID, executorID);
CommandWindow.Log(localization.format("AdminText", steamID));The SteamAdminlist.admin method either updates the judge ID if the player is already an admin, or adds a new SteamAdminID entry. If the player is currently connected, it sets client.isAdmin = true and broadcasts an Admined network message to other clients (respecting Provider.hideAdmins).
Ban Command
CommandBan supports three parameter forms: ban <name>, ban <name>/<reason>, and ban <name>/<reason>/<duration>. Duration is in seconds; SteamBlacklist.PERMANENT (1 year) is used when omitted.
The command gathers identification data for the ban: the SteamID, the player's IPv4 address (via NetTransport.ITransportConnection.TryGetIPv4Address), and HWID hashes from the online SteamPlayer. If the player is offline, HWIDs are null:
csharp
NetTransport.ITransportConnection transportConnection = Provider.findTransportConnection(steamID);
uint ip = 0;
if (transportConnection != null) transportConnection.TryGetIPv4Address(out ip);
SteamPlayer onlineClient = PlayerTool.getSteamPlayer(steamID);
hwids = onlineClient?.playerID.GetHwids();The ban is executed via Provider.requestBanPlayer, which writes the entry to SteamBlacklist and kicks the player if connected.
Kick Command
CommandKick supports kick <name> and kick <name>/<reason>. Unlike ban, kick only works on currently connected players — it uses PlayerTool.tryGetSteamPlayer which requires an online SteamPlayer. The player is kicked via Provider.kick with the specified reason:
csharp
Provider.kick(player.playerID.steamID, components[1]);
CommandWindow.Log(localization.format("KickText", player.playerID.playerName));Save Command
CommandSave is the simplest command in the set — it calls SaveManager.save() with no parameter parsing and no platform restrictions. The SaveManager.save method broadcasts a pre-save event, iterates through connected players calling save(), then saves each manager: VehicleManager.save(), BarricadeManager.save(), StructureManager.save(), ObjectManager.save(), LightingManager.save(), and GroupManager.save(). On dedicated servers, it also saves the whitelist, blacklist, and admin list.
Shutdown Command
CommandShutdown controls server lifecycle. With no parameters, it calls Provider.shutdown() immediately. With a timer parameter, it schedules a delayed shutdown:
csharp
if (components.Length == 0)
Provider.shutdown();
else
{
int timer;
if (!int.TryParse(components[0], out timer))
return;
string explanation = components.Length > 1 ? components[1] : "";
Provider.shutdown(timer, explanation);
}The Provider.shutdown overloads handle both immediate and timed server termination.
Say Command
CommandSay sends a chat message from the server. Two forms are supported: say <message> uses Palette.SERVER (default server color), while say <message>/<R>/<G>/<B> parses RGB byte values (0-255) to produce a custom color:
csharp
ChatManager.say(components[0], new Color(r / 255f, g / 255f, b / 255f));Teleport Command
CommandTeleport provides four teleport modes:
- Teleport to player (
teleport <targetPlayer>orteleport <sourcePlayer>/<targetPlayer>) - Teleport to waypoint (
teleport <player>/waypointorteleport waypoint) - Teleport to bed (
teleport <player>/bedorteleport bed) - Teleport to location node (
teleport <player>/<locationName>)
The raycastFromSkyToPosition helper casts a ray from Y=1024 downward to find ground level, using RayMasks.WAYPOINT. The raycastFromNearPosition helper casts from 4 units above the target point for indoor teleport nodes. All teleportation goes through player.teleportToPlayer or player.teleportToLocation, which return a boolean indicating if the teleport succeeded or was obstructed.
Give Command
CommandGive spawns items or grants currency. It requires Provider.hasCheats to be true. Parameter forms are give <item>, give <player>/<item>, and give <player>/<item>/<amount>.
The item resolution follows a three-tier search:
- GUID lookup — if the parameter parses as a
System.Guid, it queriesAssets.find(parsedGuid) - Legacy ID lookup — if the parameter parses as a
ushort, it usesItemTool.tryForceGiveItem - String search —
FindByStringperforms a four-pass search over allItemAssetinstances: exact file name match, exact display name match, partial file name match, partial display name match
If the resolved asset is an ItemAsset, it calls giveItem which delegates to ItemTool.tryForceGiveItem. If it is an ItemCurrencyAsset, it calls currency.grantValue directly.
Vehicle Command
CommandVehicle spawns a vehicle for a player. Like CommandGive, it requires cheats enabled. The vehicle asset resolution follows the same three-tier pattern (GUID → legacy ID → string search over VehicleAsset instances). Once resolved, VehicleTool.SpawnVehicleForPlayer instantiates the vehicle and assigns it to the player:
csharp
InteractableVehicle spawnedVehicle = VehicleTool.SpawnVehicleForPlayer(player.player, vehicleAsset);If the spawn fails (null result), an error is logged with the asset's friendly name.
Weather Command
CommandWeather controls the weather system. The command passes the parameter through multiple resolution paths:
- Zero parameter — cancels custom weather via
LightingManager.ResetScheduledWeather() - GUID parameter — attempts
AssetReference<WeatherAssetBase>.TryParse. If valid, it callsLightingManager.ForecastWeatherImmediatelyor falls back toLightingManager.ActivatePerpetualWeather - Named modes —
none(reset),disable(disable weather entirely),storm(toggle default rain),blizzard(toggle default snow)
The toggle behavior for storm and blizzard checks LightingManager.IsWeatherActive first — if the weather is already active, it resets it; if not, it forecasts it immediately.
