Commit d44d12e9 authored by Dave Cridland's avatar Dave Cridland Committed by daryl herzmann

OF-1422 Check all MUCRoles, handle nickname changes (#912)

* OF-1422 Check all MUCRoles to see if this is rejoin

* Handle errors and other presence better in MUC

Also refuse nickname changes on shared nicknames,
since they don't currently work.

* Crazy wRong Line-ending Fix
parent 155d4422
......@@ -585,9 +585,12 @@ public class LocalMUCRoom implements MUCRoom, GroupEventListener {
// Nickname is already used, and not by the same JID
throw new UserAlreadyExistsException();
}
// Is this client already joined?
if (occupantsByFullJID.containsKey(user.getAddress())) {
clientOnlyJoin = true; // This user is already an occupant. The client thinks it isn't. (Or else this is a broken gmail).
// Is this client already joined with this nickname?
for (MUCRole mucRole : occupants) {
if (mucRole.getUserAddress().equals(user.getAddress())) {
clientOnlyJoin = true;
break;
}
}
}
// If the room is password protected and the provided password is incorrect raise a
......
......@@ -435,10 +435,6 @@ public class LocalMUCUser implements MUCUser {
}
public void process(Presence packet) {
// Ignore presences of type ERROR sent to a room
if (Presence.Type.error == packet.getType()) {
return;
}
lastPacketTime = System.currentTimeMillis();
JID recipient = packet.getTo();
String group = recipient.getNode();
......@@ -503,20 +499,17 @@ public class LocalMUCUser implements MUCUser {
sendErrorPacket(packet, PacketError.Condition.not_allowed);
}
}
else {
// TODO: send error message to user (can't send presence to group you
// haven't joined)
else if (packet.getType() != Presence.Type.error) {
sendErrorPacket(packet, PacketError.Condition.unexpected_request);
}
}
else {
if (packet.isAvailable()) {
if (packet.getType() != Presence.Type.error) {
// A resource is required in order to join a room
// http://xmpp.org/extensions/xep-0045.html#enter
// If the user does not specify a room nickname (note the bare JID on the 'from' address in the following example), the service MUST return a <jid-malformed/> error
sendErrorPacket(packet, PacketError.Condition.jid_malformed);
}
// TODO: send error message to user (can't send packets to group you haven't
// joined)
}
}
else {
......@@ -550,8 +543,11 @@ public class LocalMUCUser implements MUCUser {
// Occupant has changed his nickname. Send two presences
// to each room occupant
if (role.getChatRoom().getOccupantsByBareJID(packet.getFrom().asBareJID()).size() > 1) {
sendErrorPacket(packet, PacketError.Condition.not_acceptable);
}
// Check if occupants are allowed to change their nicknames
if (!role.getChatRoom().canChangeNickname()) {
else if (!role.getChatRoom().canChangeNickname()) {
sendErrorPacket(packet, PacketError.Condition.not_acceptable);
}
// Answer a conflic error if the new nickname is taken
......@@ -613,4 +609,4 @@ public class LocalMUCUser implements MUCUser {
return false;
return true;
}
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment