From 4d4fe71a84cd3477f4385821cc7905d8cd7b1157 Mon Sep 17 00:00:00 2001 From: Shuiling <1668589925@qq.com> Date: Mon, 16 Sep 2024 22:23:40 -0700 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D/server=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E7=94=A8=E4=B8=8D=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catseedlogin/bukkit/Communication.java | 17 +++++++++-------- .../catseedlogin/bungee/Communication.java | 18 +++++++++++++----- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/main/java/cc/baka9/catseedlogin/bukkit/Communication.java b/src/main/java/cc/baka9/catseedlogin/bukkit/Communication.java index e1e60a5..5d226be 100644 --- a/src/main/java/cc/baka9/catseedlogin/bukkit/Communication.java +++ b/src/main/java/cc/baka9/catseedlogin/bukkit/Communication.java @@ -1,22 +1,22 @@ package cc.baka9.catseedlogin.bukkit; -import java.net.Socket; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; import java.net.InetAddress; import java.net.ServerSocket; -import java.io.BufferedReader; -import java.io.InputStreamReader; +import java.net.Socket; import java.net.UnknownHostException; -import java.util.concurrent.Executors; import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import cc.baka9.catseedlogin.bukkit.database.Cache; -import cc.baka9.catseedlogin.util.CommunicationAuth; import cc.baka9.catseedlogin.bukkit.object.LoginPlayer; import cc.baka9.catseedlogin.bukkit.object.LoginPlayerHelper; +import cc.baka9.catseedlogin.util.CommunicationAuth; public class Communication { private static ServerSocket serverSocket; @@ -62,8 +62,9 @@ private static void acceptConnections(ServerSocket serverSocket) { private static void handleRequest(Socket socket) { - try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream())); - Socket autoCloseSocket = socket) { + BufferedReader bufferedReader = null; + try { + bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream())); String requestType = bufferedReader.readLine(); if (requestType == null) { return; @@ -71,7 +72,7 @@ private static void handleRequest(Socket socket) { String playerName = bufferedReader.readLine(); switch (requestType) { case "Connect": - handleConnectRequest(autoCloseSocket, playerName); + handleConnectRequest(socket, playerName); break; case "KeepLoggedIn": String time = bufferedReader.readLine(); diff --git a/src/main/java/cc/baka9/catseedlogin/bungee/Communication.java b/src/main/java/cc/baka9/catseedlogin/bungee/Communication.java index 32d3cd2..d00579c 100644 --- a/src/main/java/cc/baka9/catseedlogin/bungee/Communication.java +++ b/src/main/java/cc/baka9/catseedlogin/bungee/Communication.java @@ -1,12 +1,12 @@ package cc.baka9.catseedlogin.bungee; -import java.io.BufferedWriter; +import java.net.Socket; import java.io.IOException; +import java.io.BufferedWriter; import java.io.OutputStreamWriter; -import java.net.Socket; -import cc.baka9.catseedlogin.util.CommunicationAuth; import net.md_5.bungee.api.ProxyServer; +import cc.baka9.catseedlogin.util.CommunicationAuth; /** * bc 与 bukkit 的通讯交流 @@ -16,7 +16,11 @@ public class Communication { private static final int PORT = Config.Port; public static int sendConnectRequest(String playerName) { - try (Socket socket = getSocket(); BufferedWriter writer = getSocketBufferedWriter(socket)) { + Socket socket = null; + BufferedWriter writer = null; + try { + socket = getSocket(); + writer = getSocketBufferedWriter(socket); writeMessage(writer, "Connect", playerName); return socket.getInputStream().read(); } catch (IOException e) { @@ -26,7 +30,11 @@ public static int sendConnectRequest(String playerName) { } public static void sendKeepLoggedInRequest(String playerName) { - try (Socket socket = getSocket(); BufferedWriter writer = getSocketBufferedWriter(socket)) { + Socket socket = null; + BufferedWriter writer = null; + try { + socket = getSocket(); + writer = getSocketBufferedWriter(socket); long currentTime = System.currentTimeMillis(); String time = String.valueOf(currentTime); String sign = CommunicationAuth.encryption(playerName, time, Config.AuthKey);