egs_game_server: Properly leave the zone when the user is disconnecting.
This commit is contained in:
parent
2de4359c32
commit
378e9a9927
@ -45,15 +45,9 @@ on_exit(Pid) ->
|
|||||||
[egs_users:delete(NPCGID) || {_Spot, NPCGID} <- NPCList],
|
[egs_users:delete(NPCGID) || {_Spot, NPCGID} <- NPCList],
|
||||||
psu_party:stop(PartyPid)
|
psu_party:stop(PartyPid)
|
||||||
end,
|
end,
|
||||||
|
egs_zones:leave(User#users.zonepid, User#users.gid),
|
||||||
|
egs_universes:leave(User#users.uni),
|
||||||
egs_users:delete(User#users.gid),
|
egs_users:delete(User#users.gid),
|
||||||
case User#users.uni of
|
|
||||||
undefined ->
|
|
||||||
ignore;
|
|
||||||
UniID ->
|
|
||||||
egs_universes:leave(UniID),
|
|
||||||
{ok, List} = egs_users:select({neighbors, User}),
|
|
||||||
lists:foreach(fun(Other) -> Other#users.pid ! {egs, player_unspawn, User} end, List)
|
|
||||||
end,
|
|
||||||
io:format("game (~p): quit~n", [User#users.gid]);
|
io:format("game (~p): quit~n", [User#users.gid]);
|
||||||
{error, _Reason} ->
|
{error, _Reason} ->
|
||||||
ignore
|
ignore
|
||||||
|
@ -48,8 +48,10 @@ setid(Pid) ->
|
|||||||
enter(Pid, GID) ->
|
enter(Pid, GID) ->
|
||||||
gen_server:call(Pid, {enter, GID}).
|
gen_server:call(Pid, {enter, GID}).
|
||||||
|
|
||||||
|
leave(undefined, _GID) ->
|
||||||
|
ok;
|
||||||
leave(Pid, GID) ->
|
leave(Pid, GID) ->
|
||||||
gen_server:cast(Pid, {leave, GID}).
|
gen_server:call(Pid, {leave, GID}).
|
||||||
|
|
||||||
get_all_players(Pid, ExcludeGID) ->
|
get_all_players(Pid, ExcludeGID) ->
|
||||||
gen_server:call(Pid, {get_all_players, ExcludeGID}).
|
gen_server:call(Pid, {get_all_players, ExcludeGID}).
|
||||||
@ -75,6 +77,14 @@ handle_call({enter, GID}, _From, State) ->
|
|||||||
egs_users:broadcast_spawn(GID, PlayersGID),
|
egs_users:broadcast_spawn(GID, PlayersGID),
|
||||||
{reply, LID, State#state{players=[{GID, LID}|Players], freelids=FreeLIDs}};
|
{reply, LID, State#state{players=[{GID, LID}|Players], freelids=FreeLIDs}};
|
||||||
|
|
||||||
|
handle_call({leave, GID}, _From, State) ->
|
||||||
|
{_, LID} = lists:keyfind(GID, 1, State#state.players),
|
||||||
|
Players = lists:delete({GID, LID}, State#state.players),
|
||||||
|
PlayersGID = players_gid(Players),
|
||||||
|
FreeLIDs = State#state.freelids,
|
||||||
|
egs_users:broadcast_unspawn(GID, PlayersGID),
|
||||||
|
{reply, ok, State#state{players=Players, freelids=[LID|FreeLIDs]}};
|
||||||
|
|
||||||
handle_call({get_all_players, ExcludeGID}, _From, State) ->
|
handle_call({get_all_players, ExcludeGID}, _From, State) ->
|
||||||
{reply, lists:delete(ExcludeGID, players_gid(State#state.players)), State};
|
{reply, lists:delete(ExcludeGID, players_gid(State#state.players)), State};
|
||||||
|
|
||||||
@ -84,14 +94,6 @@ handle_call(stop, _From, State) ->
|
|||||||
handle_call(_Request, _From, State) ->
|
handle_call(_Request, _From, State) ->
|
||||||
{reply, ignored, State}.
|
{reply, ignored, State}.
|
||||||
|
|
||||||
handle_cast({leave, GID}, State) ->
|
|
||||||
{_, LID} = lists:keyfind(GID, 1, State#state.players),
|
|
||||||
Players = lists:delete({GID, LID}, State#state.players),
|
|
||||||
PlayersGID = players_gid(Players),
|
|
||||||
FreeLIDs = State#state.freelids,
|
|
||||||
egs_users:broadcast_unspawn(GID, PlayersGID),
|
|
||||||
{noreply, State#state{players=Players, freelids=[LID|FreeLIDs]}};
|
|
||||||
|
|
||||||
handle_cast(_Msg, State) ->
|
handle_cast(_Msg, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user