remove username sniffer

This commit is contained in:
iceBear67
2026-07-15 16:05:34 +00:00
parent bbe4efbe16
commit a41cb7965e
5 changed files with 14 additions and 40 deletions
@@ -43,17 +43,16 @@ public final class ControlSession {
}
}
public void sendControlRequest(byte[] cid, String pattern, String playerIp, int playerPort, String username) {
public void sendControlRequest(byte[] cid, String pattern, String playerIp, int playerPort) {
byte[] msg = new ProtoWriter()
.u8(Protocol.CTL_CONTROL_REQUEST)
.bytes(cid)
.string(pattern)
.string(playerIp)
.u16(playerPort)
.string(username)
.toBytes();
frames.send(msg);
LOG.info("control-request pattern={} player={}:{} user={}", pattern, playerIp, playerPort, username);
LOG.info("control-request pattern={} player={}:{}", pattern, playerIp, playerPort);
}
private void sendRegisterAck(String pattern, int status) {
@@ -106,7 +106,7 @@ public final class HubConnection {
LOG.info("{} reserved intent 18; closing", id);
socket.close();
} else {
handlePlayer(address, intent, afterHandshake);
handlePlayer(address);
}
}
@@ -203,7 +203,7 @@ public final class HubConnection {
// ---- player connection ----
private void handlePlayer(String address, int intent, Buffer afterHandshake) {
private void handlePlayer(String address) {
String host = Hub.normalizeAddress(address);
Hub.Match matched = hub.match(address);
if (matched == null) {
@@ -219,9 +219,6 @@ public final class HubConnection {
String cidHex = Hex.encode(cid);
String ip = socket.remoteAddress() != null ? socket.remoteAddress().host() : "0.0.0.0";
int port = socket.remoteAddress() != null ? socket.remoteAddress().port() : 0;
// Best-effort username: only login/transfer intents carry a Login Start, and only
// if the client pipelined it into this same buffer (the usual case).
String username = (intent == 2 || intent == 3) ? parseLoginName(afterHandshake) : "";
socket.pause();
Buffer buffered = hs.copy(); // handshake + any pipelined bytes, forwarded verbatim
@@ -230,27 +227,8 @@ public final class HubConnection {
hub.addPending(p);
closeCleanup = () -> hub.removePending(cidHex);
session.sendControlRequest(cid, pattern, ip, port, username);
LOG.info("{} player {}:{} host '{}' user '{}' matched pattern '{}' cid={}",
id, ip, port, host, username, pattern, cidHex);
}
/**
* Best-effort read of the player's username from a pipelined Login Start packet
* (Login state, packet id 0x00, first field {@code Name: String}). Returns "" if
* the packet is not (yet) fully present or does not parse as a Login Start; the hub
* never blocks waiting for it.
*/
private static String parseLoginName(Buffer afterHandshake) {
if (afterHandshake == null || afterHandshake.length() == 0) return "";
try {
ProtoReader r = new ProtoReader(afterHandshake);
int pktLen = r.readVarInt();
if (pktLen <= 0 || pktLen > r.remaining()) return ""; // not fully buffered
if (r.readVarInt() != 0x00) return ""; // not a Login Start
return r.readString();
} catch (RuntimeException e) {
return "";
}
session.sendControlRequest(cid, pattern, ip, port);
LOG.info("{} player {}:{} host '{}' matched pattern '{}' cid={}",
id, ip, port, host, pattern, cidHex);
}
}