diff --git a/lib/game_client.rb b/lib/game_client.rb index bb3901f..1fcf5b7 100644 --- a/lib/game_client.rb +++ b/lib/game_client.rb @@ -3,6 +3,7 @@ require_relative 'models/player' require_relative 'models/chat_message' require_relative 'models/input_timing' +require_relative 'models/sv_client_drop' require_relative 'packer' require_relative 'context' @@ -58,23 +59,19 @@ class GameClient def on_input_timing(chunk) todo_rename_this = InputTiming.new(chunk.data[1..]) - context = Context.new(todo_rename_this, chunk:, packet:) + context = Context.new(todo_rename_this, chunk:) call_hook(:input_timing, context) end def on_client_drop(chunk) - u = Unpacker.new(chunk.data[1..]) - client_id = u.get_int - reason = u.get_string - silent = u.get_int - + todo_rename_this = SvClientDrop.new(chunk.data[1..]) context = Context.new( nil, - player: @players[client_id], + player: @players[todo_rename_this.client_id], chunk:, - client_id:, - reason: reason == '' ? nil : reason, - silent: silent != 0 + client_id: todo_rename_this.client_id, + reason: todo_rename_this.reason, + silent: todo_rename_this.silent? ) return if call_hook(:client_drop, context).nil? diff --git a/lib/models/sv_client_drop.rb b/lib/models/sv_client_drop.rb index d22ee31..ce58906 100644 --- a/lib/models/sv_client_drop.rb +++ b/lib/models/sv_client_drop.rb @@ -21,12 +21,13 @@ class SvClientDrop u = Unpacker.new(data) @client_id = u.get_int @reason = u.get_string + @reason = @reason == '' ? nil : @reason @silent = u.get_int end def init_hash(attr) @client_id = attr[:client_id] || 0 - @reason = attr[:reason] || '' + @reason = attr[:reason] == '' ? nil : attr[:reason] @silent = attr[:silent] || false end