dreamworkAPI
Ctrl K
GitHub
libraryDocs / server

server

librarysharedmenusource

The game's server library.

Modules

Classes & types

Fields

NameTypeDescription
singleplayerbooleantrue if server is running in singleplayer mode, false otherwise. READ-ONLY
dedicatedbooleantrue if server is running as a dedicated server, false otherwise. READ-ONLY
tickratenumberThe configured number of server ticks per second, see TPS for the measured one. READ-ONLY
slotsintegerThe maximum number of players the server can hold. READ-ONLY
gamemodestringThe name of the active gamemode, "base" if unknown. READ-ONLY
ipv4integerThe public IPv4 address of the server as an unsigned 32-bit integer, 0x7F000001 ( 127.0.0.1 ) for local servers. READ-ONLY
portintegerThe public UDP port of the server, 27015 by default. READ-ONLY
addressstringThe public address of the server in the ip:port format. READ-ONLY

Events

#server.Details

menuEventsource

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.getDownloadURLGets the download URL of the server.
server.getFrameTimeReturns an estimate of the server's performance, equivalent to calling FrameTime on the server.
server.getNameGets the name of the server.
server.getRegionGets the region the server browser reports this server in.
server.getTimeReturns the current server time, it is predicted on the client.
server.getVisibleSlotsGets the number of player slots shown in the server browser.
server.isCheatsEnabledChecks if cheats are enabled.
server.isCloseCaptionsAllowedChecks if close captions are allowed in multiplayer.
server.isDownloadAllowedChecks if the server allows downloads.
server.isHiddenChecks if the server is hidden from the master server.
server.isUploadAllowedChecks if the server allows uploads.
server.isUserScriptsAllowedChecks if the server allows clients to run lua_openscript_cl and lua_run_cl.
server.killShuts down the server immediately.
server.messageSends a message to all players on the server.
server.setCheatsEnabledEnables or disables cheats.
server.setCloseCaptionsAllowedAllows or disallows close captions in multiplayer (for dedicated servers).
server.setDownloadAllowedAllows or disallows clients to download files from the server.
server.setDownloadURLSets the download URL of the server.
server.setHiddenHides/unhides the server from the master server.
server.setNameSets the name of the server.
server.setPassword
server.setRegionSets the region the server browser reports this server in.
server.setUploadAllowedAllows or disallows clients to upload customization files to the server.
server.setUserScriptsAllowedAllows or disallows clients to run lua_openscript_cl and lua_run_cl.
server.setVisibleSlotsSets the number of player slots shown in the server browser.

#server.getDownloadURL

servernodiscardsource
function server.getDownloadURL(): string

Gets the download URL of the server.

Returns
TypeNameDescription
stringurlThe download URL.

#server.getFrameTime

clientnodiscardsource
function server.getFrameTime(): number, number

Returns an estimate of the server's performance, equivalent to calling FrameTime on the server.

Returns
TypeNameDescription
numberframe_timeThe server frame time in seconds.
numberdeviationThe standard deviation of the server frame time.

#server.getName

sharedmenunodiscardsource
function server.getName(): string

Gets the name of the server.

Returns
TypeNameDescription
stringhostnameThe name of the server.

#server.getRegion

servernodiscardsource
function server.getRegion(): server.Region

Gets the region the server browser reports this server in.

Returns
TypeNameDescription
server.RegionregionThe region of the world, "world" by default.

#server.getTime

sharedmenunodiscardsource
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.

Returns
TypeNameDescription
numbertimeThe server time in seconds.

#server.getVisibleSlots

servernodiscardsource
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.

Returns
TypeNameDescription
integerslotsThe number of visible slots.

#server.isCheatsEnabled

sharednodiscardsource
function server.isCheatsEnabled(): boolean

Checks if cheats are enabled.

Returns
TypeNameDescription
booleanenabledtrue if cheats are enabled, false if not.

#server.isCloseCaptionsAllowed

