Comparison

plugins/muc/muc.lib.lua @ 6193:b9074126639f

plugins/muc/muc.lib: Remove top level pre-join event. Assign event priorities for other handlers
author daurnimator <quae@daurnimator.com>
date Mon, 31 Mar 2014 12:21:43 -0400
parent 6192:f97aa1f4b1f1
child 6194:9b6c2d89f143
comparison
equal deleted inserted replaced
6192:f97aa1f4b1f1 6193:b9074126639f
583 module:hook("muc-room-pre-create", function(event) 583 module:hook("muc-room-pre-create", function(event)
584 event.room:set_affiliation(true, jid_bare(event.stanza.attr.from), "owner"); 584 event.room:set_affiliation(true, jid_bare(event.stanza.attr.from), "owner");
585 end, -1); 585 end, -1);
586 586
587 module:hook("muc-occupant-pre-join", function(event) 587 module:hook("muc-occupant-pre-join", function(event)
588 return module:fire_event("muc-occupant-pre-join/affiliation", event)
589 or module:fire_event("muc-occupant-pre-join/password", event)
590 or module:fire_event("muc-occupant-pre-join/locked", event);
591 end, -1)
592
593 module:hook("muc-occupant-pre-join/password", function(event)
594 local room, stanza = event.room, event.stanza; 588 local room, stanza = event.room, event.stanza;
595 local password = stanza:get_child("x", "http://jabber.org/protocol/muc"); 589 local password = stanza:get_child("x", "http://jabber.org/protocol/muc");
596 password = password and password:get_child_text("password", "http://jabber.org/protocol/muc"); 590 password = password and password:get_child_text("password", "http://jabber.org/protocol/muc");
597 if not password or password == "" then password = nil; end 591 if not password or password == "" then password = nil; end
598 if room:get_password() ~= password then 592 if room:get_password() ~= password then
601 local reply = st.error_reply(stanza, "auth", "not-authorized"):up(); 595 local reply = st.error_reply(stanza, "auth", "not-authorized"):up();
602 reply.tags[1].attr.code = "401"; 596 reply.tags[1].attr.code = "401";
603 event.origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); 597 event.origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"}));
604 return true; 598 return true;
605 end 599 end
606 end, -1); 600 end, -20);
607 601
608 module:hook("muc-occupant-pre-join/locked", function(event) 602 module:hook("muc-occupant-pre-join", function(event)
609 if event.room:is_locked() then -- Deny entry 603 if event.room:is_locked() then -- Deny entry
610 event.origin.send(st.error_reply(event.stanza, "cancel", "item-not-found")); 604 event.origin.send(st.error_reply(event.stanza, "cancel", "item-not-found"));
611 return true; 605 return true;
612 end 606 end
613 end, -1); 607 end, -30);
614 608
615 -- registration required for entering members-only room 609 -- registration required for entering members-only room
616 module:hook("muc-occupant-pre-join/affiliation", function(event) 610 module:hook("muc-occupant-pre-join", function(event)
617 local room, stanza = event.room, event.stanza; 611 local room, stanza = event.room, event.stanza;
618 local affiliation = room:get_affiliation(stanza.attr.from); 612 local affiliation = room:get_affiliation(stanza.attr.from);
619 if affiliation == nil and event.room:get_members_only() then 613 if affiliation == nil and event.room:get_members_only() then
620 local reply = st.error_reply(stanza, "auth", "registration-required"):up(); 614 local reply = st.error_reply(stanza, "auth", "registration-required"):up();
621 reply.tags[1].attr.code = "407"; 615 reply.tags[1].attr.code = "407";
622 event.origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); 616 event.origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"}));
623 return true; 617 return true;
624 end 618 end
625 end, -1); 619 end, -5);
626 620
627 -- check if user is banned 621 -- check if user is banned
628 module:hook("muc-occupant-pre-join/affiliation", function(event) 622 module:hook("muc-occupant-pre-join", function(event)
629 local room, stanza = event.room, event.stanza; 623 local room, stanza = event.room, event.stanza;
630 local affiliation = room:get_affiliation(stanza.attr.from); 624 local affiliation = room:get_affiliation(stanza.attr.from);
631 if affiliation == "outcast" then 625 if affiliation == "outcast" then
632 local reply = st.error_reply(stanza, "auth", "forbidden"):up(); 626 local reply = st.error_reply(stanza, "auth", "forbidden"):up();
633 reply.tags[1].attr.code = "403"; 627 reply.tags[1].attr.code = "403";
634 event.origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); 628 event.origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"}));
635 return true; 629 return true;
636 end 630 end
637 end, -1); 631 end, -10);
638 632
639 module:hook("muc-occupant-joined", function(event) 633 module:hook("muc-occupant-joined", function(event)
640 local room, stanza = event.room, event.stanza; 634 local room, stanza = event.room, event.stanza;
641 local real_jid = stanza.attr.from; 635 local real_jid = stanza.attr.from;
642 room:send_occupant_list(real_jid, function(nick, occupant) 636 room:send_occupant_list(real_jid, function(nick, occupant)