Browse Source

unlock ingame chat

Maxim Sokhatsky 11 years ago
parent
commit
df8ec82b6b

+ 2 - 4
apps/server/include/requests.hrl

@@ -7,16 +7,14 @@
 -record(logout, {}).
 -record(join_game, {game}).
 -record(stats_action, {player_id :: 'PlayerId'(), game_type}).
--record(chat, {chat_id :: 'GameId'(), message :: string()}).
+-record(chat, {game, who, message }).
 -record(game_action, {game :: 'GameId'(), action, args = []}).
--record(social_action, {game :: 'GameId'(), type, recipient::'PlayerId'()}).
 -record(pause_game, {table_id :: integer(),game :: 'GameId'(),action}).
 
 % event notifications from server to client
 
 -record(game_event, {game :: 'GameId'(), event, args = [] }).
--record(chat_event, {chat :: 'GameId'(), content, author_id::'PlayerId'(),author_nick::string() }).
--record(social_event, {type,game::'GameId'(),initiator::'PlayerId'(),recipient::'PlayerId'()}).
+-record(chat_event, {game :: 'GameId'(), who :: 'PlayerId'(), message }).
 -record(stats_event, {player_id :: 'PlayerId'(), games, reveals, protocol}).
 -record(game_paused, {table_id :: integer(), game :: 'GameId'(),action,who :: 'PlayerId'(),retries}).
 -record(disconnect, {reason_id,reason}).

+ 3 - 24
apps/server/src/game_session.erl

