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 { ...@@ -585,9 +585,12 @@ public class LocalMUCRoom implements MUCRoom, GroupEventListener {
// Nickname is already used, and not by the same JID // Nickname is already used, and not by the same JID
throw new UserAlreadyExistsException(); throw new UserAlreadyExistsException();
} }
// Is this client already joined? // Is this client already joined with this nickname?
if (occupantsByFullJID.containsKey(user.getAddress())) { for (MUCRole mucRole : occupants) {
clientOnlyJoin = true; // This user is already an occupant. The client thinks it isn't. (Or else this is a broken gmail). if (mucRole.getUserAddress().equals(user.getAddress())) {
clientOnlyJoin = true;
break;
}
} }
} }
// If the room is password protected and the provided password is incorrect raise a // If the room is password protected and the provided password is incorrect raise a
......
...@@ -435,10 +435,6 @@ public class LocalMUCUser implements MUCUser { ...@@ -435,10 +435,6 @@ public class LocalMUCUser implements MUCUser {
} }
public void process(Presence packet) { public void process(Presence packet) {
// Ignore presences of type ERROR sent to a room
if (Presence.Type.error == packet.getType()) {
return;
}
lastPacketTime = System.currentTimeMillis(); lastPacketTime = System.currentTimeMillis();
JID recipient = packet.getTo(); JID recipient = packet.getTo();
String group = recipient.getNode(); String group = recipient.getNode();
...@@ -503,20 +499,17 @@ public class LocalMUCUser implements MUCUser { ...@@ -503,20 +499,17 @@ public class LocalMUCUser implements MUCUser {
sendErrorPacket(packet, PacketError.Condition.not_allowed); sendErrorPacket(packet, PacketError.Condition.not_allowed);
} }
} }
else { else if (packet.getType() != Presence.Type.error) {
// TODO: send error message to user (can't send presence to group you sendErrorPacket(packet, PacketError.Condition.unexpected_request);
// haven't joined)
} }
} }
else { else {
if (packet.isAvailable()) { if (packet.getType() != Presence.Type.error) {
// A resource is required in order to join a room // A resource is required in order to join a room
// http://xmpp.org/extensions/xep-0045.html#enter // 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 // 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); sendErrorPacket(packet, PacketError.Condition.jid_malformed);
} }
// TODO: send error message to user (can't send packets to group you haven't
// joined)
} }
} }
else { else {
...@@ -550,8 +543,11 @@ public class LocalMUCUser implements MUCUser { ...@@ -550,8 +543,11 @@ public class LocalMUCUser implements MUCUser {
// Occupant has changed his nickname. Send two presences // Occupant has changed his nickname. Send two presences
// to each room occupant // 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 // Check if occupants are allowed to change their nicknames
if (!role.getChatRoom().canChangeNickname()) { else if (!role.getChatRoom().canChangeNickname()) {
sendErrorPacket(packet, PacketError.Condition.not_acceptable); sendErrorPacket(packet, PacketError.Condition.not_acceptable);
} }
// Answer a conflic error if the new nickname is taken // Answer a conflic error if the new nickname is taken
...@@ -613,4 +609,4 @@ public class LocalMUCUser implements MUCUser { ...@@ -613,4 +609,4 @@ public class LocalMUCUser implements MUCUser {
return false; return false;
return true; 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