Class: Frostbitten::Client

Inherits:
Object
  • Object
show all
Includes:
Methods::AdminCommands, Methods::NormalCommands
Defined in:
lib/frostbitten/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Methods::NormalCommands

#auth, #players, #serverinfo

Methods included from Methods::AdminCommands

#ban_list, #events, #map_list, #reserved_slots_list

Constructor Details

#initialize(uri = nil, options = {}) ⇒ Client

Initialize class with URI ‘fbrcon://password@ip:port’ Also accept options { :keepalive = true/false, :socket_timeout => 1 } will setup connection object.



22
23
24
25
26
# File 'lib/frostbitten/client.rb', line 22

def initialize(uri=nil, options={})
	if uri
		self.connection = Frostbitten::Connection.new(uri,options)
	end
end

Instance Attribute Details

#connectionObject

Access to the server object.



16
17
18
# File 'lib/frostbitten/client.rb', line 16

def connection
  @connection
end

Instance Method Details

#send(commands) ⇒ Object

Will create Frostbitten::Header and Frostbitten::Message objects for given commands. Accepts either a string or a array of strings to send. Returns a list of words returned by server.



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/frostbitten/client.rb', line 32

def send(commands)
	return unless self.connection

	if commands.is_a? String
		commands = [commands]
	end

	header = Frostbitten::Header.new(:origin => :client, :response => false)
	msg = Frostbitten::Message.new(:words => commands, :header => header)
	message = connection.send(msg)
	return message.words[1..-1]
end