From eac81918e538492966c40838caad239cdb18ae31 Mon Sep 17 00:00:00 2001 From: RayzsYT <51991564+RayzsYT@users.noreply.github.com> Date: Tue, 21 May 2024 01:44:29 +0200 Subject: [PATCH] Better Client Identification --- .../pat/api/communication/ClientCommunication.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/rayzs/pat/api/communication/ClientCommunication.java b/src/main/java/de/rayzs/pat/api/communication/ClientCommunication.java index 02b3564a..2b9fa75a 100644 --- a/src/main/java/de/rayzs/pat/api/communication/ClientCommunication.java +++ b/src/main/java/de/rayzs/pat/api/communication/ClientCommunication.java @@ -32,18 +32,18 @@ public class ClientCommunication { clientInfo.sendBytes(DataConverter.convertToBytes(packet)); } - public static void receiveInformation(String serverName, Object packet, Object serverObj) { + public static void receiveInformation(String serverName, Object packet) { if(packet instanceof DataConverter.RequestPacket) { DataConverter.RequestPacket requestPacket = (DataConverter.RequestPacket) packet; if (!requestPacket.isToken(Storage.TOKEN)) return; - ClientInfo client = getClientById(requestPacket.getServerId()); + ClientInfo client = getClientByName(serverName); if (client == null) { client = Reflection.isVelocityServer() ? new VelocityClientInfo(requestPacket.getServerId(), serverName) : new BungeeClientInfo(requestPacket.getServerId(), serverName); CLIENTS.add(client); } - if (!client.getName().equals(serverName)) client.setName(serverName); + if (!client.compareId(requestPacket.getServerId())) client.setId(requestPacket.getServerId()); syncData(client.getId()); return; @@ -61,13 +61,13 @@ public class ClientCommunication { if (!feedbackPacket.isToken(Storage.TOKEN)) return; String serverId = feedbackPacket.getServerId(); - ClientInfo client = getClientById(feedbackPacket.getServerId()); + ClientInfo client = getClientByName(serverName); if (client == null) { client = Reflection.isVelocityServer() ? new VelocityClientInfo(feedbackPacket.getServerId(), serverName) : new BungeeClientInfo(feedbackPacket.getServerId(), serverName); CLIENTS.add(client); } - if (!client.getName().equals(serverName)) client.setName(serverName); + if (!client.compareId(feedbackPacket.getServerId())) client.setId(feedbackPacket.getServerId()); if (client.hasSentFeedback()) return; client.setFeedback(true); @@ -145,6 +145,10 @@ public class ClientCommunication { return CLIENTS.isEmpty() ? null : CLIENTS.stream().filter(client -> client != null && client.compareId(id)).findFirst().orElse(null); } + public static ClientInfo getClientByName(String name) { + return CLIENTS.isEmpty() ? null : CLIENTS.stream().filter(client -> client != null && client.getName().equals(name)).findFirst().orElse(null); + } + public static ClientInfo getQueueClientById(String id) { return QUEUE_CLIENTS.get(id); }