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 engine flags under engineState
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
String hashedPassword = getHashedString(password);
//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()){
boolean foundRow = false;
//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(!foundRow){
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
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()){
foundRow = false;
//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.script.ScriptEngine;
import electrosphere.server.ServerState;
import electrosphere.server.db.DatabaseController;
import electrosphere.server.entity.poseactor.PoseModel;
import electrosphere.server.service.CharacterService;
import electrosphere.server.service.StructureScanningService;
import electrosphere.util.FileUtils;
/**
@ -98,11 +95,6 @@ public class Globals {
public static ScrollCallback scrollCallback = new ScrollCallback();
public static CursorState cursorState = new CursorState();
//
// Database stuff
//
public static DatabaseController dbController = new DatabaseController();
//
@ -163,7 +155,6 @@ public class Globals {
//services
public static FileWatcherService fileWatcherService;
public static StructureScanningService structureScanningService;
@ -194,7 +185,6 @@ public class Globals {
//server state
Globals.serverState = new ServerState();
Globals.serverState.characterService = (CharacterService)Globals.engineState.serviceManager.registerService(new CharacterService());
//load in default texture map
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.mainThreadSignalService = (MainThreadSignalService)Globals.engineState.serviceManager.registerService(new MainThreadSignalService());
Globals.fileWatcherService = (FileWatcherService)Globals.engineState.serviceManager.registerService(new FileWatcherService());
Globals.structureScanningService = (StructureScanningService)Globals.engineState.serviceManager.registerService(new StructureScanningService());
Globals.engineState.serviceManager.instantiate();
//
//End service manager
@ -383,13 +372,12 @@ public class Globals {
if(Globals.serverState != null){
Globals.serverState.aiManager.shutdown();
Globals.serverState.realmManager.reset();
Globals.serverState.dbController.disconnect();
}
Globals.dbController.disconnect();
Globals.engineState.serviceManager.unloadScene();
Globals.clientState = new ClientState();
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){
Globals.serverState.aiManager.shutdown();
Globals.serverState.realmManager.reset();
Globals.serverState.dbController.disconnect();
}
Globals.dbController.disconnect();
//
//Actual globals to destroy
Globals.assetManager = null;

View File

@ -9,7 +9,6 @@ import electrosphere.engine.signal.Signal.SignalType;
import electrosphere.engine.threads.LabeledThread.ThreadLabel;
import electrosphere.renderer.ui.elements.Window;
import electrosphere.server.ServerState;
import electrosphere.server.service.CharacterService;
/**
* Loading thread that returns the client to the main menu
@ -63,7 +62,6 @@ public class MainMenuLoading {
private static void resetServerState(){
Globals.serverState.server.close();
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
*/
private static void initInMemoryDB(){
Globals.dbController = new DatabaseController();
Globals.dbController.connect(DatabaseController.IN_MEMORY_PATH);
DatabaseUtils.runScript(Globals.dbController,"createTables.sql");
Globals.serverState.dbController.connect(DatabaseController.IN_MEMORY_PATH);
DatabaseUtils.runScript(Globals.serverState.dbController,"createTables.sql");
}
}

View File

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

View File

@ -1,5 +1,6 @@
package electrosphere.server;
import electrosphere.engine.Globals;
import electrosphere.net.server.Server;
import electrosphere.net.server.player.PlayerManager;
import electrosphere.net.synchronization.server.EntityValueTrackingService;
@ -7,8 +8,10 @@ import electrosphere.net.synchronization.server.ServerSynchronizationManager;
import electrosphere.server.ai.AIManager;
import electrosphere.server.datacell.EntityDataCellMapper;
import electrosphere.server.datacell.RealmManager;
import electrosphere.server.db.DatabaseController;
import electrosphere.server.saves.Save;
import electrosphere.server.service.CharacterService;
import electrosphere.server.service.StructureScanningService;
import electrosphere.server.simulation.MicroSimulation;
/**
@ -49,7 +52,12 @@ public class ServerState {
/**
* 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
@ -61,9 +69,22 @@ public class ServerState {
*/
public PlayerManager playerManager = new PlayerManager();
/**
* Database controller
*/
public final DatabaseController dbController = new DatabaseController();
/**
* The micro simulation
*/
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
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);
}

