Fixed typos in tests and additional refactor

This commit is contained in:
Oleg Agafonov 2020-08-29 19:04:26 +04:00
parent 4d8369afbc
commit ede06098e0
7 changed files with 652 additions and 648 deletions

View file

@ -1,17 +1,11 @@
package mage.server;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import mage.MageException;
import mage.constants.Constants;
import mage.interfaces.callback.ClientCallback;
import mage.interfaces.callback.ClientCallbackMethod;
import mage.players.net.UserData;
import mage.players.net.UserGroup;
import static mage.server.DisconnectReason.LostConnection;
import mage.server.game.GamesRoom;
import mage.server.game.GamesRoomManager;
import mage.server.util.ConfigSettings;
@ -23,6 +17,14 @@ import org.jboss.remoting.callback.Callback;
import org.jboss.remoting.callback.HandleCallbackException;
import org.jboss.remoting.callback.InvokerCallbackHandler;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static mage.server.DisconnectReason.LostConnection;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -201,9 +203,11 @@ public class Session {
}
}
}
Optional<User> selectUser = UserManager.instance.createUser(userName, host, authorizedUser);
boolean reconnect = false;
if (!selectUser.isPresent()) { // user already exists
if (!selectUser.isPresent()) {
// user already connected
selectUser = UserManager.instance.getUserByName(userName);
if (selectUser.isPresent()) {
User user = selectUser.get();
@ -222,6 +226,9 @@ public class Session {
} else {
return "User name " + userName + " already in use (or your IP address changed)";
}
} else {
// code never goes here
return "Can't find connected user name " + userName;
}
}
User user = selectUser.get();
@ -240,7 +247,6 @@ public class Session {
}
return null;
}
public void connectAdmin() {

View file

@ -1,17 +1,5 @@
package mage.server;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import mage.MageException;
import mage.cards.decks.DeckCardLists;
import mage.constants.TableState;
@ -31,6 +19,18 @@ import mage.server.game.GamesRoomManager;
import mage.server.util.ThreadExecutor;
import org.apache.log4j.Logger;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -244,7 +244,7 @@ public enum TableManager {
/**
* Starts the Match from a non tournament table
*
* @param userId table owner
* @param userId table owner
* @param roomId
* @param tableId
*/
@ -415,7 +415,7 @@ public enum TableManager {
if (table.getState() != TableState.FINISHED
&& ((System.currentTimeMillis() - table.getStartTime().getTime()) / 1000) > 30) { // removeUserFromAllTablesAndChat only if table started longer than 30 seconds ago
// removeUserFromAllTablesAndChat tables and games not valid anymore
logger.debug(table.getId() + " [" + table.getName() + "] " + formatter.format(table.getStartTime() == null ? table.getCreateTime() : table.getCreateTime()) + " (" + table.getState().toString() + ") " + (table.isTournament() ? "- Tournament" : ""));
logger.debug(table.getId() + " [" + table.getName() + "] " + formatter.format(table.getStartTime() != null ? table.getStartTime() : table.getCreateTime()) + " (" + table.getState().toString() + ") " + (table.isTournament() ? "- Tournament" : ""));
getController(table.getId()).ifPresent(tableController -> {
if ((table.isTournament() && !tableController.isTournamentStillValid())
|| (!table.isTournament() && !tableController.isMatchTableStillValid())) {