Class: RconCs::Servers::SourceServer

Inherits:
Object
  • Object
show all
Includes:
Utils::Parsers
Defined in:
lib/rcon_cs/servers/source_server.rb

Overview

Source server class, provides methods to interact with Source servers using the Source Query protocol.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Parsers

#parse_players, #parse_server_info

Constructor Details

#initialize(ip_address, port) ⇒ SourceServer

Returns a new instance of SourceServer.



15
16
17
18
19
20
21
22
23
24
# File 'lib/rcon_cs/servers/source_server.rb', line 15

def initialize(ip_address, port)
  @socket = UDPSocket.new
  @socket.connect(ip_address, port)

  @ip_address = ip_address
  @port = port

  fetch_info
  fetch_players
end

Instance Attribute Details

#infoObject (readonly)

Returns the value of attribute info.



13
14
15
# File 'lib/rcon_cs/servers/source_server.rb', line 13

def info
  @info
end

#ip_addressObject (readonly)

Returns the value of attribute ip_address.



13
14
15
# File 'lib/rcon_cs/servers/source_server.rb', line 13

def ip_address
  @ip_address
end

#pingObject (readonly)

Returns the value of attribute ping.



13
14
15
# File 'lib/rcon_cs/servers/source_server.rb', line 13

def ping
  @ping
end

#playersObject (readonly)

Returns the value of attribute players.



13
14
15
# File 'lib/rcon_cs/servers/source_server.rb', line 13

def players
  @players
end

#portObject (readonly)

Returns the value of attribute port.



13
14
15
# File 'lib/rcon_cs/servers/source_server.rb', line 13

def port
  @port
end

#rulesObject (readonly)

Returns the value of attribute rules.



13
14
15
# File 'lib/rcon_cs/servers/source_server.rb', line 13

def rules
  @rules
end

Instance Method Details

#fetch_infoObject



26
27
28
29
# File 'lib/rcon_cs/servers/source_server.rb', line 26

def fetch_info
  response = send_packet(Packets::InfoPacket.new)
  @info = parse_server_info(response.raw_body)
end

#fetch_playersObject



31
32
33
34
# File 'lib/rcon_cs/servers/source_server.rb', line 31

def fetch_players
  response = send_packet(Packets::PlayersPacket.new)
  @players = parse_players(response.raw_body)
end

#send_packet(packet) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/rcon_cs/servers/source_server.rb', line 36

def send_packet(packet)
  response = send_packet_to_server packet

  # retry with challenge if needed
  response = send_packet_to_server packet, response.body if response.type == :challenge

  response
end