Skip to content

Commit

Permalink
Use rconline class
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillerDragon committed Sep 17, 2023
1 parent 5a4d4fa commit 49b2806
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/game_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -144,11 +145,8 @@ def on_disconnect(data)
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

Expand Down
44 changes: 44 additions & 0 deletions lib/messages/rcon_line.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 49b2806

Please sign in to comment.