summaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-12-15 19:22:30 +0100 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-12-15 19:22:30 +0100 |
commit | d50ae4d7700c4cb083e907b3d3e4ee67b92a6459 (patch) | |
tree | 1a19779b083002f6e9a29f33b8f7ffdb06fa855e /src/battle/query/btl_join.erl | |
parent | 2c3aa52b642858b85ba756df927ff5730f5ee73d (diff) |
Get debug to okay the src files.
Diffstat (limited to 'src/battle/query/btl_join.erl')
-rw-r--r-- | src/battle/query/btl_join.erl | 168 |
1 files changed, 0 insertions, 168 deletions
diff --git a/src/battle/query/btl_join.erl b/src/battle/query/btl_join.erl deleted file mode 100644 index 3ab7be8..0000000 --- a/src/battle/query/btl_join.erl +++ /dev/null @@ -1,168 +0,0 @@ --module(btl_join). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --include("../../../include/yaws_api.hrl"). - --type mode() :: (attack | defend | {invalid, binary()}). - --record -( - input, - { - player_id :: shr_player:id(), - session_token :: binary(), - mode :: mode(), - size :: non_neg_integer(), - roster_ixs :: list(non_neg_integer()), - map_id :: string() - } -). - --record -( - query_state, - { - battle :: btl_battle:type() - } -). - --type input() :: #input{}. --type query_state() :: #query_state{}. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export([out/1]). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec parse_input (binary()) -> input(). -parse_input (Req) -> - JSONReqMap = jiffy:decode(Req, [return_maps]), - PlayerID = maps:get(<<"pid">>, JSONReqMap), - SessionToken = maps:get(<<"stk">>, JSONReqMap), - - Mode = - case maps:get(<<"m">>, JSONReqMap) of - <<"a">> -> attack; - <<"b">> -> defend; - V -> {invalid, V} - end, - - true = ((Mode == attack) or (Mode == defend)), - - Size = - case maps:get(<<"s">>, JSONReqMap) of - <<"s">> -> 8; - <<"m">> -> 16; - <<"l">> -> 24; - _ -> 0 - end, - - Roster = maps:get(<<"r">>, JSONReqMap), - MapID = maps:get(<<"map_id">>, JSONReqMap), - - #input - { - player_id = PlayerID, - session_token = SessionToken, - mode = Mode, - size = Size, - roster_ixs = Roster, - map_id = MapID - }. - --spec authenticate_user (input()) -> ('ok' | 'error'). -authenticate_user (Input) -> - PlayerID = Input#input.player_id, - SessionToken = Input#input.session_token, - - Player = shr_timed_cache:fetch(player_db, any, PlayerID), - - case shr_security:credentials_match(SessionToken, Player) of - true -> ok; - _ -> error - end. - --spec handle_new_attack (input()) -> query_state(). -handle_new_attack (Input) -> - PlayerID = <<"">>, - PlayerDBUser = ataxia_security:user_from_id(PlayerID), - PartySize = 8, - - AvailableBattle = - ataxia_client:update_and_fetch_any - ( - btl_pending, - PlayerDBUser, - ataxic:update_lock - ( - ataxic:apply_function - ( - ataxia_lock, - locked, - [ - ataxic:constant(PlayerDBUser), - ataxic:constant(60) - ] - ) - ), - ataxic:ge - ( - ataxic:field - ( - ataxia_entry:get_value_field(), - ataxic:field - ( - btl_pending_battle:get_free_slots_field(), - ataxic:current_value() - ) - ), - ataxic:constant(PartySize) - ) - ), - - ... - - --spec fetch_data (input()) -> query_state(). -fetch_data (Input) -> - PlayerID = Input#input.player_id, - BattleID = Input#input.battle_id, - - Battle = shr_timed_cache:fetch(battle_db, PlayerID, BattleID), - - #query_state - { - battle = Battle - }. - - --spec generate_reply(query_state(), input()) -> binary(). -generate_reply (QueryState, Input) -> - - Output. - --spec handle (binary()) -> binary(). -handle (Req) -> - Input = parse_input(Req), - case authenticate_user(Input) of - ok -> - QueryState = fetch_data(Input), - generate_reply(QueryState, Input); - - error -> jiffy:encode([shr_disconnected:generate()]) - end. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -out(A) -> - { - content, - "application/json; charset=UTF-8", - handle(A#arg.clidata) - }. |