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

Commit

Permalink
Patch (v3.3.7)
Browse files Browse the repository at this point in the history
  • Loading branch information
K4ryuu committed Feb 11, 2024
1 parent 25d15fc commit 477e636
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 21 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
-- 2023.02.10 - V3.3.7

- refactor: Adjust MySQL connection pool sizes better
- refactor: MySQL connection pool prepare to all players join at once
- fix: MySQL pool size nulled on mapchange, blocking player load
- fix: Block triple save on mapchange causing query timeout (RoundEnd, MapChange, Disconnect)

-- 2023.02.10 - V3.3.6

- fix: Points not changed because of misstypo

-- 2023.02.10 - V3.3.5

- fix: Invalid player blocked from functions (problem by GetPlayers)
Expand Down
3 changes: 2 additions & 1 deletion src/Module/Rank/RankFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace K4System
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Utils;
using Microsoft.Extensions.Logging;

public partial class ModuleRank : IModuleRank
{
Expand Down Expand Up @@ -99,7 +100,7 @@ public void ModifyPlayerPoints(CCSPlayerController player, int amount, string re
if (player.IsBot || player.IsHLTV)
return;

if (player.SteamID.ToString().Length == 17)
if (player.SteamID.ToString().Length != 17)
return;

if (!rankCache.ContainsPlayer(player))
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ public override void Load(bool hotReload)

//** ? Initialize Database tables */

Database.Instance.AdjustDatabasePooling();
Task.Run(CreateMultipleTablesAsync).Wait();

if (hotReload)
{
//** ? Load Player Caches */

LoadAllPlayersCache();
AdjustDatabasePooling();

GameRules = Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules").First().GameRules;
}
Expand Down
15 changes: 11 additions & 4 deletions src/Plugin/PluginBasics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ namespace K4System
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Utils;
using Microsoft.Extensions.Logging;

public sealed partial class Plugin : BasePlugin
{
public Timer? databasePoolingTimer;

public void Initialize_Commands()
{
AddCommand("css_k4", "More informations about K4-System",
Expand Down Expand Up @@ -83,7 +86,6 @@ public void Initialize_Events()
return HookResult.Continue;
LoadPlayerCache(player);
AdjustDatabasePooling();
return HookResult.Continue;
});
Expand All @@ -101,8 +103,12 @@ public void Initialize_Events()
if (Config.GeneralSettings.ModuleTimes)
ModuleTime.BeforeDisconnect(player);
SavePlayerCache(player);
AdjustDatabasePooling();
// Block save if the disconenct reason is mapchange, because we handle it on RoundEnd for everyone, which called on MapChange
// This reduce the load, because we use transactions and we don't open connection for each player
if (@event.Reason == 1)
{
SavePlayerCache(player);
}
return HookResult.Continue;
});
Expand All @@ -123,7 +129,7 @@ public void Initialize_Events()
if (player.IsBot || player.IsHLTV)
continue;
if (player.SteamID.ToString().Length == 17)
if (player.SteamID.ToString().Length != 17)
continue;
player.PrintToChat($" {Localizer["k4.general.prefix"]} {ChatColors.Lime}{Localizer["k4.general.spawnmessage"]}");
Expand All @@ -141,6 +147,7 @@ public void Initialize_Events()
ModuleRank.BeforeRoundEnd(@event.Winner);
SaveAllPlayersCache();
return HookResult.Continue;
});

Expand Down
20 changes: 11 additions & 9 deletions src/Plugin/PluginDatabase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

using System.Data;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Memory;
using MySqlConnector;

namespace K4System
Expand All @@ -17,17 +21,15 @@ public void Initialize(string server, string database, string userId, string pas
connectionString = BuildConnectionString(server, database, userId, password, port, sslMode, usePooling, minPoolSize, maxPoolSize);
}

public void AdjustPoolingBasedOnPlayerCount(int playerCount)
public void AdjustDatabasePooling()
{
if (connectionString == null) throw new InvalidOperationException("Connection string has not been initialized.");

uint minPoolSize = (uint)Math.Max(2, 2 + (playerCount / 10));
uint maxPoolSize = (uint)Math.Max(3, 3 + (playerCount / 3));
if (connectionString == null)
throw new InvalidOperationException("Database has not been initialized");

var builder = new MySqlConnectionStringBuilder(connectionString)
{
MinimumPoolSize = minPoolSize,
MaximumPoolSize = maxPoolSize,
MinimumPoolSize = (uint)Math.Max(5, Server.MaxPlayers / 2.5),
MaximumPoolSize = (uint)Math.Max(20, Server.MaxPlayers),
};

connectionString = builder.ConnectionString;
Expand All @@ -44,8 +46,8 @@ private static string BuildConnectionString(string server, string database, stri
Port = (uint)port,
SslMode = Enum.Parse<MySqlSslMode>(sslMode, true),
Pooling = usePooling,
MinimumPoolSize = minPoolSize,
MaximumPoolSize = maxPoolSize
MinimumPoolSize = 10,
MaximumPoolSize = 24,
};

return builder.ConnectionString;
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/PluginManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public sealed partial class Plugin : BasePlugin

public override string ModuleAuthor => "K4ryuu";

public override string ModuleVersion => "3.3.5 " +
public override string ModuleVersion => "3.3.7 " +
#if RELEASE
"(release)";
#else
Expand Down
5 changes: 0 additions & 5 deletions src/Plugin/PluginStock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ public class PlayerData

public sealed partial class Plugin : BasePlugin
{
public void AdjustDatabasePooling()
{
Database.Instance.AdjustPoolingBasedOnPlayerCount(Utilities.GetPlayers().Where(p => p?.IsValid == true && p.PlayerPawn?.IsValid == true && !p.IsBot && !p.IsHLTV).Count());
}

public CommandInfo.CommandCallback CallbackAnonymizer(Action<CCSPlayerController?, CommandInfo> action)
{
return new CommandInfo.CommandCallback(action);
Expand Down

0 comments on commit 477e636

Please sign in to comment.