From fb2596d3bef4d10ed943db6a83342df44635b168 Mon Sep 17 00:00:00 2001 From: Robert Paciorek Date: Fri, 1 Mar 2024 00:38:47 +0000 Subject: [PATCH] add config options: ListenIP, AllowChaos, ... and FirstEventTimer --- src/Core/Configuration.cs | 6 ++++-- src/Core/WorldEvent.cs | 2 +- src/Data/PlayerData.cs | 2 +- src/Program.cs | 17 ++++++++++++++++- src/Server.cs | 7 +++++-- src/appsettings.json | 16 +++++++++++++++- 6 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/Core/Configuration.cs b/src/Core/Configuration.cs index 8a94ad2..dad0c40 100644 --- a/src/Core/Configuration.cs +++ b/src/Core/Configuration.cs @@ -24,8 +24,10 @@ internal static class Configuration { } internal sealed class ServerConfiguration { - public bool EnableChat { get; set; } = true; + public string ListenIP { get; set; } = string.Empty; public int Port { get; set; } = 9933; public int EventTimer { get; set; } = 30; - + public int FirstEventTimer { get; set; } = 10; + public bool EnableChat { get; set; } = true; + public bool AllowChaos { get; set; } = false; } diff --git a/src/Core/WorldEvent.cs b/src/Core/WorldEvent.cs index e6f8879..603ea1a 100644 --- a/src/Core/WorldEvent.cs +++ b/src/Core/WorldEvent.cs @@ -26,7 +26,7 @@ class WorldEvent { startTimeString = startTime.ToString("MM/dd/yyyy HH:mm:ss"); uid = "sodoff"; state = State.End; - ScheduleEvent(10); // WE_ != WEN_ + ScheduleEvent(Configuration.ServerConfiguration.FirstEventTimer); // WE_ != WEN_ } // controlled (init/reset) by Reset() diff --git a/src/Data/PlayerData.cs b/src/Data/PlayerData.cs index 3107952..0e3f234 100644 --- a/src/Data/PlayerData.cs +++ b/src/Data/PlayerData.cs @@ -84,7 +84,7 @@ public class PlayerData { if (keyValPairs.TryGetValue("U", out string userdata)) { PetMounted = (userdata == "0" || userdata == "1"); } - if (PetMounted && + if (PetMounted && !Configuration.ServerConfiguration.AllowChaos && (GeometryType == PetGeometryType.Default && PetAge < PetAge.Teen || GeometryType == PetGeometryType.Terror && PetAge < PetAge.Titan) ) { diff --git a/src/Program.cs b/src/Program.cs index c6b01e3..6878f22 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -3,5 +3,20 @@ using sodoffmmo.Core; using System.Net; Configuration.Initialize(); -Server server = new(IPAddress.Any, Configuration.ServerConfiguration.Port); + +Server server; + +if (String.IsNullOrEmpty(Configuration.ServerConfiguration.ListenIP) || Configuration.ServerConfiguration.ListenIP == "*") { + server = new( + IPAddress.IPv6Any, + Configuration.ServerConfiguration.Port, + true + ); +} else { + server = new( + IPAddress.Parse(Configuration.ServerConfiguration.ListenIP), + Configuration.ServerConfiguration.Port, + false + ); +} await server.Run(); diff --git a/src/Server.cs b/src/Server.cs index ac8fa32..2001576 100644 --- a/src/Server.cs +++ b/src/Server.cs @@ -9,11 +9,13 @@ public class Server { readonly int port; readonly IPAddress ipAddress; + readonly bool IPv6AndIPv4; ModuleManager moduleManager = new(); - public Server(IPAddress ipAdress, int port) { + public Server(IPAddress ipAdress, int port, bool IPv6AndIPv4) { this.ipAddress = ipAdress; this.port = port; + this.IPv6AndIPv4 = IPv6AndIPv4; } public async Task Run() { @@ -21,7 +23,8 @@ public class Server { using Socket listener = new(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); - + if (IPv6AndIPv4) + listener.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, 0); listener.Bind(new IPEndPoint(ipAddress, port)); await Listen(listener); } diff --git a/src/appsettings.json b/src/appsettings.json index 1b7390f..24f6877 100644 --- a/src/appsettings.json +++ b/src/appsettings.json @@ -1,7 +1,21 @@ { "ServerConfiguration": { + "// ListenIP": "Listening IP address for the asset server, default is '*' which represents all IPv4 and IPv6 addresses", + "ListenIP": "*", + + "// Port": "Listening port number for the MMO server", "Port": 9933, + + "// EnableChat": "When true, in-game chat will be enabled", "EnableChat": true, - "EventTimer": 30 + + "// FirstEventTimer": "time to start of first world event (battle ship event) after start MMO server", + "FirstEventTimer": 10, + + "// EventTimer": "time between start of world events (battle ship events)", + "EventTimer": 30, + + "// AllowChaos": "disable server side exploit protection", + "AllowChaos": false } }