From 742b665f26a325bc09ce831e470fb7b4a85fdb91 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Sat, 5 Nov 2022 17:48:47 +0100 Subject: [PATCH] rubocop -A --- lib/array.rb | 2 ++ lib/bytes.rb | 2 ++ lib/chat_message.rb | 2 ++ lib/chunk.rb | 8 +++++--- lib/game_client.rb | 4 +++- lib/network.rb | 4 +++- lib/player.rb | 2 ++ lib/server_info.rb | 2 ++ lib/teeworlds-client.rb | 7 ++++--- sample.rb | 1 + spec/01_array_spec.rb | 2 ++ spec/02_packet_spec.rb | 2 ++ spec/03_chunk_spec.rb | 2 ++ 13 files changed, 32 insertions(+), 8 deletions(-) diff --git a/lib/array.rb b/lib/array.rb index 5b1cb0e..dab9c61 100644 --- a/lib/array.rb +++ b/lib/array.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Array def groups_of(max_size) return [] if max_size < 1 diff --git a/lib/bytes.rb b/lib/bytes.rb index a1dcdb6..13edf91 100644 --- a/lib/bytes.rb +++ b/lib/bytes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # turn byte array into hex string def str_hex(data) data.unpack1('H*').scan(/../).join(' ').upcase diff --git a/lib/chat_message.rb b/lib/chat_message.rb index 5a6839b..2de12c9 100644 --- a/lib/chat_message.rb +++ b/lib/chat_message.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ChatMesage attr_reader :mode, :client_id, :target_id, :message, :author diff --git a/lib/chunk.rb b/lib/chunk.rb index fac8224..dba6044 100644 --- a/lib/chunk.rb +++ b/lib/chunk.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'array' require_relative 'network' require_relative 'bytes' @@ -26,9 +28,9 @@ class NetChunk end def to_s - "NetChunk\n" + - " msg=#{msg} sys=#{sys}\n" + - " #{@flags}\n" + + "NetChunk\n" \ + " msg=#{msg} sys=#{sys}\n" \ + " #{@flags}\n" \ " data: #{str_hex(data)}" end diff --git a/lib/game_client.rb b/lib/game_client.rb index 4c87010..cdf1bea 100644 --- a/lib/game_client.rb +++ b/lib/game_client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'player' require_relative 'packer' require_relative 'chat_message' @@ -129,6 +131,6 @@ class GameClient data[:author] = @players[data[:client_id]] msg = ChatMesage.new(data) - @client.hooks[:chat].call(msg) if @client.hooks[:chat] + @client.hooks[:chat]&.call(msg) end end diff --git a/lib/network.rb b/lib/network.rb index dabd841..359c9dc 100644 --- a/lib/network.rb +++ b/lib/network.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + GAME_VERSION = '0.7.5' GAME_NETVERSION_HASH_FORCED = '802f1be60a05665f' -GAME_NETVERSION = '0.7 ' + GAME_NETVERSION_HASH_FORCED +GAME_NETVERSION = "0.7 #{GAME_NETVERSION_HASH_FORCED}".freeze CLIENT_VERSION = 0x0705 NETMSG_NULL = 0 diff --git a/lib/player.rb b/lib/player.rb index 70f64e3..255956e 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Player attr_accessor :id, :local, :team, :name, :clan, :country, :skin_parts, :skin_custom_colors, :skin_colors diff --git a/lib/server_info.rb b/lib/server_info.rb index 6ca6013..a1c3f33 100644 --- a/lib/server_info.rb +++ b/lib/server_info.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ServerInfo attr_reader :version, :name, :map, :gametype diff --git a/lib/teeworlds-client.rb b/lib/teeworlds-client.rb index a7f02ba..d35e3c4 100755 --- a/lib/teeworlds-client.rb +++ b/lib/teeworlds-client.rb @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require 'socket' @@ -122,8 +123,8 @@ class TeeworldsClient def disconnect puts 'disconnecting.' - @netbase.send_packet([NET_CTRLMSG_CLOSE], 0, control: true) unless @netbase.nil? - @s.close unless @s.nil? + @netbase&.send_packet([NET_CTRLMSG_CLOSE], 0, control: true) + @s&.close @signal_disconnect = true end @@ -343,7 +344,7 @@ class TeeworldsClient end @ticks += 1 - send_ctrl_keepalive if @ticks % 8 == 0 + send_ctrl_keepalive if (@ticks % 8).zero? # if @ticks % 20 == 0 # send_chat("hello world") # end diff --git a/sample.rb b/sample.rb index 6802f22..761b727 100755 --- a/sample.rb +++ b/sample.rb @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require_relative 'lib/teeworlds-client' diff --git a/spec/01_array_spec.rb b/spec/01_array_spec.rb index c2cffd5..9158dd4 100644 --- a/spec/01_array_spec.rb +++ b/spec/01_array_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative '../lib/array' describe 'Array', :array do diff --git a/spec/02_packet_spec.rb b/spec/02_packet_spec.rb index 9d81cb2..a87968f 100644 --- a/spec/02_packet_spec.rb +++ b/spec/02_packet_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative '../lib/packet' describe 'Packet', :packet do diff --git a/spec/03_chunk_spec.rb b/spec/03_chunk_spec.rb index 1a3e9e3..51d1e51 100644 --- a/spec/03_chunk_spec.rb +++ b/spec/03_chunk_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative '../lib/chunk' describe 'NetChunk', :net_chunk do