Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Big Patch (v3.3.3)
Browse files Browse the repository at this point in the history
  • Loading branch information
K4ryuu committed Feb 9, 2024
1 parent f7bf235 commit 9454d79
Show file tree
Hide file tree
Showing 21 changed files with 170 additions and 272 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
-- 2023.02.06 - V3.3.3

- fix: Crash on mapchange because of gamedata change (SetStateChanged)
- fix: Error log if rank module disabled
- fix: Remove LevelRanksCompatibility disable if any of the required modules are not running
- fix: Data load for not used modules
- fix: Lag spikes on !top command
- fix: T gets point for EventHostageRescuedAll
- refactor: Removed unnecessary operators from ranks module
- refactor: Optimised rank module player loops

-- 2023.02.06 - V3.3.2

- feat: Add MySQL pooling support fully
Expand Down
21 changes: 9 additions & 12 deletions src/Module/Interfaces/IModuleRank.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Commands;
using static K4System.ModuleRank;

namespace K4System
namespace K4System;

public interface IModuleRank
{
public interface IModuleRank
{
public void Initialize(bool hotReload);
public void Initialize(bool hotReload);

public void Release(bool hotReload);
public void Release(bool hotReload);

public Rank GetNoneRank();
public Rank GetNoneRank();

public void LoadRankData(int slot, int points);
public void LoadRankData(int slot, int points);

public void BeforeRoundEnd(int winnerTeam);
}
}
public void BeforeRoundEnd(int winnerTeam);
}
18 changes: 7 additions & 11 deletions src/Module/Interfaces/IModuleStat.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Commands;
namespace K4System;

namespace K4System
public interface IModuleStat
{
public interface IModuleStat
{
public void Initialize(bool hotReload);
public void Initialize(bool hotReload);

public void Release(bool hotReload);
public void Release(bool hotReload);

public void LoadStatData(int slot, Dictionary<string, int> statData);
public void LoadStatData(int slot, Dictionary<string, int> statData);

public void BeforeRoundEnd(int winnerTeam);
}
}
public void BeforeRoundEnd(int winnerTeam);
}
18 changes: 8 additions & 10 deletions src/Module/Interfaces/IModuleTime.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Commands;

namespace K4System
namespace K4System;

public interface IModuleTime
{
public interface IModuleTime
{
public void Initialize(bool hotReload);
public void Initialize(bool hotReload);

public void Release(bool hotReload);
public void Release(bool hotReload);

public void LoadTimeData(int slot, Dictionary<string, int> timeData);
public void LoadTimeData(int slot, Dictionary<string, int> timeData);

public void BeforeDisconnect(CCSPlayerController player);
}
}
public void BeforeDisconnect(CCSPlayerController player);
}
14 changes: 5 additions & 9 deletions src/Module/Interfaces/IModuleUtils.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Commands;
namespace K4System;

namespace K4System
public interface IModuleUtils
{
public interface IModuleUtils
{
public void Initialize(bool hotReload);
public void Initialize(bool hotReload);

public void Release(bool hotReload);
}
}
public void Release(bool hotReload);
}
32 changes: 9 additions & 23 deletions src/Module/ModuleRank.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace K4System
{
using Microsoft.Extensions.Logging;

using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Plugin;
using CounterStrikeSharp.API.Modules.Timers;

using Microsoft.Extensions.Logging;
using CounterStrikeSharp.API.Modules.Utils;

public partial class ModuleRank : IModuleRank
{
Expand Down Expand Up @@ -33,28 +33,14 @@ public void Initialize(bool hotReload)
Initialize_Events(plugin);
Initialize_Commands(plugin);

//** ? Hot Reload Events */
//** ? Register Timers */

if (hotReload)
plugin.AddTimer(Config.PointSettings.PlaytimeMinutes * 60, () =>
{
globalGameRules = Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules").First().GameRules;

plugin.AddTimer(Config.PointSettings.PlaytimeMinutes * 60, () =>
{
List<CCSPlayerController> players = Utilities.GetPlayers();
foreach (CCSPlayerController player in players)
{
if (player is null || !player.IsValid || !player.PlayerPawn.IsValid || player.IsBot || player.IsHLTV)
continue;
if (!rankCache.ContainsPlayer(player))
continue;
ModifyPlayerPoints(player, Config.PointSettings.PlaytimePoints, "k4.phrases.playtime");
}
}, TimerFlags.STOP_ON_MAPCHANGE | TimerFlags.REPEAT);
}
Utilities.GetPlayers().Where(p => p.TeamNum == (int)CsTeam.Terrorist)
.ToList()
.ForEach(p => ModifyPlayerPoints(p, Config.PointSettings.PlaytimePoints, "k4.phrases.playtime"));
}, TimerFlags.REPEAT);
}

