Skip to content

Commit 4882254

Browse files
author
Matthew Bate
committed
Proxy Checking Tab Functionality
1 parent dabea97 commit 4882254

File tree

12 files changed

+876
-491
lines changed

12 files changed

+876
-491
lines changed

BHD-ServerManager/Classes/GameManagement/StartServer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,8 @@ public static bool CheckForExistingProcess()
396396
SetProcessWindowTitle(searchProcess, windowTitle);
397397

398398
ServerMemory.AttachToGameProcess();
399-
399+
// New MatchID just incase...
400+
theInstanceManager.GenerateMatchID();
400401
return true;
401402
}
402403
}

BHD-ServerManager/Classes/InstanceManagers/theInstanceManager.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Text.Json;
1010
using System.Text.Json.Serialization;
1111
using Windows.Storage;
12+
using System.Diagnostics;
1213

1314
namespace BHD_ServerManager.Classes.InstanceManagers
1415
{
@@ -254,5 +255,40 @@ public static void changeTeamGameMode(int currentMapType, int nextMapType)
254255

255256
}
256257

258+
/// <summary>
259+
/// Generates a new match ID in the format YYYYMMDD### where ### is the match number (001-999).
260+
/// Automatically increments the match number or resets to 001 when the day changes.
261+
/// </summary>
262+
/// <returns>The generated match ID as an integer</returns>
263+
public static void GenerateMatchID()
264+
{
265+
// Format: YYMMDD### (e.g., 26012401 for Jan 24, 2026, Match 001)
266+
int currentDate = int.Parse(DateTime.Now.ToString("yyMMdd"));
267+
int currentMatchID = theInstance.gameMatchID;
268+
269+
if (currentMatchID == 0)
270+
{
271+
theInstance.gameMatchID = currentDate * 1000 + 1;
272+
AppDebug.Log("GenerateMatchID", $"Match ID: {theInstance.gameMatchID}");
273+
ServerSettings.Set("gameMatchID", theInstance.gameMatchID);
274+
return;
275+
}
276+
277+
int lastDate = currentMatchID / 1000;
278+
int lastMatchNumber = currentMatchID % 1000;
279+
280+
if (lastDate == currentDate)
281+
{
282+
theInstance.gameMatchID = currentDate * 1000 + (lastMatchNumber + 1);
283+
}
284+
else
285+
{
286+
theInstance.gameMatchID = currentDate * 1000 + 1;
287+
}
288+
289+
AppDebug.Log("GenerateMatchID", $"Match ID: {theInstance.gameMatchID}");
290+
ServerSettings.Set("gameMatchID", theInstance.gameMatchID);
291+
}
292+
257293
}
258294
}

BHD-ServerManager/Classes/Instances/banInstance.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public class proxyRecord
6262

6363
public class proxyCountry
6464
{
65+
public required int RecordID { get; set; }
6566
public required string CountryCode { get; set; } // Country ISO Code
6667
public required string CountryName { get; set; } // Country Name
6768
}

BHD-ServerManager/Classes/Instances/theInstance.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using BHD_ServerManager.Classes.ObjectClasses;
1+
using BHD_ServerManager.Classes.InstanceManagers;
2+
using BHD_ServerManager.Classes.ObjectClasses;
3+
using BHD_ServerManager.Classes.SupportClasses;
24
using System;
35
using System.Collections.Generic;
46
using System.Diagnostics;
@@ -61,6 +63,7 @@ public class theInstance
6163
public bool profileServerAttribute21 { get; set; } = true; // Loadbar
6264

6365
// Game Settings
66+
public int gameMatchID { get; set; } = ServerSettings.Get("gameMatchID", 0);
6467
public int gameMatchWinner { get; set; } = 0;
6568
public string gameServerName { get; set; } = "Untitled Server";
6669
public string gameMOTD { get; set; } = "Welcome to the server!";
@@ -164,7 +167,6 @@ public class theInstance
164167
// Instance Update Statements
165168
public bool banInstanceUpdated { get; set; } = false;
166169

167-
168170
// Player Team Information
169171
public Dictionary<int, playerObject> playerList { get; set; } = new();
170172
public List<playerTeamObject> playerChangeTeamList { get; set; } = new();
@@ -176,7 +178,17 @@ public class theInstance
176178
public bool ActiveMapPlaylistChanged { get; set; } = false;
177179
public int SelectedMapPlaylist { get; set; } = 1;
178180

