Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for long player authorization #79

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 50 additions & 12 deletions Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ private void RegisterEvents()
RegisterListener<Listeners.OnClientAuthorized>(OnClientAuthorized);
RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
RegisterListener<Listeners.OnMapStart>(OnMapStart);
//RegisterEventHandler<EventPlayerConnectFull>(OnPlayerConnectFull);
RegisterEventHandler<EventPlayerConnectFull>(OnPlayerConnectFull);
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
Expand Down Expand Up @@ -55,37 +55,75 @@ private void OnMapStart(string mapName)
if (Config.GlobalShare)
GlobalShareConnect();
});

g_hTimerCheckSkinsData = AddTimer(10.0f, () =>
{
List<CCSPlayerController> players = Utilities.GetPlayers();

foreach (CCSPlayerController player in players)
{
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || player.SteamID == 0) continue;
if (gPlayerWeaponsInfo.ContainsKey((int)player.Index)) continue;

if (Config.Additional.SkinEnabled && weaponSync != null)
_ = weaponSync.GetWeaponPaintsFromDatabase((int)player.Index);
if (Config.Additional.KnifeEnabled && weaponSync != null)
_ = weaponSync.GetKnifeFromDatabase((int)player.Index);

}
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE | CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT);
}

private void OnClientAuthorized(int playerSlot, SteamID steamID)
{
int playerIndex = playerSlot + 1;

CCSPlayerController? player = Utilities.GetPlayerFromIndex(playerIndex);

if (player == null || !player.IsValid || player.IsHLTV) return;
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return;

if (Config.Additional.SkinEnabled && weaponSync != null)
_ = weaponSync.GetWeaponPaintsFromDatabase(playerIndex);
if (Config.Additional.KnifeEnabled && weaponSync != null)
_ = weaponSync.GetKnifeFromDatabase(playerIndex);
}

/*
Task.Run(async () =>
/* WORKAROUND FOR CLIENTS WITHOUT STEAMID ON AUTHORIZATION */
private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
{
CCSPlayerController? player = @event.Userid;
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return HookResult.Continue;

if (!gPlayerWeaponsInfo.ContainsKey((int)player.Index))
{
Console.WriteLine($"[WeaponPaints] Retrying to retrieve player {player.PlayerName} skins");
if (Config.Additional.SkinEnabled && weaponSync != null)
await weaponSync.GetWeaponPaintsFromDatabase(playerIndex);
_ = weaponSync.GetWeaponPaintsFromDatabase((int)player.Index);
if (Config.Additional.KnifeEnabled && weaponSync != null)
await weaponSync.GetKnifeFromDatabase(playerIndex);
});
*/
_ = weaponSync.GetKnifeFromDatabase((int)player.Index);

/*
AddTimer(2.0f, () =>
{
if (!gPlayerWeaponsInfo.ContainsKey((int)player.Index))
{
Console.WriteLine($"[WeaponPaints] Last try to retrieve player {player.PlayerName} skins");
if (Config.Additional.SkinEnabled && weaponSync != null)
_ = weaponSync.GetWeaponPaintsFromDatabase((int)player.Index);
if (Config.Additional.KnifeEnabled && weaponSync != null)
_ = weaponSync.GetKnifeFromDatabase((int)player.Index);
}
});
*/
}

return HookResult.Continue;
}

private void OnClientDisconnect(int playerSlot)
{
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);

if (player == null || !player.IsValid || player.IsHLTV) return;
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return;

if (Config.Additional.KnifeEnabled)
g_playersKnife.Remove((int)player.Index);
Expand Down Expand Up @@ -146,7 +184,7 @@ private HookResult OnItemPickup(EventItemPickup @event, GameEventInfo info)
g_knifePickupCount[(int)player.Index]++;

RemovePlayerKnife(player, true);
AddTimer(0.3f, ()=> GiveKnifeToPlayer(player));
AddTimer(0.3f, () => GiveKnifeToPlayer(player));

//RefreshPlayerKnife(player);
/*
Expand Down
2 changes: 2 additions & 0 deletions WeaponPaints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig

internal static WeaponSynchronization? weaponSync;

private CounterStrikeSharp.API.Modules.Timers.Timer? g_hTimerCheckSkinsData = null;

/*
private Dictionary<int, Dictionary<int, int>> gPlayerWeaponPaints = new();
private Dictionary<int, Dictionary<int, int>> gPlayerWeaponSeed = new();
Expand Down