Changeset View
Standalone View
source/tools/lobbybots/mod_ipstamp/src/mod_ipstamp.erl
Show All 12 Lines | |||||
%% | %% | ||||
%% You should have received a copy of the GNU General Public License | %% You should have received a copy of the GNU General Public License | ||||
%% along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | %% along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
-module(mod_ipstamp). | -module(mod_ipstamp). | ||||
-behaviour(gen_mod). | -behaviour(gen_mod). | ||||
-include("ejabberd.hrl"). | -include("ejabberd.hrl"). | ||||
lyv: This line should be ommited for ejabberd 18.6 and later. Can leave as is for now though I… | |||||
-include("logger.hrl"). | -include("logger.hrl"). | ||||
-include("xmpp.hrl"). | -include("xmpp.hrl"). | ||||
-export([start/2, | -export([start/2, | ||||
stop/1, | stop/1, | ||||
depends/2, | depends/2, | ||||
mod_opt_type/1, | mod_opt_type/1, | ||||
reload/3, | reload/3, | ||||
on_filter_packet/1]). | on_filter_packet/1]). | ||||
start(_Host, _Opts) -> | start(_Host, _Opts) -> | ||||
ejabberd_hooks:add(filter_packet, global, ?MODULE, on_filter_packet, 50). | ejabberd_hooks:add(filter_packet, global, ?MODULE, on_filter_packet, 50). | ||||
stop(_Host) -> | stop(_Host) -> | ||||
ejabberd_hooks:delete(filter_packet, global, ?MODULE, on_filter_packet, 50). | ejabberd_hooks:delete(filter_packet, global, ?MODULE, on_filter_packet, 50). | ||||
depends(_Host, _Opts) -> []. | depends(_Host, _Opts) -> []. | ||||
mod_opt_type(_) -> []. | mod_opt_type(_) -> []. | ||||
reload(_Host, _NewOpts, _OldOpts) -> ok. | reload(_Host, _NewOpts, _OldOpts) -> ok. | ||||
-spec on_filter_packet(Input :: iq()) -> iq() | drop. | -spec on_filter_packet(Input :: iq()) -> iq() | drop. | ||||
on_filter_packet(#iq{type = set, to = To, sub_els = [SubEl]} = Input) -> | on_filter_packet(#iq{type = set, from = From, to = To, sub_els = [SubEl]} = Input) -> | ||||
% We only want to do something for the bots | % We only want to do something for the bots | ||||
case acl:match_rule(global, ipbots, To) of | case acl:match_rule(global, ipbots, To) of | ||||
allow -> | allow -> | ||||
NS = xmpp:get_ns(SubEl), | NS = xmpp:get_ns(SubEl), | ||||
if NS == <<"jabber:iq:gamelist">> -> | if NS == <<"jabber:iq:gamelist">> -> | ||||
SCommand = fxml:get_path_s(SubEl, [{elem, <<"command">>}, cdata]), | SCommand = fxml:get_path_s(SubEl, [{elem, <<"command">>}, cdata]), | ||||
if SCommand == <<"register">> -> | if SCommand == <<"register">> -> | ||||
% Get the sender's IP. | % Get the sender's IP. | ||||
Ip = xmpp:get_meta(Input, ip), | Ip = xmpp:get_meta(Input, ip), | ||||
SIp = inet_parse:ntoa(Ip), | SIp = inet_parse:ntoa(Ip), | ||||
?INFO_MSG(string:concat("Inserting IP into game registration " | ?INFO_MSG(string:concat("Inserting IP into game registration " | ||||
"stanza: ", SIp), []), | "stanza: ", SIp), []), | ||||
% Get the sender's JID | |||||
SJID = jid:encode(From), | |||||
?INFO_MSG(string:concat("Inserting JID into game registration " | |||||
"stanza: ", SJID), []), | |||||
Game = fxml:get_subtag(SubEl, <<"game">>), | Game = fxml:get_subtag(SubEl, <<"game">>), | ||||
GameWithIp = fxml:replace_tag_attr(<<"ip">>, SIp, Game), | GameWithIp = fxml:replace_tag_attr(<<"ip">>, SIp, Game), | ||||
SubEl2 = fxml:replace_subtag(GameWithIp, SubEl), | GameWithIpAndUser = fxml:replace_tag_attr(<<"hostJID">>, SJID, GameWithIp), | ||||
SubEl2 = fxml:replace_subtag(GameWithIpAndUser, SubEl), | |||||
JoshuaJBUnsubmitted Not Done Inline ActionsThis really should be unnecessary. Since we use non-anonymous rooms, we should be able to get the hoster's JID directly via the existing means built-in to the XMPP protocol. JoshuaJB: This really should be unnecessary. Since we use non-anonymous rooms, we should be able to get… | |||||
elexisAuthorUnsubmitted Done Inline ActionsCan you elaborate a bit what you mean? The host sends the "insert-game" stanza to the gamelist bot, the gamelist bot can see the real JID if the room independently of the semi-anonymous-room setting, will insert the realJID of the host into the gamelist stanza and broadcast the updated gamelist to all lobby players. If a client then wants to connect to that game via STUN, the joining client builds the jingle session with the realJID. What is the unnecessary part? Modifying the user sent stanza to insert the JID of the game registerer with an ejabberd module before the stanza is processed by the gamelist bot? How does the joining client know what JID he has to communicate with when joining a host if it's not inserted by the user or by the ejabberd module? elexis: Can you elaborate a bit what you mean?
The host sends the "insert-game" stanza to the gamelist… | |||||
xmpp:set_els(Input, [SubEl2]); | xmpp:set_els(Input, [SubEl2]); | ||||
true -> | true -> | ||||
Input | Input | ||||
end; | end; | ||||
true -> | true -> | ||||
Input | Input | ||||
end; | end; | ||||
_ -> Input | _ -> Input | ||||
end; | end; | ||||
on_filter_packet(Input) -> | on_filter_packet(Input) -> | ||||
Input. | Input. |
This line should be ommited for ejabberd 18.6 and later. Can leave as is for now though I suppose.
Or can add a conditional include.
Nothing major. Just part of the discovery when installing the latest ejabberd.