Class: SourceServer
- Inherits:
-
Object
- Object
- SourceServer
- Includes:
- GameServer
- Defined in:
- lib/steam/servers/source_server.rb
Overview
This class represents a Source game server and can be used to query information about and remotely execute commands via RCON on the server
A Source game server is an instance of the Source Dedicated Server (SrcDS) running games using Valve’s Source engine, like Counter-Strike: Source, Team Fortress 2 or Left4Dead.
Constant Summary
Constants included from GameServer
GameServer::REQUEST_CHALLENGE, GameServer::REQUEST_INFO, GameServer::REQUEST_PLAYER, GameServer::REQUEST_RULES
Instance Attribute Summary
Attributes included from Server
Instance Method Summary collapse
-
#init_socket ⇒ Object
Initializes the sockets to communicate with the Source server.
-
#initialize(address, port = 27015) ⇒ SourceServer
constructor
Creates a new instance of a server object representing a Source server, i.e.
-
#rcon_auth(password) ⇒ Boolean
Authenticates the connection for RCON communication with the server.
-
#rcon_exec(command) ⇒ String
Remotely executes a command on the server via RCON.
Methods included from GameServer
#handle_response_for_request, #init, #ping, player_status_attributes, #players, #rcon_authenticated?, #rules, #server_info, split_player_status, #to_s, #update_challenge_number, #update_ping, #update_players, #update_rules, #update_server_info
Methods included from Server
Constructor Details
#initialize(address, port = 27015) ⇒ SourceServer
Creates a new instance of a server object representing a Source server, i.e. SrcDS instance
36 37 38 |
# File 'lib/steam/servers/source_server.rb', line 36 def initialize(address, port = 27015) super end |
Instance Method Details
#init_socket ⇒ Object
Initializes the sockets to communicate with the Source server
44 45 46 47 |
# File 'lib/steam/servers/source_server.rb', line 44 def init_socket @rcon_socket = RCONSocket.new @ip_address, @port @socket = SourceSocket.new @ip_address, @port end |
#rcon_auth(password) ⇒ Boolean
Authenticates the connection for RCON communication with the server
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/steam/servers/source_server.rb', line 54 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) ⇒ String
Remotely executes a command on the server via RCON
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/steam/servers/source_server.rb', line 71 def rcon_exec(command) @rcon_socket.send RCONExecRequest.new(@rcon_request_id, command) @rcon_socket.send RCONTerminator.new(@rcon_request_id) response = '' begin response_packet = @rcon_socket.reply raise RCONNoAuthException.new if response_packet.is_a? RCONAuthResponse response << response_packet.response end while response.length == 0 || response_packet.response.size > 0 response.strip end |