diff --git a/src/Core/Configuration.cs b/src/Core/Configuration.cs index f8b2687..530ac38 100644 --- a/src/Core/Configuration.cs +++ b/src/Core/Configuration.cs @@ -44,6 +44,7 @@ internal sealed class ServerConfiguration { public int PingDelay { get; set; } = 17; public bool EnableChat { get; set; } = true; public bool AllowChaos { get; set; } = false; + public bool MakeChaos { get; set; } = false; public AuthenticationMode Authentication { get; set; } = AuthenticationMode.Disabled; public string ApiUrl { get; set; } = ""; public string BypassToken { get; set; } = ""; diff --git a/src/Core/Room.cs b/src/Core/Room.cs index 5e59735..08cc99a 100644 --- a/src/Core/Room.cs +++ b/src/Core/Room.cs @@ -1,5 +1,6 @@ using System; using sodoffmmo.Data; +using System.Timers; namespace sodoffmmo.Core; public class Room { @@ -33,6 +34,9 @@ public class Room { } AutoRemove = autoRemove; rooms.Add(Name, this); + + if (Configuration.ServerConfiguration.MakeChaos) + SetTimer(2); } public int ClientsCount => clients.Count; @@ -155,4 +159,35 @@ public class Room { } internal virtual NetworkArray GetRoomVars() { return RoomVariables; } + + + private System.Timers.Timer timer; + private Random random = new Random(); + + private void SetTimer(double timeout) { + if (timer != null) { + timer.Stop(); + timer.Close(); + } + + timer = new System.Timers.Timer(timeout * 1000); + timer.AutoReset = false; + timer.Enabled = true; + timer.Elapsed += OnTimer; + } + + private void OnTimer(Object? source, ElapsedEventArgs e) { + foreach (var roomClient in Clients) { + roomClient.PlayerData.RandomizeDragon(); + + NetworkArray vl = new(); + NetworkObject data = new(); + var value = roomClient.PlayerData.GetVariable("FP"); + data.Add("FP", value); + vl.Add(NetworkArray.Param("FP", value)); + + roomClient.SendSUV(vl, data); + } + SetTimer(random.NextDouble() * 9 + 1); + } } diff --git a/src/Data/PlayerData.cs b/src/Data/PlayerData.cs index 47eed62..45a8738 100644 --- a/src/Data/PlayerData.cs +++ b/src/Data/PlayerData.cs @@ -171,6 +171,8 @@ public class PlayerData { } } + private string PetGeometry = ""; + private string FixMountState(string value) { // raised pet geometry - set from Fp PetGeometryType GeometryType = PetGeometryType.Default; @@ -202,6 +204,11 @@ public class PlayerData { if (keyValPairs.TryGetValue("U", out string userdata)) { PetMounted = (userdata == "0" || userdata == "1"); } + if (Configuration.ServerConfiguration.MakeChaos) { + if (PetGeometry == geometry) + return variables["FP"]; + PetGeometry = geometry; + } if (PetMounted && !Configuration.ServerConfiguration.AllowChaos && (GeometryType == PetGeometryType.Default && PetAge < PetAge.Teen || GeometryType == PetGeometryType.Terror && PetAge < PetAge.Titan) @@ -211,6 +218,14 @@ public class PlayerData { return value; } } + + private Random random = new Random(); + public void RandomizeDragon() { + var s = "*C$"; + for (var i=0; i<9; ++i) + s=s+random.Next(0, 255).ToString() + "$"; + variables["FP"] = Regex.Replace(variables["FP"], "\\*C\\$[0-9$]*\\*", s + "*"); + } } public enum PetGeometryType { diff --git a/src/appsettings.json b/src/appsettings.json index a9a6b85..06b56f7 100644 --- a/src/appsettings.json +++ b/src/appsettings.json @@ -56,6 +56,9 @@ "// AllowChaos": "disable server side exploit protection", "AllowChaos": false, + "// MakeChaos": "enable server-side randomize stuff", + "MakeChaos": true, + "// Authentication": "Player authentication mode: Disabled, Optional, RequiredForChat, Required", "// Authentication Disabled": "authentication is disabled, anyone can connect to mmo", "// Authentication Optional": "authentication is required only for moderation activities",