2022-04-17 12:43:07 +00:00
package emu.grasscutter.server.dispatch ;
import java.io.IOException ;
import java.io.OutputStream ;
2022-04-30 16:30:56 +00:00
import java.util.Arrays ;
2022-04-17 12:43:07 +00:00
import java.util.Collections ;
import com.sun.net.httpserver.HttpExchange ;
import com.sun.net.httpserver.HttpHandler ;
2022-04-30 16:30:56 +00:00
import emu.grasscutter.Grasscutter ;
2022-05-01 05:52:09 +00:00
import emu.grasscutter.Grasscutter.ServerDebugMode ;
2022-04-30 16:30:56 +00:00
import express.http.HttpContextHandler ;
import express.http.Request ;
import express.http.Response ;
2022-04-17 12:43:07 +00:00
2022-04-30 16:30:56 +00:00
public final class DispatchHttpJsonHandler implements HttpContextHandler {
2022-04-17 12:43:07 +00:00
private final String response ;
2022-04-30 16:30:56 +00:00
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 "
} ;
2022-04-17 12:43:07 +00:00
public DispatchHttpJsonHandler ( String response ) {
this . response = response ;
}
@Override
2022-04-30 16:30:56 +00:00
public void handle ( Request req , Response res ) throws IOException {
// Checking for ALL here isn't required as when ALL is enabled enableDevLogging() gets enabled
2022-05-01 05:52:09 +00:00
if ( Grasscutter . getConfig ( ) . DebugMode = = ServerDebugMode . 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 = = ServerDebugMode . MISSING ? " (MISSING) " : " " ) ) ;
2022-04-30 16:30:56 +00:00
}
2022-04-30 22:43:50 +00:00
res . send ( response ) ;
2022-04-17 12:43:07 +00:00
}
}