Skip to content

Commit 5763f78

Browse files
author
Matthew Bate
committed
Addition Edit to clean Remote client from previous data. API pre-work for instance data
1 parent 22875f9 commit 5763f78

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+10729
-74
lines changed

BHD-ServerManager/Classes/CoreObjects/CommonCore.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,21 @@ public static class CommonCore
1515
// Object: thisInstance, Memory and Variable storage for the current instance of the application
1616
public static theInstance? theInstance { get; set; }
1717
public static chatInstance? instanceChat { get; set; }
18-
public static banInstance? instanceBans { get; set; }
1918
public static statInstance? instanceStats { get; set; }
19+
public static playerInstance? instancePlayers { get; set; }
2020

21-
22-
// Object: Ticker, Timer Constructor for periodic tasks
23-
public static Ticker? Ticker { get; set; }
21+
public static banInstance? instanceBans { get; set; }
22+
// Object: Ticker, Timer Constructor for periodic tasks
23+
public static Ticker? Ticker { get; set; }
2424

2525
public static void InitializeCore()
2626
{
2727
// Instances
2828
theInstance = new theInstance();
2929
instanceChat = new chatInstance();
3030
instanceStats = new statInstance();
31-
32-
// Initialize Ban Instance
33-
CommonCore.instanceBans = DatabaseManager.LoadBanInstance();
31+
instancePlayers = new playerInstance();
32+
instanceBans = DatabaseManager.LoadBanInstance();
3433

3534
// Initialize the Ticker
3635
Ticker = new Ticker();

BHD-ServerManager/Classes/GameManagement/ServerMemory.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ public static class ServerMemory
1818
{
1919
// Global Variables
2020
private readonly static theInstance thisInstance = CommonCore.theInstance!;
21+
private readonly static playerInstance playerInstance = CommonCore.instancePlayers!;
2122

22-
// START: Process Memory Variables
23-
// Import of Dynamic Link Libraries
24-
[DllImport("kernel32.dll", SetLastError = true)]
23+
// START: Process Memory Variables
24+
// Import of Dynamic Link Libraries
25+
[DllImport("kernel32.dll", SetLastError = true)]
2526
public static extern nint OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
2627
[DllImport("kernel32.dll")]
2728
public static extern bool ReadProcessMemory(int hProcess, int lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesRead);
@@ -1170,7 +1171,7 @@ public static void UpdateGameScores()
11701171
// Function UpdatePlayerTeam
11711172
public static void UpdatePlayerTeam()
11721173
{
1173-
if (thisInstance.playerChangeTeamList.Count == 0)
1174+
if (playerInstance.PlayerChangeTeamList.Count == 0)
11741175
{
11751176
return;
11761177
}
@@ -1190,16 +1191,16 @@ public static void UpdatePlayerTeam()
11901191

11911192
int playerlistStartingLocation = BitConverter.ToInt32(playerListStartingLocationByteArray, 0);
11921193

1193-
for (int ii = 0; ii < thisInstance.playerChangeTeamList.Count; ii++)
1194+
for (int ii = 0; ii < playerInstance.PlayerChangeTeamList.Count; ii++)
11941195
{
1195-
int playerLocationOffset = (thisInstance.playerChangeTeamList[ii].slotNum - 1) * 0xAF33C;
1196+
int playerLocationOffset = (playerInstance.PlayerChangeTeamList[ii].slotNum - 1) * 0xAF33C;
11961197

11971198
int playerLocation = playerlistStartingLocation + playerLocationOffset;
11981199
int playerTeamLocation = playerLocation + 0x90;
1199-
byte[] teamBytes = BitConverter.GetBytes(thisInstance.playerChangeTeamList[ii].Team);
1200+
byte[] teamBytes = BitConverter.GetBytes(playerInstance.PlayerChangeTeamList[ii].Team);
12001201
int bytesWritten = 0;
12011202
WriteProcessMemory((int)processHandle, playerTeamLocation, teamBytes, teamBytes.Length, ref bytesWritten);
1202-
thisInstance.playerChangeTeamList.RemoveAt(ii);
1203+
playerInstance.PlayerChangeTeamList.RemoveAt(ii);
12031204
}
12041205

12051206

@@ -1698,7 +1699,7 @@ public static void ReadMemoryGeneratePlayerList()
16981699
try
16991700
{
17001701
// Try to preserve PlayerJoined if player already exists in the persistent list
1701-
if (thisInstance.playerList.TryGetValue(playerSlot, out var existingPlayer))
1702+
if (playerInstance.PlayerList.TryGetValue(playerSlot, out var existingPlayer))
17021703
{
17031704
PlayerStats.PlayerJoined = existingPlayer.PlayerJoined;
17041705
}
@@ -1737,10 +1738,10 @@ public static void ReadMemoryGeneratePlayerList()
17371738

17381739

17391740
}
1740-
thisInstance.playerList.Clear();
1741+
playerInstance.PlayerList.Clear();
17411742
foreach (var kvp in currentPlayerList)
17421743
{
1743-
thisInstance.playerList[kvp.Key] = kvp.Value;
1744+
playerInstance.PlayerList[kvp.Key] = kvp.Value;
17441745
}
17451746
// CoreManager.DebugLog("PlayerList Updated");
17461747
}

BHD-ServerManager/Classes/InstanceManagers/chatInstanceManager.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,16 @@ public static class chatInstanceManager
4343
{
4444
private static chatInstance instanceChat => CommonCore.instanceChat!;
4545
private static theInstance theInstance => CommonCore.theInstance!;
46+
private static playerInstance playerInstance => CommonCore.instancePlayers!;
4647

47-
// ================================================================================
48-
// SETTINGS MANAGEMENT
49-
// ================================================================================
48+
// ================================================================================
49+
// SETTINGS MANAGEMENT
50+
// ================================================================================
5051

51-
/// <summary>
52-
/// Load chat settings from database
53-
/// </summary>
54-
public static OperationResult LoadSettings()
52+
/// <summary>
53+
/// Load chat settings from database
54+
/// </summary>
55+
public static OperationResult LoadSettings()
5556
{
5657
try
5758
{
@@ -434,7 +435,7 @@ public static (bool success, string message, string errorMessage) ParsePlayerSlo
434435
return (false, message, $"Invalid player slot format: {playerSlotText}");
435436
}
436437

437-
var playerEntry = theInstance.playerList.FirstOrDefault(p => p.Value.PlayerSlot == playerSlot);
438+
var playerEntry = playerInstance.PlayerList.FirstOrDefault(p => p.Value.PlayerSlot == playerSlot);
438439

439440
if (playerEntry.Value == null)
440441
{

BHD-ServerManager/Classes/InstanceManagers/playerInstanceManager.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ public static class playerInstanceManager
1616
private static theInstance theInstance => CommonCore.theInstance!;
1717
private static banInstance banInstance => CommonCore.instanceBans!;
1818

19-
// ================================================================================
20-
// PLAYER VALIDATION
21-
// ================================================================================
19+
private static playerInstance playerInstance => CommonCore.instancePlayers!;
2220

23-
/// <summary>
24-
/// Validate that server is online and player exists
25-
/// </summary>
26-
private static (bool isValid, string errorMessage) ValidatePlayerOperation(int playerSlot, string playerName)
21+
// ================================================================================
22+
// PLAYER VALIDATION
23+
// ================================================================================
24+
25+
/// <summary>
26+
/// Validate that server is online and player exists
27+
/// </summary>
28+
private static (bool isValid, string errorMessage) ValidatePlayerOperation(int playerSlot, string playerName)
2729
{
2830
if (theInstance.instanceStatus == InstanceStatus.OFFLINE)
2931
return (false, "Server is offline. Player operations are not available.");
@@ -34,7 +36,7 @@ private static (bool isValid, string errorMessage) ValidatePlayerOperation(int p
3436
if (string.IsNullOrWhiteSpace(playerName))
3537
return (false, "Player name cannot be empty.");
3638

37-
if (!theInstance.playerList.ContainsKey(playerSlot))
39+
if (!playerInstance.PlayerList.ContainsKey(playerSlot))
3840
return (false, $"Player slot {playerSlot} is empty.");
3941

4042
return (true, string.Empty);
@@ -214,12 +216,12 @@ public static OperationResult SwitchPlayerTeam(int playerSlot, string playerName
214216
return new OperationResult(false, errorMessage);
215217

216218
// Check if already queued for team switch
217-
var existing = theInstance.playerChangeTeamList.FirstOrDefault(p => p.slotNum == playerSlot);
219+
var existing = playerInstance.PlayerChangeTeamList.FirstOrDefault(p => p.slotNum == playerSlot);
218220

219221
if (existing != null)
220222
{
221223
// Undo the team switch
222-
theInstance.playerChangeTeamList.Remove(existing);
224+
playerInstance.PlayerChangeTeamList.Remove(existing);
223225
AppDebug.Log("playerInstanceManager", $"Team switch undone for player {playerName}");
224226
return new OperationResult(true, $"Team switch for {playerName} has been undone.");
225227
}
@@ -238,7 +240,7 @@ public static OperationResult SwitchPlayerTeam(int playerSlot, string playerName
238240
}
239241

240242
// Queue team switch for next map
241-
theInstance.playerChangeTeamList.Add(new playerTeamObject
243+
playerInstance.PlayerChangeTeamList.Add(new playerTeamObject
242244
{
243245
slotNum = playerSlot,
244246
Team = newTeam
@@ -287,7 +289,7 @@ public static OperationResult BanPlayerByName(string playerName, int playerSlot)
287289
return banResult;
288290

289291
// Kick the player if they're online
290-
if (playerSlot > 0 && theInstance.playerList.ContainsKey(playerSlot))
292+
if (playerSlot > 0 && playerInstance.PlayerList.ContainsKey(playerSlot))
291293
{
292294
ServerMemory.WriteMemorySendConsoleCommand($"punt {playerSlot}");
293295
}
@@ -346,7 +348,7 @@ public static async Task<OperationResult> BanPlayerByIPAsync(IPAddress ipAddress
346348
}
347349

348350
// Kick the player if they're online
349-
if (playerSlot > 0 && theInstance.playerList.ContainsKey(playerSlot))
351+
if (playerSlot > 0 && playerInstance.PlayerList.ContainsKey(playerSlot))
350352
{
351353
ServerMemory.WriteMemorySendConsoleCommand($"punt {playerSlot}");
352354
}
@@ -408,7 +410,7 @@ public static async Task<OperationResult> BanPlayerByBothAsync(string playerName
408410
}
409411

410412
// Kick the player if they're online
411-
if (playerSlot > 0 && theInstance.playerList.ContainsKey(playerSlot))
413+
if (playerSlot > 0 && playerInstance.PlayerList.ContainsKey(playerSlot))
412414
{
413415
ServerMemory.WriteMemorySendConsoleCommand($"punt {playerSlot}");
414416
}
@@ -439,7 +441,7 @@ public static OperationResult KickAllPlayers()
439441
return new OperationResult(false, errorMessage);
440442

441443
int kickedCount = 0;
442-
foreach (var player in theInstance.playerList.Values.ToList())
444+
foreach (var player in playerInstance.PlayerList.Values.ToList())
443445
{
444446
ServerMemory.WriteMemorySendConsoleCommand($"punt {player.PlayerSlot}");
445447
kickedCount++;

BHD-ServerManager/Classes/InstanceManagers/theInstanceManager.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public static class theInstanceManager
146146
{
147147
private static ServerManagerUI thisServer => Program.ServerManagerUI!;
148148
private static theInstance theInstance => CommonCore.theInstance!;
149+
private static playerInstance playerInstance => CommonCore.instancePlayers!;
149150

150151
// ================================================================================
151152
// PROFILE SETTINGS MANAGEMENT
@@ -1088,16 +1089,16 @@ public static void changeTeamGameMode(int currentMapType, int nextMapType)
10881089

10891090
if (isNextMapTeamMap == false && isCurrentMapTeamMap == true)
10901091
{
1091-
foreach (var playerRecord in theInstance.playerList)
1092+
foreach (var playerRecord in playerInstance.PlayerList)
10921093
{
10931094
playerObject playerObj = playerRecord.Value;
1094-
theInstance.playerPreviousTeamList.Add(new playerTeamObject
1095+
playerInstance.PlayerPreviousTeamList.Add(new playerTeamObject
10951096
{
10961097
slotNum = playerObj.PlayerSlot,
10971098
Team = playerObj.PlayerTeam
10981099
});
10991100

1100-
theInstance.playerChangeTeamList.Add(new playerTeamObject
1101+
playerInstance.PlayerChangeTeamList.Add(new playerTeamObject
11011102
{
11021103
slotNum = playerObj.PlayerSlot,
11031104
Team = playerObj.PlayerSlot + 5
@@ -1106,22 +1107,22 @@ public static void changeTeamGameMode(int currentMapType, int nextMapType)
11061107
}
11071108
else if (isNextMapTeamMap == true && isCurrentMapTeamMap == false)
11081109
{
1109-
foreach (playerTeamObject playerObj in theInstance.playerPreviousTeamList)
1110+
foreach (playerTeamObject playerObj in playerInstance.PlayerPreviousTeamList)
11101111
{
1111-
if (theInstance.playerList[playerObj.slotNum] != null)
1112+
if (playerInstance.PlayerList[playerObj.slotNum] != null)
11121113
{
1113-
theInstance.playerChangeTeamList.Add(new playerTeamObject
1114+
playerInstance.PlayerChangeTeamList.Add(new playerTeamObject
11141115
{
11151116
slotNum = playerObj.slotNum,
11161117
Team = playerObj.Team
11171118
});
11181119
}
11191120
}
1120-
foreach (var playerRecord in theInstance.playerList)
1121+
foreach (var playerRecord in playerInstance.PlayerList)
11211122
{
11221123
playerObject player = playerRecord.Value;
11231124
bool found = false;
1124-
foreach (playerTeamObject previousPlayer in theInstance.playerPreviousTeamList)
1125+
foreach (playerTeamObject previousPlayer in playerInstance.PlayerPreviousTeamList)
11251126
{
11261127
if (player.PlayerSlot == previousPlayer.slotNum)
11271128
{
@@ -1135,7 +1136,7 @@ public static void changeTeamGameMode(int currentMapType, int nextMapType)
11351136
int blueteam = 0;
11361137
int redteam = 0;
11371138

1138-
foreach (playerTeamObject playerTeam in theInstance.playerPreviousTeamList)
1139+
foreach (playerTeamObject playerTeam in playerInstance.PlayerPreviousTeamList)
11391140
{
11401141
if (playerTeam.Team == (int)Teams.TEAM_BLUE)
11411142
{
@@ -1149,25 +1150,25 @@ public static void changeTeamGameMode(int currentMapType, int nextMapType)
11491150

11501151
if (blueteam > redteam)
11511152
{
1152-
theInstance.playerChangeTeamList.Add(new playerTeamObject
1153+
playerInstance.PlayerChangeTeamList.Add(new playerTeamObject
11531154
{
11541155
slotNum = player.PlayerSlot,
11551156
Team = (int)Teams.TEAM_RED
11561157
});
1157-
theInstance.playerPreviousTeamList.Add(new playerTeamObject
1158+
playerInstance.PlayerPreviousTeamList.Add(new playerTeamObject
11581159
{
11591160
slotNum = player.PlayerSlot,
11601161
Team = (int)Teams.TEAM_RED
11611162
});
11621163
}
11631164
else if (blueteam < redteam)
11641165
{
1165-
theInstance.playerChangeTeamList.Add(new playerTeamObject
1166+
playerInstance.PlayerChangeTeamList.Add(new playerTeamObject
11661167
{
11671168
slotNum = player.PlayerSlot,
11681169
Team = (int)Teams.TEAM_BLUE
11691170
});
1170-
theInstance.playerPreviousTeamList.Add(new playerTeamObject
1171+
playerInstance.PlayerPreviousTeamList.Add(new playerTeamObject
11711172
{
11721173
slotNum = player.PlayerSlot,
11731174
Team = (int)Teams.TEAM_BLUE
@@ -1179,25 +1180,25 @@ public static void changeTeamGameMode(int currentMapType, int nextMapType)
11791180
int rnd = rand.Next(1, 3);
11801181
if (rnd == 1)
11811182
{
1182-
theInstance.playerChangeTeamList.Add(new playerTeamObject
1183+
playerInstance.PlayerChangeTeamList.Add(new playerTeamObject
11831184
{
11841185
slotNum = player.PlayerSlot,
11851186
Team = (int)Teams.TEAM_BLUE
11861187
});
1187-
theInstance.playerPreviousTeamList.Add(new playerTeamObject
1188+
playerInstance.PlayerPreviousTeamList.Add(new playerTeamObject
11881189
{
11891190
slotNum = player.PlayerSlot,
11901191
Team = (int)Teams.TEAM_BLUE
11911192
});
11921193
}
11931194
else if (rnd == 2)
11941195
{
1195-
theInstance.playerChangeTeamList.Add(new playerTeamObject
1196+
playerInstance.PlayerChangeTeamList.Add(new playerTeamObject
11961197
{
11971198
slotNum = player.PlayerSlot,
11981199
Team = (int)Teams.TEAM_RED
11991200
});
1200-
theInstance.playerPreviousTeamList.Add(new playerTeamObject
1201+
playerInstance.PlayerPreviousTeamList.Add(new playerTeamObject
12011202
{
12021203
slotNum = player.PlayerSlot,
12031204
Team = (int)Teams.TEAM_RED
@@ -1206,7 +1207,7 @@ public static void changeTeamGameMode(int currentMapType, int nextMapType)
12061207
}
12071208
}
12081209
}
1209-
theInstance.playerPreviousTeamList.Clear();
1210+
playerInstance.PlayerPreviousTeamList.Clear();
12101211
}
12111212
}
12121213

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using BHD_ServerManager.Classes.ObjectClasses;
2+
using System.Collections.Generic;
3+
4+
namespace BHD_ServerManager.Classes.Instances;
5+
6+
/// <summary>
7+
/// Contains all player-related data that changes frequently during gameplay
8+
/// </summary>
9+
public class playerInstance
10+
{
11+
// Active Players
12+
public Dictionary<int, playerObject> PlayerList { get; set; } = new();
13+
14+
// Team Management
15+
public List<playerTeamObject> PlayerChangeTeamList { get; set; } = new();
16+
public List<playerTeamObject> PlayerPreviousTeamList { get; set; } = new();
17+
18+
}

BHD-ServerManager/Classes/Instances/theInstance.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,11 @@ public class theInstance
168168
public bool banInstanceUpdated { get; set; } = false;
169169

170170
// Player Team Information
171+
[Obsolete("Use playerInstance Object instead.")]
171172
public Dictionary<int, playerObject> playerList { get; set; } = new();
173+
[Obsolete("Use playerInstance Object instead.")]
172174
public List<playerTeamObject> playerChangeTeamList { get; set; } = new();
175+
[Obsolete("Use playerInstance Object instead.")]
173176
public List<playerTeamObject> playerPreviousTeamList { get; set; } = new();
174177

175178
// Map Playlist

0 commit comments

Comments
 (0)