Skip to content

Commit

Permalink
Add tag sanitization
Browse files Browse the repository at this point in the history
  • Loading branch information
oscar-wos committed May 24, 2024
1 parent 6948bcd commit b718018
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
3 changes: 0 additions & 3 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,4 @@ public class CoreConfig : BasePluginConfig

[JsonPropertyName("DatabaseName")]
public string DatabaseName { get; set; } = "";

[JsonPropertyName("DatabaseKeepAlive")]
public int DatabaseKeepAlive { get; set; } = 30;
}
2 changes: 1 addition & 1 deletion Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion PostgreService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public string BuildConnectionString(CoreConfig config)
Username = config.DatabaseUser,
Password = config.DatabasePassword,
Database = config.DatabaseName,
KeepAlive = config.DatabaseKeepAlive,
Pooling = true,
};

Expand Down
10 changes: 7 additions & 3 deletions Sessions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Text.RegularExpressions;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Cvars;
Expand Down Expand Up @@ -29,8 +30,10 @@ public override void Load(bool hotReload)

RegisterListener<Listeners.OnClientAuthorized>((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<Listeners.OnClientDisconnect>(playerSlot =>
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions SqlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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)";
Expand Down

0 comments on commit b718018

Please sign in to comment.