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', 27010
- SOURCE_MASTER_SERVER =
The master server address to query for GoldSrc 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
Instance Attribute Summary
Attributes included from Server
Instance Method Summary collapse
-
#challenge ⇒ Object
Request a challenge number from the master server.
-
#init_socket ⇒ Object
Initializes the socket to communicate with the master server.
-
#send_heartbeat(data) ⇒ Array<SteamPacket>
Sends a constructed heartbeat to the master server.
-
#servers(region_code = MasterServer::REGION_ALL, filters = '') ⇒ Array<Array<String>>
Returns a list of game server matching the given region and filters.
Methods included from Server
Instance Method Details
#challenge ⇒ Object
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.
65 66 67 68 69 70 |
# File 'lib/steam/servers/master_server.rb', line 65 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
75 76 77 |
# File 'lib/steam/servers/master_server.rb', line 75 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.
146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/steam/servers/master_server.rb', line 146 def send_heartbeat(data) failsafe do @socket.send S2M_HEARTBEAT2_Packet.new(data) reply_packets = [] begin loop { reply_packets << @socket.reply } rescue TimeoutException end end reply_packets end |
#servers(region_code = MasterServer::REGION_ALL, filters = '') ⇒ 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
-
‘full`: Request only servers not full
-
‘proxy1`: Request only spectator proxy servers
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/steam/servers/master_server.rb', line 105 def servers(region_code = MasterServer::REGION_ALL, filters = '') fail_count = 0 finished = false current_server = '0.0.0.0:0' server_array = [] failsafe do 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 TimeoutException raise $! if (fail_count += 1) == 3 end end while !finished end server_array end |