psu_game Improve exit handling.

This commit is contained in:
Loïc Hoguin 2010-07-20 10:15:19 +02:00
parent 04265d71dc
commit 10d1f4f85b

View File

@ -36,11 +36,15 @@ start_link(Port) ->
%% @spec cleanup(Pid) -> ok %% @spec cleanup(Pid) -> ok
%% @doc Cleanup the data associated with the failing process. %% @doc Cleanup the data associated with the failing process.
cleanup(Pid) -> cleanup(Pid) ->
{ok, User} = egs_user_model:read({pid, Pid}), case egs_user_model:read({pid, Pid}) of
{ok, User} ->
egs_user_model:delete(User#egs_user_model.id), egs_user_model:delete(User#egs_user_model.id),
{ok, List} = egs_user_model:select({neighbors, User}), {ok, List} = egs_user_model:select({neighbors, User}),
lists:foreach(fun(Other) -> Other#egs_user_model.pid ! {psu_player_unspawn, User} end, List), lists:foreach(fun(Other) -> Other#egs_user_model.pid ! {psu_player_unspawn, User} end, List),
io:format("game (~p): quit~n", [User#egs_user_model.id]). io:format("game (~p): quit~n", [User#egs_user_model.id]);
{error, _Reason} ->
ignore
end.
%% @doc Listen for connections. %% @doc Listen for connections.
@ -134,8 +138,7 @@ char_select() ->
reload, reload,
?MODULE:char_select(); ?MODULE:char_select();
{error, closed} -> {error, closed} ->
log("quit"), closed %% exit
egs_user_model:delete(get(gid))
end. end.
%% @doc Character selection handler. %% @doc Character selection handler.
@ -467,9 +470,9 @@ loop(SoFar) ->
[dispatch(Orig) || Orig <- Packets], [dispatch(Orig) || Orig <- Packets],
?MODULE:loop(Rest); ?MODULE:loop(Rest);
{ssl_closed, _} -> {ssl_closed, _} ->
exit(ssl_closed); ssl_closed; %% exit
{ssl_error, _, _} -> {ssl_error, _, _} ->
exit(ssl_error); ssl_error; %% exit
_ -> _ ->
?MODULE:loop(SoFar) ?MODULE:loop(SoFar)
after 1000 -> after 1000 ->