changes for public server

This commit is contained in:
BetaSteward 2011-05-04 23:18:13 -04:00
parent 1fdc50570f
commit b81938210a
46 changed files with 218 additions and 281 deletions

View file

@ -34,11 +34,10 @@ import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import mage.interfaces.callback.ClientCallback;
import mage.util.Logging;
import mage.view.ChatMessage;
import mage.view.ChatMessage.MessageColor;
import org.apache.log4j.Logger;
/**
*
@ -46,7 +45,7 @@ import mage.view.ChatMessage.MessageColor;
*/
public class ChatSession {
private final static Logger logger = Logging.getLogger(ChatSession.class.getName());
private final static Logger logger = Logger.getLogger(ChatSession.class);
private ConcurrentHashMap<UUID, String> clients = new ConcurrentHashMap<UUID, String>();
private UUID chatId;
private DateFormat timeFormatter = SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT);

View file

@ -45,6 +45,7 @@ import mage.server.util.config.GamePlugin;
import mage.util.Copier;
import mage.utils.MageVersion;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
/**
*
@ -67,7 +68,7 @@ public class Main {
public static void main(String[] args) {
logger.info("Starting MAGE server version " + version);
logger.info("Logging level: " + logger.getLevel());
logger.info("Logging level: " + logger.getEffectiveLevel());
deleteSavedGames();
ConfigSettings config = ConfigSettings.getInstance();
for (GamePlugin plugin: config.getGameTypes()) {
@ -107,6 +108,7 @@ public class Main {
ip = ipParam;
}
System.setProperty("java.rmi.server.hostname", ip);
System.setProperty("sun.rmi.transport.tcp.readTimeout", "30000");
logger.info("MAGE server - using address " + ip);
}

View file

@ -30,13 +30,12 @@ package mage.server;
import java.util.logging.Level;
import java.util.UUID;
import java.util.logging.Logger;
import mage.cards.decks.Deck;
import mage.interfaces.callback.CallbackServerSession;
import mage.interfaces.callback.ClientCallback;
import mage.server.game.GameManager;
import mage.util.Logging;
import mage.view.TableClientMessage;
import org.apache.log4j.Logger;
/**
*
@ -44,7 +43,7 @@ import mage.view.TableClientMessage;
*/
public class Session {
private final static Logger logger = Logging.getLogger(Session.class.getName());
private final static Logger logger = Logger.getLogger(Session.class);
private UUID sessionId;
private UUID clientId;
@ -63,6 +62,10 @@ public class Session {
return sessionId;
}
public UUID getClientId() {
return clientId;
}
public void kill() {
SessionManager.getInstance().removeSession(sessionId);
TableManager.getInstance().removeSession(sessionId);
@ -74,19 +77,19 @@ public class Session {
try {
return callback.callback();
} catch (InterruptedException ex) {
logger.log(Level.SEVERE, null, ex);
logger.fatal("Session callback error", ex);
}
return null;
}
public synchronized void fireCallback(final ClientCallback call) {
call.setMessageId(messageId++);
if (logger.isLoggable(Level.FINE))
logger.fine(sessionId + " - " + call.getMessageId() + " - " + call.getMethod());
if (logger.isDebugEnabled())
logger.debug(sessionId + " - " + call.getMessageId() + " - " + call.getMethod());
try {
callback.setCallback(call);
} catch (InterruptedException ex) {
logger.log(Level.SEVERE, null, ex);
logger.fatal("Session fireCallback error", ex);
}
}

View file

@ -31,6 +31,7 @@ package mage.server;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import mage.interfaces.MageException;
import org.apache.log4j.Logger;
/**
*
@ -38,6 +39,7 @@ import mage.interfaces.MageException;
*/
public class SessionManager {
private final static Logger logger = Logger.getLogger(SessionManager.class);
private final static SessionManager INSTANCE = new SessionManager();
public static SessionManager getInstance() {
@ -51,24 +53,24 @@ public class SessionManager {
}
public UUID createSession(String userName, UUID clientId) throws MageException {
if (!isNameUsed(userName)) {
Session session = new Session(userName, clientId);
sessions.put(session.getId(), session);
return session.getId();
for (Session session: sessions.values()) {
if (session.getUsername().equals(userName)) {
if (session.getClientId().equals(clientId)) {
logger.info("reconnecting session for " + userName);
return session.getId();
}
else {
throw new MageException("User name already in use");
}
}
}
throw new MageException("User name already in use");
Session session = new Session(userName, clientId);
sessions.put(session.getId(), session);
return session.getId();
}
public void removeSession(UUID sessionId) {
sessions.remove(sessionId);
}
private boolean isNameUsed(String name) {
for (Session session: sessions.values()) {
if (session.getUsername().equals(name))
return true;
}
return false;
}
}

View file

@ -32,7 +32,6 @@ import mage.game.Table;
import java.util.Collection;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import mage.cards.decks.Deck;
import mage.cards.decks.DeckCardLists;
import mage.game.GameException;
@ -41,8 +40,7 @@ import mage.game.match.Match;
import mage.game.match.MatchOptions;
import mage.game.tournament.TournamentOptions;
import mage.players.Player;
import mage.server.game.GameReplay;
import mage.util.Logging;
import org.apache.log4j.Logger;
/**
*
@ -51,7 +49,7 @@ import mage.util.Logging;
public class TableManager {
private final static TableManager INSTANCE = new TableManager();
private final static Logger logger = Logging.getLogger(TableManager.class.getName());
//private final static Logger logger = Logger.getLogger(TableManager.class);
private ConcurrentHashMap<UUID, TableController> controllers = new ConcurrentHashMap<UUID, TableController>();
private ConcurrentHashMap<UUID, Table> tables = new ConcurrentHashMap<UUID, Table>();

View file

@ -32,7 +32,6 @@ import java.io.File;
import java.util.UUID;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import mage.game.draft.Draft;
import mage.game.draft.DraftPlayer;
@ -42,9 +41,9 @@ import mage.game.events.TableEvent;
import mage.server.game.GameController;
import mage.server.TableManager;
import mage.server.util.ThreadExecutor;
import mage.util.Logging;
import mage.view.DraftPickView;
import mage.view.DraftView;
import org.apache.log4j.Logger;
/**
*
@ -52,7 +51,7 @@ import mage.view.DraftView;
*/
public class DraftController {
private final static Logger logger = Logging.getLogger(GameController.class.getName());
private final static Logger logger = Logger.getLogger(GameController.class);
public static final String INIT_FILE_PATH = "config" + File.separator + "init.txt";
private ConcurrentHashMap<UUID, DraftSession> draftSessions = new ConcurrentHashMap<UUID, DraftSession>();
@ -122,7 +121,7 @@ public class DraftController {
private synchronized void startDraft() {
for (final Entry<UUID, DraftSession> entry: draftSessions.entrySet()) {
if (!entry.getValue().init(getDraftView())) {
logger.severe("Unable to initialize client");
logger.fatal("Unable to initialize client");
//TODO: generate client error message
return;
}

View file

@ -33,17 +33,15 @@ import java.util.UUID;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.game.draft.Draft;
import mage.interfaces.callback.ClientCallback;
import mage.server.Session;
import mage.server.SessionManager;
import mage.server.util.ThreadExecutor;
import mage.util.Logging;
import mage.view.DraftClientMessage;
import mage.view.DraftPickView;
import mage.view.DraftView;
import org.apache.log4j.Logger;
/**
*
@ -51,7 +49,7 @@ import mage.view.DraftView;
*/
public class DraftSession {
protected final static Logger logger = Logging.getLogger(DraftSession.class.getName());
protected final static Logger logger = Logger.getLogger(DraftSession.class);
protected UUID sessionId;
protected UUID playerId;
@ -143,7 +141,7 @@ public class DraftSession {
}
protected void handleRemoteException(RemoteException ex) {
logger.log(Level.SEVERE, null, ex);
logger.fatal("DraftSession error ", ex);
DraftManager.getInstance().kill(draft.getId(), sessionId);
}

View file

@ -32,11 +32,8 @@ import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import mage.cards.decks.*;
import java.util.logging.Logger;
import mage.Constants;
import mage.util.Logging;
import org.apache.log4j.Logger;
/**
*
@ -45,7 +42,7 @@ import mage.util.Logging;
public class DeckValidatorFactory {
private final static DeckValidatorFactory INSTANCE = new DeckValidatorFactory();
private final static Logger logger = Logging.getLogger(DeckValidatorFactory.class.getName());
private final static Logger logger = Logger.getLogger(DeckValidatorFactory.class);
private Map<String, Class> deckTypes = new HashMap<String, Class>();
@ -63,7 +60,7 @@ public class DeckValidatorFactory {
con = deckTypes.get(deckType).getConstructor(new Class[]{});
validator = (DeckValidator)con.newInstance(new Object[] {});
} catch (Exception ex) {
logger.log(Level.SEVERE, null, ex);
logger.fatal("DeckValidatorFactory error", ex);
return null;
}
logger.info("Deck validator created: " + validator.getName());

View file

@ -33,13 +33,11 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.game.match.Match;
import mage.game.match.MatchOptions;
import mage.util.Logging;
import mage.game.match.MatchType;
import mage.view.GameTypeView;
import org.apache.log4j.Logger;
/**
*
@ -48,7 +46,7 @@ import mage.view.GameTypeView;
public class GameFactory {
private final static GameFactory INSTANCE = new GameFactory();
private final static Logger logger = Logging.getLogger(GameFactory.class.getName());
private final static Logger logger = Logger.getLogger(GameFactory.class);
private Map<String, Class<Match>> games = new HashMap<String, Class<Match>>();
private Map<String, MatchType> gameTypes = new HashMap<String, MatchType>();
@ -69,7 +67,7 @@ public class GameFactory {
con = games.get(gameType).getConstructor(new Class[]{MatchOptions.class});
match = con.newInstance(new Object[] {options});
} catch (Exception ex) {
logger.log(Level.SEVERE, null, ex);
logger.fatal("Error creating match - " + gameType, ex);
return null;
}
logger.info("Game created: " + gameType); // + game.getId().toString());

View file

@ -64,7 +64,9 @@ public class GameManager {
}
public UUID getChatId(UUID gameId) {
return gameControllers.get(gameId).getChatId();
if (gameControllers.containsKey(gameId))
return gameControllers.get(gameId).getChatId();
return null;
}
public void sendPlayerUUID(UUID gameId, UUID sessionId, UUID data) {

View file

@ -30,14 +30,12 @@ package mage.server.game;
import java.rmi.RemoteException;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.interfaces.callback.ClientCallback;
import mage.server.Session;
import mage.server.SessionManager;
import mage.util.Logging;
import mage.view.GameClientMessage;
import mage.view.GameView;
import org.apache.log4j.Logger;
/**
*
@ -45,7 +43,7 @@ import mage.view.GameView;
*/
public class GameWatcher {
protected final static Logger logger = Logging.getLogger(GameWatcher.class.getName());
protected final static Logger logger = Logger.getLogger(GameWatcher.class);
protected UUID sessionId;
protected UUID gameId;
@ -102,7 +100,7 @@ public class GameWatcher {
}
protected void handleRemoteException(RemoteException ex) {
logger.log(Level.SEVERE, null, ex);
logger.fatal("GameWatcher error", ex);
GameManager.getInstance().kill(gameId, sessionId);
}

View file

@ -30,10 +30,8 @@ package mage.server.game;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.game.Game;
import mage.util.Logging;
import org.apache.log4j.Logger;
/**
*
@ -41,7 +39,7 @@ import mage.util.Logging;
*/
public class GameWorker implements Callable {
private final static Logger logger = Logging.getLogger(GameWorker.class.getName());
private final static Logger logger = Logger.getLogger(GameWorker.class);
private GameCallback result;
private Game game;
@ -59,7 +57,7 @@ public class GameWorker implements Callable {
game.start(choosingPlayerId);
result.gameResult(game.getWinner());
} catch (Exception ex) {
logger.log(Level.SEVERE, null, ex);
logger.fatal("GameWorker error ", ex);
result.gameResult("Server Error");
}
return null;

View file

@ -36,14 +36,12 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import mage.cards.decks.DeckCardLists;
import mage.game.GameException;
import mage.game.draft.DraftOptions;
import mage.game.match.MatchOptions;
import mage.game.tournament.TournamentOptions;
import mage.util.Logging;
import mage.view.TableView;
import org.apache.log4j.Logger;
/**
*
@ -51,7 +49,7 @@ import mage.view.TableView;
*/
public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
private final static Logger logger = Logging.getLogger(GamesRoomImpl.class.getName());
// private final static Logger logger = Logger.getLogger(GamesRoomImpl.class);
private ConcurrentHashMap<UUID, Table> tables = new ConcurrentHashMap<UUID, Table>();
@ -98,7 +96,9 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
@Override
public TableView getTable(UUID tableId) {
return new TableView(tables.get(tableId));
if (tables.containsKey(tableId))
return new TableView(tables.get(tableId));
return null;
}
@Override

View file

@ -30,8 +30,7 @@ package mage.server.game;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import mage.util.Logging;
import org.apache.log4j.Logger;
/**
*
@ -40,7 +39,7 @@ import mage.util.Logging;
public class GamesRoomManager {
private final static GamesRoomManager INSTANCE = new GamesRoomManager();
private final static Logger logger = Logging.getLogger(GamesRoomManager.class.getName());
// private final static Logger logger = Logger.getLogger(GamesRoomManager.class);
private ConcurrentHashMap<UUID, GamesRoom> rooms = new ConcurrentHashMap<UUID, GamesRoom>();
private UUID mainRoomId;

View file

@ -29,16 +29,12 @@
package mage.server.game;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.Constants.RangeOfInfluence;
import mage.cards.decks.Deck;
import mage.players.Player;
import mage.util.Logging;
import org.apache.log4j.Logger;
/**
*
@ -47,7 +43,7 @@ import mage.util.Logging;
public class PlayerFactory {
private final static PlayerFactory INSTANCE = new PlayerFactory();
private final static Logger logger = Logging.getLogger(PlayerFactory.class.getName());
private final static Logger logger = Logger.getLogger(PlayerFactory.class);
private Map<String, Class> playerTypes = new LinkedHashMap<String, Class>();
@ -64,7 +60,7 @@ public class PlayerFactory {
con = playerTypes.get(playerType).getConstructor(new Class[]{String.class, RangeOfInfluence.class});
player = (Player)con.newInstance(new Object[] {name, range});
} catch (Exception ex) {
logger.log(Level.SEVERE, null, ex);
logger.fatal("PlayerFactory error ", ex);
return null;
}
logger.info("Player created: " + name + "-" + player.getId().toString());

View file

@ -31,8 +31,6 @@ package mage.server.tournament;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.cards.decks.Deck;
import mage.game.GameException;
import mage.game.Table;
@ -47,9 +45,9 @@ import mage.game.tournament.TournamentPlayer;
import mage.server.ChatManager;
import mage.server.TableManager;
import mage.server.util.ThreadExecutor;
import mage.util.Logging;
import mage.view.ChatMessage.MessageColor;
import mage.view.TournamentView;
import org.apache.log4j.Logger;
/**
*
@ -57,7 +55,7 @@ import mage.view.TournamentView;
*/
public class TournamentController {
private final static Logger logger = Logging.getLogger(TournamentController.class.getName());
private final static Logger logger = Logger.getLogger(TournamentController.class);
private UUID sessionId;
private UUID chatId;
@ -83,7 +81,7 @@ public class TournamentController {
switch (event.getEventType()) {
case INFO:
ChatManager.getInstance().broadcast(chatId, "", event.getMessage(), MessageColor.BLACK);
logger.finest(tournament.getId() + " " + event.getMessage());
logger.debug(tournament.getId() + " " + event.getMessage());
break;
case START_DRAFT:
startDraft(event.getDraft());
@ -160,7 +158,7 @@ public class TournamentController {
private synchronized void startTournament() {
for (final Entry<UUID, TournamentSession> entry: tournamentSessions.entrySet()) {
if (!entry.getValue().init(getTournamentView())) {
logger.severe("Unable to initialize client");
logger.fatal("Unable to initialize client");
//TODO: generate client error message
return;
}
@ -179,7 +177,7 @@ public class TournamentController {
tableManager.startMatch(null, table.getId());
pair.setMatch(tableManager.getMatch(table.getId()));
} catch (GameException ex) {
Logger.getLogger(TournamentController.class.getName()).log(Level.SEVERE, null, ex);
logger.fatal("TournamentController startMatch error", ex);
}
}

View file

@ -33,13 +33,11 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.game.tournament.Tournament;
import mage.game.tournament.TournamentOptions;
import mage.game.tournament.TournamentType;
import mage.util.Logging;
import mage.view.TournamentTypeView;
import org.apache.log4j.Logger;
/**
*
@ -47,7 +45,7 @@ import mage.view.TournamentTypeView;
*/
public class TournamentFactory {
private final static TournamentFactory INSTANCE = new TournamentFactory();
private final static Logger logger = Logging.getLogger(TournamentFactory.class.getName());
private final static Logger logger = Logger.getLogger(TournamentFactory.class);
private Map<String, Class<Tournament>> tournaments = new HashMap<String, Class<Tournament>>();
private Map<String, TournamentType> tournamentTypes = new HashMap<String, TournamentType>();
@ -67,7 +65,7 @@ public class TournamentFactory {
con = tournaments.get(tournamentType).getConstructor(new Class[]{TournamentOptions.class});
tournament = con.newInstance(new Object[] {options});
} catch (Exception ex) {
logger.log(Level.SEVERE, null, ex);
logger.fatal("TournamentFactory error ", ex);
return null;
}
logger.info("Tournament created: " + tournamentType); // + game.getId().toString());

View file

@ -33,23 +33,21 @@ import java.util.UUID;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.cards.decks.Deck;
import mage.game.tournament.Tournament;
import mage.interfaces.callback.ClientCallback;
import mage.server.Session;
import mage.server.SessionManager;
import mage.server.util.ThreadExecutor;
import mage.util.Logging;
import mage.view.TournamentView;
import org.apache.log4j.Logger;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentSession {
protected final static Logger logger = Logging.getLogger(TournamentSession.class.getName());
protected final static Logger logger = Logger.getLogger(TournamentSession.class);
protected UUID sessionId;
protected UUID playerId;
@ -119,7 +117,7 @@ public class TournamentSession {
}
protected void handleRemoteException(RemoteException ex) {
logger.log(Level.SEVERE, null, ex);
logger.fatal("TournamentSession error ", ex);
TournamentManager.getInstance().kill(tournament.getId(), sessionId);
}

View file

@ -30,9 +30,7 @@ package mage.server.util;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.util.Logging;
import org.apache.log4j.Logger;
/**
*
@ -40,14 +38,14 @@ import mage.util.Logging;
*/
public class Config {
private final static Logger logger = Logging.getLogger(Config.class.getName());
private final static Logger logger = Logger.getLogger(Config.class);
static {
Properties p = new Properties();
try {
p.load(Config.class.getResourceAsStream("resources/config.properties"));
} catch (IOException ex) {
logger.log(Level.SEVERE, null, ex);
logger.fatal("Config error", ex);
}
port = Integer.parseInt(p.getProperty("port"));
remoteServer = p.getProperty("remote-server");

View file

@ -30,22 +30,21 @@ package mage.server.util;
import java.io.File;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import mage.server.util.config.Config;
import mage.server.util.config.Plugin;
import mage.server.util.config.GamePlugin;
import mage.util.Logging;
import org.apache.log4j.Logger;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class ConfigSettings {
private final static Logger logger = Logging.getLogger(ConfigSettings.class.getName());
private final static Logger logger = Logger.getLogger(ConfigSettings.class);
private final static ConfigSettings INSTANCE = new ConfigSettings();
private Config config;
@ -60,7 +59,7 @@ public class ConfigSettings {
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
config = (Config) unmarshaller.unmarshal(new File("config/config.xml"));
} catch (JAXBException ex) {
logger.log(Level.SEVERE, null, ex);
logger.fatal("ConfigSettings error", ex);
}
}