Skip to content
Snippets Groups Projects
Commit 947d3e57 authored by Benjamin Elsdon's avatar Benjamin Elsdon
Browse files

Complete rework of Dispatch, Added DebugMode

parent 4db1724d
No related merge requests found
...@@ -54,12 +54,14 @@ tmp/ ...@@ -54,12 +54,14 @@ tmp/
# Grasscutter # Grasscutter
resources/* resources/*
logs/* logs/*
plugins/*
data/AbilityEmbryos.json data/AbilityEmbryos.json
data/OpenConfig.json data/OpenConfig.json
GM Handbook.txt GM Handbook.txt
config.json config.json
mitmdump.exe mitmdump.exe
*.jar *.jar
!lib/*.jar
mongod.exe mongod.exe
/src/generated/ /src/generated/
/*.sh /*.sh
\ No newline at end of file
...@@ -16,18 +16,22 @@ buildscript { ...@@ -16,18 +16,22 @@ buildscript {
} }
plugins { plugins {
// Apply the application plugin to add support for building a CLI application
id 'application'
// Apply the java plugin to add support for Java // Apply the java plugin to add support for Java
id 'java' id 'java'
// Apply the protobuf auto generator // Apply the protobuf auto generator
id 'com.google.protobuf' version "0.8.18" id 'com.google.protobuf' version "0.8.18"
id 'idea'
// Eclipse Support
id 'eclipse' id 'eclipse'
// Apply the application plugin to add support for building a CLI application // Intelij Support
id 'application' id 'idea'
// Maven
id 'maven-publish' id 'maven-publish'
id 'signing' id 'signing'
} }
......
File added
...@@ -13,6 +13,7 @@ public final class Config { ...@@ -13,6 +13,7 @@ public final class Config {
public String SCRIPTS_FOLDER = "./resources/Scripts/"; public String SCRIPTS_FOLDER = "./resources/Scripts/";
public String PLUGINS_FOLDER = "./plugins/"; public String PLUGINS_FOLDER = "./plugins/";
public String DebugMode = "NONE"; // ALL, MISSING, NONE
public String RunMode = "HYBRID"; // HYBRID, DISPATCH_ONLY, GAME_ONLY public String RunMode = "HYBRID"; // HYBRID, DISPATCH_ONLY, GAME_ONLY
public GameServerOptions GameServer = new GameServerOptions(); public GameServerOptions GameServer = new GameServerOptions();
public DispatchServerOptions DispatchServer = new DispatchServerOptions(); public DispatchServerOptions DispatchServer = new DispatchServerOptions();
...@@ -60,8 +61,6 @@ public final class Config { ...@@ -60,8 +61,6 @@ public final class Config {
public String DispatchServerDatabaseUrl = "mongodb://localhost:27017"; public String DispatchServerDatabaseUrl = "mongodb://localhost:27017";
public String DispatchServerDatabaseCollection = "grasscutter"; public String DispatchServerDatabaseCollection = "grasscutter";
public boolean LOG_PACKETS = false;
public int InventoryLimitWeapon = 2000; public int InventoryLimitWeapon = 2000;
public int InventoryLimitRelic = 2000; public int InventoryLimitRelic = 2000;
public int InventoryLimitMaterial = 2000; public int InventoryLimitMaterial = 2000;
......
...@@ -2,26 +2,41 @@ package emu.grasscutter.server.dispatch; ...@@ -2,26 +2,41 @@ package emu.grasscutter.server.dispatch;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpHandler;
import emu.grasscutter.Grasscutter;
import express.http.HttpContextHandler;
import express.http.Request;
import express.http.Response;
public final class DispatchHttpJsonHandler implements HttpHandler { public final class DispatchHttpJsonHandler implements HttpContextHandler {
private final String response; private final String response;
private final String[] missingRoutes = { // TODO: When http requests for theses routes are found please remove it from this list and update the route request type in the DispatchServer
"/common/hk4e_global/announcement/api/getAlertPic",
"/common/hk4e_global/announcement/api/getAlertAnn",
"/common/hk4e_global/announcement/api/getAnnList",
"/common/hk4e_global/announcement/api/getAnnContent",
"/hk4e_global/mdk/shopwindow/shopwindow/listPriceTier",
"/log/sdk/upload",
"/sdk/upload",
"/perf/config/verify",
"/log",
"/crash/dataUpload"
};
public DispatchHttpJsonHandler(String response) { public DispatchHttpJsonHandler(String response) {
this.response = response; this.response = response;
} }
@Override @Override
public void handle(HttpExchange t) throws IOException { public void handle(Request req, Response res) throws IOException {
// Set the response header status and length // Checking for ALL here isn't required as when ALL is enabled enableDevLogging() gets enabled
t.getResponseHeaders().put("Content-Type", Collections.singletonList("application/json")); if(Grasscutter.getConfig().DebugMode.equalsIgnoreCase("MISSING") && Arrays.stream(missingRoutes).anyMatch(x -> x == req.baseUrl())) {
t.sendResponseHeaders(200, response.getBytes().length); Grasscutter.getLogger().info(String.format("[Dispatch] Client %s %s request: ", req.ip(), req.method(), req.baseUrl()) + (Grasscutter.getConfig().DebugMode.equalsIgnoreCase("MISSING") ? "(MISSING)" : ""));
// Write the response string res.send(response.getBytes());
OutputStream os = t.getResponseBody(); }
os.write(response.getBytes());
os.close();
} }
} }
...@@ -88,7 +88,7 @@ public class GameServerPacketHandler { ...@@ -88,7 +88,7 @@ public class GameServerPacketHandler {
} }
// Log unhandled packets // Log unhandled packets
if (Grasscutter.getConfig().getGameServerOptions().LOG_PACKETS) { if (Grasscutter.getConfig().DebugMode.equalsIgnoreCase("MISSING")) {
Grasscutter.getLogger().info("Unhandled packet (" + opcode + "): " + emu.grasscutter.net.packet.PacketOpcodesUtil.getOpcodeName(opcode)); Grasscutter.getLogger().info("Unhandled packet (" + opcode + "): " + emu.grasscutter.net.packet.PacketOpcodesUtil.getOpcodeName(opcode));
} }
} }
......
...@@ -163,7 +163,7 @@ public class GameSession extends KcpChannel { ...@@ -163,7 +163,7 @@ public class GameSession extends KcpChannel {
} }
// Log // Log
if (Grasscutter.getConfig().getGameServerOptions().LOG_PACKETS) { if (Grasscutter.getConfig().DebugMode.equalsIgnoreCase("ALL")) {
logPacket(packet); logPacket(packet);
} }
...@@ -230,7 +230,7 @@ public class GameSession extends KcpChannel { ...@@ -230,7 +230,7 @@ public class GameSession extends KcpChannel {
} }
// Log packet // Log packet
if (Grasscutter.getConfig().getGameServerOptions().LOG_PACKETS) { if (Grasscutter.getConfig().DebugMode.equalsIgnoreCase("ALL")) {
if (!loopPacket.contains(opcode)) { if (!loopPacket.contains(opcode)) {
Grasscutter.getLogger().info("RECV: " + PacketOpcodesUtil.getOpcodeName(opcode) + " (" + opcode + ")"); Grasscutter.getLogger().info("RECV: " + PacketOpcodesUtil.getOpcodeName(opcode) + " (" + opcode + ")");
System.out.println(Utils.bytesToHex(payload)); System.out.println(Utils.bytesToHex(payload));
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment