database work
This commit is contained in:
parent
07eaecfa16
commit
331375f51d
3
.gitignore
vendored
3
.gitignore
vendored
@ -27,3 +27,6 @@
|
||||
#docs backup files
|
||||
/docs/~$NetworkFlow.drawio.bkp
|
||||
/docs/~$NetworkFlow.drawio.dtmp
|
||||
|
||||
#saves
|
||||
/saves/arena
|
||||
|
||||
7
Scripts/auth/createAuthTables.sql
Normal file
7
Scripts/auth/createAuthTables.sql
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
-- accounts definition
|
||||
CREATE TABLE accounts (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT NOT NULL,
|
||||
pwdhash TEXT NOT NULL
|
||||
);
|
||||
10
Scripts/character/createCharacterTables.sql
Normal file
10
Scripts/character/createCharacterTables.sql
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
--characters
|
||||
--positions
|
||||
CREATE TABLE charaWorldPositions (id INTEGER PRIMARY KEY, charID INTEGER, posX INTEGER, posY INTEGER);
|
||||
CREATE INDEX charaWorldPositionsIDIndex ON charaWorldPositions (charID);
|
||||
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);
|
||||
@ -3,36 +3,7 @@
|
||||
CREATE TABLE mainTable (propName VARCHAR PRIMARY KEY, propValue VARCHAR);
|
||||
INSERT INTO mainTable (propName, propValue) VALUES ("ver","1");
|
||||
|
||||
--characters
|
||||
--positions
|
||||
CREATE TABLE charaWorldPositions (id INTEGER PRIMARY KEY, charID INTEGER, posX INTEGER, posY INTEGER);
|
||||
CREATE INDEX charaWorldPositionsIDIndex ON charaWorldPositions (charID);
|
||||
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);
|
||||
|
||||
|
||||
|
||||
--towns
|
||||
--positions
|
||||
CREATE TABLE townWorldPositions (id INTEGER PRIMARY KEY, townID INTEGER, posX INTEGER, posY INTEGER);
|
||||
CREATE INDEX townWorldPositionsIDIndex ON townWorldPositions (townID);
|
||||
CREATE INDEX townWorldPositionsPosIndex ON townWorldPositions (posX, posY);
|
||||
|
||||
--data
|
||||
CREATE TABLE townData (id INTEGER PRIMARY KEY, townID INTEGER, dataVal VARCHAR);
|
||||
CREATE INDEX townDataIDIndex ON townData (townID);
|
||||
|
||||
|
||||
--structures
|
||||
--positions
|
||||
CREATE TABLE structWorldPositions (id INTEGER PRIMARY KEY, structID INTEGER, posX INTEGER, posY INTEGER);
|
||||
CREATE INDEX structWorldPositionsIDIndex ON structWorldPositions (structID);
|
||||
CREATE INDEX structWorldPositionsPosIndex ON structWorldPositions (posX, posY);
|
||||
|
||||
--data
|
||||
CREATE TABLE structData (id INTEGER PRIMARY KEY, structID INTEGER, dataVal VARCHAR);
|
||||
CREATE INDEX structDataIDIndex ON structData (structID);
|
||||
|
||||
|
||||
10
Scripts/structs/createStructsTables.sql
Normal file
10
Scripts/structs/createStructsTables.sql
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
--structures
|
||||
--positions
|
||||
CREATE TABLE structWorldPositions (id INTEGER PRIMARY KEY, structID INTEGER, posX INTEGER, posY INTEGER);
|
||||
CREATE INDEX structWorldPositionsIDIndex ON structWorldPositions (structID);
|
||||
CREATE INDEX structWorldPositionsPosIndex ON structWorldPositions (posX, posY);
|
||||
|
||||
--data
|
||||
CREATE TABLE structData (id INTEGER PRIMARY KEY, structID INTEGER, dataVal VARCHAR);
|
||||
CREATE INDEX structDataIDIndex ON structData (structID);
|
||||
10
Scripts/towns/createTownsTables.sql
Normal file
10
Scripts/towns/createTownsTables.sql
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
--towns
|
||||
--positions
|
||||
CREATE TABLE townWorldPositions (id INTEGER PRIMARY KEY, townID INTEGER, posX INTEGER, posY INTEGER);
|
||||
CREATE INDEX townWorldPositionsIDIndex ON townWorldPositions (townID);
|
||||
CREATE INDEX townWorldPositionsPosIndex ON townWorldPositions (posX, posY);
|
||||
|
||||
--data
|
||||
CREATE TABLE townData (id INTEGER PRIMARY KEY, townID INTEGER, dataVal VARCHAR);
|
||||
CREATE INDEX townDataIDIndex ON townData (townID);
|
||||
56
pom.xml
56
pom.xml
@ -13,12 +13,6 @@
|
||||
<joml.version>1.9.19</joml.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/org.lwjgl/lwjgl -->
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-assimp</artifactId>
|
||||
@ -55,55 +49,9 @@
|
||||
<artifactId>lwjgl</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>${lwjgl.natives}</classifier>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!-- assimp runtimes -->
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-assimp</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>${lwjgl.natives}</classifier>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!-- GLFW runtimes -->
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-glfw</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>${lwjgl.natives}</classifier>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!-- opengl runtimes -->
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-opengl</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>${lwjgl.natives}</classifier>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!-- Embedded opengl runtimes -->
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-opengles</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>${lwjgl.natives}</classifier>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!-- Audio runtimes -->
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-openal</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>${lwjgl.natives}</classifier>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-stb</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>${lwjgl.natives}</classifier>
|
||||
<scope>runtime</scope>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.joml</groupId>
|
||||
<artifactId>joml</artifactId>
|
||||
|
||||
@ -36,6 +36,7 @@ import electrosphere.game.server.terrain.models.TerrainModification;
|
||||
import electrosphere.game.server.town.Town;
|
||||
import electrosphere.game.server.world.MacroData;
|
||||
import electrosphere.game.server.datacell.DataCellManager;
|
||||
import electrosphere.game.server.db.DatabaseUtils;
|
||||
import electrosphere.game.simulation.MicroSimulation;
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
import electrosphere.main.Globals;
|
||||
@ -65,6 +66,7 @@ import electrosphere.game.server.unit.UnitUtils;
|
||||
import electrosphere.renderer.ui.DrawableElement;
|
||||
import electrosphere.renderer.ui.WidgetUtils;
|
||||
import electrosphere.renderer.ui.Window;
|
||||
import electrosphere.util.FileUtils;
|
||||
import electrosphere.util.Utilities;
|
||||
|
||||
import java.util.LinkedList;
|
||||
@ -183,6 +185,10 @@ public class LoadingThread extends Thread {
|
||||
initServerArenaWorldData();
|
||||
//init data cell manager
|
||||
initDataCellManager();
|
||||
//init database connection
|
||||
// SaveUtils.initSave("arena");
|
||||
//connect to database
|
||||
// Globals.dbController.connect("./saves/arena/central.db");
|
||||
//init authentication
|
||||
initAuthenticationManager();
|
||||
//initialize the server thread (server only)
|
||||
|
||||
@ -57,6 +57,7 @@ public class DatabaseController {
|
||||
rVal.succeeded = false;
|
||||
rVal.hasResultSet = false;
|
||||
LoggerInterface.loggerFileIO.ERROR("SQL statement execution error", ex);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ public class DatabaseResult {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public void addResultSet(ResultSet rs){
|
||||
protected void addResultSet(ResultSet rs){
|
||||
this.rs = rs;
|
||||
}
|
||||
|
||||
|
||||
@ -11,29 +11,54 @@ import java.util.logging.Logger;
|
||||
* @author satellite
|
||||
*/
|
||||
public class DatabaseUtils {
|
||||
|
||||
|
||||
public static boolean initCentralDBFile(String path){
|
||||
String sanitizedPath = "." + FileUtils.sanitizeFilePath(path);
|
||||
String sanitizedPath = FileUtils.sanitizeFilePath(path);
|
||||
if(!FileUtils.checkFileExists(sanitizedPath)){
|
||||
return false;
|
||||
}
|
||||
String dbFilePath = sanitizedPath + "/central.db";
|
||||
DatabaseController controller = new DatabaseController();
|
||||
controller.connect(dbFilePath);
|
||||
runScript(controller,"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");
|
||||
//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");
|
||||
}
|
||||
controller.disconnect();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean runScript(DatabaseController controller, String scriptPath){
|
||||
String rawScript = "";
|
||||
try {
|
||||
rawScript = FileUtils.getSQLScriptFileAsString("createTables.sql");
|
||||
rawScript = FileUtils.getSQLScriptFileAsString(scriptPath);
|
||||
} catch (IOException ex) {
|
||||
LoggerInterface.loggerEngine.ERROR("Failure reading create db script", ex);
|
||||
return false;
|
||||
}
|
||||
String[] scriptLines = rawScript.split("\n");
|
||||
String accumulatorString = "";
|
||||
for(String line : scriptLines){
|
||||
if(line.length() > 1 && !line.startsWith("--")){
|
||||
System.out.println("EXECUTE: " + line);
|
||||
controller.executeStatement(line);
|
||||
if(line.contains(";")){
|
||||
accumulatorString = accumulatorString + line;
|
||||
System.out.println("EXECUTE: " + accumulatorString);
|
||||
controller.executeStatement(accumulatorString);
|
||||
accumulatorString = "";
|
||||
} else {
|
||||
accumulatorString = accumulatorString + line;
|
||||
}
|
||||
}
|
||||
}
|
||||
controller.disconnect();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ public class ClientNetworking implements Runnable{
|
||||
}
|
||||
if(connectionAttempts > MAX_CONNECTION_ATTEMPTS){
|
||||
LoggerInterface.loggerNetworking.ERROR("Max client connection attempts!", new Exception());
|
||||
System.exit(1);
|
||||
// System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package electrosphere.net.server;
|
||||
|
||||
import electrosphere.game.server.saves.SaveUtils;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.main.Main;
|
||||
import electrosphere.net.NetUtils;
|
||||
|
||||
@ -222,7 +222,7 @@ public class FileUtils {
|
||||
* @return true if directory was created, false if it was not
|
||||
*/
|
||||
public static boolean createDirectory(String directoryName){
|
||||
String sanitizedPath = "." + sanitizeFilePath(directoryName);
|
||||
String sanitizedPath = sanitizeFilePath(directoryName);
|
||||
File targetDir = new File(sanitizedPath);
|
||||
if(targetDir.exists()){
|
||||
return false;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user