Class: RconCs::Servers::SourceServer
- Inherits:
-
Object
- Object
- RconCs::Servers::SourceServer
- 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
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#ip_address ⇒ Object
readonly
Returns the value of attribute ip_address.
-
#ping ⇒ Object
readonly
Returns the value of attribute ping.
-
#players ⇒ Object
readonly
Returns the value of attribute players.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
- #fetch_info ⇒ Object
- #fetch_players ⇒ Object
-
#initialize(ip_address, port) ⇒ SourceServer
constructor
A new instance of SourceServer.
- #send_packet(packet) ⇒ Object
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
#info ⇒ Object (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_address ⇒ Object (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 |
#ping ⇒ Object (readonly)
Returns the value of attribute ping.
13 14 15 |
# File 'lib/rcon_cs/servers/source_server.rb', line 13 def ping @ping end |
#players ⇒ Object (readonly)
Returns the value of attribute players.
13 14 15 |
# File 'lib/rcon_cs/servers/source_server.rb', line 13 def players @players end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
13 14 15 |
# File 'lib/rcon_cs/servers/source_server.rb', line 13 def port @port end |
#rules ⇒ Object (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_info ⇒ Object
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_players ⇒ Object
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 |