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