Use rconline class
This commit is contained in:
parent
5a4d4fac6e
commit
49b2806966
|
@ -3,6 +3,7 @@
|
|||
require_relative 'models/player'
|
||||
require_relative 'models/chat_message'
|
||||
require_relative 'messages/input_timing'
|
||||
require_relative 'messages/rcon_line'
|
||||
require_relative 'messages/sv_client_drop'
|
||||
require_relative 'messages/rcon_cmd_add'
|
||||
require_relative 'messages/rcon_cmd_rem'
|
||||
|
@ -144,11 +145,8 @@ class GameClient
|
|||
end
|
||||
|
||||
def on_rcon_line(chunk)
|
||||
u = Unpacker.new(chunk.data[1..])
|
||||
context = Context.new(
|
||||
nil,
|
||||
line: u.get_string
|
||||
)
|
||||
message = RconLine.new(chunk.data[1..])
|
||||
context = Context.new(message)
|
||||
call_hook(:rcon_line, context)
|
||||
end
|
||||
|
||||
|
|
44
lib/messages/rcon_line.rb
Normal file
44
lib/messages/rcon_line.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../packer'
|
||||
|
||||
##
|
||||
# RconLine
|
||||
#
|
||||
# Server -> Client
|
||||
class RconLine
|
||||
attr_accessor :command
|
||||
|
||||
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)
|
||||
@command = u.get_string
|
||||
end
|
||||
|
||||
def init_hash(attr)
|
||||
@command = attr[:command] || 'hello world'
|
||||
end
|
||||
|
||||
def to_h
|
||||
{
|
||||
command: @command
|
||||
}
|
||||
end
|
||||
|
||||
# basically to_network
|
||||
# int array the Server sends to the Client
|
||||
def to_a
|
||||
Packer.pack_str(@command)
|
||||
end
|
||||
|
||||
def to_s
|
||||
to_h
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue