Skip to content

Commit 793fac5

Browse files
author
Matthew Bate
committed
Ready for Ban tabs
1 parent b984824 commit 793fac5

File tree

7 files changed

+18
-88
lines changed

7 files changed

+18
-88
lines changed

BHD-ServerManager/API/Controllers/SnapshotController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public ActionResult<ServerSnapshot> GetSnapshot()
2121

2222
var snapshot = InstanceMapper.CreateSnapshot(
2323
CommonCore.theInstance,
24-
CommonCore.instancePlayers!.PlayerList ?? new(),
24+
CommonCore.instancePlayers ?? new(),
2525
CommonCore.instanceChat ?? new(),
2626
CommonCore.instanceBans ?? new(),
2727
CommonCore.instanceMaps ?? new()

BHD-ServerManager/API/Services/InstanceBroadcastService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
3333

3434
var snapshot = InstanceMapper.CreateSnapshot(
3535
CommonCore.theInstance,
36-
CommonCore.instancePlayers!.PlayerList ?? new(),
36+
CommonCore.instancePlayers ?? new(),
3737
CommonCore.instanceChat ?? new(),
3838
CommonCore.instanceBans ?? new(),
3939
CommonCore.instanceMaps ?? new()

BHD-ServerManager/API/Services/InstanceMapper.cs

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -12,92 +12,20 @@ public static class InstanceMapper
1212

1313
public static ServerSnapshot CreateSnapshot(
1414
theInstance server,
15-
Dictionary<int, playerObject> playerList,
15+
playerInstance playerList,
1616
chatInstance chat,
1717
banInstance bans,
1818
mapInstance maps)
1919
{
2020
return new ServerSnapshot
2121
{
2222
ServerData = server,
23-
Players = MapPlayerInstance(playerList),
23+
Players = playerList,
2424
Chat = chat,
25-
Bans = MapBanInstance(bans),
25+
Bans = bans,
2626
Maps = maps,
2727
SnapshotTime = DateTime.UtcNow
2828
};
2929
}
3030

31-
private static PlayerInstanceDTO MapPlayerInstance(Dictionary<int, playerObject> playerList)
32-
{
33-
var players = playerList.ToDictionary(
34-
kvp => kvp.Key,
35-
kvp => new PlayerDTO
36-
{
37-
Slot = kvp.Value.PlayerSlot,
38-
Name = DecodePlayerName(kvp.Value.PlayerNameBase64),
39-
IPAddress = kvp.Value.PlayerIPAddress,
40-
Team = kvp.Value.PlayerTeam,
41-
Ping = kvp.Value.PlayerPing,
42-
Kills = kvp.Value.stat_Kills,
43-
Deaths = kvp.Value.stat_Deaths
44-
}
45-
);
46-
47-
return new PlayerInstanceDTO { Players = players };
48-
}
49-
50-
private static ChatInstanceDTO MapChatInstance(chatInstance chat)
51-
{
52-
return new ChatInstanceDTO
53-
{
54-
RecentMessages = chat.ChatLog.TakeLast(100).Select(log => new ChatMessageDTO
55-
{
56-
Timestamp = log.MessageTimeStamp,
57-
PlayerName = log.PlayerName,
58-
Message = log.MessageText,
59-
Team = GetTeamName(log.MessageType2)
60-
}).ToList(),
61-
SlapMessages = chat.SlapMessages.Select(s =>
62-
new SlapMessageDTO(s.SlapMessageId, s.SlapMessageText)).ToList()
63-
};
64-
}
65-
66-
private static BanInstanceDTO MapBanInstance(banInstance bans)
67-
{
68-
return new BanInstanceDTO
69-
{
70-
BannedNames = bans.BannedPlayerNames.Select(b =>
71-
new BannedNameDTO(b.RecordID, b.PlayerName, b.Date, b.RecordType.ToString())).ToList(),
72-
BannedIPs = bans.BannedPlayerIPs.Select(b =>
73-
new BannedIPDTO(b.RecordID, b.PlayerIP.ToString(), b.SubnetMask, b.Date, b.RecordType.ToString())).ToList(),
74-
WhitelistedNames = bans.WhitelistedNames.Select(w =>
75-
new WhitelistedNameDTO(w.RecordID, w.PlayerName)).ToList()
76-
};
77-
}
78-
79-
private static string DecodePlayerName(string? base64)
80-
{
81-
if (string.IsNullOrEmpty(base64)) return "Unknown";
82-
try
83-
{
84-
byte[] bytes = Convert.FromBase64String(base64);
85-
return Encoding.GetEncoding("Windows-1252").GetString(bytes);
86-
}
87-
catch
88-
{
89-
return "Unknown";
90-
}
91-
}
92-
93-
private static string GetTeamName(int messageType2)
94-
{
95-
return messageType2 switch
96-
{
97-
1 => "Blue",
98-
2 => "Red",
99-
3 => "Host",
100-
_ => "All"
101-
};
102-
}
10331
}

BHD-ServerManager/Forms/Panels/tabBans.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ private void Blacklist_Save_Click(object sender, EventArgs e)
566566
blacklist_btnDelete.Visible = false;
567567
blacklist_btnSave.Visible = false;
568568
blacklist_btnReset.Visible = false;
569+
blacklist_btnClose.Visible = false;
569570

570571
MessageBox.Show("Ban record saved successfully.", "Success",
571572
MessageBoxButtons.OK, MessageBoxIcon.Information);
@@ -1456,6 +1457,12 @@ private void Whitelist_Save_Click(object sender, EventArgs e)
14561457
Whitelist_Reset_Click(sender, e);
14571458
panel2.Visible = false;
14581459

1460+
// Control Buttons
1461+
wlControlClose.Visible = false;
1462+
wlControlSave.Visible = false;
1463+
wlControlDelete.Visible = false;
1464+
wlControlReset.Visible = false;
1465+
14591466
MessageBox.Show("Whitelist record saved successfully.", "Success",
14601467
MessageBoxButtons.OK, MessageBoxIcon.Information);
14611468
}

