diff --git a/lib/game_client.rb b/lib/game_client.rb index ea180d5..7f0671d 100644 --- a/lib/game_client.rb +++ b/lib/game_client.rb @@ -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) diff --git a/lib/teeworlds_client.rb b/lib/teeworlds_client.rb index b5fcdff..ecddc04 100644 --- a/lib/teeworlds_client.rb +++ b/lib/teeworlds_client.rb @@ -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}"