Class: SteamCondenser::Servers::GoldSrcServer

Inherits:
Object
  • Object
show all
Includes:
Logging, GameServer
Defined in:
lib/steam-condenser/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:

Instance Attribute Summary

Attributes included from BaseServer

#host_names, #ip_addresses

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

formatter=, included, level=, #log, logdev=

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 BaseServer

#disconnect, #failsafe, #rotate_ip

Constructor Details

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

Creates a new instance of a GoldSrc server object

Raises:

  • (Error)

    if an host name cannot be resolved


45
46
47
48
49
# File 'lib/steam-condenser/servers/goldsrc_server.rb', line 45

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


32
33
34
# File 'lib/steam-condenser/servers/goldsrc_server.rb', line 32

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:

  • GoldSrcSocket

54
55
56
# File 'lib/steam-condenser/servers/goldsrc_server.rb', line 54

def init_socket
  @socket = Sockets::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:


67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/steam-condenser/servers/goldsrc_server.rb', line 67

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

  begin
    rcon_exec ''
  rescue Error::RCONNoAuth
    @rcon_password = nil
  end

  @rcon_authenticated
end

#rcon_exec(command) ⇒ String

Remotely executes a command on the server via RCON

Raises:

See Also:


85
86
87
88
89
90
91
92
93
94
# File 'lib/steam-condenser/servers/goldsrc_server.rb', line 85

def rcon_exec(command)
  raise Error::RCONNoAuth unless @rcon_authenticated

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