Class: MasterServer
- Inherits:
-
Object
- Object
- MasterServer
- Includes:
- Server
- Defined in:
- lib/steam/servers/master_server.rb
Overview
This class represents a Steam master server and can be used to get game servers which are publicly available
An intance of this class can be used much like Steam’s server browser to get a list of available game servers, including filters to narrow down the search results.
Constant Summary collapse
- GOLDSRC_MASTER_SERVER =
The master server address to query for GoldSrc game servers
'hl1master.steampowered.com', 27011
- SOURCE_MASTER_SERVER =
The master server address to query for Source game servers
'hl2master.steampowered.com', 27011
- REGION_US_EAST_COAST =
The region code for the US east coast
0x00
- REGION_US_WEST_COAST =
The region code for the US west coast
0x01
- REGION_SOUTH_AMERICA =
The region code for South America
0x02
- REGION_EUROPE =
The region code for Europe
0x03
- REGION_ASIA =
The region code for Asia
0x04
- REGION_AUSTRALIA =
The region code for Australia
0x05
- REGION_MIDDLE_EAST =
The region code for the Middle East
0x06
- REGION_AFRICA =
The region code for Africa
0x07
- REGION_ALL =
The region code for the whole world
0xFF
- @@retries =
The default number of allowed retries
3
Instance Attribute Summary
Attributes included from Server
Class Method Summary collapse
-
.retries=(retries) ⇒ Object
Sets the number of consecutive requests that may fail, before getting the server list is cancelled (default: 3).
Instance Method Summary collapse
- #challenge ⇒ Fixnum deprecated Deprecated.
-
#init_socket ⇒ Object
Initializes the socket to communicate with the master server.
- #send_heartbeat(data) ⇒ Array<SteamPacket> deprecated Deprecated.
-
#servers(region_code = MasterServer::REGION_ALL, filters = '', force = false) ⇒ Array<Array<String>>
Returns a list of game server matching the given region and filters.
Methods included from Server
#disconnect, #initialize, #rotate_ip
Class Method Details
.retries=(retries) ⇒ Object
Sets the number of consecutive requests that may fail, before getting the server list is cancelled (default: 3)
65 66 67 |
# File 'lib/steam/servers/master_server.rb', line 65 def self.retries=(retries) @@retries = retries end |
Instance Method Details
#challenge ⇒ Fixnum
Please note that this is not needed for finding servers using #servers.
Request a challenge number from the master server.
This is used for further communication with the master server.
78 79 80 81 82 83 |
# File 'lib/steam/servers/master_server.rb', line 78 def challenge failsafe do @socket.send C2M_CHECKMD5_Packet.new @socket.reply.challenge end end |
#init_socket ⇒ Object
Initializes the socket to communicate with the master server
88 89 90 |
# File 'lib/steam/servers/master_server.rb', line 88 def init_socket @socket = MasterServerSocket.new @ip_address, @port end |
#send_heartbeat(data) ⇒ Array<SteamPacket>
Sends a constructed heartbeat to the master server
This can be used to check server versions externally.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/steam/servers/master_server.rb', line 173 def send_heartbeat(data) reply_packets = [] failsafe do @socket.send S2M_HEARTBEAT2_Packet.new(data) begin loop { reply_packets << @socket.reply } rescue SteamCondenser::TimeoutError end end reply_packets end |
#servers(region_code = MasterServer::REGION_ALL, filters = '', force = false) ⇒ Array<Array<String>>
Receiving all servers from the master server is taking quite some time.
Returns a list of game server matching the given region and filters
Filtering: Instead of filtering the results sent by the master server locally, you should at least use the following filters to narrow down the results sent by the master server.
Available filters:
-
‘typed`: Request only dedicated servers
-
‘secure1`: Request only secure servers
-
‘gamedir`: Request only servers of a specific mod
-
‘map`: Request only servers running a specific map
-
‘linux1`: Request only linux servers
-
‘emtpy1`: Request only non-empty servers
-
‘full1`: Request only servers not full
-
‘proxy1`: Request only spectator proxy servers
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/steam/servers/master_server.rb', line 123 def servers(region_code = MasterServer::REGION_ALL, filters = '', force = false) finished = false current_server = '0.0.0.0:0' server_array = [] begin failsafe do fail_count = 0 begin @socket.send A2M_GET_SERVERS_BATCH2_Packet.new(region_code, current_server, filters) begin servers = @socket.reply.servers servers.each do |server| if server == '0.0.0.0:0' finished = true else current_server = server server_array << server.split(':') end end fail_count = 0 rescue SteamCondenser::TimeoutError raise $! if (fail_count += 1) == @@retries if $DEBUG puts "Request to master server #@ip_address timed out, retrying..." end end end while !finished end rescue SteamCondenser::TimeoutError raise $! unless force end server_array end |