From 1f4d0aa960029455c7c44e5556104c2febae5fed Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Tue, 12 Jul 2022 04:48:57 +0700 Subject: [PATCH] Change globals to load KF API only in _server --- sources/CoreRealm/Global.uc | 32 --------------- sources/CoreRealm/ServerGlobal.uc | 40 +++++++++++++++++++ .../KF1Frontend/Trading/KF1_Trader.uc | 2 +- sources/ServerLevelCore.uc | 7 ---- 4 files changed, 41 insertions(+), 40 deletions(-) diff --git a/sources/CoreRealm/Global.uc b/sources/CoreRealm/Global.uc index 5195905..d6a03a1 100644 --- a/sources/CoreRealm/Global.uc +++ b/sources/CoreRealm/Global.uc @@ -45,8 +45,6 @@ var public AvariceAPI avarice; var public AcediaEnvironment environment; -var public KFFrontend kf; - public final static function Global GetInstance() { if (default.myself == none) { @@ -80,40 +78,10 @@ protected function Initialize() json = JSONAPI(memory.Allocate(class'JSONAPI')); db = DBAPI(memory.Allocate(class'DBAPI')); avarice = AvariceAPI(memory.Allocate(class'AvariceAPI')); - kf = KFFrontend(memory.Allocate(class'KF1_Frontend')); environment = AcediaEnvironment(memory.Allocate(class'AcediaEnvironment')); class'InfoQueryHandler'.static.StaticConstructor(); } -public final function bool ConnectServerLevelCore() -{ - if (class'ServerLevelCore'.static.GetInstance() == none) { - return false; - } - class'UnrealService'.static.Require(); - class'ConnectionService'.static.Require(); - // TODO: this is hack as fuck, needs to be redone - unreal.mutator.OnMutate( - ServiceAnchor(memory.Allocate(class'ServiceAnchor'))) - .connect = EnableCommandsFeature; - return true; -} - -public function DropGameplayAPI() -{ - memory.Free(kf); - kf = none; -} - -private final function EnableCommandsFeature( - string command, - PlayerController sendingPlayer) -{ - if (command ~= "acediacommands") { - class'Commands_Feature'.static.EmergencyEnable(); - } -} - public function DropCoreAPI() { memory = none; diff --git a/sources/CoreRealm/ServerGlobal.uc b/sources/CoreRealm/ServerGlobal.uc index 933ffa1..0bdd8cc 100644 --- a/sources/CoreRealm/ServerGlobal.uc +++ b/sources/CoreRealm/ServerGlobal.uc @@ -21,10 +21,13 @@ */ class ServerGlobal extends Object; +var protected bool initialized; // `Global` is expected to behave like a singleton and will store it's // main instance in this variable's default value. var protected ServerGlobal myself; +var public KFFrontend kf; + public final static function ServerGlobal GetInstance() { if (default.myself == none) @@ -38,6 +41,43 @@ public final static function ServerGlobal GetInstance() protected function Initialize() { + local Global _; + + if (initialized) { + return; + } + _ = class'Global'.static.GetInstance(); + kf = KFFrontend(_.memory.Allocate(class'KF1_Frontend')); + // TODO: this is hack, needs to be redone later + KF1_HealthComponent(kf.health).PseudoConstructor(); + initialized = true; +} + +public final function bool ConnectServerLevelCore() +{ + local Global _; + + if (class'ServerLevelCore'.static.GetInstance() == none) { + return false; + } + Initialize(); + class'UnrealService'.static.Require(); + class'ConnectionService'.static.Require(); + // TODO: this is hack as fuck, needs to be redone + _ = class'Global'.static.GetInstance(); + _.unreal.mutator.OnMutate( + ServiceAnchor(_.memory.Allocate(class'ServiceAnchor'))) + .connect = EnableCommandsFeature; + return true; +} + +private final function EnableCommandsFeature( + string command, + PlayerController sendingPlayer) +{ + if (command ~= "acediacommands") { + class'Commands_Feature'.static.EmergencyEnable(); + } } defaultproperties diff --git a/sources/Gameplay/KF1Frontend/Trading/KF1_Trader.uc b/sources/Gameplay/KF1Frontend/Trading/KF1_Trader.uc index ad665a3..0897d19 100644 --- a/sources/Gameplay/KF1Frontend/Trading/KF1_Trader.uc +++ b/sources/Gameplay/KF1Frontend/Trading/KF1_Trader.uc @@ -205,7 +205,7 @@ protected function UpdateShopList() local KF1_Trader nextTrader; local array shopVolumes; local array availableTraders; - availableTraders = _.kf.trading.GetTraders(); + availableTraders = _server.kf.trading.GetTraders(); for (i = 0; i < availableTraders.length; i += 1) { nextTrader = KF1_Trader(availableTraders[i]); diff --git a/sources/ServerLevelCore.uc b/sources/ServerLevelCore.uc index dd49b53..8f1a11d 100644 --- a/sources/ServerLevelCore.uc +++ b/sources/ServerLevelCore.uc @@ -18,13 +18,6 @@ */ class ServerLevelCore extends LevelCore; -protected function Constructor() -{ - super.Constructor(); - // TODO: this is hack, needs to be redone later - KF1_HealthComponent(_.kf.health).PseudoConstructor(); -} - public static function LevelCore CreateLevelCore(Actor source) { if (source == none) return none;