|
|
|
@ -1,12 +1,10 @@
|
|
|
|
|
package eu.jonahbauer.wizard.server;
|
|
|
|
|
|
|
|
|
|
import eu.jonahbauer.wizard.common.messages.server.ServerMessage;
|
|
|
|
|
import eu.jonahbauer.wizard.common.messages.server.SessionCreatedMessage;
|
|
|
|
|
import eu.jonahbauer.wizard.common.messages.server.SessionListMessage;
|
|
|
|
|
import eu.jonahbauer.wizard.common.messages.server.SessionRemovedMessage;
|
|
|
|
|
import eu.jonahbauer.wizard.common.messages.server.*;
|
|
|
|
|
import eu.jonahbauer.wizard.common.model.Configuration;
|
|
|
|
|
import eu.jonahbauer.wizard.server.debug.DebugSession;
|
|
|
|
|
import eu.jonahbauer.wizard.server.machine.Player;
|
|
|
|
|
import org.intellij.lang.annotations.Language;
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
@ -14,6 +12,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|
|
|
|
|
|
|
|
|
public class Lobby {
|
|
|
|
|
@Language("RegExp")
|
|
|
|
|
private static final String SESSION_NAME_PATTERN = "[a-zA-Z0-9_ ]{1,20}";
|
|
|
|
|
private static final Lobby INSTANCE = new Lobby();
|
|
|
|
|
public static Lobby getInstance() {
|
|
|
|
|
return INSTANCE;
|
|
|
|
@ -26,8 +26,16 @@ public class Lobby {
|
|
|
|
|
private Lobby() {}
|
|
|
|
|
|
|
|
|
|
public Session createSession(@NotNull String name, long timeout, @NotNull Configuration configuration) {
|
|
|
|
|
if (!name.matches(SESSION_NAME_PATTERN)) {
|
|
|
|
|
throw new NackException(NackMessage.SESSION_NAME_NOT_ALLOWED, "Session name is too short, too long or contains illegal characters.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lock.readLock().lock();
|
|
|
|
|
try {
|
|
|
|
|
if (sessions.values().stream().anyMatch(s -> s.getName().equalsIgnoreCase(name))) {
|
|
|
|
|
throw new NackException(NackMessage.SESSION_NAME_TAKEN, "Session name is already taken.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Session session;
|
|
|
|
|
do {
|
|
|
|
|
session = new Session(UUID.randomUUID(), name, timeout, configuration);
|
|
|
|
|