Skip to content

Commit

Permalink
Merge branch 'serveractors'
Browse files Browse the repository at this point in the history
  • Loading branch information
GenZmeY committed Mar 2, 2023
2 parents 68de02c + 6e04846 commit e2ea9d5
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 7 deletions.
11 changes: 11 additions & 0 deletions SML/Classes/KFGI_Access.uc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class KFGI_Access extends Object within KFGameInfo;

public function bool IsRankedGame()
{
return !IsUnrankedGame();
}

defaultproperties
{

}
36 changes: 36 additions & 0 deletions SML/Classes/Mut.uc
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -53,7 +57,9 @@ private function ModifyLoad()
local String MutatorsRaw;
local String AccessControlRaw;
local Array<String> Mutators;
local int PrevServerActorsCount;
local int Index;
local GameEngine GameEngine;

`Log_Trace();

Expand All @@ -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;
Expand All @@ -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);
Expand Down
153 changes: 146 additions & 7 deletions SML/Classes/SafeMutLoader.uc
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,70 @@ struct CMR
var String Replacement;
};

var private Array<Actor> ServerActors;
var private Array<Actor> ActiveMutators;
var private Array<Actor> ActiveServerActors;
var private Array<CMR> CustomMutReplacements;
var private Array<String> SystemServerActors;
var private config E_LogLevel LogLevel;
var private config Array<String> Mutators;
var private config Array<String> ServerActors;

public function PreBeginPlay()
{
LogLevel = GetLogLevel();

`Log_Trace();

LogLevel = GetLogLevel();
Super.PreBeginPlay();

LoadActors();
LoadMutators();
LoadServerActors();
}

public function PostBeginPlay()
{
local KFGI_Access KFGIA;

`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<Mutator> MutClass;
Expand Down Expand Up @@ -55,11 +102,96 @@ private function LoadActors()
continue;
}

ServerActors.AddItem(ServerActor);
ActiveMutators.AddItem(ServerActor);
`Log_Info("Loaded:" @ MutString);
}
}

private function LoadServerActors()
{
local String ActorString;
local class<Actor> ActorClass;
local Actor ServerActor;

foreach ServerActors(ActorString)
{
ActorClass = class<Actor>(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<Actor> ActorClass;

if (default.SystemServerActors.Find(ServerActor) != INDEX_NONE)
{
return false;
}

ActorClass = class<Actor>(DynamicLoadObject(ServerActor, class'Class'));

if (ActorClass == None)
{
return false;
}

if (ClassIsChildOf(ActorClass, class'Mutator'))
{
return false;
}

if (default.ServerActors.Find(ServerActor) == INDEX_NONE)
{
default.ServerActors.AddItem(ServerActor);
}

return true;
}

public static function bool AddMutator(String MutString)
{
if (GetMutStringReplacement(MutString) != None)
Expand All @@ -79,6 +211,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);
Expand Down Expand Up @@ -111,7 +248,7 @@ public function PostLogin(PlayerController C)
if (C != None)
{
foreach ServerActors(A)
foreach ActiveMutators(A)
{
A.GetTargetLocation(C, false);
}
Expand All @@ -130,7 +267,7 @@ public function OnClientConnectionClose(Player ClientConnection)
C = ClientConnection.Actor;
if (C != None)
{
foreach ServerActors(A)
foreach ActiveMutators(A)
{
A.GetTargetLocation(C, true);
}
Expand Down Expand Up @@ -189,4 +326,6 @@ defaultproperties
Mutator="UnofficialKFPatch.UKFPMutatorNW",
Replacement="UnofficialKFPatch.UKFPReplicationInfo"
)})
SystemServerActors.Add("IpDrv.WebServer")
}

0 comments on commit e2ea9d5

Please sign in to comment.