diff --git a/.gitignore b/.gitignore index ae65572..e440c55 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ client/target/ core/target/ server/target/ server-registry/target/ -*.iml \ No newline at end of file +*.iml +/settings.yaml +/*.log \ No newline at end of file diff --git a/server/src/main/java/nl/andrewlalis/aos_server/Server.java b/server/src/main/java/nl/andrewlalis/aos_server/Server.java index 8bff6f8..7ca0d7f 100644 --- a/server/src/main/java/nl/andrewlalis/aos_server/Server.java +++ b/server/src/main/java/nl/andrewlalis/aos_server/Server.java @@ -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.util.ByteUtils; import nl.andrewlalis.aos_server.settings.ServerSettings; +import nl.andrewlalis.aos_server.settings.SettingsLoader; import java.awt.*; import java.io.IOException; @@ -54,6 +55,7 @@ public class Server { this.worldUpdater = new WorldUpdater(this, this.world); this.chatManager = new ChatManager(this); if (settings.getRegistrySettings().isDiscoverable()) { + System.out.println("Starting registry communications."); this.registryManager = new RegistryManager(this); } } @@ -267,11 +269,7 @@ public class Server { public static void main(String[] args) throws IOException { - ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); - 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 server = new Server(SettingsLoader.load()); server.run(); } } diff --git a/server/src/main/java/nl/andrewlalis/aos_server/settings/SettingsLoader.java b/server/src/main/java/nl/andrewlalis/aos_server/settings/SettingsLoader.java new file mode 100644 index 0000000..be42436 --- /dev/null +++ b/server/src/main/java/nl/andrewlalis/aos_server/settings/SettingsLoader.java @@ -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; + } +} diff --git a/server/src/main/resources/default_settings.yaml b/server/src/main/resources/default_settings.yaml index 1d002be..8edecc7 100644 --- a/server/src/main/resources/default_settings.yaml +++ b/server/src/main/resources/default_settings.yaml @@ -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. port: 8035 # 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. 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: # 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. registry-uri: "http://localhost:8567" # How often to send status updates to the registry server, in seconds. @@ -26,26 +32,42 @@ registry-settings: # Settings that control player behavior. player-settings: + # Walking speed, in meters per second. speed: 10 + # Sprinting speed, in meters per second. sprint-speed: 18 + # Sneaking speed, in meters per second. sneak-speed: 5 + # Acceleration when player starts moving or changes direction, in m/s^2. acceleration: 60 + # Deceleration when player stops moving, in m/s^2. deceleration: 30 + # The radius of the player. radius: 0.5 + # How many seconds a player must wait before resupplying again. resupply-cooldown: 30 + # The maximum health of players. max-health: 100 + # How quickly players regenerate health, in points per second. Set to 0 to disable regeneration. 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 + # How much sprinting affects gun accuracy. Values less than 0 increase accuracy, and greater than 0 decrease accuracy. sprint-accuracy-modifier: 1.5 # Should be the name of one of the guns defined in "gun-settings". default-gun: M1 Garand + # Settings for team mechanics. team-settings: + # The radius of team spawn points, in meters. spawn-point-radius: 3 + # The radius of team resupply points, in meters. supply-point-radius: 2 + # Whether friendly fire is enabled. If enabled, players can kill teammates. friendly-fire: false + # The list of available guns are defined in this list. gun-settings: - name: AK-47