allow temporary dir for testing database off nas
This commit is contained in:
parent
331375f51d
commit
2fa8099d67
@ -1,10 +1,10 @@
|
||||
|
||||
--characters
|
||||
--positions
|
||||
CREATE TABLE charaWorldPositions (id INTEGER PRIMARY KEY, charID INTEGER, posX INTEGER, posY INTEGER);
|
||||
CREATE INDEX charaWorldPositionsIDIndex ON charaWorldPositions (charID);
|
||||
CREATE TABLE charaWorldPositions (playerId INTEGER PRIMARY KEY, id INTEGER, posX INTEGER, posY INTEGER);
|
||||
CREATE INDEX charaWorldPositionsIDIndex ON charaWorldPositions (id);
|
||||
CREATE INDEX charaWorldPositionsPosIndex ON charaWorldPositions (posX, posY);
|
||||
|
||||
--data
|
||||
CREATE TABLE charaData (id INTEGER PRIMARY KEY, charID INTEGER, dataVal VARCHAR);
|
||||
CREATE INDEX charaDataIDIndex ON charaData (charID);
|
||||
CREATE TABLE charaData (playerId INTEGER PRIMARY KEY, id INTEGER, dataVal VARCHAR);
|
||||
CREATE INDEX charaDataIDIndex ON charaData (id);
|
||||
|
||||
@ -69,6 +69,9 @@ import electrosphere.renderer.ui.Window;
|
||||
import electrosphere.util.FileUtils;
|
||||
import electrosphere.util.Utilities;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
@ -185,10 +188,12 @@ public class LoadingThread extends Thread {
|
||||
initServerArenaWorldData();
|
||||
//init data cell manager
|
||||
initDataCellManager();
|
||||
//for testing purposes
|
||||
FileUtils.recursivelyDelete("/home/satellite/temp/saves/arena");
|
||||
//init database connection
|
||||
// SaveUtils.initSave("arena");
|
||||
SaveUtils.initSave("arena");
|
||||
//connect to database
|
||||
// Globals.dbController.connect("./saves/arena/central.db");
|
||||
SaveUtils.loadSave("arena");
|
||||
//init authentication
|
||||
initAuthenticationManager();
|
||||
//initialize the server thread (server only)
|
||||
|
||||
@ -30,6 +30,7 @@ public class DatabaseController {
|
||||
conn = DriverManager.getConnection(fullAddress, connectionProps);
|
||||
} catch (SQLException ex) {
|
||||
LoggerInterface.loggerFileIO.ERROR("Failure to connect to db", ex);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,6 +81,9 @@ public class DatabaseController {
|
||||
|
||||
public boolean isConnected(){
|
||||
boolean rVal = false;
|
||||
if(conn == null){
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
rVal = conn.isValid(100);
|
||||
} catch (SQLException ex) {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package electrosphere.game.server.db;
|
||||
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.util.FileUtils;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
@ -19,19 +20,23 @@ public class DatabaseUtils {
|
||||
return false;
|
||||
}
|
||||
String dbFilePath = sanitizedPath + "/central.db";
|
||||
DatabaseController controller = new DatabaseController();
|
||||
controller.connect(dbFilePath);
|
||||
runScript(controller,"createTables.sql");
|
||||
if(Globals.dbController == null){
|
||||
Globals.dbController = new DatabaseController();
|
||||
}
|
||||
if(!Globals.dbController.isConnected()){
|
||||
Globals.dbController.connect(dbFilePath);
|
||||
}
|
||||
runScript(Globals.dbController,"createTables.sql");
|
||||
//both of these are used for arena mode as well as main game
|
||||
runScript(controller,"/auth/createAuthTables.sql");
|
||||
runScript(controller,"/character/createCharacterTables.sql");
|
||||
runScript(Globals.dbController,"/auth/createAuthTables.sql");
|
||||
runScript(Globals.dbController,"/character/createCharacterTables.sql");
|
||||
//create adventure-only files
|
||||
if(!dbFilePath.equals("./saves/arena/central.db")){
|
||||
//we only want to create these if we're not in arena mode
|
||||
runScript(controller,"/towns/createTownsTables.sql");
|
||||
runScript(controller,"/structs/createStructsTables.sql");
|
||||
runScript(Globals.dbController,"/towns/createTownsTables.sql");
|
||||
runScript(Globals.dbController,"/structs/createStructsTables.sql");
|
||||
}
|
||||
controller.disconnect();
|
||||
Globals.dbController.disconnect();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -16,7 +16,8 @@ import java.util.List;
|
||||
public class SaveUtils {
|
||||
|
||||
static String deriveSaveDirectoryPath(String saveName){
|
||||
return "./saves/" + saveName;
|
||||
String path = "/home/satellite/temp/saves/" + saveName;
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -30,7 +31,7 @@ public class SaveUtils {
|
||||
if(FileUtils.checkFileExists(dirPath)){
|
||||
return false;
|
||||
}
|
||||
//create dir
|
||||
// create dir
|
||||
if(!FileUtils.createDirectory(dirPath)){
|
||||
//we for some unknown reason, couldn't make the save dir
|
||||
return false;
|
||||
@ -61,8 +62,10 @@ public class SaveUtils {
|
||||
String dirPath = deriveSaveDirectoryPath(saveName);
|
||||
String dbFilePath = FileUtils.sanitizeFilePath(dirPath) + "/central.db";
|
||||
Globals.dbController.connect(dbFilePath);
|
||||
Globals.serverTerrainManager.load(saveName);
|
||||
Globals.serverWorldData = FileUtils.loadObjectFromSavePath(saveName, "world.json", ServerWorldData.class);
|
||||
if(!saveName.equals("arena")){
|
||||
Globals.serverTerrainManager.load(saveName);
|
||||
Globals.serverWorldData = FileUtils.loadObjectFromSavePath(saveName, "world.json", ServerWorldData.class);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -242,6 +242,21 @@ public class FileUtils {
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static void recursivelyDelete(String path){
|
||||
File file = new File(path);
|
||||
if(file.isDirectory()){
|
||||
for(File child : file.listFiles()){
|
||||
recursivelyDelete(child.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
try {
|
||||
Files.delete(file.toPath());
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user