DispatchHttpJsonHandler.java 1.56 KB
Newer Older
Melledy's avatar
Melledy committed
1
2
3
package emu.grasscutter.server.dispatch;

import java.io.IOException;
4
import java.util.Arrays;
Melledy's avatar
Melledy committed
5

6
import emu.grasscutter.Grasscutter;
7
import emu.grasscutter.Grasscutter.ServerDebugMode;
8
9
10
import express.http.HttpContextHandler;
import express.http.Request;
import express.http.Response;
Melledy's avatar
Melledy committed
11

12
public final class DispatchHttpJsonHandler implements HttpContextHandler {
Melledy's avatar
Melledy committed
13
	private final String response;
14
15
16
17
18
19
20
21
22
23
24
25
	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"
	};
Melledy's avatar
Melledy committed
26
27
28
29
30
31
	
	public DispatchHttpJsonHandler(String response) {
		this.response = response;
	}

	@Override
32
33
	public void handle(Request req, Response res) throws IOException {
		// Checking for ALL here isn't required as when ALL is enabled enableDevLogging() gets enabled
34
		if(Grasscutter.getConfig().DebugMode == ServerDebugMode.MISSING && Arrays.stream(missingRoutes).anyMatch(x -> x == req.baseUrl())) {
4Benj_'s avatar
4Benj_ committed
35
			Grasscutter.getLogger().info(String.format("[Dispatch] Client %s %s request: %s", req.ip(), req.method(), req.baseUrl()) + (Grasscutter.getConfig().DebugMode == ServerDebugMode.MISSING ? "(MISSING)" : ""));
36
		}
37
		res.send(response);
Melledy's avatar
Melledy committed
38
39
	}
}