mod_muc: Add support for being a component
authorMatthew Wild <mwild1@gmail.com>
Thu, 29 Jan 2009 02:14:16 +0000 (02:14 +0000)
committerMatthew Wild <mwild1@gmail.com>
Thu, 29 Jan 2009 02:14:16 +0000 (02:14 +0000)
plugins/mod_muc.lua

index f1b46eed86f1a96200efd434af15648bede3f63f..0b610835c417ef11413ea6e6c4e47e4b12ee97a4 100644 (file)
@@ -8,7 +8,12 @@ local st = require "util.stanza";
 local log = require "util.logger".init("mod_muc");\r
 local multitable_new = require "util.multitable".new;\r
 \r
-local muc_domain = "conference."..module:get_host();\r
+if module:get_host_type() ~= "component" then\r
+       error("MUC should be loaded as a component, please see http://prosody.im/doc/components", 0);\r
+end\r
+\r
+local muc_domain = module:get_host();\r
+\r
 local muc_name = "MUCMUCMUC!!!";\r
 \r
 -- room_name -> room\r
@@ -256,7 +261,7 @@ function handle_to_domain(origin, stanza)
        end\r
 end\r
 \r
-component = register_component(muc_domain, function(origin, stanza)\r
+function handle_stanza(origin, stanza)\r
        local to_node, to_host, to_resource = jid_split(stanza.attr.to);\r
        if stanza.name == "presence" and stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" then\r
                if type == "error" or type == "result" then return; end\r
@@ -272,7 +277,11 @@ component = register_component(muc_domain, function(origin, stanza)
                if type == "error" or type == "result" then return; end\r
                handle_to_domain(origin, stanza);\r
        end\r
-end);\r
+end\r
+\r
+module.load_component = function()\r
+       return handle_stanza; -- Return the function that we want to handle incoming stanzas\r
+end\r
 \r
 module.unload = function()\r
        deregister_component(muc_domain);\r