Skip to content

Commit 22875f9

Browse files
committed
Add warning on the players tab to notify VPN/Proxy/TOR fromt he player list.
1 parent 62177b7 commit 22875f9

File tree

3 files changed

+106
-10
lines changed

3 files changed

+106
-10
lines changed

BHD-ServerManager/Databases/database.sqlite.sql

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,24 @@ CREATE TABLE IF NOT EXISTS "tb_settings" (
9292
"value" TEXT,
9393
PRIMARY KEY("id" AUTOINCREMENT)
9494
);
95+
CREATE TABLE IF NOT EXISTS "tb_userPermissions" (
96+
"PermissionID" INTEGER,
97+
"UserID" INTEGER NOT NULL,
98+
"Permission" TEXT NOT NULL,
99+
PRIMARY KEY("PermissionID" AUTOINCREMENT),
100+
FOREIGN KEY("UserID") REFERENCES "tb_users"("UserID") ON DELETE CASCADE
101+
);
102+
CREATE TABLE IF NOT EXISTS "tb_users" (
103+
"UserID" INTEGER,
104+
"Username" TEXT NOT NULL UNIQUE COLLATE NOCASE,
105+
"PasswordHash" TEXT NOT NULL,
106+
"Salt" TEXT NOT NULL,
107+
"IsActive" INTEGER DEFAULT 1,
108+
"Created" TEXT DEFAULT (datetime('now')),
109+
"LastLogin" TEXT,
110+
"Notes" TEXT DEFAULT '',
111+
PRIMARY KEY("UserID" AUTOINCREMENT)
112+
);
95113
INSERT INTO "tb_defaultMaps" VALUES (1,'Road Rage','DMK_01A.BMS',0,0);
96114
INSERT INTO "tb_defaultMaps" VALUES (2,'City Madness','DMM_01A.BMS',0,0);
97115
INSERT INTO "tb_defaultMaps" VALUES (3,'Cracked','DMM_01E.BMS',0,0);
@@ -217,6 +235,12 @@ INSERT INTO "tb_defaultMaps" VALUES (122,'Desert Fox A','KHM_03A.BMS',0,4);
217235
CREATE INDEX IF NOT EXISTS "idx_chatLogs_timestamp" ON "tb_chatLogs" (
218236
"messageTimeStamp"
219237
);
238+
CREATE INDEX IF NOT EXISTS "idx_permissions_permission" ON "tb_userPermissions" (
239+
"Permission"
240+
);
241+
CREATE INDEX IF NOT EXISTS "idx_permissions_userid" ON "tb_userPermissions" (
242+
"UserID"
243+
);
220244
CREATE INDEX IF NOT EXISTS "idx_playerip_category" ON "tb_playerIPRecords" (
221245
"RecordCategory",
222246
"RecordType"
@@ -257,4 +281,10 @@ CREATE INDEX IF NOT EXISTS "idx_proxy_vpn" ON "tb_proxyRecords" (
257281
"IsProxy",
258282
"IsTor"
259283
);
284+
CREATE INDEX IF NOT EXISTS "idx_users_active" ON "tb_users" (
285+
"IsActive"
286+
);
287+
CREATE INDEX IF NOT EXISTS "idx_users_username" ON "tb_users" (
288+
"Username"
289+
);
260290
COMMIT;

BHD-ServerManager/Forms/SubPanels/PlayerCard.Designer.cs

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BHD-ServerManager/Forms/SubPanels/PlayerCard.cs

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using BHD_ServerManager.Classes.Instances;
55
using BHD_ServerManager.Classes.ObjectClasses;
66
using BHD_ServerManager.Classes.SupportClasses;
7+
using BHD_ServerManager.Classes.Services;
78
using System.Diagnostics;
89
using System.Net;
910
using System.Text;
@@ -18,6 +19,7 @@ public partial class PlayerCard : UserControl
1819
private const string EncodingName = "Windows-1252";
1920

2021
private static chatInstance ChatInstance = CommonCore.instanceChat!;
22+
private static theInstance TheInstance = CommonCore.theInstance!;
2123
private playerObject Player { get; set; } = new playerObject();
2224
private int SlotNumber = 0;
2325
private ContextMenuStrip ContextMenu;
@@ -362,10 +364,71 @@ private ToolStripMenuItem CreateSwitchTeamMenuItem()
362364
}
363365

