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
def groups_of(max_size)
return [] if max_size < 1

View file

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

View file

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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

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

View file

@ -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

View file

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

View file

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

View file

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

View file

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