game_server.htm 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  4. <link href="synrc.css" type="text/css" rel="stylesheet">
  5. </head>
  6. <body>
  7. <div class="threecol">
  8. <div class="left">
  9. <div class="hints"></div>
  10. <div class="main">
  11. <h1>Game Server Architecture</h1>
  12. <h3>Bots and Players</h3>
  13. <p>Bots are special <b>gen_server</b> that acts similar to
  14. connection handlers. They also owns <b>game_session</b> instance
  15. and loop bot logic for games. Same the conn_handler acts
  16. just like a bots it is relying on network connection
  17. for user actions and also own game_session.</p>
  18. <h3>User Session</h3>
  19. <p>Session <b>gen_server</b> for every logged user that
  20. holds the references to game relays and chat relays.</p>
  21. <h3>Game FSMs</h3>
  22. <p>Game events in gen_fsm module for particular games
  23. implementations that hold the board information,
  24. link to game relay and users sessions pids.</p>
  25. <h3>Relays</h3>
  26. <p>Relay for routing messages from/to user session
  27. instances and/or clients within game instances that
  28. hold link to game module.</p>
  29. <p>This picture describes the structural organization of
  30. modules and run-time connections of instances. As you
  31. can see Game Relay is tightly coupled with particular
  32. board implementation and Session connected with Bot
  33. implementations and Connection Handler (for real users).
  34. All four blocks are gen_servers and just board game implementation is gen_fsm. </p>
  35. <code> +---------------+
  36. | Game Manager |
  37. +---------------+
  38. | TOURNAMENT |
  39. +---------------+
  40. |
  41. V
  42. +---------------+
  43. | RELAY |
  44. +---------------+
  45. | GAME FSM |
  46. +---------------+
  47. | |
  48. +----------------+ +----------------+
  49. | USER SESSION | | USER SESSION |
  50. +----------------+ +----------------+
  51. | BOT | | PLAYER |
  52. +----------------+ +----------------+
  53. </code>
  54. <h2>Bots and Players</h2>
  55. <p>Each instance of game_session holds the state of each player in system.
  56. Once created by connection handler or by bot modules game session responds to
  57. requests from game clients (bots and players). </p>
  58. <h2><b>send_message { }</b></h2>
  59. Sends async message down to the bot logic or directly to connection socket.
  60. <h2><b>call_rpc { }</b></h2>
  61. Process the request to underlying game_session.
  62. <h2><b>get_session { }</b></h2>
  63. Return underlying game_session.
  64. <h2><b>init_state { }</b></h2>
  65. Override
  66. <h2><b>join_game { }</b></h2>
  67. Create
  68. <h2>User Session</h2>
  69. <h2><b>state { user,rpc,rpc_mon,games,chats,match_request }</b></h2>
  70. <p>The state hold user info, rpc for pid of self session instance
  71. and its erlang:monitor. Also holds all games
  72. participations (relay pids) and chats relays for given user.</p>
  73. <h2><b>session_attach { token }</b></h2>
  74. Used for authenticate the client by the registered
  75. token by the authentication server.
  76. If the user is not found, then terminate send to client pid.
  77. Also you can check for session_attach_debug for
  78. authentication by token and username.
  79. It replaces the user in state of game_session from
  80. unknown to authorized user info #'PlayerInfo'.
  81. This is the first message sent by Flex client.
  82. Reply with #'PlayerInfo', if not found invalid_token returns.
  83. <h2><b>logout { }</b></h2>
  84. Send termination to client pid uncoditionally. Please use this function for correct consumer behavior at the end of gaming session. Reply is ok.
  85. <h2><b>chat { chat_id, message }</b></h2>
  86. Used for talking through publishing messages to relay.
  87. chat_id is actually the game id to which message should be relayed.
  88. Result not valuable, in case of failure returns chat_not_registered.
  89. <h2><b>get_player_info { player_id = 0 }</b></h2>
  90. Reply with current #'PlayerInfo' stored in State. Other player_id
  91. parameters replies with not_implemented.
  92. <h2><b>match_me { game_type }</b></h2>
  93. Asynchronous match the current user in state along with game type.
  94. Replies with generated request ref integer that will be answered
  95. in match_found API.
  96. <h2><b>match_found { ref,game_id,is_replacing,pid }</b></h2>
  97. Answer to matching request ref with relay as pid, and running game_id.
  98. <h2><b>join_game { game }</b></h2>
  99. Join current user in state for a particular game instance by its id.
  100. This is the second message send by Flex client. Returns #'TableInfo' for success. In case of failure returns: game_not_found, already_joined, this_game_is_private.
  101. <h2><b>game_event { game, event, args }</b></h2>
  102. This is both info and cast async API for handling game events.
  103. Send async notification message from SERVER to PLAYER.
  104. <h2><b>game_action { game, action, msg }</b></h2>
  105. This is just like game_event but being sent from PLAYERS to SERVER.
  106. <h2><b>pause_game { game, action }</b></h2>
  107. Action could be pause or resume. Then message downstreams to FSM by signaling.
  108. <h2><b>rematch { game }</b></h2>
  109. Rematching request for current player in USER SESSION for existing game instance. Message forwarded to FSM module by signaling.
  110. <h2><b>game_crashed { game }</b></h2>
  111. <h2><b>game_rematched { game }</b></h2>
  112. <h2><b>chat_msg { game }</b></h2>
  113. <h2><b>social_action { game, type, initiator, recepient }</b></h2>
  114. <h2><b>social_action_msg { type, initiator, recepient }</b></h2>
  115. </div>
  116. <div class="contents">
  117. <iframe src="contents.htm" frameborder=0 width=340 height=2190></iframe>
  118. </div>
  119. </div>
  120. </body>
  121. </html>