Maxim Sokhatsky 11 лет назад
Родитель
Сommit
e8d6f4152c

+ 8 - 11
apps/server/include/requests.hrl

@@ -1,21 +1,18 @@
+
 -include("basic_types.hrl").
 
 -record(session_attach, {token}).
 -record(login, {username, password}).
 -record(logout, {}).
 -record(join_game, {game}).
--record(get_game_info, {game}).
--record(get_player_info, {player_id :: 'PlayerId'() | 0}).
--record(get_player_stats, {player_id :: 'PlayerId'() | 0, game_type}).
--record(subscribe_player_rels, {players :: list()}).
--record(unsubscribe_player_rels, {players :: list()}).
--record(chat,          {chat_id :: 'GameId'(),message :: string()}).
--record(game_action,   { game :: 'GameId'(), action :: any(), args = []}).
+-record(player_stats, {player_id :: 'PlayerId'() | 0, game_type}).
+-record(chat, {chat_id :: 'GameId'(), message :: string()}).
+-record(game_action, {game :: 'GameId'(), action, args = []}).
+-record(social_action, {game :: 'GameId'(), type, recipient::'PlayerId'()}).
 
--record(game_event,    {game :: 'GameId'(), event, args = [] }).
--record(chat_msg,      {chat :: 'GameId'(), content, author_id::'PlayerId'(),author_nick::string() }).
--record(social_action, {game :: 'GameId'(),type,recipient::'PlayerId'()}).
--record(social_action_msg, {type,game::'GameId'(),initiator::'PlayerId'(),recipient::'PlayerId'()}).
+-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(pause_game, {table_id :: integer(),game :: 'GameId'(),action}).
 -record(game_paused, {table_id :: integer(), game :: 'GameId'(),action,who :: 'PlayerId'(),retries}).
 -record(disconnect, {reason_id,reason}).

+ 5 - 136
apps/server/src/game_session.erl

@@ -75,39 +75,6 @@ handle_info({relay_kick, SubscrId, Reason}, State) ->
     gas:info(?MODULE,"Recived a kick notification from the table: ~p", [Reason]),
     handle_relay_kick(Reason, SubscrId, State);
 
