summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-04-10 13:01:12 +0200
committernsensfel <SpamShield0@noot-noot.org>2018-04-10 13:01:12 +0200
commit1001c3f6cfefd880c1721f2b80c1795197d05365 (patch)
tree8696137b5684547b80129d308bc854a7e74fa0b0 /src/query/load_state.erl
parentd7032b408c5f66a3cb62c44cf0953abe48c39ef9 (diff)
Changing how the server services are organized...
Diffstat (limited to 'src/query/load_state.erl')
-rw-r--r--src/query/load_state.erl110
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)
- }.