Server

Server

Root object for interacting with SourceMod.js servers.

Constructor

new Server(host, options)

Source:
Properties:
Name Type Description
host string

The host WebSocket address. Example: ws://localhost:5050

connected boolean

Will be true if the server is connected to the WebSocket, and false otherwise.

socket object

An instance of the Socket class used for interacting with the WebSocket. Will be null if not yet connected.

console object

Instance of the Console object for this server.

players object

Instance of the Players object for this server.

currentMap string

Name of the current map. Keep in mind that this is a generic response from the engine and not the game itself.

isDedicated boolean

Whether the server is a dedicated server or not.

authID string

The SteamID of the server.

gameTime number

The game time, based on the game tick.

gameTick number

The current game tick.

gameFolder string

The directory of the server.

gameDescription string

The description of the game. Keep in mind that this is a generic response from the engine, and not the game itself.

engineVersion string

The engine version that SourceMod was compilied against.

Parameters:
Name Type Description
host string

The host WebSocket address. Example: ws://localhost:5050

options object

Options to provide the server.

Methods

connect()

Source:

Connects to the server.

disconnect()

Source:

Disconnects from the server. Internally calls Socket.disconnect().

fetch() → {Object}

Source:

Fetches information about the server. Keep in mind that you must run this function to keep the server information up-to-date.

Returns:

The new server object with fetched information.

Type
Object

setMap(map, reason) → {Object}

Source:

Forcefully changes the current map, with an optional reason. SourceMod API Reference

Parameters:
Name Type Description
map string

Name of the new map

reason string

Reason for changing the map

Returns:
  • The new server object with fetched information.
Type
Object

setNextMap(map) → {Object}

Source:

Sets SourceMod's internal nextmap. Same as changing sm_nextmap. Will run Server.fetch(), ensuring the nextMap property is updated. SourceMod API Reference

Parameters:
Name Type Description
map string

Name of the new map

Returns:
  • The new server object with fetched information.
Type
Object

Events

convarChanged

Source:

Fires when a ConVar changes. SourceMod API Reference

Parameters:
Name Type Description
name string

Name of the ConVar.

steamid string

New value of the ConVar.

disconnect

Source:

Fired when the server disconnects.

ready

Source:

Fired when the connection to the server has been established.