You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
196 lines
6.3 KiB
196 lines
6.3 KiB
5 years ago
|
/**
|
||
4 years ago
|
* Main and only Acedia mutator used for loading Acedia packages
|
||
5 years ago
|
* and providing access to mutator events' calls.
|
||
4 years ago
|
* Name is chosen to make config files more readable.
|
||
5 years ago
|
* Copyright 2020 Anton Tarasenko
|
||
|
*------------------------------------------------------------------------------
|
||
|
* This file is part of Acedia.
|
||
|
*
|
||
|
* Acedia is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation, version 3 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* Acedia is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with Acedia. If not, see <https://www.gnu.org/licenses/>.
|
||
|
*/
|
||
4 years ago
|
class Packages extends Mutator
|
||
5 years ago
|
config(Acedia);
|
||
|
|
||
|
// Default value of this variable will be used to store
|
||
|
// reference to the active Acedia mutator,
|
||
|
// as well as to ensure there's only one copy of it.
|
||
|
// We can't use 'Singleton' class for that,
|
||
|
// as we have to derive from 'Mutator'.
|
||
4 years ago
|
var private Packages selfReference;
|
||
5 years ago
|
|
||
4 years ago
|
// Acedia's reference to a `Global` object.
|
||
|
var private Global _;
|
||
|
|
||
|
// Package's manifest is supposed to always have a name of
|
||
|
// "<package_name>.Manifest", this variable stores the ".Manifest" part
|
||
|
var private const string manifestSuffix;
|
||
5 years ago
|
|
||
4 years ago
|
// Array of predefined services that must be started along with Acedia mutator.
|
||
4 years ago
|
var private config array<string> package;
|
||
|
|
||
|
// AcediaCore package that this launcher is build for
|
||
|
var private config const string corePackage;
|
||
5 years ago
|
|
||
4 years ago
|
static public final function Packages GetInstance()
|
||
5 years ago
|
{
|
||
|
return default.selfReference;
|
||
|
}
|
||
|
|
||
|
event PreBeginPlay()
|
||
|
{
|
||
|
// Enforce one copy rule and remember a reference to that copy
|
||
|
if (default.selfReference != none)
|
||
|
{
|
||
|
Destroy();
|
||
|
return;
|
||
|
}
|
||
|
default.selfReference = self;
|
||
4 years ago
|
BootUp();
|
||
|
if (class'TestingService'.default.runTestsOnStartUp) {
|
||
|
RunStartUpTests();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private final function BootUp()
|
||
|
{
|
||
4 years ago
|
local int i;
|
||
|
local class<_manifest> nextManifest;
|
||
|
_ = Spawn(class'Global');
|
||
|
// Load core
|
||
|
nextManifest = LoadManifestClass(corePackage);
|
||
|
if (nextManifest == none)
|
||
|
{
|
||
|
_.logger.Fatal("Cannot load required AcediaCore package \""
|
||
|
$ corePackage $ "\". Acedia will shut down.");
|
||
|
Destroy();
|
||
|
return;
|
||
4 years ago
|
}
|
||
4 years ago
|
LoadManifest(nextManifest);
|
||
|
// Load packages
|
||
|
for (i = 0; i < package.length; i += 1)
|
||
|
{
|
||
|
nextManifest = LoadManifestClass(package[i]);
|
||
|
if (nextManifest == none)
|
||
|
{
|
||
|
_.logger.Failure("Cannot load `Manifest` for package \""
|
||
|
$ package[i] $ "\". Check if it's missing or"
|
||
|
@ "if it's name is spelled incorrectly.");
|
||
|
continue;
|
||
|
}
|
||
|
LoadManifest(nextManifest);
|
||
|
}
|
||
|
// Inject broadcast handler
|
||
5 years ago
|
InjectBroadcastHandler(); // TODO: move this to 'SideEffect' mechanic
|
||
|
}
|
||
|
|
||
4 years ago
|
private final function RunStartUpTests()
|
||
|
{
|
||
|
local TestingService testService;
|
||
|
testService = TestingService(class'TestingService'.static.Require());
|
||
|
testService.PrepareTests();
|
||
|
if (testService.filterTestsByName) {
|
||
|
testService.FilterByName(testService.requiredName);
|
||
|
}
|
||
|
if (testService.filterTestsByGroup) {
|
||
|
testService.FilterByName(testService.requiredGroup);
|
||
|
}
|
||
4 years ago
|
if (testService.Run())
|
||
|
{
|
||
|
// This listener will output test results into server's console
|
||
|
class'TestingListener_AcediaLauncher'.static.SetActive(true);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
_.logger.Failure("Could not launch Acedia's start up testing process.");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private final function class<_manifest> LoadManifestClass(string packageName)
|
||
|
{
|
||
|
return class<_manifest>(DynamicLoadObject( packageName $ manifestSuffix,
|
||
|
class'Class', true));
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
private final function LoadManifest(class<_manifest> manifestClass)
|
||
5 years ago
|
{
|
||
|
local int i;
|
||
4 years ago
|
// Load alias sources
|
||
|
for (i = 0; i < manifestClass.default.aliasSources.length; i += 1)
|
||
5 years ago
|
{
|
||
4 years ago
|
if (manifestClass.default.aliasSources[i] == none) continue;
|
||
|
Spawn(manifestClass.default.aliasSources[i]);
|
||
5 years ago
|
}
|
||
|
// Enable features
|
||
|
for (i = 0; i < manifestClass.default.features.length; i += 1)
|
||
|
{
|
||
|
if (manifestClass.default.features[i] == none) continue;
|
||
4 years ago
|
if (manifestClass.default.features[i].static.IsAutoEnabled()) {
|
||
5 years ago
|
manifestClass.default.features[i].static.EnableMe();
|
||
|
}
|
||
|
}
|
||
4 years ago
|
// Load tests cases
|
||
5 years ago
|
for (i = 0; i < manifestClass.default.testCases.length; i += 1)
|
||
|
{
|
||
4 years ago
|
class'TestingService'.static
|
||
|
.RegisterTestCase(manifestClass.default.testCases[i]);
|
||
5 years ago
|
}
|
||
|
}
|
||
|
|
||
|
private final function InjectBroadcastHandler()
|
||
|
{
|
||
|
local BroadcastHandler ourBroadcastHandler;
|
||
|
if (level == none || level.game == none) return;
|
||
|
|
||
|
ourBroadcastHandler = Spawn(class'BroadcastHandler');
|
||
|
// Swap out level's first handler with ours
|
||
|
// (needs to be done for both actor reference and it's class)
|
||
|
ourBroadcastHandler.nextBroadcastHandler = level.game.broadcastHandler;
|
||
|
ourBroadcastHandler.nextBroadcastHandlerClass = level.game.broadcastClass;
|
||
|
level.game.broadcastHandler = ourBroadcastHandler;
|
||
|
level.game.broadcastClass = class'BroadcastHandler';
|
||
|
}
|
||
|
|
||
|
// Acedia is only able to run in a server mode right now,
|
||
|
// so this function is just a stub.
|
||
|
public final function bool IsServerOnly()
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
// Provide a way to handle CheckReplacement event
|
||
|
function bool CheckReplacement(Actor other, out byte isSuperRelevant)
|
||
|
{
|
||
|
return class'MutatorEvents'.static.
|
||
|
CallCheckReplacement(other, isSuperRelevant);
|
||
|
}
|
||
|
|
||
4 years ago
|
function Mutate(string command, PlayerController sendingController)
|
||
5 years ago
|
{
|
||
4 years ago
|
if (class'MutatorEvents'.static.CallMutate(command, sendingController)) {
|
||
|
super.Mutate(command, sendingController);
|
||
5 years ago
|
}
|
||
|
}
|
||
|
|
||
|
defaultproperties
|
||
|
{
|
||
4 years ago
|
corePackage = "AcediaCore_0_2"
|
||
|
manifestSuffix = ".Manifest"
|
||
5 years ago
|
// This is a server-only mutator
|
||
|
remoteRole = ROLE_None
|
||
|
bAlwaysRelevant = true
|
||
|
// Mutator description
|
||
4 years ago
|
GroupName = "Package loader"
|
||
|
FriendlyName = "Acedia loader"
|
||
|
Description = "Launcher for Acedia packages"
|
||
5 years ago
|
}
|