fix testing
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2025-05-11 14:12:10 -04:00
parent fa4fd1e106
commit 3df3beafba
6 changed files with 45 additions and 7 deletions

View File

@ -1723,6 +1723,10 @@ Player characters not simulated at macro level
Macro simulation inventory utilities Macro simulation inventory utilities
Build structure goal properly working from macro sim Build structure goal properly working from macro sim
Repairability check when repairing structure Repairability check when repairing structure
Fix viewport loading
Database warning handling
In memory database support
Fix test utils creating characters

Binary file not shown.

Binary file not shown.

View File

@ -15,6 +15,7 @@ import electrosphere.net.parser.net.message.TerrainMessage;
import electrosphere.net.server.player.Player; import electrosphere.net.server.player.Player;
import electrosphere.renderer.ui.elements.Window; import electrosphere.renderer.ui.elements.Window;
import electrosphere.server.db.DatabaseController; import electrosphere.server.db.DatabaseController;
import electrosphere.server.db.DatabaseUtils;
/** /**
* Loads the viewport * Loads the viewport
@ -41,7 +42,7 @@ public class ViewportLoading {
// //
//connect client to server //connect client to server
LoggerInterface.loggerEngine.INFO("run server: " + Globals.RUN_SERVER + " run client: " + Globals.RUN_CLIENT); LoggerInterface.loggerEngine.INFO("run server: " + Globals.RUN_SERVER + " run client: " + Globals.RUN_CLIENT);
Globals.dbController = new DatabaseController(); ViewportLoading.initInMemoryDB();
LoadingUtils.initAuthenticationManager(true); LoadingUtils.initAuthenticationManager(true);
Globals.clientUsername = "leveleditor"; Globals.clientUsername = "leveleditor";
Globals.clientPassword = AuthenticationManager.getHashedString("leveleditor"); Globals.clientPassword = AuthenticationManager.getHashedString("leveleditor");
@ -79,4 +80,13 @@ public class ViewportLoading {
ClientLoading.loadViewport(params); ClientLoading.loadViewport(params);
} }
/**
* Initializes an in-memory db
*/
private static void initInMemoryDB(){
Globals.dbController = new DatabaseController();
Globals.dbController.connect(DatabaseController.IN_MEMORY_PATH);
DatabaseUtils.runScript(Globals.dbController,"createTables.sql");
}
} }

View File

@ -6,6 +6,7 @@ import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.SQLWarning;
import java.util.Properties; import java.util.Properties;
/** /**
@ -17,6 +18,11 @@ public class DatabaseController {
* file extension for allowed database files to open * file extension for allowed database files to open
*/ */
public static final String FILE_EXT = ".sqlite"; public static final String FILE_EXT = ".sqlite";
/**
* The in-memory path for database connections
*/
public static final String IN_MEMORY_PATH = ":memory:";
/** /**
* The database connection * The database connection
@ -39,8 +45,11 @@ public class DatabaseController {
try { try {
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); String message = "" +
ex.printStackTrace(); "Failure to connect to db\n" +
ex.getMessage() +
"";
throw new Error(message);
} }
} }
@ -51,6 +60,9 @@ public class DatabaseController {
* @return true if there is a result set, false if there is an update count or no result * @return true if there is a result set, false if there is an update count or no result
*/ */
public boolean executePreparedStatement(String statementRaw, Object...arguments){ public boolean executePreparedStatement(String statementRaw, Object...arguments){
if(conn == null){
throw new Error("Connection not initialized!");
}
try { try {
PreparedStatement statement = conn.prepareStatement(statementRaw); PreparedStatement statement = conn.prepareStatement(statementRaw);
//Set arguments for prepared statements //Set arguments for prepared statements
@ -73,6 +85,10 @@ public class DatabaseController {
} }
//actually execute //actually execute
boolean result = statement.execute(); boolean result = statement.execute();
SQLWarning warning = statement.getWarnings();
if(warning != null){
LoggerInterface.loggerDB.WARNING(warning.toString());
}
statement.close(); statement.close();
return result; return result;
} catch (SQLException ex) { } catch (SQLException ex) {
@ -90,8 +106,7 @@ public class DatabaseController {
public DatabaseResult executePreparedQuery(String statementRaw, Object...arguments){ public DatabaseResult executePreparedQuery(String statementRaw, Object...arguments){
DatabaseResult rVal = DatabaseResult.createQuery(statementRaw); DatabaseResult rVal = DatabaseResult.createQuery(statementRaw);
if(conn == null){ if(conn == null){
rVal.succeeded = false; throw new Error("Connection not initialized!");
return rVal;
} }
try { try {
PreparedStatement statement = conn.prepareStatement(statementRaw); PreparedStatement statement = conn.prepareStatement(statementRaw);
@ -116,6 +131,14 @@ public class DatabaseController {
} }
//actually execute //actually execute
ResultSet results = statement.executeQuery(); ResultSet results = statement.executeQuery();
SQLWarning warning = results.getWarnings();
if(warning != null){
LoggerInterface.loggerDB.WARNING(warning.toString());
}
warning = statement.getWarnings();
if(warning != null){
LoggerInterface.loggerDB.WARNING(warning.toString());
}
if(results != null){ if(results != null){
rVal.addResultSet(results); rVal.addResultSet(results);
} }

View File

@ -14,9 +14,9 @@ import electrosphere.engine.loadingthreads.LoadingThread;
import electrosphere.entity.Entity; import electrosphere.entity.Entity;
import electrosphere.entity.types.creature.CreatureTemplate; import electrosphere.entity.types.creature.CreatureTemplate;
import electrosphere.net.server.ServerConnectionHandler; import electrosphere.net.server.ServerConnectionHandler;
import electrosphere.net.server.protocol.CharacterProtocol;
import electrosphere.server.datacell.utils.EntityLookupUtils; import electrosphere.server.datacell.utils.EntityLookupUtils;
import electrosphere.server.macro.character.PlayerCharacterCreation; import electrosphere.server.macro.character.PlayerCharacterCreation;
import electrosphere.server.macro.character.Character;
/** /**
* Utils for testing the engine * Utils for testing the engine
@ -164,7 +164,8 @@ public class TestEngineUtils {
CreatureTemplate creatureTemplate = CreatureTemplate.createDefault("human"); CreatureTemplate creatureTemplate = CreatureTemplate.createDefault("human");
ServerConnectionHandler serverConnection = Globals.server.getFirstConnection(); ServerConnectionHandler serverConnection = Globals.server.getFirstConnection();
serverConnection.setCreatureTemplate(creatureTemplate); serverConnection.setCreatureTemplate(creatureTemplate);
serverConnection.setCharacterId(CharacterProtocol.SPAWN_EXISTING_TEMPLATE); Character chara = Globals.characterService.createCharacter(creatureTemplate, serverConnection.getPlayerId());
serverConnection.setCharacterId(chara.getId());
PlayerCharacterCreation.spawnPlayerCharacter(serverConnection); PlayerCharacterCreation.spawnPlayerCharacter(serverConnection);
} }