diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/SocketHookManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/SocketHookManager.java index fb9b6c38..87699daf 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/SocketHookManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/SocketHookManager.java @@ -3,28 +3,35 @@ import ru.gravit.launcher.request.RequestException; import ru.gravit.launchserver.socket.SocketContext; +import java.net.Socket; import java.util.HashSet; import java.util.Set; public class SocketHookManager { @FunctionalInterface - interface SocketPreHook + public interface SocketPreHook { boolean preHook(SocketContext context); //Вернуть true если необходимо продолжть обработку, false если остановить обработку } @FunctionalInterface - interface SocketPostHook + public interface SocketPostHook { void postHook(SocketContext context); } @FunctionalInterface - interface SocketErrorHook + public interface SocketErrorHook { boolean errorHook(SocketContext context, RequestException e); //Вернуть true если необходимо продолжть обработку, false если остановить обработку } + @FunctionalInterface + public interface SocketFatalErrorHook + { + boolean fatalErrorHook(Socket socket, Exception e); //Вернуть true если необходимо продолжть обработку, false если остановить обработку + } private Set POST_HOOKS; private Set PRE_HOOKS; private Set ERROR_HOOKS; + private Set FATALERROR_HOOKS; public void registerPostHook(SocketPostHook hook) { if(POST_HOOKS == null) POST_HOOKS = new HashSet<>(); @@ -40,6 +47,11 @@ public void registerErrorHook(SocketErrorHook hook) if(ERROR_HOOKS == null) ERROR_HOOKS = new HashSet<>(); ERROR_HOOKS.add(hook); } + public void registerFatalErrorHook(SocketFatalErrorHook hook) + { + if(FATALERROR_HOOKS == null) FATALERROR_HOOKS = new HashSet<>(); + FATALERROR_HOOKS.add(hook); + } public boolean preHook(SocketContext context) { if(PRE_HOOKS == null) return true; @@ -66,4 +78,13 @@ public boolean errorHook(SocketContext context, RequestException e) } return true; } + public boolean fatalErrorHook(Socket socket, Exception e) + { + if(FATALERROR_HOOKS == null) return true; + for(SocketFatalErrorHook errorHook : FATALERROR_HOOKS) + { + if(!errorHook.fatalErrorHook(socket,e)) return false; + } + return true; + } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ResponseThread.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ResponseThread.java index 027b5ab1..b1f4d20d 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ResponseThread.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ResponseThread.java @@ -133,7 +133,8 @@ public void run() { } } catch (Exception e) { savedError = e; - LogHelper.error(e); + if(server.socketHookManager.fatalErrorHook(socket,e)) + LogHelper.error(e); } finally { IOHelper.close(socket); if (!cancelled) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ServerSocketHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ServerSocketHandler.java index 5509390f..f80075e6 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ServerSocketHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ServerSocketHandler.java @@ -101,7 +101,11 @@ public void run() { // Invoke pre-connect listener long id = idCounter.incrementAndGet(); if (listener != null && !listener.onConnect(socket.getInetAddress())) + { + socket.close(); continue; // Listener didn't accepted this connection + } + // Reply in separate thread threadPool.execute(new ResponseThread(server, id, socket, sessionManager, server.socketHookManager)); diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 75b8c7c8..488effa9 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Wed Jan 02 17:51:09 GMT+07:00 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip