diff --git a/src/egs_cron.erl b/src/egs_cron.erl index dbe526f..7d91319 100644 --- a/src/egs_cron.erl +++ b/src/egs_cron.erl @@ -18,16 +18,15 @@ -module(egs_cron). -export([start/0]). % external --export([cleanup/0, keepalive/0]). % internal +-export([cleanup/0]). % internal -include("include/records.hrl"). %% @doc Start the cron processes. start() -> - KeepAlivePid = spawn_link(?MODULE, keepalive, []), - spawn_link(?MODULE, cleanup, []), - {ok, KeepAlivePid}. + Pid = spawn_link(?MODULE, cleanup, []), + {ok, Pid}. %% @doc Cleanup the users table of failures to log into the game server. @@ -40,16 +39,3 @@ cleanup() -> reload, ?MODULE:cleanup() end. - -%% @doc Keep connected players alive. -%% @todo Don't even need to send a keepalive packet if we sent a packet in the last Timeout milliseconds. - -keepalive() -> - receive - _ -> - ?MODULE:keepalive() - after 5000 -> - lists:foreach(fun(User) -> User#users.pid ! {psu_keepalive} end, egs_db:users_select_all()), - reload, - ?MODULE:keepalive() - end. diff --git a/src/psu/psu_game.erl b/src/psu/psu_game.erl index 4d952d6..1060896 100644 --- a/src/psu/psu_game.erl +++ b/src/psu/psu_game.erl @@ -66,6 +66,7 @@ process_init(CSocket, MPid) -> link(MPid), put(socket, CSocket), send_0202(), + timer:send_interval(5000, {psu_keepalive}), process(). %% @doc Process the new connections. @@ -427,6 +428,7 @@ myroom_send_packet(Filename) -> send(File). %% @doc Game's main loop. +%% @todo We probably don't want to send a keepalive packet unnecessarily. loop(SoFar) -> receive