-
Notifications
You must be signed in to change notification settings - Fork 0
SourceServer
The SourceServer
object represents an instance of a source dedicated server, and provides methods for querying the server it represents using UDP.
To create a new instance of a server, simply pass a connection string (ipv4:port
) to the constructor.
Any errors that the server anticipates (like a bad response packet, or connection timeout) are raised as a SourceError
, which closes the connection to the server.
Note that the actual socket connection to the server is never closed, but the instance is simply marked as closed until a successful retry (see methods table).
Name | Description |
---|---|
info |
Property that performs an info request (see below) |
rules |
Property that performs a rules request (see below) |
constr |
Connection string (as passed to the constructor) |
isClosed |
Whether or not the server connection is closed |
Method | Description |
---|---|
close() |
Marks the server as closed |
retry() |
Attempts to reconnect to the server |
ping(places: int = 0) |
Returns the ping to the server rounded to places decimal places |
getPlayers() |
Returns a tuple of players. See below for the structure of each player |
Each player is a tuple in the form (index: int, name: str, score: int, duration: float)
, unless the server is running The Ship, in which case each player tuple is in the form (index: int, name: str, score: int, duration: float, deaths: int, money: int)
The .info
property may look like a variable, but is, in fact, a property that sends an info query to the server and returns the response when read.
Any attempts to set this will raise an AttributeError
.
Note, this table is a modified version of the table found here
Also, you don't need to worry about the technical info on certain values (EDF and possible truncated id for example) as this is handled automatically, just use it for reference regarding the contents of .info
. If in doubt, print its contents after connecting to a server
Field Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
protocol | byte | Protocol version used by the server. | ||||||||||||
name | str | Name of the server. | ||||||||||||
map | str | Map the server has currently loaded. | ||||||||||||
folder | str | Name of the folder containing the game files. | ||||||||||||
game | str | Full name of the game. | ||||||||||||
id | int | Steam Application ID of game. | ||||||||||||
players | byte | Number of players on the server. | ||||||||||||
max_players | byte | Maximum number of players the server reports it can hold. | ||||||||||||
bots | byte | Number of bots on the server. | ||||||||||||
server_type | byte | Indicates the type of server:
|
||||||||||||
environment | byte | Indicates the operating system of the server:
|
||||||||||||
visibility | byte | Indicates whether the server requires a password:
|
||||||||||||
VAC | byte | Specifies whether the server uses VAC:
|
||||||||||||
These fields only exist in a response if the server is running The Ship:
|
||||||||||||||
version | str | Version of the game installed on the server. | ||||||||||||
EDF | byte | If present, this specifies which additional data fields will be included. | ||||||||||||
Only if EDF & 0x80 proves true:
|
||||||||||||||
Only if EDF & 0x10 proves true:
|
||||||||||||||
Only if EDF & 0x40 proves true:
|
||||||||||||||
Only if EDF & 0x20 proves true:
|
||||||||||||||
Only if EDF & 0x01 proves true:
|
Like the .info
property, this performs a rules request when its getter is called, returning a dictionary of the key-value pair server rules (convars).
Note, this wiki is a work in progress. Please open an issue if you spot a mistake