Fix crash on server messages and add tests for it
This commit is contained in:
parent
ec92b073e8
commit
1e829c0eaf
35
integration_test/client/srv_say.rb
Executable file
35
integration_test/client/srv_say.rb
Executable file
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../../lib/teeworlds_client'
|
||||
|
||||
client = TeeworldsClient.new
|
||||
|
||||
connected = false
|
||||
|
||||
client.on_connected do |_|
|
||||
client.rcon_auth(password: 'rcon')
|
||||
connected = true
|
||||
end
|
||||
|
||||
# this should nicley print the server message
|
||||
client.on_chat do |_, msg|
|
||||
puts "[chat] #{msg}"
|
||||
end
|
||||
|
||||
# connect and block main thread
|
||||
client.connect('localhost', 8377, detach: true)
|
||||
|
||||
sleep 0.5 until connected
|
||||
|
||||
puts '[test] sending server hello'
|
||||
client.rcon('say "hello"')
|
||||
sleep 1
|
||||
|
||||
client.rcon('shutdown')
|
||||
sleep 0.2
|
||||
|
||||
# this is also testing a disconnect
|
||||
# if the server shutdown already
|
||||
# should never crash
|
||||
client.disconnect
|
|
@ -160,6 +160,12 @@ then
|
|||
then
|
||||
fail "Error: server still running rcon shutdown failed"
|
||||
fi
|
||||
elif [ "$testname" == "client/srv_say.rb" ]
|
||||
then
|
||||
if ! grep -q '^\[chat\].*hello' "$logdir/ruby_client.txt"
|
||||
then
|
||||
fail "Error: missing 'hello' chat message in client log"
|
||||
fi
|
||||
elif [ "$testname" == "client/multiple_blocks.rb" ]
|
||||
then
|
||||
sleep 1
|
||||
|
|
|
@ -26,6 +26,14 @@ class ChatMesage
|
|||
end
|
||||
|
||||
def to_s
|
||||
"#{@author.name}: #{@message}"
|
||||
# server message
|
||||
return "*** #{@message}" if @client_id == -1
|
||||
|
||||
# player message
|
||||
# should never be from an invalid id
|
||||
# but lets not crash if servers send weird stuff
|
||||
name = ''
|
||||
name = @author.name if @author
|
||||
"#{name}: #{@message}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -446,6 +446,9 @@ class TeeworldsClient
|
|||
# puts "tick"
|
||||
begin
|
||||
pck = @s.recvfrom_nonblock(1400)
|
||||
rescue Errno::ECONNREFUSED
|
||||
puts 'connection problems ...'
|
||||
pck = nil
|
||||
rescue IO::EAGAINWaitReadable
|
||||
pck = nil
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue