2022-11-15 11:13:48 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require_relative '../packer'
|
|
|
|
|
|
|
|
##
|
|
|
|
# SvClientDrop
|
|
|
|
#
|
|
|
|
# Server -> Client
|
|
|
|
class SvClientDrop
|
|
|
|
attr_accessor :client_id, :reason, :silent
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def init_raw(data)
|
|
|
|
u = Unpacker.new(data)
|
|
|
|
@client_id = u.get_int
|
|
|
|
@reason = u.get_string
|
2022-11-15 11:55:43 +00:00
|
|
|
@reason = @reason == '' ? nil : @reason
|
2022-11-15 11:13:48 +00:00
|
|
|
@silent = u.get_int
|
|
|
|
end
|
|
|
|
|
|
|
|
def init_hash(attr)
|
|
|
|
@client_id = attr[:client_id] || 0
|
2022-11-15 11:55:43 +00:00
|
|
|
@reason = attr[:reason] == '' ? nil : attr[:reason]
|
2022-11-15 11:13:48 +00:00
|
|
|
@silent = attr[:silent] || false
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_h
|
|
|
|
{
|
|
|
|
client_id: @client_id,
|
|
|
|
reason: @reason,
|
|
|
|
silent: @silent
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def silent?
|
|
|
|
!@silent.zero?
|
|
|
|
end
|
|
|
|
|
|
|
|
# basically to_network
|
|
|
|
# int array the Server sends to the Client
|
|
|
|
def to_a
|
|
|
|
Packer.pack_int(@client_id) +
|
|
|
|
Packer.pack_str(@reason) +
|
|
|
|
Packer.pack_int(@silent)
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
to_h
|
|
|
|
end
|
|
|
|
end
|