Compare commits
8 Commits
2022.02.11
...
2022.02.16
Author | SHA1 | Date | |
---|---|---|---|
482cd9c339 | |||
51667159a2 | |||
ea18a286b2 | |||
9a6d7c6a20 | |||
adcb75319c | |||
037fac5786 | |||
f4b892d8f4 | |||
3640d1df54 |
@ -412,7 +412,7 @@ namespace IW4MAdmin.Application
|
||||
|
||||
if (!validationResult.IsValid)
|
||||
{
|
||||
throw new ConfigurationException(_translationLookup["MANAGER_CONFIGURATION_ERROR"])
|
||||
throw new ConfigurationException("Could not validate configuration")
|
||||
{
|
||||
Errors = validationResult.Errors.Select(_error => _error.ErrorMessage).ToArray(),
|
||||
ConfigurationFileName = ConfigHandler.FileName
|
||||
|
@ -21,7 +21,7 @@ namespace IW4MAdmin.Application.IO
|
||||
{
|
||||
_reader = gameLogReaderFactory.CreateGameLogReader(gameLogUris, server.EventParser);
|
||||
_server = server;
|
||||
_ignoreBots = server?.Manager.GetApplicationSettings().Configuration().IgnoreBots ?? false;
|
||||
_ignoreBots = server.Manager.GetApplicationSettings().Configuration()?.IgnoreBots ?? false;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ namespace IW4MAdmin.Application.IO
|
||||
return;
|
||||
}
|
||||
|
||||
var events = await _reader.ReadEventsFromLog(fileDiff, previousFileSize);
|
||||
var events = await _reader.ReadEventsFromLog(fileDiff, previousFileSize, _server);
|
||||
|
||||
foreach (var gameEvent in events)
|
||||
{
|
||||
|
@ -28,7 +28,7 @@ namespace IW4MAdmin.Application.IO
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<GameEvent>> ReadEventsFromLog(long fileSizeDiff, long startPosition)
|
||||
public async Task<IEnumerable<GameEvent>> ReadEventsFromLog(long fileSizeDiff, long startPosition, Server server = null)
|
||||
{
|
||||
// allocate the bytes for the new log lines
|
||||
List<string> logLines = new List<string>();
|
||||
|
@ -34,7 +34,7 @@ namespace IW4MAdmin.Application.IO
|
||||
|
||||
public int UpdateInterval => 500;
|
||||
|
||||
public async Task<IEnumerable<GameEvent>> ReadEventsFromLog(long fileSizeDiff, long startPosition)
|
||||
public async Task<IEnumerable<GameEvent>> ReadEventsFromLog(long fileSizeDiff, long startPosition, Server server = null)
|
||||
{
|
||||
var events = new List<GameEvent>();
|
||||
var response = await _logServerApi.Log(_safeLogPath, lastKey);
|
||||
|
@ -5,76 +5,92 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Integrations.Cod;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog.Context;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
|
||||
namespace IW4MAdmin.Application.IO
|
||||
{
|
||||
/// <summary>
|
||||
/// provides capability of reading log files over HTTP
|
||||
/// provides capability of reading log files over udp
|
||||
/// </summary>
|
||||
class NetworkGameLogReader : IGameLogReader
|
||||
{
|
||||
private readonly IEventParser _eventParser;
|
||||
private readonly UdpClient _udpClient;
|
||||
private readonly ILogger _logger;
|
||||
private readonly Uri _uri;
|
||||
private static readonly NetworkLogState State = new();
|
||||
private bool _stateRegistered;
|
||||
private CancellationToken _token;
|
||||
|
||||
public NetworkGameLogReader(Uri[] uris, IEventParser parser, ILogger<NetworkGameLogReader> logger)
|
||||
public NetworkGameLogReader(IReadOnlyList<Uri> uris, IEventParser parser, ILogger<NetworkGameLogReader> logger)
|
||||
{
|
||||
_eventParser = parser;
|
||||
try
|
||||
{
|
||||
var endPoint = new IPEndPoint(Dns.GetHostAddresses(uris[0].Host).First(), uris[0].Port);
|
||||
_udpClient = new UdpClient(endPoint);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Could setup {LogReader}", nameof(NetworkGameLogReader));
|
||||
}
|
||||
|
||||
_uri = uris[0];
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public long Length => -1;
|
||||
|
||||
public int UpdateInterval => 500;
|
||||
public int UpdateInterval => 150;
|
||||
|
||||
public async Task<IEnumerable<GameEvent>> ReadEventsFromLog(long fileSizeDiff, long startPosition)
|
||||
public Task<IEnumerable<GameEvent>> ReadEventsFromLog(long fileSizeDiff, long startPosition,
|
||||
Server server = null)
|
||||
{
|
||||
if (_udpClient == null)
|
||||
// todo: other games might support this
|
||||
var serverEndpoint = (server?.RemoteConnection as CodRConConnection)?.Endpoint;
|
||||
|
||||
if (serverEndpoint is null)
|
||||
{
|
||||
return Enumerable.Empty<GameEvent>();
|
||||
return Task.FromResult(Enumerable.Empty<GameEvent>());
|
||||
}
|
||||
|
||||
byte[] buffer;
|
||||
if (!_stateRegistered && !State.EndPointExists(serverEndpoint))
|
||||
{
|
||||
try
|
||||
{
|
||||
buffer = (await _udpClient.ReceiveAsync()).Buffer;
|
||||
var client = State.RegisterEndpoint(serverEndpoint, BuildLocalEndpoint()).Client;
|
||||
|
||||
_stateRegistered = true;
|
||||
_token = server.Manager.CancellationToken;
|
||||
|
||||
if (client == null)
|
||||
{
|
||||
using (LogContext.PushProperty("Server", server.ToString()))
|
||||
{
|
||||
_logger.LogInformation("Not registering {Name} socket because it is already bound",
|
||||
nameof(NetworkGameLogReader));
|
||||
}
|
||||
return Task.FromResult(Enumerable.Empty<GameEvent>());
|
||||
}
|
||||
|
||||
new Thread(() => ReadNetworkData(client)).Start();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Could receive lines for {LogReader}", nameof(NetworkGameLogReader));
|
||||
return Enumerable.Empty<GameEvent>();
|
||||
_logger.LogError(ex, "Could not register {Name} endpoint {Endpoint}",
|
||||
nameof(NetworkGameLogReader), _uri);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
if (!buffer.Any())
|
||||
var events = new List<GameEvent>();
|
||||
|
||||
foreach (var logData in State.GetServerLogData(serverEndpoint)
|
||||
.Select(log => Utilities.EncodingType.GetString(log)))
|
||||
{
|
||||
return Enumerable.Empty<GameEvent>();
|
||||
}
|
||||
|
||||
var logData = Utilities.EncodingType.GetString(buffer);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(logData))
|
||||
{
|
||||
return Enumerable.Empty<GameEvent>();
|
||||
return Task.FromResult(Enumerable.Empty<GameEvent>());
|
||||
}
|
||||
|
||||
var lines = logData
|
||||
.Split('\n')
|
||||
.Where(line => line.Length > 0);
|
||||
|
||||
var events = new List<GameEvent>();
|
||||
foreach (var eventLine in lines)
|
||||
{
|
||||
try
|
||||
@ -86,11 +102,56 @@ namespace IW4MAdmin.Application.IO
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Could not properly parse event line from http {eventLine}", eventLine);
|
||||
_logger.LogError(ex, "Could not properly parse event line from http {EventLine}",
|
||||
eventLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return events;
|
||||
return Task.FromResult((IEnumerable<GameEvent>)events);
|
||||
}
|
||||
|
||||
private void ReadNetworkData(UdpClient client)
|
||||
{
|
||||
while (!_token.IsCancellationRequested)
|
||||
{
|
||||
// get more data
|
||||
IPEndPoint remoteEndpoint = null;
|
||||
byte[] bufferedData = null;
|
||||
|
||||
if (client == null)
|
||||
{
|
||||
// we already have a socket listening on this port for data, so we don't need to run another thread
|
||||
break;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
bufferedData = client.Receive(ref remoteEndpoint);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Could not receive lines for {LogReader}", nameof(NetworkGameLogReader));
|
||||
}
|
||||
|
||||
if (bufferedData != null)
|
||||
{
|
||||
State.QueueServerLogData(remoteEndpoint, bufferedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IPEndPoint BuildLocalEndpoint()
|
||||
{
|
||||
try
|
||||
{
|
||||
return new IPEndPoint(Dns.GetHostAddresses(_uri.Host).First(), _uri.Port);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Could not setup {LogReader} endpoint", nameof(NetworkGameLogReader));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
138
Application/IO/NetworkLogState.cs
Normal file
138
Application/IO/NetworkLogState.cs
Normal file
@ -0,0 +1,138 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
|
||||
namespace IW4MAdmin.Application.IO;
|
||||
|
||||
public class NetworkLogState : Dictionary<IPEndPoint, UdpClientState>
|
||||
{
|
||||
public UdpClientState RegisterEndpoint(IPEndPoint serverEndpoint, IPEndPoint localEndpoint)
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
if (!ContainsKey(serverEndpoint))
|
||||
{
|
||||
Add(serverEndpoint, new UdpClientState { Client = new UdpClient(localEndpoint) });
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SocketException ex) when (ex.SocketErrorCode == SocketError.AddressAlreadyInUse)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
// we don't add the udp client because it already exists (listening to multiple servers from one socket)
|
||||
Add(serverEndpoint, new UdpClientState());
|
||||
}
|
||||
}
|
||||
|
||||
return this[serverEndpoint];
|
||||
}
|
||||
|
||||
|
||||
public List<byte[]> GetServerLogData(IPEndPoint serverEndpoint)
|
||||
{
|
||||
try
|
||||
{
|
||||
var state = this[serverEndpoint];
|
||||
|
||||
if (state == null)
|
||||
{
|
||||
return new List<byte[]>();
|
||||
}
|
||||
|
||||
// it's possible that we could be trying to read and write to the queue simultaneously so we need to wait
|
||||
this[serverEndpoint].OnAction.Wait();
|
||||
|
||||
var data = new List<byte[]>();
|
||||
|
||||
while (this[serverEndpoint].AvailableLogData.Count > 0)
|
||||
{
|
||||
data.Add(this[serverEndpoint].AvailableLogData.Dequeue());
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (this[serverEndpoint].OnAction.CurrentCount == 0)
|
||||
{
|
||||
this[serverEndpoint].OnAction.Release(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void QueueServerLogData(IPEndPoint serverEndpoint, byte[] data)
|
||||
{
|
||||
var endpoint = Keys.FirstOrDefault(key =>
|
||||
Equals(key.Address, serverEndpoint.Address) && key.Port == serverEndpoint.Port);
|
||||
|
||||
try
|
||||
{
|
||||
if (endpoint == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// currently our expected start and end characters
|
||||
var startsWithPrefix = StartsWith(data, "ÿÿÿÿprint\n");
|
||||
var endsWithDelimiter = data[^1] == '\n';
|
||||
|
||||
// we have the data we expected
|
||||
if (!startsWithPrefix || !endsWithDelimiter)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// it's possible that we could be trying to read and write to the queue simultaneously so we need to wait
|
||||
this[endpoint].OnAction.Wait();
|
||||
this[endpoint].AvailableLogData.Enqueue(data);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (endpoint != null && this[endpoint].OnAction.CurrentCount == 0)
|
||||
{
|
||||
this[endpoint].OnAction.Release(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool EndPointExists(IPEndPoint serverEndpoint)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
return ContainsKey(serverEndpoint);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool StartsWith(byte[] sourceArray, string match)
|
||||
{
|
||||
if (sourceArray is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (match.Length > sourceArray.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return !match.Where((t, i) => sourceArray[i] != (byte)t).Any();
|
||||
}
|
||||
}
|
||||
|
||||
public class UdpClientState
|
||||
{
|
||||
public UdpClient Client { get; set; }
|
||||
public Queue<byte[]> AvailableLogData { get; } = new();
|
||||
public SemaphoreSlim OnAction { get; } = new(1, 1);
|
||||
|
||||
~UdpClientState()
|
||||
{
|
||||
OnAction.Dispose();
|
||||
Client?.Dispose();
|
||||
}
|
||||
}
|
@ -236,7 +236,7 @@ namespace IW4MAdmin
|
||||
private async Task CreatePluginTask(IPlugin plugin, GameEvent gameEvent)
|
||||
{
|
||||
// we don't want to run the events on parser plugins
|
||||
if (plugin is ScriptPlugin scriptPlugin && scriptPlugin.IsParser)
|
||||
if (plugin is ScriptPlugin { IsParser: true })
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -248,6 +248,11 @@ namespace IW4MAdmin
|
||||
{
|
||||
await plugin.OnEventAsync(gameEvent, this).WithWaitCancellation(tokenSource.Token);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
ServerLogger.LogWarning("Timed out executing event {EventType} for {Plugin}", gameEvent.Type,
|
||||
plugin.Name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(loc["SERVER_PLUGIN_ERROR"].FormatExt(plugin.Name, ex.GetType().Name));
|
||||
@ -290,7 +295,7 @@ namespace IW4MAdmin
|
||||
}
|
||||
}
|
||||
|
||||
if (E.Type == GameEvent.EventType.ConnectionLost)
|
||||
else if (E.Type == GameEvent.EventType.ConnectionLost)
|
||||
{
|
||||
var exception = E.Extra as Exception;
|
||||
ServerLogger.LogError(exception,
|
||||
@ -304,7 +309,7 @@ namespace IW4MAdmin
|
||||
Throttled = true;
|
||||
}
|
||||
|
||||
if (E.Type == GameEvent.EventType.ConnectionRestored)
|
||||
else if (E.Type == GameEvent.EventType.ConnectionRestored)
|
||||
{
|
||||
ServerLogger.LogInformation(
|
||||
"Connection restored with {server}", ToString());
|
||||
@ -322,7 +327,7 @@ namespace IW4MAdmin
|
||||
Throttled = false;
|
||||
}
|
||||
|
||||
if (E.Type == GameEvent.EventType.ChangePermission)
|
||||
else if (E.Type == GameEvent.EventType.ChangePermission)
|
||||
{
|
||||
var newPermission = (Permission) E.Extra;
|
||||
ServerLogger.LogInformation("{origin} is setting {target} to permission level {newPermission}",
|
||||
@ -614,7 +619,7 @@ namespace IW4MAdmin
|
||||
await OnClientUpdate(E.Origin);
|
||||
}
|
||||
|
||||
if (E.Type == GameEvent.EventType.Say)
|
||||
else if (E.Type == GameEvent.EventType.Say)
|
||||
{
|
||||
if (E.Data?.Length > 0)
|
||||
{
|
||||
@ -644,7 +649,7 @@ namespace IW4MAdmin
|
||||
}
|
||||
}
|
||||
|
||||
if (E.Type == GameEvent.EventType.MapChange)
|
||||
else if (E.Type == GameEvent.EventType.MapChange)
|
||||
{
|
||||
ServerLogger.LogInformation("New map loaded - {clientCount} active players", ClientNum);
|
||||
|
||||
@ -685,7 +690,7 @@ namespace IW4MAdmin
|
||||
}
|
||||
}
|
||||
|
||||
if (E.Type == GameEvent.EventType.MapEnd)
|
||||
else if (E.Type == GameEvent.EventType.MapEnd)
|
||||
{
|
||||
ServerLogger.LogInformation("Game ending...");
|
||||
|
||||
@ -695,12 +700,12 @@ namespace IW4MAdmin
|
||||
}
|
||||
}
|
||||
|
||||
if (E.Type == GameEvent.EventType.Tell)
|
||||
else if (E.Type == GameEvent.EventType.Tell)
|
||||
{
|
||||
await Tell(E.Message, E.Target);
|
||||
}
|
||||
|
||||
if (E.Type == GameEvent.EventType.Broadcast)
|
||||
else if (E.Type == GameEvent.EventType.Broadcast)
|
||||
{
|
||||
if (!Utilities.IsDevelopment && E.Data != null) // hides broadcast when in development mode
|
||||
{
|
||||
|
@ -18,6 +18,7 @@ using SharedLibraryCore.Repositories;
|
||||
using SharedLibraryCore.Services;
|
||||
using Stats.Dtos;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
@ -112,10 +113,11 @@ namespace IW4MAdmin.Application
|
||||
var tasks = new[]
|
||||
{
|
||||
versionChecker.CheckVersion(),
|
||||
_serverManager.Init(),
|
||||
_applicationTask
|
||||
};
|
||||
|
||||
await _serverManager.Init();
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
@ -138,11 +140,8 @@ namespace IW4MAdmin.Application
|
||||
|
||||
if (e is ConfigurationException configException)
|
||||
{
|
||||
if (translationLookup != null)
|
||||
{
|
||||
Console.WriteLine(translationLookup[configException.Message]
|
||||
.FormatExt(configException.ConfigurationFileName));
|
||||
}
|
||||
Console.WriteLine("{{fileName}} contains an error."
|
||||
.FormatExt(Path.GetFileName(configException.ConfigurationFileName)));
|
||||
|
||||
foreach (var error in configException.Errors)
|
||||
{
|
||||
|
@ -59,7 +59,7 @@ namespace IW4MAdmin.Application.Misc
|
||||
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ConfigurationException("MANAGER_CONFIGURATION_ERROR")
|
||||
throw new ConfigurationException("Could not load configuration")
|
||||
{
|
||||
Errors = new[] { e.Message },
|
||||
ConfigurationFileName = FileName
|
||||
|
@ -223,8 +223,11 @@ namespace IW4MAdmin.Application.Misc
|
||||
|
||||
public async Task OnEventAsync(GameEvent gameEvent, Server server)
|
||||
{
|
||||
if (_successfullyLoaded)
|
||||
if (!_successfullyLoaded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await _onProcessing.WaitAsync();
|
||||
@ -266,7 +269,6 @@ namespace IW4MAdmin.Application.Misc
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Task OnLoadAsync(IManager manager)
|
||||
{
|
||||
|
@ -34,6 +34,11 @@ init()
|
||||
level.eventCallbacks[level.eventTypes.executeCommandRequested] = ::OnExecuteCommand;
|
||||
level.eventCallbacks[level.eventTypes.setClientDataCompleted] = ::OnSetClientDataCompleted;
|
||||
|
||||
if ( GetDvarInt( "sv_iw4madmin_integration_enabled" ) != 1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// start long running tasks
|
||||
level thread MonitorClientEvents();
|
||||
level thread MonitorBus();
|
||||
@ -61,6 +66,7 @@ OnPlayerConnect()
|
||||
|
||||
player thread OnPlayerSpawned();
|
||||
player thread PlayerTrackingOnInterval();
|
||||
player ToggleNightMode();
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,7 +100,7 @@ OnGameEnded()
|
||||
{
|
||||
level waittill( "game_ended" );
|
||||
// note: you can run data code here but it's possible for
|
||||
// data to get trucated, so we will try a timer based approach for now
|
||||
// data to get truncated, so we will try a timer based approach for now
|
||||
}
|
||||
}
|
||||
|
||||
@ -228,15 +234,16 @@ SaveTrackingMetrics()
|
||||
{
|
||||
if ( level.iw4adminIntegrationDebug == 1 )
|
||||
{
|
||||
self IPrintLn( "Saving tracking metrics for " + self.persistentClientId );
|
||||
IPrintLn( "Saving tracking metrics for " + self.persistentClientId );
|
||||
}
|
||||
|
||||
currentShotCount = self getPlayerStat( "mostshotsfired" );
|
||||
change = currentShotCount - self.lastShotCount;
|
||||
self.lastShotCount = currentShotCount;
|
||||
|
||||
if ( level.iw4adminIntegrationDebug == 1 )
|
||||
{
|
||||
self IPrintLn( "Total Shots Fired increased by " + change );
|
||||
IPrintLn( "Total Shots Fired increased by " + change );
|
||||
}
|
||||
|
||||
if ( !IsDefined( change ) )
|
||||
@ -251,7 +258,6 @@ SaveTrackingMetrics()
|
||||
|
||||
IncrementClientMeta( "TotalShotsFired", change, self.persistentClientId );
|
||||
|
||||
self.lastShotCount = currentShotCount;
|
||||
}
|
||||
|
||||
BuildEventRequest( responseExpected, eventType, eventSubtype, entOrId, data )
|
||||
@ -391,18 +397,22 @@ NotifyClientEventTimeout( eventType )
|
||||
|
||||
NotifyClientEvent( eventInfo )
|
||||
{
|
||||
client = getPlayerFromClientNum( int( eventInfo[3] ) );
|
||||
origin = getPlayerFromClientNum( int( eventInfo[3] ) );
|
||||
target = getPlayerFromClientNum( int( eventInfo[4] ) );
|
||||
|
||||
event = spawnstruct();
|
||||
event.type = eventInfo[1];
|
||||
event.subtype = eventInfo[2];
|
||||
event.data = eventInfo[4];
|
||||
event.data = eventInfo[5];
|
||||
event.origin = origin;
|
||||
event.target = target;
|
||||
|
||||
if ( level.iw4adminIntegrationDebug == 1 )
|
||||
{
|
||||
IPrintLn(event.data);
|
||||
IPrintLn( "NotifyClientEvent->" + event.data );
|
||||
}
|
||||
|
||||
client = event.origin;
|
||||
client.event = event;
|
||||
|
||||
level notify( level.eventTypes.localClientEvent, client );
|
||||
@ -452,33 +462,56 @@ OnClientDataReceived( event )
|
||||
OnExecuteCommand( event )
|
||||
{
|
||||
data = ParseDataString( event.data );
|
||||
response = "";
|
||||
|
||||
switch ( event.subtype )
|
||||
{
|
||||
case "GiveWeapon":
|
||||
self GiveWeaponImpl( data );
|
||||
response = event.target GiveWeaponImpl( data );
|
||||
break;
|
||||
case "TakeWeapons":
|
||||
self TakeWeaponsImpl();
|
||||
response = event.target TakeWeaponsImpl();
|
||||
break;
|
||||
case "SwitchTeams":
|
||||
self TeamSwitchImpl();
|
||||
response = event.target TeamSwitchImpl();
|
||||
break;
|
||||
case "Hide":
|
||||
self HideImpl();
|
||||
response = self HideImpl();
|
||||
break;
|
||||
case "Unhide":
|
||||
self UnhideImpl();
|
||||
response = self UnhideImpl();
|
||||
break;
|
||||
case "Alert":
|
||||
self AlertImpl( data );
|
||||
response = event.target AlertImpl( data );
|
||||
break;
|
||||
case "Goto":
|
||||
if ( IsDefined( event.target ) )
|
||||
{
|
||||
response = self GotoPlayerImpl( event.target );
|
||||
}
|
||||
else
|
||||
{
|
||||
response = self GotoImpl( event.data );
|
||||
}
|
||||
break;
|
||||
case "Kill":
|
||||
response = event.target KillImpl();
|
||||
break;
|
||||
case "NightMode":
|
||||
NightModeImpl();
|
||||
break;
|
||||
}
|
||||
|
||||
// send back the response to the origin, but only if they're not the target
|
||||
if ( response != "" && IsPlayer( event.origin ) && event.origin != event.target )
|
||||
{
|
||||
event.origin IPrintLnBold( response );
|
||||
}
|
||||
}
|
||||
|
||||
OnSetClientDataCompleted( event )
|
||||
{
|
||||
// IW4MAdmin let us know it persisted (success or fail)
|
||||
|
||||
if ( level.iw4adminIntegrationDebug == 1 )
|
||||
{
|
||||
IPrintLn( "Set Client Data -> subtype = " + event.subType + " status = " + event.data["status"] );
|
||||
@ -491,54 +524,181 @@ OnSetClientDataCompleted( event )
|
||||
|
||||
GiveWeaponImpl( data )
|
||||
{
|
||||
if ( IsAlive( self ) )
|
||||
if ( !IsAlive( self ) )
|
||||
{
|
||||
return self.name + "^7 is not alive";
|
||||
}
|
||||
|
||||
self IPrintLnBold( "You have been given a new weapon" );
|
||||
self GiveWeapon( data["weaponName"] );
|
||||
self SwitchToWeapon( data["weaponName"] );
|
||||
}
|
||||
|
||||
return self.name + "^7 has been given ^5" + data["weaponName"];
|
||||
}
|
||||
|
||||
TakeWeaponsImpl()
|
||||
{
|
||||
if ( IsAlive( self ) )
|
||||
if ( !IsAlive( self ) )
|
||||
{
|
||||
return self.name + "^7 is not alive";
|
||||
}
|
||||
|
||||
self TakeAllWeapons();
|
||||
self IPrintLnBold( "All your weapons have been taken" );
|
||||
}
|
||||
|
||||
return "Took weapons from " + self.name;
|
||||
}
|
||||
|
||||
TeamSwitchImpl()
|
||||
{
|
||||
if ( !IsAlive( self ) )
|
||||
{
|
||||
return self.name + "^7 is not alive";
|
||||
}
|
||||
|
||||
team = level.allies;
|
||||
|
||||
if ( self.team == "allies" )
|
||||
{
|
||||
self [[level.axis]]();
|
||||
}
|
||||
else
|
||||
{
|
||||
self [[level.allies]]();
|
||||
team = level.axis;
|
||||
}
|
||||
|
||||
self IPrintLnBold( "You are being team switched" );
|
||||
wait( 2 );
|
||||
self [[team]]();
|
||||
|
||||
return self.name + "^7 switched to " + self.team;
|
||||
}
|
||||
|
||||
HideImpl()
|
||||
{
|
||||
if ( IsAlive( self ) )
|
||||
if ( !IsAlive( self ) )
|
||||
{
|
||||
self Hide();
|
||||
self IPrintLnBold( "You are now hidden" );
|
||||
self IPrintLnBold( "You are not alive" );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( self.isHidden )
|
||||
{
|
||||
self IPrintLnBold( "You are already hidden" );
|
||||
return;
|
||||
}
|
||||
|
||||
self SetClientDvar( "sv_cheats", 1 );
|
||||
self SetClientDvar( "cg_thirdperson", 1 );
|
||||
self SetClientDvar( "sv_cheats", 0 );
|
||||
|
||||
self.savedHealth = self.health;
|
||||
self.health = 9999;
|
||||
self.isHidden = true;
|
||||
|
||||
self Hide();
|
||||
|
||||
self IPrintLnBold( "You are now ^5hidden ^7from other players" );
|
||||
}
|
||||
|
||||
UnhideImpl()
|
||||
{
|
||||
if ( IsAlive( self ) )
|
||||
if ( !IsAlive( self ) )
|
||||
{
|
||||
self Show();
|
||||
self IPrintLnBold( "You are now visible" );
|
||||
self IPrintLnBold( "You are not alive" );
|
||||
return;
|
||||
}
|
||||
|
||||
self SetClientDvar( "sv_cheats", 1 );
|
||||
self SetClientDvar( "cg_thirdperson", 0 );
|
||||
self SetClientDvar( "sv_cheats", 0 );
|
||||
|
||||
self.health = self.savedHealth;
|
||||
self.isHidden = false;
|
||||
|
||||
self Show();
|
||||
self IPrintLnBold( "You are now ^5visible ^7to other players" );
|
||||
}
|
||||
|
||||
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 );
|
||||
return "Sent alert to " + self.name;
|
||||
}
|
||||
|
||||
GotoImpl( data )
|
||||
{
|
||||
if ( !IsAlive( self ) )
|
||||
{
|
||||
self IPrintLnBold( "You are not alive" );
|
||||
return;
|
||||
}
|
||||
|
||||
position = ( int(data["x"]), int(data["y"]), int(data["z"]) );
|
||||
self SetOrigin( position );
|
||||
self IPrintLnBold( "Moved to " + "("+ position[0] + "," + position[1] + "," + position[2] + ")" );
|
||||
}
|
||||
|
||||
GotoPlayerImpl( target )
|
||||
{
|
||||
if ( !IsAlive( target ) )
|
||||
{
|
||||
self IPrintLnBold( target.name + " is not alive" );
|
||||
return;
|
||||
}
|
||||
|
||||
self SetOrigin( target GetOrigin() );
|
||||
self IPrintLnBold( "Moved to " + target.name );
|
||||
}
|
||||
|
||||
KillImpl()
|
||||
{
|
||||
if ( !IsAlive( self ) )
|
||||
{
|
||||
return self.name + " is not alive";
|
||||
}
|
||||
|
||||
self Suicide();
|
||||
self IPrintLnBold( "You were killed by " + self.name );
|
||||
|
||||
return "You killed " + self.name;
|
||||
}
|
||||
|
||||
NightModeImpl()
|
||||
{
|
||||
if ( !IsDefined ( level.nightModeEnabled ) )
|
||||
{
|
||||
level.nightModeEnabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
level.nightModeEnabled = !level.nightModeEnabled;
|
||||
}
|
||||
|
||||
message = "^5NightMode ^7is disabled";
|
||||
|
||||
if ( level.nightModeEnabled )
|
||||
{
|
||||
message = "^5NightMode ^7is enabled";
|
||||
}
|
||||
|
||||
IPrintLnBold( message );
|
||||
|
||||
foreach( player in level.players )
|
||||
{
|
||||
self ToggleNightMode();
|
||||
}
|
||||
}
|
||||
|
||||
ToggleNightMode()
|
||||
{
|
||||
colorMap = 1;
|
||||
fxDraw = 1;
|
||||
|
||||
if ( IsDefined( level.nightModeEnabled ) && level.nightModeEnabled )
|
||||
{
|
||||
colorMap = 0;
|
||||
fxDraw = 0;
|
||||
}
|
||||
|
||||
self SetClientDvar( "sv_cheats", 1 );
|
||||
self SetClientDvar( "r_colorMap", colorMap );
|
||||
self SetClientDvar( "fx_draw", fxDraw );
|
||||
self SetClientDvar( "sv_cheats", 0 );
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
||||
version.txt = version.txt
|
||||
DeploymentFiles\UpdateIW4MAdmin.ps1 = DeploymentFiles\UpdateIW4MAdmin.ps1
|
||||
DeploymentFiles\UpdateIW4MAdmin.sh = DeploymentFiles\UpdateIW4MAdmin.sh
|
||||
GameFiles\IW4x\userraw\scripts\_integration.gsc = GameFiles\IW4x\userraw\scripts\_integration.gsc
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharedLibraryCore", "SharedLibraryCore\SharedLibraryCore.csproj", "{AA0541A2-8D51-4AD9-B0AC-3D1F5B162481}"
|
||||
|
@ -17,9 +17,13 @@ let plugin = {
|
||||
name: 'Game Interface',
|
||||
|
||||
onEventAsync: (gameEvent, server) => {
|
||||
if (servers[server.EndPoint] != null && !servers[server.EndPoint].enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
const eventType = eventTypes[gameEvent.Type];
|
||||
|
||||
if (servers[server.EndPoint] != null && !servers[server.EndPoint].enabled) {
|
||||
if (eventType === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -33,7 +37,7 @@ let plugin = {
|
||||
break;
|
||||
case 'preconnect':
|
||||
// when the plugin is reloaded after the servers are started
|
||||
if (servers[server.EndPoint] == null) {
|
||||
if (servers[server.EndPoint] === undefined || servers[server.EndPoint] == null) {
|
||||
const enabled = initialize(server);
|
||||
|
||||
if (!enabled) {
|
||||
@ -73,118 +77,84 @@ let plugin = {
|
||||
};
|
||||
|
||||
let commands = [{
|
||||
// required
|
||||
name: 'giveweapon',
|
||||
// required
|
||||
description: 'gives specified weapon',
|
||||
// required
|
||||
alias: 'gw',
|
||||
// required
|
||||
permission: 'SeniorAdmin',
|
||||
// optional (defaults to false)
|
||||
targetRequired: false,
|
||||
// optional
|
||||
targetRequired: true,
|
||||
arguments: [{
|
||||
name: 'player',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
name: 'weapon name',
|
||||
required: true
|
||||
}],
|
||||
supportedGames: ['IW4'],
|
||||
// required
|
||||
execute: (gameEvent) => {
|
||||
sendScriptCommand(gameEvent.Owner, 'GiveWeapon', gameEvent.Origin, {weaponName: gameEvent.Data});
|
||||
sendScriptCommand(gameEvent.Owner, 'GiveWeapon', gameEvent.Origin, gameEvent.Target, {weaponName: gameEvent.Data});
|
||||
}
|
||||
},
|
||||
{
|
||||
// required
|
||||
name: 'takeweapons',
|
||||
// required
|
||||
description: 'take all weapons from specifies player',
|
||||
// required
|
||||
description: 'take all weapons from specified player',
|
||||
alias: 'tw',
|
||||
// required
|
||||
permission: 'SeniorAdmin',
|
||||
// optional (defaults to false)
|
||||
targetRequired: true,
|
||||
// optional
|
||||
arguments: [],
|
||||
supportedGames: ['IW4'],
|
||||
// required
|
||||
execute: (gameEvent) => {
|
||||
sendScriptCommand(gameEvent.Owner, 'TakeWeapons', gameEvent.Target, undefined);
|
||||
}
|
||||
},
|
||||
{
|
||||
// required
|
||||
name: 'switchteam',
|
||||
// required
|
||||
description: 'switches specified player to the opposite team',
|
||||
// required
|
||||
alias: 'st',
|
||||
// required
|
||||
permission: 'Administrator',
|
||||
// optional (defaults to false)
|
||||
targetRequired: true,
|
||||
// optional
|
||||
arguments: [{
|
||||
name: 'player',
|
||||
required: true
|
||||
}],
|
||||
supportedGames: ['IW4'],
|
||||
// required
|
||||
execute: (gameEvent) => {
|
||||
sendScriptCommand(gameEvent.Owner, 'SwitchTeams', gameEvent.Target, undefined);
|
||||
sendScriptCommand(gameEvent.Owner, 'TakeWeapons', gameEvent.Origin, gameEvent.Target, undefined);
|
||||
}
|
||||
},
|
||||
{
|
||||
// required
|
||||
name: 'hide',
|
||||
// required
|
||||
description: 'hide yourself',
|
||||
// required
|
||||
alias: 'hi',
|
||||
// required
|
||||
permission: 'SeniorAdmin',
|
||||
// optional (defaults to false)
|
||||
targetRequired: false,
|
||||
// optional
|
||||
arguments: [],
|
||||
supportedGames: ['IW4'],
|
||||
// required
|
||||
execute: (gameEvent) => {
|
||||
sendScriptCommand(gameEvent.Owner, 'Hide', gameEvent.Origin, undefined);
|
||||
}
|
||||
},
|
||||
{
|
||||
// required
|
||||
name: 'unhide',
|
||||
// required
|
||||
description: 'unhide yourself',
|
||||
// required
|
||||
alias: 'unh',
|
||||
// required
|
||||
permission: 'SeniorAdmin',
|
||||
// optional (defaults to false)
|
||||
targetRequired: false,
|
||||
// optional
|
||||
arguments: [],
|
||||
supportedGames: ['IW4'],
|
||||
// required
|
||||
execute: (gameEvent) => {
|
||||
sendScriptCommand(gameEvent.Owner, 'Unhide', gameEvent.Origin, undefined);
|
||||
}
|
||||
},
|
||||
{
|
||||
// required
|
||||
name: 'alert',
|
||||
// required
|
||||
description: 'alert a player',
|
||||
// required
|
||||
alias: 'alr',
|
||||
// required
|
||||
permission: 'SeniorAdmin',
|
||||
// optional (defaults to false)
|
||||
name: 'switchteam',
|
||||
description: 'switches specified player to the opposite team',
|
||||
alias: 'st',
|
||||
permission: 'Administrator',
|
||||
targetRequired: true,
|
||||
arguments: [{
|
||||
name: 'player',
|
||||
required: true
|
||||
}],
|
||||
supportedGames: ['IW4'],
|
||||
execute: (gameEvent) => {
|
||||
sendScriptCommand(gameEvent.Owner, 'SwitchTeams', gameEvent.Origin, gameEvent.Target, undefined);
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'hide',
|
||||
description: 'hide yourself',
|
||||
alias: 'hi',
|
||||
permission: 'SeniorAdmin',
|
||||
targetRequired: false,
|
||||
arguments: [],
|
||||
supportedGames: ['IW4'],
|
||||
execute: (gameEvent) => {
|
||||
sendScriptCommand(gameEvent.Owner, 'Hide', gameEvent.Origin, gameEvent.Origin, undefined);
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'unhide',
|
||||
description: 'unhide yourself',
|
||||
alias: 'unh',
|
||||
permission: 'SeniorAdmin',
|
||||
targetRequired: false,
|
||||
arguments: [],
|
||||
supportedGames: ['IW4'],
|
||||
execute: (gameEvent) => {
|
||||
sendScriptCommand(gameEvent.Owner, 'Unhide', gameEvent.Origin, gameEvent.Origin, undefined);
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'alert',
|
||||
description: 'alert a player',
|
||||
alias: 'alr',
|
||||
permission: 'SeniorAdmin',
|
||||
targetRequired: true,
|
||||
// optional
|
||||
arguments: [{
|
||||
name: 'player',
|
||||
required: true
|
||||
@ -194,31 +164,100 @@ let commands = [{
|
||||
required: true
|
||||
}],
|
||||
supportedGames: ['IW4'],
|
||||
// required
|
||||
execute: (gameEvent) => {
|
||||
sendScriptCommand(gameEvent.Owner, 'Alert', gameEvent.Target, {
|
||||
sendScriptCommand(gameEvent.Owner, 'Alert', gameEvent.Origin, gameEvent.Target, {
|
||||
alertType: 'Alert',
|
||||
message: gameEvent.Data
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'gotoplayer',
|
||||
description: 'teleport to a player',
|
||||
alias: 'g2p',
|
||||
permission: 'SeniorAdmin',
|
||||
targetRequired: true,
|
||||
arguments: [{
|
||||
name: 'player',
|
||||
required: true
|
||||
}],
|
||||
supportedGames: ['IW4'],
|
||||
execute: (gameEvent) => {
|
||||
sendScriptCommand(gameEvent.Owner, 'Goto', gameEvent.Origin, gameEvent.Target, undefined);
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'goto',
|
||||
description: 'teleport to a position',
|
||||
alias: 'g2',
|
||||
permission: 'SeniorAdmin',
|
||||
targetRequired: false,
|
||||
arguments: [{
|
||||
name: 'x',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
name: 'y',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
name: 'z',
|
||||
required: true
|
||||
}],
|
||||
supportedGames: ['IW4'],
|
||||
execute: (gameEvent) => {
|
||||
const args = String(gameEvent.Data).split(' ');
|
||||
sendScriptCommand(gameEvent.Owner, 'Goto', gameEvent.Origin, gameEvent.Target, {
|
||||
x: args[0],
|
||||
y: args[1],
|
||||
z: args[2]
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'kill',
|
||||
description: 'kill a player',
|
||||
alias: 'kpl',
|
||||
permission: 'SeniorAdmin',
|
||||
targetRequired: true,
|
||||
arguments: [{
|
||||
name: 'player',
|
||||
required: true
|
||||
}],
|
||||
supportedGames: ['IW4'],
|
||||
execute: (gameEvent) => {
|
||||
sendScriptCommand(gameEvent.Owner, 'Kill', gameEvent.Origin, gameEvent.Target, undefined);
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'nightmode',
|
||||
description: 'sets server into nightmode',
|
||||
alias: 'nitem',
|
||||
permission: 'SeniorAdmin',
|
||||
targetRequired: false,
|
||||
arguments: [],
|
||||
supportedGames: ['IW4'],
|
||||
execute: (gameEvent) => {
|
||||
sendScriptCommand(gameEvent.Owner, 'NightMode', gameEvent.Origin, undefined, undefined);
|
||||
}
|
||||
}];
|
||||
|
||||
const sendScriptCommand = (server, command, target, data) => {
|
||||
const sendScriptCommand = (server, command, origin, target, data) => {
|
||||
const state = servers[server.EndPoint];
|
||||
if (state === undefined || !state.enabled) {
|
||||
return;
|
||||
}
|
||||
sendEvent(server, false, 'ExecuteCommandRequested', command, target, data);
|
||||
sendEvent(server, false, 'ExecuteCommandRequested', command, origin, target, data);
|
||||
}
|
||||
|
||||
const sendEvent = (server, responseExpected, event, subtype, client, data) => {
|
||||
const sendEvent = (server, responseExpected, event, subtype, origin, target, data) => {
|
||||
const logger = _serviceResolver.ResolveService('ILogger');
|
||||
|
||||
let pendingOut = true;
|
||||
let pendingCheckCount = 0;
|
||||
const start = new Date();
|
||||
|
||||
while (pendingOut && pendingCheckCount <= 30) {
|
||||
while (pendingOut && pendingCheckCount <= 10) {
|
||||
try {
|
||||
const out = server.GetServerDvar(outDvar);
|
||||
pendingOut = !(out == null || out === '' || out === 'null');
|
||||
@ -237,7 +276,12 @@ const sendEvent = (server, responseExpected, event, subtype, client, data) => {
|
||||
logger.WriteWarning(`Reached maximum attempts waiting for output to be available for ${server.EndPoint}`)
|
||||
}
|
||||
|
||||
const output = `${responseExpected ? '1' : '0'};${event};${subtype};${client.ClientNumber};${buildDataString(data)}`;
|
||||
let targetClientNumber = -1;
|
||||
if (target != null) {
|
||||
targetClientNumber = target.ClientNumber;
|
||||
}
|
||||
|
||||
const output = `${responseExpected ? '1' : '0'};${event};${subtype};${origin.ClientNumber};${targetClientNumber};${buildDataString(data)}`;
|
||||
logger.WriteDebug(`Sending output to server ${output}`);
|
||||
|
||||
try {
|
||||
@ -265,6 +309,11 @@ const parseEvent = (input) => {
|
||||
|
||||
const initialize = (server) => {
|
||||
const logger = _serviceResolver.ResolveService('ILogger');
|
||||
|
||||
servers[server.EndPoint] = {
|
||||
enabled: false
|
||||
}
|
||||
|
||||
let enabled = false;
|
||||
try {
|
||||
enabled = server.GetServerDvar('sv_iw4madmin_integration_enabled') === '1';
|
||||
@ -275,9 +324,6 @@ const initialize = (server) => {
|
||||
logger.WriteInfo(`GSC Integration enabled = ${enabled}`);
|
||||
|
||||
if (!enabled) {
|
||||
servers[server.EndPoint] = {
|
||||
enabled: false
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -288,10 +334,8 @@ const initialize = (server) => {
|
||||
// necessary to prevent multi-threaded access to the JS context
|
||||
timer.SetDependency(_lock);
|
||||
|
||||
servers[server.EndPoint] = {
|
||||
timer: timer,
|
||||
enabled: true
|
||||
}
|
||||
servers[server.EndPoint].timer = timer;
|
||||
servers[server.EndPoint].enabled = true;
|
||||
|
||||
try {
|
||||
server.SetServerDvar(inDvar, '');
|
||||
@ -344,10 +388,10 @@ const pollForEvents = server => {
|
||||
};
|
||||
}
|
||||
|
||||
sendEvent(server, false, 'ClientDataReceived', event.subType, client, data);
|
||||
sendEvent(server, false, 'ClientDataReceived', event.subType, client, undefined, data);
|
||||
} else {
|
||||
logger.WriteWarning(`Could not find client slot ${event.clientNumber} when processing ${event.eventType}`);
|
||||
sendEvent(server, false, 'ClientDataReceived', 'Fail', {ClientNumber: event.clientNumber}, undefined);
|
||||
sendEvent(server, false, 'ClientDataReceived', 'Fail', event.clientNumber, undefined, {ClientNumber: event.clientNumber});
|
||||
}
|
||||
}
|
||||
|
||||
@ -365,7 +409,7 @@ const pollForEvents = server => {
|
||||
|
||||
if (clientId == null) {
|
||||
logger.WriteWarning(`Could not find client slot ${event.clientNumber} when processing ${event.eventType}`);
|
||||
sendEvent(server, false, 'SetClientDataCompleted', 'Meta', {ClientNumber: event.clientNumber}, {status: 'Fail'});
|
||||
sendEvent(server, false, 'SetClientDataCompleted', 'Meta', {ClientNumber: event.clientNumber}, undefined, {status: 'Fail'});
|
||||
} else {
|
||||
if (event.subType === 'Meta') {
|
||||
const metaService = _serviceResolver.ResolveService('IMetaService');
|
||||
@ -378,9 +422,9 @@ const pollForEvents = server => {
|
||||
} else {
|
||||
metaService.SetPersistentMeta(event.data['key'], event.data['value'], clientId).GetAwaiter().GetResult();
|
||||
}
|
||||
sendEvent(server, false, 'SetClientDataCompleted', 'Meta', {ClientNumber: event.clientNumber}, {status: 'Complete'});
|
||||
sendEvent(server, false, 'SetClientDataCompleted', 'Meta', {ClientNumber: event.clientNumber}, undefined,{status: 'Complete'});
|
||||
} catch (error) {
|
||||
sendEvent(server, false, 'SetClientDataCompleted', 'Meta', {ClientNumber: event.clientNumber}, {status: 'Fail'});
|
||||
sendEvent(server, false, 'SetClientDataCompleted', 'Meta', {ClientNumber: event.clientNumber}, undefined,{status: 'Fail'});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -391,8 +435,7 @@ const pollForEvents = server => {
|
||||
} catch (error) {
|
||||
logger.WriteError(`Could not reset in bus value for ${server.EndPoint} - ${error}`);
|
||||
}
|
||||
}
|
||||
else if (server.ClientNum === 0) {
|
||||
} else if (server.ClientNum === 0) {
|
||||
servers[server.EndPoint].timer.Stop();
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ Latest binary builds are always available at:
|
||||
**IW4MAdmin** requires minimal effort to get up and running.
|
||||
### Prerequisites
|
||||
* [.NET Core 6.0.x Runtime](https://www.microsoft.com/net/download)
|
||||
* [Direct Download (Windows)](https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-aspnetcore-6.0.1-windows-x64-installer)
|
||||
* [Direct Download (Windows)](https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-aspnetcore-6.0.1-windows-hosting-bundle-installer)
|
||||
* [Package Installation Instructions (Linux)](https://docs.microsoft.com/en-us/dotnet/core/install/linux)
|
||||
### Installation
|
||||
1. Install .NET Core Runtime
|
||||
|
@ -23,7 +23,8 @@ namespace SharedLibraryCore.Interfaces
|
||||
/// </summary>
|
||||
/// <param name="fileSizeDiff"></param>
|
||||
/// <param name="startPosition"></param>
|
||||
/// <param name="server"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<GameEvent>> ReadEventsFromLog(long fileSizeDiff, long startPosition);
|
||||
Task<IEnumerable<GameEvent>> ReadEventsFromLog(long fileSizeDiff, long startPosition, Server server);
|
||||
}
|
||||
}
|
@ -390,17 +390,48 @@ namespace SharedLibraryCore
|
||||
|
||||
public string[] ExecuteServerCommand(string command)
|
||||
{
|
||||
return this.ExecuteCommandAsync(command).GetAwaiter().GetResult();
|
||||
var tokenSource = new CancellationTokenSource();
|
||||
tokenSource.CancelAfter(TimeSpan.FromMilliseconds(400));
|
||||
|
||||
try
|
||||
{
|
||||
return this.ExecuteCommandAsync(command).WithWaitCancellation(tokenSource.Token).GetAwaiter().GetResult();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public string GetServerDvar(string dvarName)
|
||||
{
|
||||
return this.GetDvarAsync<string>(dvarName).GetAwaiter().GetResult()?.Value;
|
||||
var tokenSource = new CancellationTokenSource();
|
||||
tokenSource.CancelAfter(TimeSpan.FromMilliseconds(400));
|
||||
try
|
||||
{
|
||||
return this.GetDvarAsync<string>(dvarName).WithWaitCancellation(tokenSource.Token).GetAwaiter()
|
||||
.GetResult()?.Value;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetServerDvar(string dvarName, string dvarValue)
|
||||
public bool SetServerDvar(string dvarName, string dvarValue)
|
||||
{
|
||||
this.SetDvarAsync(dvarName, dvarValue).GetAwaiter().GetResult();
|
||||
var tokenSource = new CancellationTokenSource();
|
||||
tokenSource.CancelAfter(TimeSpan.FromMilliseconds(400));
|
||||
try
|
||||
{
|
||||
this.SetDvarAsync(dvarName, dvarValue).WithWaitCancellation(tokenSource.Token).GetAwaiter().GetResult();
|
||||
return true;
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public EFClient GetClientByNumber(int clientNumber) =>
|
||||
|
@ -956,6 +956,19 @@ namespace SharedLibraryCore
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<T> WithWaitCancellation<T>(this Task<T> task,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var completedTask = await Task.WhenAny(task, Task.Delay(Timeout.Infinite, cancellationToken));
|
||||
if (completedTask == task)
|
||||
{
|
||||
return await task;
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
throw new InvalidOperationException("Infinite delay task completed.");
|
||||
}
|
||||
|
||||
public static async Task<T> WithTimeout<T>(this Task<T> task, TimeSpan timeout)
|
||||
{
|
||||
await Task.WhenAny(task, Task.Delay(timeout));
|
||||
|
Reference in New Issue
Block a user