server
The game's server library.
Modules
Classes & types
Fields
| Name | Type | Description |
|---|---|---|
singleplayer | boolean | true if server is running in singleplayer mode, false otherwise. READ-ONLY |
dedicated | boolean | true if server is running as a dedicated server, false otherwise. READ-ONLY |
tickrate | number | The configured number of server ticks per second, see TPS for the measured one. READ-ONLY |
slots | integer | The maximum number of players the server can hold. READ-ONLY |
gamemode | string | The name of the active gamemode, "base" if unknown. READ-ONLY |
ipv4 | integer | The public IPv4 address of the server as an unsigned 32-bit integer, 0x7F000001 ( 127.0.0.1 ) for local servers. READ-ONLY |
port | integer | The public UDP port of the server, 27015 by default. READ-ONLY |
address | string | The public address of the server in the ip:port format. READ-ONLY |
Events
#server.Details
Called when the server details are received while connecting to a server.
Arguments: details: table with server_name: string, loading_url: string, map_name: string, max_players: integer, player_steamid64: string and gamemode_name: string keys.
Functions
server.getDownloadURL | Gets the download URL of the server. |
server.getFrameTime | Returns an estimate of the server's performance, equivalent to calling FrameTime on the server. |
server.getName | Gets the name of the server. |
server.getRegion | Gets the region the server browser reports this server in. |
server.getTime | Returns the current server time, it is predicted on the client. |
server.getVisibleSlots | Gets the number of player slots shown in the server browser. |
server.isCheatsEnabled | Checks if cheats are enabled. |
server.isCloseCaptionsAllowed | Checks if close captions are allowed in multiplayer. |
server.isDownloadAllowed | Checks if the server allows downloads. |
server.isHidden | Checks if the server is hidden from the master server. |
server.isUploadAllowed | Checks if the server allows uploads. |
server.isUserScriptsAllowed | Checks if the server allows clients to run lua_openscript_cl and lua_run_cl. |
server.kill | Shuts down the server immediately. |
server.message | Sends a message to all players on the server. |
server.setCheatsEnabled | Enables or disables cheats. |
server.setCloseCaptionsAllowed | Allows or disallows close captions in multiplayer (for dedicated servers). |
server.setDownloadAllowed | Allows or disallows clients to download files from the server. |
server.setDownloadURL | Sets the download URL of the server. |
server.setHidden | Hides/unhides the server from the master server. |
server.setName | Sets the name of the server. |
server.setPassword | |
server.setRegion | Sets the region the server browser reports this server in. |
server.setUploadAllowed | Allows or disallows clients to upload customization files to the server. |
server.setUserScriptsAllowed | Allows or disallows clients to run lua_openscript_cl and lua_run_cl. |
server.setVisibleSlots | Sets the number of player slots shown in the server browser. |
#server.getDownloadURL
function server.getDownloadURL(): string
Gets the download URL of the server.
| Type | Name | Description |
|---|---|---|
string | url | The download URL. |
#server.getFrameTime
function server.getFrameTime(): number, number
Returns an estimate of the server's performance, equivalent to calling FrameTime on the server.
| Type | Name | Description |
|---|---|---|
number | frame_time | The server frame time in seconds. |
number | deviation | The standard deviation of the server frame time. |
#server.getName
function server.getName(): string
Gets the name of the server.
| Type | Name | Description |
|---|---|---|
string | hostname | The name of the server. |
#server.getRegion
function server.getRegion(): server.Region
Gets the region the server browser reports this server in.
| Type | Name | Description |
|---|---|---|
server.Region | region | The region of the world, "world" by default. |
#server.getTime
function server.getTime(): number
Returns the current server time, it is predicted on the client.
Falls back to dreamwork.getUpTime when CurTime is not available.
| Type | Name | Description |
|---|---|---|
number | time | The server time in seconds. |
#server.getVisibleSlots
function server.getVisibleSlots(): integer
Gets the number of player slots shown in the server browser.
Values below 1 mean that the real server.slots count is shown.
| Type | Name | Description |
|---|---|---|
integer | slots | The number of visible slots. |
#server.isCheatsEnabled
function server.isCheatsEnabled(): boolean
Checks if cheats are enabled.
| Type | Name | Description |
|---|---|---|
boolean | enabled | true if cheats are enabled, false if not. |
#server.isCloseCaptionsAllowed
function server.isCloseCaptionsAllowed(): boolean
Checks if close captions are allowed in multiplayer.
| Type | Name | Description |
|---|---|---|
boolean | allowed | true if close captions are allowed, false otherwise. |
#server.isDownloadAllowed
function server.isDownloadAllowed(): boolean
Checks if the server allows downloads.
| Type | Name | Description |
|---|---|---|
boolean | allowed | true if clients can download files from the server, false if not. |
#server.isHidden
function server.isHidden(): boolean
Checks if the server is hidden from the master server.
| Type | Name | Description |
|---|---|---|
boolean | hidden | true if the server is hidden, false if not. |
#server.isUploadAllowed
function server.isUploadAllowed(): boolean
Checks if the server allows uploads.
| Type | Name | Description |
|---|---|---|
boolean | allowed | true if clients can upload customization files ( sprays ) to the server, false if not. |
#server.isUserScriptsAllowed
function server.isUserScriptsAllowed(): boolean
Checks if the server allows clients to run lua_openscript_cl and lua_run_cl.
| Type | Name | Description |
|---|---|---|
boolean | allowed | true if the server allows clients to run lua_openscript_cl and lua_run_cl, false if not. |
#server.kill
function server.kill()
Shuts down the server immediately.
#server.message
function server.message(message: string, in_chat?: boolean, in_hud?: boolean)
Sends a message to all players on the server.
This message will be displayed in the console, chat or HUD.
| Name | Type | Description |
|---|---|---|
message | string | The message to print. |
in_chatoptional | boolean | true to print the message in chat ( and console ), false to print it in the console only. |
in_hudoptional | boolean | true to print the message in the HUD (center of the screen), false to not print it. |
#server.setCheatsEnabled
function server.setCheatsEnabled(enabled: boolean)
Enables or disables cheats.
It gives all players access to commands that would normally be abused or misused by players.
| Name | Type | Description |
|---|---|---|
enabled | boolean | true to enable cheats, false to disable them. |
#server.setCloseCaptionsAllowed
function server.setCloseCaptionsAllowed(allowed: boolean)
Allows or disallows close captions in multiplayer (for dedicated servers).
| Name | Type | Description |
|---|---|---|
allowed | boolean | true to allow close captions, false to disallow them. |
#server.setDownloadAllowed
function server.setDownloadAllowed(allowed: boolean)
Allows or disallows clients to download files from the server.
| Name | Type | Description |
|---|---|---|
allowed | boolean | true to allow downloads, false to disallow them. |
#server.setDownloadURL
function server.setDownloadURL(url: string)
Sets the download URL of the server.
| Name | Type | Description |
|---|---|---|
url | string | The download URL to set. |
#server.setHidden
function server.setHidden(hidden: boolean)
Hides/unhides the server from the master server.
| Name | Type | Description |
|---|---|---|
hidden | boolean | true to hide the server, false to unhide it. |
#server.setName
function server.setName(name: string)
Sets the name of the server.
| Name | Type | Description |
|---|---|---|
name | string | The name to set. |
#server.setPassword
function server.setPassword(password_str: string | nil)
| Name | Type | Description |
|---|---|---|
password_str | string | nil |
#server.setRegion
function server.setRegion(region: server.Region)
Sets the region the server browser reports this server in.
| Name | Type | Description |
|---|---|---|
region | server.Region | The region of the world, unknown regions are reported as "world". |
#server.setUploadAllowed
function server.setUploadAllowed(allowed: boolean)
Allows or disallows clients to upload customization files to the server.
| Name | Type | Description |
|---|---|---|
allowed | boolean | true to allow uploads, false to disallow them. |
#server.setUserScriptsAllowed
function server.setUserScriptsAllowed(allowed: boolean)
Allows or disallows clients to run lua_openscript_cl and lua_run_cl.
| Name | Type | Description |
|---|---|---|
allowed | boolean | true to allow clients to run lua_openscript_cl and lua_run_cl, false to disallow them. |
#server.setVisibleSlots
function server.setVisibleSlots(slots: integer): integer
Sets the number of player slots shown in the server browser.
Does not limit how many players can join, use it to reserve slots ( e.g. for admins ).
| Name | Type | Description |
|---|---|---|
slots | integer | The number of visible slots, clamped between 1 and server.slots. |
| Type | Name | Description |
|---|---|---|
integer | slots | The number of visible slots that was set. |