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);