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.
Instance Attribute Summary
Attributes included from Server
Class Method Summary (collapse)
-
+ (MasterServer) master
Returns a master server instance for the default master server for Source games.
Instance Method Summary (collapse)
-
- (Object) disconnect
Disconnects the TCP-based channel used for RCON commands.
-
- (Object) init_socket
Initializes the sockets to communicate with the Source server.
-
- (SourceServer) initialize(address, port = 27015)
constructor
Creates a new instance of a server object representing a Source server, i.e.
-
- (Boolean) rcon_auth(password)
Authenticates the connection for RCON communication with the server.
-
- (String) rcon_exec(command)
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?, #reply, #rules, #send_request, #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
- (SourceServer) initialize(address, port = 27015)
Creates a new instance of a server object representing a Source server, i.e. SrcDS instance
45 46 47 |
# File 'lib/steam/servers/source_server.rb', line 45 def initialize(address, port = 27015) super end |
Class Method Details
+ (MasterServer) master
Returns a master server instance for the default master server for Source games
33 34 35 |
# File 'lib/steam/servers/source_server.rb', line 33 def self.master MasterServer.new *MasterServer::SOURCE_MASTER_SERVER end |
Instance Method Details
- (Object) disconnect
Disconnects the TCP-based channel used for RCON commands
52 53 54 |
# File 'lib/steam/servers/source_server.rb', line 52 def disconnect @rcon_socket.close end |
- (Object) init_socket
Initializes the sockets to communicate with the Source server
60 61 62 63 |
# File 'lib/steam/servers/source_server.rb', line 60 def init_socket @rcon_socket = RCONSocket.new @ip_address, @port @socket = SourceSocket.new @ip_address, @port end |
- (Boolean) rcon_auth(password)
Authenticates the connection for RCON communication with the server
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/steam/servers/source_server.rb', line 71 def rcon_auth(password) @rcon_request_id = rand 2**16 @rcon_socket.send RCONAuthRequest.new @rcon_request_id, password begin @rcon_socket.reply reply = @rcon_socket.reply @rcon_authenticated = reply.request_id == @rcon_request_id rescue Errno::ECONNRESET raise RCONBanError end end |
- (String) rcon_exec(command)
Remotely executes a command on the server via RCON
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/steam/servers/source_server.rb', line 93 def rcon_exec(command) raise RCONNoAuthError unless @rcon_authenticated @rcon_socket.send RCONExecRequest.new(@rcon_request_id, command) @rcon_socket.send RCONTerminator.new(@rcon_request_id) response = [] begin begin response_packet = @rcon_socket.reply if response_packet.is_a? RCONAuthResponse @rcon_authenticated = false raise RCONNoAuthError end rescue Errno::ECONNRESET @rcon_authenticated = false raise RCONNoAuthError end response << response_packet.response end while response.size < 3 || response_packet.response.size > 0 response.join('').strip end |