Added SettingsLoader and improved default settings.
This commit is contained in:
parent
12daa6ab1b
commit
cbcc8b3db1
|
@ -3,4 +3,6 @@ client/target/
|
||||||
core/target/
|
core/target/
|
||||||
server/target/
|
server/target/
|
||||||
server-registry/target/
|
server-registry/target/
|
||||||
*.iml
|
*.iml
|
||||||
|
/settings.yaml
|
||||||
|
/*.log
|
|
@ -17,6 +17,7 @@ import nl.andrewlalis.aos_core.net.data.PlayerDetailUpdate;
|
||||||
import nl.andrewlalis.aos_core.net.data.WorldUpdate;
|
import nl.andrewlalis.aos_core.net.data.WorldUpdate;
|
||||||
import nl.andrewlalis.aos_core.util.ByteUtils;
|
import nl.andrewlalis.aos_core.util.ByteUtils;
|
||||||
import nl.andrewlalis.aos_server.settings.ServerSettings;
|
import nl.andrewlalis.aos_server.settings.ServerSettings;
|
||||||
|
import nl.andrewlalis.aos_server.settings.SettingsLoader;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -54,6 +55,7 @@ public class Server {
|
||||||
this.worldUpdater = new WorldUpdater(this, this.world);
|
this.worldUpdater = new WorldUpdater(this, this.world);
|
||||||
this.chatManager = new ChatManager(this);
|
this.chatManager = new ChatManager(this);
|
||||||
if (settings.getRegistrySettings().isDiscoverable()) {
|
if (settings.getRegistrySettings().isDiscoverable()) {
|
||||||
|
System.out.println("Starting registry communications.");
|
||||||
this.registryManager = new RegistryManager(this);
|
this.registryManager = new RegistryManager(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,11 +269,7 @@ public class Server {
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
|
Server server = new Server(SettingsLoader.load());
|
||||||
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.KEBAB_CASE);
|
|
||||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
||||||
var settings = mapper.readValue(Server.class.getClassLoader().getResourceAsStream("default_settings.yaml"), ServerSettings.class);
|
|
||||||
Server server = new Server(settings);
|
|
||||||
server.run();
|
server.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package nl.andrewlalis.aos_server.settings;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
||||||
|
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public class SettingsLoader {
|
||||||
|
public static ServerSettings load() throws IOException {
|
||||||
|
Path settingsFile = Path.of("settings.yaml");
|
||||||
|
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
|
||||||
|
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.KEBAB_CASE);
|
||||||
|
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
if (Files.notExists(settingsFile)) {
|
||||||
|
System.out.println(settingsFile.getFileName() + " does not exist yet. Initializing with default settings.");
|
||||||
|
try (
|
||||||
|
InputStream in = SettingsLoader.class.getClassLoader().getResourceAsStream("default_settings.yaml");
|
||||||
|
OutputStream out = Files.newOutputStream(settingsFile)
|
||||||
|
) {
|
||||||
|
if (in == null) throw new IOException("Could not read default settings.");
|
||||||
|
in.transferTo(out);
|
||||||
|
System.out.println("Initialized server with default settings. Please review these and restart to apply changes.");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
InputStream in = Files.newInputStream(settingsFile);
|
||||||
|
var settings = mapper.readValue(in, ServerSettings.class);
|
||||||
|
in.close();
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,8 @@
|
||||||
|
# Ace of Shades Server Settings
|
||||||
|
|
||||||
|
# Changes to these settings take effect only after restarting the server.
|
||||||
|
|
||||||
|
|
||||||
# The port that this server uses for TCP and UDP communication.
|
# The port that this server uses for TCP and UDP communication.
|
||||||
port: 8035
|
port: 8035
|
||||||
# The maximum number of players that can be connected at once.
|
# The maximum number of players that can be connected at once.
|
||||||
|
@ -6,10 +11,11 @@ max-players: 32
|
||||||
# WARNING: Changing this has a major impact on server performance.
|
# WARNING: Changing this has a major impact on server performance.
|
||||||
ticks-per-second: 120
|
ticks-per-second: 120
|
||||||
|
|
||||||
# Information for the public server registry.
|
|
||||||
|
# Information for the public server registry. Ignore this unless you want your server to be displayed publicly.
|
||||||
registry-settings:
|
registry-settings:
|
||||||
# Set this to true to allow other players to see this server and join it.
|
# Set this to true to allow other players to see this server and join it.
|
||||||
discoverable: true
|
discoverable: false
|
||||||
# The URI which points to the registry server. This is only used if discoverable is true.
|
# The URI which points to the registry server. This is only used if discoverable is true.
|
||||||
registry-uri: "http://localhost:8567"
|
registry-uri: "http://localhost:8567"
|
||||||
# How often to send status updates to the registry server, in seconds.
|
# How often to send status updates to the registry server, in seconds.
|
||||||
|
@ -26,26 +32,42 @@ registry-settings:
|
||||||
|
|
||||||
# Settings that control player behavior.
|
# Settings that control player behavior.
|
||||||
player-settings:
|
player-settings:
|
||||||
|
# Walking speed, in meters per second.
|
||||||
speed: 10
|
speed: 10
|
||||||
|
# Sprinting speed, in meters per second.
|
||||||
sprint-speed: 18
|
sprint-speed: 18
|
||||||
|
# Sneaking speed, in meters per second.
|
||||||
sneak-speed: 5
|
sneak-speed: 5
|
||||||
|
# Acceleration when player starts moving or changes direction, in m/s^2.
|
||||||
acceleration: 60
|
acceleration: 60
|
||||||
|
# Deceleration when player stops moving, in m/s^2.
|
||||||
deceleration: 30
|
deceleration: 30
|
||||||
|
# The radius of the player.
|
||||||
radius: 0.5
|
radius: 0.5
|
||||||
|
# How many seconds a player must wait before resupplying again.
|
||||||
resupply-cooldown: 30
|
resupply-cooldown: 30
|
||||||
|
# The maximum health of players.
|
||||||
max-health: 100
|
max-health: 100
|
||||||
|
# How quickly players regenerate health, in points per second. Set to 0 to disable regeneration.
|
||||||
health-regen-rate: 1.0
|
health-regen-rate: 1.0
|
||||||
|
# How much sneaking affects gun accuracy. Values less than 0 increase accuracy, and greater than 0 decrease accuracy.
|
||||||
sneak-accuracy-modifier: 0.5
|
sneak-accuracy-modifier: 0.5
|
||||||
|
# How much sprinting affects gun accuracy. Values less than 0 increase accuracy, and greater than 0 decrease accuracy.
|
||||||
sprint-accuracy-modifier: 1.5
|
sprint-accuracy-modifier: 1.5
|
||||||
# Should be the name of one of the guns defined in "gun-settings".
|
# Should be the name of one of the guns defined in "gun-settings".
|
||||||
default-gun: M1 Garand
|
default-gun: M1 Garand
|
||||||
|
|
||||||
|
|
||||||
# Settings for team mechanics.
|
# Settings for team mechanics.
|
||||||
team-settings:
|
team-settings:
|
||||||
|
# The radius of team spawn points, in meters.
|
||||||
spawn-point-radius: 3
|
spawn-point-radius: 3
|
||||||
|
# The radius of team resupply points, in meters.
|
||||||
supply-point-radius: 2
|
supply-point-radius: 2
|
||||||
|
# Whether friendly fire is enabled. If enabled, players can kill teammates.
|
||||||
friendly-fire: false
|
friendly-fire: false
|
||||||
|
|
||||||
|
|
||||||
# The list of available guns are defined in this list.
|
# The list of available guns are defined in this list.
|
||||||
gun-settings:
|
gun-settings:
|
||||||
- name: AK-47
|
- name: AK-47
|
||||||
|
|
Loading…
Reference in New Issue