Comparison

plugins/muc/mod_muc.lua @ 3575:bc3dfc00da5d

MUC: Allow restricting room creation to local JIDs (thanks thomas.mangin).
author Waqas Hussain <waqas20@gmail.com>
date Mon, 08 Nov 2010 20:44:53 +0500
parent 3560:fb49b63e3fe2
child 3576:8d8ce17b83ca
comparison
equal deleted inserted replaced
3574:1e088ec07d33 3575:bc3dfc00da5d
13 13
14 local muc_host = module:get_host(); 14 local muc_host = module:get_host();
15 local muc_name = module:get_option("name"); 15 local muc_name = module:get_option("name");
16 if type(muc_name) ~= "string" then muc_name = "Prosody Chatrooms"; end 16 if type(muc_name) ~= "string" then muc_name = "Prosody Chatrooms"; end
17 local restrict_room_creation = module:get_option("restrict_room_creation"); 17 local restrict_room_creation = module:get_option("restrict_room_creation");
18 if restrict_room_creation and restrict_room_creation ~= true then restrict_room_creation = nil; end 18 if restrict_room_creation then
19 19 if restrict_room_creation == true then
20 restrict_room_creation = "admin";
21 elseif restrict_room_creation ~= "admin" and restrict_room_creation ~= "local" then
22 restrict_room_creation = nil;
23 end
24 end
20 local muc_new_room = module:require "muc".new_room; 25 local muc_new_room = module:require "muc".new_room;
21 local register_component = require "core.componentmanager".register_component; 26 local register_component = require "core.componentmanager".register_component;
22 local deregister_component = require "core.componentmanager".deregister_component; 27 local deregister_component = require "core.componentmanager".deregister_component;
23 local jid_split = require "util.jid".split; 28 local jid_split = require "util.jid".split;
24 local jid_bare = require "util.jid".bare; 29 local jid_bare = require "util.jid".bare;
119 if to_node then 124 if to_node then
120 local bare = to_node.."@"..to_host; 125 local bare = to_node.."@"..to_host;
121 if to_host == muc_host or bare == muc_host then 126 if to_host == muc_host or bare == muc_host then
122 local room = rooms[bare]; 127 local room = rooms[bare];
123 if not room then 128 if not room then
124 if not(restrict_room_creation) or is_admin(stanza.attr.from) then 129 if not(restrict_room_creation) or
130 (restrict_room_creation == "admin" and is_admin(stanza.attr.from)) or
131 (restrict_room_creation == "local" and select(2, jid_split(stanza.attr.from)) == module.host:gsub("^[^%.]+%.", "")) then
125 room = muc_new_room(bare, { 132 room = muc_new_room(bare, {
126 history_length = max_history_messages; 133 history_length = max_history_messages;
127 }); 134 });
128 room.route_stanza = room_route_stanza; 135 room.route_stanza = room_route_stanza;
129 room.save = room_save; 136 room.save = room_save;