Mercurial > prosody-modules
annotate mod_broadcast/mod_broadcast.lua @ 966:a65df6e97d94
mod_firewall: Add time and date deps
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 06 Apr 2013 14:02:38 +0100 |
parents | e318a341d332 |
children | 0fc9e1f086c1 |
rev | line source |
---|---|
786
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local allowed_senders = module:get_option_set("broadcast_senders", {}); |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local jid_bare = require "util.jid".bare; |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 function send_to_online(message) |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local c = 0; |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 for hostname, host_session in pairs(hosts) do |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 if host_session.sessions then |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 for username in pairs(host_session.sessions) do |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 c = c + 1; |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 message.attr.to = username.."@"..hostname; |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 module:send(message); |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 end |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 end |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 end |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 return c; |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 end |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 function send_message(event) |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 local stanza = event.stanza; |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 if allowed_senders:contains(jid_bare(stanza.attr.from)) then |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 local c = send_to_online(stanza); |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 module:log("debug", "Broadcast stanza from %s to %d online users", stanza.attr.from, c); |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 return true; |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 else |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 module:log("warn", "Broadcasting is not allowed for %s", stanza.attr.from); |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 end |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 end |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 |
e318a341d332
mod_broadcast: New module to set up a component that forwards received messages to all online users (similar to Openfire's broadcast module) (thanks Yann Verry)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 module:hook("message/bare", send_message); |