egs_users: Introduce broadcast_all/1 to broadcast messages to all online users.
This commit is contained in:
parent
6c8b831fd2
commit
d69fe073a8
@ -53,14 +53,12 @@ global(Message) ->
|
||||
if length(Message) > 511 ->
|
||||
io:format("global: message too long~n");
|
||||
true ->
|
||||
{ok, List} = egs_users:select(all),
|
||||
lists:foreach(fun(User) -> User#users.pid ! {egs, notice, top, Message} end, List)
|
||||
egs_users:broadcast_all({egs, notice, top, Message})
|
||||
end.
|
||||
|
||||
%% @doc Warp all players to a new map.
|
||||
warp(QuestID, ZoneID, MapID, EntryID) ->
|
||||
{ok, List} = egs_users:select(all),
|
||||
lists:foreach(fun(User) -> User#users.pid ! {egs, warp, QuestID, ZoneID, MapID, EntryID} end, List).
|
||||
egs_users:broadcast_all({egs, warp, QuestID, ZoneID, MapID, EntryID}).
|
||||
|
||||
%% @doc Warp one player to a new map.
|
||||
warp(GID, QuestID, ZoneID, MapID, EntryID) ->
|
||||
|
@ -235,9 +235,7 @@ event({chat, _FromTypeID, FromGID, _FromName, Modifiers, ChatMsg}, #state{gid=Us
|
||||
[TmpMessage|_] = re:split(ChatMsg, "\\0\\0", [{return, binary}]),
|
||||
LogMessage = re:replace(TmpMessage, "\\n", " ", [global, {return, binary}]),
|
||||
log("chat from ~s: ~s", [[re:replace(LogName, "\\0", "", [global, {return, binary}])], [re:replace(LogMessage, "\\0", "", [global, {return, binary}])]]),
|
||||
%% broadcast
|
||||
{ok, List} = egs_users:select(all),
|
||||
lists:foreach(fun(X) -> X#users.pid ! {egs, chat, UserGID, BcastTypeID, BcastGID, BcastName, Modifiers, ChatMsg} end, List);
|
||||
egs_users:broadcast_all({egs, chat, UserGID, BcastTypeID, BcastGID, BcastName, Modifiers, ChatMsg});
|
||||
|
||||
%% @todo There's at least 9 different sets of locations. Handle all of them correctly.
|
||||
event(counter_background_locations_request, _State) ->
|
||||
|
@ -20,7 +20,7 @@
|
||||
-module(egs_users).
|
||||
-behaviour(gen_server).
|
||||
|
||||
-export([start_link/0, stop/0, broadcast/2, find_by_pid/1, set_zone/3]). %% API.
|
||||
-export([start_link/0, stop/0, broadcast/2, broadcast_all/1, find_by_pid/1, 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.
|
||||
@ -47,6 +47,9 @@ stop() ->
|
||||
broadcast(Message, PlayersGID) ->
|
||||
gen_server:cast(?SERVER, {broadcast, Message, PlayersGID}).
|
||||
|
||||
broadcast_all(Message) ->
|
||||
gen_server:cast(?SERVER, {broadcast_all, Message}).
|
||||
|
||||
find_by_pid(Pid) ->
|
||||
gen_server:call(?SERVER, {find_by_pid, Pid}).
|
||||
|
||||
@ -225,6 +228,10 @@ handle_cast({broadcast, Message, PlayersGID}, State) ->
|
||||
end || GID <- PlayersGID],
|
||||
{noreply, State};
|
||||
|
||||
handle_cast({broadcast_all, Message}, State) ->
|
||||
[Pid ! Message || {_GID, #users{pid=Pid}} <- State#stateu.users],
|
||||
{noreply, State};
|
||||
|
||||
handle_cast(_Msg, State) ->
|
||||
{noreply, State}.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user