Fix multiple clients being connected at the same time

This commit is contained in:
ChillerDragon 2022-11-13 15:47:37 +01:00
parent 6275508a18
commit 41b5277613

View file

@ -57,10 +57,12 @@ class NetBase
ack = @ack ack = @ack
ip = @ip ip = @ip
port = @port port = @port
token = @peer_token
unless opts[:client].nil? unless opts[:client].nil?
ack = opts[:client].ack ack = opts[:client].ack
ip = opts[:client].addr.ip ip = opts[:client].addr.ip
port = opts[:client].addr.port port = opts[:client].addr.port
token = opts[:client].token
end end
unless opts[:addr].nil? unless opts[:addr].nil?
ip = opts[:addr].ip ip = opts[:addr].ip
@ -74,9 +76,19 @@ class NetBase
eight_bits.join.to_i(2) eight_bits.join.to_i(2)
end end
header += str_bytes(@peer_token) header += str_bytes(token)
data = (header + payload).pack('C*') data = (header + payload).pack('C*')
puts "send to #{ip}:#{port}" if @verbose client = opts[:client]
if @verbose
if client
puts "send to #{ip}:#{port} " \
"client(id=#{client.id} " \
"token=#{client.token} " \
"name=#{client.player.name} port=#{client.addr.port})"
else
puts "send to #{ip}:#{port}"
end
end
@s.send(data, 0, ip, port) @s.send(data, 0, ip, port)
puts Packet.new(data, '>').to_s if @verbose || opts[:test] puts Packet.new(data, '>').to_s if @verbose || opts[:test]