class Zrcon::Packet
Attributes
data[RW]
id[RW]
type[RW]
Public Class Methods
auth(password)
click to toggle source
# File lib/zrcon/packet.rb, line 24 def self.auth(password) new type: 3, data: password end
command(cmd)
click to toggle source
# File lib/zrcon/packet.rb, line 28 def self.command(cmd) new type: 2, data: cmd end
decode(raw)
click to toggle source
# File lib/zrcon/packet.rb, line 32 def self.decode(raw) raw = raw.to_s fields = raw.unpack("l<l<Z*x") Packet.new id: fields.shift, type: fields.shift, data: fields.shift end
new(id: next_id, type: 2, data: "")
click to toggle source
# File lib/zrcon/packet.rb, line 5 def initialize(id: next_id, type: 2, data: "") @id = id @type = type @data = data end
next_id()
click to toggle source
# File lib/zrcon/packet.rb, line 15 def self.next_id @id ||= -1 @id += 1 end
Public Instance Methods
encode()
click to toggle source
# File lib/zrcon/packet.rb, line 20 def encode [10 + data.length, id, type, data].pack("l<l<l<A#{data.length}xx") end
next_id()
click to toggle source
# File lib/zrcon/packet.rb, line 11 def next_id self.class.next_id end