summaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-11-28 22:19:38 +0100 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-11-28 22:19:38 +0100 |
commit | 02da4adf9ae6b477376bb27a092feec06a3f2b91 (patch) | |
tree | c679a019547f69f0593f2563373a373ce12f1d82 /src/io | |
parent | 2273ff20faa24a0daba4e4b43ace250716a39172 (diff) |
Fixes timed caches.
Allowing a refresh of the timer opened the door to exploits.
Diffstat (limited to 'src/io')
-rw-r--r-- | src/io/database_shim.erl | 10 | ||||
-rw-r--r-- | src/io/timed_cache.erl | 14 | ||||
-rw-r--r-- | src/io/timed_caches_manager.erl | 8 |
3 files changed, 19 insertions, 13 deletions
diff --git a/src/io/database_shim.erl b/src/io/database_shim.erl index 5ae6a62..0b9ea1c 100644 --- a/src/io/database_shim.erl +++ b/src/io/database_shim.erl @@ -12,7 +12,8 @@ [ generate_db/1, fetch/2, - commit/3 + commit/3, + assert_session_is_valid/2 ] ). @@ -100,3 +101,10 @@ fetch (DB, ObjectID) -> commit (DB, ObjectID, Value) -> add_to_db({DB, ObjectID}, Value), timed_cache:invalidate(DB, ObjectID). + +assert_session_is_valid (_PlayerID, _SessionToken) -> + % Ask PlayerID's login server if SessionToken is correct. + % If so, update last login time to prevent relogin within + % (database_timeout * 2). + % If not, crash. + ok. diff --git a/src/io/timed_cache.erl b/src/io/timed_cache.erl index ec93a48..1b750b0 100644 --- a/src/io/timed_cache.erl +++ b/src/io/timed_cache.erl @@ -48,16 +48,13 @@ init ({DB, ObjectID}) -> {ok, {DB, ObjectID}}. handle_call (invalidate, _, State) -> - {stop, normal, State}; -handle_call (ping, _, {DB, ObjectID}) -> - {noreply, {DB, ObjectID}, timed_caches_manager:get_timeout(DB)}. + {stop, normal, State}. handle_cast (invalidate, State) -> - {stop, normal, State}; -handle_cast (ping, {DB, ObjectID}) -> - {noreply, {DB, ObjectID}, timed_caches_manager:get_timeout(DB)}. + {stop, normal, State}. terminate (_, {DB, ObjectID}) -> + io:format("~nCache entry timed out: ~p.~n", [{DB, ObjectID}]), ets:delete(DB, ObjectID). code_change (_, State, _) -> @@ -78,7 +75,6 @@ fetch (DB, ObjectID) -> [] -> add_to_cache(DB, ObjectID); [{_, TimerPID, Data}] -> - gen_server:cast(TimerPID, ping), Data end. @@ -89,3 +85,7 @@ invalidate (DB, ObjectID) -> [{_, TimerPID, _}] -> gen_server:stop(TimerPID) end. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Notes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/io/timed_caches_manager.erl b/src/io/timed_caches_manager.erl index aad7c37..21f2b6b 100644 --- a/src/io/timed_caches_manager.erl +++ b/src/io/timed_caches_manager.erl @@ -45,7 +45,7 @@ add_cache (DB, none) -> set, public, named_table, - {keypos, 2}, + {keypos, 1}, {read_concurrency, true}, {heir, none} ] @@ -58,7 +58,7 @@ add_cache (DB, Heir) -> set, public, named_table, - {keypos, 2}, + {keypos, 1}, {read_concurrency, true}, {heir, Heir, DB} ] @@ -139,7 +139,5 @@ add_cache (CacheList, DB, Heir) -> [DB|CacheList] end. -get_timeout(battlemap_db) -> - 60000; get_timeout(_) -> - 60000. + 300000. % 5min. |