Class: SourceServer
- Inherits:
-
Object
- Object
- SourceServer
- Includes:
- GameServer
- Defined in:
- lib/steam/servers/source_server.rb
Constant Summary
Constants included from GameServer
GameServer::REQUEST_CHALLENGE, GameServer::REQUEST_INFO, GameServer::REQUEST_PLAYER, GameServer::REQUEST_RULES
Class Method Summary collapse
-
.split_player_status(player_status) ⇒ Object
Splits the player status obtained with rcon status.
Instance Method Summary collapse
-
#initialize(ip_address, port_number = 27015) ⇒ SourceServer
constructor
A new instance of SourceServer.
- #rcon_auth(password) ⇒ Object
- #rcon_exec(command) ⇒ Object
Methods included from GameServer
#handle_response_for_request, #init, #ping, #players, #rules, #server_info, #to_s, #update_challenge_number, #update_ping, #update_player_info, #update_rules_info, #update_server_info
Constructor Details
#initialize(ip_address, port_number = 27015) ⇒ SourceServer
Returns a new instance of SourceServer.
27 28 29 30 31 |
# File 'lib/steam/servers/source_server.rb', line 27 def initialize(ip_address, port_number = 27015) super port_number @rcon_socket = RCONSocket.new ip_address, port_number @socket = SourceSocket.new ip_address, port_number end |
Class Method Details
.split_player_status(player_status) ⇒ Object
Splits the player status obtained with rcon status
19 20 21 22 23 24 25 |
# File 'lib/steam/servers/source_server.rb', line 19 def self.split_player_status(player_status) player_data = player_status.match(/# *(\d+) +"(.*)" +(.*)/).to_a[1..-1] player_data[2] = player_data[2].split player_data.flatten! player_data.delete_at(3) player_data end |
Instance Method Details
#rcon_auth(password) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/steam/servers/source_server.rb', line 33 def rcon_auth(password) @rcon_request_id = rand 2**16 @rcon_socket.send RCONAuthRequest.new(@rcon_request_id, password) @rcon_socket.reply reply = @rcon_socket.reply raise RCONNoAuthException.new if reply.request_id == -1 reply.request_id == @rcon_request_id end |
#rcon_exec(command) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/steam/servers/source_server.rb', line 45 def rcon_exec(command) @rcon_socket.send RCONExecRequest.new(@rcon_request_id, command) response_packets = [] begin begin response_packet = @rcon_socket.reply raise RCONNoAuthException.new if response_packet.is_a? RCONAuthResponse response_packets << response_packet end while true rescue TimeoutException raise $! if response_packets.empty? end response = '' response_packets.each do |packet| response << packet.response end response.strip end |