| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src/query/load_state.erl')
| -rw-r--r-- | src/query/load_state.erl | 110 | 
1 files changed, 0 insertions, 110 deletions
| diff --git a/src/query/load_state.erl b/src/query/load_state.erl deleted file mode 100644 index a03a20f..0000000 --- a/src/query/load_state.erl +++ /dev/null @@ -1,110 +0,0 @@ --module(load_state). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --include("../../include/yaws_api.hrl"). - --record -( -   input, -   { -      player_id :: player:id(), -      session_token :: binary(), -      battle_id :: binary() -   } -). - --record -( -   query_state, -   { -      battle :: battle:struct() -   } -). - --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), -   BattleID = maps:get(<<"bmi">>, JSONReqMap), - -   #input -   { -      player_id = PlayerID, -      session_token = SessionToken, -      battle_id = BattleID -   }. - --spec fetch_data (input()) -> query_state(). -fetch_data (Input) -> -   PlayerID = Input#input.player_id, -   BattleID = Input#input.battle_id, - -   Battle = -      timed_cache:fetch -      ( -         battle_db, -         PlayerID, -         BattleID -      ), - -   #query_state -   { -      battle = Battle -   }. - --spec generate_reply(query_state(), input()) -> binary(). -generate_reply (QueryState, Input) -> -   PlayerID = Input#input.player_id, -   Battle = QueryState#query_state.battle, - -   jiffy:encode -   ( -      [ -         set_timeline:generate(battle:get_encoded_last_turns_effects(Battle)), -         set_map:generate(battle:get_battlemap(Battle)) -         | -         array:sparse_to_list -         ( -            array:map -            ( -               fun (IX, CharacterInstance) -> -                  add_char:generate(IX, CharacterInstance, PlayerID) -               end, -               battle:get_character_instances(Battle) -            ) -         ) -      ] -   ). - --spec handle (binary()) -> binary(). -handle (Req) -> -   Input = parse_input(Req), -   security:assert_identity(Input#input.player_id, Input#input.session_token), -   security:lock_queries(Input#input.player_id), -   QueryState = fetch_data(Input), -   security:unlock_queries(Input#input.player_id), -   generate_reply(QueryState, Input). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -out(A) -> -   { -      content, -      "application/json; charset=UTF-8", -      handle(A#arg.clidata) -   }. | 


