saltysystems / overworld

Open source framework for scalable multiplayer games.
Mozilla Public License 2.0
20 stars 3 forks source link

Session state machine, dumb down zones #54

Closed cmdrk closed 2 weeks ago

cmdrk commented 2 weeks ago

It was starting to become rather nasty to track all of the possible states that a client could be in from the Zone handler, and it wasn't really the Zone's job to do this in the first place.

Instead, I've refactored the session server to be a finite state machine with 3 states: disconnected, connected, and active.

The zone now only tracks the clients connected. It will still send messages to clients when someone connects, disconnects, or parts, but it won't manage the session states beyond that.

To help with that, we now send the full ZoneData for every message. i.e., handle_join/3 now becomes handle_join/4. The same for handle_part, handle_disconnect, and handle_reconnect callbacks.

Callback modules can read the connect client list from the ZoneData and act appropriately.

Whenever a client leaves a zone, they go back to connected state. If they drop their proxy pid (i.e., the connection has been terminated), they will flip over to disconnected state and the timeout handler will run. Once triggered, the session will shut down.