plugins/muc/muc.lib.lua

changeset 2219
838f6d546177
parent 2218
dbbb5ed41365
child 2411
c2b6c55201af
equal deleted inserted replaced
2218:dbbb5ed41365 2219:838f6d546177
433 433
434 if self.save then self:save(true); end 434 if self.save then self:save(true); end
435 origin.send(st.reply(stanza)); 435 origin.send(st.reply(stanza));
436 end 436 end
437 437
438 function room_mt:destroy(newjid, reason, password)
439 local pr = st.presence({type = "unavailable"})
440 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"})
441 :tag("item", { affiliation='none', role='none' }):up()
442 :tag("destroy", {jid=newjid})
443 if reason then pr:tag("reason"):text(reason):up(); end
444 if password then pr:tag("password"):text(password):up(); end
445 for nick, occupant in pairs(self._occupants) do
446 pr.attr.from = nick;
447 for jid in pairs(occupant.sessions) do
448 pr.attr.to = jid;
449 self:_route_stanza(pr);
450 self._jid_nick[jid] = nil;
451 end
452 self._occupants[nick] = nil;
453 end
454 self._data.persistent = nil;
455 if self.save then self:save(true); end
456 end
457
438 function room_mt:handle_to_room(origin, stanza) -- presence changes and groupchat messages, along with disco/etc 458 function room_mt:handle_to_room(origin, stanza) -- presence changes and groupchat messages, along with disco/etc
439 local type = stanza.attr.type; 459 local type = stanza.attr.type;
440 local xmlns = stanza.tags[1] and stanza.tags[1].attr.xmlns; 460 local xmlns = stanza.tags[1] and stanza.tags[1].attr.xmlns;
441 if stanza.name == "iq" then 461 if stanza.name == "iq" then
442 if xmlns == "http://jabber.org/protocol/disco#info" and type == "get" then 462 if xmlns == "http://jabber.org/protocol/disco#info" and type == "get" then
513 if self:get_affiliation(stanza.attr.from) ~= "owner" then 533 if self:get_affiliation(stanza.attr.from) ~= "owner" then
514 origin.send(st.error_reply(stanza, "auth", "forbidden")); 534 origin.send(st.error_reply(stanza, "auth", "forbidden"));
515 elseif stanza.attr.type == "get" then 535 elseif stanza.attr.type == "get" then
516 self:send_form(origin, stanza); 536 self:send_form(origin, stanza);
517 elseif stanza.attr.type == "set" then 537 elseif stanza.attr.type == "set" then
518 self:process_form(origin, stanza) 538 local child = stanza.tags[1].tags[1];
539 if not child then
540 origin.send(st.error_reply(stanza, "auth", "bad-request"));
541 elseif child.name == "destroy" then
542 local newjid = child.attr.jid;
543 local reason, password;
544 for _,tag in ipairs(child.tags) do
545 if tag.name == "reason" then
546 reason = #tag.tags == 0 and tag[1];
547 elseif tag.name == "password" then
548 password = #tag.tags == 0 and tag[1];
549 end
550 end
551 self:destroy(newjid, reason, password);
552 origin.send(st.reply(stanza));
553 else
554 self:process_form(origin, stanza);
555 end
519 end 556 end
520 elseif type == "set" or type == "get" then 557 elseif type == "set" or type == "get" then
521 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); 558 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
522 end 559 end
523 elseif stanza.name == "message" and type == "groupchat" then 560 elseif stanza.name == "message" and type == "groupchat" then

mercurial