Show disconnect reason from server by default

I was missing it for a 'Wrong password' error
but it is also nice in the non error case
or all other disconnects triggered by the server
like kick etc
This commit is contained in:
ChillerDragon 2022-11-24 09:53:21 +01:00
parent 06328cf838
commit bddc48ef82
2 changed files with 8 additions and 5 deletions

View file

@ -144,8 +144,11 @@ class GameClient
@client.send_msg_start_info @client.send_msg_start_info
end end
def on_disconnect def on_disconnect(data)
call_hook(:disconnect, Context.new(nil)) context = Context.new(nil, reason: data)
return if call_hook(:disconnect, context).nil?
puts "got disconnect. reason='#{context.data[:reason]}'"
end end
def on_rcon_line(chunk) def on_rcon_line(chunk)

View file

@ -354,8 +354,8 @@ class TeeworldsClient
send_info send_info
end end
def on_msg_close def on_msg_close(data)
@game_client.on_disconnect @game_client.on_disconnect(data)
end end
private private
@ -365,7 +365,7 @@ class TeeworldsClient
case msg case msg
when NET_CTRLMSG_TOKEN then on_msg_token(data) when NET_CTRLMSG_TOKEN then on_msg_token(data)
when NET_CTRLMSG_ACCEPT then on_msg_accept when NET_CTRLMSG_ACCEPT then on_msg_accept
when NET_CTRLMSG_CLOSE then on_msg_close when NET_CTRLMSG_CLOSE then on_msg_close(data)
when NET_CTRLMSG_KEEPALIVE # silently ignore keepalive when NET_CTRLMSG_KEEPALIVE # silently ignore keepalive
else else
puts "Uknown control message #{msg}" puts "Uknown control message #{msg}"