Compare commits
2 Commits
2022.02.08
...
2022.02.09
Author | SHA1 | Date | |
---|---|---|---|
aa6ae0ab8d | |||
12dfd8c558 |
@ -311,9 +311,9 @@ namespace IW4MAdmin.Application
|
|||||||
}
|
}
|
||||||
|
|
||||||
// register any script plugins
|
// register any script plugins
|
||||||
foreach (var func in pluginImporter.DiscoverScriptPlugins())
|
foreach (var plugin in pluginImporter.DiscoverScriptPlugins())
|
||||||
{
|
{
|
||||||
serviceCollection.AddSingleton(sp => func(sp));
|
serviceCollection.AddSingleton(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
// register any eventable types
|
// register any eventable types
|
||||||
|
@ -38,13 +38,13 @@ namespace IW4MAdmin.Application.Misc
|
|||||||
/// discovers all the script plugins in the plugins dir
|
/// discovers all the script plugins in the plugins dir
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public IEnumerable<Func<IServiceProvider, IPlugin>> DiscoverScriptPlugins()
|
public IEnumerable<IPlugin> DiscoverScriptPlugins()
|
||||||
{
|
{
|
||||||
var pluginDir = $"{Utilities.OperatingDirectory}{PLUGIN_DIR}{Path.DirectorySeparatorChar}";
|
var pluginDir = $"{Utilities.OperatingDirectory}{PLUGIN_DIR}{Path.DirectorySeparatorChar}";
|
||||||
|
|
||||||
if (!Directory.Exists(pluginDir))
|
if (!Directory.Exists(pluginDir))
|
||||||
{
|
{
|
||||||
return Enumerable.Empty<Func<IServiceProvider, IPlugin>>();
|
return Enumerable.Empty<IPlugin>();
|
||||||
}
|
}
|
||||||
|
|
||||||
var scriptPluginFiles =
|
var scriptPluginFiles =
|
||||||
@ -52,11 +52,10 @@ namespace IW4MAdmin.Application.Misc
|
|||||||
|
|
||||||
_logger.LogDebug("Discovered {count} potential script plugins", scriptPluginFiles.Count);
|
_logger.LogDebug("Discovered {count} potential script plugins", scriptPluginFiles.Count);
|
||||||
|
|
||||||
return scriptPluginFiles.Select<string, Func<IServiceProvider, IPlugin>>(fileName => serviceProvider =>
|
return scriptPluginFiles.Select(fileName =>
|
||||||
{
|
{
|
||||||
_logger.LogDebug("Discovered script plugin {fileName}", fileName);
|
_logger.LogDebug("Discovered script plugin {fileName}", fileName);
|
||||||
return new ScriptPlugin(_logger,
|
return new ScriptPlugin(_logger, fileName);
|
||||||
serviceProvider.GetRequiredService<IScriptPluginTimerHelper>(), fileName);
|
|
||||||
}).ToList();
|
}).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,9 +45,8 @@ namespace IW4MAdmin.Application.Misc
|
|||||||
private bool _successfullyLoaded;
|
private bool _successfullyLoaded;
|
||||||
private readonly List<string> _registeredCommandNames;
|
private readonly List<string> _registeredCommandNames;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IScriptPluginTimerHelper _timerHelper;
|
|
||||||
|
|
||||||
public ScriptPlugin(ILogger logger, IScriptPluginTimerHelper timerHelper, string filename, string workingDirectory = null)
|
public ScriptPlugin(ILogger logger, string filename, string workingDirectory = null)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_fileName = filename;
|
_fileName = filename;
|
||||||
@ -60,8 +59,6 @@ namespace IW4MAdmin.Application.Misc
|
|||||||
|
|
||||||
Watcher.EnableRaisingEvents = true;
|
Watcher.EnableRaisingEvents = true;
|
||||||
_registeredCommandNames = new List<string>();
|
_registeredCommandNames = new List<string>();
|
||||||
_timerHelper = timerHelper;
|
|
||||||
_timerHelper.SetDependency(_onProcessing);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~ScriptPlugin()
|
~ScriptPlugin()
|
||||||
@ -127,6 +124,7 @@ namespace IW4MAdmin.Application.Misc
|
|||||||
_scriptEngine.Execute(script);
|
_scriptEngine.Execute(script);
|
||||||
_scriptEngine.SetValue("_localization", Utilities.CurrentLocalization);
|
_scriptEngine.SetValue("_localization", Utilities.CurrentLocalization);
|
||||||
_scriptEngine.SetValue("_serviceResolver", serviceResolver);
|
_scriptEngine.SetValue("_serviceResolver", serviceResolver);
|
||||||
|
_scriptEngine.SetValue("_lock", _onProcessing);
|
||||||
dynamic pluginObject = _scriptEngine.Evaluate("plugin").ToObject();
|
dynamic pluginObject = _scriptEngine.Evaluate("plugin").ToObject();
|
||||||
|
|
||||||
Author = pluginObject.author;
|
Author = pluginObject.author;
|
||||||
@ -276,7 +274,6 @@ namespace IW4MAdmin.Application.Misc
|
|||||||
{
|
{
|
||||||
_logger.LogDebug("OnLoad executing for {Name}", Name);
|
_logger.LogDebug("OnLoad executing for {Name}", Name);
|
||||||
_scriptEngine.SetValue("_manager", manager);
|
_scriptEngine.SetValue("_manager", manager);
|
||||||
_scriptEngine.SetValue("_timerHelper", _timerHelper);
|
|
||||||
_scriptEngine.Evaluate("plugin.onLoadAsync(_manager)");
|
_scriptEngine.Evaluate("plugin.onLoadAsync(_manager)");
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
|
@ -120,7 +120,7 @@ public class ScriptPluginTimerHelper : IScriptPluginTimerHelper
|
|||||||
{
|
{
|
||||||
if (!_onRunningTick.IsSet)
|
if (!_onRunningTick.IsSet)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Previous {OnTick} is still running, so we are skipping this one",
|
_logger.LogDebug("Previous {OnTick} is still running, so we are skipping this one",
|
||||||
nameof(OnTick));
|
nameof(OnTick));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -129,7 +129,9 @@ public class ScriptPluginTimerHelper : IScriptPluginTimerHelper
|
|||||||
|
|
||||||
// the js engine is not thread safe so we need to ensure we're not executing OnTick and OnEventAsync simultaneously
|
// the js engine is not thread safe so we need to ensure we're not executing OnTick and OnEventAsync simultaneously
|
||||||
_onDependentAction?.WaitAsync().Wait();
|
_onDependentAction?.WaitAsync().Wait();
|
||||||
|
var start = DateTime.Now;
|
||||||
_jsAction.DynamicInvoke(JsValue.Undefined, new[] { JsValue.Undefined });
|
_jsAction.DynamicInvoke(JsValue.Undefined, new[] { JsValue.Undefined });
|
||||||
|
_logger.LogDebug("OnTick took {Time}ms", (DateTime.Now - start).TotalMilliseconds);
|
||||||
ReleaseThreads();
|
ReleaseThreads();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ namespace IW4MAdmin.Application.RConParsers
|
|||||||
public string NoticeLineSeparator { get; set; } = Environment.NewLine;
|
public string NoticeLineSeparator { get; set; } = Environment.NewLine;
|
||||||
public int? DefaultRConPort { get; set; }
|
public int? DefaultRConPort { get; set; }
|
||||||
public string DefaultInstallationDirectoryHint { get; set; }
|
public string DefaultInstallationDirectoryHint { get; set; }
|
||||||
|
public short FloodProtectInterval { get; set; } = 750;
|
||||||
|
|
||||||
public ColorCodeMapping ColorCodeMapping { get; set; } = new ColorCodeMapping
|
public ColorCodeMapping ColorCodeMapping { get; set; } = new ColorCodeMapping
|
||||||
{
|
{
|
||||||
@ -59,4 +60,4 @@ namespace IW4MAdmin.Application.RConParsers
|
|||||||
MaxPlayersStatus = parserRegexFactory.CreateParserRegex();
|
MaxPlayersStatus = parserRegexFactory.CreateParserRegex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
#include common_scripts\utility;
|
|
||||||
#include maps\mp\_utility;
|
|
||||||
#include maps\mp\gametypes\_hud_util;
|
|
||||||
#include maps\mp\gametypes\_playerlogic;
|
|
||||||
|
|
||||||
init()
|
|
||||||
{
|
|
||||||
SetDvarIfUninitialized( "sv_iw4madmin_command", "" );
|
|
||||||
level thread WaitForCommand();
|
|
||||||
}
|
|
||||||
|
|
||||||
WaitForCommand()
|
|
||||||
{
|
|
||||||
level endon( "game_ended" );
|
|
||||||
|
|
||||||
for(;;)
|
|
||||||
{
|
|
||||||
commandInfo = strtok( getDvar("sv_iw4madmin_command"), ";" );
|
|
||||||
command = commandInfo[0];
|
|
||||||
|
|
||||||
switch( command )
|
|
||||||
{
|
|
||||||
case "alert":
|
|
||||||
//clientId alertType sound message
|
|
||||||
SendAlert( commandInfo[1], commandInfo[2], commandInfo[3], commandInfo[4] );
|
|
||||||
break;
|
|
||||||
case "killplayer":
|
|
||||||
// clientId
|
|
||||||
KillPlayer( commandInfo[1], commandInfo[2] );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
setDvar( "sv_iw4madmin_command", "" );
|
|
||||||
wait( 1 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SendAlert( clientId, alertType, sound, message )
|
|
||||||
{
|
|
||||||
client = getPlayerFromClientNum( int( clientId ) );
|
|
||||||
client thread playLeaderDialogOnPlayer( sound, client.team );
|
|
||||||
client playLocalSound( sound );
|
|
||||||
client iPrintLnBold( "^1" + alertType + ": ^3" + message );
|
|
||||||
}
|
|
||||||
|
|
||||||
KillPlayer( targetId, originId)
|
|
||||||
{
|
|
||||||
target = getPlayerFromClientNum( int( targetId ) );
|
|
||||||
target suicide();
|
|
||||||
origin = getPlayerFromClientNum( int( originId ) );
|
|
||||||
|
|
||||||
iPrintLnBold("^1" + origin.name + " ^7killed ^5" + target.name);
|
|
||||||
}
|
|
414
GameFiles/IW4x/userraw/scripts/_integration.gsc
Normal file
414
GameFiles/IW4x/userraw/scripts/_integration.gsc
Normal file
@ -0,0 +1,414 @@
|
|||||||
|
#include common_scripts\utility;
|
||||||
|
#include maps\mp\_utility;
|
||||||
|
#include maps\mp\gametypes\_hud_util;
|
||||||
|
#include maps\mp\gametypes\_playerlogic;
|
||||||
|
|
||||||
|
init()
|
||||||
|
{
|
||||||
|
// setup default vars
|
||||||
|
level.eventBus = spawnstruct();
|
||||||
|
level.eventBus.inVar = "sv_iw4madmin_in";
|
||||||
|
level.eventBus.outVar = "sv_iw4madmin_out";
|
||||||
|
level.eventBus.failKey = "fail";
|
||||||
|
level.eventBus.timeoutKey = "timeout";
|
||||||
|
level.eventBus.timeout = 10;
|
||||||
|
|
||||||
|
level.clientDataKey = "clientData";
|
||||||
|
|
||||||
|
level.eventTypes = spawnstruct();
|
||||||
|
level.eventTypes.clientDataReceived = "ClientDataReceived";
|
||||||
|
level.eventTypes.clientDataRequested = "ClientDataRequested";
|
||||||
|
level.eventTypes.executeCommandRequested = "ExecuteCommandRequested";
|
||||||
|
|
||||||
|
SetDvarIfUninitialized( level.eventBus.inVar, "" );
|
||||||
|
SetDvarIfUninitialized( level.eventBus.outVar, "" );
|
||||||
|
SetDvarIfUninitialized( "sv_iw4madmin_integration_enabled", 1 );
|
||||||
|
SetDvarIfUninitialized( "sv_iw4madmin_integration_debug", 0 );
|
||||||
|
|
||||||
|
// map the event type to the handler
|
||||||
|
level.eventCallbacks = [];
|
||||||
|
level.eventCallbacks[level.eventTypes.clientDataReceived] = ::OnClientDataReceived;
|
||||||
|
level.eventCallbacks[level.eventTypes.executeCommandRequested] = ::OnExecuteCommand;
|
||||||
|
|
||||||
|
// start long running tasks
|
||||||
|
level thread PlayerWaitEvents();
|
||||||
|
level thread MonitorBus();
|
||||||
|
level thread OnPlayerConnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////
|
||||||
|
// Client Methods
|
||||||
|
//////////////////////////////////
|
||||||
|
|
||||||
|
OnPlayerConnect()
|
||||||
|
{
|
||||||
|
level endon ( "disconnect" );
|
||||||
|
|
||||||
|
for ( ;; )
|
||||||
|
{
|
||||||
|
level waittill( "connected", player );
|
||||||
|
|
||||||
|
level.iw4adminIntegrationDebug = GetDvarInt( "sv_iw4madmin_integration_debug" );
|
||||||
|
|
||||||
|
if ( !isDefined( player.pers[level.clientDataKey] ) )
|
||||||
|
{
|
||||||
|
player.pers[level.clientDataKey] = spawnstruct();
|
||||||
|
}
|
||||||
|
|
||||||
|
player thread OnPlayerSpawned();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
OnPlayerSpawned()
|
||||||
|
{
|
||||||
|
self endon( "disconnect" );
|
||||||
|
|
||||||
|
for ( ;; )
|
||||||
|
{
|
||||||
|
self waittill( "spawned_player" );
|
||||||
|
self PlayerConnectEvents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DisplayWelcomeData()
|
||||||
|
{
|
||||||
|
self endon( "disconnect" );
|
||||||
|
|
||||||
|
clientData = self.pers[level.clientDataKey];
|
||||||
|
|
||||||
|
if ( clientData.permissionLevel != "User" )
|
||||||
|
{
|
||||||
|
self IPrintLnBold( "Welcome, your level is ^5" + clientData.permissionLevel );
|
||||||
|
}
|
||||||
|
wait (2.0);
|
||||||
|
self IPrintLnBold( "You were last seen ^5" + clientData.lastConnection );
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerConnectEvents()
|
||||||
|
{
|
||||||
|
self endon( "disconnect" );
|
||||||
|
|
||||||
|
clientData = self.pers[level.clientDataKey];
|
||||||
|
|
||||||
|
// this gives IW4MAdmin some time to register the player before making the request;
|
||||||
|
wait ( 2 );
|
||||||
|
|
||||||
|
if ( isDefined( clientData.state ) && clientData.state == "complete" )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self RequestClientBasicData();
|
||||||
|
// example of requesting meta from IW4MAdmin
|
||||||
|
// self RequestClientMeta( "LastServerPlayed" );
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerWaitEvents()
|
||||||
|
{
|
||||||
|
level endon( "game_ended" );
|
||||||
|
self endon( "disconnect" );
|
||||||
|
|
||||||
|
for ( ;; )
|
||||||
|
{
|
||||||
|
level waittill( "client_event", client );
|
||||||
|
|
||||||
|
if ( level.iw4adminIntegrationDebug == 1 )
|
||||||
|
{
|
||||||
|
self IPrintLn( "Processing Event " + client.event.type + "-" + client.event.subtype );
|
||||||
|
}
|
||||||
|
|
||||||
|
eventHandler = level.eventCallbacks[client.event.type];
|
||||||
|
|
||||||
|
if ( isDefined( eventHandler ) )
|
||||||
|
{
|
||||||
|
client [[eventHandler]]( client.event );
|
||||||
|
}
|
||||||
|
|
||||||
|
client.eventData = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////
|
||||||
|
// Helper Methods
|
||||||
|
//////////////////////////////////
|
||||||
|
|
||||||
|
RequestClientMeta( metaKey )
|
||||||
|
{
|
||||||
|
getClientMetaEvent = BuildEventRequest( true, level.eventTypes.clientDataRequested, "Meta", self, metaKey );
|
||||||
|
self thread QueueEvent( getClientMetaEvent, level.eventTypes.clientDataRequested );
|
||||||
|
}
|
||||||
|
|
||||||
|
RequestClientBasicData()
|
||||||
|
{
|
||||||
|
getClientDataEvent = BuildEventRequest( true, level.eventTypes.clientDataRequested, "None", self, "" );
|
||||||
|
self thread QueueEvent( getClientDataEvent, level.eventTypes.clientDataRequested );
|
||||||
|
}
|
||||||
|
|
||||||
|
BuildEventRequest( responseExpected, eventType, eventSubtype, client, data )
|
||||||
|
{
|
||||||
|
if ( !isDefined( data ) )
|
||||||
|
{
|
||||||
|
data = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !isDefined( eventSubtype ) )
|
||||||
|
{
|
||||||
|
eventSubtype = "None";
|
||||||
|
}
|
||||||
|
|
||||||
|
request = "0";
|
||||||
|
|
||||||
|
if ( responseExpected )
|
||||||
|
{
|
||||||
|
request = "1";
|
||||||
|
}
|
||||||
|
|
||||||
|
request = request + ";" + eventType + ";" + eventSubtype + ";" + client getEntityNumber() + ";" + data;
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
MonitorBus()
|
||||||
|
{
|
||||||
|
level endon( "game_ended" );
|
||||||
|
|
||||||
|
for( ;; )
|
||||||
|
{
|
||||||
|
wait ( 0.25 );
|
||||||
|
|
||||||
|
// check to see if IW4MAdmin is ready to receive more data
|
||||||
|
if ( getDvar( level.eventBus.inVar ) == "" )
|
||||||
|
{
|
||||||
|
level notify( "bus_ready" );
|
||||||
|
}
|
||||||
|
|
||||||
|
eventString = getDvar( level.eventBus.outVar );
|
||||||
|
|
||||||
|
if ( eventString == "" )
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( level.iw4adminIntegrationDebug == 1 )
|
||||||
|
{
|
||||||
|
IPrintLn( "-> " + eventString );
|
||||||
|
}
|
||||||
|
|
||||||
|
NotifyClientEvent( strtok( eventString, ";" ) );
|
||||||
|
|
||||||
|
SetDvar( level.eventBus.outVar, "" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QueueEvent( request, eventType )
|
||||||
|
{
|
||||||
|
self endon( "disconnect" );
|
||||||
|
|
||||||
|
start = GetTime();
|
||||||
|
maxWait = level.eventBus.timeout * 1000; // 10 seconds
|
||||||
|
timedOut = "";
|
||||||
|
|
||||||
|
while ( GetDvar( level.eventBus.inVar ) != "" && ( GetTime() - start ) < maxWait )
|
||||||
|
{
|
||||||
|
level waittill_notify_or_timeout( "bus_ready", 1 );
|
||||||
|
|
||||||
|
if ( GetDvar( level.eventBus.inVar ) != "" )
|
||||||
|
{
|
||||||
|
if ( level.iw4adminIntegrationDebug == 1 )
|
||||||
|
{
|
||||||
|
self IPrintLn( "A request is already in progress..." );
|
||||||
|
}
|
||||||
|
timedOut = "set";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
timedOut = "unset";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( timedOut == "set")
|
||||||
|
{
|
||||||
|
if ( level.iw4adminIntegrationDebug == 1 )
|
||||||
|
{
|
||||||
|
self IPrintLn( "Timed out waiting for response..." );
|
||||||
|
}
|
||||||
|
|
||||||
|
NotifyClientEventTimeout( eventType );
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( level.iw4adminIntegrationDebug == 1 )
|
||||||
|
{
|
||||||
|
IPrintLn("<- " + request);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetDvar( level.eventBus.inVar, request );
|
||||||
|
}
|
||||||
|
|
||||||
|
ParseDataString( data )
|
||||||
|
{
|
||||||
|
dataParts = strtok( data, "|" );
|
||||||
|
dict = [];
|
||||||
|
|
||||||
|
counter = 0;
|
||||||
|
foreach ( part in dataParts )
|
||||||
|
{
|
||||||
|
splitPart = strtok( part, "=" );
|
||||||
|
key = splitPart[0];
|
||||||
|
value = splitPart[1];
|
||||||
|
dict[key] = value;
|
||||||
|
dict[counter] = key;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dict;
|
||||||
|
}
|
||||||
|
|
||||||
|
NotifyClientEventTimeout( eventType )
|
||||||
|
{
|
||||||
|
// todo: make this actual eventing
|
||||||
|
if ( eventType == level.eventTypes.clientDataRequested )
|
||||||
|
{
|
||||||
|
self.pers["clientData"].state = level.eventBus.timeoutKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NotifyClientEvent( eventInfo )
|
||||||
|
{
|
||||||
|
client = getPlayerFromClientNum( int( eventInfo[3] ) );
|
||||||
|
|
||||||
|
event = spawnstruct();
|
||||||
|
event.type = eventInfo[1];
|
||||||
|
event.subtype = eventInfo[2];
|
||||||
|
event.data = eventInfo[4];
|
||||||
|
|
||||||
|
if ( level.iw4adminIntegrationDebug == 1 )
|
||||||
|
{
|
||||||
|
IPrintLn(event.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
client.event = event;
|
||||||
|
|
||||||
|
level notify( "client_event", client );
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////
|
||||||
|
// Event Handlers
|
||||||
|
/////////////////////////////////
|
||||||
|
|
||||||
|
OnClientDataReceived( event )
|
||||||
|
{
|
||||||
|
event.data = ParseDataString( event.data );
|
||||||
|
clientData = self.pers[level.clientDataKey];
|
||||||
|
|
||||||
|
if ( event.subtype == "Fail" )
|
||||||
|
{
|
||||||
|
if ( level.iw4adminIntegrationDebug == 1 )
|
||||||
|
{
|
||||||
|
IPrintLn( "Received fail response" );
|
||||||
|
}
|
||||||
|
clientData.state = level.eventBus.failKey;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( event.subtype == "Meta" )
|
||||||
|
{
|
||||||
|
if ( !isDefined( clientData["meta"] ) )
|
||||||
|
{
|
||||||
|
clientData.meta = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
metaKey = event.data[0];
|
||||||
|
clientData["meta"][metaKey] = event.data[metaKey];
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clientData.permissionLevel = event.data["level"];
|
||||||
|
clientData.lastConnection = event.data["lastConnection"];
|
||||||
|
clientData.state = "complete";
|
||||||
|
|
||||||
|
self thread DisplayWelcomeData();
|
||||||
|
}
|
||||||
|
|
||||||
|
OnExecuteCommand( event )
|
||||||
|
{
|
||||||
|
data = ParseDataString( event.data );
|
||||||
|
switch ( event.subtype )
|
||||||
|
{
|
||||||
|
case "GiveWeapon":
|
||||||
|
self GiveWeaponImpl( data );
|
||||||
|
break;
|
||||||
|
case "TakeWeapons":
|
||||||
|
self TakeWeaponsImpl();
|
||||||
|
break;
|
||||||
|
case "SwitchTeams":
|
||||||
|
self TeamSwitchImpl();
|
||||||
|
break;
|
||||||
|
case "Hide":
|
||||||
|
self HideImpl();
|
||||||
|
break;
|
||||||
|
case "Unhide":
|
||||||
|
self UnhideImpl();
|
||||||
|
break;
|
||||||
|
case "Alert":
|
||||||
|
self AlertImpl( data );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////
|
||||||
|
// Command Implementations
|
||||||
|
/////////////////////////////////
|
||||||
|
|
||||||
|
GiveWeaponImpl( data )
|
||||||
|
{
|
||||||
|
if ( IsAlive( self ) )
|
||||||
|
{
|
||||||
|
self IPrintLnBold( "You have been given a new weapon" );
|
||||||
|
self GiveWeapon( data["weaponName"] );
|
||||||
|
self SwitchToWeapon( data["weaponName"] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TakeWeaponsImpl()
|
||||||
|
{
|
||||||
|
if ( IsAlive( self ) )
|
||||||
|
{
|
||||||
|
self TakeAllWeapons();
|
||||||
|
self IPrintLnBold( "All your weapons have been taken" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TeamSwitchImpl()
|
||||||
|
{
|
||||||
|
if ( self.team == "allies" )
|
||||||
|
{
|
||||||
|
self [[level.axis]]();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
self [[level.allies]]();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HideImpl()
|
||||||
|
{
|
||||||
|
if ( IsAlive( self ) )
|
||||||
|
{
|
||||||
|
self Hide();
|
||||||
|
self IPrintLnBold( "You are now hidden" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UnhideImpl()
|
||||||
|
{
|
||||||
|
if ( IsAlive( self ) )
|
||||||
|
{
|
||||||
|
self Show();
|
||||||
|
self IPrintLnBold( "You are now visible" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AlertImpl( data )
|
||||||
|
{
|
||||||
|
self thread maps\mp\gametypes\_hud_message::oldNotifyMessage( data["alertType"], data["message"], "compass_waypoint_target", ( 1, 0, 0 ), "ui_mp_nukebomb_timer", 7.5 );
|
||||||
|
}
|
@ -6,7 +6,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{26E8
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8C8F3945-0AEF-4949-A1F7-B18E952E50BC}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8C8F3945-0AEF-4949-A1F7-B18E952E50BC}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
GameFiles\IW4x\userraw\scripts\_commands.gsc = GameFiles\IW4x\userraw\scripts\_commands.gsc
|
|
||||||
GameFiles\IW4x\userraw\scripts\_customcallbacks.gsc = GameFiles\IW4x\userraw\scripts\_customcallbacks.gsc
|
GameFiles\IW4x\userraw\scripts\_customcallbacks.gsc = GameFiles\IW4x\userraw\scripts\_customcallbacks.gsc
|
||||||
DeploymentFiles\deployment-pipeline.yml = DeploymentFiles\deployment-pipeline.yml
|
DeploymentFiles\deployment-pipeline.yml = DeploymentFiles\deployment-pipeline.yml
|
||||||
DeploymentFiles\PostPublish.ps1 = DeploymentFiles\PostPublish.ps1
|
DeploymentFiles\PostPublish.ps1 = DeploymentFiles\PostPublish.ps1
|
||||||
@ -30,8 +29,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProfanityDeterment", "Plugi
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Login", "Plugins\Login\Login.csproj", "{D9F2ED28-6FA5-40CA-9912-E7A849147AB1}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Login", "Plugins\Login\Login.csproj", "{D9F2ED28-6FA5-40CA-9912-E7A849147AB1}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IW4ScriptCommands", "Plugins\IW4ScriptCommands\IW4ScriptCommands.csproj", "{6C706CE5-A206-4E46-8712-F8C48D526091}"
|
|
||||||
EndProject
|
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ScriptPlugins", "ScriptPlugins", "{3F9ACC27-26DB-49FA-BCD2-50C54A49C9FA}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ScriptPlugins", "ScriptPlugins", "{3F9ACC27-26DB-49FA-BCD2-50C54A49C9FA}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
Plugins\ScriptPlugins\ActionOnReport.js = Plugins\ScriptPlugins\ActionOnReport.js
|
Plugins\ScriptPlugins\ActionOnReport.js = Plugins\ScriptPlugins\ActionOnReport.js
|
||||||
@ -253,30 +250,6 @@ Global
|
|||||||
{D9F2ED28-6FA5-40CA-9912-E7A849147AB1}.Release|x64.Build.0 = Release|Any CPU
|
{D9F2ED28-6FA5-40CA-9912-E7A849147AB1}.Release|x64.Build.0 = Release|Any CPU
|
||||||
{D9F2ED28-6FA5-40CA-9912-E7A849147AB1}.Release|x86.ActiveCfg = Release|Any CPU
|
{D9F2ED28-6FA5-40CA-9912-E7A849147AB1}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{D9F2ED28-6FA5-40CA-9912-E7A849147AB1}.Release|x86.Build.0 = Release|Any CPU
|
{D9F2ED28-6FA5-40CA-9912-E7A849147AB1}.Release|x86.Build.0 = Release|Any CPU
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Debug|x64.ActiveCfg = Debug|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Debug|x64.Build.0 = Debug|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Debug|x86.ActiveCfg = Debug|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Debug|x86.Build.0 = Debug|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Prerelease|Any CPU.ActiveCfg = Prerelease|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Prerelease|Any CPU.Build.0 = Prerelease|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Prerelease|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Prerelease|Mixed Platforms.Build.0 = Debug|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Prerelease|x64.ActiveCfg = Debug|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Prerelease|x64.Build.0 = Debug|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Prerelease|x86.ActiveCfg = Debug|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Prerelease|x86.Build.0 = Debug|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Release|x64.ActiveCfg = Release|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Release|x64.Build.0 = Release|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Release|x86.ActiveCfg = Release|Any CPU
|
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091}.Release|x86.Build.0 = Release|Any CPU
|
|
||||||
{F5815359-CFC7-44B4-9A3B-C04BACAD5836}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{F5815359-CFC7-44B4-9A3B-C04BACAD5836}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{F5815359-CFC7-44B4-9A3B-C04BACAD5836}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{F5815359-CFC7-44B4-9A3B-C04BACAD5836}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{F5815359-CFC7-44B4-9A3B-C04BACAD5836}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
{F5815359-CFC7-44B4-9A3B-C04BACAD5836}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||||
@ -406,7 +379,6 @@ Global
|
|||||||
{179140D3-97AA-4CB4-8BF6-A0C73CA75701} = {26E8B310-269E-46D4-A612-24601F16065F}
|
{179140D3-97AA-4CB4-8BF6-A0C73CA75701} = {26E8B310-269E-46D4-A612-24601F16065F}
|
||||||
{958FF7EC-0226-4E85-A85B-B84EC768197D} = {26E8B310-269E-46D4-A612-24601F16065F}
|
{958FF7EC-0226-4E85-A85B-B84EC768197D} = {26E8B310-269E-46D4-A612-24601F16065F}
|
||||||
{D9F2ED28-6FA5-40CA-9912-E7A849147AB1} = {26E8B310-269E-46D4-A612-24601F16065F}
|
{D9F2ED28-6FA5-40CA-9912-E7A849147AB1} = {26E8B310-269E-46D4-A612-24601F16065F}
|
||||||
{6C706CE5-A206-4E46-8712-F8C48D526091} = {26E8B310-269E-46D4-A612-24601F16065F}
|
|
||||||
{3F9ACC27-26DB-49FA-BCD2-50C54A49C9FA} = {26E8B310-269E-46D4-A612-24601F16065F}
|
{3F9ACC27-26DB-49FA-BCD2-50C54A49C9FA} = {26E8B310-269E-46D4-A612-24601F16065F}
|
||||||
{F5815359-CFC7-44B4-9A3B-C04BACAD5836} = {26E8B310-269E-46D4-A612-24601F16065F}
|
{F5815359-CFC7-44B4-9A3B-C04BACAD5836} = {26E8B310-269E-46D4-A612-24601F16065F}
|
||||||
{00A1FED2-2254-4AF7-A5DB-2357FA7C88CD} = {26E8B310-269E-46D4-A612-24601F16065F}
|
{00A1FED2-2254-4AF7-A5DB-2357FA7C88CD} = {26E8B310-269E-46D4-A612-24601F16065F}
|
||||||
|
@ -64,9 +64,9 @@ namespace Integrations.Cod
|
|||||||
|
|
||||||
var timeSinceLastQuery = (DateTime.Now - connectionState.LastQuery).TotalMilliseconds;
|
var timeSinceLastQuery = (DateTime.Now - connectionState.LastQuery).TotalMilliseconds;
|
||||||
|
|
||||||
if (timeSinceLastQuery < StaticHelpers.FloodProtectionInterval)
|
if (timeSinceLastQuery < config.FloodProtectInterval)
|
||||||
{
|
{
|
||||||
await Task.Delay(StaticHelpers.FloodProtectionInterval - (int)timeSinceLastQuery);
|
await Task.Delay(config.FloodProtectInterval - (int)timeSinceLastQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
connectionState.LastQuery = DateTime.Now;
|
connectionState.LastQuery = DateTime.Now;
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
using SharedLibraryCore;
|
|
||||||
using SharedLibraryCore.Commands;
|
|
||||||
using SharedLibraryCore.Configuration;
|
|
||||||
using SharedLibraryCore.Database.Models;
|
|
||||||
using SharedLibraryCore.Interfaces;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace IW4ScriptCommands.Commands
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Example script command
|
|
||||||
/// </summary>
|
|
||||||
public class KillPlayerCommand : Command
|
|
||||||
{
|
|
||||||
public KillPlayerCommand(CommandConfiguration config, ITranslationLookup lookup) : base(config, lookup)
|
|
||||||
{
|
|
||||||
Name = "killplayer";
|
|
||||||
Description = "kill a player";
|
|
||||||
Alias = "kp";
|
|
||||||
Permission = EFClient.Permission.Administrator;
|
|
||||||
RequiresTarget = true;
|
|
||||||
Arguments = new[]
|
|
||||||
{
|
|
||||||
new CommandArgument()
|
|
||||||
{
|
|
||||||
Name = "player",
|
|
||||||
Required = true
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task ExecuteAsync(GameEvent E)
|
|
||||||
{
|
|
||||||
var cmd = new ScriptCommand()
|
|
||||||
{
|
|
||||||
CommandName = "killplayer",
|
|
||||||
ClientNumber = E.Target.ClientNumber,
|
|
||||||
CommandArguments = new[] { E.Origin.ClientNumber.ToString() }
|
|
||||||
};
|
|
||||||
|
|
||||||
await cmd.Execute(E.Owner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using SharedLibraryCore;
|
|
||||||
using SharedLibraryCore.Interfaces;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace WebfrontCore.Controllers.API
|
|
||||||
{
|
|
||||||
[Route("api/gsc/[action]")]
|
|
||||||
public class GscApiController : BaseController
|
|
||||||
{
|
|
||||||
public GscApiController(IManager manager) : base(manager)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// grabs basic info about the client from IW4MAdmin
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="networkId"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("{networkId}")]
|
|
||||||
public IActionResult ClientInfo(string networkId)
|
|
||||||
{
|
|
||||||
long decimalNetworkId = networkId.ConvertGuidToLong(System.Globalization.NumberStyles.HexNumber);
|
|
||||||
var clientInfo = Manager.GetActiveClients()
|
|
||||||
.FirstOrDefault(c => c.NetworkId == decimalNetworkId);
|
|
||||||
|
|
||||||
if (clientInfo != null)
|
|
||||||
{
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.AppendLine($"admin={clientInfo.IsPrivileged()}");
|
|
||||||
sb.AppendLine($"level={(int)clientInfo.Level}");
|
|
||||||
sb.AppendLine($"levelstring={clientInfo.Level.ToLocalizedLevelName()}");
|
|
||||||
sb.AppendLine($"connections={clientInfo.Connections}");
|
|
||||||
sb.AppendLine($"authenticated={clientInfo.GetAdditionalProperty<bool>("IsLoggedIn") == true}");
|
|
||||||
|
|
||||||
return Content(sb.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return Content("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>Library</OutputType>
|
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
|
||||||
<ApplicationIcon />
|
|
||||||
<StartupObject />
|
|
||||||
<Configurations>Debug;Release;Prerelease</Configurations>
|
|
||||||
<LangVersion>Latest</LangVersion>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2022.1.28.1" PrivateAssets="All" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
|
||||||
<Exec Command="dotnet publish $(ProjectPath) -c $(ConfigurationName) -o $(ProjectDir)..\..\Build\Plugins --no-build --no-restore --no-dependencies" />
|
|
||||||
</Target>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,46 +0,0 @@
|
|||||||
using SharedLibraryCore;
|
|
||||||
using SharedLibraryCore.Interfaces;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace IW4ScriptCommands
|
|
||||||
{
|
|
||||||
public class Plugin : IPlugin
|
|
||||||
{
|
|
||||||
public string Name => "IW4 Script Commands";
|
|
||||||
|
|
||||||
public float Version => 1.0f;
|
|
||||||
|
|
||||||
public string Author => "RaidMax";
|
|
||||||
|
|
||||||
public async Task OnEventAsync(GameEvent E, Server S)
|
|
||||||
{
|
|
||||||
if (E.Type == GameEvent.EventType.Start)
|
|
||||||
{
|
|
||||||
await S.SetDvarAsync("sv_iw4madmin_serverid", S.EndPoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (E.Type == GameEvent.EventType.Warn)
|
|
||||||
{
|
|
||||||
var cmd = new ScriptCommand()
|
|
||||||
{
|
|
||||||
ClientNumber = E.Target.ClientNumber,
|
|
||||||
CommandName = "alert",
|
|
||||||
CommandArguments = new[]
|
|
||||||
{
|
|
||||||
"Warning",
|
|
||||||
"ui_mp_nukebomb_timer",
|
|
||||||
E.Data
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// notifies the player ingame of the warning
|
|
||||||
await cmd.Execute(S);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task OnLoadAsync(IManager manager) => Task.CompletedTask;
|
|
||||||
|
|
||||||
public Task OnTickAsync(Server S) => Task.CompletedTask;
|
|
||||||
|
|
||||||
public Task OnUnloadAsync() => Task.CompletedTask;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
using SharedLibraryCore;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace IW4ScriptCommands
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Contains basic properties for command information read by gsc
|
|
||||||
/// </summary>
|
|
||||||
class ScriptCommand
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Name of the command to execute
|
|
||||||
/// </summary>
|
|
||||||
public string CommandName { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Target client number
|
|
||||||
/// </summary>
|
|
||||||
public int ClientNumber { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Arguments for the script function itself
|
|
||||||
/// </summary>
|
|
||||||
public string[] CommandArguments { get; set; } = new string[0];
|
|
||||||
|
|
||||||
public override string ToString() => string.Join(";", new[] { CommandName, ClientNumber.ToString() }.Concat(CommandArguments).Select(_arg => _arg.Replace(";", "")));
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Executes the command
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="server">server to execute the command on</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task Execute(Server server) => await server.SetDvarAsync("sv_iw4madmin_command", ToString());
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,7 +8,7 @@
|
|||||||
const servers = {};
|
const servers = {};
|
||||||
const inDvar = 'sv_iw4madmin_in';
|
const inDvar = 'sv_iw4madmin_in';
|
||||||
const outDvar = 'sv_iw4madmin_out';
|
const outDvar = 'sv_iw4madmin_out';
|
||||||
const pollRate = 1000;
|
const pollRate = 750;
|
||||||
let logger = {};
|
let logger = {};
|
||||||
|
|
||||||
let plugin = {
|
let plugin = {
|
||||||
@ -26,7 +26,7 @@ let plugin = {
|
|||||||
switch (eventType) {
|
switch (eventType) {
|
||||||
case 'start':
|
case 'start':
|
||||||
const enabled = initialize(server);
|
const enabled = initialize(server);
|
||||||
|
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -67,7 +67,9 @@ let plugin = {
|
|||||||
|
|
||||||
onUnloadAsync: () => {
|
onUnloadAsync: () => {
|
||||||
for (let i = 0; i < servers.length; i++) {
|
for (let i = 0; i < servers.length; i++) {
|
||||||
servers[i].timer.Stop();
|
if (servers[i].enabled) {
|
||||||
|
servers[i].timer.Stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -189,7 +191,11 @@ let commands = [{
|
|||||||
targetRequired: true,
|
targetRequired: true,
|
||||||
// optional
|
// optional
|
||||||
arguments: [{
|
arguments: [{
|
||||||
name: 'alert message',
|
name: 'player',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'message',
|
||||||
required: true
|
required: true
|
||||||
}],
|
}],
|
||||||
supportedGames: ['IW4'],
|
supportedGames: ['IW4'],
|
||||||
@ -203,9 +209,11 @@ let commands = [{
|
|||||||
}];
|
}];
|
||||||
|
|
||||||
const sendScriptCommand = (server, command, target, data) => {
|
const sendScriptCommand = (server, command, target, data) => {
|
||||||
if (plugin.enabled) {
|
const state = servers[server.EndPoint];
|
||||||
sendEvent(server, false, 'ExecuteCommandRequested', command, target, data);
|
if (state === undefined || !state.enabled) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
sendEvent(server, false, 'ExecuteCommandRequested', command, target, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sendEvent = (server, responseExpected, event, subtype, client, data) => {
|
const sendEvent = (server, responseExpected, event, subtype, client, data) => {
|
||||||
@ -213,9 +221,12 @@ const sendEvent = (server, responseExpected, event, subtype, client, data) => {
|
|||||||
|
|
||||||
let pendingOut = true;
|
let pendingOut = true;
|
||||||
let pendingCheckCount = 0;
|
let pendingCheckCount = 0;
|
||||||
while (pendingOut === true && pendingCheckCount <= 10) {
|
const start = new Date();
|
||||||
|
|
||||||
|
while (pendingOut && pendingCheckCount <= 30) {
|
||||||
try {
|
try {
|
||||||
pendingOut = server.GetServerDvar(outDvar) !== null;
|
const out = server.GetServerDvar(outDvar);
|
||||||
|
pendingOut = !(out == null || out === '' || out === 'null');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.WriteError(`Could not check server output dvar for IO status ${error}`);
|
logger.WriteError(`Could not check server output dvar for IO status ${error}`);
|
||||||
}
|
}
|
||||||
@ -227,22 +238,16 @@ const sendEvent = (server, responseExpected, event, subtype, client, data) => {
|
|||||||
pendingCheckCount++;
|
pendingCheckCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pendingCheckCount === true) {
|
if (pendingOut) {
|
||||||
logger.WriteWarning(`Reached maximum attempts waiting for output to be available for ${server.EndPoint}`)
|
logger.WriteWarning(`Reached maximum attempts waiting for output to be available for ${server.EndPoint}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
let clientNumber = '';
|
const output = `${responseExpected ? '1' : '0'};${event};${subtype};${client.ClientNumber};${buildDataString(data)}`;
|
||||||
if (client !== undefined) {
|
|
||||||
clientNumber = client.ClientNumber;
|
|
||||||
}
|
|
||||||
if (responseExpected === undefined) {
|
|
||||||
responseExpected = 0;
|
|
||||||
}
|
|
||||||
const output = `${responseExpected ? '1' : '0'};${event};${subtype};${clientNumber};${buildDataString(data)}`;
|
|
||||||
logger.WriteDebug(`Sending output to server ${output}`);
|
logger.WriteDebug(`Sending output to server ${output}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
server.SetServerDvar(outDvar, output);
|
server.SetServerDvar(outDvar, output);
|
||||||
|
logger.WriteDebug(`SendEvent took ${(new Date() - start) / 1000}ms`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.WriteError(`Could not set server output dvar ${error}`);
|
logger.WriteError(`Could not set server output dvar ${error}`);
|
||||||
}
|
}
|
||||||
@ -272,7 +277,7 @@ const initialize = (server) => {
|
|||||||
logger.WriteError(`Could not get integration status of ${server.EndPoint} - ${error}`);
|
logger.WriteError(`Could not get integration status of ${server.EndPoint} - ${error}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.WriteDebug(`GSC Integration enabledGSC Integration enabled = ${enabled}`);
|
logger.WriteInfo(`GSC Integration enabled = ${enabled}`);
|
||||||
|
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
servers[server.EndPoint] = {
|
servers[server.EndPoint] = {
|
||||||
@ -283,8 +288,10 @@ const initialize = (server) => {
|
|||||||
|
|
||||||
logger.WriteDebug(`Setting up bus timer for ${server.EndPoint}`);
|
logger.WriteDebug(`Setting up bus timer for ${server.EndPoint}`);
|
||||||
|
|
||||||
let timer = _timerHelper;
|
let timer = _serviceResolver.ResolveService('IScriptPluginTimerHelper');
|
||||||
timer.OnTick(() => pollForEvents(server), `GameEventPoller ${server.ToString()}`)
|
timer.OnTick(() => pollForEvents(server), `GameEventPoller ${server.ToString()}`);
|
||||||
|
// necessary to prevent multi-threaded access to the JS context
|
||||||
|
timer.SetDependency(_lock);
|
||||||
|
|
||||||
servers[server.EndPoint] = {
|
servers[server.EndPoint] = {
|
||||||
timer: timer,
|
timer: timer,
|
||||||
@ -317,16 +324,15 @@ const pollForEvents = server => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (input.length > 0) {
|
if (input.length > 0) {
|
||||||
|
|
||||||
const event = parseEvent(input)
|
const event = parseEvent(input)
|
||||||
|
|
||||||
logger.WriteInfo(`Processing input... ${event.eventType}`);
|
logger.WriteDebug(`Processing input... ${event.eventType} ${event.subType} ${event.data} ${event.clientNumber}`);
|
||||||
|
|
||||||
if (event.eventType === 'ClientDataRequested') {
|
if (event.eventType === 'ClientDataRequested') {
|
||||||
const client = server.GetClientByNumber(event.clientNumber);
|
const client = server.GetClientByNumber(event.clientNumber);
|
||||||
|
|
||||||
if (client != null) {
|
if (client != null) {
|
||||||
logger.WriteInfo(`Found client ${client.Name}`);
|
logger.WriteDebug(`Found client ${client.Name}`);
|
||||||
|
|
||||||
let data = [];
|
let data = [];
|
||||||
|
|
||||||
@ -342,9 +348,10 @@ const pollForEvents = server => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendEvent(server, false, 'ClientDataReceived', event.subType, client, data);
|
sendEvent(server, false, 'ClientDataReceived', event.subType, client, data);
|
||||||
|
} else {
|
||||||
|
logger.WriteWarning(`Could not find client slot ${event.clientNumber} when processing ${event.eventType}`);
|
||||||
|
sendEvent(server, false, 'ClientDataReceived', 'Fail', { ClientNumber: event.clientNumber }, undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.WriteWarning(`Could not find client slot ${event.clientNumber} when processing ${event.eventType}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -3,7 +3,7 @@ var eventParser;
|
|||||||
|
|
||||||
var plugin = {
|
var plugin = {
|
||||||
author: 'RaidMax',
|
author: 'RaidMax',
|
||||||
version: 0.5,
|
version: 0.6,
|
||||||
name: 'IW4x Parser',
|
name: 'IW4x Parser',
|
||||||
isParser: true,
|
isParser: true,
|
||||||
|
|
||||||
@ -20,10 +20,11 @@ var plugin = {
|
|||||||
rconParser.Configuration.CommandPrefixes.Ban = 'clientkick {0} "{1}"';
|
rconParser.Configuration.CommandPrefixes.Ban = 'clientkick {0} "{1}"';
|
||||||
rconParser.Configuration.CommandPrefixes.TempBan = 'tempbanclient {0} "{1}"';
|
rconParser.Configuration.CommandPrefixes.TempBan = 'tempbanclient {0} "{1}"';
|
||||||
|
|
||||||
rconParser.Configuration.DefaultRConPort = 28960;
|
rconParser.Configuration.DefaultRConPort = 28960;
|
||||||
rconParser.Configuration.DefaultInstallationDirectoryHint = 'HKEY_CURRENT_USER\\Software\\Classes\\iw4x\\shell\\open\\command';
|
rconParser.Configuration.DefaultInstallationDirectoryHint = 'HKEY_CURRENT_USER\\Software\\Classes\\iw4x\\shell\\open\\command';
|
||||||
|
rconParser.Configuration.FloodProtectInterval = 150;
|
||||||
|
|
||||||
eventParser.Configuration.GameDirectory = 'userraw';
|
eventParser.Configuration.GameDirectory = 'userraw';
|
||||||
|
|
||||||
rconParser.Version = 'IW4x (v0.6.0)';
|
rconParser.Version = 'IW4x (v0.6.0)';
|
||||||
rconParser.GameName = 2; // IW4x
|
rconParser.GameName = 2; // IW4x
|
||||||
@ -37,4 +38,4 @@ var plugin = {
|
|||||||
|
|
||||||
onTickAsync: function (server) {
|
onTickAsync: function (server) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -18,6 +18,6 @@ namespace SharedLibraryCore.Interfaces
|
|||||||
/// discovers the script plugins
|
/// discovers the script plugins
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>initialized script plugin collection</returns>
|
/// <returns>initialized script plugin collection</returns>
|
||||||
IEnumerable<Func<IServiceProvider, IPlugin>> DiscoverScriptPlugins();
|
IEnumerable<IPlugin> DiscoverScriptPlugins();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,5 +100,7 @@ namespace SharedLibraryCore.Interfaces
|
|||||||
string DefaultInstallationDirectoryHint { get; }
|
string DefaultInstallationDirectoryHint { get; }
|
||||||
|
|
||||||
ColorCodeMapping ColorCodeMapping { get; }
|
ColorCodeMapping ColorCodeMapping { get; }
|
||||||
|
|
||||||
|
short FloodProtectInterval { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user