View File

@ -22,15 +22,12 @@ public class DatabaseUtils {
return false;
}
String dbFilePath = sanitizedPath + "/central" + DatabaseController.FILE_EXT;
if(Globals.dbController == null){
Globals.dbController = new DatabaseController();
if(!Globals.serverState.dbController.isConnected()){
Globals.serverState.dbController.connect(dbFilePath);
}
if(!Globals.dbController.isConnected()){
Globals.dbController.connect(dbFilePath);
}
DatabaseUtils.runScript(Globals.dbController,"createTables.sql");
DatabaseUtils.runScript(Globals.serverState.dbController,"createTables.sql");
//both of these are used for arena mode as well as main game
Globals.dbController.disconnect();
Globals.serverState.dbController.disconnect();
return true;
}

View File

@ -39,7 +39,7 @@ public class BlockActions {
String goalBlockEntityId = Item.getBlockTypeId(blockTypeData);
if(CreatureUtils.hasControllerPlayerId(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)){
@ -64,7 +64,7 @@ public class BlockActions {
ServerChargeState.attemptRemoveCharges(creature, 1);
if(CreatureUtils.hasControllerPlayerId(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
String dbFilePath = FileUtils.sanitizeFilePath(dirPath) + "/central" + DatabaseController.FILE_EXT;
Globals.dbController.connect(dbFilePath);
Globals.serverState.dbController.connect(dbFilePath);
return true;
}

View File

@ -69,7 +69,7 @@ public class CharacterService extends SignalServiceImpl {
lock.lock();
Character toStore = new Character(template);
toStore.setPlayerId(playerId);
DatabaseResult result = Globals.dbController.executePreparedQuery(
DatabaseResult result = Globals.serverState.dbController.executePreparedQuery(
"INSERT INTO charaData (playerId,dataVal) VALUES (?,?) RETURNING id;",
playerId,
new Gson().toJson(toStore)
@ -98,7 +98,7 @@ public class CharacterService extends SignalServiceImpl {
return rVal;
}
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()){
LoggerInterface.loggerDB.WARNING("Failed to locate creature template for characterId=" + characterId);
lock.unlock();
@ -121,7 +121,7 @@ public class CharacterService extends SignalServiceImpl {
*/
public List<Character> getCharacters(int playerId){
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>();
if(result.hasResult()){
//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);
//store a serialization to associate with the character
Globals.dbController.executePreparedStatement(
Globals.serverState.dbController.executePreparedStatement(
"UPDATE charaData SET dataVal=? WHERE id=?;",
toStore,
charaData.getId()
@ -174,7 +174,7 @@ public class CharacterService extends SignalServiceImpl {
*/
public List<Character> getAllCharacters(){
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>();
if(result.hasResult()){
//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);
//store a serialization to associate with the character
Globals.dbController.executePreparedStatement(
Globals.serverState.dbController.executePreparedStatement(
"UPDATE charaData SET dataVal=? WHERE id=?;",
toStore,
chara.getId()

View File

@ -7,7 +7,6 @@ import org.joml.Vector3d;
import electrosphere.test.annotations.UnitTest;
import electrosphere.engine.Globals;
import electrosphere.server.datacell.Realm;
import electrosphere.server.service.CharacterService;
/**
* Unit tests for the server entity utils
@ -18,7 +17,6 @@ public class ServerEntityUtilsUnitTests {
public void destroyEntity_ValidEntity_NoRealm(){
//setup
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));
Entity entity = EntityCreationUtils.createServerEntity(realm, new Vector3d());