Skip to content

Commit

Permalink
fix: Data invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
K4ryuu committed May 19, 2024
1 parent 1089e69 commit 890ca17
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 54 deletions.
68 changes: 34 additions & 34 deletions src/KitsuneSteamRestrict.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,53 +189,53 @@ private void OnPlayerConnectFull(CCSPlayerController player)
}
}

await CheckUserViolations(handle, authorizedSteamID);
Server.NextWorldUpdate(() =>
{
CheckUserViolations(handle, authorizedSteamID);
});
});
}

private async Task CheckUserViolations(nint handle, ulong authorizedSteamID)
private void CheckUserViolations(nint handle, ulong authorizedSteamID)
{
SteamService steamService = new SteamService(this);
await steamService.FetchSteamUserInfo(handle, authorizedSteamID);
steamService.FetchSteamUserInfo(handle, authorizedSteamID);

SteamUserInfo? userInfo = steamService.UserInfo;

Server.NextWorldUpdate(() =>
{
CCSPlayerController? player = Utilities.GetPlayerFromSteamId(authorizedSteamID);
CCSPlayerController? player = Utilities.GetPlayerFromSteamId(authorizedSteamID);

if (player?.IsValid == true && userInfo != null)
if (player?.IsValid == true && userInfo != null)
{
Logger.LogInformation($"{player.PlayerName} info:");
Logger.LogInformation($"CS2Playtime: {userInfo.CS2Playtime}");
Logger.LogInformation($"CS2Level: {userInfo.CS2Level}");
Logger.LogInformation($"SteamLevel: {userInfo.SteamLevel}");
if ((DateTime.Now - userInfo.SteamAccountAge).TotalSeconds > 30)
Logger.LogInformation($"Steam Account Creation Date: {userInfo.SteamAccountAge:dd-MM-yyyy}");
else
Logger.LogInformation($"Steam Account Creation Date: N/A");
Logger.LogInformation($"HasPrime: {userInfo.HasPrime}");
Logger.LogInformation($"HasPrivateProfile: {userInfo.IsPrivate}");
Logger.LogInformation($"IsTradeBanned: {userInfo.IsTradeBanned}");
Logger.LogInformation($"IsGameBanned: {userInfo.IsGameBanned}");
Logger.LogInformation($"IsInSteamGroup: {userInfo.IsInSteamGroup}");

if (IsRestrictionViolated(player, userInfo))
{
Logger.LogInformation($"{player.PlayerName} info:");
Logger.LogInformation($"CS2Playtime: {userInfo.CS2Playtime}");
Logger.LogInformation($"CS2Level: {userInfo.CS2Level}");
Logger.LogInformation($"SteamLevel: {userInfo.SteamLevel}");
if ((DateTime.Now - userInfo.SteamAccountAge).TotalSeconds > 30)
Logger.LogInformation($"Steam Account Creation Date: {userInfo.SteamAccountAge:dd-MM-yyyy}");
else
Logger.LogInformation($"Steam Account Creation Date: N/A");
Logger.LogInformation($"HasPrime: {userInfo.HasPrime}");
Logger.LogInformation($"HasPrivateProfile: {userInfo.IsPrivate}");
Logger.LogInformation($"IsTradeBanned: {userInfo.IsTradeBanned}");
Logger.LogInformation($"IsGameBanned: {userInfo.IsGameBanned}");
Logger.LogInformation($"IsInSteamGroup: {userInfo.IsInSteamGroup}");

if (IsRestrictionViolated(player, userInfo))
{
Server.ExecuteCommand($"kickid {player.UserId} \"You have been kicked for not meeting the minimum requirements.\"");
}
else if (!IsDatabaseConfigDefault())
{
ulong steamID = player.AuthorizedSteamID?.SteamId64 ?? 0;
Server.ExecuteCommand($"kickid {player.UserId} \"You have been kicked for not meeting the minimum requirements.\"");
}
else if (!IsDatabaseConfigDefault())
{
ulong steamID = player.AuthorizedSteamID?.SteamId64 ?? 0;

if (steamID != 0)
{
var databaseService = new DatabaseService(Config.DatabaseSettings);
Task.Run(async () => await databaseService.AddAllowedUserAsync(steamID, Config.DatabaseSettings.TablePurgeDays));
}
if (steamID != 0)
{
var databaseService = new DatabaseService(Config.DatabaseSettings);
Task.Run(async () => await databaseService.AddAllowedUserAsync(steamID, Config.DatabaseSettings.TablePurgeDays));
}
}
});
}
}

private bool IsRestrictionViolated(CCSPlayerController player, SteamUserInfo userInfo)
Expand Down
38 changes: 18 additions & 20 deletions src/Models/SteamService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,28 @@ public SteamService(SteamRestrictPlugin plugin)
_steamWebAPIKey = _config.SteamWebAPI;
}

public async Task FetchSteamUserInfo(nint handle, ulong authorizedSteamID)
public void FetchSteamUserInfo(nint handle, ulong authorizedSteamID)
{
await Server.NextWorldUpdateAsync(() =>
CSteamID cSteamID = new CSteamID(authorizedSteamID);

UserInfo = new SteamUserInfo
{
string steamId = authorizedSteamID.ToString();
CSteamID cSteamID = new CSteamID(authorizedSteamID);
HasPrime = SteamGameServer.UserHasLicenseForApp(cSteamID, (AppId_t)624820) == EUserHasLicenseForAppResult.k_EUserHasLicenseResultHasLicense
|| SteamGameServer.UserHasLicenseForApp(cSteamID, (AppId_t)54029) == EUserHasLicenseForAppResult.k_EUserHasLicenseResultHasLicense,
CS2Level = new CCSPlayerController_InventoryServices(handle).PersonaDataPublicLevel
};

UserInfo = new SteamUserInfo
{
HasPrime = SteamGameServer.UserHasLicenseForApp(cSteamID, (AppId_t)624820) == EUserHasLicenseForAppResult.k_EUserHasLicenseResultHasLicense
|| SteamGameServer.UserHasLicenseForApp(cSteamID, (AppId_t)54029) == EUserHasLicenseForAppResult.k_EUserHasLicenseResultHasLicense,
CS2Level = new CCSPlayerController_InventoryServices(handle).PersonaDataPublicLevel
};
Task.Run(async () => await FetchSteamUserInfo(authorizedSteamID.ToString())).Wait();
}

Task.Run(async () =>
{
UserInfo.CS2Playtime = await FetchCS2PlaytimeAsync(steamId) / 60;
UserInfo.SteamLevel = await FetchSteamLevelAsync(steamId);
await FetchProfilePrivacyAsync(steamId, UserInfo);
await FetchTradeBanStatusAsync(steamId, UserInfo);
await FetchGameBanStatusAsync(steamId, UserInfo);
await FetchSteamGroupMembershipAsync(steamId, UserInfo);
});
});
public async Task FetchSteamUserInfo(string steamId)
{
UserInfo!.CS2Playtime = await FetchCS2PlaytimeAsync(steamId) / 60;
UserInfo.SteamLevel = await FetchSteamLevelAsync(steamId);
await FetchProfilePrivacyAsync(steamId, UserInfo);
await FetchTradeBanStatusAsync(steamId, UserInfo);
await FetchGameBanStatusAsync(steamId, UserInfo);
await FetchSteamGroupMembershipAsync(steamId, UserInfo);
}

private async Task<int> FetchCS2PlaytimeAsync(string steamId)
Expand Down

0 comments on commit 890ca17

Please sign in to comment.