RegistrationRequiredException, ConflictException, ServiceUnavailableException,
NotAcceptableException {
if (((MultiUserChatServiceImpl)mucService).getMUCDelegate() != null) {
if (!((MultiUserChatServiceImpl)mucService).getMUCDelegate().joiningRoom(this, user.getAddress())) {
// Delegate said no, reject join.
throw new UnauthorizedException();
}
}
LocalMUCRole joinRole = null;
lock.writeLock().lock();
try {
// If the room has a limit of max user then check if the limit has been reached
if (isDestroyed || (getMaxUsers() > 0 && getOccupantsCount() >= getMaxUsers())) {
throw new ServiceUnavailableException();
}
boolean isOwner = owners.contains(user.getAddress().toBareJID());
// If the room is locked and this user is not an owner raise a RoomLocked exception
if (isLocked()) {
if (!isOwner) {
throw new RoomLockedException();
}
}
// Check if the nickname is already used in the room
if (occupants.containsKey(nickname.toLowerCase())) {
if (occupants.get(nickname.toLowerCase()).getUserAddress().toBareJID().equals(user.getAddress().toBareJID())) {
// Nickname exists in room, and belongs to this user, pretend to kick the previous instance.
// The previous instance will see that they are disconnected, and the new instance will
// "take over" the previous role. Participants in the room shouldn't notice anything
// has occurred.
String reason = "Your account signed into this chatroom with the same nickname from another location.";
Presence updatedPresence = new Presence(Presence.Type.unavailable);
updatedPresence.setFrom(occupants.get(nickname.toLowerCase()).getRoleAddress());
updatedPresence.setTo(occupants.get(nickname.toLowerCase()).getUserAddress());
Element frag = updatedPresence.addChildElement(
"x", "http://jabber.org/protocol/muc#user");
// Set the person who performed the kick ("you" effectively)
frag.addElement("item").addElement("actor").setText(user.getAddress().toString());
// Add the reason why the user was kicked
frag.element("item").addElement("reason").setText(reason);
// Add the status code 307 that indicates that the user was kicked
frag.addElement("status").addAttribute("code", "307");
router.route(updatedPresence);
}
else {
// Nickname is already used, and not by the same JID
throw new UserAlreadyExistsException();
}
}
// If the room is password protected and the provided password is incorrect raise a
// Unauthorized exception
if (isPasswordProtected()) {
if (password == null || !password.equals(getPassword())) {
throw new UnauthorizedException();
}
}
// If another user attempts to join the room with a nickname reserved by the first user
// raise a ConflictException
if (members.containsValue(nickname)) {