diff --git a/Config.cs b/Config.cs index 91c7ef1..9b30ab2 100644 --- a/Config.cs +++ b/Config.cs @@ -24,7 +24,4 @@ public class CoreConfig : BasePluginConfig [JsonPropertyName("DatabaseName")] public string DatabaseName { get; set; } = ""; - - [JsonPropertyName("DatabaseKeepAlive")] - public int DatabaseKeepAlive { get; set; } = 30; } \ No newline at end of file diff --git a/Globals.cs b/Globals.cs index 9cc2fb0..02d297e 100644 --- a/Globals.cs +++ b/Globals.cs @@ -5,7 +5,7 @@ public partial class Sessions public override string ModuleName => "Sessions"; public override string ModuleDescription => "Track player sessions"; public override string ModuleAuthor => "github.com/oscar-wos/Sessions"; - public override string ModuleVersion => "1.2.6"; + public override string ModuleVersion => "1.2.7"; public required IDatabase _database; public readonly Ip _ip = new(); diff --git a/PostgreService.cs b/PostgreService.cs index d2d5b6d..d5ce933 100644 --- a/PostgreService.cs +++ b/PostgreService.cs @@ -39,7 +39,6 @@ public string BuildConnectionString(CoreConfig config) Username = config.DatabaseUser, Password = config.DatabasePassword, Database = config.DatabaseName, - KeepAlive = config.DatabaseKeepAlive, Pooling = true, }; diff --git a/Sessions.cs b/Sessions.cs index 4ebc9b7..e300dca 100644 --- a/Sessions.cs +++ b/Sessions.cs @@ -1,3 +1,4 @@ +using System.Text.RegularExpressions; using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Cvars; @@ -29,8 +30,10 @@ public override void Load(bool hotReload) RegisterListener((playerSlot, steamId) => { + string playerName = Utilities.GetPlayerFromSlot(playerSlot)!.PlayerName; + OnPlayerConnect(playerSlot, steamId.SteamId64, NativeAPI.GetPlayerIpAddress(playerSlot).Split(":")[0]).GetAwaiter().GetResult(); - CheckAlias(playerSlot, Utilities.GetPlayerFromSlot(playerSlot)!.PlayerName).GetAwaiter().GetResult(); + CheckAlias(playerSlot, playerName).GetAwaiter().GetResult(); }); RegisterListener(playerSlot => @@ -58,10 +61,10 @@ public override void Load(bool hotReload) }, HookMode.Post); _timer = AddTimer(1.0f, Timer_Repeat, TimerFlags.REPEAT); - + if (!hotReload) return; - + _server.Map = _database.GetMapAsync(Server.MapName).GetAwaiter().GetResult(); Utilities.GetPlayers().Where(player => player.IsValid && !player.IsBot).ToList().ForEach(player => { @@ -93,6 +96,7 @@ public async Task CheckAlias(int playerSlot, string alias) return; AliasSQL? recentAlias = await _database.GetAliasAsync(player.Id); + alias = Regex.Replace(alias, @"[0\\]x[\da-fA-F]{2}", string.Empty); if (recentAlias == null || recentAlias.Alias != alias) _database.InsertAlias(player.Session!.Id, player.Id, _server!.Id, _server.Map!.Id, alias); diff --git a/SqlService.cs b/SqlService.cs index b77dbd7..2d9a7d8 100644 --- a/SqlService.cs +++ b/SqlService.cs @@ -39,7 +39,6 @@ public string BuildConnectionString(CoreConfig config) UserID = config.DatabaseUser, Password = config.DatabasePassword, Database = config.DatabaseName, - Keepalive = (uint)config.DatabaseKeepAlive, AllowUserVariables = true, Pooling = true, }; @@ -285,7 +284,7 @@ message VARCHAR(128) COLLATE utf8_unicode_520_ci public override string InsertSession => "INSERT INTO sessions (player_id, server_id, map_id, ip) VALUES (@PlayerId, @ServerId, @MapId, @Ip); SELECT last_insert_id()"; public override string UpdateSession => "UPDATE sessions SET end_time = NOW() WHERE id = @SessionId"; - public override string UpdateSeen => "UPDATE players SET last_seen = NOW() WHERE id = @PlayerId"; + public override string UpdateSeen => "UPDATE players SET last_seen = NOW() WHERE id = @PlayerId"; public override string SelectAlias => "SELECT id, alias FROM aliases WHERE player_id = @PlayerId ORDER BY id DESC LIMIT 1"; public override string InsertAlias => "INSERT INTO aliases (session_id, player_id, map_id, alias) VALUES (@SessionId, @PlayerId, @MapId, @Alias)";