Class: MasterServer
- Inherits:
-
Object
- Object
- MasterServer
- Includes:
- Server
- Defined in:
- lib/steam/servers/master_server.rb
Constant Summary collapse
- GOLDSRC_MASTER_SERVER =
'hl1master.steampowered.com', 27010
- SOURCE_MASTER_SERVER =
'hl2master.steampowered.com', 27011
- REGION_US_EAST_COAST =
0x00
- REGION_US_WEST_COAST =
0x01
- REGION_SOUTH_AMERICA =
0x02
- REGION_EUROPE =
0x03
- REGION_ASIA =
0x04
- REGION_AUSTRALIA =
0x05
- REGION_MIDDLE_EAST =
0x06
- REGION_AFRICA =
0x07
- REGION_ALL =
0xFF
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.
-
#initialize(address, port) ⇒ MasterServer
constructor
Creates a new instance of a master server object.
-
#send_heartbeat(data) ⇒ Object
Sends a constructed heartbeat to the master server.
- #servers(region_code = MasterServer::REGION_ALL, filters = '') ⇒ Object
- #update_servers(region_code, filters) ⇒ Object
Methods included from Server
Constructor Details
#initialize(address, port) ⇒ MasterServer
Creates a new instance of a master server object
30 31 32 33 34 |
# File 'lib/steam/servers/master_server.rb', line 30 def initialize(address, port) super @server_array = [] end |
Instance Method Details
#challenge ⇒ Object
Request a challenge number from the master server. This is used for further communication with the master server.
Please note that this is NOT needed for finding servers using the servers
method
41 42 43 44 45 46 |
# File 'lib/steam/servers/master_server.rb', line 41 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
49 50 51 |
# File 'lib/steam/servers/master_server.rb', line 49 def init_socket @socket = MasterServerSocket.new @ip_address, @port end |
#send_heartbeat(data) ⇒ Object
Sends a constructed heartbeat to the master server
This can be used to check server versions externally.
The reply from the master server – usually zero or more packets. Zero means either the heartbeat was accepted by the master or there was a timeout. So usually it’s best to repeat a heartbeat a few times when not receiving any packets.
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/steam/servers/master_server.rb', line 92 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 = '') ⇒ Object
53 54 55 56 |
# File 'lib/steam/servers/master_server.rb', line 53 def servers(region_code = MasterServer::REGION_ALL, filters = '') update_servers region_code, filters if @server_array.empty? @server_array end |
#update_servers(region_code, filters) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/steam/servers/master_server.rb', line 58 def update_servers(region_code, filters) fail_count = 0 finished = false current_server = '0.0.0.0:0' 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 end |