From 7f7963189c1b26a886f41f4b74a383dd4a98ee08 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Fri, 11 Nov 2022 17:52:57 +0100 Subject: [PATCH] Got client stuck in connecting till timeout --- lib/game_server.rb | 2 +- lib/map.rb | 17 ++++++++++++++--- lib/teeworlds_server.rb | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/game_server.rb b/lib/game_server.rb index ef1144f..fa8ac03 100644 --- a/lib/game_server.rb +++ b/lib/game_server.rb @@ -13,7 +13,7 @@ class GameServer @pred_game_tick = 0 @map = Map.new( name: 'dm1', - crc: 1_683_261_464, + crc: '98a0a4c50c', # decimal 64548818 size: 6793, sha256: '491af17a510214506270904f147a4c30ae0a85b91bb854395bef8c397fc078c3' ) diff --git a/lib/map.rb b/lib/map.rb index 7c671d5..7284447 100644 --- a/lib/map.rb +++ b/lib/map.rb @@ -3,14 +3,23 @@ require_relative 'bytes' class Map - attr_reader :name, :crc, :size, :sha256, :sha256_str, :sha256_arr + attr_reader :name, :crc, :crc_str, :crc_arr, :size, :sha256, :sha256_str, :sha256_arr def initialize(attr = {}) # map name as String @name = attr[:name] - # crc has to be a positive Integer + # crc hex encoded string (8 characters / 4 bytes) @crc = attr[:crc] + raise "Error: map crc invalid type: #{@crc.class}" unless @crc.instance_of?(String) + + unless @crc.match(/[a-fA-F0-9]{8}/) # str encoded hex + raise "Error: map crc raw string expects size 8 but got #{@crc.size}" + end + + @crc_str = @crc + @crc_arr = str_bytes(@crc) + @crc = @crc_arr.pack('C*') # size has to be a positive Integer @size = attr[:size] @@ -33,7 +42,7 @@ class Map @sha256 = @sha256_arr.pack('C*') @sha256_str = str_hex(@sha256).gsub(' ', '') else - raise "Error: map raw string expects size 32 but got #{@sha256.size}" + raise "Error: map sha256 raw string expects size 64 but got #{@sha256.size}" end elsif @sha256.instance_of?(Array) # int byte array raise "Error: map sha256 array expects size 32 but got #{@sha256.size}" if @sha256.size != 32 @@ -41,6 +50,8 @@ class Map @sha256_arr = @sha256 @sha256 = @sha256.pack('C*') @sha256_str = @sha256.map { |b| b.to_s(16).rjust(2, '0') }.join + else + raise "Error: map sha256 invalid type: #{@sha256.class}" end end end diff --git a/lib/teeworlds_server.rb b/lib/teeworlds_server.rb index c536dea..091fc23 100644 --- a/lib/teeworlds_server.rb +++ b/lib/teeworlds_server.rb @@ -116,7 +116,7 @@ class TeeworldsServer def send_map(addr) data = [] data += Packer.pack_str(@game_server.map.name) - data += Packer.pack_int(@game_server.map.crc) + data += @game_server.map.crc_arr # poor mans pack_raw() data += Packer.pack_int(@game_server.map.size) data += Packer.pack_int(8) # chunk num? data += Packer.pack_int(MAP_CHUNK_SIZE)