diff --git a/pom.xml b/pom.xml
index 90693f9..d8ff5ef 100644
--- a/pom.xml
+++ b/pom.xml
@@ -40,5 +40,13 @@
jakarta.persistence-api
3.1.0
+
+
+
+ org.yaml
+ snakeyaml
+ 2.5
+
+
\ No newline at end of file
diff --git a/server.yml b/server.yml
new file mode 100644
index 0000000..a63fed8
--- /dev/null
+++ b/server.yml
@@ -0,0 +1,12 @@
+#Подключение к БД
+database:
+ host: db
+ user: your_user
+ password: your_password
+ db: your_database
+#CDN (транспортные) серверы
+transport_servers:
+ - https://cdn.rosetta-im.com
+#Серверы обновлений
+update_servers:
+ - https://update.rosetta-im.com
diff --git a/src/main/java/com/rosetta/im/Boot.java b/src/main/java/com/rosetta/im/Boot.java
index 79b03dc..0f1c21b 100644
--- a/src/main/java/com/rosetta/im/Boot.java
+++ b/src/main/java/com/rosetta/im/Boot.java
@@ -2,6 +2,7 @@ package com.rosetta.im;
import com.rosetta.im.client.ClientManager;
import com.rosetta.im.client.OnlineManager;
+import com.rosetta.im.config.Configuration;
import com.rosetta.im.event.EventManager;
import com.rosetta.im.executors.Executor0Handshake;
import com.rosetta.im.executors.Executor11Typeing;
@@ -53,6 +54,7 @@ public class Boot {
private ServerAdapter serverAdapter;
private ClientManager clientManager;
private OnlineManager onlineManager;
+ private Configuration configuration;
public Boot() {
this.packetManager = new PacketManager();
@@ -65,6 +67,7 @@ public class Boot {
30
), packetManager, this.serverAdapter);
this.clientManager = new ClientManager(server);
+ this.configuration = new Configuration("server.yml");
}
/**
@@ -104,12 +107,19 @@ public class Boot {
* @return Boot
*/
public Boot bootstrap() {
- this.server.start();
- this.registerAllPackets();
- this.registerAllExecutors();
- this.registerAllEvents();
- this.printBootMessage();
- return this;
+ try{
+ this.configuration.loadConfiguration();
+ this.server.start();
+ this.registerAllPackets();
+ this.registerAllExecutors();
+ this.registerAllEvents();
+ this.printBootMessage();
+ return this;
+ }catch(Exception e){
+ this.logger.error("Booting error, stack trace:");
+ e.printStackTrace();
+ return null;
+ }
}
private void registerAllEvents() {
diff --git a/src/main/java/com/rosetta/im/Configuration.java b/src/main/java/com/rosetta/im/Configuration.java
deleted file mode 100644
index be0b559..0000000
--- a/src/main/java/com/rosetta/im/Configuration.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.rosetta.im;
-
-public class Configuration {
-
- public static final int PROTOCOL_VERSION = 1;
-
-}
diff --git a/src/main/java/com/rosetta/im/config/Configuration.java b/src/main/java/com/rosetta/im/config/Configuration.java
new file mode 100644
index 0000000..2d5ae4b
--- /dev/null
+++ b/src/main/java/com/rosetta/im/config/Configuration.java
@@ -0,0 +1,41 @@
+package com.rosetta.im.config;
+
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import org.yaml.snakeyaml.LoaderOptions;
+import org.yaml.snakeyaml.Yaml;
+
+import com.rosetta.im.exception.ConfigurationException;
+
+public class Configuration {
+
+ private String serverConfigName;
+
+ public Configuration(String serverConfigName) {
+ this.serverConfigName = serverConfigName;
+ }
+
+ public ServerConfiguration loadConfiguration() throws ConfigurationException, Exception {
+ if(!Files.exists(Paths.get(this.serverConfigName))){
+ /**
+ * Файл конфигурации с переданным названием не найден
+ */
+ throw new ConfigurationException(this.serverConfigName + " is missing");
+ }
+
+ LoaderOptions options = new LoaderOptions();
+ Yaml yaml = new Yaml(options);
+
+ InputStream inputStream = Files.newInputStream(Paths.get(this.serverConfigName));
+ /**
+ * SnakeYAML автоматически загрузит обьект ServerConfiguration через рефлексию
+ * обратите внимание название полей в ServerConfiguration должны совпадать с названиями в
+ * server.yml
+ */
+ ServerConfiguration serverConfiguration = yaml.loadAs(inputStream, ServerConfiguration.class);
+ return serverConfiguration;
+ }
+
+}
diff --git a/src/main/java/com/rosetta/im/config/DatabaseConfiguration.java b/src/main/java/com/rosetta/im/config/DatabaseConfiguration.java
new file mode 100644
index 0000000..558d403
--- /dev/null
+++ b/src/main/java/com/rosetta/im/config/DatabaseConfiguration.java
@@ -0,0 +1,42 @@
+package com.rosetta.im.config;
+
+public class DatabaseConfiguration {
+
+ public String host;
+ public String user;
+ public String password;
+ public String db;
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getDb() {
+ return db;
+ }
+
+ public void setDb(String db) {
+ this.db = db;
+ }
+
+}
diff --git a/src/main/java/com/rosetta/im/config/ServerConfiguration.java b/src/main/java/com/rosetta/im/config/ServerConfiguration.java
new file mode 100644
index 0000000..de36447
--- /dev/null
+++ b/src/main/java/com/rosetta/im/config/ServerConfiguration.java
@@ -0,0 +1,31 @@
+package com.rosetta.im.config;
+
+import java.util.List;
+
+/**
+ * Этот файл отвечает за конфигурацию которая хранится в файле server.yml
+ */
+public class ServerConfiguration {
+
+ public DatabaseConfiguration database;
+
+ public List cdn_servers;
+
+ public DatabaseConfiguration getDatabase() {
+ return database;
+ }
+
+ public void setDatabase(DatabaseConfiguration database) {
+ this.database = database;
+ }
+
+ public List getCdnServers() {
+ return cdn_servers;
+ }
+
+ public void setCdnServers(List cdn_servers) {
+ this.cdn_servers = cdn_servers;
+ }
+
+
+}
diff --git a/src/main/java/com/rosetta/im/exception/ConfigurationException.java b/src/main/java/com/rosetta/im/exception/ConfigurationException.java
new file mode 100644
index 0000000..a5a42eb
--- /dev/null
+++ b/src/main/java/com/rosetta/im/exception/ConfigurationException.java
@@ -0,0 +1,12 @@
+package com.rosetta.im.exception;
+
+/**
+ * Выбрасывается когда файл конфигурации не найден
+ */
+public class ConfigurationException extends Exception {
+
+ public ConfigurationException(String message){
+ super(message);
+ }
+
+}
diff --git a/src/main/java/com/rosetta/im/executors/Executor0Handshake.java b/src/main/java/com/rosetta/im/executors/Executor0Handshake.java
index a87ebcb..75d6913 100644
--- a/src/main/java/com/rosetta/im/executors/Executor0Handshake.java
+++ b/src/main/java/com/rosetta/im/executors/Executor0Handshake.java
@@ -1,6 +1,5 @@
package com.rosetta.im.executors;
-import com.rosetta.im.Configuration;
import com.rosetta.im.Failures;
import com.rosetta.im.client.ClientManager;
import com.rosetta.im.client.tags.ECIAuthentificate;
@@ -65,7 +64,7 @@ public class Executor0Handshake extends PacketExecutor {
/**
* Проверяем корректность версии протокола
*/
- if(protocolVersion != Configuration.PROTOCOL_VERSION) {
+ if(protocolVersion != 1) {
client.disconnect(Failures.UNSUPPORTED_PROTOCOL);
return;
}