Class: ClSay

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

Overview

ClSay

Client -> Server

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash_or_raw) ⇒ ClSay

Returns a new instance of ClSay.



12
13
14
15
16
17
18
# File 'lib/messages/cl_say.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

#messageObject

Returns the value of attribute message.



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

def message
  @message
end

#modeObject

Returns the value of attribute mode.



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

def mode
  @mode
end

#target_idObject

Returns the value of attribute target_id.



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

def target_id
  @target_id
end

Instance Method Details

#init_hash(attr) ⇒ Object



27
28
29
30
31
# File 'lib/messages/cl_say.rb', line 27

def init_hash(attr)
  @mode = attr[:mode] || 0
  @target_id = attr[:target_id] || 0
  @message = attr[:message] || 0
end

#init_raw(data) ⇒ Object



20
21
22
23
24
25
# File 'lib/messages/cl_say.rb', line 20

def init_raw(data)
  u = Unpacker.new(data)
  @mode = u.get_int
  @target_id = u.get_int
  @message = u.get_string
end

#to_aObject

basically to_network int array the client sends to the server



43
44
45
46
47
# File 'lib/messages/cl_say.rb', line 43

def to_a
  Packer.pack_int(@mode) +
    Packer.pack_int(@target_id) +
    Packer.pack_str(@message)
end

#to_hObject



33
34
35
36
37
38
39
# File 'lib/messages/cl_say.rb', line 33

def to_h
  {
    mode: @mode,
    target_id: @target_id,
    message: @message
  }
end

#to_sObject



49
50
51
# File 'lib/messages/cl_say.rb', line 49

def to_s
  to_h
end