Browse Source

new protocol

Maxim Sokhatsky 11 years ago
parent
commit
f86c3f6ce7
1 changed files with 11 additions and 55 deletions
  1. 11 55
      apps/face/src/protocol.erl

+ 11 - 55
apps/face/src/protocol.erl

@@ -4,59 +4,15 @@
 -include_lib("n2o/include/wf.hrl").
 -jsmacro([take/2,attach/1,join/1,discard/3,player_info/2,reveal/4,piece/2,logout/0,pause/2]).
 
-attach(Token) ->
-    ws:send(bert:encodebuf(bert:tuple(
-        bert:atom('client'),
-        bert:tuple(bert:atom("session_attach"), Token)))).
-
-join(Game) ->
-    ws:send(bert:encodebuf(bert:tuple(
-        bert:atom('client'),
-        bert:tuple(bert:atom("join_game"), Game)))).
-
-logout() ->
-    ws:send(bert:encodebuf(bert:tuple(
-        bert:atom('client'),
-        bert:tuple(bert:atom("logout"))))).
-
-take(GameId,Place) ->
-    ws:send(bert:encodebuf(bert:tuple(
-        bert:atom('client'),
-        bert:tuple(bert:atom("game_action"),GameId,
-            bert:atom("okey_take"),[{pile,Place}])))).
-
-discard(GameId, Color, Value) ->
-    ws:send(bert:encodebuf(bert:tuple(
-        bert:atom('client'),
-        bert:tuple(
-            bert:atom("game_action"),
-            GameId,
-            bert:atom("okey_discard"),
-            [{tile, bert:tuple(bert:atom("OkeyPiece"), Color, Value)}])))).
-
-player_info(User,GameModule) ->
-    ws:send(bert:encodebuf(bert:tuple(
-        bert:atom('client'),
-        bert:tuple(bert:atom("get_player_stats"),bert:binary(User),bert:atom(GameModule))))).
-
-piece(Color,Value) ->
-    bert:tuple(bert:atom("OkeyPiece"), Color, Value).
-
+attach(Token) -> ws:send(enc(tuple(atom('client'),tuple(atom("session_attach"), Token)))).
+join(Game) -> ws:send(enc(tuple(atom('client'),tuple(atom("join_game"), Game)))).
+logout() -> ws:send(enc(tuple(atom('client'),tuple(atom("logout"))))).
+pause(GameId, Action) -> ws:send(enc(tuple(atom("client"),tuple(atom("pause_game"),atom("undefined"),GameId,atom(Action))))).
+take(GameId,Place) -> ws:send(enc(tuple(atom('client'),tuple(atom("game_action"),GameId,atom("okey_take"),[{pile,Place}])))).
+discard(GameId, Color, Value) -> ws:send(enc(tuple(atom('client'),tuple(atom("game_action"),GameId,atom("okey_discard"),
+    [{tile,tuple(atom("OkeyPiece"), Color, Value)}])))).
+player_info(User,GameModule) -> ws:send(enc(tuple(atom('client'),tuple(atom("get_player_stats"),bin(User),atom(GameModule))))).
+piece(Color,Value) -> tuple(atom("OkeyPiece"), Color, Value).
 reveal(GameId, Color, Value, Hand) ->
-    ws:send(bert:encodebuf(bert:tuple(
-        bert:atom('client'),
-        bert:tuple(
-            bert:atom("game_action"),
-            GameId,
-            bert:atom("okey_reveal"),
-            [{discarded, bert:tuple(bert:atom("OkeyPiece"), Color, Value)},
-             {hand, Hand}])))).
-
-pause(GameId, Action) ->
-    ws:send(bert:encodebuf(bert:tuple(
-        bert:atom("client"),
-        bert:tuple(
-            bert:atom("pause_game"),
-            bert:atom("undefined"),
-            GameId,
-            bert:atom(Action))))).
+    ws:send(enco(tuple(atom('client'),tuple(atom("game_action"),GameId,atom("okey_reveal"),
+        [{discarded, tuple(atom("OkeyPiece"), Color, Value)},{hand, Hand}])))).