servernodiscardsource
function server.isCloseCaptionsAllowed(): boolean

Checks if close captions are allowed in multiplayer.

Returns
TypeNameDescription
booleanallowedtrue if close captions are allowed, false otherwise.

#server.isDownloadAllowed

servernodiscardsource
function server.isDownloadAllowed(): boolean

Checks if the server allows downloads.

Returns
TypeNameDescription
booleanallowedtrue if clients can download files from the server, false if not.

#server.isHidden

servernodiscardsource
function server.isHidden(): boolean

Checks if the server is hidden from the master server.

Returns
TypeNameDescription
booleanhiddentrue if the server is hidden, false if not.

#server.isUploadAllowed

servernodiscardsource
function server.isUploadAllowed(): boolean

Checks if the server allows uploads.

Returns
TypeNameDescription
booleanallowedtrue if clients can upload customization files ( sprays ) to the server, false if not.

#server.isUserScriptsAllowed

sharednodiscardsource
function server.isUserScriptsAllowed(): boolean

Checks if the server allows clients to run lua_openscript_cl and lua_run_cl.

Returns
TypeNameDescription
booleanallowedtrue if the server allows clients to run lua_openscript_cl and lua_run_cl, false if not.

#server.kill

serversource
function server.kill()

Shuts down the server immediately.

#server.message

serversource
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.

Parameters
NameTypeDescription
messagestringThe message to print.
in_chatoptionalbooleantrue to print the message in chat ( and console ), false to print it in the console only.
in_hudoptionalbooleantrue to print the message in the HUD (center of the screen), false to not print it.

#server.setCheatsEnabled

serversource
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.

Parameters
NameTypeDescription
enabledbooleantrue to enable cheats, false to disable them.

#server.setCloseCaptionsAllowed

serversource
function server.setCloseCaptionsAllowed(allowed: boolean)

Allows or disallows close captions in multiplayer (for dedicated servers).

Parameters
NameTypeDescription
allowedbooleantrue to allow close captions, false to disallow them.

#server.setDownloadAllowed

serversource
function server.setDownloadAllowed(allowed: boolean)

Allows or disallows clients to download files from the server.

Parameters
NameTypeDescription
allowedbooleantrue to allow downloads, false to disallow them.

#server.setDownloadURL

serversource
function server.setDownloadURL(url: string)

Sets the download URL of the server.

Parameters
NameTypeDescription
urlstringThe download URL to set.

#server.setHidden

serversource
function server.setHidden(hidden: boolean)

Hides/unhides the server from the master server.

Parameters
NameTypeDescription
hiddenbooleantrue to hide the server, false to unhide it.

#server.setName

serversource
function server.setName(name: string)

Sets the name of the server.

Parameters
NameTypeDescription
namestringThe name to set.

#server.setPassword

function server.setPassword(password_str: string | nil)
Parameters
NameTypeDescription
password_strstring | nil

#server.setRegion

serversource
function server.setRegion(region: server.Region)

Sets the region the server browser reports this server in.

Parameters
NameTypeDescription
regionserver.RegionThe region of the world, unknown regions are reported as "world".

#server.setUploadAllowed

serversource
function server.setUploadAllowed(allowed: boolean)

Allows or disallows clients to upload customization files to the server.

Parameters
NameTypeDescription
allowedbooleantrue to allow uploads, false to disallow them.

#server.setUserScriptsAllowed

serversource
function server.setUserScriptsAllowed(allowed: boolean)

Allows or disallows clients to run lua_openscript_cl and lua_run_cl.

Parameters
NameTypeDescription
allowedbooleantrue to allow clients to run lua_openscript_cl and lua_run_cl, false to disallow them.

#server.setVisibleSlots

serversource
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 ).

Parameters
NameTypeDescription
slotsintegerThe number of visible slots, clamped between 1 and server.slots.
Returns
TypeNameDescription
integerslotsThe number of visible slots that was set.
Generated from the dreamwork meta branch.