From 3640d1df547b16ed8e63b431cbd38a73a1373a73 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Sat, 12 Feb 2022 21:54:21 -0600 Subject: [PATCH] small updates for game interface --- .../IW4x/userraw/scripts/_integration.gsc | 9 ++++++-- Plugins/ScriptPlugins/GameInterface.js | 22 +++++++++++-------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/GameFiles/IW4x/userraw/scripts/_integration.gsc b/GameFiles/IW4x/userraw/scripts/_integration.gsc index eda3de0ca..8276008a4 100644 --- a/GameFiles/IW4x/userraw/scripts/_integration.gsc +++ b/GameFiles/IW4x/userraw/scripts/_integration.gsc @@ -33,7 +33,12 @@ init() level.eventCallbacks[level.eventTypes.clientDataReceived] = ::OnClientDataReceived; 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(); @@ -233,6 +238,7 @@ SaveTrackingMetrics() currentShotCount = self getPlayerStat( "mostshotsfired" ); change = currentShotCount - self.lastShotCount; + self.lastShotCount = currentShotCount; if ( level.iw4adminIntegrationDebug == 1 ) { @@ -251,7 +257,6 @@ SaveTrackingMetrics() IncrementClientMeta( "TotalShotsFired", change, self.persistentClientId ); - self.lastShotCount = currentShotCount; } BuildEventRequest( responseExpected, eventType, eventSubtype, entOrId, data ) diff --git a/Plugins/ScriptPlugins/GameInterface.js b/Plugins/ScriptPlugins/GameInterface.js index 7bb0b232e..86395c432 100644 --- a/Plugins/ScriptPlugins/GameInterface.js +++ b/Plugins/ScriptPlugins/GameInterface.js @@ -17,12 +17,16 @@ let plugin = { name: 'Game Interface', onEventAsync: (gameEvent, server) => { - const eventType = eventTypes[gameEvent.Type]; - if (servers[server.EndPoint] != null && !servers[server.EndPoint].enabled) { return; } + const eventType = eventTypes[gameEvent.Type]; + + if (eventType === undefined) { + return; + } + switch (eventType) { case 'start': const enabled = initialize(server); @@ -265,6 +269,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 +284,6 @@ const initialize = (server) => { logger.WriteInfo(`GSC Integration enabled = ${enabled}`); if (!enabled) { - servers[server.EndPoint] = { - enabled: false - } return false; } @@ -288,10 +294,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, '');