2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
9 local st, jid, set = require "util.stanza", require "util.jid", require "util.set";
11 local is_admin = require "core.usermanager".is_admin;
12 local admins = set.new(config.get(module:get_host(), "core", "admins"));
14 function handle_announcement(data)
15 local origin, stanza = data.origin, data.stanza;
16 local host, resource = select(2, jid.split(stanza.attr.to));
18 if resource ~= "announce/online" then
19 return; -- Not an announcement
22 if not is_admin(stanza.attr.from) then
23 -- Not an admin? Not allowed!
24 module:log("warn", "Non-admin %s tried to send server announcement", tostring(jid.bare(stanza.attr.from)));
25 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
29 module:log("info", "Sending server announcement to all online users");
30 local host_session = hosts[host];
31 local message = st.clone(stanza);
32 message.attr.type = "headline";
33 message.attr.from = host;
36 for user in pairs(host_session.sessions) do
38 message.attr.to = user.."@"..host;
39 core_post_stanza(host_session, message);
42 module:log("info", "Announcement sent to %d online users", c);
46 module:hook("message/host", handle_announcement);