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
end
def on_disconnect
call_hook(:disconnect, Context.new(nil))
def on_disconnect(data)
context = Context.new(nil, reason: data)
return if call_hook(:disconnect, context).nil?
puts "got disconnect. reason='#{context.data[:reason]}'"
end
def on_rcon_line(chunk)

View file

@ -354,8 +354,8 @@ class TeeworldsClient
send_info
end
def on_msg_close
@game_client.on_disconnect
def on_msg_close(data)
@game_client.on_disconnect(data)
end
private
@ -365,7 +365,7 @@ class TeeworldsClient
case msg
when NET_CTRLMSG_TOKEN then on_msg_token(data)
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
else
puts "Uknown control message #{msg}"