179-
}
181+
// Proxy Checking Settings
182+
public bool proxyCheckEnabled { get; set; } = false;
183+
public string proxyCheckAPIKey { get; set; } = string.Empty;
184+
public decimal proxyCheckCacheTime { get; set; } = 60; // In Days
185+
public int proxyCheckProxyAction { get; set; } = 0; // 0 = Nothing, 1 = Kick, 2 = Ban
186+
public int proxyCheckVPNAction { get; set; } = 0; // 0 = Nothing, 1 = Kick, 2 = Ban
187+
public int proxyCheckTORAction { get; set; } = 0; // 0 = Nothing, 1 = Kick, 2 = Ban
188+
public int proxyCheckGeoMode { get; set; } = 0; // 0 = Nothing, 1 = Block, 2 = Allow
189+
public int proxyCheckServiceProvider { get; set; } = 0; // 0 = None, 1 = ProxyCheck.io
190+
191+
}
180192

181193
public enum InstanceStatus
182194
{

BHD-ServerManager/Classes/SupportClasses/DatabaseManager.cs

Lines changed: 121 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -685,24 +685,6 @@ FROM tb_proxyRecords
685685
return records;
686686
}
687687

688-
/// <summary>
689-
/// Load all proxy blocked countries from the database.
690-
/// </summary>
691-
public static List<proxyCountry> GetProxyBlockedCountries()
692-
{
693-
if (!IsInitialized)
694-
throw new InvalidOperationException("DatabaseManager is not initialized.");
695-
696-
var countries = new List<proxyCountry>();
697-
698-
// Note: This table doesn't exist in your schema yet
699-
// You may need to create tb_proxyBlockedCountries table
700-
// For now, returning empty list
701-
702-
AppDebug.Log("DatabaseManager", $"Loaded {countries.Count} blocked countries");
703-
return countries;
704-
}
705-
706688
/// <summary>
707689
/// Load all player name records for a specific category.
708690
/// </summary>
@@ -1069,6 +1051,127 @@ DELETE FROM tb_playerIPRecords
10691051
}
10701052
}
10711053

