move server state
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2025-05-15 16:28:53 -04:00
parent 7e8659d17b
commit da3893f3ff
13 changed files with 45 additions and 43 deletions

View File

@ -1828,6 +1828,7 @@ Move microSimulation into serverState
Move fluidCellManager into clientState Move fluidCellManager into clientState
Move engine flags under engineState Move engine flags under engineState
Move rendering flags under renderingEngine Move rendering flags under renderingEngine
Move database connection into serverState

View File

@ -61,7 +61,7 @@ public class AuthenticationManager {
//first we hash the input password //first we hash the input password
String hashedPassword = getHashedString(password); String hashedPassword = getHashedString(password);
//then query the database for the username and hash for the input username //then query the database for the username and hash for the input username
DatabaseResult result = Globals.dbController.executePreparedQuery("SELECT id, username, pwdhash FROM accounts WHERE username=?;",username); DatabaseResult result = Globals.serverState.dbController.executePreparedQuery("SELECT id, username, pwdhash FROM accounts WHERE username=?;",username);
if(result.hasResult()){ if(result.hasResult()){
boolean foundRow = false; boolean foundRow = false;
//if we get a valid response from the database, check that it actually matches hashes //if we get a valid response from the database, check that it actually matches hashes
@ -76,10 +76,10 @@ public class AuthenticationManager {
//If we didn't find a single account, go ahead and create it //If we didn't find a single account, go ahead and create it
if(!foundRow){ if(!foundRow){
LoggerInterface.loggerAuth.INFO("Created user " + username); LoggerInterface.loggerAuth.INFO("Created user " + username);
Globals.dbController.executePreparedStatement("INSERT INTO accounts (username, pwdhash) VALUES(?, ?);",username,hashedPassword); Globals.serverState.dbController.executePreparedStatement("INSERT INTO accounts (username, pwdhash) VALUES(?, ?);",username,hashedPassword);
//verify the account was created //verify the account was created
result = Globals.dbController.executePreparedQuery("SELECT id, username, pwdhash FROM accounts WHERE username=?;",username); result = Globals.serverState.dbController.executePreparedQuery("SELECT id, username, pwdhash FROM accounts WHERE username=?;",username);
if(result.hasResult()){ if(result.hasResult()){
foundRow = false; foundRow = false;
//if we get a valid response from the database, check that it actually matches hashes //if we get a valid response from the database, check that it actually matches hashes

View File

@ -35,10 +35,7 @@ import electrosphere.renderer.ui.elements.ImagePanel;
import electrosphere.renderer.ui.font.FontManager; import electrosphere.renderer.ui.font.FontManager;
import electrosphere.script.ScriptEngine; import electrosphere.script.ScriptEngine;
import electrosphere.server.ServerState; import electrosphere.server.ServerState;
import electrosphere.server.db.DatabaseController;
import electrosphere.server.entity.poseactor.PoseModel; import electrosphere.server.entity.poseactor.PoseModel;
import electrosphere.server.service.CharacterService;
import electrosphere.server.service.StructureScanningService;
import electrosphere.util.FileUtils; import electrosphere.util.FileUtils;
/** /**
@ -98,11 +95,6 @@ public class Globals {
public static ScrollCallback scrollCallback = new ScrollCallback(); public static ScrollCallback scrollCallback = new ScrollCallback();
public static CursorState cursorState = new CursorState(); public static CursorState cursorState = new CursorState();
//
// Database stuff
//
public static DatabaseController dbController = new DatabaseController();
// //
@ -163,7 +155,6 @@ public class Globals {
//services //services
public static FileWatcherService fileWatcherService; public static FileWatcherService fileWatcherService;
public static StructureScanningService structureScanningService;
@ -194,7 +185,6 @@ public class Globals {
//server state //server state
Globals.serverState = new ServerState(); Globals.serverState = new ServerState();
Globals.serverState.characterService = (CharacterService)Globals.engineState.serviceManager.registerService(new CharacterService());
//load in default texture map //load in default texture map
textureMapDefault = TextureMap.construct("Textures/default_texture_map.json"); textureMapDefault = TextureMap.construct("Textures/default_texture_map.json");
@ -224,7 +214,6 @@ public class Globals {
Globals.scriptEngine = (ScriptEngine)Globals.engineState.serviceManager.registerService(new ScriptEngine()); Globals.scriptEngine = (ScriptEngine)Globals.engineState.serviceManager.registerService(new ScriptEngine());
Globals.mainThreadSignalService = (MainThreadSignalService)Globals.engineState.serviceManager.registerService(new MainThreadSignalService()); Globals.mainThreadSignalService = (MainThreadSignalService)Globals.engineState.serviceManager.registerService(new MainThreadSignalService());
Globals.fileWatcherService = (FileWatcherService)Globals.engineState.serviceManager.registerService(new FileWatcherService()); Globals.fileWatcherService = (FileWatcherService)Globals.engineState.serviceManager.registerService(new FileWatcherService());
Globals.structureScanningService = (StructureScanningService)Globals.engineState.serviceManager.registerService(new StructureScanningService());
Globals.engineState.serviceManager.instantiate(); Globals.engineState.serviceManager.instantiate();
// //
//End service manager //End service manager
@ -383,13 +372,12 @@ public class Globals {
if(Globals.serverState != null){ if(Globals.serverState != null){
Globals.serverState.aiManager.shutdown(); Globals.serverState.aiManager.shutdown();
Globals.serverState.realmManager.reset(); Globals.serverState.realmManager.reset();
Globals.serverState.dbController.disconnect();
} }
Globals.dbController.disconnect();
Globals.engineState.serviceManager.unloadScene(); Globals.engineState.serviceManager.unloadScene();
Globals.clientState = new ClientState(); Globals.clientState = new ClientState();
Globals.serverState = new ServerState(); Globals.serverState = new ServerState();
Globals.serverState.characterService = (CharacterService)Globals.engineState.serviceManager.registerService(new CharacterService());
} }
/** /**
@ -399,8 +387,8 @@ public class Globals {
if(Globals.serverState != null){ if(Globals.serverState != null){
Globals.serverState.aiManager.shutdown(); Globals.serverState.aiManager.shutdown();
Globals.serverState.realmManager.reset(); Globals.serverState.realmManager.reset();
Globals.serverState.dbController.disconnect();
} }
Globals.dbController.disconnect();
// //
//Actual globals to destroy //Actual globals to destroy
Globals.assetManager = null; Globals.assetManager = null;

View File

@ -9,7 +9,6 @@ import electrosphere.engine.signal.Signal.SignalType;
import electrosphere.engine.threads.LabeledThread.ThreadLabel; import electrosphere.engine.threads.LabeledThread.ThreadLabel;
import electrosphere.renderer.ui.elements.Window; import electrosphere.renderer.ui.elements.Window;
import electrosphere.server.ServerState; import electrosphere.server.ServerState;
import electrosphere.server.service.CharacterService;
/** /**
* Loading thread that returns the client to the main menu * Loading thread that returns the client to the main menu
@ -63,7 +62,6 @@ public class MainMenuLoading {
private static void resetServerState(){ private static void resetServerState(){
Globals.serverState.server.close(); Globals.serverState.server.close();
Globals.serverState = new ServerState(); Globals.serverState = new ServerState();
Globals.serverState.characterService = (CharacterService)Globals.engineState.serviceManager.registerService(new CharacterService());
} }
/** /**

View File

@ -84,9 +84,8 @@ public class ViewportLoading {
* Initializes an in-memory db * Initializes an in-memory db
*/ */
private static void initInMemoryDB(){ private static void initInMemoryDB(){
Globals.dbController = new DatabaseController(); Globals.serverState.dbController.connect(DatabaseController.IN_MEMORY_PATH);
Globals.dbController.connect(DatabaseController.IN_MEMORY_PATH); DatabaseUtils.runScript(Globals.serverState.dbController,"createTables.sql");
DatabaseUtils.runScript(Globals.dbController,"createTables.sql");
} }
} }

View File

@ -60,7 +60,7 @@ public class MainServerFunctions {
* Simulates server services * Simulates server services
*/ */
private static void simulateServices(){ private static void simulateServices(){
Globals.structureScanningService.simulate(); Globals.serverState.structureScanningService.simulate();
} }
} }

View File

@ -1,5 +1,6 @@
package electrosphere.server; package electrosphere.server;
import electrosphere.engine.Globals;
import electrosphere.net.server.Server; import electrosphere.net.server.Server;
import electrosphere.net.server.player.PlayerManager; import electrosphere.net.server.player.PlayerManager;
import electrosphere.net.synchronization.server.EntityValueTrackingService; import electrosphere.net.synchronization.server.EntityValueTrackingService;
@ -7,8 +8,10 @@ import electrosphere.net.synchronization.server.ServerSynchronizationManager;
import electrosphere.server.ai.AIManager; import electrosphere.server.ai.AIManager;
import electrosphere.server.datacell.EntityDataCellMapper; import electrosphere.server.datacell.EntityDataCellMapper;
import electrosphere.server.datacell.RealmManager; import electrosphere.server.datacell.RealmManager;
import electrosphere.server.db.DatabaseController;
import electrosphere.server.saves.Save; import electrosphere.server.saves.Save;
import electrosphere.server.service.CharacterService; import electrosphere.server.service.CharacterService;
import electrosphere.server.service.StructureScanningService;
import electrosphere.server.simulation.MicroSimulation; import electrosphere.server.simulation.MicroSimulation;
/** /**
@ -49,7 +52,12 @@ public class ServerState {
/** /**
* Service for managing characters * Service for managing characters
*/ */
public CharacterService characterService; public final CharacterService characterService;
/**
* Service for background scanning to detect when players create structures
*/
public final StructureScanningService structureScanningService;
/** /**
* behavior tree tracking service * behavior tree tracking service
@ -61,9 +69,22 @@ public class ServerState {
*/ */
public PlayerManager playerManager = new PlayerManager(); public PlayerManager playerManager = new PlayerManager();
/**
* Database controller
*/
public final DatabaseController dbController = new DatabaseController();
/** /**
* The micro simulation * The micro simulation
*/ */
public final MicroSimulation microSimulation = new MicroSimulation(); public final MicroSimulation microSimulation = new MicroSimulation();
/**
* Constructor
*/
public ServerState(){
this.characterService = (CharacterService)Globals.engineState.serviceManager.registerService(new CharacterService());
this.structureScanningService = (StructureScanningService)Globals.engineState.serviceManager.registerService(new StructureScanningService());
}
} }

View File

@ -258,7 +258,7 @@ public class Realm {
// //
//macro data simulation //macro data simulation
if(this.macroData != null && Globals.dbController != null && Globals.dbController.isConnected()){ if(this.macroData != null && Globals.serverState.dbController != null && Globals.serverState.dbController.isConnected()){
MacroSimulation.simulate(this); MacroSimulation.simulate(this);
} }

View File

@ -22,15 +22,12 @@ public class DatabaseUtils {
return false; return false;
} }
String dbFilePath = sanitizedPath + "/central" + DatabaseController.FILE_EXT; String dbFilePath = sanitizedPath + "/central" + DatabaseController.FILE_EXT;
if(Globals.dbController == null){ if(!Globals.serverState.dbController.isConnected()){
Globals.dbController = new DatabaseController(); Globals.serverState.dbController.connect(dbFilePath);
} }
if(!Globals.dbController.isConnected()){ DatabaseUtils.runScript(Globals.serverState.dbController,"createTables.sql");
Globals.dbController.connect(dbFilePath);
}
DatabaseUtils.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
Globals.dbController.disconnect(); Globals.serverState.dbController.disconnect();
return true; return true;
} }

View File

@ -39,7 +39,7 @@ public class BlockActions {
String goalBlockEntityId = Item.getBlockTypeId(blockTypeData); String goalBlockEntityId = Item.getBlockTypeId(blockTypeData);
if(CreatureUtils.hasControllerPlayerId(creature)){ if(CreatureUtils.hasControllerPlayerId(creature)){
Player player = Globals.serverState.playerManager.getPlayerFromId(CreatureUtils.getControllerPlayerId(creature)); Player player = Globals.serverState.playerManager.getPlayerFromId(CreatureUtils.getControllerPlayerId(creature));
Globals.structureScanningService.queue(player, ServerWorldData.convertLocalBlockToRealSpace(chunkPos, blockPos)); Globals.serverState.structureScanningService.queue(player, ServerWorldData.convertLocalBlockToRealSpace(chunkPos, blockPos));
} }
if(equippedItemType.equals(goalBlockEntityId)){ if(equippedItemType.equals(goalBlockEntityId)){
@ -64,7 +64,7 @@ public class BlockActions {
ServerChargeState.attemptRemoveCharges(creature, 1); ServerChargeState.attemptRemoveCharges(creature, 1);
if(CreatureUtils.hasControllerPlayerId(creature)){ if(CreatureUtils.hasControllerPlayerId(creature)){
Player player = Globals.serverState.playerManager.getPlayerFromId(CreatureUtils.getControllerPlayerId(creature)); Player player = Globals.serverState.playerManager.getPlayerFromId(CreatureUtils.getControllerPlayerId(creature));
Globals.structureScanningService.queue(player, ServerWorldData.convertLocalBlockToRealSpace(chunkPos, blockPos)); Globals.serverState.structureScanningService.queue(player, ServerWorldData.convertLocalBlockToRealSpace(chunkPos, blockPos));
} }
} }

View File

@ -226,7 +226,7 @@ public class SaveUtils {
//load db //load db
String dbFilePath = FileUtils.sanitizeFilePath(dirPath) + "/central" + DatabaseController.FILE_EXT; String dbFilePath = FileUtils.sanitizeFilePath(dirPath) + "/central" + DatabaseController.FILE_EXT;
Globals.dbController.connect(dbFilePath); Globals.serverState.dbController.connect(dbFilePath);
return true; return true;
} }

View File

@ -69,7 +69,7 @@ public class CharacterService extends SignalServiceImpl {
lock.lock(); lock.lock();
Character toStore = new Character(template); Character toStore = new Character(template);
toStore.setPlayerId(playerId); toStore.setPlayerId(playerId);
DatabaseResult result = Globals.dbController.executePreparedQuery( DatabaseResult result = Globals.serverState.dbController.executePreparedQuery(
"INSERT INTO charaData (playerId,dataVal) VALUES (?,?) RETURNING id;", "INSERT INTO charaData (playerId,dataVal) VALUES (?,?) RETURNING id;",
playerId, playerId,
new Gson().toJson(toStore) new Gson().toJson(toStore)
@ -98,7 +98,7 @@ public class CharacterService extends SignalServiceImpl {
return rVal; return rVal;
} }
Character charData = null; Character charData = null;
DatabaseResult result = Globals.dbController.executePreparedQuery("SELECT id, playerId, dataVal FROM charaData WHERE id=?;", characterId); DatabaseResult result = Globals.serverState.dbController.executePreparedQuery("SELECT id, playerId, dataVal FROM charaData WHERE id=?;", characterId);
if(!result.hasResult()){ if(!result.hasResult()){
LoggerInterface.loggerDB.WARNING("Failed to locate creature template for characterId=" + characterId); LoggerInterface.loggerDB.WARNING("Failed to locate creature template for characterId=" + characterId);
lock.unlock(); lock.unlock();
@ -121,7 +121,7 @@ public class CharacterService extends SignalServiceImpl {
*/ */
public List<Character> getCharacters(int playerId){ public List<Character> getCharacters(int playerId){
lock.lock(); lock.lock();
DatabaseResult result = Globals.dbController.executePreparedQuery("SELECT id, playerId, dataVal FROM charaData WHERE playerId=?;",playerId); DatabaseResult result = Globals.serverState.dbController.executePreparedQuery("SELECT id, playerId, dataVal FROM charaData WHERE playerId=?;",playerId);
List<Character> rVal = new LinkedList<Character>(); List<Character> rVal = new LinkedList<Character>();
if(result.hasResult()){ if(result.hasResult()){
//if we get a valid response from the database, check that it actually matches hashes //if we get a valid response from the database, check that it actually matches hashes
@ -160,7 +160,7 @@ public class CharacterService extends SignalServiceImpl {
String toStore = SerializationUtils.serialize(charaData); String toStore = SerializationUtils.serialize(charaData);
//store a serialization to associate with the character //store a serialization to associate with the character
Globals.dbController.executePreparedStatement( Globals.serverState.dbController.executePreparedStatement(
"UPDATE charaData SET dataVal=? WHERE id=?;", "UPDATE charaData SET dataVal=? WHERE id=?;",
toStore, toStore,
charaData.getId() charaData.getId()
@ -174,7 +174,7 @@ public class CharacterService extends SignalServiceImpl {
*/ */
public List<Character> getAllCharacters(){ public List<Character> getAllCharacters(){
lock.lock(); lock.lock();
DatabaseResult result = Globals.dbController.executePreparedQuery("SELECT id, playerId, dataVal FROM charaData"); DatabaseResult result = Globals.serverState.dbController.executePreparedQuery("SELECT id, playerId, dataVal FROM charaData");
List<Character> rVal = new LinkedList<Character>(); List<Character> rVal = new LinkedList<Character>();
if(result.hasResult()){ if(result.hasResult()){
//if we get a valid response from the database, check that it actually matches hashes //if we get a valid response from the database, check that it actually matches hashes
@ -266,7 +266,7 @@ public class CharacterService extends SignalServiceImpl {
String toStore = SerializationUtils.serialize(chara); String toStore = SerializationUtils.serialize(chara);
//store a serialization to associate with the character //store a serialization to associate with the character
Globals.dbController.executePreparedStatement( Globals.serverState.dbController.executePreparedStatement(
"UPDATE charaData SET dataVal=? WHERE id=?;", "UPDATE charaData SET dataVal=? WHERE id=?;",
toStore, toStore,
chara.getId() chara.getId()

View File

@ -7,7 +7,6 @@ import org.joml.Vector3d;
import electrosphere.test.annotations.UnitTest; import electrosphere.test.annotations.UnitTest;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.server.datacell.Realm; import electrosphere.server.datacell.Realm;
import electrosphere.server.service.CharacterService;
/** /**
* Unit tests for the server entity utils * Unit tests for the server entity utils
@ -18,7 +17,6 @@ public class ServerEntityUtilsUnitTests {
public void destroyEntity_ValidEntity_NoRealm(){ public void destroyEntity_ValidEntity_NoRealm(){
//setup //setup
Globals.initGlobals(); Globals.initGlobals();
Globals.serverState.characterService = (CharacterService)Globals.engineState.serviceManager.registerService(new CharacterService());
Realm realm = Globals.serverState.realmManager.createViewportRealm(new Vector3d(0,0,0), new Vector3d(1,1,1)); Realm realm = Globals.serverState.realmManager.createViewportRealm(new Vector3d(0,0,0), new Vector3d(1,1,1));
Entity entity = EntityCreationUtils.createServerEntity(realm, new Vector3d()); Entity entity = EntityCreationUtils.createServerEntity(realm, new Vector3d());