public void Release(bool hotReload)
Expand Down
13 changes: 2 additions & 11 deletions src/Module/ModuleStat.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
namespace K4System
{
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Plugin;

using Microsoft.Extensions.Logging;

using CounterStrikeSharp.API.Core.Plugin;

public partial class ModuleStat : IModuleStat
{
public ModuleStat(ILogger<ModuleStat> logger, IPluginContext pluginContext)
Expand All @@ -28,13 +26,6 @@ public void Initialize(bool hotReload)

Initialize_Events(plugin);
Initialize_Commands(plugin);

//** ? Hot Reload Events */

if (hotReload)
{
globalGameRules = Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules").First().GameRules;
}
}

public void Release(bool hotReload)
Expand Down
4 changes: 2 additions & 2 deletions src/Module/ModuleTime.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace K4System
{
using CounterStrikeSharp.API.Core.Plugin;

using Microsoft.Extensions.Logging;

using CounterStrikeSharp.API.Core.Plugin;

public partial class ModuleTime : IModuleTime
{
public ModuleTime(ILogger<ModuleTime> logger, IPluginContext pluginContext)
Expand Down
4 changes: 2 additions & 2 deletions src/Module/ModuleUtils.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace K4System
{
using CounterStrikeSharp.API.Core.Plugin;

using Microsoft.Extensions.Logging;

using CounterStrikeSharp.API.Core.Plugin;

public partial class ModuleUtils : IModuleUtils
{
public ModuleUtils(ILogger<ModuleUtils> logger, IPluginContext pluginContext)
Expand Down
6 changes: 2 additions & 4 deletions src/Module/Rank/RankCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void OnCommandTop(CCSPlayerController? player, CommandInfo info)
CCSPlayerController savedPlayer = player;
List<PlayerData> playersData = plugin.PreparePlayersData();

Task<List<(int points, string name)>?> task = Task.Run(() => FetchTopDataAsync(plugin, printCount, playersData));
Task<List<(int points, string name)>?> task = Task.Run(() => FetchTopDataAsync(printCount));
task.Wait();
List<(int points, string name)>? rankData = task.Result;

Expand All @@ -186,16 +186,14 @@ public void OnCommandTop(CCSPlayerController? player, CommandInfo info)
}
}

public async Task<List<(int points, string name)>?> FetchTopDataAsync(Plugin plugin, int printCount, List<PlayerData> playersData)
public async Task<List<(int points, string name)>?> FetchTopDataAsync(int printCount)
{
string query = $"SELECT `points`, `name` FROM `{Config.DatabaseSettings.TablePrefix}k4ranks` ORDER BY `points` DESC LIMIT {printCount};";

List<(int points, string name)> rankData = new List<(int points, string name)>();

try
{
await plugin.SaveAllPlayersCacheAsync(playersData);

using (MySqlCommand command = new MySqlCommand(query))
{
using (MySqlDataReader? reader = await Database.Instance.ExecuteReaderAsync(command.CommandText, command.Parameters.Cast<MySqlParameter>().ToArray()))
Expand Down
Loading

0 comments on commit 9454d79

Please sign in to comment.