DispatchHttpJsonHandler.java 1.64 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;
5
import java.util.Objects;
Melledy's avatar
Melledy committed
6

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

13
14
import static emu.grasscutter.utils.Language.translate;

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

	@Override
35
36
	public void handle(Request req, Response res) throws IOException {
		// Checking for ALL here isn't required as when ALL is enabled enableDevLogging() gets enabled
37
38
		if(Grasscutter.getConfig().DebugMode == ServerDebugMode.MISSING && Arrays.stream(missingRoutes).anyMatch(x -> Objects.equals(x, req.baseUrl()))) {
			Grasscutter.getLogger().info(translate("messages.dispatch.request", req.ip(), req.method(), req.baseUrl()) + (Grasscutter.getConfig().DebugMode == ServerDebugMode.MISSING ? "(MISSING)" : ""));
39
		}
40
		res.send(response);
Melledy's avatar
Melledy committed
41
42
	}
}