From 4367cd2b15c480041d625cc168a8783adac9bacc Mon Sep 17 00:00:00 2001 From: GenZmeY Date: Thu, 2 Mar 2023 03:01:14 +0300 Subject: [PATCH 1/3] add server actors support --- SML/Classes/KFGI_Access.uc | 11 +++ SML/Classes/Mut.uc | 36 +++++++++ SML/Classes/SafeMutLoader.uc | 141 +++++++++++++++++++++++++++++++++-- 3 files changed, 181 insertions(+), 7 deletions(-) create mode 100644 SML/Classes/KFGI_Access.uc diff --git a/SML/Classes/KFGI_Access.uc b/SML/Classes/KFGI_Access.uc new file mode 100644 index 0000000..84c1ab6 --- /dev/null +++ b/SML/Classes/KFGI_Access.uc @@ -0,0 +1,11 @@ +class KFGI_Access extends Object within KFGameInfo; + +public function bool IsRankedGame() +{ + return !IsUnrankedGame(); +} + +defaultproperties +{ + +} diff --git a/SML/Classes/Mut.uc b/SML/Classes/Mut.uc index 8fd6fb0..02a86b8 100644 --- a/SML/Classes/Mut.uc +++ b/SML/Classes/Mut.uc @@ -32,9 +32,13 @@ public function AddMutator(Mutator Mut) if (CorrectLoadOrder() || Mut == Self) return; if (Mut.Class == Class) + { Mut.Destroy(); + } else + { Super.AddMutator(Mut); + } } private function bool CorrectLoadOrder() @@ -53,7 +57,9 @@ private function ModifyLoad() local String MutatorsRaw; local String AccessControlRaw; local Array Mutators; + local int PrevServerActorsCount; local int Index; + local GameEngine GameEngine; `Log_Trace(); @@ -66,6 +72,7 @@ private function ModifyLoad() LoadURL = Repl(LoadURL, Subst(OptAC) $ AccessControlRaw, ""); SML.static.ClearMutators(); + SML.static.ClearServerActors(); ParseStringIntoArray(MutatorsRaw, Mutators, ",", true); Index = 0; @@ -81,6 +88,35 @@ private function ModifyLoad() ++Index; } } + + GameEngine = GameEngine(Class'Engine'.static.GetEngine()); + if (GameEngine == None) + { + `Log_Error("GameEngine is None, skip loading server actors"); + } + else + { + PrevServerActorsCount = GameEngine.ServerActors.Length; + + Index = 0; + while (Index < GameEngine.ServerActors.Length) + { + if (SML.static.AddServerActor(GameEngine.ServerActors[Index])) + { + GameEngine.ServerActors.Remove(Index, 1); + } + else + { + ++Index; + } + } + + if (GameEngine.ServerActors.Length != PrevServerActorsCount) + { + GameEngine.SaveConfig(); + } + } + SML.static.StaticSaveConfig(); JoinArray(Mutators, MutatorsRaw); diff --git a/SML/Classes/SafeMutLoader.uc b/SML/Classes/SafeMutLoader.uc index d645c52..aaed52b 100644 --- a/SML/Classes/SafeMutLoader.uc +++ b/SML/Classes/SafeMutLoader.uc @@ -7,23 +7,69 @@ struct CMR var String Replacement; }; -var private Array ServerActors; +var private Array ActiveMutators; +var private Array ActiveServerActors; var private Array CustomMutReplacements; var private config E_LogLevel LogLevel; var private config Array Mutators; +var private config Array ServerActors; public function PreBeginPlay() { + LogLevel = GetLogLevel(); + `Log_Trace(); - LogLevel = GetLogLevel(); + Super.PreBeginPlay(); + + LoadMutators(); + LoadServerActors(); +} + +public function PostBeginPlay() +{ + local KFGI_Access KFGIA; - LoadActors(); + `Log_Trace(); Super.PreBeginPlay(); + + RestoreServerActors(); + + KFGIA = GetKFGIA(); + if (KFGIA == None) + { + `Log_Error("Can't check ranked status"); + } + else if (KFGIA.IsRankedGame()) + { + `Log_Info("Mutators and server actors successfully loaded! Your server is RANKED!"); + } + else + { + `Log_Warn("Your server is UNRANKED! Check the mutators and server actors you are using. Maybe some of them are incompatible with SML"); + } } -private function LoadActors() +private function KFGI_Access GetKFGIA() +{ + local KFGameInfo KFGI; + + if (WorldInfo == None || WorldInfo.Game == None) + { + return None; + } + + KFGI = KFGameInfo(WorldInfo.Game); + if (KFGI == None) + { + return None; + } + + return new(KFGI) class'KFGI_Access'; +} + +private function LoadMutators() { local String MutString; local class MutClass; @@ -55,11 +101,87 @@ private function LoadActors() continue; } - ServerActors.AddItem(ServerActor); + ActiveMutators.AddItem(ServerActor); `Log_Info("Loaded:" @ MutString); } } +private function LoadServerActors() +{ + local String ActorString; + local class ActorClass; + local Actor ServerActor; + + foreach ServerActors(ActorString) + { + ActorClass = class(DynamicLoadObject(ActorString, class'Class')); + if (ActorClass == None) + { + `Log_Error("Can't load server actor:" @ ActorString); + continue; + } + + ServerActor = WorldInfo.Spawn(ActorClass); + if (ServerActor == None) + { + `Log_Error("Can't spawn:" @ ActorString); + continue; + } + + ActiveServerActors.AddItem(ServerActor); + `Log_Info("Loaded:" @ ActorString); + } +} + +private function RestoreServerActors() +{ + local GameEngine GameEngine; + local String ActorString; + local int PrevServerActorsCount; + + GameEngine = GameEngine(Class'Engine'.static.GetEngine()); + + if (GameEngine == None) + { + `Log_Error("GameEngine is None! Can't restore ServerActors!"); + return; + } + + PrevServerActorsCount = GameEngine.ServerActors.Length; + foreach ServerActors(ActorString) + { + if (GameEngine.ServerActors.Find(ActorString) != INDEX_NONE) + { + GameEngine.ServerActors.AddItem(ActorString); + } + } + + if (GameEngine.ServerActors.Length != PrevServerActorsCount) + { + GameEngine.SaveConfig(); + } +} + +public static function bool AddServerActor(String ServerActor) +{ + local class ActorClass; + + ActorClass = class(DynamicLoadObject(ServerActor, class'Class')); + + if (ActorClass == None) + { + return false; + } + + if (ClassIsChildOf(ActorClass, class'Mutator')) + { + return false; + } + + default.ServerActors.AddItem(ServerActor); + return true; +} + public static function bool AddMutator(String MutString) { if (GetMutStringReplacement(MutString) != None) @@ -79,6 +201,11 @@ public static function ClearMutators() default.Mutators.Length = 0; } +public static function ClearServerActors() +{ + default.ServerActors.Length = 0; +} + public static function bool WantsToSpawn() { return (default.Mutators.Length > 0); @@ -111,7 +238,7 @@ public function PostLogin(PlayerController C) if (C != None) { - foreach ServerActors(A) + foreach ActiveMutators(A) { A.GetTargetLocation(C, false); } @@ -130,7 +257,7 @@ public function OnClientConnectionClose(Player ClientConnection) C = ClientConnection.Actor; if (C != None) { - foreach ServerActors(A) + foreach ActiveMutators(A) { A.GetTargetLocation(C, true); } From 62f3421cb11828d59a826bfea9a0d4b193169bbd Mon Sep 17 00:00:00 2001 From: GenZmeY Date: Thu, 2 Mar 2023 03:33:50 +0300 Subject: [PATCH 2/3] fix webadmin --- SML/Classes/SafeMutLoader.uc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/SML/Classes/SafeMutLoader.uc b/SML/Classes/SafeMutLoader.uc index aaed52b..c372909 100644 --- a/SML/Classes/SafeMutLoader.uc +++ b/SML/Classes/SafeMutLoader.uc @@ -10,6 +10,7 @@ struct CMR var private Array ActiveMutators; var private Array ActiveServerActors; var private Array CustomMutReplacements; +var private Array SystemServerActors; var private config E_LogLevel LogLevel; var private config Array Mutators; var private config Array ServerActors; @@ -166,6 +167,11 @@ public static function bool AddServerActor(String ServerActor) { local class ActorClass; + if (default.SystemServerActors.Find(ServerActor) != INDEX_NONE) + { + return false; + } + ActorClass = class(DynamicLoadObject(ServerActor, class'Class')); if (ActorClass == None) @@ -316,4 +322,6 @@ defaultproperties Mutator="UnofficialKFPatch.UKFPMutatorNW", Replacement="UnofficialKFPatch.UKFPReplicationInfo" )}) + + SystemServerActors.Add("IpDrv.WebServer") } \ No newline at end of file From 6e048463f6327dd8b679faf2483caf235a5b616e Mon Sep 17 00:00:00 2001 From: GenZmeY Date: Thu, 2 Mar 2023 05:07:19 +0300 Subject: [PATCH 3/3] dont add server actor twice --- SML/Classes/SafeMutLoader.uc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/SML/Classes/SafeMutLoader.uc b/SML/Classes/SafeMutLoader.uc index c372909..6162628 100644 --- a/SML/Classes/SafeMutLoader.uc +++ b/SML/Classes/SafeMutLoader.uc @@ -184,7 +184,11 @@ public static function bool AddServerActor(String ServerActor) return false; } - default.ServerActors.AddItem(ServerActor); + if (default.ServerActors.Find(ServerActor) == INDEX_NONE) + { + default.ServerActors.AddItem(ServerActor); + } + return true; }