Class: GoldSrcServer

Inherits:
Object
  • Object
show all
Includes:
GameServer
Defined in:
lib/steam/servers/goldsrc_server.rb

Overview

This class represents a GoldSrc game server and can be used to query information about and remotely execute commands via RCON on the server

A GoldSrc game server is an instance of the Half-Life Dedicated Server (HLDS) running games using Valve’s GoldSrc engine, like Half-Life Deathmatch, Counter-Strike 1.6 or Team Fortress Classic.

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

#disconnect, #rotate_ip

Constructor Details

#initialize(address, port = 27015, is_hltv = false) ⇒ GoldSrcServer

Creates a new instance of a GoldSrc server object

Raises:



40
41
42
43
44
# File 'lib/steam/servers/goldsrc_server.rb', line 40

def initialize(address, port = 27015, is_hltv = false)
  super address, port

  @is_hltv = is_hltv
end

Class Method Details

.masterMasterServer

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



27
28
29
# File 'lib/steam/servers/goldsrc_server.rb', line 27

def self.master
  MasterServer.new *MasterServer::GOLDSRC_MASTER_SERVER
end

Instance Method Details

#init_socketObject

Initializes the socket to communicate with the GoldSrc server

See Also:



49
50
51
# File 'lib/steam/servers/goldsrc_server.rb', line 49

def init_socket
  @socket = GoldSrcSocket.new @ip_address, @port, @is_hltv
end

#rcon_auth(password) ⇒ Boolean

Tries to establish RCON authentication with the server with the given password

This will send an empty command that will ensure the given password was correct. If successful, the password is stored for future use.

See Also:



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

def rcon_auth(password)
  @rcon_authenticated = true
  @rcon_password = password

  begin
    rcon_exec ''
  rescue RCONNoAuthError
    @rcon_password = nil
  end

  @rcon_authenticated
end

#rcon_exec(command) ⇒ String

Remotely executes a command on the server via RCON

Raises:

See Also:



80
81
82
83
84
85
86
87
88
89
# File 'lib/steam/servers/goldsrc_server.rb', line 80

def rcon_exec(command)
  raise RCONNoAuthError unless @rcon_authenticated

  begin
    @socket.rcon_exec(@rcon_password, command).strip
  rescue RCONNoAuthError
    @rcon_authenticated = false
    raise
  end
end