Mercurial > prosody-hg
comparison plugins/mod_muc.lua @ 752:a9642c1d5827
mod_muc: Add support for being a component
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 29 Jan 2009 02:14:16 +0000 |
| parents | 7653519ec4f2 |
| children | 2ca5fa47f317 |
comparison
equal
deleted
inserted
replaced
| 751:7c22619fdb19 | 752:a9642c1d5827 |
|---|---|
| 6 local jid_bare = require "util.jid".bare; | 6 local jid_bare = require "util.jid".bare; |
| 7 local st = require "util.stanza"; | 7 local st = require "util.stanza"; |
| 8 local log = require "util.logger".init("mod_muc"); | 8 local log = require "util.logger".init("mod_muc"); |
| 9 local multitable_new = require "util.multitable".new; | 9 local multitable_new = require "util.multitable".new; |
| 10 | 10 |
| 11 local muc_domain = "conference."..module:get_host(); | 11 if module:get_host_type() ~= "component" then |
| 12 error("MUC should be loaded as a component, please see http://prosody.im/doc/components", 0); | |
| 13 end | |
| 14 | |
| 15 local muc_domain = module:get_host(); | |
| 16 | |
| 12 local muc_name = "MUCMUCMUC!!!"; | 17 local muc_name = "MUCMUCMUC!!!"; |
| 13 | 18 |
| 14 -- room_name -> room | 19 -- room_name -> room |
| 15 -- occupant_room_nick -> data | 20 -- occupant_room_nick -> data |
| 16 -- affiliation = ... | 21 -- affiliation = ... |
| 254 else | 259 else |
| 255 origin.send(st.error_reply(stanza, "cancel", "service-unavailable", "The muc server doesn't deal with messages and presence directed at it")); | 260 origin.send(st.error_reply(stanza, "cancel", "service-unavailable", "The muc server doesn't deal with messages and presence directed at it")); |
| 256 end | 261 end |
| 257 end | 262 end |
| 258 | 263 |
| 259 component = register_component(muc_domain, function(origin, stanza) | 264 function handle_stanza(origin, stanza) |
| 260 local to_node, to_host, to_resource = jid_split(stanza.attr.to); | 265 local to_node, to_host, to_resource = jid_split(stanza.attr.to); |
| 261 if stanza.name == "presence" and stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" then | 266 if stanza.name == "presence" and stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" then |
| 262 if type == "error" or type == "result" then return; end | 267 if type == "error" or type == "result" then return; end |
| 263 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME what's appropriate? | 268 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME what's appropriate? |
| 264 elseif to_resource and not to_node then | 269 elseif to_resource and not to_node then |
| 270 handle_to_room(origin, stanza) | 275 handle_to_room(origin, stanza) |
| 271 else -- to the main muc domain | 276 else -- to the main muc domain |
| 272 if type == "error" or type == "result" then return; end | 277 if type == "error" or type == "result" then return; end |
| 273 handle_to_domain(origin, stanza); | 278 handle_to_domain(origin, stanza); |
| 274 end | 279 end |
| 275 end); | 280 end |
| 281 | |
| 282 module.load_component = function() | |
| 283 return handle_stanza; -- Return the function that we want to handle incoming stanzas | |
| 284 end | |
| 276 | 285 |
| 277 module.unload = function() | 286 module.unload = function() |
| 278 deregister_component(muc_domain); | 287 deregister_component(muc_domain); |
| 279 end | 288 end |
| 280 module.save = function() | 289 module.save = function() |
