Browse Source

fix emit message

Maxim Sokhatsky 11 years ago
parent
commit
fbbfa10f93

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

@@ -7,14 +7,14 @@
 -record(logout, {}).
 -record(join_game, {game}).
 -record(stats_action, {player_id :: 'PlayerId'(), game_type}).
--record(chat, {game, who, message }).
+-record(chat, {game, player_id, who, message }).
 -record(game_action, {game :: 'GameId'(), action, args = []}).
 -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, {game :: 'GameId'(), who :: 'PlayerId'(), message }).
+-record(chat_event, {game :: 'GameId'(), player_id :: 'PlayerId'(), who, 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}).

+ 1 - 1
apps/server/src/game_session.erl

@@ -143,7 +143,7 @@ handle_client_request(#stats_action{player_id = PlayerId, game_type = GameModule
 handle_client_request(#chat{game = GameId, who = DisplayName, message = Msg0}, _From,
                       #state{user = User, games = Games} = State) ->
     gas:info(?MODULE,"Chat Message ~n ~p", [Msg0]),
-    Msg = #chat_event{game = GameId, message = Msg0, who = DisplayName },
+    Msg = #chat_event{game = GameId, message = Msg0, player_id = User#'PlayerInfo'.id, who = DisplayName },
     Participation = get_relay(GameId, Games),
     Res = case Participation of
               false ->

+ 11 - 2
apps/server/src/okey/okey_table.erl

@@ -16,6 +16,7 @@
 -include_lib("server/include/game_state.hrl").
 -include_lib("server/include/requests.hrl").
 -include_lib("db/include/journal.hrl").
+-include_lib("kvs/include/user.hrl").
 
 %% --------------------------------------------------------------------
 %% External exports
@@ -1284,11 +1285,13 @@ round_results(
 
     Results = [begin
 
-        #player{user_id = UserId,is_bot=IsBot} = get_player_by_seat_num(SeatNum, Players),
+        Player = #player{user_id = UserId,is_bot=IsBot} = get_player_by_seat_num(SeatNum, Players),
         IsWinner = if SeatNum == Revealer -> RevealerWin; true -> not RevealerWin end,
         GoodShot = if SeatNum == Revealer -> RevealerWin; true -> not lists:member(SeatNum, WrongRejects) end,
         {_, PlayerScoreTotal} = lists:keyfind(SeatNum, 1, TotalScore),
         {_, PlayerScoreRound} = lists:keyfind(SeatNum, 1, RoundScore),
+        
+        io:format("XXX Player ~p",[Player]),
 
         RE = #reveal_event{
             id = ?GAME_STATS:timestamp(),
@@ -1304,11 +1307,17 @@ round_results(
             winner = IsWinner,
             score = PlayerScoreRound,
             total = PlayerScoreTotal},
+
+        PlayerInfo = Player#player.info,
+        DisplayName = wf:to_list(PlayerInfo#'PlayerInfo'.name) ++ " " ++
+                      wf:to_list(PlayerInfo#'PlayerInfo'.surname),
+
         case {SeatNum == Revealer,Revealer,IsBot} of
             {_,none,_} -> ?GAME_STATS:reveal_event(UserId,RE,State);
             {true,_,false}  -> ?GAME_STATS:reveal_event(UserId,RE,State);
             _ -> skip end,
-        RE
+
+        {DisplayName,IsWinner,PlayerScoreRound,PlayerScoreTotal}
 
     end || SeatNum <- lists:seq(1, ?SEATS_NUM)],
 

+ 7 - 0
apps/web/priv/static/app/js/bootloader.js

@@ -206,6 +206,13 @@ function initPauseOverlay() {
     page.insertBefore(svg(html),kakush);
 }
 
+function showRoundEnd(o)
+{
+    $overlay.show();
+    $("#Overlay-Text").text(player + " revealed ");
+
+}
+
 function showRevealHand(o) {
 
     var player    = o.value[0][3][0].value[0][1].value,

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

@@ -320,6 +320,7 @@ function chatEditor(evt) {
                 ws.send(enc(tuple(atom('client'),
                     tuple(atom('chat'),
                          scope.gameId,
+                         bin(document.user),
                          bin(document.names),
                          utf8toByteArray(text)))));
             }

+ 10 - 4
apps/web/priv/static/app/js/okey/okey_protocol.js

@@ -21,6 +21,7 @@ function OkeyApiProviderScope(scope) {
         // roster protocol
         "online_number",
         "online",
+        "chat",
         "offline",
         "roster_item",
         "roster_group",
@@ -65,6 +66,9 @@ function OkeyApiProviderScope(scope) {
             if (msg.data) { this.emitEvent(msg.data,this.beutify(this.parse(dec(msg.data)))); }
 
         },
+
+        // TODO: remove parse/beautify or make it proper BERT to JSON transformation
+
         parse: function(msg) {
             if (Array.isArray(msg)) {
                 if (msg.every(function(el, i) {
@@ -101,10 +105,12 @@ function OkeyApiProviderScope(scope) {
             return msg;
         },
         emitEvent: function(raw,msg) {
-            //console.log(String(dec(raw)));
-            for (var event, i = eventMap.length; i--; ) event = eventMap[i], msg[event] && this.$socket.trigger(event, {
-                detail: {json:msg[event],bert:raw}
-            });
+            for (var event, i = eventMap.length, obj; i--; ) {
+                event = eventMap[i];
+                found = (event == msg[0] || msg[event] != null);
+                body = event == msg[0] ? msg : msg[event];
+                found && this.$socket.trigger(event, {detail: {json:body,bert:raw} });
+            }
         },
         actionTake: function(card) {
             var from = null != card.value ? 1 : 0;

+ 6 - 5
apps/web/priv/static/app/js/roster.js

@@ -58,12 +58,13 @@ function RosterHandlers(scope) {
 
     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)
+        var gameId  = dec(e.raw).value[0][1];
+        var userId  = dec(e.raw).value[0][2].value;
+        var name    = dec(e.raw).value[0][3].value;
+        var message = dec(e.raw).value[0][4];
+        if (userId != document.user)
         {
-            chatMessage("Chat","1",name==document.user?"Self":name,name+":\n"+utf8decode(message));
+            chatMessage("Chat","1",userId==document.user?"Self":userId,name+":\n"+utf8decode(message));
             scroll_right = -10000;
             barHover();
             mouseWheelHandler({'detail':-10000,'wheelDelta':-10000});

BIN
apps/web/priv/static/doc/Kakaranet-Scene.sketch/Data


+ 1 - 1
apps/web/priv/static/doc/Kakaranet-Scene.sketch/metadata

@@ -16,7 +16,7 @@
 		<string>ZapfDingbatsITC</string>
 	</array>
 	<key>length</key>
-	<integer>2878316</integer>
+	<integer>2881780</integer>
 	<key>version</key>
 	<integer>37</integer>
 </dict>

+ 3 - 2
apps/web/src/logallow.erl

@@ -4,10 +4,11 @@
 log_modules() -> [
 %    wf_core,
     n2o_bullet,
-    game_session,
+%    game_session,
     bullet_handler,
-    okey_scoring,
+%    okey_scoring,
     journal,
+    lucky,
 %    n2o_secret,
 %    js_session,
     okey