Comparison

plugins/muc/muc.lib.lua @ 6476:fb8a9873728b

plugins/muc/muc.lib: Kick users from outcast hosts
author daurnimator <quae@daurnimator.com>
date Wed, 15 Oct 2014 16:56:42 -0400
parent 6475:3c815a64042b
child 6478:413923bbd1a0
comparison
equal deleted inserted replaced
6475:3c815a64042b 6476:fb8a9873728b
15 local dataform = require "util.dataforms"; 15 local dataform = require "util.dataforms";
16 local iterators = require "util.iterators"; 16 local iterators = require "util.iterators";
17 local jid_split = require "util.jid".split; 17 local jid_split = require "util.jid".split;
18 local jid_bare = require "util.jid".bare; 18 local jid_bare = require "util.jid".bare;
19 local jid_prep = require "util.jid".prep; 19 local jid_prep = require "util.jid".prep;
20 local jid_join = require "util.jid".join;
20 local st = require "util.stanza"; 21 local st = require "util.stanza";
21 local log = require "util.logger".init("mod_muc"); 22 local log = require "util.logger".init("mod_muc");
22 local base64 = require "util.encodings".base64; 23 local base64 = require "util.encodings".base64;
23 local md5 = require "util.hashes".md5; 24 local md5 = require "util.hashes".md5;
24 25
988 end 989 end
989 990
990 function room_mt:set_affiliation(actor, jid, affiliation, reason) 991 function room_mt:set_affiliation(actor, jid, affiliation, reason)
991 if not actor then return nil, "modify", "not-acceptable"; end; 992 if not actor then return nil, "modify", "not-acceptable"; end;
992 993
993 jid = jid_bare(jid); 994 local node, host, resource = jid_split(jid);
995 if not host then return nil, "modify", "not-acceptable"; end
996 jid = jid_join(node, host); -- Bare
997 local is_host_only = node == nil;
994 998
995 if valid_affiliations[affiliation or "none"] == nil then 999 if valid_affiliations[affiliation or "none"] == nil then
996 return nil, "modify", "not-acceptable"; 1000 return nil, "modify", "not-acceptable";
997 end 1001 end
998 affiliation = affiliation ~= "none" and affiliation or nil; -- coerces `affiliation == false` to `nil` 1002 affiliation = affiliation ~= "none" and affiliation or nil; -- coerces `affiliation == false` to `nil`
1028 -- Update roles 1032 -- Update roles
1029 local role = self:get_default_role(affiliation); 1033 local role = self:get_default_role(affiliation);
1030 local role_rank = valid_roles[role or "none"]; 1034 local role_rank = valid_roles[role or "none"];
1031 local occupants_updated = {}; -- Filled with old roles 1035 local occupants_updated = {}; -- Filled with old roles
1032 for nick, occupant in self:each_occupant() do 1036 for nick, occupant in self:each_occupant() do
1033 if occupant.bare_jid == jid then 1037 if occupant.bare_jid == jid or (
1038 -- Outcast can be by host.
1039 is_host_only and affiliation == "outcast" and select(2, jid_split(occupant.bare_jid)) == host
1040 ) then
1034 -- need to publcize in all cases; as affiliation in <item/> has changed. 1041 -- need to publcize in all cases; as affiliation in <item/> has changed.
1035 occupants_updated[occupant] = occupant.role; 1042 occupants_updated[occupant] = occupant.role;
1036 if occupant.role ~= role and ( 1043 if occupant.role ~= role and (
1037 is_downgrade or 1044 is_downgrade or
1038 valid_roles[occupant.role or "none"] < role_rank -- upgrade 1045 valid_roles[occupant.role or "none"] < role_rank -- upgrade