2025-12-13 15:53:57 +01:00
|
|
|
package org.openautonomousconnection.insserver;
|
2025-11-03 18:33:59 +01:00
|
|
|
|
|
|
|
|
import dev.unlegitdqrk.unlegitlibrary.command.CommandExecutor;
|
|
|
|
|
import dev.unlegitdqrk.unlegitlibrary.command.CommandManager;
|
|
|
|
|
import dev.unlegitdqrk.unlegitlibrary.command.CommandPermission;
|
2025-12-12 19:46:00 +01:00
|
|
|
import dev.unlegitdqrk.unlegitlibrary.event.EventManager;
|
2026-01-18 22:01:14 +01:00
|
|
|
import dev.unlegitdqrk.unlegitlibrary.file.ConfigurationManager;
|
2025-12-12 19:46:00 +01:00
|
|
|
import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
|
2025-12-11 12:01:09 +01:00
|
|
|
import lombok.Getter;
|
2026-01-18 22:56:12 +01:00
|
|
|
import org.openautonomousconnection.insserver.commands.StopCommand;
|
2025-11-03 18:33:59 +01:00
|
|
|
import org.openautonomousconnection.protocol.ProtocolBridge;
|
2026-01-18 22:01:14 +01:00
|
|
|
import org.openautonomousconnection.protocol.ProtocolValues;
|
2025-11-03 18:33:59 +01:00
|
|
|
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
|
|
|
|
|
public class Main {
|
2026-01-18 22:56:12 +01:00
|
|
|
public static final CommandPermission PERMISSION_ALL = new CommandPermission("all", 1);
|
2025-12-13 16:48:28 +01:00
|
|
|
private static final CommandExecutor commandExecutor = new CommandExecutor("INS", PERMISSION_ALL) {};
|
2026-01-18 22:56:12 +01:00
|
|
|
@Getter
|
2025-11-03 18:33:59 +01:00
|
|
|
private static CommandManager commandManager;
|
|
|
|
|
|
2025-12-11 12:01:09 +01:00
|
|
|
@Getter
|
|
|
|
|
private static ProtocolBridge protocolBridge;
|
|
|
|
|
|
2025-12-13 16:48:28 +01:00
|
|
|
@Getter
|
2026-01-18 22:01:14 +01:00
|
|
|
private static ProtocolValues values;
|
2025-12-13 16:48:28 +01:00
|
|
|
|
2025-11-03 18:33:59 +01:00
|
|
|
public static void main(String[] args) throws Exception {
|
2026-01-18 22:01:14 +01:00
|
|
|
values = new ProtocolValues();
|
|
|
|
|
values.packetHandler = new PacketHandler();
|
|
|
|
|
values.eventManager = new EventManager();
|
|
|
|
|
values.eventManager.registerListener(Listener.class);
|
|
|
|
|
|
|
|
|
|
ConfigurationManager config = new ConfigurationManager(new File("config.properties"));
|
2026-01-18 23:13:38 +01:00
|
|
|
config.loadProperties();
|
2026-01-18 22:01:14 +01:00
|
|
|
|
|
|
|
|
if (!config.isSet("db.url")) {
|
|
|
|
|
config.set(
|
|
|
|
|
"db.url",
|
|
|
|
|
"jdbc:mysql://localhost:3306/ins?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC"
|
|
|
|
|
);
|
|
|
|
|
config.saveProperties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!config.isSet("db.user")) {
|
|
|
|
|
config.set("db.user", "username");
|
|
|
|
|
config.saveProperties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!config.isSet("db.password")) {
|
|
|
|
|
config.set("db.password", "password");
|
|
|
|
|
config.saveProperties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!config.isSet("port.udp")) {
|
|
|
|
|
config.set("port.udp", 1025);
|
|
|
|
|
config.saveProperties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!config.isSet("port.tcp")) {
|
|
|
|
|
config.set("port.tcp", 1026);
|
|
|
|
|
config.saveProperties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!config.isSet("ins.info")) {
|
2026-01-18 22:48:36 +01:00
|
|
|
config.set("ins.info", "INS INFO SITE (HOST)");
|
2026-01-18 22:01:14 +01:00
|
|
|
config.saveProperties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!config.isSet("ins.frontend")) {
|
2026-01-18 22:48:36 +01:00
|
|
|
config.set("ins.frontend", "INS FRONTEND SITE (HOST)");
|
2026-01-18 22:01:14 +01:00
|
|
|
config.saveProperties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String url = config.getString("db.url");
|
|
|
|
|
String user = config.getString("db.user");
|
|
|
|
|
String password = config.getString("db.password");
|
|
|
|
|
|
|
|
|
|
int tcpPort = config.getInt("port.tcp");
|
|
|
|
|
int udpPort = config.getInt("port.udp");
|
|
|
|
|
|
|
|
|
|
String info = config.getString("ins.info");
|
|
|
|
|
String frontend = config.getString("ins.frontend");
|
|
|
|
|
|
|
|
|
|
DatabaseINSServer server = new DatabaseINSServer(info, frontend, tcpPort, udpPort, url, user, password);
|
|
|
|
|
protocolBridge = new ProtocolBridge(server, values, ProtocolVersion.PV_1_0_0_BETA, new File("logs"));
|
|
|
|
|
server.getNetwork().start();
|
|
|
|
|
|
|
|
|
|
commandManager = new CommandManager(values.eventManager);
|
2026-01-18 22:56:12 +01:00
|
|
|
commandManager.registerCommand(StopCommand.class);
|
|
|
|
|
|
2025-11-03 18:33:59 +01:00
|
|
|
Scanner scanner = new Scanner(System.in);
|
|
|
|
|
|
|
|
|
|
while (true) {
|
2026-01-18 22:48:36 +01:00
|
|
|
System.out.print(commandExecutor.getName() + "> ");
|
|
|
|
|
String line = scanner.nextLine();
|
2025-11-03 18:33:59 +01:00
|
|
|
commandManager.execute(commandExecutor, line);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|