2025-12-12 21:16:13 +01:00
|
|
|
package org.openautonomousconnection.webserver;
|
|
|
|
|
|
|
|
|
|
import dev.unlegitdqrk.unlegitlibrary.command.CommandExecutor;
|
|
|
|
|
import dev.unlegitdqrk.unlegitlibrary.command.CommandManager;
|
|
|
|
|
import dev.unlegitdqrk.unlegitlibrary.command.CommandPermission;
|
|
|
|
|
import dev.unlegitdqrk.unlegitlibrary.event.EventManager;
|
2026-01-18 22:25:50 +01:00
|
|
|
import dev.unlegitdqrk.unlegitlibrary.file.ConfigurationManager;
|
2025-12-12 21:16:13 +01:00
|
|
|
import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
|
|
|
|
|
import lombok.Getter;
|
|
|
|
|
import org.openautonomousconnection.protocol.ProtocolBridge;
|
2026-01-18 22:25:50 +01:00
|
|
|
import org.openautonomousconnection.protocol.ProtocolValues;
|
2025-12-12 21:16:13 +01:00
|
|
|
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
2026-01-18 22:55:58 +01:00
|
|
|
import org.openautonomousconnection.webserver.commands.StopCommand;
|
2025-12-12 21:16:13 +01:00
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
|
|
|
|
|
public class Main {
|
2026-01-18 22:55:58 +01:00
|
|
|
public static final CommandPermission PERMISSION_ALL = new CommandPermission("all", 1);
|
|
|
|
|
private static final CommandExecutor commandExecutor = new CommandExecutor("WebServer", PERMISSION_ALL) {};
|
|
|
|
|
|
|
|
|
|
@Getter
|
2025-12-12 21:16:13 +01:00
|
|
|
private static CommandManager commandManager;
|
|
|
|
|
|
|
|
|
|
@Getter
|
|
|
|
|
private static ProtocolBridge protocolBridge;
|
|
|
|
|
|
2026-01-18 22:25:50 +01:00
|
|
|
@Getter
|
|
|
|
|
private static ProtocolValues values;
|
|
|
|
|
|
2025-12-12 21:16:13 +01:00
|
|
|
public static void main(String[] args) throws Exception {
|
2026-01-18 22:25:50 +01:00
|
|
|
values = new ProtocolValues();
|
|
|
|
|
values.packetHandler = new PacketHandler();
|
|
|
|
|
values.eventManager = new EventManager();
|
|
|
|
|
|
|
|
|
|
ConfigurationManager config = new ConfigurationManager(new File("config.properties"));
|
2026-01-18 23:15:54 +01:00
|
|
|
config.loadProperties();
|
2026-01-18 22:25:50 +01:00
|
|
|
|
|
|
|
|
if (!config.isSet("port.udp")) {
|
|
|
|
|
config.set("port.udp", 1027);
|
|
|
|
|
config.saveProperties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!config.isSet("port.tcp")) {
|
|
|
|
|
config.set("port.tcp", 1028);
|
|
|
|
|
config.saveProperties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!config.isSet("sessionexpiremin")) {
|
|
|
|
|
config.set("sessionexpiremin", 1000);
|
|
|
|
|
config.saveProperties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!config.isSet("maxuploadmb")) {
|
|
|
|
|
config.set("maxuploadmb", 1024);
|
|
|
|
|
config.saveProperties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int tcpPort = config.getInt("port.tcp");
|
|
|
|
|
int udpPort = config.getInt("port.udp");
|
|
|
|
|
|
|
|
|
|
int sessionExpire = config.getInt("sessionexpiremin");
|
|
|
|
|
int maxUpload = config.getInt("maxuploadmb");
|
|
|
|
|
|
|
|
|
|
protocolBridge = new ProtocolBridge(new WebServer(
|
|
|
|
|
new File("auth.ini"), new File("rules.ini"),
|
|
|
|
|
sessionExpire, maxUpload),
|
|
|
|
|
values, ProtocolVersion.PV_1_0_0_BETA, new File("logs"));
|
|
|
|
|
|
2026-02-01 19:28:45 +01:00
|
|
|
protocolBridge.getProtocolServer().getNetwork().start(tcpPort, udpPort);
|
2026-01-18 22:25:50 +01:00
|
|
|
|
|
|
|
|
commandManager = new CommandManager(values.eventManager);
|
2026-01-18 22:55:58 +01:00
|
|
|
commandManager.registerCommand(StopCommand.class);
|
|
|
|
|
|
2025-12-12 21:16:13 +01:00
|
|
|
Scanner scanner = new Scanner(System.in);
|
|
|
|
|
|
|
|
|
|
while (true) {
|
2026-01-18 22:55:58 +01:00
|
|
|
System.out.print(commandExecutor.getName() + "> ");
|
2025-12-12 21:16:13 +01:00
|
|
|
String line = scanner.nextLine();
|
|
|
|
|
commandManager.execute(commandExecutor, line);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|