mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-14 16:04:40 +01:00
Refactor existing code
This commit is contained in:
@@ -6,8 +6,8 @@ import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Arrays;
|
||||
|
||||
import emu.grasscutter.utils.Utils;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
@@ -22,19 +22,25 @@ import emu.grasscutter.server.game.GameServer;
|
||||
import emu.grasscutter.tools.Tools;
|
||||
import emu.grasscutter.utils.Crypto;
|
||||
|
||||
public class Grasscutter {
|
||||
private static Logger log = (Logger) LoggerFactory.getLogger(Grasscutter.class);
|
||||
public final class Grasscutter {
|
||||
private static final Logger log = (Logger) LoggerFactory.getLogger(Grasscutter.class);
|
||||
private static Config config;
|
||||
|
||||
private static Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
private static File configFile = new File("./config.json");
|
||||
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
private static final File configFile = new File("./config.json");
|
||||
|
||||
public static RunMode MODE = RunMode.BOTH;
|
||||
private static DispatchServer dispatchServer;
|
||||
private static GameServer gameServer;
|
||||
|
||||
static {
|
||||
// Load configuration.
|
||||
Grasscutter.loadConfig();
|
||||
// Check server structure.
|
||||
Utils.startupCheck();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Grasscutter.loadConfig();
|
||||
Crypto.loadKeys();
|
||||
|
||||
for (String arg : args) {
|
||||
@@ -48,56 +54,34 @@ public class Grasscutter {
|
||||
case "-handbook":
|
||||
Tools.createGmHandbook();
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Startup
|
||||
Grasscutter.getLogger().info("Grasscutter Emu");
|
||||
// Initialize server.
|
||||
Grasscutter.getLogger().info("Starting Grasscutter...");
|
||||
|
||||
// Load resource files
|
||||
// Load all resources.
|
||||
ResourceLoader.loadAll();
|
||||
|
||||
// Database
|
||||
DatabaseManager.initialize();
|
||||
|
||||
// Run servers
|
||||
// Start servers.
|
||||
dispatchServer = new DispatchServer();
|
||||
dispatchServer.start();
|
||||
|
||||
gameServer = new GameServer(new InetSocketAddress(getConfig().GameServerIp, getConfig().GameServerPort));
|
||||
gameServer.start();
|
||||
|
||||
// Open console.
|
||||
startConsole();
|
||||
}
|
||||
|
||||
public static Config getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public static Logger getLogger() {
|
||||
return log;
|
||||
}
|
||||
|
||||
public static Gson getGsonFactory() {
|
||||
return gson;
|
||||
}
|
||||
|
||||
public static DispatchServer getDispatchServer() {
|
||||
return dispatchServer;
|
||||
}
|
||||
|
||||
public static GameServer getGameServer() {
|
||||
return gameServer;
|
||||
}
|
||||
|
||||
public static void loadConfig() {
|
||||
try (FileReader file = new FileReader(configFile)) {
|
||||
config = gson.fromJson(file, Config.class);
|
||||
} catch (Exception e) {
|
||||
Grasscutter.config = new Config();
|
||||
Grasscutter.config = new Config(); saveConfig();
|
||||
}
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
public static void saveConfig() {
|
||||
@@ -115,7 +99,7 @@ public class Grasscutter {
|
||||
ServerCommands.handle(input);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Grasscutter.getLogger().error("Console error:", e);
|
||||
Grasscutter.getLogger().error("An error occurred.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,4 +108,24 @@ public class Grasscutter {
|
||||
AUTH,
|
||||
GAME
|
||||
}
|
||||
|
||||
public static Config getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public static Logger getLogger() {
|
||||
return log;
|
||||
}
|
||||
|
||||
public static Gson getGsonFactory() {
|
||||
return gson;
|
||||
}
|
||||
|
||||
public static DispatchServer getDispatchServer() {
|
||||
return dispatchServer;
|
||||
}
|
||||
|
||||
public static GameServer getGameServer() {
|
||||
return gameServer;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user