summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2018-12-13 19:09:49 +0100 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2018-12-13 19:09:49 +0100 |
commit | 3ffb430c28ba3c04835d2762a17aac39a1e64ded (patch) | |
tree | e0200629f57ad717cb247a2cae71d266217848a7 | |
parent | da06d32b135b3bc29cedd15ed8630a0eef0c2ab3 (diff) |
...
-rw-r--r-- | src/battle/query/btl_join.erl | 31 | ||||
-rw-r--r-- | src/shared/struct/shr_db_user.erl | 5 | ||||
-rw-r--r-- | src/special/spe_map.erl | 31 |
3 files changed, 50 insertions, 17 deletions
diff --git a/src/battle/query/btl_join.erl b/src/battle/query/btl_join.erl index 8ecb609..7b8a124 100644 --- a/src/battle/query/btl_join.erl +++ b/src/battle/query/btl_join.erl @@ -63,7 +63,7 @@ parse_input (Req) -> end, Roster = maps:get(<<"r">>, JSONReqMap), - MapID = maps:get(<<"map_id">>, JSONReqMap), + MapID = maps:get(<<"map_id">>, JSONReqMap), #input { @@ -87,6 +87,33 @@ authenticate_user (Input) -> _ -> error end. +-spec handle_new_attack (input()) -> query_state(). +handle_new_attack (Input) -> + PlayerID = <<"">>, + PlayerDBUser = shr_db_user:player(PlayerID), + PartySize = 8, + DBCond = + recl:ge + ( + recl:on_field + ( + btl_builder:get_free_slots_field(), + [recl:current_value()] + ), + recl:constant(PartySize) + ), + + TempLockQuery = + shr_db_query:first_match + ( + db_name, + PlayerDBUser, + DBCond, + shr_db_query:temporary_lock(PlayerDBUser) + ), + + %% Need: find[lone]; update; fetch + -spec fetch_data (input()) -> query_state(). fetch_data (Input) -> PlayerID = Input#input.player_id, @@ -110,9 +137,7 @@ handle (Req) -> Input = parse_input(Req), case authenticate_user(Input) of ok -> - shr_security:lock_queries(Input#input.player_id), QueryState = fetch_data(Input), - shr_security:unlock_queries(Input#input.player_id), generate_reply(QueryState, Input); error -> jiffy:encode([shr_disconnected:generate()]) diff --git a/src/shared/struct/shr_db_user.erl b/src/shared/struct/shr_db_user.erl index 8368024..dcd8685 100644 --- a/src/shared/struct/shr_db_user.erl +++ b/src/shared/struct/shr_db_user.erl @@ -15,7 +15,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -export_type([user/0, permission/0]). --export([can_access/2]). +-export([can_access/2, player/1]). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -24,6 +24,9 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec player (shr_player:id()) -> db_user(). +player (ID) -> {user, ID}. + -spec can_access (permission(), user()) -> boolean(). can_access (_, admin) -> true; can_access (any, _) -> true; diff --git a/src/special/spe_map.erl b/src/special/spe_map.erl index 418d6b5..94075d9 100644 --- a/src/special/spe_map.erl +++ b/src/special/spe_map.erl @@ -16,35 +16,40 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec grant_additional (binary()) -> map_map:type(). +-spec grant_additional (ataxia_id:type()) -> map_map:type(). grant_additional (OwnerID) -> Map = map_map:default(OwnerID), {ok, MapID} = - shr_database:insert + ataxia_client:add ( map_db, - any, - [{user, OwnerID}], + ataxia_security:any(), + [ataxia_security:user_from_id(OwnerID)], Map ), MapSummary = shr_map_summary:new(MapID, <<"Untitled Map">>), - PlayerUpdateQueryOps = - [ - shr_db_query:add_to_field + PlayerUpdateQueryOp = + ataxic:on_field + ( + shr_player:get_map_summaries_field(), + ataxic:apply_function ( - shr_player:get_map_summaries_field(), - [MapSummary], - false + lists, + append, + [ataxic:constant([MapSummary]), ataxic:current_value()] ) - ], + ), ok = - shr_database:commit + ataxia_client:update ( - shr_db_query:new(player_db, OwnerID, admin, PlayerUpdateQueryOps) + player_db, + ataxia_security:admin(), + PlayerUpdateQueryOp, + OwnerID ), Map. |