Class: SteamCondenser::Servers::MasterServer

Inherits:
Object
  • Object
show all
Includes:
Logging, BaseServer
Defined in:
lib/steam-condenser/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.

Author:

  • Sebastian Staudt

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 BaseServer

#host_names, #ip_addresses

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

formatter=, included, level=, #log, logdev=

Methods included from BaseServer

#disconnect, #failsafe, #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)


68
69
70
# File 'lib/steam-condenser/servers/master_server.rb', line 68

def self.retries=(retries)
  @@retries = retries
end

Instance Method Details

#init_socketObject

Initializes the socket to communicate with the master server

See Also:

  • MasterServerSocket

75
76
77
# File 'lib/steam-condenser/servers/master_server.rb', line 75

def init_socket
  @socket = Sockets::MasterServerSocket.new @ip_address, @port
end

#servers(region_code = MasterServer::REGION_ALL, filters = '', force = false) ⇒ Array<Array<String>>

Note:

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:

  • \type\d: Request only dedicated servers
  • \secure\1: Request only secure servers
  • \gamedir\[mod]: Request only servers of a specific mod
  • \map\[mapname]: Request only servers running a specific map
  • \linux\1: Request only linux servers
  • \empty\1: Request only non-empty servers
  • \full\1: Request only servers not full
  • \proxy\1: Request only spectator proxy servers

Raises:

  • (Error::Timeout)

    if too many timeouts occur while querying the master server

See Also:

  • A2M_GET_SERVERS_BATCH2_Packet
  • retries=

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/steam-condenser/servers/master_server.rb', line 110

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 Packets::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 Error::Timeout
          raise $! if (fail_count += 1) == @@retries
          log.info "Request to master server #@ip_address timed out, retrying..."
        end
      end while !finished
    end
  rescue Error::Timeout
    raise $! unless force
  end

  server_array
end