Skip to content

MasterServer

100PXSquared edited this page Aug 12, 2020 · 1 revision

MasterServer Object

Overview

The MasterServer object has one public method, .query(), which takes in a region code and a filter dictionary as parameters, and returns an iterator, which will yield a list of IPs for each packet.

Rate Limiting

UDP requests to Source master servers are heavily rate limited, therefor I have capped the number of query requests that will be sent when calling .query(), however you will still get a connection timeout after 3 full requests (meaning there were enough IPs returned to hit the request cap, as the server forces you to send another request with a seed IP, rather than sending them as multiple packets at once) back to back.

To combat this, I've added a 5 minute delay if the initial request to the server times out before making another attempt.
There is no limit to how many times it will retry.

Region Codes

Each valid region code is defined as a constant within a MasterServer object, and can be accessed similar to an enum by doing masterServerInstance.REGION_CODE
These region codes are taken from the Valve dev wiki

Variable Name Hex
US_EAST_COAST 0x00
US_WEST_COAST 0x01
SOUTH_AMERICA 0x02
EUROPE 0x03
ASIA 0x04
AUSTRALIA 0x05
MIDDLE_EAST 0x06
AFRICA 0x07
REST_OF_THE_WORLD 0xFF

Note, the REST_OF_THE_WORLD code actually means the entire world

Filters

The filters you can specify are an improved version of the actual filters the master server uses. A set of filters are represented as a dictionary of "filterName": filterVal pairs, unless using the logical filters described below.
Note, boolean filters, if set, will filter either only servers that match that filter if true, or only servers that don't match that filter if false

Filter Name Type Description
dedicated bool Dedicated servers
secure bool Servers with anti-cheat (almost always VAC)
gamedir str Servers with specified game directory name (e.g. cstrike for counter strike)
map str Servers that are on that map
linux bool Servers that are running on Linux
password bool Password protected servers
empty bool Empty servers
full bool Full servers
proxy bool SourceTV proxies
appid int Servers running games with that app ID
napp int Servers running games without that app ID
whitelisted bool Servers using a whitelist
gametype tuple Servers with all tags in the specified tuple present in sv_tags
gamedata tuple Servers with all tags in the specified tuple present in their "hidden" tags (L4D2 Only)
gamedataor tuple Servers with any of the tags in the specified tuple present in their "hidden" tags (L4D2 Only)
name_match str Servers with a matching hostname (can use * as a wildcard)
version_match str Servers running specified version (can use * as a wildcard)
collapse_addr_hash bool Returns only one server for each unique IP address matched
gameaddr str Returns only servers with a matching address (port supported and optional)

Logical Filters

The master server compares each filter with an and by default, however it supports two logical "filters":

  • nand
  • nor

You can use these by simply adding it to a filter dictionary like you would with a normal filter, however its value should be another filter dictionary.
It is possible to create other logical operators by combining the available and, nand, and nor operators, however I'm going to add these as their own logical filters that merely represent a combination of and, nand, and nor.

Example Filter

filter = {
    "dedicated": True,
    "nor": {
        "gamedir": "cstrike",
        "appid": 500
    }
}