From e1c7e78b4b4db2f818226faf58efff82fbdfeeaa Mon Sep 17 00:00:00 2001 From: nsensfel Date: Wed, 29 Aug 2018 16:46:13 +0200 Subject: Updates TODOs, handles max health changes. --- src/battle/game-logic/btl_turn_actions_move.erl | 26 +++++++++++++++---------- src/battle/game-logic/btl_victory.erl | 6 ++++-- src/character/chr_shim.erl | 2 +- src/character/query/chr_update.erl | 2 +- src/character/struct/chr_character.erl | 14 ++++++------- src/db/logic/db_access.erl | 6 +++--- src/login/query/lgn_sign_up.erl | 2 +- src/map/query/map_update.erl | 5 +++-- src/shared/struct/shr_player.erl | 7 ++++--- 9 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/battle/game-logic/btl_turn_actions_move.erl b/src/battle/game-logic/btl_turn_actions_move.erl index 5669b75..1485094 100644 --- a/src/battle/game-logic/btl_turn_actions_move.erl +++ b/src/battle/game-logic/btl_turn_actions_move.erl @@ -61,10 +61,9 @@ get_path_cost_and_destination (Data, Path) -> ) -> 'ok'. assert_character_can_move (Data, Cost) -> - Character = btl_character_turn_data:get_character(Data), - CharacterStatistics = btl_character:get_statistics(Character), - CharacterMovementPoints = - shr_statistics:get_movement_points(CharacterStatistics), + CharacterData = btl_character_turn_data:get_character_current_data(Data), + CharacterStats= btl_character_current_data:get_statistics(CharacterData), + CharacterMovementPoints = shr_statistics:get_movement_points(CharacterStats), true = (Cost =< CharacterMovementPoints), @@ -72,19 +71,24 @@ assert_character_can_move (Data, Cost) -> -spec commit_move ( + btl_character_current_data:type(), btl_character_turn_update:type(), list(btl_direction:type()), btl_location:type() ) -> btl_character_turn_update:type(). -commit_move (Update, Path, NewLocation) -> +commit_move (PreviousCurrentData, Update, Path, NewLocation) -> Data = btl_character_turn_update:get_data(Update), Character = btl_character_turn_data:get_character(Data), CharacterIX = btl_character_turn_data:get_character_ix(Data), UpdatedCharacter = btl_character:set_location(NewLocation, Character), + S0Data = btl_character_turn_data:set_character(UpdatedCharacter, Data), + S1Data = btl_character_turn_data:refresh_character_current_data(S0Data), - UpdatedData = btl_character_turn_data:set_character(UpdatedCharacter, Data), + S0Update = btl_character_turn_update:set_data(S1Data, Update), + S1Update = + btl_turn_actions:handle_max_health_changes(PreviousCurrentData, S0Update), TimelineItem = btl_turn_result:new_character_moved(CharacterIX, Path, NewLocation), @@ -103,15 +107,15 @@ commit_move (Update, Path, NewLocation) -> ] ), - S0Update = + S2Update = btl_character_turn_update:add_to_timeline ( TimelineItem, DBQuery, - Update + S1Update ), - btl_character_turn_update:set_data(UpdatedData, S0Update). + S2Update. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -124,9 +128,11 @@ commit_move (Update, Path, NewLocation) -> -> btl_character_turn_update:type(). handle (BattleAction, Update) -> Data = btl_character_turn_update:get_data(Update), + CharacterCurrentData = + btl_character_turn_data:get_character_current_data(Data), Path = btl_battle_action:get_path(BattleAction), {PathCost, NewLocation} = get_path_cost_and_destination(Data, Path), assert_character_can_move(Data, PathCost), - commit_move(Update, Path, NewLocation). + commit_move(CharacterCurrentData, Update, Path, NewLocation). diff --git a/src/battle/game-logic/btl_victory.erl b/src/battle/game-logic/btl_victory.erl index 5611302..116fdc3 100644 --- a/src/battle/game-logic/btl_victory.erl +++ b/src/battle/game-logic/btl_victory.erl @@ -69,7 +69,8 @@ handle_player_defeat (PlayerIX, Update) -> Battle = btl_character_turn_data:get_battle(Data), Characters = btl_battle:get_characters(Battle), - %% FIXME: The controlled character might slip through. + %% FIXME [FUNCTION: battle][MEDIUM]: The controlled character might slip + %% through. {UpdatedCharacters, ModifiedIXs} = mark_players_characters_as_defeated(PlayerIX, Characters), @@ -81,7 +82,8 @@ handle_player_defeat (PlayerIX, Update) -> ModifiedIXs ), - %% TODO: Battle.player[PlayerIX].is_active <- false + %% TODO [FUNCTION: battle][MEDIUM]: Battle.player[PlayerIX].is_active <- + %% false UpdatedBattle = btl_battle:set_characters(UpdatedCharacters, Battle), UpdatedData = btl_character_turn_data:set_battle(UpdatedBattle, Data), diff --git a/src/character/chr_shim.erl b/src/character/chr_shim.erl index d7e688f..04b3708 100644 --- a/src/character/chr_shim.erl +++ b/src/character/chr_shim.erl @@ -20,6 +20,6 @@ generate_random_character_roster () -> Result = chr_roster:new(<<"0">>, <<"0">>), - %% TODO: unimplemented. + %% TODO [DEBUG][REQUIRED]: unimplemented. Result. diff --git a/src/character/query/chr_update.erl b/src/character/query/chr_update.erl index adac09a..90d87c5 100644 --- a/src/character/query/chr_update.erl +++ b/src/character/query/chr_update.erl @@ -89,7 +89,7 @@ update_data (QueryState, Input) -> chr_character:validate(Inventory, Character), - %% TODO + %% TODO [FUNCTION: chr][REQUIRED]: unimplemented. QueryState. -spec commit_update (query_state(), input()) -> 'ok'. diff --git a/src/character/struct/chr_character.erl b/src/character/struct/chr_character.erl index 80b9bcd..0b1056e 100644 --- a/src/character/struct/chr_character.erl +++ b/src/character/struct/chr_character.erl @@ -69,12 +69,12 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec validate_name (binary()) -> ok. validate_name (_Name) -> - % TODO: unimplemented + % TODO [SECURITY][LOW]: unimplemented ok. -spec validate_portrait (shr_inventory:type(), binary()) -> ok. validate_portrait (_Inventory, _Portrait) -> - % TODO: unimplemented + % TODO [SECURITY][LOW]: unimplemented ok. -spec validate_weapons @@ -84,22 +84,22 @@ validate_portrait (_Inventory, _Portrait) -> ) -> ok. validate_weapons (_Inventory, {_ActiveWeapon, _SecondaryWeapon}) -> - % TODO: unimplemented + % TODO [SECURITY][LOW]: unimplemented ok. -spec validate_armor (shr_inventory:type(), shr_armor:id()) -> ok. validate_armor (_Inventory, _Armor) -> - % TODO: unimplemented + % TODO [SECURITY][LOW]: unimplemented ok. -spec validate_glyphs (shr_inventory:type(), array:array(shr_glyph:id())) -> ok. validate_glyphs (_Inventory, _Glyphs) -> - % TODO: unimplemented + % TODO [SECURITY][LOW]: unimplemented ok. -spec validate_glyph_board (shr_inventory:type(), shr_glyph_board:id()) -> ok. validate_glyph_board (_Inventory, _GlyphBoard) -> - % TODO: unimplemented + % TODO [SECURITY][LOW]: unimplemented ok. -spec validate_glyphs_on_board @@ -109,7 +109,7 @@ validate_glyph_board (_Inventory, _GlyphBoard) -> ) -> ok. validate_glyphs_on_board (_Glyphs, _GlyphBoard) -> - % TODO: unimplemented + % TODO [SECURITY][LOW]: unimplemented ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/db/logic/db_access.erl b/src/db/logic/db_access.erl index 0a18edb..d62e4ec 100644 --- a/src/db/logic/db_access.erl +++ b/src/db/logic/db_access.erl @@ -88,7 +88,7 @@ insert_at (DB, ID, ReadPerm, WritePerm, Value) -> any()) -> ({'aborted', any()} | {'atomic', {'ok', binary()}}). insert (DB, ReadPerm, WritePerm, Value) -> - ID = <<"?">>, %% TODO: gen new ID. + ID = <<"?">>, %% TODO [FUNCTION: db][HIGH]: gen new ID. case insert_at(DB, ID, ReadPerm, WritePerm, Value) of {'atomic', 'ok'} -> {'atomic', {'ok', ID}}; {aborted, Val} -> {aborted, Val} @@ -114,7 +114,7 @@ reserve (DB, ID, Cred) -> [Cred], { reserved, - <<"?">> %% TODO: timestamp + <<"?">> %% TODO [FUNCTION: db][LOW]: timestamp } ). @@ -126,7 +126,7 @@ reserve (DB, ID, Cred) -> ) -> ({'aborted', any()} | {'atomic', ({'ok', any()} | 'not_found')}). remove (_DB, _ID, _Cred) -> - %% TODO: unimplemented + %% TODO [FUNCTION: db][MEDIUM]: unimplemented %% Don't forget to checkt that Cred has write access before removing the %% value. {'aborted', 'unimplemented'}. diff --git a/src/login/query/lgn_sign_up.erl b/src/login/query/lgn_sign_up.erl index 6a2b3d5..4111597 100644 --- a/src/login/query/lgn_sign_up.erl +++ b/src/login/query/lgn_sign_up.erl @@ -118,7 +118,7 @@ generate_reply (QueryState) -> -spec handle (binary()) -> binary(). handle (Req) -> Input = parse_input(Req), - %% TODO: validate input + %% TODO [SECURITY][LOW]: validate input size. QueryState = register_user(Input), generate_reply(QueryState). diff --git a/src/map/query/map_update.erl b/src/map/query/map_update.erl index 4c38ddf..a4e4038 100644 --- a/src/map/query/map_update.erl +++ b/src/map/query/map_update.erl @@ -47,7 +47,7 @@ parse_input (Req) -> MapHeight = maps:get(<<"h">>, JSONReqMap), MapContent = maps:get(<<"t">>, JSONReqMap), - %% TODO: those checks should be done while queries are locked. + %% TODO [LOW]: those checks should be done while queries are locked. true = (MapWidth > 0), true = (MapHeight > 0), true = (length(MapContent) == (MapWidth * MapHeight)), @@ -64,7 +64,8 @@ parse_input (Req) -> lists:all ( fun (Bo) -> - %% FIXME: this does not prevent "Error" tiles. + %% FIXME [SECURITY][LOW]: this does not prevent "Error" + %% tiles. (Bo >= 0) end, B diff --git a/src/shared/struct/shr_player.erl b/src/shared/struct/shr_player.erl index 13fa1ed..0843e87 100644 --- a/src/shared/struct/shr_player.erl +++ b/src/shared/struct/shr_player.erl @@ -89,9 +89,10 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec secure_value (binary(), binary()) -> binary(). secure_value (Salt, Val) -> - % TODO: Maybe it would be a good idea to include the user's IP in there as - % well. This would ensure that sessions alway use the same server (and thus, - % the same caches), and make timed cache exploits easier to prevent. + % TODO [SECURITY][LOW]: Maybe it would be a good idea to include the user's + % IP in there as well. This would ensure that sessions alway use the same + % server (and thus, the same caches), and make timed cache exploits easier to + % prevent. SaltedVal = erlang:iolist_to_binary([Salt, Val]), HashedSaltedVal = crypto:hash(sha384, SaltedVal), -- cgit v1.2.3-70-g09d2