From d50ae4d7700c4cb083e907b3d3e4ee67b92a6459 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Sat, 15 Dec 2018 19:22:30 +0100 Subject: Get debug to okay the src files. --- src/battle/query/btl_join.erl | 168 ------------------------------------- src/battle/query/btl_join.erl.next | 168 +++++++++++++++++++++++++++++++++++++ 2 files changed, 168 insertions(+), 168 deletions(-) delete mode 100644 src/battle/query/btl_join.erl create mode 100644 src/battle/query/btl_join.erl.next (limited to 'src/battle') 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) - }. diff --git a/src/battle/query/btl_join.erl.next b/src/battle/query/btl_join.erl.next new file mode 100644 index 0000000..3ab7be8 --- /dev/null +++ b/src/battle/query/btl_join.erl.next @@ -0,0 +1,168 @@ +-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) + }. -- cgit v1.2.3-70-g09d2