rubocop -A

This commit is contained in:
ChillerDragon 2022-11-05 17:48:47 +01:00
parent 28477ab90d
commit 742b665f26
13 changed files with 32 additions and 8 deletions

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Array class Array
def groups_of(max_size) def groups_of(max_size)
return [] if max_size < 1 return [] if max_size < 1

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
# turn byte array into hex string # turn byte array into hex string
def str_hex(data) def str_hex(data)
data.unpack1('H*').scan(/../).join(' ').upcase data.unpack1('H*').scan(/../).join(' ').upcase

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ChatMesage class ChatMesage
attr_reader :mode, :client_id, :target_id, :message, :author attr_reader :mode, :client_id, :target_id, :message, :author

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_relative 'array' require_relative 'array'
require_relative 'network' require_relative 'network'
require_relative 'bytes' require_relative 'bytes'
@ -26,9 +28,9 @@ class NetChunk
end end
def to_s def to_s
"NetChunk\n" + "NetChunk\n" \
" msg=#{msg} sys=#{sys}\n" + " msg=#{msg} sys=#{sys}\n" \
" #{@flags}\n" + " #{@flags}\n" \
" data: #{str_hex(data)}" " data: #{str_hex(data)}"
end end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_relative 'player' require_relative 'player'
require_relative 'packer' require_relative 'packer'
require_relative 'chat_message' require_relative 'chat_message'
@ -129,6 +131,6 @@ class GameClient
data[:author] = @players[data[:client_id]] data[:author] = @players[data[:client_id]]
msg = ChatMesage.new(data) msg = ChatMesage.new(data)
@client.hooks[:chat].call(msg) if @client.hooks[:chat] @client.hooks[:chat]&.call(msg)
end end
end end

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true
GAME_VERSION = '0.7.5' GAME_VERSION = '0.7.5'
GAME_NETVERSION_HASH_FORCED = '802f1be60a05665f' 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 CLIENT_VERSION = 0x0705
NETMSG_NULL = 0 NETMSG_NULL = 0

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Player class Player
attr_accessor :id, :local, :team, :name, :clan, :country, :skin_parts, :skin_custom_colors, :skin_colors attr_accessor :id, :local, :team, :name, :clan, :country, :skin_parts, :skin_custom_colors, :skin_colors

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ServerInfo class ServerInfo
attr_reader :version, :name, :map, :gametype attr_reader :version, :name, :map, :gametype

View file

@ -1,4 +1,5 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
# frozen_string_literal: true
require 'socket' require 'socket'
@ -122,8 +123,8 @@ class TeeworldsClient
def disconnect def disconnect
puts 'disconnecting.' puts 'disconnecting.'
@netbase.send_packet([NET_CTRLMSG_CLOSE], 0, control: true) unless @netbase.nil? @netbase&.send_packet([NET_CTRLMSG_CLOSE], 0, control: true)
@s.close unless @s.nil? @s&.close
@signal_disconnect = true @signal_disconnect = true
end end
@ -343,7 +344,7 @@ class TeeworldsClient
end end
@ticks += 1 @ticks += 1
send_ctrl_keepalive if @ticks % 8 == 0 send_ctrl_keepalive if (@ticks % 8).zero?
# if @ticks % 20 == 0 # if @ticks % 20 == 0
# send_chat("hello world") # send_chat("hello world")
# end # end

View file

@ -1,4 +1,5 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
# frozen_string_literal: true
require_relative 'lib/teeworlds-client' require_relative 'lib/teeworlds-client'

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_relative '../lib/array' require_relative '../lib/array'
describe 'Array', :array do describe 'Array', :array do

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_relative '../lib/packet' require_relative '../lib/packet'
describe 'Packet', :packet do describe 'Packet', :packet do

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_relative '../lib/chunk' require_relative '../lib/chunk'
describe 'NetChunk', :net_chunk do describe 'NetChunk', :net_chunk do