DispatchHttpJsonHandler.java 1.66 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
import static emu.grasscutter.utils.Language.translate;
14
import static emu.grasscutter.Configuration.*;
15

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

	@Override
36
37
	public void handle(Request req, Response res) throws IOException {
		// Checking for ALL here isn't required as when ALL is enabled enableDevLogging() gets enabled
38
39
		if(SERVER.debugLevel == 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()) + (SERVER.debugLevel == ServerDebugMode.MISSING ? "(MISSING)" : ""));
40
		}
41
		res.send(response);
Melledy's avatar
Melledy committed
42
43
	}
}