fix issue with game interface meta/provide full example

This commit is contained in:
RaidMax 2022-09-11 11:46:13 -05:00
parent dadd236069
commit 1e1e8bbe7b
4 changed files with 29 additions and 6 deletions

View File

@ -24,7 +24,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Jint" Version="3.0.0-beta-2040" /> <PackageReference Include="Jint" Version="3.0.0-beta-2038" />
<PackageReference Include="MaxMind.GeoIP2" Version="5.1.0" /> <PackageReference Include="MaxMind.GeoIP2" Version="5.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.8"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.8">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>

View File

@ -193,8 +193,6 @@ PlayerSpawnEvents()
} }
self RequestClientBasicData(); self RequestClientBasicData();
// example of requesting meta from IW4MAdmin
// self RequestClientMeta( "LastServerPlayed" );
} }
PlayerTrackingOnInterval() PlayerTrackingOnInterval()
@ -436,7 +434,6 @@ SaveTrackingMetrics()
} }
IncrementClientMeta( "TotalShotsFired", change, self.persistentClientId ); IncrementClientMeta( "TotalShotsFired", change, self.persistentClientId );
} }
BuildEventRequest( responseExpected, eventType, eventSubtype, entOrId, data ) BuildEventRequest( responseExpected, eventType, eventSubtype, entOrId, data )
@ -665,6 +662,8 @@ OnClientDataReceived( event )
metaKey = event.data[0]; metaKey = event.data[0];
clientData.meta[metaKey] = event.data[metaKey]; clientData.meta[metaKey] = event.data[metaKey];
LogDebug( "Meta Key=" + metaKey + ", Meta Value=" + event.data[metaKey] );
return; return;
} }

View File

@ -47,6 +47,7 @@ OnPlayerConnect()
} }
player thread SetPersistentData(); player thread SetPersistentData();
player thread WaitForClientEvents();
} }
} }
@ -67,6 +68,28 @@ RegisterClientCommands()
scripts\_integration_base::AddClientCommand( "NoClip", false, ::NoClipImpl ); scripts\_integration_base::AddClientCommand( "NoClip", false, ::NoClipImpl );
} }
WaitForClientEvents()
{
self endon( "disconnect" );
// example of requesting a meta value
lastServerMetaKey = "LastServerPlayed";
// self scripts\_integration_base::RequestClientMeta( lastServerMetaKey );
for ( ;; )
{
self waittill( level.eventTypes.localClientEvent, event );
scripts\_integration_base::LogDebug( "Received client event " + event.type );
if ( event.type == level.eventTypes.clientDataReceived && event.data[0] == lastServerMetaKey )
{
clientData = self.pers[level.clientDataKey];
lastServerPlayed = clientData.meta[lastServerMetaKey];
}
}
}
GetTotalShotsFired() GetTotalShotsFired()
{ {
return maps\mp\_utility::getPlayerStat( "mostshotsfired" ); return maps\mp\_utility::getPlayerStat( "mostshotsfired" );

View File

@ -465,8 +465,9 @@ function onReceivedDvar(server, dvarName, dvarValue, success) {
if (event.subType === 'Meta') { if (event.subType === 'Meta') {
const metaService = _serviceResolver.ResolveService('IMetaServiceV2'); const metaService = _serviceResolver.ResolveService('IMetaServiceV2');
const meta = metaService.GetPersistentMeta(event.data, client, token).GetAwaiter().GetResult(); const meta = metaService.GetPersistentMeta(event.data, client.ClientId, token).GetAwaiter().GetResult();
data[event.data] = meta === null ? '' : meta.Value; data[event.data] = meta === null ? '' : meta.Value;
logger.WriteDebug(`event data is ${event.data}`);
} else { } else {
data = { data = {
level: client.Level, level: client.Level,
@ -612,7 +613,7 @@ const parseDataString = data => {
dict[keyValue[0]] = keyValue[1]; dict[keyValue[0]] = keyValue[1];
} }
return dict.length === 0 ? data : dict; return Object.keys(dict).length === 0 ? data : dict;
} }
const validateEnabled = (server, origin) => { const validateEnabled = (server, origin) => {