Общая система сборки у репозиториев, определение порта
This commit is contained in:
@@ -62,14 +62,14 @@ public class Boot {
|
||||
private Configuration configuration;
|
||||
private ServerConfiguration serverConfiguration;
|
||||
|
||||
public Boot() {
|
||||
public Boot(int port) {
|
||||
this.packetManager = new PacketManager();
|
||||
this.eventManager = new EventManager();
|
||||
this.onlineManager = new OnlineManager();
|
||||
this.logger = new Logger(LogLevel.INFO);
|
||||
this.serverAdapter = new ServerAdapter(this.eventManager);
|
||||
this.server = new Server(new Settings(
|
||||
8881,
|
||||
port,
|
||||
30
|
||||
), packetManager, this.serverAdapter);
|
||||
this.clientManager = new ClientManager(server);
|
||||
|
||||
@@ -2,13 +2,37 @@ package com.rosetta.im;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
int port = resolvePort(args);
|
||||
/**
|
||||
* Регистрация всех пакетов и их обработчиков
|
||||
*/
|
||||
Boot boot = new Boot();
|
||||
Boot boot = new Boot(port);
|
||||
/**
|
||||
* Стартуем сервер
|
||||
*/
|
||||
boot.bootstrap();
|
||||
}
|
||||
|
||||
private static int resolvePort(String[] args) {
|
||||
// Если порт указан аргументом — используем его.
|
||||
if (args != null && args.length > 0) {
|
||||
try {
|
||||
return Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
// Если порт задан в окружении — используем его.
|
||||
String envPort = System.getenv("PORT");
|
||||
if (envPort != null && !envPort.isBlank()) {
|
||||
try {
|
||||
return Integer.parseInt(envPort);
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
// Значение по умолчанию.
|
||||
return 8080;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user