aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2009-02-19 20:17:07 +0500
committerWaqas Hussain <waqas20@gmail.com>2009-02-19 20:17:07 +0500
commit3af91c3bf28a042b5ba08d085b3b4f1aefabb377 (patch)
treeefa2288a03cfe2489c90e71d244a54ba4e43c7c0 /plugins
parent3b253992f156d8c91a1d9be6141349e032fa49bf (diff)
downloadprosody-3af91c3bf28a042b5ba08d085b3b4f1aefabb377.tar.gz
prosody-3af91c3bf28a042b5ba08d085b3b4f1aefabb377.zip
MUC: Bug fixes and workarounds
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_muc.lua70
1 files changed, 40 insertions, 30 deletions
diff --git a/plugins/mod_muc.lua b/plugins/mod_muc.lua
index 51a6c3b5..5fa52726 100644
--- a/plugins/mod_muc.lua
+++ b/plugins/mod_muc.lua
@@ -229,7 +229,7 @@ function handle_to_occupant(origin, stanza) -- PM, vCards, etc
log("debug", "room: %s, current_nick: %s, stanza: %s", room or "nil", current_nick or "nil", stanza:top_tag());
if stanza.name == "presence" then
local pr = get_filtered_presence(stanza);
- pr.attr.from = to;
+ pr.attr.from = current_nick;
if type == "error" then -- error, kick em out!
if current_nick then
log("debug", "kicking %s from %s", current_nick, room);
@@ -246,6 +246,8 @@ function handle_to_occupant(origin, stanza) -- PM, vCards, etc
elseif type == "unavailable" then -- unavailable
if current_nick then
log("debug", "%s leaving %s", current_nick, room);
+-- log("debug", "rooms: %s", require "util.serialization".serialize(rooms.data));
+-- log("debug", "jid_nick: %s", require "util.serialization".serialize(jid_nick.data));
local data = rooms:get(room, current_nick);
data.role = 'none';
broadcast_presence_stanza(room, pr);
@@ -255,40 +257,47 @@ function handle_to_occupant(origin, stanza) -- PM, vCards, etc
end
elseif not type then -- available
if current_nick then
- if current_nick == to then -- simple presence
- if #pr == #stanza then
+ if #pr == #stanza then
+ if current_nick == to then -- simple presence
log("debug", "%s broadcasted presence", current_nick);
+ rooms:get(room, current_nick).sessions[from] = pr;
broadcast_presence_stanza(room, pr);
- else -- possible rejoin
- log("debug", "%s had connection replaced", current_nick);
- local pr_ = st.presence({type='unavailable', from=from, to=current_nick}):tag('status'):text('Replaced by new connection');
- handle_to_occupant(origin, pr_); -- send unavailable
- handle_to_occupant(origin, pr); -- resend available
- end
- else -- change nick
- if rooms:get(room, to) then
- log("debug", "%s couldn't change nick", current_nick);
- origin.send(st.error_reply(stanza, "cancel", "conflict"));
- else
- local data = rooms:get(room, current_nick);
- local to_nick = select(3, jid_split(to));
- if to_nick then
- log("debug", "%s changing nick to %s", current_nick, to_nick);
- local p = st.presence({type='unavailable', from=current_nick});
- --[[:tag('x', {xmlns='http://jabber.org/protocol/muc#user'})
- :tag('item', {affiliation=data.affiliation, role=data.role, nick=to_nick}):up()
- :tag('status', {code='303'});]]
- broadcast_presence_stanza(room, p, '303', to_nick);
- --broadcast_presence('unavailable', current_nick, room, '303', to_nick);
- rooms:remove(room, current_nick);
- rooms:set(room, to, data);
- jid_nick:set(from, room, to);
- broadcast_presence_stanza(room, pr);
- --broadcast_presence(nil, to, room, nil);
+ else -- change nick
+ if rooms:get(room, to) then
+ log("debug", "%s couldn't change nick", current_nick);
+ origin.send(st.error_reply(stanza, "cancel", "conflict"));
else
- --TODO malformed-jid
+ local data = rooms:get(room, current_nick);
+ local to_nick = select(3, jid_split(to));
+ if to_nick then
+ log("debug", "%s (%s) changing nick to %s", current_nick, data.jid, to);
+-- log("debug", "rooms: %s", require "util.serialization".serialize(rooms.data));
+-- log("debug", "jid_nick: %s", require "util.serialization".serialize(jid_nick.data));
+ local p = st.presence({type='unavailable', from=current_nick});
+ --[[:tag('x', {xmlns='http://jabber.org/protocol/muc#user'})
+ :tag('item', {affiliation=data.affiliation, role=data.role, nick=to_nick}):up()
+ :tag('status', {code='303'});]]
+ broadcast_presence_stanza(room, p, '303', to_nick);
+ --broadcast_presence('unavailable', current_nick, room, '303', to_nick);
+ rooms:remove(room, current_nick);
+ rooms:set(room, to, data);
+ jid_nick:set(from, room, to);
+ pr.attr.from = to;
+ rooms:get(room, to).sessions[from] = pr;
+ broadcast_presence_stanza(room, pr);
+-- log("debug", "rooms: %s", require "util.serialization".serialize(rooms.data));
+-- log("debug", "jid_nick: %s", require "util.serialization".serialize(jid_nick.data));
+ --broadcast_presence(nil, to, room, nil);
+ else
+ --TODO malformed-jid
+ end
end
end
+ else -- possible rejoin
+ log("debug", "%s had connection replaced", current_nick);
+ local pr_ = st.presence({type='unavailable', from=from, to=current_nick}):tag('status'):text('Replaced by new connection');
+ handle_to_occupant(origin, pr_); -- send unavailable
+ handle_to_occupant(origin, stanza); -- resend available
end
else -- enter room
local new_nick = to;
@@ -323,6 +332,7 @@ function handle_to_occupant(origin, stanza) -- PM, vCards, etc
end
end
end
+ pr.attr.from = to;
broadcast_presence_stanza(room, pr);
--broadcast_presence(nil, to, room);
local history = rooms_info:get(room, 'history'); -- send discussion history