Class: SvClientDrop

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

Overview

SvClientDrop

Server -> Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash_or_raw) ⇒ SvClientDrop

Returns a new instance of SvClientDrop.



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

#client_idObject

Returns the value of attribute client_id.



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

def client_id
  @client_id
end

#reasonObject

Returns the value of attribute reason.



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

def reason
  @reason
end

#silentObject

Returns the value of attribute silent.



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

def silent
  @silent
end

Instance Method Details

#init_hash(attr) ⇒ Object



28
29
30
31
32
# File 'lib/messages/sv_client_drop.rb', line 28

def init_hash(attr)
  @client_id = attr[:client_id] || 0
  @reason = attr[:reason] == '' ? nil : attr[:reason]
  @silent = attr[:silent] || false
end

#init_raw(data) ⇒ Object



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

def init_raw(data)
  u = Unpacker.new(data)
  @client_id = u.get_int
  @reason = u.get_string
  @reason = @reason == '' ? nil : @reason
  @silent = u.get_int
end

#silent?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/messages/sv_client_drop.rb', line 42

def silent?
  !@silent.zero?
end

#to_aObject

basically to_network int array the Server sends to the Client



48
49
50
51
52
# File 'lib/messages/sv_client_drop.rb', line 48

def to_a
  Packer.pack_int(@client_id) +
    Packer.pack_str(@reason) +
    Packer.pack_int(@silent)
end

#to_hObject



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

def to_h
  {
    client_id: @client_id,
    reason: @reason,
    silent: @silent
  }
end

#to_sObject



54
55
56
# File 'lib/messages/sv_client_drop.rb', line 54

def to_s
  to_h
end