TeensyMud - 'A ruby mud server.'

Subject: Player 'quit' and disconnection
Subject: Player 'quit' and disconnection
Author: Tyche
Posted: 01/04/2006 05:44AM

Q. How does player quit and disconnection work?

A. When a player types 'quit' the following occurs.

1) Player#disconnect is only called by the quit command (as well as from cmd_kill I think).
2) It publishes a :logged_out event to the Connection
3) Connection turns on it's @closing flag
4) the above disconnect routine continues, unsubscribes the Connection, etc.
5) At some point, the next input loop, the Reactor will get around to closing the Connection.
6) Now at that point Connection#handle_close sends a :logged_out message to Player#update, and cleans up it's side, unsubscribing the Player.
7) Player#update sends a message to the other players indicating the player quit.

A. There are two other ways you can be booted from the network side.

If you look at Player#update you'll see that you can get a :logged_out or a :disconnect message from the Connection; even without the player typing the command 'quit'. Message :disconnect is a network error of some sort and :logged_out is the user slamming the connection shut them self with their client instead of 'quit' from within the mud.

I've tried to distinguish the events, merely for the sake of generating a different message to the rest of the users. I'm not sure it's entirely meaningful because many mud clients don't shutdown their end of a connection gracefully anyway, and it would always appear as a network error or :disconnect.

So there are three situations in Player were you could get dropped. Maybe a fourth if one adds a command to allow an admin to boot a player. If you are going to do something in common for all situations then you need to put the code in Player#update for :disconnect and :logged_out messages.

You could also combine the cases in Player#update if you don't care
about the distinction or if it's really inaccurate.
  when :disconnected, :logged_out
     do same stuff

Note: There is some duplication of code here which is harmless but I should clean up. (I had made some changes in messaging from tmud 2.5 to 2.6)



reply