Конфигурационный файл
This commit is contained in:
8
pom.xml
8
pom.xml
@@ -40,5 +40,13 @@
|
|||||||
<artifactId>jakarta.persistence-api</artifactId>
|
<artifactId>jakarta.persistence-api</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>3.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Source: https://mvnrepository.com/artifact/org.yaml/snakeyaml -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.yaml</groupId>
|
||||||
|
<artifactId>snakeyaml</artifactId>
|
||||||
|
<version>2.5</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
12
server.yml
Normal file
12
server.yml
Normal file
@@ -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
|
||||||
@@ -2,6 +2,7 @@ package com.rosetta.im;
|
|||||||
|
|
||||||
import com.rosetta.im.client.ClientManager;
|
import com.rosetta.im.client.ClientManager;
|
||||||
import com.rosetta.im.client.OnlineManager;
|
import com.rosetta.im.client.OnlineManager;
|
||||||
|
import com.rosetta.im.config.Configuration;
|
||||||
import com.rosetta.im.event.EventManager;
|
import com.rosetta.im.event.EventManager;
|
||||||
import com.rosetta.im.executors.Executor0Handshake;
|
import com.rosetta.im.executors.Executor0Handshake;
|
||||||
import com.rosetta.im.executors.Executor11Typeing;
|
import com.rosetta.im.executors.Executor11Typeing;
|
||||||
@@ -53,6 +54,7 @@ public class Boot {
|
|||||||
private ServerAdapter serverAdapter;
|
private ServerAdapter serverAdapter;
|
||||||
private ClientManager clientManager;
|
private ClientManager clientManager;
|
||||||
private OnlineManager onlineManager;
|
private OnlineManager onlineManager;
|
||||||
|
private Configuration configuration;
|
||||||
|
|
||||||
public Boot() {
|
public Boot() {
|
||||||
this.packetManager = new PacketManager();
|
this.packetManager = new PacketManager();
|
||||||
@@ -65,6 +67,7 @@ public class Boot {
|
|||||||
30
|
30
|
||||||
), packetManager, this.serverAdapter);
|
), packetManager, this.serverAdapter);
|
||||||
this.clientManager = new ClientManager(server);
|
this.clientManager = new ClientManager(server);
|
||||||
|
this.configuration = new Configuration("server.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,12 +107,19 @@ public class Boot {
|
|||||||
* @return Boot
|
* @return Boot
|
||||||
*/
|
*/
|
||||||
public Boot bootstrap() {
|
public Boot bootstrap() {
|
||||||
this.server.start();
|
try{
|
||||||
this.registerAllPackets();
|
this.configuration.loadConfiguration();
|
||||||
this.registerAllExecutors();
|
this.server.start();
|
||||||
this.registerAllEvents();
|
this.registerAllPackets();
|
||||||
this.printBootMessage();
|
this.registerAllExecutors();
|
||||||
return this;
|
this.registerAllEvents();
|
||||||
|
this.printBootMessage();
|
||||||
|
return this;
|
||||||
|
}catch(Exception e){
|
||||||
|
this.logger.error("Booting error, stack trace:");
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerAllEvents() {
|
private void registerAllEvents() {
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
package com.rosetta.im;
|
|
||||||
|
|
||||||
public class Configuration {
|
|
||||||
|
|
||||||
public static final int PROTOCOL_VERSION = 1;
|
|
||||||
|
|
||||||
}
|
|
||||||
41
src/main/java/com/rosetta/im/config/Configuration.java
Normal file
41
src/main/java/com/rosetta/im/config/Configuration.java
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
31
src/main/java/com/rosetta/im/config/ServerConfiguration.java
Normal file
31
src/main/java/com/rosetta/im/config/ServerConfiguration.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package com.rosetta.im.config;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Этот файл отвечает за конфигурацию которая хранится в файле server.yml
|
||||||
|
*/
|
||||||
|
public class ServerConfiguration {
|
||||||
|
|
||||||
|
public DatabaseConfiguration database;
|
||||||
|
|
||||||
|
public List<String> cdn_servers;
|
||||||
|
|
||||||
|
public DatabaseConfiguration getDatabase() {
|
||||||
|
return database;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDatabase(DatabaseConfiguration database) {
|
||||||
|
this.database = database;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getCdnServers() {
|
||||||
|
return cdn_servers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCdnServers(List<String> cdn_servers) {
|
||||||
|
this.cdn_servers = cdn_servers;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.rosetta.im.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Выбрасывается когда файл конфигурации не найден
|
||||||
|
*/
|
||||||
|
public class ConfigurationException extends Exception {
|
||||||
|
|
||||||
|
public ConfigurationException(String message){
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.rosetta.im.executors;
|
package com.rosetta.im.executors;
|
||||||
|
|
||||||
import com.rosetta.im.Configuration;
|
|
||||||
import com.rosetta.im.Failures;
|
import com.rosetta.im.Failures;
|
||||||
import com.rosetta.im.client.ClientManager;
|
import com.rosetta.im.client.ClientManager;
|
||||||
import com.rosetta.im.client.tags.ECIAuthentificate;
|
import com.rosetta.im.client.tags.ECIAuthentificate;
|
||||||
@@ -65,7 +64,7 @@ public class Executor0Handshake extends PacketExecutor<Packet0Handshake> {
|
|||||||
/**
|
/**
|
||||||
* Проверяем корректность версии протокола
|
* Проверяем корректность версии протокола
|
||||||
*/
|
*/
|
||||||
if(protocolVersion != Configuration.PROTOCOL_VERSION) {
|
if(protocolVersion != 1) {
|
||||||
client.disconnect(Failures.UNSUPPORTED_PROTOCOL);
|
client.disconnect(Failures.UNSUPPORTED_PROTOCOL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user