Comparison

plugins/muc/muc.lib.lua @ 6134:48b6ef993888

plugins/muc/muc.lib: Move password check and nick conflict check into `handle_join`
author daurnimator <quae@daurnimator.com>
date Fri, 21 Mar 2014 14:01:02 -0400
parent 6133:5d8949bb15b0
child 6135:6b061f8c6e11
comparison
equal deleted inserted replaced
6133:5d8949bb15b0 6134:48b6ef993888
470 end 470 end
471 471
472 function room_mt:handle_join(origin, stanza) 472 function room_mt:handle_join(origin, stanza)
473 local from, to = stanza.attr.from, stanza.attr.to; 473 local from, to = stanza.attr.from, stanza.attr.to;
474 log("debug", "%s joining as %s", from, to); 474 log("debug", "%s joining as %s", from, to);
475 local password = stanza:get_child("x", "http://jabber.org/protocol/muc");
476 password = password and password:get_child("password", "http://jabber.org/protocol/muc");
477 password = password and password[1] ~= "" and password[1];
478 if self:get_password() and self:get_password() ~= password then
479 log("debug", "%s couldn't join due to invalid password: %s", from, to);
480 local reply = st.error_reply(stanza, "auth", "not-authorized"):up();
481 reply.tags[1].attr.code = "401";
482 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"}));
483 return true;
484 elseif self._occupants[to] -- occupant already exists
485 and jid_bare(from) ~= jid_bare(self._occupants[to].jid) then -- and has different bare real jid
486 log("debug", "%s couldn't join due to nick conflict: %s", from, to);
487 local reply = st.error_reply(stanza, "cancel", "conflict"):up();
488 reply.tags[1].attr.code = "409";
489 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"}));
490 return true;
491 end
475 if not next(self._affiliations) then -- new room, no owners 492 if not next(self._affiliations) then -- new room, no owners
476 self._affiliations[jid_bare(from)] = "owner"; 493 self._affiliations[jid_bare(from)] = "owner";
477 if self:is_locked() and not stanza:get_child("x", "http://jabber.org/protocol/muc") then 494 if self:is_locked() and not stanza:get_child("x", "http://jabber.org/protocol/muc") then
478 self:unlock(); -- Older groupchat protocol doesn't lock 495 self:unlock(); -- Older groupchat protocol doesn't lock
479 end 496 end
539 -- self:handle_to_occupant(origin, st.presence({type='unavailable', from=from, to=to}) 556 -- self:handle_to_occupant(origin, st.presence({type='unavailable', from=from, to=to})
540 -- :tag('status'):text('Replaced by new connection'):up()); -- send unavailable 557 -- :tag('status'):text('Replaced by new connection'):up()); -- send unavailable
541 -- self:handle_to_occupant(origin, stanza); -- resend available 558 -- self:handle_to_occupant(origin, stanza); -- resend available
542 --end 559 --end
543 else -- enter room 560 else -- enter room
544 local new_nick = to; 561 return self:handle_join(origin, stanza)
545 if self._occupants[to] then
546 if jid_bare(from) ~= jid_bare(self._occupants[to].jid) then
547 new_nick = nil;
548 end
549 end
550 local password = stanza:get_child("x", "http://jabber.org/protocol/muc");
551 password = password and password:get_child("password", "http://jabber.org/protocol/muc");
552 password = password and password[1] ~= "" and password[1];
553 if self:get_password() and self:get_password() ~= password then
554 log("debug", "%s couldn't join due to invalid password: %s", from, to);
555 local reply = st.error_reply(stanza, "auth", "not-authorized"):up();
556 reply.tags[1].attr.code = "401";
557 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"}));
558 return true;
559 elseif not new_nick then
560 log("debug", "%s couldn't join due to nick conflict: %s", from, to);
561 local reply = st.error_reply(stanza, "cancel", "conflict"):up();
562 reply.tags[1].attr.code = "409";
563 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"}));
564 return true;
565 else
566 return self:handle_join(origin, stanza)
567 end
568 end 562 end
569 end 563 end
570 564
571 function room_mt:handle_presence_to_occupant(origin, stanza) 565 function room_mt:handle_presence_to_occupant(origin, stanza)
572 local type = stanza.attr.type; 566 local type = stanza.attr.type;