Game Server Architecture
Bots and Players
Bots are special gen_server that acts similar to connection handlers. They also owns game_session instance and loop bot logic for games. Same the conn_handler acts just like a bots it is relying on network connection for user actions and also own game_session.
User Session
Session gen_server for every logged user that holds the references to game relays and chat relays.
Game FSMs
Game events in gen_fsm module for particular games implementations that hold the board information, link to game relay and users sessions pids.
Relays
Relay for routing messages from/to user session instances and/or clients within game instances that hold link to game module.
This picture describes the structural organization of modules and run-time connections of instances. As you can see Game Relay is tightly coupled with particular board implementation and Session connected with Bot implementations and Connection Handler (for real users). All four blocks are gen_servers and just board game implementation is gen_fsm.
+---------------+
| Game Manager |
+---------------+
| TOURNAMENT |
+---------------+
|
V
+---------------+
| RELAY |
+---------------+
| GAME FSM |
+---------------+
| |
+----------------+ +----------------+
| USER SESSION | | USER SESSION |
+----------------+ +----------------+
| BOT | | PLAYER |
+----------------+ +----------------+
Bots and Players
Each instance of game_session holds the state of each player in system. Once created by connection handler or by bot modules game session responds to requests from game clients (bots and players).
send_message { }
Sends async message down to the bot logic or directly to connection socket.call_rpc { }
Process the request to underlying game_session.get_session { }
Return underlying game_session.init_state { }
Overridejoin_game { }
CreateUser Session
state { user,rpc,rpc_mon,games,chats,match_request }
The state hold user info, rpc for pid of self session instance and its erlang:monitor. Also holds all games participations (relay pids) and chats relays for given user.