Skip to main content

Server

Server-side utilities for sending commands to player clients.

public static class Server

Namespace: DeadworksManaged.Api
Source: Server.cs#L7

Properties​

Server.MapName​

The current map name, set when the server starts up.

Signature

public static string MapName { get; internal set; } = "";

Source: Server.cs#L9

Server.IsChangingLevel​

True while the map is changing, until the next map's IDeadworksPlugin.OnStartupServer. It turns on at ChangeLevel, or for a change started elsewhere, such as changelevel in the server console, once the current map starts shutting down, which is before every player gets a disconnect event with ClientDisconnectedEvent.IsMapChange. Anything done to players, pawns or panels meanwhile is lost with the old map. If the change fails, such as for a map that doesn't exist, it turns off again after a few seconds.

Signature

public static bool IsChangingLevel { get; }

Source: Server.cs#L18

Methods​

Server.ChangeLevel()​

Change to map. Everyone connected stays connected and reloads into it; see ClientConnectEvent.IsMapChangeReconnect. IsChangingLevel is true from this call.

Signature

public static void ChangeLevel(string map)

Parameters

  • map: A map name, such as dl_midtown.

Throws

  • ArgumentException: map is empty or isn't a plain map name.

Source: Server.cs#L32

Server.ClientCommand()​

Sends a console command to the client in the given slot.

Signature

public static void ClientCommand(int slot, string command)

Source: Server.cs#L60

Server.ExecuteCommand()​

Executes a command on the server console.

Signature

public static void ExecuteCommand(string command)
public static void ExecuteCommand(string command, Action<string> onOutput)

Source: Server.cs#L68, Server.cs#L287

Server.ExecuteCommandAsPlayer()​

Runs a server command as if the player in slot sent it. Cheat commands run even with sv_cheats off, and plugin commands still check the player's permissions.

Signature

public static bool ExecuteCommandAsPlayer(int slot, string command)

Parameters

Returns False if there is no such command or the slot is invalid.

Source: Server.cs#L82

Server.SetAddons()​

Sets the server's addons string. Clients receive this in SignonState/connection messages.

Signature

public static void SetAddons(string addons)

Source: Server.cs#L90

Server.AddSearchPath()​

Adds a search path to the engine's filesystem. Use pathID "GAME" for general content.

Signature

public static bool AddSearchPath(string path, string pathID = "GAME", bool addToHead = true)

Parameters

  • path: Path to a directory or VPK file.
  • pathID: Search path group (e.g. "GAME", "MOD").
  • addToHead: If true, path is searched first (highest priority).

Source: Server.cs#L101

Server.EnumerateConVars()​

Enumerates all registered ConVars by index.

Signature

public static List<ConVarEntry> EnumerateConVars()

Source: Server.cs#L111

Server.EnumerateConCommands()​

Enumerates all registered ConCommands by index.

Signature

public static List<ConCommandEntry> EnumerateConCommands()

Source: Server.cs#L125

Server.AddEngineLogListener()​

Adds a listener to receive all engine logging output. Multiple listeners are supported.

Signature

public static void AddEngineLogListener(EngineLogHandler handler)

Source: Server.cs#L156

Server.RemoveEngineLogListener()​

Removes a previously added engine log listener. The native listener is unregistered when the last listener is removed.

Signature

public static void RemoveEngineLogListener(EngineLogHandler handler)

Source: Server.cs#L170

Server.CreateFakeClient()​

Connects a fake client ("bot") that occupies a real player slot but has no netchannel. Returns its player slot, or -1 when the engine had no slot free. An unreserved Deadlock server keeps no slots at all, so this fails until a match has been set up.

Signature

public static int CreateFakeClient(string name)

Source: Server.cs#L186

Server.Kick()​

Disconnects the player in slot. They're sent back to the main menu without being told why, so tell them first if they should know. The reason is for plugins: it's what IDeadworksPlugin.OnClientDisconnecting and IDeadworksPlugin.OnClientDisconnect see.

Signature

public static void Kick(int slot, ENetworkDisconnectionReason reason = ENetworkDisconnectionReason.NetworkDisconnectKicked)
public static void Kick(int slot, string message, ENetworkDisconnectionReason reason = ENetworkDisconnectionReason.NetworkDisconnectKicked)

Source: Server.cs#L198, Server.cs#L205

Server.GetMapList()​

Maps the server can change to: the game's own .vpk maps plus extra_maps from deadworks.jsonc, sorted by name.

Signature

public static IReadOnlyList<string> GetMapList()

Source: Server.cs#L236

Server.IsMapValid()​

Whether map can be loaded: the engine knows it, or it's in GetMapList. Names with spaces, quotes, ; or path tricks are always rejected, so a valid name is safe to put in a command.

Signature

public static bool IsMapValid(string map)

Source: Server.cs#L254

Server.ChangeMap()​

Changes to map if IsMapValid accepts it. Returns false otherwise.

Signature

public static bool ChangeMap(string map)

Source: Server.cs#L273

Server.HasCommandLineParm()​

Returns true if the given parameter is present on the engine command line (e.g. "-nomaster").

Signature

public static bool HasCommandLineParm(string parm)

Source: Server.cs#L295