diff --git a/src/egs_users.erl b/src/egs_users.erl index f90a1c7..7640669 100644 --- a/src/egs_users.erl +++ b/src/egs_users.erl @@ -20,7 +20,7 @@ -module(egs_users). -behaviour(gen_server). --export([start_link/0, stop/0, broadcast_spawn/2, broadcast_unspawn/2, broadcast/2, set_zone/3]). %% API. +-export([start_link/0, stop/0, broadcast_unspawn/2, broadcast/2, set_zone/3]). %% API. -export([read/1, select/1, write/1, delete/1, item_nth/2, item_add/3, item_qty_add/3, shop_enter/2, shop_leave/1, shop_get/1, money_add/2]). %% Deprecated API. -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). %% gen_server. @@ -44,9 +44,6 @@ start_link() -> stop() -> gen_server:call(?SERVER, stop). -broadcast_spawn(GID, PlayersGID) -> - gen_server:cast(?SERVER, {broadcast_spawn, GID, PlayersGID}). - broadcast_unspawn(GID, PlayersGID) -> gen_server:cast(?SERVER, {broadcast_unspawn, GID, PlayersGID}). @@ -222,13 +219,6 @@ handle_call(stop, _From, State) -> handle_call(_Request, _From, State) -> {reply, ignored, State}. -handle_cast({broadcast_spawn, GID, PlayersGID}, State) -> - {GID, OrigUser} = lists:keyfind(GID, 1, State#stateu.users), - [begin {_, #users{pid=DestPid}} = lists:keyfind(DestGID, 1, State#stateu.users), - DestPid ! {egs, player_spawn, OrigUser} - end || DestGID <- PlayersGID], - {noreply, State}; - handle_cast({broadcast_unspawn, GID, PlayersGID}, State) -> {GID, OrigUser} = lists:keyfind(GID, 1, State#stateu.users), [begin {_, #users{pid=DestPid}} = lists:keyfind(DestGID, 1, State#stateu.users), diff --git a/src/egs_zones.erl b/src/egs_zones.erl index 6d5968a..c614108 100644 --- a/src/egs_zones.erl +++ b/src/egs_zones.erl @@ -75,10 +75,9 @@ handle_call(setid, _From, State) -> handle_call({enter, GID}, _From, State) -> [LID|FreeLIDs] = State#state.freelids, egs_users:set_zone(GID, self(), LID), - Players = State#state.players, - PlayersGID = players_gid(Players), - egs_users:broadcast_spawn(GID, PlayersGID), - {reply, LID, State#state{players=[{GID, LID}|Players], freelids=FreeLIDs}}; + {ok, Spawn} = egs_users:read(GID), + egs_users:broadcast({egs, player_spawn, Spawn}, players_gid(State#state.players)), + {reply, LID, State#state{players=[{GID, LID}|State#state.players], freelids=FreeLIDs}}; handle_call({leave, GID}, _From, State) -> {_, LID} = lists:keyfind(GID, 1, State#state.players),