Refactor dispatch (now called HTTP) server (pt. 2)

This commit is contained in:
KingRainbow44
2022-05-13 23:22:30 -04:00
parent 840f4706b5
commit 3adf0d448c
25 changed files with 195 additions and 882 deletions

View File

@@ -1,10 +1,13 @@
package emu.grasscutter.plugin.api;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.auth.AuthenticationSystem;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.dispatch.DispatchServer;
import emu.grasscutter.server.game.GameServer;
import emu.grasscutter.server.http.HttpServer;
import emu.grasscutter.server.http.Router;
import java.util.LinkedList;
import java.util.List;
@@ -15,7 +18,7 @@ import java.util.List;
public final class ServerHook {
private static ServerHook instance;
private final GameServer gameServer;
private final DispatchServer dispatchServer;
private final HttpServer httpServer;
/**
* Gets the server hook instance.
@@ -28,11 +31,11 @@ public final class ServerHook {
/**
* Hooks into a server.
* @param gameServer The game server to hook into.
* @param dispatchServer The dispatch server to hook into.
* @param httpServer The HTTP server to hook into.
*/
public ServerHook(GameServer gameServer, DispatchServer dispatchServer) {
public ServerHook(GameServer gameServer, HttpServer httpServer) {
this.gameServer = gameServer;
this.dispatchServer = dispatchServer;
this.httpServer = httpServer;
instance = this;
}
@@ -45,10 +48,10 @@ public final class ServerHook {
}
/**
* @return The dispatch server.
* @return The HTTP server.
*/
public DispatchServer getDispatchServer() {
return this.dispatchServer;
public HttpServer getHttpServer() {
return this.httpServer;
}
/**
@@ -70,4 +73,28 @@ public final class ServerHook {
Command commandData = clazz.getAnnotation(Command.class);
this.gameServer.getCommandMap().registerCommand(commandData.label(), handler);
}
/**
* Adds a router using an instance of a class.
* @param router A router instance.
*/
public void addRouter(Router router) {
this.addRouter(router.getClass());
}
/**
* Adds a router using a class.
* @param router The class of the router.
*/
public void addRouter(Class<? extends Router> router) {
this.httpServer.addRouter(router);
}
/**
* Sets the server's authentication system.
* @param authSystem An instance of the authentication system.
*/
public void setAuthSystem(AuthenticationSystem authSystem) {
Grasscutter.setAuthenticationSystem(authSystem);
}
}