-handle_info({delivery, ["user_action", Action, Who, Whom], _} = Notification,
-            #state{rels_players = RelsPlayers, user = User, rpc = RPC } = State) ->
-    gas:info(?MODULE,"Handle_info/2 Delivery: ~p", [Notification]),
-    UserId = User#'PlayerInfo'.id,
-    case list_to_binary(Who) of
-        UserId ->
-            PlayerId = list_to_binary(Whom),
-            case lists:member(PlayerId, RelsPlayers) of
-                true ->
-                    Type = case Action of
-                               "subscribe" -> ?SOCIAL_ACTION_SUBSCRIBE;
-                               "unsubscribe" -> ?SOCIAL_ACTION_UNSUBSCRIBE;
-                               "block" -> ?SOCIAL_ACTION_BLOCK;
-                               "unblock" -> ?SOCIAL_ACTION_UNBLOCK
-                           end,
-                    Msg = #social_action_msg{initiator = UserId,
-                                             recipient = PlayerId,
-                                             type = Type
-                                            },
-
-                    % TODO: put real db change notification from users:343 module here
-                    %       wf:send_db_subscription_change
-                    %       should be additionaly subscribed in bg feed worker binded to USER_EXCHANGE
-
-                    ok = send_message_to_player(RPC, Msg);
-                false ->
-                    do_nothing
-            end;
-        _ ->
-            do_nothing
-    end,
-    {noreply, State};
-
 handle_info({'DOWN', MonitorRef, _Type, _Object, _Info} = Msg, State = #state{rpc_mon = MonitorRef}) ->
     gas:info("connection closed, shutting down session:~p", [Msg]),
     {stop, normal, State};
@@ -157,16 +124,13 @@ handle_client_request(_, _From, #state{user = undefined} = State) ->
     gas:info(?MODULE,"Unknown session call", []),
     {reply, {error, do_session_attach_first}, State};
 
-handle_client_request(#get_game_info{}, _From, State) ->
-    gas:info(?MODULE,"Session get game info", []),
-    {reply, {error, not_implemented}, State};
-
 handle_client_request(#logout{}, _From, State) ->
     gas:info(?MODULE,"Logout", []),
     {stop, normal, ok, State};
 
-handle_client_request(#get_player_stats{player_id = PlayerId, game_type = GameModule}, _From, #state{rpc = RPC} = State) ->
-    Res = GameModule:get_player_stats(PlayerId),
+handle_client_request(#player_stats{player_id = PlayerId, game_type = GameModule}, _From, #state{rpc = RPC} = State) ->
+    % TODO add here everything about player statistic
+    Res = <<"everything player stats :)">>, %GameModule:get_player_stats(PlayerId),
     gas:info(?MODULE,"Get player stats: ~p", [Res]),
     send_message_to_player(RPC, Res),
     {reply, Res, State};
@@ -174,7 +138,7 @@ handle_client_request(#get_player_stats{player_id = PlayerId, game_type = GameMo
 handle_client_request(#chat{chat_id = GameId, message = Msg0}, _From,
                       #state{user = User, games = Games} = State) ->
     gas:info(?MODULE,"Chat", []),
-    Msg = #chat_msg{chat = GameId, content = Msg0,
+    Msg = #chat_event{chat = GameId, content = Msg0,
                     author_id = User#'PlayerInfo'.id,
                     author_nick = User#'PlayerInfo'.login
                    },
@@ -187,42 +151,12 @@ handle_client_request(#chat{chat_id = GameId, message = Msg0}, _From,
           end,
     {reply, Res, State};
 
-handle_client_request(#social_action_msg{type=Type, initiator=P1, recipient=P2}, _From,
-                      #state{user = User} = State) when User =/= undefined ->
-    UserIdBin = User#'PlayerInfo'.id,
-    gas:info(?MODULE,"Social action msg from ~p to ~p (casted by ~p)", [P1, P2, UserIdBin]),
-    UserId = binary_to_list(UserIdBin),
-    case Type of
-        ?SOCIAL_ACTION_SUBSCRIBE ->
-            Subject = binary_to_list(P2),
-            nsm_users:subscribe_user(UserId, Subject),
-            {reply, ok, State};
-        ?SOCIAL_ACTION_UNSUBSCRIBE ->
-            Subject = binary_to_list(P2),
-            nsm_users:remove_subscribe(UserId, Subject),
-            {reply, ok, State};
-        ?SOCIAL_ACTION_BLOCK ->
-            Subject = binary_to_list(P2),
-            wf:send(["subscription", "user", UserId, "block_user"], {Subject}),
-            {reply, ok, State};
-        ?SOCIAL_ACTION_UNBLOCK ->
-            Subject = binary_to_list(P2),
-            wf:send(["subscription", "user", UserId, "unblock_user"], {Subject}),
-            {reply, ok, State};
-        ?SOCIAL_ACTION_LOVE ->
-            {reply, ok, State};
-        ?SOCIAL_ACTION_HAMMER ->
-            {reply, ok, State};
-        UnknownAction ->
-            gas:error(?MODULE,"Unknown social action msg from ~p to ~p: ~w", [P1,P2, UnknownAction]),
-            {reply, {error, unknown_action}, State}
-    end;
 
 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_action_msg{type = Msg#social_action.type,
+    Res = #social_event{type = Msg#social_action.type,
                              game = GameId,
                              recipient = Msg#social_action.recipient,
                              initiator = User#'PlayerInfo'.id},
@@ -235,71 +169,6 @@ handle_client_request(#social_action{} = Msg, _From,
           end,
     {reply, Ans, State};
 
-
-handle_client_request(#subscribe_player_rels{players = Players}, _From,
-            #state{user = User, rels_notif_channel = RelsChannel,
-                   rels_players = RelsPlayers, rpc = RPC} = State) ->
-    gas:info(?MODULE,"Subscribe player relations notifications: ~p", [Players]),
-    UserId = User#'PlayerInfo'.id,
-    UserIdStr = binary_to_list(UserId),
-    %% Create subscription if we need
-    NewRelsChannel =
-        if RelsChannel == undefined ->
-%               {ok, Channel} = nsx_msg:subscribe_for_user_actions(UserIdStr, self()),
-%               Channel;
-                RelsChannel;
-           true ->
-               RelsChannel
-        end,
-    %% Add players relations to which we need to common list
-    F = fun(PlayerId, Acc) ->
-                case lists:member(PlayerId, Acc) of
-                    true -> Acc;
-                    false -> [PlayerId | Acc]
-                end
-        end,
-    NewRelsPlayers = lists:foldl(F, RelsPlayers, Players),
-
-    %% Notify the client about current state of subscription relations.
-    %% (Blocking relations state should be "false" at the start)
-    F2 =
-        fun(PlayerId) ->
-                PlayerIdStr = binary_to_list(PlayerId),
-                Type = case nsm_users:is_user_subscr(UserIdStr, PlayerIdStr) of
-                           true -> ?SOCIAL_ACTION_SUBSCRIBE;
-                           false -> ?SOCIAL_ACTION_UNSUBSCRIBE
-                       end,
-                Msg = #social_action_msg{initiator = UserId,
-                                         recipient = PlayerId,
-                                         type = Type},
-                ok = send_message_to_player(RPC, Msg)
-        end,
-    lists:foreach(F2, Players),
-    NewState = State#state{rels_players = NewRelsPlayers,
-                           rels_notif_channel = NewRelsChannel},
-    {reply, ok, NewState};
-
-
-handle_client_request(#unsubscribe_player_rels{players = Players}, _From,
-                      #state{rels_notif_channel = RelsChannel,
-                             rels_players = RelsPlayers
-                            } = State) ->
-    gas:info(?MODULE,"Unsubscribe player relations notifications", []),
-    %% Remove players from common list
-    NewRelsPlayers = RelsPlayers -- Players,
-
-    %% Remove subscription if we don't need it now
-    NewRelsChannel =
-        if NewRelsPlayers == [] -> nsm_mq_channel:close(RelsChannel),
-               undefined;
-           true ->
-               RelsChannel
-        end,
-    NewState = State#state{rels_players = NewRelsPlayers,
-                           rels_notif_channel = NewRelsChannel},
-    {reply, ok, NewState};
-
-
 handle_client_request(#join_game{game = GameId}, _From,
                       #state{user = User, rpc = RPC, games = Games} = State) ->
     UserId = User#'PlayerInfo'.id,

+ 4 - 7
apps/server/src/lib/known_records.erl

@@ -11,24 +11,21 @@
 fields(T) when is_tuple(T) ->      fields(element(1, T));
 fields(game_action) ->             record_info(fields, game_action);
 fields(join_game) ->               record_info(fields, join_game);
-fields(get_game_info) ->           record_info(fields, get_game_info);
 fields(login) ->                   record_info(fields, login);
 fields(session_attach) ->          record_info(fields, session_attach);
 fields(logout) ->                  record_info(fields, logout);
 fields(chat) ->                    record_info(fields, chat);
-fields(get_player_stats) ->        record_info(fields, get_player_stats);
-fields(subscribe_player_rels) ->   record_info(fields, subscribe_player_rels);
-fields(unsubscribe_player_rels) -> record_info(fields, unsubscribe_player_rels);
+fields(player_stats) ->        record_info(fields, player_stats);
 fields('PlayerInfo') ->            record_info(fields, 'PlayerInfo');
 fields(game_event) ->              record_info(fields, game_event);
-fields(chat_msg) ->                record_info(fields, chat_msg);
+fields(chat_event) ->                record_info(fields, chat_event);
 fields(social_action) ->           record_info(fields, social_action);
-fields(social_action_msg) ->       record_info(fields, social_action_msg);
+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);
 fields(player_left) ->             record_info(fields, player_left);
-fields(okey_debug) ->              record_info(fields, okey_debug);
+
 fields('OkeyPiece') ->             record_info(fields, 'OkeyPiece');
 fields('OkeySeriesResult') ->      record_info(fields, 'OkeySeriesResult');
 fields('OkeyGameResults') ->       record_info(fields, 'OkeyGameResults');

+ 3 - 3
apps/server/src/okey/test_okey.erl

@@ -280,7 +280,7 @@ init_with_join_game(Owner, Host, Port, GameId, OwnId, Rematch, Mode) ->
     TT = ?TEST_TOKEN,
     #'PlayerInfo'{id = Id} = ?TCM:call_rpc(S1, #session_attach{token = TT}) ,
     log(connected),
-    Stats = ?TCM:call_rpc(S1, #get_player_stats{game_type = <<"okey">>, player_id = Id}) ,
+    Stats = ?TCM:call_rpc(S1, #player_stats{game_type = <<"okey">>, player_id = Id}) ,
     #'PlayerOkeyStats'{} = Stats,
     ok = ?TCM:call_rpc(S1, #join_game{game = GameId}) ,
     State = #state{conn = S1, gid = GameId, uid = Id, acker_fun = standard_acker(Owner)},
@@ -296,7 +296,7 @@ init_with_join_game_observe(_Owner, Host, Port, GameId, OwnId, Mode, EJoinResult
     TT = ?TEST_TOKEN,
     #'PlayerInfo'{id = Id} = ?TCM:call_rpc(S1, #session_attach{token = TT}) ,
     log(connected),
-    Stats = ?TCM:call_rpc(S1, #get_player_stats{game_type = <<"okey">>, player_id = Id}) ,
+    Stats = ?TCM:call_rpc(S1, #player_stats{game_type = <<"okey">>, player_id = Id}) ,
     #'PlayerOkeyStats'{} = Stats,
     JR = ?TCM:call_rpc(S1, #join_game{game = GameId}) ,
     gas:info(?MODULE,"JR: ~p, expected result: ~p", [JR, EJoinResult]),
@@ -831,7 +831,7 @@ send_and_receive_social_action(State, Recipient) ->
 
 receive_social_action(_State, Sender, Recipient) ->
     receive
-        #social_action_msg{type = Type, initiator = I, recipient = R} ->
+        #social_event{type = Type, initiator = I, recipient = R} ->
             true = Type == 0,
             true = Sender == I,
             true = Recipient == R