
Test Post - 测试文章
by MLChinoo
要和死神一起喝杯茶吗?
代码渲染测试:
public static void main(String[] args) throws Exception {
Crypto.loadKeys(); // Load keys from buffers.
// Parse start-up arguments.
if (StartupArguments.parse(args)) {
System.exit(0); // Exit early.
}
// Get the server run mode.
var runMode = Grasscutter.getRunMode();
// Create command map.
commandMap = new CommandMap(true);
// Initialize server.
logger.info(translate("messages.status.starting"));
logger.info(translate("messages.status.game_version", GameConstants.VERSION));
logger.info(translate("messages.status.version", BuildConfig.VERSION, BuildConfig.GIT_HASH));
// Initialize database.
DatabaseManager.initialize();
// Initialize the default systems.
authenticationSystem = new DefaultAuthentication();
permissionHandler = new DefaultPermissionHandler();
// Create server instances.
if (runMode == ServerRunMode.HYBRID || runMode == ServerRunMode.GAME_ONLY)
Grasscutter.gameServer = new GameServer();
if (runMode == ServerRunMode.HYBRID || runMode == ServerRunMode.DISPATCH_ONLY)
Grasscutter.httpServer = new HttpServer();
// Create a server hook instance with both servers.
new ServerHelper(gameServer, httpServer);
// Create plugin manager instance.
pluginManager = new PluginManager();
if (runMode != ServerRunMode.GAME_ONLY) {
// Add HTTP routes after loading plugins.
httpServer.addRouter(HttpServer.UnhandledRequestRouter.class);
httpServer.addRouter(HttpServer.DefaultRequestRouter.class);
httpServer.addRouter(RegionHandler.class);
httpServer.addRouter(LogHandler.class);
httpServer.addRouter(GenericHandler.class);
httpServer.addRouter(AnnouncementsHandler.class);
httpServer.addRouter(AuthenticationHandler.class);
httpServer.addRouter(GachaHandler.class);
httpServer.addRouter(DocumentationServerHandler.class);
httpServer.addRouter(HandbookHandler.class);
}
// Check if the HTTP server should start.
var started = config.server.http.startImmediately;
if (started) {
Grasscutter.getLogger().info("HTTP server is starting...");
Grasscutter.startDispatch();
Grasscutter.getLogger().info("Game server is starting...");
}
// Load resources.
if (runMode != ServerRunMode.DISPATCH_ONLY) {
// Load all resources.
Grasscutter.updateDayOfWeek();
ResourceLoader.loadAll();
// Generate handbooks.
Tools.createGmHandbooks(false);
// Generate gacha mappings.
Tools.generateGachaMappings();
}
// Start servers.
if (runMode == ServerRunMode.HYBRID) {
if (!started) Grasscutter.startDispatch();
gameServer.start();
} else if (runMode == ServerRunMode.DISPATCH_ONLY) {
if (!started) Grasscutter.startDispatch();
} else if (runMode == ServerRunMode.GAME_ONLY) {
gameServer.start();
} else {
logger.error(translate("messages.status.run_mode_error", runMode));
logger.error(translate("messages.status.run_mode_help"));
logger.error(translate("messages.status.shutdown"));
System.exit(1);
}
// Enable all plugins.
pluginManager.enablePlugins();
// Hook into shutdown event.
Runtime.getRuntime().addShutdownHook(new Thread(Grasscutter::onShutdown));
// Open console.
Grasscutter.startConsole();
}