package net.sourceforge.pain;
import net.sourceforge.pain.data.*;
import net.sourceforge.pain.db.*;
import net.sourceforge.pain.network.console.*;
import net.sourceforge.pain.network.guitool.*;
import net.sourceforge.pain.plugin.*;
import net.sourceforge.pain.util.*;
public class Launcher {
public static void main(String[] args) throws Exception {
init();
}
private static void init() throws Exception {
if (Core.getDB() != null) {
throw new IllegalStateException("already inited!");
}
initDb();
loadWorld();
loadAllWhatsLeft();
}
private static void initDb() throws Exception {
PainDB db = new PainDB("pain.pdb");
Core.setDB(db);
}
private static void loadWorld() throws Exception {
PainDB db = Core.getDB();
Log.info("loading World");
World world = (World) db.getRoot();
if (world == null) {
if (!db.isDatabaseEmpty()) {
throw new RuntimeException("database is not empty, but world instance not found!");
}
Log.debug("Empty database detected!, creating world!");
world = new World(db);
Core.setWorld(world);
Core.processEvent("deploy.CreateInitialWorldEvent", null);
db.setRoot(world);
Log.debug("World Created!");
} else {
Log.info("World instance found");
Core.setWorld(world);
}
Log.info("flushing all startup fixes");
db.flush();
Log.info("Flushed OK!");
}
private static void loadAllWhatsLeft() throws Exception {
Log.info("Creating plugin manager");
PluginManager plm = new PluginManager(Core.getApplicationPath() + "/classes");
plm.init();
Core.setPluginManager(plm);
Log.info("Creating plugin manager OK");
checkSafeShutdown(); // checks if server was properly shutted down (mark all players as logged out snd so on..)
Log.info("Creating console manager");
Core.setConsoleManager(new ConsoleManager());
Log.info("Creating console manager OK");
Log.info("Creating guitool connection manager");
Core.setGuiToolSessionManager(new GuiToolSessionManager(5555));
Log.info("Creating console manager OK");
Log.info("Creating affect processor");
Core.getTime().addListener(new AffectProcessor(Core.getWorld().getAffectsQueue()));
Log.info("Creating affect processor OK");
Log.info("starting timer...");
new Thread(Core.getTime()).start();
Log.info("done!");
}
private static void checkSafeShutdown() throws Exception {
Core.processEvent("CheckSafeShutdown", null);
}
}