HawkSyncShared/DTOs/InstanceSnapshots.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ namespace HawkSyncShared.DTOs;
55
public record ServerSnapshot
66
{
77
public theInstance ServerData { get; init; } = new();
8-
public PlayerInstanceDTO Players { get; init; } = new();
8+
public playerInstance Players { get; init; } = new();
99
public chatInstance Chat { get; init; } = new();
10-
public BanInstanceDTO Bans { get; init; } = new();
10+
public banInstance Bans { get; init; } = new();
1111
public mapInstance Maps { get; init; } = new();
1212
public DateTime SnapshotTime { get; init; } = DateTime.UtcNow;
1313
}

RemoteClient/Forms/Panels/tabPlayers.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,13 @@ private void OnSnapshotReceived(ServerSnapshot snapshot)
1717
{
1818
if (InvokeRequired)
1919
{
20-
Invoke(() => UpdatePlayerGrid(snapshot.Players));
20+
Invoke(() => OnSnapshotReceived(snapshot));
21+
return;
2122
}
22-
else
23-
{
24-
UpdatePlayerGrid(snapshot.Players);
25-
}
26-
}
27-
28-
private void UpdatePlayerGrid(PlayerInstanceDTO players)
29-
{
3023

3124
}
3225

3326

3427

28+
3529
}

RemoteClient/Forms/ServerManagerUI.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ private void OnSnapshotReceived(ServerSnapshot snapshot)
100100
CommonCore.theInstance = snapshot.ServerData;
101101
CommonCore.instanceChat = snapshot.Chat;
102102
CommonCore.instanceMaps = snapshot.Maps;
103+
CommonCore.instanceBans = snapshot.Bans;
103104

104105
AppDebug.Log("ServerManagerUI", "Snapshot received, updating server info panel. Active Playlist: " + CommonCore.instanceMaps.ActivePlaylist);
105106

0 commit comments

Comments
 (0)