DispatchHttpJsonHandler.java 1.51 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
7
8
9
import emu.grasscutter.Grasscutter;
import express.http.HttpContextHandler;
import express.http.Request;
import express.http.Response;
Melledy's avatar
Melledy committed
10

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

	@Override
31
32
33
34
35
	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)" : ""));
		}
36
		res.send(response);
Melledy's avatar
Melledy committed
37
38
	}
}