From 395470b38c241458ea507ba979ce22f1ad75c365 Mon Sep 17 00:00:00 2001 From: Popax21 Date: Wed, 24 Jul 2024 02:35:19 +0200 Subject: [PATCH] Rename ConnInfo to ExtHandshakeCheckValues Turns out the variable was just poorly named :catplush: --- .../frontend/cp/js/components/dialog.js | 8 +++--- .../Content/frontend/cp/js/panels/players.js | 8 +++--- CelesteNet.Server.FrontendModule/Frontend.cs | 7 ++--- .../WSCMDs/WSCMDsExtra.cs | 28 +++++++++---------- .../ConPlus/ExtendedHandshake.cs | 8 ++---- CelesteNet.Server/ConPlus/TCPUDPConnection.cs | 4 --- 6 files changed, 26 insertions(+), 37 deletions(-) diff --git a/CelesteNet.Server.FrontendModule/Content/frontend/cp/js/components/dialog.js b/CelesteNet.Server.FrontendModule/Content/frontend/cp/js/components/dialog.js index ece01aaa..fa62203c 100644 --- a/CelesteNet.Server.FrontendModule/Content/frontend/cp/js/components/dialog.js +++ b/CelesteNet.Server.FrontendModule/Content/frontend/cp/js/components/dialog.js @@ -368,8 +368,8 @@ export class FrontendDialog { ${group( row( el => { let optKeys = opts.map(e => e[0] + '#' + e[1]); - el = mdcrd.dropdown("connInfo", optKeys, 0)(el); - el.id = "connInfo-select"; + el = mdcrd.dropdown("checkValue", optKeys, 0)(el); + el.id = "checkValue-select"; return el; }), row(input("banext-connUID", mdcrd.checkbox(`Also ban Conn UID: ${connectionUID}`, true))), @@ -400,7 +400,7 @@ export class FrontendDialog { let promise = new Promise( resolve => el.addEventListener("MDCDialog:closed", e => resolve(e["detail"]["action"] === "0" && { - selection: el.querySelector("#connInfo-select .mdc-select__selected-text")["value"], + selection: el.querySelector("#checkValue-select .mdc-select__selected-text")["value"], banConnUID: el.querySelector("#banext-connUID input")["checked"], reason: el.querySelector("#banext-reason input")["value"], quiet: el.querySelector("#banext-quiet input")["checked"], @@ -412,7 +412,7 @@ export class FrontendDialog { ban => { if (!ban || !(ban.reason = ban.reason.trim())) return; - this.frontend.sync.run("banext", { ID: id, ConnUID: connectionUID, ConnInfo: ban.selection, BanConnUID: ban.banConnUID, Reason: ban.reason, Quiet: ban.quiet }); + this.frontend.sync.run("banext", { ID: id, ConnUID: connectionUID, CheckValue: ban.selection, BanConnUID: ban.banConnUID, Reason: ban.reason, Quiet: ban.quiet }); } ); diff --git a/CelesteNet.Server.FrontendModule/Content/frontend/cp/js/panels/players.js b/CelesteNet.Server.FrontendModule/Content/frontend/cp/js/panels/players.js index 8d243c2a..91bfacd9 100644 --- a/CelesteNet.Server.FrontendModule/Content/frontend/cp/js/panels/players.js +++ b/CelesteNet.Server.FrontendModule/Content/frontend/cp/js/panels/players.js @@ -23,7 +23,7 @@ const mdc = window["mdc"]; // mdc UDPDownlinkBpS: number?, UDPDownlinkPpS: number?, TCPUplinkBpS: number?, TCPUplinkPpS: number?, UDPUplinkBpS: number?, UDPUplinkPpS: number?, - ConnInfo: Map? + ExtHandshakeCheckValues: Map? }} PlayerData */ @@ -115,10 +115,10 @@ export class FrontendPlayersPanel extends FrontendBasicPanel { UDP ↑:${` ${p.UDPUplinkBpS ? `${p.UDPUplinkBpS.toFixed(3)} BpS` : '-'} | ${p.UDPUplinkPpS ? `${p.UDPUplinkPpS.toFixed(3)} PpS` : '-'}`}
${el => { el = rd$(el)``; - if (!p.hasOwnProperty("ConnInfo")) + if (!p.hasOwnProperty("ExtHandshakeCheckValues")) return el; let list = new RDOMListHelper(el); - for (const [cikey, civalue] of Object.entries(p.ConnInfo)) { + for (const [cikey, civalue] of Object.entries(p.ExtHandshakeCheckValues)) { list.add(cikey, el => rd$(el)`${cikey}: ${civalue}
`); } list.end(); @@ -131,7 +131,7 @@ export class FrontendPlayersPanel extends FrontendBasicPanel { this.frontend.dom.setContext(el, [ "error_outline", `Kick ${p.FullName}`, () => this.frontend.dialog.kick(p.FullName, p.ID) ], [ "gavel", `Ban ${p.FullName}`, () => this.frontend.dialog.ban(p.FullName, p.ID, p.UID, p.ConnectionUID) ], - [ "gavel", `BanExt ${p.FullName}`, () => p.hasOwnProperty("ConnInfo") ? this.frontend.dialog.banExt(p.FullName, p.ID, Object.entries(p.ConnInfo), p.ConnectionUID) : null ], + [ "gavel", `BanExt ${p.FullName}`, () => p.hasOwnProperty("ExtHandshakeCheckValues") ? this.frontend.dialog.banExt(p.FullName, p.ID, Object.entries(p.ExtHandshakeCheckValues), p.ConnectionUID) : null ], [ "content_copy", `Copy FullName: ${p.FullName}`, () => navigator.clipboard.writeText(p.FullName) ], [ "content_copy", `Copy UID: ${p.UID}`, () => navigator.clipboard.writeText(p.UID) ], [ "content_copy", `Copy Con: ${p.ConnectionUID}`, () => navigator.clipboard.writeText(p.ConnectionUID) ], diff --git a/CelesteNet.Server.FrontendModule/Frontend.cs b/CelesteNet.Server.FrontendModule/Frontend.cs index 5b6af3f4..f016a131 100644 --- a/CelesteNet.Server.FrontendModule/Frontend.cs +++ b/CelesteNet.Server.FrontendModule/Frontend.cs @@ -269,11 +269,8 @@ public object PlayerSessionToFrontend(CelesteNetPlayerSession p, bool auth = fal player.UDPUplinkPpS = pCon?.UDPSendRate.PacketRate; } - player.ConnInfo = new Dictionary(); - if (pCon != null) { - foreach (IConnectionInfoProvider conInfoProv in pCon.IterAssociatedData()) - conInfoProv.DumpConnectionInfo(player.ConnInfo); - } + if (pCon?.GetAssociatedData() is ExtendedHandshake.ConnectionData conData && conData.CheckEntriesValid) + player.ExtHandshakeCheckValues = new Dictionary(conData.CheckEntries); return player; } diff --git a/CelesteNet.Server.FrontendModule/WSCMDs/WSCMDsExtra.cs b/CelesteNet.Server.FrontendModule/WSCMDs/WSCMDsExtra.cs index 15b76069..698fd341 100644 --- a/CelesteNet.Server.FrontendModule/WSCMDs/WSCMDsExtra.cs +++ b/CelesteNet.Server.FrontendModule/WSCMDs/WSCMDsExtra.cs @@ -9,24 +9,24 @@ public class WSCMDBanExt : WSCMD { public override bool MustAuth => true; public override object? Run(dynamic? input) { uint id = (uint)input?.ID; - string? connInfo = (string?)input?.ConnInfo; + string? checkValue = (string?)input?.CheckValue; bool? banConnUID = (bool?)input?.BanConnUID; string? reason = (string?)input?.Reason; string? connUid = (string?)input?.ConnUID; bool quiet = ((bool?)input?.Quiet) ?? false; - Logger.Log(LogLevel.VVV, "frontend", $"BanExt called:\n{connUid} => {connInfo} (ban connUID: {banConnUID}, q: {quiet})\nReason: {reason}"); + Logger.Log(LogLevel.VVV, "frontend", $"BanExt called:\n{connUid} => {checkValue} (ban connUID: {banConnUID}, q: {quiet})\nReason: {reason}"); - if ((connInfo = connInfo?.Trim() ?? "").IsNullOrEmpty() || + if ((checkValue = checkValue?.Trim() ?? "").IsNullOrEmpty() || (reason = reason?.Trim() ?? "").IsNullOrEmpty() || (connUid = connUid?.Trim() ?? "").IsNullOrEmpty()) return false; - // connInfo should include "key" at this point e.g. CheckMAC#Y2F0IGdvZXMgbWVvdw== - string[] splitConnInfo = connInfo.Split('#'); - Logger.Log(LogLevel.VVV, "frontend", $"BanExt split connInfo: {splitConnInfo}"); + // checkValue should include "key" at this point e.g. CheckMAC#Y2F0IGdvZXMgbWVvdw== + string[] splitCheckValue = checkValue.Split('#'); + Logger.Log(LogLevel.VVV, "frontend", $"BanExt split checkValue: {splitCheckValue}"); - if (splitConnInfo.Length < 2) + if (splitCheckValue.Length < 2) return false; CelesteNetPlayerSession[] players; @@ -38,14 +38,14 @@ public class WSCMDBanExt : WSCMD { Frontend.Server.PlayersByID.TryGetValue(id, out p); } - string connInfoVal = splitConnInfo[1]; + string checkValueVal = splitCheckValue[1]; // Just to make extra sure we got the right guy, I guess if (p != null && p.Con is ConPlusTCPUDPConnection pCon && pCon.GetAssociatedData() is ExtendedHandshake.ConnectionData conData - && conData.CheckEntries.TryGetValue(splitConnInfo[0], out string? connVal) + && conData.CheckEntries.TryGetValue(splitCheckValue[0], out string? connVal) && !string.IsNullOrEmpty(connVal)) { - connInfoVal = connVal; + checkValueVal = connVal; } // UID will be the connectionUID as extra info, further down the banned identifier is where it'll be stored @@ -60,7 +60,7 @@ public class WSCMDBanExt : WSCMD { if (plusCon == null) continue; - if (!(plusCon.GetAssociatedData() is ExtendedHandshake.ConnectionData plConData && plConData.CheckEntries.ContainsKey(connInfoVal))) + if (!(plusCon.GetAssociatedData() is ExtendedHandshake.ConnectionData plConData && plConData.CheckEntries.ContainsKey(checkValueVal))) continue; if (ban.Name.IsNullOrEmpty()) @@ -74,10 +74,10 @@ public class WSCMDBanExt : WSCMD { player.Dispose(); } - // stored with the "full" connInfo which includes the "key" e.g. CheckMAC#Y2F0IGdvZXMgbWVvdw== - Frontend.Server.UserData.Save(connInfo, ban); + // stored with the "full" checkVal which includes the "key" e.g. CheckMAC#Y2F0IGdvZXMgbWVvdw== + Frontend.Server.UserData.Save(checkValue, ban); - Logger.Log(LogLevel.VVV, "frontend", $"BanExt ban saved for: {connInfo}"); + Logger.Log(LogLevel.VVV, "frontend", $"BanExt ban saved for: {checkValue}"); if (banConnUID ?? false) { // reuse banInfo but store for connection UID like a regular ban diff --git a/CelesteNet.Server/ConPlus/ExtendedHandshake.cs b/CelesteNet.Server/ConPlus/ExtendedHandshake.cs index 4c7c429b..f20f878e 100644 --- a/CelesteNet.Server/ConPlus/ExtendedHandshake.cs +++ b/CelesteNet.Server/ConPlus/ExtendedHandshake.cs @@ -4,12 +4,12 @@ using System.Threading.Tasks; using Celeste.Mod.CelesteNet.DataTypes; using Celeste.Mod.CelesteNet.Server; -using MonoMod.Utils; namespace Celeste.Mod.CelesteNet { public class ExtendedHandshake : IConnectionFeature { - public record ConnectionData(string CheckEnv = "", string CheckMAC = "", string CheckDevice = "", string SelfReportBan = "") : IConnectionInfoProvider { + public record ConnectionData(string CheckEnv = "", string CheckMAC = "", string CheckDevice = "", string SelfReportBan = "") { + public IDictionary CheckEntries => new Dictionary() { ["CheckEnv"] = CheckEnv, ["CheckMAC"] = CheckMAC, @@ -18,10 +18,6 @@ public record ConnectionData(string CheckEnv = "", string CheckMAC = "", string public bool CheckEntriesValid => CheckEntries.All(e => !e.Value.IsNullOrEmpty()); - public void DumpConnectionInfo(IDictionary conInfo) { - conInfo.AddRange(CheckEntries); - conInfo.Add("SelfReportBan", SelfReportBan); - } } public static string? ClientCheck(ConPlusTCPUDPConnection con, ConnectionData conData) { diff --git a/CelesteNet.Server/ConPlus/TCPUDPConnection.cs b/CelesteNet.Server/ConPlus/TCPUDPConnection.cs index c3b35dc4..90cf746a 100644 --- a/CelesteNet.Server/ConPlus/TCPUDPConnection.cs +++ b/CelesteNet.Server/ConPlus/TCPUDPConnection.cs @@ -489,8 +489,4 @@ public void HandleUDPDatagram(byte[] buffer, int dgSize) { } } - - public interface IConnectionInfoProvider { - void DumpConnectionInfo(IDictionary conInfo); - } } \ No newline at end of file