Commit 934c415d authored by Magix's avatar Magix Committed by GitHub
Browse files

Merge pull request #383 from 4Benj/api

Complete rework of Dispatch, Added DebugModes
parents a62520f9 be507310
......@@ -54,12 +54,14 @@ tmp/
# Grasscutter
resources/*
logs/*
plugins/*
data/AbilityEmbryos.json
data/OpenConfig.json
GM Handbook.txt
config.json
mitmdump.exe
*.jar
!lib/*.jar
mongod.exe
/src/generated/
/*.sh
......@@ -16,18 +16,22 @@ buildscript {
}
plugins {
// Apply the application plugin to add support for building a CLI application
id 'application'
// Apply the java plugin to add support for Java
id 'java'
// Apply the protobuf auto generator
id 'com.google.protobuf' version "0.8.18"
id 'idea'
// Eclipse Support
id 'eclipse'
// Apply the application plugin to add support for building a CLI application
id 'application'
// Intelij Support
id 'idea'
// Maven
id 'maven-publish'
id 'signing'
}
......
......@@ -15,6 +15,7 @@ public final class Config {
public String SCRIPTS_FOLDER = "./resources/Scripts/";
public String PLUGINS_FOLDER = "./plugins/";
public String DebugMode = "NONE"; // ALL, MISSING, NONE
public String RunMode = "HYBRID"; // HYBRID, DISPATCH_ONLY, GAME_ONLY
public GameServerOptions GameServer = new GameServerOptions();
public DispatchServerOptions DispatchServer = new DispatchServerOptions();
......@@ -62,8 +63,6 @@ public final class Config {
public String DispatchServerDatabaseUrl = "mongodb://localhost:27017";
public String DispatchServerDatabaseCollection = "grasscutter";
public boolean LOG_PACKETS = false;
public int InventoryLimitWeapon = 2000;
public int InventoryLimitRelic = 2000;
public int InventoryLimitMaterial = 2000;
......
......@@ -2,26 +2,41 @@ package emu.grasscutter.server.dispatch;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collections;
import com.sun.net.httpserver.HttpExchange;
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[] 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) {
this.response = response;
}
@Override
public void handle(HttpExchange t) throws IOException {
// Set the response header status and length
t.getResponseHeaders().put("Content-Type", Collections.singletonList("application/json"));
t.sendResponseHeaders(200, response.getBytes().length);
// Write the response string
OutputStream os = t.getResponseBody();
os.write(response.getBytes());
os.close();
public void handle(Request req, Response res) throws IOException {
// 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());
}
}
}
......@@ -88,7 +88,7 @@ public class GameServerPacketHandler {
}
// 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));
}
}
......
......@@ -163,7 +163,7 @@ public class GameSession extends KcpChannel {
}
// Log
if (Grasscutter.getConfig().getGameServerOptions().LOG_PACKETS) {
if (Grasscutter.getConfig().DebugMode.equalsIgnoreCase("ALL")) {
logPacket(packet);
}
......@@ -230,7 +230,7 @@ public class GameSession extends KcpChannel {
}
// Log packet
if (Grasscutter.getConfig().getGameServerOptions().LOG_PACKETS) {
if (Grasscutter.getConfig().DebugMode.equalsIgnoreCase("ALL")) {
if (!loopPacket.contains(opcode)) {
Grasscutter.getLogger().info("RECV: " + PacketOpcodesUtil.getOpcodeName(opcode) + " (" + opcode + ")");
System.out.println(Utils.bytesToHex(payload));
......
Markdown is supported
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