From 14c4673d488665c989e368db12b827eb65535453 Mon Sep 17 00:00:00 2001 From: Muhammad Eko Prasetyo Date: Sun, 1 May 2022 05:43:50 +0700 Subject: [PATCH] Fix DispatchHttpJson handler and add setHttpServer because Express doesn't support removing defined route. (#388) --- .../server/dispatch/DispatchHttpJsonHandler.java | 2 +- .../emu/grasscutter/server/dispatch/DispatchServer.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/emu/grasscutter/server/dispatch/DispatchHttpJsonHandler.java b/src/main/java/emu/grasscutter/server/dispatch/DispatchHttpJsonHandler.java index 81908f9ef..80e582b5f 100644 --- a/src/main/java/emu/grasscutter/server/dispatch/DispatchHttpJsonHandler.java +++ b/src/main/java/emu/grasscutter/server/dispatch/DispatchHttpJsonHandler.java @@ -36,7 +36,7 @@ public final class DispatchHttpJsonHandler implements HttpContextHandler { // Checking for ALL here isn't required as when ALL is enabled enableDevLogging() gets enabled if(Grasscutter.getConfig().DebugMode.equalsIgnoreCase("MISSING") && Arrays.stream(missingRoutes).anyMatch(x -> x == req.baseUrl())) { Grasscutter.getLogger().info(String.format("[Dispatch] Client %s %s request: ", req.ip(), req.method(), req.baseUrl()) + (Grasscutter.getConfig().DebugMode.equalsIgnoreCase("MISSING") ? "(MISSING)" : "")); - res.send(response.getBytes()); } + res.send(response); } } diff --git a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java index 8b41d2a6f..27167931d 100644 --- a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java +++ b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java @@ -50,6 +50,12 @@ public final class DispatchServer { return httpServer; } + public void setHttpServer(Express httpServer) { + this.httpServer.stop(); + this.httpServer = httpServer; + this.httpServer.listen(Grasscutter.getConfig().getDispatchOptions().Port); + } + public Gson getGsonFactory() { return gson; } @@ -271,12 +277,12 @@ public final class DispatchServer { }); // Login + httpServer.post("/hk4e_global/mdk/shield/api/login", (req, res) -> { // Get post data LoginAccountRequestJson requestData = null; try { String body = req.ctx().body(); - Grasscutter.getLogger().info(body); requestData = getGsonFactory().fromJson(body, LoginAccountRequestJson.class); } catch (Exception ignored) { }