Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Game Servers in OTP

Game Servers in OTP

Given at ElixirConf 2014

Martin Schürrer

July 26, 2014
Tweet

More Decks by Martin Schürrer

Other Decks in Programming

Transcript

  1. Architecture big-picture The Table-FSM Life of an in-game event Real

    world concerns BoldPoker <3 Elixir Lessons Learned & QA
  2. Architecture big-picture The Table-FSM Life of an in-game event Real

    world concerns BoldPoker <3 Elixir Lessons Learned & QA
  3. [ {DealCards, [cards_to_deal, :private]}, {Knocking, [5000]}, {DealCards, [cards_to_deal, :private]}, {Negotiation,

    []}, {Play, [contra_enabled: true]}, {Play, []}, {Play, []}, … {Play, []}, {Play, []}, {Result, []} ]
  4. {:next_stage, new_stage_data, new_state_data} ! {:end_game, new_stage_data, new_state_data} ! Table.broadcast_event {:next_state,

    next_state_name, new_state_data} ! {:stop, reason, new_state_data} ! GenServer.reply Table.playing/2 -----> DealCards.playing/3
  5. Architecture big-picture The Table-FSM Life of an in-game event Real

    world concerns BoldPoker <3 Elixir Lessons Learned & QA
  6. P1 {Table,9} {Player,1} { "type": "playACard", "card": "XH" } {:game_event,

    {:play_card,{:ten,:hearts}} ProtocolJSON.parse/1
  7. Architecture big-picture The Table-FSM Life of an in-game event Real

    world concerns BoldPoker <3 Elixir Lessons Learned & QA
  8. P1 P2 P3 P4 {Table,9} P5 P6 P7 old new

    ConnectionProxy {TableMigrator,9}
  9. P1 2 3 4 old new { portable_state portable_state %{table_id:

     9,      player_ids:  [1,2,3,4],      positions:  %{1  =>  3,                                2  =>  0,                                3  =>  1,                                4  =>  2},      modifications:  [:short_hand],      last_game_id:  123   }
  10. Architecture big-picture The Table-FSM Life of an in-game event Real

    world concerns BoldPoker <3 Elixir Lessons Learned & QA
  11. Architecture big-picture The Table-FSM Life of an in-game event Moving

    tables across servers BoldPoker <3 Elixir Lessons Learned & QA
  12. Perform en/decoding at the system border P1 { "type": "playACard",

    "card": "XH" } {:game_event, {:play_card,{:ten,:hearts}} ProtocolJSON.parse/1 WS
  13. Create your own behaviours for fun better reusability and profit

    easier testing {:next_stage, new_stage_data, new_state_data} {:end_game, new_stage_data, new_state_data}
  14. DB failure? We got all data already, so finish the

    game, then just store result on disk