Module: Server
- Included in:
- GameServer, MasterServer
- Defined in:
- lib/steam/servers/server.rb
Overview
This module is included by all classes implementing server functionality
It provides basic name resolution features and the ability to rotate between different IP addresses belonging to a single DNS name.
Instance Attribute Summary collapse
-
#host_names ⇒ Array<String>
readonly
Returns a list of host names associated with this server.
-
#ip_addresses ⇒ Array<String>
readonly
Returns a list of IP addresses associated with this server.
Instance Method Summary collapse
-
#disconnect ⇒ Object
Disconnect the connections to this server.
-
#initialize(address, port = nil) ⇒ Object
Creates a new server instance with the given address and port.
-
#rotate_ip ⇒ Boolean
Rotate this server’s IP address to the next one in the IP list.
Instance Attribute Details
#host_names ⇒ Array<String> (readonly)
Returns a list of host names associated with this server
19 20 21 |
# File 'lib/steam/servers/server.rb', line 19 def host_names @host_names end |
#ip_addresses ⇒ Array<String> (readonly)
Returns a list of IP addresses associated with this server
24 25 26 |
# File 'lib/steam/servers/server.rb', line 24 def ip_addresses @ip_addresses end |
Instance Method Details
#disconnect ⇒ Object
In the base implementation this does nothing, only connection-based communication channels have to be disconnected.
Disconnect the connections to this server
59 60 |
# File 'lib/steam/servers/server.rb', line 59 def disconnect end |
#initialize(address, port = nil) ⇒ Object
Creates a new server instance with the given address and port
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/steam/servers/server.rb', line 34 def initialize(address, port = nil) address = address.to_s address, port = address.split(':', 2) if address.include? ':' @host_names = [] @ip_addresses = [] @ip_index = 0 @port = port Socket.getaddrinfo(address, port, Socket::AF_INET, Socket::SOCK_DGRAM). each do |address| @host_names << address[2] @ip_addresses << address[3] end @ip_address = @ip_addresses.first init_socket end |
#rotate_ip ⇒ Boolean
Rotate this server’s IP address to the next one in the IP list
If this method returns ‘true`, it indicates that all IP addresses have been used, hinting at the server(s) being unreachable. An appropriate action should be taken to inform the user.
Servers with only one IP address will always cause this method to return ‘true` and the sockets will not be reinitialized.
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/steam/servers/server.rb', line 75 def rotate_ip return true if @ip_addresses.size == 1 @ip_index = (@ip_index + 1) % @ip_addresses.size @ip_address = @ip_addresses[@ip_index] init_socket @ip_index == 0 end |