class Source::Server

Constants

InfoPacket
PingPacket

Attributes

host[RW]
pass[RW]
port[RW]

Public Class Methods

connect(*args) click to toggle source
# File library/source/server.rb, line 12
def self.connect *args
  new(*args).tap do |this|
    this.connect
  end
end
new(host, port = 27015, password = nil) click to toggle source
# File library/source/server.rb, line 18
def initialize host, port = 27015, password = nil
  @host, @port, @pass = host, port, password

  @socket, @connected = UDPSocket.new, false
end

Public Instance Methods

connect() click to toggle source
# File library/source/server.rb, line 24
def connect
  @connected = true if not @connected and @socket.connect @host, @port
end
info() click to toggle source
# File library/source/server.rb, line 40
def info
  raise ConnectionError, 'Not connected to server' unless @connected

  transmit InfoPacket
  response = read.unpack 'CCZ*Z*Z*Z*vc7Z*c'

  %w{type version name map game description appid players slots bots dedicated os password secure version EDF}.pair response
end
rcon(password = nil) click to toggle source
# File library/source/server.rb, line 49
def rcon password = nil
  @pass ||= password
  @rcon ||= RCON.new @host, @port, @password
end
read() click to toggle source
# File library/source/server.rb, line 34
def read
  raise ConnectionError, 'Not connected to server' unless @connected

  @socket.recvfrom(1024)[0][4..-1]
end
transmit(packet) click to toggle source
# File library/source/server.rb, line 28
def transmit packet
  raise ConnectionError, 'Not connected to server' unless @connected

  @socket.send "\xFF\xFF\xFF\xFF#{packet}", 0
end