mirror of
https://github.com/magefree/mage.git
synced 2025-12-21 11:02:00 -08:00
...
This commit is contained in:
parent
3a4378067e
commit
4896421f17
13 changed files with 33 additions and 757 deletions
|
|
@ -30,6 +30,7 @@ package mage.server;
|
|||
|
||||
import mage.server.util.PluginClassLoader;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import mage.server.game.DeckValidatorFactory;
|
||||
|
|
@ -61,6 +62,7 @@ public class Main {
|
|||
|
||||
logger.info("Starting MAGE server version " + Main.class.getPackage().getImplementationVersion());
|
||||
logger.info("Logging level: " + Logging.getLevel(logger));
|
||||
deleteSavedGames();
|
||||
ConfigSettings config = ConfigSettings.getInstance();
|
||||
for (Plugin plugin: config.getGameTypes()) {
|
||||
GameFactory.getInstance().addGameType(plugin.getName(), loadPlugin(plugin));
|
||||
|
|
@ -96,4 +98,20 @@ public class Main {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static void deleteSavedGames() {
|
||||
File directory = new File("saved/");
|
||||
File[] files = directory.listFiles(
|
||||
new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".game");
|
||||
}
|
||||
}
|
||||
);
|
||||
for (File file : files)
|
||||
{
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.players.Player;
|
||||
import mage.util.Logging;
|
||||
|
||||
|
|
@ -54,12 +55,12 @@ public class PlayerFactory {
|
|||
|
||||
private PlayerFactory() {}
|
||||
|
||||
public Player createPlayer(String playerType, String name) {
|
||||
public Player createPlayer(String playerType, String name, Deck deck) {
|
||||
Player player;
|
||||
Constructor<?> con;
|
||||
try {
|
||||
con = playerTypes.get(playerType).getConstructor(new Class[]{String.class});
|
||||
player = (Player)con.newInstance(new Object[] {name});
|
||||
con = playerTypes.get(playerType).getConstructor(new Class[]{String.class, Deck.class});
|
||||
player = (Player)con.newInstance(new Object[] {name, deck});
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -134,9 +134,9 @@ public class TableController {
|
|||
}
|
||||
|
||||
private Player createPlayer(String name, Deck deck, String playerType) {
|
||||
Player player = PlayerFactory.getInstance().createPlayer(playerType, name);
|
||||
Player player = PlayerFactory.getInstance().createPlayer(playerType, name, deck);
|
||||
logger.info("Player created " + player.getId());
|
||||
player.setDeck(deck);
|
||||
// player.setDeck(deck);
|
||||
return player;
|
||||
}
|
||||
|
||||
|
|
@ -178,8 +178,8 @@ public class TableController {
|
|||
}
|
||||
finally {
|
||||
output.close();
|
||||
logger.log(Level.SEVERE, "Saved game:" + game.getId());
|
||||
}
|
||||
logger.log(Level.SEVERE, "Saved game:" + game.getId());
|
||||
}
|
||||
catch(IOException ex) {
|
||||
logger.log(Level.SEVERE, "Cannot save game.", ex);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue