8 Plugin Development
RaidMax edited this page 2023-05-20 22:14:17 -05:00

You can extend the functionality of IW4MAdmin by writing your own plugins.

NuGet Package

The NuGet package for IW4MAdmin's "Shared Library" can be obtained from the NuGet Gallery Referencing this package will give you the ability to write plugins against IW4MAdmin's core library.

Code

IW4MAdmin's functionality can be extended by writing additional plugins in C#.
Each class library must implement the IPluginV2 interface.
See the existing plugins for examples.

JavaScript

IW4MAdmin functionality can also be extended using JavaScript. The JavaScript parser supports these ECMA Features. JavaScript plugins use C# classes behind the scenes and as such there is interop between the C# backing.

Plugin Object Template

In order to be properly parsed by the JavaScript engine, every plugin must conform to the following template.

const init = (registerNotify, serviceResolver, config) => {
    return plugin;
};

const plugin = {
    author: 'Author',
    version: '1.0',
    name: 'PluginName'
}

const commands = [];

Template Example/Breakdown

const init = (registerNotify, serviceResolver, config) => {
    registerNotify('IManagementEventSubscriptions.ClientStateInitialized', (clientEvent, _) => plugin.onClientEnteredMatch(clientEvent));
    plugin.onLoad(serviceResolver, config);
    return plugin;
};
Arguments
Name Description
registerNotify Helper to subscribe to events
serviceResolver IScriptPluginServiceResolver
config ScriptPluginConfigurationWrapper
registerNotify event sources

IManagementEventSubscriptions
IGameServerEventSubscriptions
IGameEventSubscriptions


const plugin = {
    author: 'Raidmax',
    version: '1.0',
    name: 'Example PLugin',
    eventManager: null,
    onLoad: function(serviceResolver, config) {
        // use pseudo dependency injection to get IManager
	    this.eventManager = serviceResolver.resolveService('IManager');
    },
    requestExecuteCommand: function(command, server) {
	    const serverEvents = importNamespace('SharedLibraryCore.Events.Server');
        const requestEvent = new serverEvents.ServerCommandExecuteRequested(command, server);
        requestEvent.timeoutMs = 2000;
        requestEvent.source = this.name;

        // queue our request on the event manager
	    this.eventManager.queueEvent(requestEvent);
    }
}

IManager
ServerCommandExecuteRequested
IPluginV2


const commands = [{
    name: 'example',
    description: 'executes example command',
    alias: 'ex',
    permission: 'User',
    targetRequired: false,
    arguments: [],
    execute: (gameEvent) => {
        plugin.requestExecuteCommand('example', gameEvent.owner);
    }
}];

IManagerCommand
Permission
GameEvent


Live Reloading

Thanks to JavaScript's flexibility and parsability, the plugin importer scans the plugins folder and reloads the JavaScript plugins on demand as they're modified. This allows faster development/testing/debugging.

Additional Examples