1054+
/// <summary>
1055+
/// Load all proxy blocked countries from the database.
1056+
/// </summary>
1057+
public static List<proxyCountry> GetProxyBlockedCountries()
1058+
{
1059+
if (!IsInitialized)
1060+
throw new InvalidOperationException("DatabaseManager is not initialized.");
1061+
1062+
var countries = new List<proxyCountry>();
1063+
1064+
using var conn = new SqliteConnection($"Data Source={_databasePath};Mode=ReadWrite;");
1065+
conn.Open();
1066+
1067+
using var cmd = conn.CreateCommand();
1068+
cmd.CommandText = @"
1069+
SELECT RecordID, CountryCode, CountryName
1070+
FROM tb_proxyBlockedCountries
1071+
ORDER BY CountryName COLLATE NOCASE;
1072+
";
1073+
1074+
using var reader = cmd.ExecuteReader();
1075+
while (reader.Read())
1076+
{
1077+
countries.Add(new proxyCountry
1078+
{
1079+
RecordID = reader.GetInt32(0),
1080+
CountryCode = reader.GetString(1),
1081+
CountryName = reader.GetString(2)
1082+
});
1083+
}
1084+
1085+
AppDebug.Log("DatabaseManager", $"Loaded {countries.Count} blocked countries");
1086+
return countries;
1087+
}
1088+
1089+
/// <summary>
1090+
/// Add a new blocked country to the database.
1091+
/// </summary>
1092+
public static int AddProxyBlockedCountry(string countryCode, string countryName)
1093+
{
1094+
if (!IsInitialized)
1095+
throw new InvalidOperationException("DatabaseManager is not initialized.");
1096+
1097+
if (string.IsNullOrWhiteSpace(countryCode) || countryCode.Length != 2)
1098+
throw new ArgumentException("Country code must be exactly 2 characters.", nameof(countryCode));
1099+
1100+
if (string.IsNullOrWhiteSpace(countryName))
1101+
throw new ArgumentException("Country name cannot be empty.", nameof(countryName));
1102+
1103+
using var conn = new SqliteConnection($"Data Source={_databasePath};Mode=ReadWrite;");
1104+
conn.Open();
1105+
1106+
using var tx = conn.BeginTransaction();
1107+
1108+
try
1109+
{
1110+
using var cmd = conn.CreateCommand();
1111+
cmd.Transaction = tx;
1112+
cmd.CommandText = @"
1113+
INSERT INTO tb_proxyBlockedCountries (CountryCode, CountryName)
1114+
VALUES ($countryCode, $countryName);
1115+
SELECT last_insert_rowid();
1116+
";
1117+
cmd.Parameters.AddWithValue("$countryCode", countryCode.ToUpper());
1118+
cmd.Parameters.AddWithValue("$countryName", countryName);
1119+
1120+
var newId = (long)cmd.ExecuteScalar()!;
1121+
tx.Commit();
1122+
1123+
AppDebug.Log("DatabaseManager", $"Added blocked country: {countryCode} - {countryName} (ID: {newId})");
1124+
return (int)newId;
1125+
}
1126+
catch (SqliteException ex) when (ex.SqliteErrorCode == 19) // UNIQUE constraint
1127+
{
1128+
tx.Rollback();
1129+
AppDebug.Log("DatabaseManager", $"Country code {countryCode} already exists");
1130+
return -1;
1131+
}
1132+
catch
1133+
{
1134+
tx.Rollback();
1135+
throw;
1136+
}
1137+
}
1138+
1139+
/// <summary>
1140+
/// Remove a blocked country from the database by RecordID.
1141+
/// </summary>
1142+
public static bool RemoveProxyBlockedCountry(int recordId)
1143+
{
1144+
if (!IsInitialized)
1145+
throw new InvalidOperationException("DatabaseManager is not initialized.");
1146+
1147+
using var conn = new SqliteConnection($"Data Source={_databasePath};Mode=ReadWrite;");
1148+
conn.Open();
1149+
1150+
using var tx = conn.BeginTransaction();
1151+
1152+
try
1153+
{
1154+
using var cmd = conn.CreateCommand();
1155+
cmd.Transaction = tx;
1156+
cmd.CommandText = @"
1157+
DELETE FROM tb_proxyBlockedCountries
1158+
WHERE RecordID = $recordId;
1159+
";
1160+
cmd.Parameters.AddWithValue("$recordId", recordId);
1161+
1162+
int rowsAffected = cmd.ExecuteNonQuery();
1163+
tx.Commit();
1164+
1165+
AppDebug.Log("DatabaseManager", $"Removed blocked country ID: {recordId}");
1166+
return rowsAffected > 0;
1167+
}
1168+
catch
1169+
{
1170+
tx.Rollback();
1171+
throw;
1172+
}
1173+
}
1174+
10721175
/// <summary>
10731176
/// Releases the exclusive lock and closes the internal connection.
10741177
/// Call this at application shutdown.

BHD-ServerManager/Classes/SupportClasses/ServerSettings.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ private static string ConvertToString<T>(T value)
4747
{
4848
bool b => b.ToString().ToLowerInvariant(),
4949
int i => i.ToString(),
50-
decimal d => d.ToString(),
50+
long l => l.ToString(),
51+
decimal d => d.ToString(),
5152
string s => s,
5253
_ => throw new NotSupportedException(
5354
$"Type {typeof(T)} is not supported"
@@ -66,6 +67,10 @@ private static T ConvertFromString<T>(string value, T defaultValue)
6667
if (typeof(T) == typeof(int) &&
6768
int.TryParse(value, out var i))
6869
return (T)(object)i;
70+
71+
if (typeof(T) == typeof(long) &&
72+
long.TryParse(value, out var l))
73+
return (T)(object)l;
6974

7075
if (typeof(T) == typeof(decimal) &&
7176
decimal.TryParse(value, out var d))

BHD-ServerManager/Classes/Tickers/tickerServerManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ private static void tickerEvent_preGameProcessing()
176176
theInstance.playerList.Clear();
177177
StatFunctions.ResetPlayerStats();
178178

179+
// New MatchID
180+
theInstanceManager.GenerateMatchID();
181+
179182
// Update the Global Game Type (Pinger Reasons)
180183
ServerMemory.UpdateGlobalGameType();
181184
// Update the Scores Required to Win the Game
4 KB
Binary file not shown.

0 commit comments

Comments
 (0)