protocol.erl 1.5 KB

123456789101112131415161718192021
  1. -module(protocol).
  2. -compile({parse_transform, shen}).
  3. -compile(export_all).
  4. -jsmacro([take/2,attach/1,join/1,discard/3,player_info/2,reveal/4,
  5. piece/2,logout/0,pause/2,i_saw_okey/1,i_have_8_tashes/1]).
  6. attach(Token) -> ws:send(enc(tuple(atom('client'),tuple(atom("session_attach"), Token)))).
  7. join(Game) -> ws:send(enc(tuple(atom('client'),tuple(atom("join_game"), Game)))).
  8. logout() -> ws:send(enc(tuple(atom('client'),tuple(atom("logout"))))).
  9. pause(GameId, Action) -> ws:send(enc(tuple(atom('client'),tuple(atom("pause_game"),atom('undefined'),GameId,atom(Action))))).
  10. player_info(User,GameModule) -> ws:send(enc(tuple(atom('client'),tuple(atom("get_player_stats"),bin(User),atom(GameModule))))).
  11. take(GameId,Place) -> ws:send(enc(tuple(atom('client'),tuple(atom("game_action"),GameId,atom("okey_take"),[{pile,Place}])))).
  12. discard(GameId, Color, Value) -> ws:send(enc(tuple(atom('client'),tuple(atom("game_action"),GameId,atom("okey_discard"),
  13. [{tile,tuple(atom("OkeyPiece"), Color, Value)}])))).
  14. piece(Color,Value) -> tuple(atom("OkeyPiece"), Color, Value).
  15. reveal(GameId, Color, Value, Hand) ->
  16. ws:send(enc(tuple(atom('client'),tuple(atom("game_action"),GameId,atom("okey_reveal"),
  17. [{discarded, tuple(atom("OkeyPiece"), Color, Value)},{hand, Hand}])))).
  18. i_saw_okey(GameId) -> ws:send(enc(tuple(atom('client'),tuple(atom("game_action"),GameId,atom("okey_i_saw_okey"),[])))).
  19. i_have_8_tashes(GameId) -> ws:send(enc(tuple(atom('client'),tuple(atom("game_action"),GameId,atom("okey_i_have_8_tashes"),[])))).