Class: SourceServer

Inherits:
Object
  • Object
show all
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.

See Also:

Author:

  • Sebastian Staudt

Instance Attribute Summary

Attributes included from Server

#host_names, #ip_addresses

Class Method Summary collapse

Instance Method Summary collapse

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

#rotate_ip

Constructor Details

#initialize(address, port = 27015) ⇒ SourceServer

Creates a new instance of a server object representing a Source server, i.e. SrcDS instance

Parameters:

  • address (String)

    Either an IP address, a DNS name or one of them combined with the port number. If a port number is given, e.g. ‘server.example.com:27016’ it will override the second argument.

  • port (Fixnum) (defaults to: 27015)

    The port the server is listening on

Raises:



45
46
47
# File 'lib/steam/servers/source_server.rb', line 45

def initialize(address, port = 27015)
  super
end

Class Method Details

.masterMasterServer

Returns a master server instance for the default master server for Source games

Returns:



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

#init_socketObject

Initializes the sockets to communicate with the Source server



53
54
55
56
# File 'lib/steam/servers/source_server.rb', line 53

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

Parameters:

  • password (String)

    The RCON password of the server

Returns:

  • (Boolean)

    whether authentication was successful

Raises:

See Also:



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/steam/servers/source_server.rb', line 64

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 RCONNoAuthError if reply.request_id == -1

  @rcon_authenticated = reply.request_id == @rcon_request_id
end

#rcon_exec(command) ⇒ String

Remotely executes a command on the server via RCON

Parameters:

  • command (String)

    The command to execute on the server via RCON

Returns:

  • (String)

    The output of the executed command

Raises:

See Also:



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/steam/servers/source_server.rb', line 81

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
    response_packet = @rcon_socket.reply
    if response_packet.is_a? RCONAuthResponse
      @rcon_authenticated = false
      raise RCONNoAuthError
    end
    response << response_packet.response
  end while response.size < 3 || response_packet.response.size > 0

  response.join('').strip
end