use of org.jivesoftware.openfire.muc.MultiUserChatService in project Openfire by igniterealtime.
the class ServiceAddedEvent method run.
@Override
public void run() {
// should really never occur.
if (!XMPPServer.getInstance().getMultiUserChatManager().isServiceRegistered(subdomain)) {
MultiUserChatService service = new MultiUserChatServiceImpl(subdomain, description, isHidden);
XMPPServer.getInstance().getMultiUserChatManager().registerMultiUserChatService(service, false);
}
}
use of org.jivesoftware.openfire.muc.MultiUserChatService in project Openfire by igniterealtime.
the class CreateMUCRoom method execute.
@Override
public void execute(SessionData sessionData, Element command) {
Element note = command.addElement("note");
Collection<JID> admins = XMPPServer.getInstance().getAdmins();
if (admins.size() <= 0) {
note.addAttribute("type", "error");
note.setText("Server needs admin user to be able to create rooms.");
return;
}
Map<String, List<String>> data = sessionData.getData();
// Let's find the requested MUC service to create the room in
String servicehostname = get(data, "servicename", 0);
if (servicehostname == null) {
note.addAttribute("type", "error");
note.setText("Service name must be specified.");
return;
}
// Remove the server's domain name from the passed hostname
String servicename = servicehostname.replace("." + XMPPServer.getInstance().getServerInfo().getXMPPDomain(), "");
MultiUserChatService mucService;
mucService = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(servicename);
if (mucService == null) {
note.addAttribute("type", "error");
note.setText("Invalid service name specified.");
return;
}
if (!mucService.isServiceEnabled()) {
note.addAttribute("type", "error");
note.setText("Multi user chat is disabled for specified service.");
return;
}
// Let's create the jid and check that they are a local user
String roomname = get(data, "roomname", 0);
if (roomname == null) {
note.addAttribute("type", "error");
note.setText("Room name must be specified.");
return;
}
JID admin = admins.iterator().next();
boolean isPersistent;
try {
final String value = get(data, "persistent", 0);
if (value == null) {
// this field is not required.
isPersistent = false;
} else {
isPersistent = DataForm.parseBoolean(value);
}
} catch (ParseException e) {
note.addAttribute("type", "error");
note.setText("persistent has invalid value. Needs to be boolean.");
return;
}
boolean isPublic;
try {
final String value = get(data, "public", 0);
if (value == null) {
// this field is not required.
isPublic = false;
} else {
isPublic = DataForm.parseBoolean(value);
}
} catch (ParseException e) {
note.addAttribute("type", "error");
note.setText("public has invalid value. Needs to be boolean.");
return;
}
final Lock lock = mucService.getChatRoomLock(roomname);
lock.lock();
try {
MUCRoom room;
try {
room = mucService.getChatRoom(roomname, admin);
} catch (NotAllowedException e) {
note.addAttribute("type", "error");
note.setText("No permission to create rooms.");
return;
}
room.setPersistent(isPersistent);
room.setPublicRoom(isPublic);
String password = get(data, "password", 0);
if (password != null) {
room.setPassword(password);
}
// Make sure that other cluster nodes see the changes made here.
mucService.syncChatRoom(room);
} finally {
lock.unlock();
}
}
Aggregations