Skip to content

Commit

Permalink
tweaks and persistent guid update to game integration/interface
Browse files Browse the repository at this point in the history
  • Loading branch information
RaidMax committed Jul 16, 2022
1 parent 790b508 commit b2d4e59
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 35 deletions.
41 changes: 21 additions & 20 deletions Application/IW4MServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using SharedLibraryCore.Interfaces;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
Expand Down Expand Up @@ -771,17 +772,28 @@ await Manager.GetPenaltyService().RemoveActivePenalties(E.Target.AliasLinkId, E.

else if (E.Type == GameEvent.EventType.MetaUpdated)
{
if (E.Extra is "PersistentStatClientId" && int.TryParse(E.Data, out var persistentClientId))
if (E.Extra is "PersistentClientGuid")
{
var penalties = await Manager.GetPenaltyService().GetActivePenaltiesByClientId(persistentClientId);
var banPenalty = penalties.FirstOrDefault(penalty => penalty.Type == EFPenalty.PenaltyType.Ban);
var parts = E.Data.Split(",");

if (banPenalty is not null && E.Origin.Level != Permission.Banned)
if (parts.Length == 2 && int.TryParse(parts[0], out var high) &&
int.TryParse(parts[1], out var low))
{
ServerLogger.LogInformation(
"Banning {Client} as they have have provided a persistent clientId of {PersistentClientId}, which is banned",
E.Origin.ToString(), persistentClientId);
E.Origin.Ban(loc["SERVER_BAN_EVADE"].FormatExt(persistentClientId), Utilities.IW4MAdminClient(this), true);
var guid = long.Parse(high.ToString("X") + low.ToString("X"), NumberStyles.HexNumber);

var penalties = await Manager.GetPenaltyService()
.GetActivePenaltiesByIdentifier(null, guid, (Reference.Game)GameName);
var banPenalty =
penalties.FirstOrDefault(penalty => penalty.Type == EFPenalty.PenaltyType.Ban);

if (banPenalty is not null && E.Origin.Level != Permission.Banned)
{
ServerLogger.LogInformation(
"Banning {Client} as they have have provided a persistent clientId of {PersistentClientId}, which is banned",
E.Origin.ToString(), guid);
E.Origin.Ban(loc["SERVER_BAN_EVADE"].FormatExt(guid),
Utilities.IW4MAdminClient(this), true);
}
}
}
}
Expand Down Expand Up @@ -1289,28 +1301,17 @@ await this.SetDvarAsync("sv_sayname", Manager.GetApplicationSettings().Configura
this.GamePassword = gamePassword.Value;
UpdateMap(mapname);

if (RconParser.CanGenerateLogPath)
if (RconParser.CanGenerateLogPath && string.IsNullOrEmpty(ServerConfig.ManualLogPath))
{
bool needsRestart = false;

if (logsync.Value == 0)
{
await this.SetDvarAsync("g_logsync", 2, Manager.CancellationToken); // set to 2 for continous in other games, clamps to 1 for IW4
needsRestart = true;
}

if (string.IsNullOrWhiteSpace(logfile.Value))
{
logfile.Value = "games_mp.log";
await this.SetDvarAsync("g_log", logfile.Value, Manager.CancellationToken);
needsRestart = true;
}

if (needsRestart)
{
// disabling this for the time being
/*Logger.WriteWarning("Game log file not properly initialized, restarting map...");
await this.ExecuteCommandAsync("map_restart");*/
}

// this DVAR isn't set until the a map is loaded
Expand Down
135 changes: 120 additions & 15 deletions GameFiles/_integration.gsc
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ init()

OnPlayerConnect()
{
level endon ( "disconnect" );
level endon ( "game_ended" );

for ( ;; )
{
level waittill( "connected", player );

level.iw4adminIntegrationDebug = GetDvarInt( "sv_iw4madmin_integration_debug" );

if ( isDefined(player.pers["isBot"]) && player.pers["isBot"] )
if ( isDefined( player.pers["isBot"] ) && player.pers["isBot"] )
{
// we don't want to track bots
continue;
Expand Down Expand Up @@ -104,7 +104,7 @@ OnPlayerSpawned()

OnPlayerDisconnect()
{
level endon ( "disconnect" );
self endon ( "disconnect" );

for ( ;; )
{
Expand Down Expand Up @@ -139,8 +139,6 @@ OnPlayerJoinedSpectators()

OnGameEnded()
{
level endon ( "disconnect" );

for ( ;; )
{
level waittill( "game_ended" );
Expand All @@ -167,24 +165,29 @@ DisplayWelcomeData()

SetPersistentData()
{
storedClientId = self GetPlayerData( "bests", "none" );
guidHigh = self GetPlayerData( "bests", "none" );
guidLow = self GetPlayerData( "awards", "none" );
persistentGuid = guidHigh + "," + guidLow;

if ( storedClientId != 0 )
if ( guidHigh != 0 && guidLow != 0)
{
if ( level.iw4adminIntegrationDebug == 1 )
{
IPrintLn( "Uploading persistent client id " + storedClientId );
IPrintLn( "Uploading persistent guid " + persistentGuid );
}

SetClientMeta( "PersistentStatClientId", storedClientId );
SetClientMeta( "PersistentClientGuid", persistentGuid );
}

if ( level.iw4adminIntegrationDebug == 1 )
{
IPrintLn( "Persisting client id " + self.persistentClientId );
IPrintLn( "Persisting client guid " + persistentGuid );
}

self SetPlayerData( "bests", "none", int( self.persistentClientId ) );
guid = self SplitGuid();

self SetPlayerData( "bests", "none", guid["high"] );
self SetPlayerData( "awards", "none", guid["low"] );
}

PlayerConnectEvents()
Expand Down Expand Up @@ -228,8 +231,7 @@ PlayerTrackingOnInterval()

MonitorClientEvents()
{
level endon( "disconnect" );
self endon( "disconnect" );
level endon( "game_ended" );

for ( ;; )
{
Expand Down Expand Up @@ -324,6 +326,107 @@ DecrementClientMeta( metaKey, decrementValue, clientId )
SetClientMeta( metaKey, decrementValue, clientId, "decrement" );
}

SplitGuid()
{
guid = self GetGuid();

if ( isDefined( self.guid ) )
{
guid = self.guid;
}

firstPart = 0;
secondPart = 0;
stringLength = 17;
firstPartExp = 0;
secondPartExp = 0;

for ( i = stringLength - 1; i > 0; i-- )
{
char = GetSubStr( guid, i - 1, i );
if ( char == "" )
{
char = "0";
}

if ( i > stringLength / 2 )
{
value = GetIntForHexChar( char );
power = Pow( 16, secondPartExp );
secondPart = secondPart + ( value * power );
secondPartExp++;
}
else
{
value = GetIntForHexChar( char );
power = Pow( 16, firstPartExp );
firstPart = firstPart + ( value * power );
firstPartExp++;
}
}

split = [];
split["low"] = int( secondPart );
split["high"] = int( firstPart );

return split;
}

Pow( num, exponent )
{
result = 1;
while( exponent != 0 )
{
result = result * num;
exponent--;
}

return result;
}

GetIntForHexChar( char )
{
char = ToLower( char );
// generated by co-pilot because I can't be bothered to make it more "elegant"
switch( char )
{
case "0":
return 0;
case "1":
return 1;
case "2":
return 2;
case "3":
return 3;
case "4":
return 4;
case "5":
return 5;
case "6":
return 6;
case "7":
return 7;
case "8":
return 8;
case "9":
return 9;
case "a":
return 10;
case "b":
return 11;
case "c":
return 12;
case "d":
return 13;
case "e":
return 14;
case "f":
return 15;
default:
return 0;
}
}

GenerateJoinTeamString( isSpectator )
{
team = self.team;
Expand Down Expand Up @@ -476,7 +579,7 @@ MonitorBus()

QueueEvent( request, eventType, notifyEntity )
{
level endon( "disconnect" );
level endon( "game_ended" );

start = GetTime();
maxWait = level.eventBus.timeout * 1000; // 30 seconds
Expand Down Expand Up @@ -510,6 +613,8 @@ QueueEvent( request, eventType, notifyEntity )
{
notifyEntity NotifyClientEventTimeout( eventType );
}

SetDvar( level.eventBus.inVar, "" );

return;
}
Expand Down Expand Up @@ -923,7 +1028,7 @@ GotoCoordImpl( data )
return;
}

position = ( int(data["x"]), int(data["y"]), int(data["z"]) );
position = ( int( data["x"] ), int( data["y"] ), int( data["z"]) );
self SetOrigin( position );
self IPrintLnBold( "Moved to " + "("+ position[0] + "," + position[1] + "," + position[2] + ")" );
}
Expand Down

0 comments on commit b2d4e59

Please sign in to comment.