diff --git a/src/com/projectswg/ClientConnection.java b/src/com/projectswg/ClientConnection.java index a9a9637..f528991 100644 --- a/src/com/projectswg/ClientConnection.java +++ b/src/com/projectswg/ClientConnection.java @@ -139,7 +139,9 @@ public class ClientConnection { private void ping() { if (!connected) return; - if (receiver.getTimeSinceLastPacket() > 5000) + if (receiver.getTimeSinceLastPacket() > 5000 && !interceptor.getData().isZoning()) + onDisconnected(); + else if (receiver.getTimeSinceLastPacket() > 15000 && interceptor.getData().isZoning()) onDisconnected(); else sender.send(new HeartBeat().encode().array()); diff --git a/src/com/projectswg/Connections.java b/src/com/projectswg/Connections.java index f138142..34f2a19 100644 --- a/src/com/projectswg/Connections.java +++ b/src/com/projectswg/Connections.java @@ -51,9 +51,12 @@ public class Connections { public void terminate() { server.stop(); - for (int i = 0; i < 3; i++) { - if (client.restart()) + while (!client.restart()) { + try { + Thread.sleep(5); + } catch (InterruptedException e) { break; + } } } diff --git a/src/com/projectswg/ServerConnection.java b/src/com/projectswg/ServerConnection.java index 76edd3a..657ae9a 100644 --- a/src/com/projectswg/ServerConnection.java +++ b/src/com/projectswg/ServerConnection.java @@ -11,6 +11,7 @@ import java.util.Locale; import java.util.Queue; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import com.projectswg.networking.encryption.Compression; @@ -61,6 +62,8 @@ public class ServerConnection { } public void stop() { + if (!running) + return; running = false; disconnect(ConnectionStatus.DISCONNECTED); if (thread != null) @@ -70,6 +73,12 @@ public class ServerConnection { processor.shutdownNow(); if (callbackExecutor != null) callbackExecutor.shutdownNow(); + try { + processor.awaitTermination(1, TimeUnit.MINUTES); + callbackExecutor.awaitTermination(1, TimeUnit.MINUTES); + } catch (InterruptedException e) { + + } processor = null; callbackExecutor = null; } @@ -182,10 +191,12 @@ public class ServerConnection { } } catch (IOException e) { if (connected) { - if (e.getMessage().equals("Connection reset")) - System.err.println("Connection reset"); - else - e.printStackTrace(); + if (e != null) { + if (e.getMessage().equals("Connection reset")) + System.err.println("Connection reset"); + else + e.printStackTrace(); + } disconnect(getReason(e.getMessage())); } } catch (Exception e) { @@ -196,6 +207,8 @@ public class ServerConnection { } private void addToBuffer(ByteBuffer data) { + if (!running) + return; synchronized (bufferMutex) { if (data.remaining() > buffer.remaining()) { // Increase size int nCapacity = buffer.capacity() * 2; @@ -213,7 +226,8 @@ public class ServerConnection { shrinkBuffer(); } } - processor.execute(() -> process()); + if (running) + processor.execute(() -> process()); } private void shrinkBuffer() { @@ -258,7 +272,10 @@ public class ServerConnection { reset(); return true; } catch (IOException e) { - disconnect(getReason(e.getMessage())); + if (e.getMessage() == null) + disconnect(ConnectionStatus.DISCONNECTED); + else + disconnect(getReason(e.getMessage())); return false; } } diff --git a/src/com/projectswg/networking/NetInterceptor.java b/src/com/projectswg/networking/NetInterceptor.java index 6c613c6..a08e78d 100644 --- a/src/com/projectswg/networking/NetInterceptor.java +++ b/src/com/projectswg/networking/NetInterceptor.java @@ -10,15 +10,21 @@ import com.projectswg.networking.swg.LoginClusterStatus; public class NetInterceptor { private final InterceptorProperties properties; + private final InterceptorData data; public NetInterceptor() { properties = new InterceptorProperties(); + data = new InterceptorData(); } public InterceptorProperties getProperties() { return properties; } + public InterceptorData getData() { + return data; + } + public byte [] interceptClient(byte [] data) { if (data.length < 6) return data; @@ -26,6 +32,12 @@ public class NetInterceptor { switch (bb.getInt(2)) { case 0x41131F96: return setAutoLogin(bb); + case 0x3AE6DFAE: // CmdStartScene + this.data.setZoning(true); + return data; + case 0x43FD1C22: // CmdSceneReady + this.data.setZoning(false); + return data; default: return data; } @@ -62,6 +74,24 @@ public class NetInterceptor { return cluster.encode().array(); } + public static class InterceptorData { + + private boolean zoning; + + public InterceptorData() { + zoning = false; + } + + public boolean isZoning() { + return zoning; + } + + public void setZoning(boolean zoning) { + this.zoning = zoning; + } + + } + public static class InterceptorProperties { private int port;