Skip to content

Commit

Permalink
Rename ConnInfo to ExtHandshakeCheckValues
Browse files Browse the repository at this point in the history
Turns out the variable was just poorly named :catplush:
  • Loading branch information
Popax21 committed Jul 24, 2024
1 parent d62eb18 commit 395470b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))),
Expand Down Expand Up @@ -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"],
Expand All @@ -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 });
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const mdc = window["mdc"]; // mdc
UDPDownlinkBpS: number?, UDPDownlinkPpS: number?,
TCPUplinkBpS: number?, TCPUplinkPpS: number?,
UDPUplinkBpS: number?, UDPUplinkPpS: number?,
ConnInfo: Map<string, string>?
ExtHandshakeCheckValues: Map<string, string>?
}} PlayerData
*/

Expand Down Expand Up @@ -115,10 +115,10 @@ export class FrontendPlayersPanel extends FrontendBasicPanel {
<code>UDP ↑:${` ${p.UDPUplinkBpS ? `${p.UDPUplinkBpS.toFixed(3)} BpS` : '-'} | ${p.UDPUplinkPpS ? `${p.UDPUplinkPpS.toFixed(3)} PpS` : '-'}`}</code><br>
${el => {
el = rd$(el)`<span></span>`;
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)`<code>${cikey}:&nbsp;${civalue}<br></code>`);
}
list.end();
Expand All @@ -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) ],
Expand Down
7 changes: 2 additions & 5 deletions CelesteNet.Server.FrontendModule/Frontend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,8 @@ public object PlayerSessionToFrontend(CelesteNetPlayerSession p, bool auth = fal
player.UDPUplinkPpS = pCon?.UDPSendRate.PacketRate;
}

player.ConnInfo = new Dictionary<string, string>();
if (pCon != null) {
foreach (IConnectionInfoProvider conInfoProv in pCon.IterAssociatedData<IConnectionInfoProvider>())
conInfoProv.DumpConnectionInfo(player.ConnInfo);
}
if (pCon?.GetAssociatedData<ExtendedHandshake.ConnectionData>() is ExtendedHandshake.ConnectionData conData && conData.CheckEntriesValid)
player.ExtHandshakeCheckValues = new Dictionary<string, string>(conData.CheckEntries);

return player;
}
Expand Down
28 changes: 14 additions & 14 deletions CelesteNet.Server.FrontendModule/WSCMDs/WSCMDsExtra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ExtendedHandshake.ConnectionData>() 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
Expand All @@ -60,7 +60,7 @@ public class WSCMDBanExt : WSCMD {
if (plusCon == null)
continue;

if (!(plusCon.GetAssociatedData<ExtendedHandshake.ConnectionData>() is ExtendedHandshake.ConnectionData plConData && plConData.CheckEntries.ContainsKey(connInfoVal)))
if (!(plusCon.GetAssociatedData<ExtendedHandshake.ConnectionData>() is ExtendedHandshake.ConnectionData plConData && plConData.CheckEntries.ContainsKey(checkValueVal)))
continue;

if (ban.Name.IsNullOrEmpty())
Expand All @@ -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
Expand Down
8 changes: 2 additions & 6 deletions CelesteNet.Server/ConPlus/ExtendedHandshake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> CheckEntries => new Dictionary<string, string>() {
["CheckEnv"] = CheckEnv,
["CheckMAC"] = CheckMAC,
Expand All @@ -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<string, string> conInfo) {
conInfo.AddRange(CheckEntries);
conInfo.Add("SelfReportBan", SelfReportBan);
}
}

public static string? ClientCheck(ConPlusTCPUDPConnection con, ConnectionData conData) {
Expand Down
4 changes: 0 additions & 4 deletions CelesteNet.Server/ConPlus/TCPUDPConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,4 @@ public void HandleUDPDatagram(byte[] buffer, int dgSize) {
}

}

public interface IConnectionInfoProvider {
void DumpConnectionInfo(IDictionary<string, string> conInfo);
}
}

0 comments on commit 395470b

Please sign in to comment.