Generate SvClientDrop

twnet g sv SvClientDrop client_id:int reason:str silent:bool
This commit is contained in:
ChillerDragon 2022-11-15 12:13:48 +01:00
parent 3ab4fc61d1
commit c11a7ae2d2

View file

@ -0,0 +1,56 @@
# 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
@silent = u.get_int
end
def init_hash(attr)
@client_id = attr[:client_id] || 0
@reason = attr[:reason] || ''
@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