game: Separate connection closing handler. Small cleanup.
This commit is contained in:
parent
536fdd5f50
commit
47c656ce96
@ -230,7 +230,6 @@ loop(CSocket, GID, Version) ->
|
|||||||
loop(CSocket, GID, Version, << >>).
|
loop(CSocket, GID, Version, << >>).
|
||||||
|
|
||||||
%% @doc Game's main loop.
|
%% @doc Game's main loop.
|
||||||
%% @todo Have some kind of clock process for keepalive packets.
|
|
||||||
|
|
||||||
loop(CSocket, GID, Version, SoFar) ->
|
loop(CSocket, GID, Version, SoFar) ->
|
||||||
receive
|
receive
|
||||||
@ -245,21 +244,17 @@ loop(CSocket, GID, Version, SoFar) ->
|
|||||||
{psu_keepalive} ->
|
{psu_keepalive} ->
|
||||||
egs_proto:send_keepalive(CSocket, GID),
|
egs_proto:send_keepalive(CSocket, GID),
|
||||||
?MODULE:loop(CSocket, GID, Version, SoFar);
|
?MODULE:loop(CSocket, GID, Version, SoFar);
|
||||||
{psu_player_spawn, SpawnPlayer} ->
|
{psu_player_spawn, PlayerGID} ->
|
||||||
send_spawn(CSocket, GID, SpawnPlayer),
|
send_spawn(CSocket, GID, PlayerGID),
|
||||||
?MODULE:loop(CSocket, GID, Version, SoFar);
|
?MODULE:loop(CSocket, GID, Version, SoFar);
|
||||||
{ssl, _, Data} ->
|
{ssl, _, Data} ->
|
||||||
{Packets, Rest} = egs_proto:packet_split(<< SoFar/bits, Data/bits >>),
|
{Packets, Rest} = egs_proto:packet_split(<< SoFar/bits, Data/bits >>),
|
||||||
[dispatch(CSocket, GID, Version, P) || P <- Packets],
|
[dispatch(CSocket, GID, Version, P) || P <- Packets],
|
||||||
?MODULE:loop(CSocket, GID, Version, Rest);
|
?MODULE:loop(CSocket, GID, Version, Rest);
|
||||||
{ssl_closed, _} ->
|
{ssl_closed, _} ->
|
||||||
log(GID, "ssl closed~n"),
|
close(CSocket, GID);
|
||||||
egs_db:users_delete(GID),
|
|
||||||
ssl:close(CSocket);
|
|
||||||
{ssl_error, _, _} ->
|
{ssl_error, _, _} ->
|
||||||
io:format("ssl error~n"),
|
close(CSocket, GID);
|
||||||
egs_db:users_delete(GID),
|
|
||||||
ssl:close(CSocket);
|
|
||||||
_ ->
|
_ ->
|
||||||
?MODULE:loop(CSocket, GID, Version, SoFar)
|
?MODULE:loop(CSocket, GID, Version, SoFar)
|
||||||
after 1000 ->
|
after 1000 ->
|
||||||
@ -267,6 +262,13 @@ loop(CSocket, GID, Version, SoFar) ->
|
|||||||
?MODULE:loop(CSocket, GID, Version, SoFar)
|
?MODULE:loop(CSocket, GID, Version, SoFar)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
%% @doc Close the connection for the given user.
|
||||||
|
|
||||||
|
close(CSocket, GID) ->
|
||||||
|
log(GID, "quit"),
|
||||||
|
egs_db:users_delete(GID),
|
||||||
|
ssl:close(CSocket).
|
||||||
|
|
||||||
%% @doc Dispatch the command to the right handler.
|
%% @doc Dispatch the command to the right handler.
|
||||||
|
|
||||||
dispatch(CSocket, GID, Version, Packet) ->
|
dispatch(CSocket, GID, Version, Packet) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user