@@ -136,13 +136,10 @@ handle_client_request(#stats_action{player_id = PlayerId, game_type = GameModule
     send_message_to_player(RPC, Res),
     {reply, Res, State};
 
-handle_client_request(#chat{chat_id = GameId, message = Msg0}, _From,
+handle_client_request(#chat{game = GameId, who = DisplayName, message = Msg0}, _From,
                       #state{user = User, games = Games} = State) ->
-    gas:info(?MODULE,"Chat", []),
-    Msg = #chat_event{chat = GameId, content = Msg0,
-                    author_id = User#'PlayerInfo'.id,
-                    author_nick = User#'PlayerInfo'.login
-                   },
+    gas:info(?MODULE,"Chat Message ~n ~p", [Msg0]),
+    Msg = #chat_event{game = GameId, message = Msg0, who = DisplayName },
     Participation = get_relay(GameId, Games),
     Res = case Participation of
               false ->
@@ -152,24 +149,6 @@ handle_client_request(#chat{chat_id = GameId, message = Msg0}, _From,
           end,
     {reply, Res, State};
 
-
-handle_client_request(#social_action{} = Msg, _From,
-                      #state{user = User, games = Games} = State) ->
-    gas:info(?MODULE,"Social action", []),
-    GameId = Msg#social_action.game,
-    Res = #social_event{type = Msg#social_action.type,
-                             game = GameId,
-                             recipient = Msg#social_action.recipient,
-                             initiator = User#'PlayerInfo'.id},
-    Participation = get_relay(GameId, Games),
-    Ans = case Participation of
-              false ->
-                  {error, chat_not_registered};
-              #participation{rel_pid = Srv, rel_module=RMod} ->
-                  RMod:publish(Srv, Res)
-          end,
-    {reply, Ans, State};
-
 handle_client_request(#join_game{game = GameId}, _From,
                       #state{user = User, rpc = RPC, games = Games} = State) ->
     UserId = User#'PlayerInfo'.id,

+ 0 - 2
apps/server/src/lib/known_records.erl

@@ -22,8 +22,6 @@ fields(reveal_event) ->            record_info(fields, reveal_event);
 fields('PlayerInfo') ->            record_info(fields, 'PlayerInfo');
 fields(game_event) ->              record_info(fields, game_event);
 fields(chat_event) ->                record_info(fields, chat_event);
-fields(social_action) ->           record_info(fields, social_action);
-fields(social_event) ->           record_info(fields, social_event);
 fields(pause_game) ->              record_info(fields, pause_game);
 fields(game_paused) ->             record_info(fields, game_paused);
 fields(disconnect) ->              record_info(fields, disconnect);

+ 42 - 0
apps/server/src/okey/okey_scoring.erl

@@ -333,9 +333,51 @@ check_win([TopRow, BottomRow], Gosterge) ->
                        _ -> E
                   end || E <- FlatList],
     gas:info(?MODULE,"check_reveal/2 ~n    ~p ~p~n",[Normalized, Gosterge]),
+    
+    
 
     ok.
 
+reveals() -> [[3,3,3,5], [3,3,4,4], [5,5,4], [2,2,2,2,2,2,2]].
+
+check_5_5_4(_Deck,_Gosterme) ->
+    Deck=[[{4,4},{4,3},{4,6},{4,7},{1,7},null,{3,9},{3,10},{3,11},{3,12},false_okey,null,null,null,null],
+          [{2,6},{3,6},{1,6},{4,6}, null,null, null, null, null, null,   null,      null,null,null,null]],
+    Gosterme = {1,6},
+    Ret = check_reveal(Deck,Gosterme),
+    io:format("Old Check: ~p",[Ret]),
+    Okey = gosterge_to_okey(Gosterme),
+    Normalized = lists:flatten([case E of
+                      Okey -> okey;
+                      false_okey -> okey;
+                      null -> [];
+                       _ -> E
+                  end || E <- lists:flatten(Deck)]),
+    X = lists:foldl(
+        fun (okey=C,A) -> {C,VA} = lists:keyfind(C,1,A), game:plist_setkey(C,1,A,{C,[C|VA]});
+            ({C,V},A) ->  {C,VA} = lists:keyfind(C,1,A), game:plist_setkey(C,1,A,{C,[{C,V}|VA]}) end,
+        [{1,[]},{2,[]},{3,[]},{4,[]},{okey,[]}],Normalized),
+
+%      [{1,[{1,6}]},                                    []   [2]    [1]
+%       {2,[{2,6}]},                                    []   []     [1]
+%       {3,[{3,6},{3,12},{3,11},{3,10},{3,9}]},         [1,5] [3,5] [4]
+%       {4,[{4,6},{4,7},{4,6},{4,3},{4,4}]},            [1,3] []    [4]
+%       {okey,[okey,okey]}]                                4  4     4
+
+    %  okey
+    %  0      5 5 4run / 5 5 4set
+    %  1      5 4run 4run / 5 4run 4set
+    %  2      5 5 2run / 5 5 2set 
+    %         5 5 (1,x,x,1+3)run / 5 5 2set
+    %         5 4run 3run / 5 4run 3set
+    %         5 (1,x,x,1+3)run 4run / 5 (1,x,x,1+3)run 3set
+    %         5 (1,x,1+2)run 3run / 5 (1,x,1+2)run 3set
+    %         5 3run 4set / 5 3run 4run
+    %  3
+    %  4
+
+    io:format("Deck: ~p",[X]).
+
 %% @spec check_reveal(TashPlaces, Gosterge) -> {RightReveal, WithPairs, SameColor}
 %% @end
 check_reveal([TopRow, BottomRow], Gosterge) ->

+ 17 - 5
apps/web/priv/static/app/js/chat.js

@@ -290,13 +290,25 @@ function chatEditor(evt) {
         var text = e.textContent == null?"":e.textContent.trim();
         if (text != ""){
             text = text.encodeHTML();
-            chatMessage(chatContainer,"100",document.user,text);
+            if ("Chat" != chatContainer)
+            {
+                chatMessage(chatContainer,"100",document.user,text);
                 ws.send(enc(tuple(atom('client'),
                     tuple(atom('message'),
-                          bin(document.user),
-                          bin(document.names),
-                          bin(chatContainer.substr(5)),
-                          utf8toByteArray(text)))));
+                         bin(document.user),
+                         bin(document.names),
+                         bin(chatContainer.substr(5)),
+                         utf8toByteArray(text)))));
+            }
+            else
+            {
+                chatMessage(chatContainer,"100",document.user,text);
+                ws.send(enc(tuple(atom('client'),
+                    tuple(atom('chat'),
+                         scope.gameId,
+                         bin(document.names),
+                         utf8toByteArray(text)))));
+            }
             e.innerHTML = '';
         }
     } else if (evt.keyCode == 13 && evt.altKey == true) {

+ 1 - 0
apps/web/priv/static/app/js/okey/okey_protocol.js

@@ -26,6 +26,7 @@ function OkeyApiProviderScope(scope) {
         "roster_group",
         "roster_end",
         "chat_message",
+        "chat_event",
         // okey game protocol
         "okey_game_info",
         "okey_game_started",

+ 16 - 0
apps/web/priv/static/app/js/roster.js

@@ -12,6 +12,7 @@ function RosterHandlers(scope) {
         document.getElementById("Users-Online-Number").firstElementChild.textContent = e.detail.toString(); 
     });
 
+
     scope.apiProvider.on("online", function (x) {
         var e = {detail: x.detail.json, raw: x.detail.bert};
         var msg = e.detail, id = msg[0], name = msg[1], surname = msg[2];
@@ -50,6 +51,21 @@ function RosterHandlers(scope) {
         onlineHoverOut();
     });
 
+    scope.apiProvider.on("chat_event", function(x) {
+        var e = {detail: x.detail.json, raw: x.detail.bert};
+        var gameId = dec(e.raw).value[0][1],
+            name = dec(e.raw).value[0][2].value,
+            message = dec(e.raw).value[0][3];
+        if (name != document.names)
+        {
+            chatMessage("Chat","1",name==document.user?"Self":name,name+":\n"+utf8decode(message).encodeHTML());
+            scroll_right = -10000;
+            barHover();
+            mouseWheelHandler({'detail':-10000,'wheelDelta':-10000});
+            barHoverOut();
+        }
+    });
+
     scope.apiProvider.on("roster_group", function (x) {
         var e = {detail: x.detail.json, raw: x.detail.bert};
         var list = dec(e.raw).value[0][1];

+ 5 - 1
apps/web/src/okey.erl

@@ -253,10 +253,14 @@ event(pause) ->
 %event({binary,M}) -> {ok,<<"Hello">>};
 
 event({client,{message,From,Name,To,Message}}) ->
-    wf:info(?MODULE,"Chat Message from ~p(~p) to ~p:~n ~p~n",[From,Name,To,Message]),
+    wf:info(?MODULE,"Online Chat Message from ~p(~p) to ~p:~n ~p~n",[From,Name,To,Message]),
     wf:send(To,{server,{chat_message,{From,Name},To,wf:to_binary(Message)}}),
     ok;
 
+%event({client,{chat,GameId,Name,Message}}) ->
+%    wf:info(?MODULE,"In-Game Chat Message from ~p(~p):~n ~p~n",[GameId,Name,Message]),
+%    ok;
+
 event({client,Message}) ->
     wf:info(?MODULE,"Client: ~p", [Message]),
     case wf:session(<<"game_pid">>) of