Manually fix netbase

This commit is contained in:
ChillerDragon 2022-11-05 17:47:47 +01:00
parent 2b4f7335f3
commit 28477ab90d

View file

@ -1,3 +1,10 @@
# frozen_string_literal: true
##
# NetBase
#
# Lowest network layer logic. Sends packets via udp.
# Also adding the teeworlds protocol packet header.
class NetBase class NetBase
attr_accessor :client_token, :server_token, :ack attr_accessor :client_token, :server_token, :ack
@ -20,6 +27,7 @@ class NetBase
# Sends a packing setting the proper header for you # Sends a packing setting the proper header for you
# #
# @param payload [Array] The Integer list representing the data after the header # @param payload [Array] The Integer list representing the data after the header
# @param num_chunks [Integer] Amount of NetChunks in the payload
# @param flags [Hash] Packet header flags for more details check the class +PacketFlags+ # @param flags [Hash] Packet header flags for more details check the class +PacketFlags+
def send_packet(payload, num_chunks = 1, flags = {}) def send_packet(payload, num_chunks = 1, flags = {})
# unsigned char flags_ack; // 6bit flags, 2bit ack # unsigned char flags_ack; // 6bit flags, 2bit ack
@ -34,11 +42,9 @@ class NetBase
# // TTTTTTTT # // TTTTTTTT
# // TTTTTTTT # // TTTTTTTT
flags_bits = PacketFlags.new(flags).bits flags_bits = PacketFlags.new(flags).bits
header_bits = # unused flags ack num chunks
'00' + # unused flags? # ff # ff ffff aa aaaa aaaa NNNN NNNN
flags_bits + # ffff header_bits = "00#{flags_bits}#{@ack.to_s(2).rjust(10, '0')}#{num_chunks.to_s(2).rjust(8, '0')}"
@ack.to_s(2).rjust(10, '0') + # aa aaaa aaaa
num_chunks.to_s(2).rjust(8, '0') # NNNN NNNN
header = header_bits.chars.groups_of(8).map do |eight_bits| header = header_bits.chars.groups_of(8).map do |eight_bits|
eight_bits.join('').to_i(2) eight_bits.join('').to_i(2)
@ -48,9 +54,6 @@ class NetBase
data = (header + payload).pack('C*') data = (header + payload).pack('C*')
@s.send(data, 0, @ip, @port) @s.send(data, 0, @ip, @port)
if @verbose || flags[:test] puts Packet.new(data, '>').to_s if @verbose || flags[:test]
p = Packet.new(data, '>')
puts p.to_s
end
end end
end end