Class: RconLine

Inherits:
Object
  • Object
show all
Defined in:
lib/messages/rcon_line.rb

Overview

RconLine

Server -> Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash_or_raw) ⇒ RconLine

Returns a new instance of RconLine.



12
13
14
15
16
17
18
# File 'lib/messages/rcon_line.rb', line 12

def initialize(hash_or_raw)
  if hash_or_raw.instance_of?(Hash)
    init_hash(hash_or_raw)
  else
    init_raw(hash_or_raw)
  end
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



10
11
12
# File 'lib/messages/rcon_line.rb', line 10

def command
  @command
end

Instance Method Details

#init_hash(attr) ⇒ Object



25
26
27
# File 'lib/messages/rcon_line.rb', line 25

def init_hash(attr)
  @command = attr[:command] || 'hello world'
end

#init_raw(data) ⇒ Object



20
21
22
23
# File 'lib/messages/rcon_line.rb', line 20

def init_raw(data)
  u = Unpacker.new(data)
  @command = u.get_string
end

#to_aObject

basically to_network int array the Server sends to the Client



37
38
39
# File 'lib/messages/rcon_line.rb', line 37

def to_a
  Packer.pack_str(@command)
end

#to_hObject



29
30
31
32
33
# File 'lib/messages/rcon_line.rb', line 29

def to_h
  {
    command: @command
  }
end

#to_sObject



41
42
43
# File 'lib/messages/rcon_line.rb', line 41

def to_s
  to_h
end