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 261c6f2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/game_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,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 261c6f2

Please sign in to comment.