364366
// ================================================================================
365-
// PLAYER CARD UI UPDATE METHODS (No changes needed)
367+
// PROXY/VPN DETECTION METHODS
366368
// ================================================================================
367369

368-
public void UpdateStatus(playerObject playerInfo)
370+
/// <summary>
371+
/// Check if player's IP is flagged as proxy/VPN/TOR
372+
/// </summary>
373+
private async Task<bool> IsProxyDetectedAsync(string ipAddress)
374+
{
375+
try
376+
{
377+
// Check if proxy detection is enabled
378+
if (!TheInstance.proxyCheckEnabled || !ProxyCheckManager.IsInitialized)
379+
return false;
380+
381+
if (!IPAddress.TryParse(ipAddress, out IPAddress? ip))
382+
return false;
383+
384+
var result = await ProxyCheckManager.CheckIPAsync(ip);
385+
386+
if (result.Success)
387+
{
388+
// Check if any proxy/VPN/TOR flag is set
389+
return result.IsProxy || result.IsVpn || result.IsTor;
390+
}
391+
392+
return false;
393+
}
394+
catch (Exception ex)
395+
{
396+
AppDebug.Log("PlayerCard", $"Error checking proxy status: {ex}");
397+
return false;
398+
}
399+
}
400+
401+
/// <summary>
402+
/// Update player icon based on team and proxy status
403+
/// </summary>
404+
private async Task UpdatePlayerIconAsync(string ipAddress, int team)
405+
{
406+
bool isProxyDetected = await IsProxyDetectedAsync(ipAddress);
407+
408+
if (isProxyDetected)
409+
{
410+
// Show warning icon for proxy/VPN/TOR
411+
playerTeamIcon.IconChar = FontAwesome.Sharp.IconChar.PersonCircleExclamation;
412+
playerTeamIcon.IconColor = Color.Yellow;
413+
}
414+
else
415+
{
416+
// Show default team icon
417+
playerTeamIcon.IconChar = FontAwesome.Sharp.IconChar.PersonHiking;
418+
playerTeamIcon.IconColor = team switch
419+
{
420+
1 => Color.Blue,
421+
2 => Color.Red,
422+
_ => Color.Black
423+
};
424+
}
425+
}
426+
427+
// ================================================================================
428+
// PLAYER CARD UI UPDATE METHODS
429+
// ================================================================================
430+
431+
public async void UpdateStatus(playerObject playerInfo)
369432
{
370433
Player = playerInfo;
371434

@@ -378,12 +441,9 @@ public void UpdateStatus(playerObject playerInfo)
378441
label_dataPlayerNameRole.Text = decodedPlayerName;
379442

380443
label_dataIPinfo.Text = Player.PlayerIPAddress;
381-
playerTeamIcon.IconColor = Player.PlayerTeam switch
382-
{
383-
1 => Color.Blue,
384-
2 => Color.Red,
385-
_ => Color.Black
386-
};
444+
445+
// Update icon based on proxy detection and team
446+
await UpdatePlayerIconAsync(Player.PlayerIPAddress, Player.PlayerTeam);
387447

388448
ContextMenu.Items[0].Text = decodedPlayerName;
389449
ContextMenu.Items[1].Text = $"Ping: {Player.PlayerPing} ms";
@@ -407,7 +467,11 @@ public void ResetStatus()
407467
label_dataPlayerNameRole.UseCompatibleTextRendering = true;
408468
label_dataPlayerNameRole.Text = Player.PlayerName;
409469
label_dataSlotNum.Text = Player.PlayerSlot.ToString();
470+
471+
// Reset to default icon
472+
playerTeamIcon.IconChar = FontAwesome.Sharp.IconChar.PersonHiking;
410473
playerTeamIcon.IconColor = Color.Black;
474+
411475
playerContextMenuIcon.Visible = false;
412476
}
413477

0 commit comments

Comments
 (0)