From e776a6bb9e6e628bb27e706d6d4097d582c81993 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 18 Jan 2025 15:34:51 -0700 Subject: [PATCH 01/58] Adds a config flag for managing warps --- AriasServerUtils/ASUModSystem.cs | 18 +++++++++++++++++- AriasServerUtils/EventHandler.cs | 10 ++++++++++ AriasServerUtils/{ModConfig.cs => Globals.cs} | 14 ++++++++++++++ AriasServerUtils/modinfo.json | 2 +- 4 files changed, 42 insertions(+), 2 deletions(-) rename AriasServerUtils/{ModConfig.cs => Globals.cs} (51%) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index 7e0589b..dcb1b58 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -20,6 +20,9 @@ namespace AriasServerUtils internal static Dictionary mPlayerData = new Dictionary(); + internal static Warps serverWarps = new Warps(); + + internal static string[] saveInvTypes = new string[] { GlobalConstants.hotBarInvClassName, GlobalConstants.backpackInvClassName, @@ -107,9 +110,16 @@ namespace AriasServerUtils .HandleWith(Events.HandleUpdateASUBypass) .EndSubCommand() .WithDescription("Updates the ASU mod configuration") + .BeginSubCommand("onlyAdminManageWarps") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs( + parsers.Bool("manageWarps") + ) + .WithDescription("DANGER: This updates the flag allowing anybody to create warps, even non-admins. It is recommended to leave this alone. The default is true/on/yes") + .HandleWith(Events.HandleUpdateASUMgrWarps) + .EndSubCommand() .EndSubCommand() .BeginSubCommand("help") - .RequiresPlayer() .RequiresPrivilege(Privilege.chat) .HandleWith(Events.HandleASU) .WithDescription("Lists all Aria's Server Utils commands") @@ -223,6 +233,8 @@ namespace AriasServerUtils public void SaveGlobalConfig() { API.StoreModConfig(config, GetConfigurationFile("global", ModConfigType.Global)); + + API.StoreModConfig(serverWarps, GetConfigurationFile("warps", ModConfigType.Global)); } private void OnGameReady() @@ -232,6 +244,10 @@ namespace AriasServerUtils config = API.LoadModConfig(GetConfigurationFile("global", ModConfigType.Global)); if (config == null) config = new ASUModConfig(); + + // -> Step 2. Load Mod Warps <- + serverWarps = API.LoadModConfig(GetConfigurationFile("warps", ModConfigType.Global)); + if (serverWarps == null) serverWarps = new Warps(); } public string GetConfigurationFile(string sName, ModConfigType type) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index f378e84..9f491be 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -211,5 +211,15 @@ namespace AriasServerUtils return TextCommandResult.Success(); } + + internal static TextCommandResult HandleUpdateASUMgrWarps(TextCommandCallingArgs args) + { + if (args[0] is bool mgr) + ServerUtilities.config.onlyAdminsCreateWarps = mgr; + else ServerUtilities.config.onlyAdminsCreateWarps = true; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } } } \ No newline at end of file diff --git a/AriasServerUtils/ModConfig.cs b/AriasServerUtils/Globals.cs similarity index 51% rename from AriasServerUtils/ModConfig.cs rename to AriasServerUtils/Globals.cs index d16e04e..eba4c15 100644 --- a/AriasServerUtils/ModConfig.cs +++ b/AriasServerUtils/Globals.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace AriasServerUtils { @@ -13,8 +14,21 @@ namespace AriasServerUtils { public int MaxHomes { get; set; } = 20; public bool AdminsBypassMaxHomes { get; set; } = true; + public bool onlyAdminsCreateWarps { get; set; } = true; public PlayerPosition Spawn { get; set; } } + + [Serializable] + public class Warp + { + public PlayerPosition Location; + } + + [Serializable] + public class Warps + { + public Dictionary warps = new Dictionary(); + } } \ No newline at end of file diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 5247ac9..8bcd409 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -4,7 +4,7 @@ "name": "Aria's Server Utilities", "authors": ["zontreck"], "description": "A collection of server utilities\n\nBuild Date: 01-18-2025 @ 03:18 PM", - "version": "1.0.1", + "version": "1.0.1-dev.1", "dependencies": { "game": "" } From 737c51989bd3090c33049307b2218c7ce7829e91 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 18 Jan 2025 16:11:00 -0700 Subject: [PATCH 02/58] Adds in warps --- AriasServerUtils/ASUModSystem.cs | 5 ++ AriasServerUtils/EventHandler.cs | 86 ++++++++++++++++++- AriasServerUtils/Globals.cs | 14 +++ .../assets/ariasserverutils/lang/en.json | 9 +- AriasServerUtils/modinfo.json | 4 +- 5 files changed, 114 insertions(+), 4 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index dcb1b58..6efd6d2 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -124,6 +124,11 @@ namespace AriasServerUtils .HandleWith(Events.HandleASU) .WithDescription("Lists all Aria's Server Utils commands") .EndSubCommand(); + + api.ChatCommands.Create("setwarp").RequiresPlayer().WithDescription("Creates a new server warp").HandleWith(Events.HandleWarpUpdate).WithArgs(parsers.OptionalWord("name")); + api.ChatCommands.Create("warp").RequiresPlayer().WithDescription("Warp to the specified server warp").HandleWith(Events.HandleWarp).WithArgs(parsers.OptionalWord("name")); + api.ChatCommands.Create("delwarp").RequiresPlayer().WithDescription("Deletes the specified warp").HandleWith(Events.HandleWarpDelete).WithArgs(parsers.OptionalWord("name")); + api.ChatCommands.Create("warps").RequiresPlayer().WithDescription("Lists all server warps").HandleWith(Events.HandleWarpList); } private void OnPlayerDC(IServerPlayer byPlayer) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 9f491be..01f300f 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -12,7 +12,7 @@ namespace AriasServerUtils { internal static TextCommandResult HandleASU(TextCommandCallingArgs args) { - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:help", ServerUtilities.config.MaxHomes, ServerUtilities.config.AdminsBypassMaxHomes, string.Join(", ", new string[] { "setspawn", "spawn", "delspawn", "sethome", "home", "delhome", "homes", "restoreinv", "asu" }))); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:help", ServerUtilities.config.MaxHomes, ServerUtilities.config.AdminsBypassMaxHomes, string.Join(", ", new string[] { "setspawn", "spawn", "delspawn", "sethome", "home", "delhome", "homes", "restoreinv", "asu", "warp", "setwarp", "delwarp", "warps" }))); } internal static TextCommandResult HandleClearSpawn(TextCommandCallingArgs args) @@ -221,5 +221,89 @@ namespace AriasServerUtils return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); } + + internal static TextCommandResult HandleWarp(TextCommandCallingArgs args) + { + string name = "default"; + if (args.ArgCount > 0) name = args[0] as string ?? "default"; + + if (args.Caller.Player is IServerPlayer isp) + { + if (ServerUtilities.serverWarps.warps.ContainsKey(name)) + { + + ServerUtilities.serverWarps.warps[name].Location.Merge(isp.Entity); + + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:warp-set", name)); + } + else + { + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:warp-fail", name)); + + } + + } + + return TextCommandResult.Success(); + } + + internal static TextCommandResult HandleWarpDelete(TextCommandCallingArgs args) + { + string name = "default"; + if (args.ArgCount > 0) name = args[0] as string ?? "default"; + + if (args.Caller.Player is IServerPlayer isp) + { + if (isp.HasPrivilege(Privilege.controlserver) || !ServerUtilities.config.onlyAdminsCreateWarps) + { + ServerUtilities.serverWarps.warps.Remove(name); + ServerUtilities.MarkDirty(); + + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:warp-del")); + } + else + { + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:warp-no")); + } + } + + return TextCommandResult.Success(); + } + + internal static TextCommandResult HandleWarpList(TextCommandCallingArgs args) + { + List warps = new List(); + foreach (string id in ServerUtilities.serverWarps.warps.Keys) + { + warps.Add(id); + } + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:warp-list", warps.Count, string.Join(", ", warps))); + } + + internal static TextCommandResult HandleWarpUpdate(TextCommandCallingArgs args) + { + string name = "default"; + if (args.ArgCount > 0) name = args[0] as string ?? "default"; + + if (args.Caller.Player is IServerPlayer isp) + { + if (isp.HasPrivilege(Privilege.controlserver) || !ServerUtilities.config.onlyAdminsCreateWarps) + { + ServerUtilities.serverWarps.warps[name] = Warp.Create(isp); + ServerUtilities.MarkDirty(); + + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:warp-set", name)); + + } + else + { + + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:warp-no")); + } + } + + return TextCommandResult.Success(); + } } } \ No newline at end of file diff --git a/AriasServerUtils/Globals.cs b/AriasServerUtils/Globals.cs index eba4c15..8d8f85e 100644 --- a/AriasServerUtils/Globals.cs +++ b/AriasServerUtils/Globals.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Vintagestory.API.Server; namespace AriasServerUtils { @@ -24,6 +25,19 @@ namespace AriasServerUtils public class Warp { public PlayerPosition Location; + public string CreatedBy; + public DateTime CreatedAt; + + + public static Warp Create(IServerPlayer player) + { + Warp warp = new Warp(); + warp.Location = PlayerPosition.from(player.Entity); + warp.CreatedBy = player.PlayerName; + warp.CreatedAt = DateTime.Now; + + return warp; + } } [Serializable] diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index 0dc690a..49bdb1d 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -20,5 +20,12 @@ "help": "All Aria's Server Utilities Commands: \n\nMax Homes: {0}; Admins can bypass max homes: {1}\n{2}", - "updatedconfig": "[ASU] server config updated" + "updatedconfig": "[ASU] server config updated", + + "warp-tp": "Teleported to warp [{0}]", + "warp-set": "Warp [{0}] created!", + "warp-no": "You lack permissions to manage a warp", + "warp-fail": "Warp [{0}] does not exist", + "warp-del": "Warp [{0}] deleted", + "warp-list": "There are [{0}] total warps\n\n{1}" } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 8bcd409..84c6b9d 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 01-18-2025 @ 03:18 PM", - "version": "1.0.1-dev.1", + "description": "A collection of server utilities\n\nBuild Date: 01-18-2025 @ 04:10 PM", + "version": "1.0.1-dev.2", "dependencies": { "game": "" } From 1f43ffaa6ca0d225d58bceb91f96f6ad99e85702 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 18 Jan 2025 16:14:51 -0700 Subject: [PATCH 03/58] Release 1.0.2 --- AriasServerUtils/ASUModSystem.cs | 8 ++++---- AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index 6efd6d2..c92644c 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -125,10 +125,10 @@ namespace AriasServerUtils .WithDescription("Lists all Aria's Server Utils commands") .EndSubCommand(); - api.ChatCommands.Create("setwarp").RequiresPlayer().WithDescription("Creates a new server warp").HandleWith(Events.HandleWarpUpdate).WithArgs(parsers.OptionalWord("name")); - api.ChatCommands.Create("warp").RequiresPlayer().WithDescription("Warp to the specified server warp").HandleWith(Events.HandleWarp).WithArgs(parsers.OptionalWord("name")); - api.ChatCommands.Create("delwarp").RequiresPlayer().WithDescription("Deletes the specified warp").HandleWith(Events.HandleWarpDelete).WithArgs(parsers.OptionalWord("name")); - api.ChatCommands.Create("warps").RequiresPlayer().WithDescription("Lists all server warps").HandleWith(Events.HandleWarpList); + api.ChatCommands.Create("setwarp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Creates a new server warp").WithArgs(parsers.OptionalWord("name")).HandleWith(Events.HandleWarpUpdate); + api.ChatCommands.Create("warp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Warp to the specified server warp").WithArgs(parsers.OptionalWord("name")).HandleWith(Events.HandleWarp); + api.ChatCommands.Create("delwarp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Deletes the specified warp").WithArgs(parsers.OptionalWord("name")).HandleWith(Events.HandleWarpDelete); + api.ChatCommands.Create("warps").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Lists all server warps").HandleWith(Events.HandleWarpList); } private void OnPlayerDC(IServerPlayer byPlayer) diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 84c6b9d..5821fc5 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 01-18-2025 @ 04:10 PM", - "version": "1.0.1-dev.2", + "description": "A collection of server utilities\n\nBuild Date: 01-18-2025 @ 04:14 PM", + "version": "1.0.2", "dependencies": { "game": "" } From 3e0896f5f99e900021b38a2eb12638eff310ffa2 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 18 Jan 2025 21:23:21 -0700 Subject: [PATCH 04/58] Release 1.0.3 Fix: Permissions on /homes Add: /back --- AriasServerUtils/ASUModSystem.cs | 21 ++++++++++- AriasServerUtils/EventHandler.cs | 37 +++++++++++++++++-- AriasServerUtils/Globals.cs | 36 ++++++++++++++++++ .../assets/ariasserverutils/lang/en.json | 7 +++- AriasServerUtils/modinfo.json | 4 +- 5 files changed, 97 insertions(+), 8 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index c92644c..6ffab7c 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -20,6 +20,8 @@ namespace AriasServerUtils internal static Dictionary mPlayerData = new Dictionary(); + internal static BackCaches backCaches = new BackCaches(); + internal static Warps serverWarps = new Warps(); @@ -87,7 +89,7 @@ namespace AriasServerUtils api.ChatCommands.Create("sethome").RequiresPlayer().WithArgs(parsers.OptionalWord("name")).WithDescription("Creates a home").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleSetHome); api.ChatCommands.Create("home").RequiresPlayer().WithArgs(parsers.OptionalWord("name")).WithDescription("Teleports you to home").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleGoHome); api.ChatCommands.Create("delhome").RequiresPlayer().WithArgs(parsers.OptionalWord("name")).WithDescription("Deletes a home entry").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleDelHome); - api.ChatCommands.Create("homes").RequiresPlayer().WithDescription("Lists your homes").RequiresPrivilege(Privilege.controlserver).HandleWith(Events.HandleListHomes); + api.ChatCommands.Create("homes").RequiresPlayer().WithDescription("Lists your homes").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleListHomes); api.ChatCommands.Create("asu") .RequiresPrivilege(Privilege.chat) @@ -118,6 +120,14 @@ namespace AriasServerUtils .WithDescription("DANGER: This updates the flag allowing anybody to create warps, even non-admins. It is recommended to leave this alone. The default is true/on/yes") .HandleWith(Events.HandleUpdateASUMgrWarps) .EndSubCommand() + .BeginSubCommand("maxback") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs( + parsers.OptionalInt("max") + ) + .WithDescription("Max number of back positions cached for players") + .HandleWith(Events.HandleUpdateASUMaxBack) + .EndSubCommand() .EndSubCommand() .BeginSubCommand("help") .RequiresPrivilege(Privilege.chat) @@ -129,6 +139,13 @@ namespace AriasServerUtils api.ChatCommands.Create("warp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Warp to the specified server warp").WithArgs(parsers.OptionalWord("name")).HandleWith(Events.HandleWarp); api.ChatCommands.Create("delwarp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Deletes the specified warp").WithArgs(parsers.OptionalWord("name")).HandleWith(Events.HandleWarpDelete); api.ChatCommands.Create("warps").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Lists all server warps").HandleWith(Events.HandleWarpList); + + api.ChatCommands.Create("back").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Returns you to the last location you were at").HandleWith(Events.HandleBack); + } + + public static void NewBackCacheForPlayer(IServerPlayer player) + { + backCaches.AddPosition(player.PlayerName, PlayerPosition.from(player.Entity)); } private void OnPlayerDC(IServerPlayer byPlayer) @@ -172,6 +189,8 @@ namespace AriasServerUtils PlayerInventory inv = new PlayerInventory(); var invMgr = player.InventoryManager; + NewBackCacheForPlayer(player); + var iBackpackSlotNum = 0; foreach (var type in saveInvTypes) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 01f300f..1e75408 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -12,7 +12,23 @@ namespace AriasServerUtils { internal static TextCommandResult HandleASU(TextCommandCallingArgs args) { - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:help", ServerUtilities.config.MaxHomes, ServerUtilities.config.AdminsBypassMaxHomes, string.Join(", ", new string[] { "setspawn", "spawn", "delspawn", "sethome", "home", "delhome", "homes", "restoreinv", "asu", "warp", "setwarp", "delwarp", "warps" }))); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:help", ServerUtilities.config.MaxHomes, ServerUtilities.config.AdminsBypassMaxHomes, ServerUtilities.config.MaxBackCache, string.Join(", ", new string[] { "setspawn", "spawn", "delspawn", "sethome", "home", "delhome", "homes", "restoreinv", "asu", "warp", "setwarp", "delwarp", "warps", "back" }))); + } + + internal static TextCommandResult HandleBack(TextCommandCallingArgs args) + { + PlayerPosition pos = ServerUtilities.backCaches.ReadAndPopNewestPosition(args.Caller.Player.PlayerName); + if (pos == null) + { + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:back-no")); + } + else + { + // Go back to old position + pos.Merge(args.Caller.Player.Entity); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:back")); + } + } internal static TextCommandResult HandleClearSpawn(TextCommandCallingArgs args) @@ -63,6 +79,7 @@ namespace AriasServerUtils PlayerStorage data = ServerUtilities.GetPlayerData(isp); if (data.Homes.ContainsKey(homeName)) { + ServerUtilities.NewBackCacheForPlayer(isp); data.Homes[homeName].Location.Merge(isp.Entity); ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:home-tp")); @@ -177,6 +194,7 @@ namespace AriasServerUtils if (args.Caller.Player is IServerPlayer isp) { ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:tp-spawn")); + ServerUtilities.NewBackCacheForPlayer(isp); ServerUtilities.config.Spawn.Merge(args.Caller.Player.Entity); } @@ -188,7 +206,7 @@ namespace AriasServerUtils internal static TextCommandResult HandleUpdateASUBypass(TextCommandCallingArgs args) { - if (args[1] is bool bypass) + if (args[0] is bool bypass) { ServerUtilities.config.AdminsBypassMaxHomes = bypass; ServerUtilities.MarkDirty(); @@ -199,6 +217,19 @@ namespace AriasServerUtils } + internal static TextCommandResult HandleUpdateASUMaxBack(TextCommandCallingArgs args) + { + if (args[0] is int max) + { + ServerUtilities.config.MaxBackCache = max; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } + + return TextCommandResult.Success(); + } + internal static TextCommandResult HandleUpdateASUMaxHomes(TextCommandCallingArgs args) { if (args[0] is int maxHomes) @@ -231,7 +262,7 @@ namespace AriasServerUtils { if (ServerUtilities.serverWarps.warps.ContainsKey(name)) { - + ServerUtilities.NewBackCacheForPlayer(isp); ServerUtilities.serverWarps.warps[name].Location.Merge(isp.Entity); ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:warp-set", name)); diff --git a/AriasServerUtils/Globals.cs b/AriasServerUtils/Globals.cs index 8d8f85e..df5a653 100644 --- a/AriasServerUtils/Globals.cs +++ b/AriasServerUtils/Globals.cs @@ -16,6 +16,7 @@ namespace AriasServerUtils public int MaxHomes { get; set; } = 20; public bool AdminsBypassMaxHomes { get; set; } = true; public bool onlyAdminsCreateWarps { get; set; } = true; + public int MaxBackCache { get; set; } = 10; public PlayerPosition Spawn { get; set; } @@ -45,4 +46,39 @@ namespace AriasServerUtils { public Dictionary warps = new Dictionary(); } + + + public class BackCaches + { + private const int MaxCacheSize = 10; + private readonly Dictionary> playerCache = new(); + + public void AddPosition(string playerName, PlayerPosition position) + { + if (!playerCache.TryGetValue(playerName, out var positions)) + { + positions = new LinkedList(); + playerCache[playerName] = positions; + } + + if (positions.Count >= MaxCacheSize) + { + positions.RemoveFirst(); // Remove the oldest position + } + + positions.AddLast(position.Clone()); // Add the new position + } + + public PlayerPosition ReadAndPopNewestPosition(string playerName) + { + if (playerCache.TryGetValue(playerName, out var positions) && positions.Count > 0) + { + var newestPosition = positions.Last.Value; + positions.RemoveLast(); // Remove the newest position + return newestPosition; + } + + return null; // Return null if no positions are available + } + } } \ No newline at end of file diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index 49bdb1d..7116583 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -18,7 +18,7 @@ "home-del": "Home deleted", "home-list": "You have [{0}] home(s)\n\n{1}", - "help": "All Aria's Server Utilities Commands: \n\nMax Homes: {0}; Admins can bypass max homes: {1}\n{2}", + "help": "All Aria's Server Utilities Commands: \n\nMax Homes: {0}; \nAdmins can bypass max homes: {1}\nMax back positions: {2}\n\n{3}", "updatedconfig": "[ASU] server config updated", @@ -27,5 +27,8 @@ "warp-no": "You lack permissions to manage a warp", "warp-fail": "Warp [{0}] does not exist", "warp-del": "Warp [{0}] deleted", - "warp-list": "There are [{0}] total warps\n\n{1}" + "warp-list": "There are [{0}] total warps\n\n{1}", + + "back-no": "There's no position to go back to", + "back": "You've been taken back to your last position" } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 5821fc5..ef9e6f3 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 01-18-2025 @ 04:14 PM", - "version": "1.0.2", + "description": "A collection of server utilities\n\nBuild Date: 01-18-2025 @ 09:22 PM", + "version": "1.0.3", "dependencies": { "game": "" } From 1f5458b8b1b86259afccf9956825d41290e1bcb3 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 20 Jan 2025 04:10:17 -0700 Subject: [PATCH 05/58] Begin to add player sleeping percentage --- AriasServerUtils/ASUModSystem.cs | 10 ++++++++++ AriasServerUtils/EventHandler.cs | 8 ++++++++ AriasServerUtils/Globals.cs | 1 + AriasServerUtils/modinfo.json | 4 ++-- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index 6ffab7c..ed22f3b 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -5,6 +5,7 @@ using Vintagestory.API.Client; using Vintagestory.API.Common; using Vintagestory.API.Common.Entities; using Vintagestory.API.Config; +using Vintagestory.API.MathTools; using Vintagestory.API.Server; using Vintagestory.GameContent; @@ -128,6 +129,14 @@ namespace AriasServerUtils .WithDescription("Max number of back positions cached for players") .HandleWith(Events.HandleUpdateASUMaxBack) .EndSubCommand() + .BeginSubCommand("playerSleepingPercentage") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs( + parsers.OptionalIntRange("psp", 1, 100, 50) + ) + .WithDescription("Percentage of players required to sleep before sleeping through the night") + .HandleWith(Events.HandleUpdateASUPSP) + .EndSubCommand() .EndSubCommand() .BeginSubCommand("help") .RequiresPrivilege(Privilege.chat) @@ -143,6 +152,7 @@ namespace AriasServerUtils api.ChatCommands.Create("back").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Returns you to the last location you were at").HandleWith(Events.HandleBack); } + public static void NewBackCacheForPlayer(IServerPlayer player) { backCaches.AddPosition(player.PlayerName, PlayerPosition.from(player.Entity)); diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 1e75408..4731723 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -253,6 +253,14 @@ namespace AriasServerUtils return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); } + internal static TextCommandResult HandleUpdateASUPSP(TextCommandCallingArgs args) + { + if (args[0] is int psp) ServerUtilities.config.PlayerSleepingPercentage = psp; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } + internal static TextCommandResult HandleWarp(TextCommandCallingArgs args) { string name = "default"; diff --git a/AriasServerUtils/Globals.cs b/AriasServerUtils/Globals.cs index df5a653..223b195 100644 --- a/AriasServerUtils/Globals.cs +++ b/AriasServerUtils/Globals.cs @@ -17,6 +17,7 @@ namespace AriasServerUtils public bool AdminsBypassMaxHomes { get; set; } = true; public bool onlyAdminsCreateWarps { get; set; } = true; public int MaxBackCache { get; set; } = 10; + public int PlayerSleepingPercentage { get; set; } = 50; public PlayerPosition Spawn { get; set; } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index ef9e6f3..8b8b488 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 01-18-2025 @ 09:22 PM", - "version": "1.0.3", + "description": "A collection of server utilities\n\nBuild Date: 01-20-2025 @ 12:38 AM MST", + "version": "1.0.4-dev.1", "dependencies": { "game": "" } From 740801bd96faa7075064237f2c059fc137378323 Mon Sep 17 00:00:00 2001 From: zontreck Date: Thu, 6 Mar 2025 09:36:38 -0700 Subject: [PATCH 06/58] Begin adding RTP Part of #2 --- AriasServerUtils/ASUModSystem.cs | 2 ++ AriasServerUtils/EventHandler.cs | 7 ++++++- AriasServerUtils/modinfo.json | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index ed22f3b..0755aac 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -150,6 +150,8 @@ namespace AriasServerUtils api.ChatCommands.Create("warps").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Lists all server warps").HandleWith(Events.HandleWarpList); api.ChatCommands.Create("back").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Returns you to the last location you were at").HandleWith(Events.HandleBack); + + api.ChatCommands.Create("rtp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Seeks a position possibly thousands of blocks away to teleport to.").HandleWith(Events.HandleRTP); } diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 4731723..1df0360 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -12,7 +12,7 @@ namespace AriasServerUtils { internal static TextCommandResult HandleASU(TextCommandCallingArgs args) { - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:help", ServerUtilities.config.MaxHomes, ServerUtilities.config.AdminsBypassMaxHomes, ServerUtilities.config.MaxBackCache, string.Join(", ", new string[] { "setspawn", "spawn", "delspawn", "sethome", "home", "delhome", "homes", "restoreinv", "asu", "warp", "setwarp", "delwarp", "warps", "back" }))); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:help", ServerUtilities.config.MaxHomes, ServerUtilities.config.AdminsBypassMaxHomes, ServerUtilities.config.MaxBackCache, string.Join(", ", new string[] { "setspawn", "spawn", "delspawn", "sethome", "home", "delhome", "homes", "restoreinv", "asu", "warp", "setwarp", "delwarp", "warps", "back", "rtp" }))); } internal static TextCommandResult HandleBack(TextCommandCallingArgs args) @@ -39,6 +39,11 @@ namespace AriasServerUtils return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:rmspawn")); } + internal static TextCommandResult HandleRTP(TextCommandCallingArgs args) + { + return TextCommandResult.Success(); + } + internal static TextCommandResult HandleDelHome(TextCommandCallingArgs args) { string homeName = "default"; diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 8b8b488..040407c 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 01-20-2025 @ 12:38 AM MST", - "version": "1.0.4-dev.1", + "description": "A collection of server utilities\n\nBuild Date: 03-06-2025 @ 9:36 AM MST", + "version": "1.0.4-dev.2", "dependencies": { "game": "" } From aedef3317ca0b05988a252776446764a97610f9a Mon Sep 17 00:00:00 2001 From: zontreck Date: Thu, 6 Mar 2025 15:14:01 -0700 Subject: [PATCH 07/58] Add RTP Language entries #2 --- AriasServerUtils/assets/ariasserverutils/lang/en.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index 7116583..eb944c0 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -30,5 +30,10 @@ "warp-list": "There are [{0}] total warps\n\n{1}", "back-no": "There's no position to go back to", - "back": "You've been taken back to your last position" + "back": "You've been taken back to your last position", + + "rtp-search": "Searching for a random position...", + "rtp": "You have been teleported [{0}] blocks away!", + + "cmd-cooldown": "[{0}] is currently on cooldown. You can use this command again in [{1}]" } From 86ff08b9e74adb20981d1193e07c6d014ae93154 Mon Sep 17 00:00:00 2001 From: zontreck Date: Thu, 6 Mar 2025 16:48:41 -0700 Subject: [PATCH 08/58] Implement the rtp function #2 --- AriasServerUtils/ASUModSystem.cs | 9 +++ AriasServerUtils/EventHandler.cs | 31 ++++++++ AriasServerUtils/Globals.cs | 1 + AriasServerUtils/RTPFactory.cs | 71 +++++++++++++++++++ .../assets/ariasserverutils/lang/en.json | 1 + 5 files changed, 113 insertions(+) create mode 100644 AriasServerUtils/RTPFactory.cs diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index 0755aac..b7bc9a2 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using Vintagestory.API.Client; using Vintagestory.API.Common; +using Vintagestory.API.Common.CommandAbbr; using Vintagestory.API.Common.Entities; using Vintagestory.API.Config; using Vintagestory.API.MathTools; @@ -137,6 +138,14 @@ namespace AriasServerUtils .WithDescription("Percentage of players required to sleep before sleeping through the night") .HandleWith(Events.HandleUpdateASUPSP) .EndSubCommand() + .BeginSubCommand("rtp") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs( + parsers.Int("maxDistance") + ) + .WithDescription("Update RTP Max block distance. Plus and/or minus this distance from player current position") + .HandleWith(Events.HandleUpdateASURTPMax) + .EndSubCommand() .EndSubCommand() .BeginSubCommand("help") .RequiresPrivilege(Privilege.chat) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 1df0360..9dcb867 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using Vintagestory.API.Common; using Vintagestory.API.Config; +using Vintagestory.API.MathTools; using Vintagestory.API.Server; namespace AriasServerUtils @@ -41,6 +42,23 @@ namespace AriasServerUtils internal static TextCommandResult HandleRTP(TextCommandCallingArgs args) { + if (args.Caller is IServerPlayer isp) + { + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-search")); + + PlayerPosition pPos = RTPFactory.GetRandomPosition(isp); + if (pPos == null) + { + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail")); + } + Vec2i origin = new((int)isp.Entity.Pos.X, (int)isp.Entity.Pos.Z); + Vec2i npos = new(pPos.X, pPos.Z); + + float distance = RTPFactory.GetDistance(origin, npos); + + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp", distance)); + + } return TextCommandResult.Success(); } @@ -349,5 +367,18 @@ namespace AriasServerUtils return TextCommandResult.Success(); } + + internal static TextCommandResult HandleUpdateASURTPMax(TextCommandCallingArgs args) + { + if (args[0] is int maxDist) + { + ServerUtilities.config.MaxRTPBlockDistance = maxDist; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } + + return TextCommandResult.Success(); + } } } \ No newline at end of file diff --git a/AriasServerUtils/Globals.cs b/AriasServerUtils/Globals.cs index 223b195..98f125c 100644 --- a/AriasServerUtils/Globals.cs +++ b/AriasServerUtils/Globals.cs @@ -18,6 +18,7 @@ namespace AriasServerUtils public bool onlyAdminsCreateWarps { get; set; } = true; public int MaxBackCache { get; set; } = 10; public int PlayerSleepingPercentage { get; set; } = 50; + public int MaxRTPBlockDistance { get; set; } = 5000; public PlayerPosition Spawn { get; set; } diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs new file mode 100644 index 0000000..2018d31 --- /dev/null +++ b/AriasServerUtils/RTPFactory.cs @@ -0,0 +1,71 @@ +using System; +using System.Data; +using System.Numerics; +using AriasServerUtils; +using Vintagestory.API.Common; +using Vintagestory.API.Common.Entities; +using Vintagestory.API.MathTools; +using Vintagestory.API.Server; +using Vintagestory.GameContent; + +public class RTPFactory +{ + /// + /// This function searches for a safe position, honoring the max RTP distance in the global configuration + /// + /// The player to be teleported + /// A random position +/- max distance from current position. + public static PlayerPosition GetRandomPosition(IServerPlayer isp) + { + Random rng = new Random(); + EntityPos vPos = isp.Entity.Pos; + BlockPos bPos = new BlockPos(isp.Entity.Pos.Dimension); + IServerWorldAccessor iswa = isp.Entity.World as IServerWorldAccessor; + + int tries = 5; + PlayerPosition PPos = PlayerPosition.from(isp.Entity); + + while (tries-- > 0) + { + // Generate random X and Z within max RTP distance + bPos.X = (int)vPos.X + rng.Next(-ServerUtilities.config.MaxRTPBlockDistance, ServerUtilities.config.MaxRTPBlockDistance); + bPos.Z = (int)vPos.Z + rng.Next(-ServerUtilities.config.MaxRTPBlockDistance, ServerUtilities.config.MaxRTPBlockDistance); + bPos.Y = 255; + + Block lastAboveLast = null; + Block lastBlock = null; + Block curBlock; + + // Scan downwards to find a valid landing spot + for (int i = 255; i > 50; i--) + { + bPos.Y = i; + curBlock = iswa.BlockAccessor.GetBlock(bPos); + + if (curBlock != null && !curBlock.IsLiquid() && curBlock.MatterState == EnumMatterState.Solid) + { + if (lastBlock != null && lastBlock.MatterState == EnumMatterState.Gas && + lastAboveLast != null && lastAboveLast.MatterState == EnumMatterState.Gas) + { + // Found a valid spot: curBlock is solid, lastBlock & lastAboveLast are gas (air) + PPos.X = bPos.X; + PPos.Y = bPos.Y + 1; + PPos.Z = bPos.Z; + + return PPos; + } + } + + lastAboveLast = lastBlock; + lastBlock = curBlock; + } + } + + return null; // Return null if no valid position is found after retries + } + public static float GetDistance(Vec2i pos1, Vec2i pos2) + { + return MathF.Sqrt(MathF.Pow(pos2.X - pos1.X, 2) + MathF.Pow(pos2.Y - pos1.Y, 2)); + } + +} \ No newline at end of file diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index eb944c0..52606b7 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -34,6 +34,7 @@ "rtp-search": "Searching for a random position...", "rtp": "You have been teleported [{0}] blocks away!", + "rtp-fail": "Giving up on RTP search. No valid position could be found. Try again later", "cmd-cooldown": "[{0}] is currently on cooldown. You can use this command again in [{1}]" } From 51a71fee249234ad06d5e71f89a17bb01893a27d Mon Sep 17 00:00:00 2001 From: zontreck Date: Thu, 6 Mar 2025 16:50:12 -0700 Subject: [PATCH 09/58] Bump dev build number --- AriasServerUtils/modinfo.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 040407c..47deabd 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-06-2025 @ 9:36 AM MST", - "version": "1.0.4-dev.2", + "description": "A collection of server utilities\n\nBuild Date: 03-06-2025 @ 4:49 PM MST", + "version": "1.0.4-dev.4", "dependencies": { "game": "" } From 403f18c0207a34352caceb0cd4c7226235b192aa Mon Sep 17 00:00:00 2001 From: zontreck Date: Thu, 6 Mar 2025 16:55:47 -0700 Subject: [PATCH 10/58] Fix rtp not executing #2 --- AriasServerUtils/EventHandler.cs | 2 +- AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 9dcb867..12a7600 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -42,7 +42,7 @@ namespace AriasServerUtils internal static TextCommandResult HandleRTP(TextCommandCallingArgs args) { - if (args.Caller is IServerPlayer isp) + if (args.Caller.Player is IServerPlayer isp) { ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-search")); diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 47deabd..cee9c46 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-06-2025 @ 4:49 PM MST", - "version": "1.0.4-dev.4", + "description": "A collection of server utilities\n\nBuild Date: 03-06-2025 @ 4:54 PM MST", + "version": "1.0.4-dev.5", "dependencies": { "game": "" } From 7120b4083a4588748ddb379a416d24a76e9943a0 Mon Sep 17 00:00:00 2001 From: zontreck Date: Thu, 6 Mar 2025 16:58:41 -0700 Subject: [PATCH 11/58] Fix a exception that was thrown when running /rtp #2 --- AriasServerUtils/EventHandler.cs | 1 + AriasServerUtils/RTPFactory.cs | 4 ++-- AriasServerUtils/modinfo.json | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 12a7600..eef4ba4 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -50,6 +50,7 @@ namespace AriasServerUtils if (pPos == null) { ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail")); + return TextCommandResult.Success(); } Vec2i origin = new((int)isp.Entity.Pos.X, (int)isp.Entity.Pos.Z); Vec2i npos = new(pPos.X, pPos.Z); diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 2018d31..61bac29 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -22,7 +22,7 @@ public class RTPFactory BlockPos bPos = new BlockPos(isp.Entity.Pos.Dimension); IServerWorldAccessor iswa = isp.Entity.World as IServerWorldAccessor; - int tries = 5; + int tries = 10; PlayerPosition PPos = PlayerPosition.from(isp.Entity); while (tries-- > 0) @@ -37,7 +37,7 @@ public class RTPFactory Block curBlock; // Scan downwards to find a valid landing spot - for (int i = 255; i > 50; i--) + for (int i = 255; i > 25; i--) { bPos.Y = i; curBlock = iswa.BlockAccessor.GetBlock(bPos); diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index cee9c46..306dc32 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-06-2025 @ 4:54 PM MST", - "version": "1.0.4-dev.5", + "description": "A collection of server utilities\n\nBuild Date: 03-06-2025 @ 4:58 PM MST", + "version": "1.0.4-dev.6", "dependencies": { "game": "" } From e53f26717fa5a118345faf2384d7f42caca83efb Mon Sep 17 00:00:00 2001 From: zontreck Date: Thu, 6 Mar 2025 17:13:49 -0700 Subject: [PATCH 12/58] Adjusts the detection of air and solids #2 --- .vscode/launch.json | 16 ++++++++-------- .vscode/settings.json | 2 +- .vscode/tasks.json | 2 +- AriasServerUtils/RTPFactory.cs | 6 +++--- AriasServerUtils/modinfo.json | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index d1cd6d4..26b43b9 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,12 +8,12 @@ "name": "Launch Client (Debug)", "type": "coreclr", "request": "launch", - "program": "${env:VINTAGE_STORY}/Vintagestory.exe", + "program": ".game/Vintagestory.exe", "linux": { - "program": "${env:VINTAGE_STORY}/Vintagestory" + "program": ".game/Vintagestory" }, "osx": { - "program": "${env:VINTAGE_STORY}/Vintagestory" + "program": ".game/Vintagestory" }, "preLaunchTask": "build", "args": [ @@ -21,7 +21,7 @@ // "--openWorld" , "modding test world", "--tracelog", "--addModPath", - "${workspaceFolder}/ModTemplate/bin/Debug/Mods" + "${workspaceFolder}/AriasServerUtils/bin/Debug/Mods" ], "console": "internalConsole", "stopAtEntry": false @@ -30,18 +30,18 @@ "name": "Launch Server", "type": "coreclr", "request": "launch", - "program": "${env:VINTAGE_STORY}/VintagestoryServer.exe", + "program": ".game/VintagestoryServer.exe", "linux": { - "program": "${env:VINTAGE_STORY}/VintagestoryServer" + "program": ".game/VintagestoryServer" }, "osx": { - "program": "${env:VINTAGE_STORY}/VintagestoryServer" + "program": ".game/VintagestoryServer" }, "preLaunchTask": "build", "args": [ "--tracelog", "--addModPath", - "${workspaceFolder}/ModTemplate/bin/Debug/Mods" + "${workspaceFolder}/AriasServerUtils/bin/Debug/Mods" ], "console": "internalConsole", "stopAtEntry": false diff --git a/.vscode/settings.json b/.vscode/settings.json index 3535556..fbe5f0e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,5 @@ { - "dotnet.defaultSolution": "ModTemplate.sln", + "dotnet.defaultSolution": "AriasServerUtils.sln", "files.associations": { "server-*.txt": "log", "client-*.txt": "log" diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 3b7b591..8fe9dac 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -9,7 +9,7 @@ "build", "-c", "Debug", - "${workspaceFolder}/ModTemplate/ModTemplate.csproj" + "${workspaceFolder}/AriasServerUtils/AriasServerUtils.csproj" ], "problemMatcher": "$msCompile" }, diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 61bac29..94a940b 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -42,10 +42,10 @@ public class RTPFactory bPos.Y = i; curBlock = iswa.BlockAccessor.GetBlock(bPos); - if (curBlock != null && !curBlock.IsLiquid() && curBlock.MatterState == EnumMatterState.Solid) + if (curBlock.MatterState == EnumMatterState.Solid) { - if (lastBlock != null && lastBlock.MatterState == EnumMatterState.Gas && - lastAboveLast != null && lastAboveLast.MatterState == EnumMatterState.Gas) + if (lastBlock != null && lastBlock.BlockMaterial == EnumBlockMaterial.Air && + lastAboveLast != null && lastAboveLast.BlockMaterial == EnumBlockMaterial.Air) { // Found a valid spot: curBlock is solid, lastBlock & lastAboveLast are gas (air) PPos.X = bPos.X; diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 306dc32..ed36f42 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-06-2025 @ 4:58 PM MST", - "version": "1.0.4-dev.6", + "description": "A collection of server utilities\n\nBuild Date: 03-06-2025 @ 5:13 PM MST", + "version": "1.0.4-dev.7", "dependencies": { "game": "" } From 107f5027367ff638bb9e5a248f691743447d1b17 Mon Sep 17 00:00:00 2001 From: zontreck Date: Thu, 6 Mar 2025 17:19:40 -0700 Subject: [PATCH 13/58] Fix: #2 - Finish adding /rtp --- AriasServerUtils/EventHandler.cs | 2 ++ AriasServerUtils/RTPFactory.cs | 4 ++-- AriasServerUtils/modinfo.json | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index eef4ba4..8ef9e33 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -57,6 +57,8 @@ namespace AriasServerUtils float distance = RTPFactory.GetDistance(origin, npos); + pPos.Merge(isp.Entity); + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp", distance)); } diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 94a940b..1390eda 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -22,7 +22,7 @@ public class RTPFactory BlockPos bPos = new BlockPos(isp.Entity.Pos.Dimension); IServerWorldAccessor iswa = isp.Entity.World as IServerWorldAccessor; - int tries = 10; + int tries = 100; PlayerPosition PPos = PlayerPosition.from(isp.Entity); while (tries-- > 0) @@ -37,7 +37,7 @@ public class RTPFactory Block curBlock; // Scan downwards to find a valid landing spot - for (int i = 255; i > 25; i--) + for (int i = 255; i > 0; i--) { bPos.Y = i; curBlock = iswa.BlockAccessor.GetBlock(bPos); diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index ed36f42..e73b8ac 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-06-2025 @ 5:13 PM MST", - "version": "1.0.4-dev.7", + "description": "A collection of server utilities\n\nBuild Date: 03-06-2025 @ 5:19 PM MST", + "version": "1.0.4-dev.8", "dependencies": { "game": "" } From 85f728babf8adf779b578c478e0e3531507bfc09 Mon Sep 17 00:00:00 2001 From: zontreck Date: Thu, 6 Mar 2025 18:16:13 -0700 Subject: [PATCH 14/58] Begin adding cooldowns to specific commands --- AriasServerUtils/ASUModSystem.cs | 28 ++++++++++++- AriasServerUtils/EventHandler.cs | 59 ++++++++++++++++++++++++++ AriasServerUtils/Globals.cs | 42 +++++++++++++++++++ AriasServerUtils/PlayerData.cs | 1 + AriasServerUtils/RTPFactory.cs | 1 + AriasServerUtils/TimeUtil.cs | 72 ++++++++++++++++++++++++++++++++ AriasServerUtils/modinfo.json | 4 +- 7 files changed, 204 insertions(+), 3 deletions(-) create mode 100644 AriasServerUtils/TimeUtil.cs diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index b7bc9a2..ad0a547 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -8,6 +8,7 @@ using Vintagestory.API.Common.Entities; using Vintagestory.API.Config; using Vintagestory.API.MathTools; using Vintagestory.API.Server; +using Vintagestory.API.Util; using Vintagestory.GameContent; namespace AriasServerUtils @@ -72,6 +73,7 @@ namespace AriasServerUtils api.Event.ServerRunPhase(EnumServerRunPhase.GameReady, OnGameReady); api.Event.ServerRunPhase(EnumServerRunPhase.Shutdown, OnShutdown); api.Event.Timer(OnCheckModDirty, 20); + api.Event.Timer(OnCheckPlayerCooldowns, 1); api.Event.PlayerDeath += OnPlayerDeath; api.Event.PlayerJoin += OnPlayerJoin; api.Event.PlayerDisconnect += OnPlayerDC; @@ -163,6 +165,27 @@ namespace AriasServerUtils api.ChatCommands.Create("rtp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Seeks a position possibly thousands of blocks away to teleport to.").HandleWith(Events.HandleRTP); } + private void OnCheckPlayerCooldowns() + { + foreach (var cdEntry in ServerUtilities.mPlayerData) + { + List toRemove = new(); + foreach (var cd in cdEntry.Value.ActiveCooldowns) + { + if (cd.Value < TimeUtil.GetUnixEpochTimestamp()) + { + toRemove.Add(cd.Key); + } + } + + foreach (var item in toRemove) + { + cdEntry.Value.ActiveCooldowns.Remove(item); + } + + if (toRemove.Count > 0) MarkDirty(); + } + } public static void NewBackCacheForPlayer(IServerPlayer player) { @@ -290,7 +313,10 @@ namespace AriasServerUtils config = API.LoadModConfig(GetConfigurationFile("global", ModConfigType.Global)); if (config == null) config = new ASUModConfig(); - // -> Step 2. Load Mod Warps <- + // Step 2. Check if there are new or missing cooldowns + config.SanityCheckCooldowns(); + + // -> Step 3. Load Mod Warps <- serverWarps = API.LoadModConfig(GetConfigurationFile("warps", ModConfigType.Global)); if (serverWarps == null) serverWarps = new Warps(); } diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 8ef9e33..5529cf4 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -6,6 +6,7 @@ using Vintagestory.API.Common; using Vintagestory.API.Config; using Vintagestory.API.MathTools; using Vintagestory.API.Server; +using Vintagestory.API.Util; namespace AriasServerUtils { @@ -18,6 +19,12 @@ namespace AriasServerUtils internal static TextCommandResult HandleBack(TextCommandCallingArgs args) { + PlayerStorage ps = ServerUtilities.GetPlayerData(args.Caller.Player as IServerPlayer); + if (ps.ActiveCooldowns.ContainsKey(CooldownType.Back)) + { + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:cmd-cooldown", "/back", TimeUtil.EncodeTimeNotation(ps.ActiveCooldowns.Get(CooldownType.Back) - TimeUtil.GetUnixEpochTimestamp()))); + } + PlayerPosition pos = ServerUtilities.backCaches.ReadAndPopNewestPosition(args.Caller.Player.PlayerName); if (pos == null) { @@ -27,6 +34,9 @@ namespace AriasServerUtils { // Go back to old position pos.Merge(args.Caller.Player.Entity); + ps.ActiveCooldowns.Add(CooldownType.Back, TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.Back)) + TimeUtil.GetUnixEpochTimestamp()); + ServerUtilities.MarkDirty(); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:back")); } @@ -44,8 +54,19 @@ namespace AriasServerUtils { if (args.Caller.Player is IServerPlayer isp) { + + PlayerStorage ps = ServerUtilities.GetPlayerData(isp); + if (ps.ActiveCooldowns.ContainsKey(CooldownType.RTP)) + { + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:cmd-cooldown", "/rtp", TimeUtil.EncodeTimeNotation(ps.ActiveCooldowns.Get(CooldownType.RTP) - TimeUtil.GetUnixEpochTimestamp()))); + } + + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-search")); + ps.ActiveCooldowns.Add(CooldownType.RTP, TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.RTP)) + TimeUtil.GetUnixEpochTimestamp()); + ServerUtilities.MarkDirty(); + PlayerPosition pPos = RTPFactory.GetRandomPosition(isp); if (pPos == null) { @@ -103,6 +124,12 @@ namespace AriasServerUtils if (args.Caller.Player is IServerPlayer isp) { PlayerStorage data = ServerUtilities.GetPlayerData(isp); + if (data.ActiveCooldowns.ContainsKey(CooldownType.Home)) + { + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:cmd-cooldown", "/home", TimeUtil.EncodeTimeNotation(data.ActiveCooldowns.Get(CooldownType.Home) - TimeUtil.GetUnixEpochTimestamp()))); + } + + if (data.Homes.ContainsKey(homeName)) { ServerUtilities.NewBackCacheForPlayer(isp); @@ -114,6 +141,11 @@ namespace AriasServerUtils { ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:home-no")); } + + + + data.ActiveCooldowns.Add(CooldownType.Home, TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.Home)) + TimeUtil.GetUnixEpochTimestamp()); + ServerUtilities.MarkDirty(); } return TextCommandResult.Success(); @@ -219,10 +251,23 @@ namespace AriasServerUtils { if (args.Caller.Player is IServerPlayer isp) { + + PlayerStorage data = ServerUtilities.GetPlayerData(isp); + if (data.ActiveCooldowns.ContainsKey(CooldownType.Spawn)) + { + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:cmd-cooldown", "/spawn", TimeUtil.EncodeTimeNotation(data.ActiveCooldowns.Get(CooldownType.Spawn) - TimeUtil.GetUnixEpochTimestamp()))); + } + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:tp-spawn")); ServerUtilities.NewBackCacheForPlayer(isp); ServerUtilities.config.Spawn.Merge(args.Caller.Player.Entity); + + + + + data.ActiveCooldowns.Add(CooldownType.Spawn, TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.Spawn)) + TimeUtil.GetUnixEpochTimestamp()); + ServerUtilities.MarkDirty(); } } @@ -294,12 +339,26 @@ namespace AriasServerUtils if (args.Caller.Player is IServerPlayer isp) { + PlayerStorage data = ServerUtilities.GetPlayerData(isp); + if (data.ActiveCooldowns.ContainsKey(CooldownType.Warp)) + { + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:cmd-cooldown", "/warp", TimeUtil.EncodeTimeNotation(data.ActiveCooldowns.Get(CooldownType.Warp) - TimeUtil.GetUnixEpochTimestamp()))); + } + + if (ServerUtilities.serverWarps.warps.ContainsKey(name)) { ServerUtilities.NewBackCacheForPlayer(isp); ServerUtilities.serverWarps.warps[name].Location.Merge(isp.Entity); ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:warp-set", name)); + + + + + + data.ActiveCooldowns.Add(CooldownType.Warp, TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.Warp)) + TimeUtil.GetUnixEpochTimestamp()); + ServerUtilities.MarkDirty(); } else { diff --git a/AriasServerUtils/Globals.cs b/AriasServerUtils/Globals.cs index 98f125c..37be46e 100644 --- a/AriasServerUtils/Globals.cs +++ b/AriasServerUtils/Globals.cs @@ -19,11 +19,53 @@ namespace AriasServerUtils public int MaxBackCache { get; set; } = 10; public int PlayerSleepingPercentage { get; set; } = 50; public int MaxRTPBlockDistance { get; set; } = 5000; + public Dictionary Cooldowns { get; set; } = new Dictionary + { + { CooldownType.Home, "5s" }, + { CooldownType.Warp, "10s" }, + { CooldownType.Spawn, "5s" }, + { CooldownType.RTP, "30s" }, + { CooldownType.Back, "5s" } + }; + + public Dictionary GetDefaultCooldowns() + { + return new Dictionary{ + + { CooldownType.Home, "5s" }, + { CooldownType.Warp, "10s" }, + { CooldownType.Spawn, "5s" }, + { CooldownType.RTP, "30s" }, + { CooldownType.Back, "5s" } + }; + } + + public void SanityCheckCooldowns() + { + foreach (var cd in GetDefaultCooldowns()) + { + if (!Cooldowns.ContainsKey(cd.Key)) + { + Cooldowns.Add(cd.Key, cd.Value); + ServerUtilities.MarkDirty(); + } + } + } public PlayerPosition Spawn { get; set; } } + [Serializable] + public enum CooldownType + { + Home, // Default: 5s + Warp, // Default 10s + Spawn, // Default 5s + RTP, // Default 30s + Back // Default 5s + } + [Serializable] public class Warp { diff --git a/AriasServerUtils/PlayerData.cs b/AriasServerUtils/PlayerData.cs index c31560d..baec1b3 100644 --- a/AriasServerUtils/PlayerData.cs +++ b/AriasServerUtils/PlayerData.cs @@ -78,6 +78,7 @@ namespace AriasServerUtils public class PlayerStorage { public Dictionary Homes = new Dictionary(); + public Dictionary ActiveCooldowns = new(); } /// diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 1390eda..ddc1c35 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -8,6 +8,7 @@ using Vintagestory.API.MathTools; using Vintagestory.API.Server; using Vintagestory.GameContent; +namespace AriasServerUtils; public class RTPFactory { /// diff --git a/AriasServerUtils/TimeUtil.cs b/AriasServerUtils/TimeUtil.cs new file mode 100644 index 0000000..aca557e --- /dev/null +++ b/AriasServerUtils/TimeUtil.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Linq; + + +namespace AriasServerUtils +{ + public static class TimeUtil + { + private static readonly Dictionary TimeUnits = new() + { + { 's', 1 }, // seconds + { 'm', 60 }, // minutes + { 'h', 3600 }, // hours + { 'd', 86400 }, // days + { 'w', 604800 }, // weeks + { 'M', 2592000 }, // months (approx. 30 days) + { 'y', 31536000 } // years (365 days) + }; + + public static long DecodeTimeNotation(string input) + { + if (string.IsNullOrWhiteSpace(input)) return 0; + + long totalSeconds = 0; + int number = 0; + + foreach (char c in input) + { + if (char.IsDigit(c)) + { + number = number * 10 + (c - '0'); + } + else if (TimeUnits.TryGetValue(c, out int unitSeconds)) + { + totalSeconds += number * unitSeconds; + number = 0; + } + else + { + throw new FormatException($"Invalid time unit: {c}"); + } + } + + return totalSeconds; + } + + public static string EncodeTimeNotation(long seconds) + { + if (seconds <= 0) return "0s"; + + var result = new List(); + + foreach (var (unit, unitSeconds) in TimeUnits.OrderByDescending(u => u.Value)) + { + long value = seconds / unitSeconds; + if (value > 0) + { + result.Add($"{value}{unit}"); + seconds %= unitSeconds; + } + } + + return string.Join("", result); + } + + public static long GetUnixEpochTimestamp() + { + return DateTimeOffset.UtcNow.ToUnixTimeSeconds(); + } + } +} diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index e73b8ac..ac727a0 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-06-2025 @ 5:19 PM MST", - "version": "1.0.4-dev.8", + "description": "A collection of server utilities\n\nBuild Date: 03-06-2025 @ 6:16 PM MST", + "version": "1.0.4-dev.10", "dependencies": { "game": "" } From 65ec65bfc9115517f9ea52ee26e78120fafbac30 Mon Sep 17 00:00:00 2001 From: zontreck Date: Thu, 6 Mar 2025 18:18:33 -0700 Subject: [PATCH 15/58] Create Release 1.0.4 --- AriasServerUtils/modinfo.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index ac727a0..97ff8fd 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -4,7 +4,7 @@ "name": "Aria's Server Utilities", "authors": ["zontreck"], "description": "A collection of server utilities\n\nBuild Date: 03-06-2025 @ 6:16 PM MST", - "version": "1.0.4-dev.10", + "version": "1.0.4", "dependencies": { "game": "" } From 54e8d8a4d584d2e1f2b698852010acd2d9c9ddcd Mon Sep 17 00:00:00 2001 From: zontreck Date: Thu, 6 Mar 2025 18:39:12 -0700 Subject: [PATCH 16/58] oops, forgot to commit the ASU Update Cooldowns commands --- AriasServerUtils/ASUModSystem.cs | 48 +++++++++ AriasServerUtils/EventHandler.cs | 98 +++++++++++++++++++ AriasServerUtils/Globals.cs | 19 ++-- .../assets/ariasserverutils/lang/en.json | 1 + AriasServerUtils/modinfo.json | 2 +- 5 files changed, 159 insertions(+), 9 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index ad0a547..5921fc8 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -148,6 +148,54 @@ namespace AriasServerUtils .WithDescription("Update RTP Max block distance. Plus and/or minus this distance from player current position") .HandleWith(Events.HandleUpdateASURTPMax) .EndSubCommand() + .BeginSubCommand("cooldowns") + .WithDescription("Commands related to all the various cooldowns") + .BeginSubCommand("back") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs( + parsers.Word("cooldown") + ) + .WithDescription("Updates the cooldown time on /back (Default is 5s)") + .HandleWith(Events.HandleUpdateASUCDBack) + .EndSubCommand() + .BeginSubCommand("warp") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs( + parsers.Word("cooldown") + ) + .WithDescription("Updates the cooldown time on /warp (Default is 10s)") + .HandleWith(Events.HandleUpdateASUCDWarp) + .EndSubCommand() + .BeginSubCommand("home") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs( + parsers.Word("cooldown") + ) + .WithDescription("Updates the cooldown time on /home (Default is 5s)") + .HandleWith(Events.HandleUpdateASUCDHome) + .EndSubCommand() + .BeginSubCommand("spawn") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs( + parsers.Word("cooldown") + ) + .WithDescription("Updates the cooldown time on /spawn (Default is 5s)") + .HandleWith(Events.HandleUpdateASUCDSpawn) + .EndSubCommand() + .BeginSubCommand("rtp") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs( + parsers.Word("cooldown") + ) + .WithDescription("Updates the cooldown time on /rtp (Default is 30s)") + .HandleWith(Events.HandleUpdateASUCDRTP) + .EndSubCommand() + .BeginSubCommand("reset") + .RequiresPrivilege(Privilege.controlserver) + .WithDescription("Resets all cooldowns to default values") + .HandleWith(Events.HandleUpdateASUCDReset) + .EndSubCommand() + .EndSubCommand() .EndSubCommand() .BeginSubCommand("help") .RequiresPrivilege(Privilege.chat) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 5529cf4..9386346 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -442,5 +442,103 @@ namespace AriasServerUtils return TextCommandResult.Success(); } + + internal static TextCommandResult HandleUpdateASUCDBack(TextCommandCallingArgs args) + { + if (args[0] is string CD) + { + ServerUtilities.config.Cooldowns[CooldownType.Back] = CD; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } + else + { + ServerUtilities.config.Cooldowns[CooldownType.Back] = "5s"; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:config-value-reset")); + } + } + + internal static TextCommandResult HandleUpdateASUCDWarp(TextCommandCallingArgs args) + { + if (args[0] is string CD) + { + ServerUtilities.config.Cooldowns[CooldownType.Warp] = CD; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } + else + { + ServerUtilities.config.Cooldowns[CooldownType.Warp] = "10s"; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:config-value-reset")); + } + } + + internal static TextCommandResult HandleUpdateASUCDHome(TextCommandCallingArgs args) + { + if (args[0] is string CD) + { + ServerUtilities.config.Cooldowns[CooldownType.Home] = CD; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } + else + { + ServerUtilities.config.Cooldowns[CooldownType.Home] = "5s"; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:config-value-reset")); + } + } + + internal static TextCommandResult HandleUpdateASUCDSpawn(TextCommandCallingArgs args) + { + if (args[0] is string CD) + { + ServerUtilities.config.Cooldowns[CooldownType.Spawn] = CD; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } + else + { + ServerUtilities.config.Cooldowns[CooldownType.Spawn] = "5s"; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:config-value-reset")); + } + } + + internal static TextCommandResult HandleUpdateASUCDRTP(TextCommandCallingArgs args) + { + if (args[0] is string CD) + { + ServerUtilities.config.Cooldowns[CooldownType.RTP] = CD; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } + else + { + ServerUtilities.config.Cooldowns[CooldownType.RTP] = "30s"; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:config-value-reset")); + } + } + + internal static TextCommandResult HandleUpdateASUCDReset(TextCommandCallingArgs args) + { + ServerUtilities.config.Cooldowns = ServerUtilities.config.GetDefaultCooldowns(); + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:config-value-reset")); + } } } \ No newline at end of file diff --git a/AriasServerUtils/Globals.cs b/AriasServerUtils/Globals.cs index 37be46e..bf1dd29 100644 --- a/AriasServerUtils/Globals.cs +++ b/AriasServerUtils/Globals.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Runtime.ConstrainedExecution; using Vintagestory.API.Server; namespace AriasServerUtils @@ -13,6 +14,15 @@ namespace AriasServerUtils [Serializable] public class ASUModConfig { + private readonly static Dictionary m_defaultCD = new Dictionary{ + + { CooldownType.Home, "5s" }, + { CooldownType.Warp, "10s" }, + { CooldownType.Spawn, "5s" }, + { CooldownType.RTP, "30s" }, + { CooldownType.Back, "5s" } + }; + public int MaxHomes { get; set; } = 20; public bool AdminsBypassMaxHomes { get; set; } = true; public bool onlyAdminsCreateWarps { get; set; } = true; @@ -30,14 +40,7 @@ namespace AriasServerUtils public Dictionary GetDefaultCooldowns() { - return new Dictionary{ - - { CooldownType.Home, "5s" }, - { CooldownType.Warp, "10s" }, - { CooldownType.Spawn, "5s" }, - { CooldownType.RTP, "30s" }, - { CooldownType.Back, "5s" } - }; + return m_defaultCD; } public void SanityCheckCooldowns() diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index 52606b7..5f983f0 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -21,6 +21,7 @@ "help": "All Aria's Server Utilities Commands: \n\nMax Homes: {0}; \nAdmins can bypass max homes: {1}\nMax back positions: {2}\n\n{3}", "updatedconfig": "[ASU] server config updated", + "config-value-reset": "[ASU] server config value reset to default", "warp-tp": "Teleported to warp [{0}]", "warp-set": "Warp [{0}] created!", diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 97ff8fd..4259fac 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,7 +3,7 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-06-2025 @ 6:16 PM MST", + "description": "A collection of server utilities\n\nBuild Date: 03-06-2025 @ 6:37 PM MST", "version": "1.0.4", "dependencies": { "game": "" From a9150cf3226d6d1323fe194bc35ea64672e5c542 Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 01:12:36 -0700 Subject: [PATCH 17/58] Add max distance argument to rtp --- AriasServerUtils/ASUModSystem.cs | 2 +- AriasServerUtils/EventHandler.cs | 11 ++++++++++- AriasServerUtils/RTPFactory.cs | 9 ++++++--- AriasServerUtils/assets/ariasserverutils/lang/en.json | 1 + AriasServerUtils/modinfo.json | 4 ++-- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index 5921fc8..bdefbaf 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -210,7 +210,7 @@ namespace AriasServerUtils api.ChatCommands.Create("back").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Returns you to the last location you were at").HandleWith(Events.HandleBack); - api.ChatCommands.Create("rtp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Seeks a position possibly thousands of blocks away to teleport to.").HandleWith(Events.HandleRTP); + api.ChatCommands.Create("rtp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithArgs(parsers.Int("maxDist")).WithDescription("Seeks a position possibly thousands of blocks away to teleport to.").HandleWith(Events.HandleRTP); } private void OnCheckPlayerCooldowns() diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 9386346..f74b377 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -54,6 +54,15 @@ namespace AriasServerUtils { if (args.Caller.Player is IServerPlayer isp) { + int maxDistance = ServerUtilities.config.MaxRTPBlockDistance; + if (args[0] is int ix) + { + if (ix > maxDistance) + { + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-capped", ix, maxDistance)); + } + else maxDistance = ix; + } PlayerStorage ps = ServerUtilities.GetPlayerData(isp); if (ps.ActiveCooldowns.ContainsKey(CooldownType.RTP)) @@ -67,7 +76,7 @@ namespace AriasServerUtils ps.ActiveCooldowns.Add(CooldownType.RTP, TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.RTP)) + TimeUtil.GetUnixEpochTimestamp()); ServerUtilities.MarkDirty(); - PlayerPosition pPos = RTPFactory.GetRandomPosition(isp); + PlayerPosition pPos = RTPFactory.GetRandomPosition(isp, maxDistance: maxDistance); if (pPos == null) { ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail")); diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index ddc1c35..8e70256 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -16,7 +16,7 @@ public class RTPFactory /// /// The player to be teleported /// A random position +/- max distance from current position. - public static PlayerPosition GetRandomPosition(IServerPlayer isp) + public static PlayerPosition GetRandomPosition(IServerPlayer isp, int maxDistance) { Random rng = new Random(); EntityPos vPos = isp.Entity.Pos; @@ -29,10 +29,13 @@ public class RTPFactory while (tries-- > 0) { // Generate random X and Z within max RTP distance - bPos.X = (int)vPos.X + rng.Next(-ServerUtilities.config.MaxRTPBlockDistance, ServerUtilities.config.MaxRTPBlockDistance); - bPos.Z = (int)vPos.Z + rng.Next(-ServerUtilities.config.MaxRTPBlockDistance, ServerUtilities.config.MaxRTPBlockDistance); + bPos.X = (int)vPos.X + rng.Next(0, maxDistance); + bPos.Z = (int)vPos.Z + rng.Next(0, maxDistance); bPos.Y = 255; + if (rng.Next(0, 1) == 1) bPos.X = -bPos.X; + if (rng.Next(0, 1) == 1) bPos.Z = -bPos.Z; + Block lastAboveLast = null; Block lastBlock = null; Block curBlock; diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index 5f983f0..4498f90 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -36,6 +36,7 @@ "rtp-search": "Searching for a random position...", "rtp": "You have been teleported [{0}] blocks away!", "rtp-fail": "Giving up on RTP search. No valid position could be found. Try again later", + "rtp-capped": "The distance you tried to go [{0}] is greater than the maximum allowable by the server [{1}]", "cmd-cooldown": "[{0}] is currently on cooldown. You can use this command again in [{1}]" } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 4259fac..028e657 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-06-2025 @ 6:37 PM MST", - "version": "1.0.4", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 00:52 AM MST", + "version": "1.0.5-dev.1", "dependencies": { "game": "" } From 9f7edc64c380b46c0c886534a06539987d060cb6 Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 01:16:03 -0700 Subject: [PATCH 18/58] Make max distance arg optional --- AriasServerUtils/ASUModSystem.cs | 2 +- AriasServerUtils/EventHandler.cs | 1 + AriasServerUtils/modinfo.json | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index bdefbaf..f52be58 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -210,7 +210,7 @@ namespace AriasServerUtils api.ChatCommands.Create("back").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Returns you to the last location you were at").HandleWith(Events.HandleBack); - api.ChatCommands.Create("rtp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithArgs(parsers.Int("maxDist")).WithDescription("Seeks a position possibly thousands of blocks away to teleport to.").HandleWith(Events.HandleRTP); + api.ChatCommands.Create("rtp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithArgs(parsers.OptionalInt("maxDist", defaultValue: -1)).WithDescription("Seeks a position possibly thousands of blocks away to teleport to.").HandleWith(Events.HandleRTP); } private void OnCheckPlayerCooldowns() diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index f74b377..740276f 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -57,6 +57,7 @@ namespace AriasServerUtils int maxDistance = ServerUtilities.config.MaxRTPBlockDistance; if (args[0] is int ix) { + if (ix == -1) ix = maxDistance; if (ix > maxDistance) { ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-capped", ix, maxDistance)); diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 028e657..aed5cbf 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 00:52 AM MST", - "version": "1.0.5-dev.1", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 1:15 AM MST", + "version": "1.0.5-dev.2", "dependencies": { "game": "" } From 2efa5320598cbd01044f560006412fa274a6598d Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 01:18:05 -0700 Subject: [PATCH 19/58] Increase max RTP tries --- AriasServerUtils/RTPFactory.cs | 2 +- AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 8e70256..ad91bff 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -23,7 +23,7 @@ public class RTPFactory BlockPos bPos = new BlockPos(isp.Entity.Pos.Dimension); IServerWorldAccessor iswa = isp.Entity.World as IServerWorldAccessor; - int tries = 100; + int tries = 1000; PlayerPosition PPos = PlayerPosition.from(isp.Entity); while (tries-- > 0) diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index aed5cbf..441bda3 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 1:15 AM MST", - "version": "1.0.5-dev.2", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 1:17 AM MST", + "version": "1.0.5-dev.3", "dependencies": { "game": "" } From a3eee94f7e9fce92e05c52f18d38730cfe7385fe Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 01:22:25 -0700 Subject: [PATCH 20/58] Include a version number in config, to track if it needs automatic migrations. --- AriasServerUtils/ASUModSystem.cs | 4 ++-- AriasServerUtils/Globals.cs | 20 +++++++++++--------- AriasServerUtils/modinfo.json | 4 ++-- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index f52be58..c688363 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -361,8 +361,8 @@ namespace AriasServerUtils config = API.LoadModConfig(GetConfigurationFile("global", ModConfigType.Global)); if (config == null) config = new ASUModConfig(); - // Step 2. Check if there are new or missing cooldowns - config.SanityCheckCooldowns(); + // Step 2. Check if config needs Migrations + config.SanityCheck(); // -> Step 3. Load Mod Warps <- serverWarps = API.LoadModConfig(GetConfigurationFile("warps", ModConfigType.Global)); diff --git a/AriasServerUtils/Globals.cs b/AriasServerUtils/Globals.cs index bf1dd29..1b8af8c 100644 --- a/AriasServerUtils/Globals.cs +++ b/AriasServerUtils/Globals.cs @@ -22,28 +22,24 @@ namespace AriasServerUtils { CooldownType.RTP, "30s" }, { CooldownType.Back, "5s" } }; + private static readonly int CURRENT_VERSION = 3; + + public int Version { get; set; } = 0; public int MaxHomes { get; set; } = 20; public bool AdminsBypassMaxHomes { get; set; } = true; public bool onlyAdminsCreateWarps { get; set; } = true; public int MaxBackCache { get; set; } = 10; public int PlayerSleepingPercentage { get; set; } = 50; public int MaxRTPBlockDistance { get; set; } = 5000; - public Dictionary Cooldowns { get; set; } = new Dictionary - { - { CooldownType.Home, "5s" }, - { CooldownType.Warp, "10s" }, - { CooldownType.Spawn, "5s" }, - { CooldownType.RTP, "30s" }, - { CooldownType.Back, "5s" } - }; + public Dictionary Cooldowns { get; set; } = new Dictionary(); public Dictionary GetDefaultCooldowns() { return m_defaultCD; } - public void SanityCheckCooldowns() + public void SanityCheck() { foreach (var cd in GetDefaultCooldowns()) { @@ -53,6 +49,12 @@ namespace AriasServerUtils ServerUtilities.MarkDirty(); } } + + if (Version < CURRENT_VERSION) + { + Version = CURRENT_VERSION; + ServerUtilities.MarkDirty(); // This is here to ensure that the config gets saved when there is a update. Whenever a new field is added to config, the CURRENT_VERSION should get bumped so that this SanityCheck can properly work + } } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 441bda3..b0c8d9b 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 1:17 AM MST", - "version": "1.0.5-dev.3", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 1:21 AM MST", + "version": "1.0.5-dev.4", "dependencies": { "game": "" } From 67df350a04bc6f039f2de1853da608ee34e2c1cb Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 01:26:45 -0700 Subject: [PATCH 21/58] For failed RTP, cooldown is half the cooldown time. --- AriasServerUtils/EventHandler.cs | 9 +++++++-- AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 740276f..134c08d 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -74,12 +74,13 @@ namespace AriasServerUtils ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-search")); - ps.ActiveCooldowns.Add(CooldownType.RTP, TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.RTP)) + TimeUtil.GetUnixEpochTimestamp()); - ServerUtilities.MarkDirty(); PlayerPosition pPos = RTPFactory.GetRandomPosition(isp, maxDistance: maxDistance); if (pPos == null) { + ps.ActiveCooldowns.Add(CooldownType.RTP, (TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.RTP)) / 2) + TimeUtil.GetUnixEpochTimestamp()); + ServerUtilities.MarkDirty(); + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail")); return TextCommandResult.Success(); } @@ -90,6 +91,10 @@ namespace AriasServerUtils pPos.Merge(isp.Entity); + + ps.ActiveCooldowns.Add(CooldownType.RTP, TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.RTP)) + TimeUtil.GetUnixEpochTimestamp()); + ServerUtilities.MarkDirty(); + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp", distance)); } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index b0c8d9b..870a2ef 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 1:21 AM MST", - "version": "1.0.5-dev.4", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 1:26 AM MST", + "version": "1.0.5-dev.5", "dependencies": { "game": "" } From f86030dc61943d3d235977ab825dd4222ba3b4a4 Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 01:28:53 -0700 Subject: [PATCH 22/58] Release 1.0.5 --- AriasServerUtils/modinfo.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 870a2ef..2036aac 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 1:26 AM MST", - "version": "1.0.5-dev.5", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 1:28 AM MST", + "version": "1.0.5", "dependencies": { "game": "" } From cd00e620c3d2994b33811f4477c855986e45a16e Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 01:44:27 -0700 Subject: [PATCH 23/58] Begin to add the admin bypass cooldown option --- AriasServerUtils/ASUModSystem.cs | 8 ++++++++ AriasServerUtils/EventHandler.cs | 12 ++++++++++++ AriasServerUtils/Globals.cs | 3 ++- AriasServerUtils/modinfo.json | 4 ++-- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index c688363..b37da69 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -124,6 +124,14 @@ namespace AriasServerUtils .WithDescription("DANGER: This updates the flag allowing anybody to create warps, even non-admins. It is recommended to leave this alone. The default is true/on/yes") .HandleWith(Events.HandleUpdateASUMgrWarps) .EndSubCommand() + .BeginSubCommand("adminBypassCooldown") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs( + parsers.Bool("bypass") + ) + .WithDescription("This flag controls whether admins can or can not bypass the cooldown system") + .HandleWith(Events.HandleUpdateASUBypassCD) + .EndSubCommand() .BeginSubCommand("maxback") .RequiresPrivilege(Privilege.controlserver) .WithArgs( diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 134c08d..05da76e 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -555,5 +555,17 @@ namespace AriasServerUtils return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:config-value-reset")); } + + internal static TextCommandResult HandleUpdateASUBypassCD(TextCommandCallingArgs args) + { + if (args[0] is bool bypass) + { + // Update the bypass + ServerUtilities.config.AdminsBypassCooldowns = bypass; + ServerUtilities.MarkDirty(); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } + else return TextCommandResult.Success(); + } } } \ No newline at end of file diff --git a/AriasServerUtils/Globals.cs b/AriasServerUtils/Globals.cs index 1b8af8c..cd10039 100644 --- a/AriasServerUtils/Globals.cs +++ b/AriasServerUtils/Globals.cs @@ -22,13 +22,14 @@ namespace AriasServerUtils { CooldownType.RTP, "30s" }, { CooldownType.Back, "5s" } }; - private static readonly int CURRENT_VERSION = 3; + private static readonly int CURRENT_VERSION = 4; public int Version { get; set; } = 0; public int MaxHomes { get; set; } = 20; public bool AdminsBypassMaxHomes { get; set; } = true; public bool onlyAdminsCreateWarps { get; set; } = true; + public bool AdminsBypassCooldowns { get; set; } = true; public int MaxBackCache { get; set; } = 10; public int PlayerSleepingPercentage { get; set; } = 50; public int MaxRTPBlockDistance { get; set; } = 5000; diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 2036aac..ea0a11d 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 1:28 AM MST", - "version": "1.0.5", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 1:44 AM MST", + "version": "1.0.6-dev.1", "dependencies": { "game": "" } From 700de94ffe2ad610a67e017e934e3d665c961d74 Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 11:49:59 -0700 Subject: [PATCH 24/58] Admins can now bypass cooldowns --- AriasServerUtils/ASUModSystem.cs | 7 +++++++ AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index b37da69..a2eb075 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using Vintagestory.API.Client; using Vintagestory.API.Common; using Vintagestory.API.Common.CommandAbbr; @@ -225,6 +226,12 @@ namespace AriasServerUtils { foreach (var cdEntry in ServerUtilities.mPlayerData) { + // Obtain the IServerPlayer instance for this player. + IServerPlayer player = API.Server.Players.First(x => x.PlayerName == cdEntry.Key); + if (player.HasPrivilege(Privilege.controlserver) && ServerUtilities.config.AdminsBypassCooldowns) + { + cdEntry.Value.ActiveCooldowns.Clear(); // Problem solved. + } List toRemove = new(); foreach (var cd in cdEntry.Value.ActiveCooldowns) { diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index ea0a11d..aa3c197 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 1:44 AM MST", - "version": "1.0.6-dev.1", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 11:49 AM MST", + "version": "1.0.6-dev.2", "dependencies": { "game": "" } From c5c605d057128af7b8f84c0cf2d40d92727a1db0 Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 11:53:57 -0700 Subject: [PATCH 25/58] Allow admins to bypass the max rtp distance --- AriasServerUtils/ASUModSystem.cs | 8 ++++++++ AriasServerUtils/EventHandler.cs | 12 ++++++++++++ AriasServerUtils/Globals.cs | 5 +++-- AriasServerUtils/modinfo.json | 4 ++-- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index a2eb075..6da73de 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -133,6 +133,14 @@ namespace AriasServerUtils .WithDescription("This flag controls whether admins can or can not bypass the cooldown system") .HandleWith(Events.HandleUpdateASUBypassCD) .EndSubCommand() + .BeginSubCommand("adminsBypassRTPMaxDist") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs( + parsers.Bool("bypass") + ) + .WithDescription("This flag would allow admins to go further than the max server RTP distance when manually specifying a distance to RTP") + .HandleWith(Events.HandleUpdateASUBypassRTPMaxDist) + .EndSubCommand() .BeginSubCommand("maxback") .RequiresPrivilege(Privilege.controlserver) .WithArgs( diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 05da76e..4bc6020 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -567,5 +567,17 @@ namespace AriasServerUtils } else return TextCommandResult.Success(); } + + internal static TextCommandResult HandleUpdateASUBypassRTPMaxDist(TextCommandCallingArgs args) + { + if (args[0] is bool bypass) + { + // Update the flag + ServerUtilities.config.AdminsBypassRTPMaxDistance = bypass; + ServerUtilities.MarkDirty(); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } + else return TextCommandResult.Success(); + } } } \ No newline at end of file diff --git a/AriasServerUtils/Globals.cs b/AriasServerUtils/Globals.cs index cd10039..a98b5cc 100644 --- a/AriasServerUtils/Globals.cs +++ b/AriasServerUtils/Globals.cs @@ -22,7 +22,7 @@ namespace AriasServerUtils { CooldownType.RTP, "30s" }, { CooldownType.Back, "5s" } }; - private static readonly int CURRENT_VERSION = 4; + private static readonly int CURRENT_VERSION = 5; public int Version { get; set; } = 0; @@ -30,9 +30,10 @@ namespace AriasServerUtils public bool AdminsBypassMaxHomes { get; set; } = true; public bool onlyAdminsCreateWarps { get; set; } = true; public bool AdminsBypassCooldowns { get; set; } = true; + public bool AdminsBypassRTPMaxDistance { get; set; } = false; public int MaxBackCache { get; set; } = 10; public int PlayerSleepingPercentage { get; set; } = 50; - public int MaxRTPBlockDistance { get; set; } = 5000; + public int MaxRTPBlockDistance { get; set; } = 50000; public Dictionary Cooldowns { get; set; } = new Dictionary(); public Dictionary GetDefaultCooldowns() diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index aa3c197..f4b8f54 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 11:49 AM MST", - "version": "1.0.6-dev.2", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 11:53 AM MST", + "version": "1.0.6-dev.3", "dependencies": { "game": "" } From 29cf4e21b779da6fcd8de00a1dba7579d50fd584 Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 12:05:04 -0700 Subject: [PATCH 26/58] Add a command to list cooldown settings and all active command cooldowns for the current player --- AriasServerUtils/ASUModSystem.cs | 8 +++++--- AriasServerUtils/EventHandler.cs | 22 +++++++++++++++++++++- AriasServerUtils/modinfo.json | 4 ++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index 6da73de..c808b5a 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -130,7 +130,7 @@ namespace AriasServerUtils .WithArgs( parsers.Bool("bypass") ) - .WithDescription("This flag controls whether admins can or can not bypass the cooldown system") + .WithDescription("This flag controls whether admins can or can not bypass the cooldown system (Default: true)") .HandleWith(Events.HandleUpdateASUBypassCD) .EndSubCommand() .BeginSubCommand("adminsBypassRTPMaxDist") @@ -138,7 +138,7 @@ namespace AriasServerUtils .WithArgs( parsers.Bool("bypass") ) - .WithDescription("This flag would allow admins to go further than the max server RTP distance when manually specifying a distance to RTP") + .WithDescription("This flag would allow admins to go further than the max server RTP distance when manually specifying a distance to RTP (Default: false)") .HandleWith(Events.HandleUpdateASUBypassRTPMaxDist) .EndSubCommand() .BeginSubCommand("maxback") @@ -162,7 +162,7 @@ namespace AriasServerUtils .WithArgs( parsers.Int("maxDistance") ) - .WithDescription("Update RTP Max block distance. Plus and/or minus this distance from player current position") + .WithDescription("Update RTP Max block distance. Plus and/or minus this distance from player current position (Default is 50000)") .HandleWith(Events.HandleUpdateASURTPMax) .EndSubCommand() .BeginSubCommand("cooldowns") @@ -228,6 +228,8 @@ namespace AriasServerUtils api.ChatCommands.Create("back").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Returns you to the last location you were at").HandleWith(Events.HandleBack); api.ChatCommands.Create("rtp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithArgs(parsers.OptionalInt("maxDist", defaultValue: -1)).WithDescription("Seeks a position possibly thousands of blocks away to teleport to.").HandleWith(Events.HandleRTP); + + api.ChatCommands.Create("listcooldowns").RequiresPrivilege(Privilege.chat).WithDescription("Lists the cooldown settings on the server, as well as your own active cooldowns if applicable.").HandleWith(Events.HandleListCooldowns); } private void OnCheckPlayerCooldowns() diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 4bc6020..0cfc261 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -14,7 +14,7 @@ namespace AriasServerUtils { internal static TextCommandResult HandleASU(TextCommandCallingArgs args) { - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:help", ServerUtilities.config.MaxHomes, ServerUtilities.config.AdminsBypassMaxHomes, ServerUtilities.config.MaxBackCache, string.Join(", ", new string[] { "setspawn", "spawn", "delspawn", "sethome", "home", "delhome", "homes", "restoreinv", "asu", "warp", "setwarp", "delwarp", "warps", "back", "rtp" }))); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:help", ServerUtilities.config.MaxHomes, ServerUtilities.config.AdminsBypassMaxHomes, ServerUtilities.config.MaxBackCache, string.Join(", ", new string[] { "setspawn", "spawn", "delspawn", "sethome", "home", "delhome", "homes", "restoreinv", "asu", "warp", "setwarp", "delwarp", "warps", "back", "rtp", "listcooldowns" }))); } internal static TextCommandResult HandleBack(TextCommandCallingArgs args) @@ -579,5 +579,25 @@ namespace AriasServerUtils } else return TextCommandResult.Success(); } + + internal static TextCommandResult HandleListCooldowns(TextCommandCallingArgs args) + { + string sReturn = "SERVER COOLDOWN SETTINGS\n"; + foreach (var cd in ServerUtilities.config.Cooldowns) + { + sReturn += $"{cd.Key}: {cd.Value}\n"; + } + if (args.Caller.Player is IServerPlayer isp) + { + sReturn += "\nYour active cooldowns:"; + foreach (var cd in ServerUtilities.GetPlayerData(isp).ActiveCooldowns) + { + long remain = cd.Value - TimeUtil.GetUnixEpochTimestamp(); + string sCDVal = TimeUtil.EncodeTimeNotation(remain); + sReturn += $"{cd.Key}: {sCDVal}\n"; + } + } + return TextCommandResult.Success(sReturn); + } } } \ No newline at end of file diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index f4b8f54..c9e0d43 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 11:53 AM MST", - "version": "1.0.6-dev.3", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 12:04 PM MST", + "version": "1.0.6-dev.4", "dependencies": { "game": "" } From 1b6586c9e85a54d133e4796a4f7b5a7ea9b67a3d Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 12:19:34 -0700 Subject: [PATCH 27/58] Fix rtp so that admins can bypass max distance --- AriasServerUtils/EventHandler.cs | 2 +- AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 0cfc261..8a57802 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -58,7 +58,7 @@ namespace AriasServerUtils if (args[0] is int ix) { if (ix == -1) ix = maxDistance; - if (ix > maxDistance) + if (ix > maxDistance && !(ServerUtilities.config.AdminsBypassRTPMaxDistance && isp.HasPrivilege(Privilege.controlserver))) { ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-capped", ix, maxDistance)); } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index c9e0d43..b5af4c0 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 12:04 PM MST", - "version": "1.0.6-dev.4", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 12:09 PM MST", + "version": "1.0.6-dev.5", "dependencies": { "game": "" } From 2f1ac319de74742e64a87aafb352482af3a7eedb Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 12:23:08 -0700 Subject: [PATCH 28/58] Properly fix the rtp position calculator --- AriasServerUtils/RTPFactory.cs | 14 ++++++++------ AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index ad91bff..3f200a6 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -28,13 +28,15 @@ public class RTPFactory while (tries-- > 0) { - // Generate random X and Z within max RTP distance - bPos.X = (int)vPos.X + rng.Next(0, maxDistance); - bPos.Z = (int)vPos.Z + rng.Next(0, maxDistance); - bPos.Y = 255; + int ixMax = (int)vPos.X + maxDistance; + int ixMin = (int)vPos.X - maxDistance; + int izMax = (int)vPos.Z + maxDistance; + int izMin = (int)vPos.Z - maxDistance; - if (rng.Next(0, 1) == 1) bPos.X = -bPos.X; - if (rng.Next(0, 1) == 1) bPos.Z = -bPos.Z; + // Generate random X and Z within max RTP distance + bPos.X = (int)vPos.X + rng.Next(ixMin, ixMax); + bPos.Z = (int)vPos.Z + rng.Next(izMin, izMax); + bPos.Y = 255; Block lastAboveLast = null; Block lastBlock = null; diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index b5af4c0..4626e83 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 12:09 PM MST", - "version": "1.0.6-dev.5", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 12:20 PM MST", + "version": "1.0.6-dev.6", "dependencies": { "game": "" } From 70fe822b0a57e508cb561310c2649a464159ad98 Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 12:27:07 -0700 Subject: [PATCH 29/58] Fixes rng to use a seed --- AriasServerUtils/ASUModSystem.cs | 1 + AriasServerUtils/RTPFactory.cs | 2 +- AriasServerUtils/modinfo.json | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index c808b5a..9a44786 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -27,6 +27,7 @@ namespace AriasServerUtils internal static BackCaches backCaches = new BackCaches(); internal static Warps serverWarps = new Warps(); + internal static Random rng = new Random((int)TimeUtil.GetUnixEpochTimestamp()); internal static string[] saveInvTypes = new string[] { diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 3f200a6..8b27e92 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -18,7 +18,7 @@ public class RTPFactory /// A random position +/- max distance from current position. public static PlayerPosition GetRandomPosition(IServerPlayer isp, int maxDistance) { - Random rng = new Random(); + Random rng = ServerUtilities.rng; EntityPos vPos = isp.Entity.Pos; BlockPos bPos = new BlockPos(isp.Entity.Pos.Dimension); IServerWorldAccessor iswa = isp.Entity.World as IServerWorldAccessor; diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 4626e83..82c5df4 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 12:20 PM MST", - "version": "1.0.6-dev.6", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 12:25 PM MST", + "version": "1.0.6-dev.7", "dependencies": { "game": "" } From 89e483521670625ceb09003672cd124d7b620d99 Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 14:10:41 -0700 Subject: [PATCH 30/58] Begin refactoring RTP --- AriasServerUtils/ASUModSystem.cs | 3 +- AriasServerUtils/EventHandler.cs | 24 +-- AriasServerUtils/RTPFactory.cs | 141 +++++++++++++++++- .../assets/ariasserverutils/lang/en.json | 1 + AriasServerUtils/modinfo.json | 4 +- 5 files changed, 146 insertions(+), 27 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index 9a44786..84c74af 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -18,7 +18,7 @@ namespace AriasServerUtils { public static string MOD_ID = "ariasserverutils"; public static ASUModConfig config = new ASUModConfig(); - private static ICoreServerAPI API; + internal static ICoreServerAPI API; private static bool bDirty = false; internal static Dictionary backupInventory = new Dictionary(); @@ -79,6 +79,7 @@ namespace AriasServerUtils api.Event.PlayerDeath += OnPlayerDeath; api.Event.PlayerJoin += OnPlayerJoin; api.Event.PlayerDisconnect += OnPlayerDC; + api.Event.ChunkColumnLoaded += RTPFactory.ChunkColumnGenerated; //api.Event.PlayerLeave += OnPlayerDC; diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 8a57802..1b5a646 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -74,29 +74,7 @@ namespace AriasServerUtils ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-search")); - - PlayerPosition pPos = RTPFactory.GetRandomPosition(isp, maxDistance: maxDistance); - if (pPos == null) - { - ps.ActiveCooldowns.Add(CooldownType.RTP, (TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.RTP)) / 2) + TimeUtil.GetUnixEpochTimestamp()); - ServerUtilities.MarkDirty(); - - ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail")); - return TextCommandResult.Success(); - } - Vec2i origin = new((int)isp.Entity.Pos.X, (int)isp.Entity.Pos.Z); - Vec2i npos = new(pPos.X, pPos.Z); - - float distance = RTPFactory.GetDistance(origin, npos); - - pPos.Merge(isp.Entity); - - - ps.ActiveCooldowns.Add(CooldownType.RTP, TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.RTP)) + TimeUtil.GetUnixEpochTimestamp()); - ServerUtilities.MarkDirty(); - - ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp", distance)); - + RTPFactory.TryRTP(isp, maxDistance: maxDistance); } return TextCommandResult.Success(); } diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 8b27e92..42c0b51 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -1,9 +1,11 @@ using System; +using System.Collections.Generic; using System.Data; using System.Numerics; using AriasServerUtils; using Vintagestory.API.Common; using Vintagestory.API.Common.Entities; +using Vintagestory.API.Config; using Vintagestory.API.MathTools; using Vintagestory.API.Server; using Vintagestory.GameContent; @@ -11,6 +13,33 @@ using Vintagestory.GameContent; namespace AriasServerUtils; public class RTPFactory { + + private static List RTPCache = new(); + + /* + if (pPos == null) + { + ps.ActiveCooldowns.Add(CooldownType.RTP, (TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.RTP)) / 2) + TimeUtil.GetUnixEpochTimestamp()); + ServerUtilities.MarkDirty(); + + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail")); + return TextCommandResult.Success(); + } + Vec2i origin = new((int)isp.Entity.Pos.X, (int)isp.Entity.Pos.Z); + Vec2i npos = new(pPos.X, pPos.Z); + + float distance = RTPFactory.GetDistance(origin, npos); + + pPos.Merge(isp.Entity); + + + ps.ActiveCooldowns.Add(CooldownType.RTP, TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.RTP)) + TimeUtil.GetUnixEpochTimestamp()); + ServerUtilities.MarkDirty(); + + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp", distance)); + + */ + /// /// This function searches for a safe position, honoring the max RTP distance in the global configuration /// @@ -23,8 +52,9 @@ public class RTPFactory BlockPos bPos = new BlockPos(isp.Entity.Pos.Dimension); IServerWorldAccessor iswa = isp.Entity.World as IServerWorldAccessor; - int tries = 1000; + int tries = 10000; PlayerPosition PPos = PlayerPosition.from(isp.Entity); + PlayerPosition original = PlayerPosition.from(isp.Entity); while (tries-- > 0) { @@ -41,11 +71,38 @@ public class RTPFactory Block lastAboveLast = null; Block lastBlock = null; Block curBlock; + // Ensure the chunk is loaded before accessing blocks + int chunkX = bPos.X / 32; + int chunkY = bPos.Y / 32; + int chunkZ = bPos.Z / 32; + var chunk = iswa.ChunkProvider.GetUnpackedChunkFast(chunkX, chunkY, chunkZ); + + if (chunk == null) + { + // Chunk doesn't exist, or isn't loaded. + // Teleport the player to the position up in the sky. That way the chunk does get loaded and we can proceed. + PPos.X = bPos.X; + PPos.Y = bPos.Y; + PPos.Z = bPos.Z; + + PPos.Merge(isp.Entity); + } // Scan downwards to find a valid landing spot for (int i = 255; i > 0; i--) { bPos.Y = i; + if (i / 32 != chunkY) + { + chunkY = i / 32; + chunk = iswa.ChunkProvider.GetUnpackedChunkFast(chunkX, chunkY, chunkZ); + if (chunk == null) + { + + PPos.Y = i; + PPos.Merge(isp.Entity); + } + } curBlock = iswa.BlockAccessor.GetBlock(bPos); if (curBlock.MatterState == EnumMatterState.Solid) @@ -58,6 +115,8 @@ public class RTPFactory PPos.Y = bPos.Y + 1; PPos.Z = bPos.Z; + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-found", tries)); + return PPos; } } @@ -67,11 +126,91 @@ public class RTPFactory } } + original.Merge(isp.Entity); + return null; // Return null if no valid position is found after retries } + + /// + /// This function will schedule a task to perform an RTP. + /// + /// Player to be teleported + /// Max distance +/- the current position. + public static void TryRTP(IServerPlayer isp, int maxDistance) + { + var data = new RTPData(isp, maxDistance, 1000, PlayerPosition.from(isp)); + RTPCache.Add(data); + } + public static float GetDistance(Vec2i pos1, Vec2i pos2) { return MathF.Sqrt(MathF.Pow(pos2.X - pos1.X, 2) + MathF.Pow(pos2.Y - pos1.Y, 2)); } + internal static void ChunkColumnGenerated(Vec2i chunkCoord, IWorldChunk[] chunks) + { + throw new NotImplementedException(); + } +} + +public class RTPData +{ + public IServerPlayer player; + public int NumTriesRemaining; + public int MaxDistance; + public PlayerPosition StartPosition; + + public RTPData(IServerPlayer isp, int maxDistance, int tries, PlayerPosition playerPosition) + { + MaxDistance = maxDistance; + player = isp; + NumTriesRemaining = tries; + StartPosition = playerPosition; + } + + public RTPPosition MakeNewPosition() + { + NumTriesRemaining--; + + return new RTPPosition((int)player.Entity.Pos.X, (int)player.Entity.Pos.Z, MaxDistance, player.Entity.Pos.Dimension); + } +} + +public class RTPPosition +{ + int x; + int y; + int z; + + int dimension; + + public RTPPosition(int x, int z, int maxDist, int dim) + { + int minX = x - maxDist; + int maxX = x + maxDist; + int minZ = z - maxDist; + int maxZ = z + maxDist; + + this.x = ServerUtilities.rng.Next(minX, maxX); + this.y = 1; + this.z = ServerUtilities.rng.Next(minZ, maxZ); + + this.dimension = dim; + } + + PlayerPosition GetPlayerPosition() + { + return new PlayerPosition + { + X = x, + Y = y, + Dimension = dimension, + Z = z + }; + } + + BlockPos GetBlockPos() + { + return new BlockPos(new Vec3i(x, y, z), dimension); + } } \ No newline at end of file diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index 4498f90..cda0fee 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -35,6 +35,7 @@ "rtp-search": "Searching for a random position...", "rtp": "You have been teleported [{0}] blocks away!", + "rtp-found": "Found a valid landing position after {0} tries.", "rtp-fail": "Giving up on RTP search. No valid position could be found. Try again later", "rtp-capped": "The distance you tried to go [{0}] is greater than the maximum allowable by the server [{1}]", diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 82c5df4..3cf221e 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 12:25 PM MST", - "version": "1.0.6-dev.7", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 1:32 PM MST", + "version": "1.0.6-dev.8", "dependencies": { "game": "" } From 6e0dbb361a8e0ccd7c1606bf09b634558de21d28 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 10:02:00 -0700 Subject: [PATCH 31/58] Implement the RTP refactor --- AriasServerUtils/ASUModSystem.cs | 3 +- AriasServerUtils/RTPFactory.cs | 186 ++++++++++++++++++------------- AriasServerUtils/modinfo.json | 4 +- 3 files changed, 114 insertions(+), 79 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index 84c74af..e2775d2 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -76,10 +76,11 @@ namespace AriasServerUtils api.Event.ServerRunPhase(EnumServerRunPhase.Shutdown, OnShutdown); api.Event.Timer(OnCheckModDirty, 20); api.Event.Timer(OnCheckPlayerCooldowns, 1); + api.Event.Timer(RTPFactory.HandleRTPChecking, 1); api.Event.PlayerDeath += OnPlayerDeath; api.Event.PlayerJoin += OnPlayerJoin; api.Event.PlayerDisconnect += OnPlayerDC; - api.Event.ChunkColumnLoaded += RTPFactory.ChunkColumnGenerated; + api.Event.ChunkColumnLoaded += RTPFactory.ChunkLoaded; //api.Event.PlayerLeave += OnPlayerDC; diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 42c0b51..8155b8c 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data; +using System.Linq; using System.Numerics; using AriasServerUtils; using Vintagestory.API.Common; @@ -15,6 +16,7 @@ public class RTPFactory { private static List RTPCache = new(); + private static List ChunkChecks = new(); /* if (pPos == null) @@ -41,93 +43,58 @@ public class RTPFactory */ /// - /// This function searches for a safe position, honoring the max RTP distance in the global configuration + /// This function searches for a safe position /// /// The player to be teleported - /// A random position +/- max distance from current position. - public static PlayerPosition GetRandomPosition(IServerPlayer isp, int maxDistance) + /// A safe position if able to be found + public static PlayerPosition GetSafePosition(RTPData data, RTPPosition position) { Random rng = ServerUtilities.rng; + IServerPlayer isp = data.player; EntityPos vPos = isp.Entity.Pos; BlockPos bPos = new BlockPos(isp.Entity.Pos.Dimension); IServerWorldAccessor iswa = isp.Entity.World as IServerWorldAccessor; int tries = 10000; PlayerPosition PPos = PlayerPosition.from(isp.Entity); - PlayerPosition original = PlayerPosition.from(isp.Entity); + //PlayerPosition original = PlayerPosition.from(isp.Entity); - while (tries-- > 0) + + // Generate random X and Z within max RTP distance + bPos.X = position.x; + bPos.Z = position.z; + bPos.Y = 255; + + Block lastAboveLast = null; + Block lastBlock = null; + Block curBlock; + + // Scan downwards to find a valid landing spot + for (int i = 255; i > 0; i--) { - int ixMax = (int)vPos.X + maxDistance; - int ixMin = (int)vPos.X - maxDistance; - int izMax = (int)vPos.Z + maxDistance; - int izMin = (int)vPos.Z - maxDistance; + bPos.Y = i; + curBlock = iswa.BlockAccessor.GetBlock(bPos); - // Generate random X and Z within max RTP distance - bPos.X = (int)vPos.X + rng.Next(ixMin, ixMax); - bPos.Z = (int)vPos.Z + rng.Next(izMin, izMax); - bPos.Y = 255; - - Block lastAboveLast = null; - Block lastBlock = null; - Block curBlock; - // Ensure the chunk is loaded before accessing blocks - int chunkX = bPos.X / 32; - int chunkY = bPos.Y / 32; - int chunkZ = bPos.Z / 32; - var chunk = iswa.ChunkProvider.GetUnpackedChunkFast(chunkX, chunkY, chunkZ); - - if (chunk == null) + if (curBlock.MatterState == EnumMatterState.Solid) { - // Chunk doesn't exist, or isn't loaded. - // Teleport the player to the position up in the sky. That way the chunk does get loaded and we can proceed. - PPos.X = bPos.X; - PPos.Y = bPos.Y; - PPos.Z = bPos.Z; + if (lastBlock != null && lastBlock.BlockMaterial == EnumBlockMaterial.Air && + lastAboveLast != null && lastAboveLast.BlockMaterial == EnumBlockMaterial.Air) + { + // Found a valid spot: curBlock is solid, lastBlock & lastAboveLast are gas (air) + PPos.X = bPos.X; + PPos.Y = bPos.Y + 1; + PPos.Z = bPos.Z; - PPos.Merge(isp.Entity); + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-found", tries)); + + return PPos; + } } - // Scan downwards to find a valid landing spot - for (int i = 255; i > 0; i--) - { - bPos.Y = i; - if (i / 32 != chunkY) - { - chunkY = i / 32; - chunk = iswa.ChunkProvider.GetUnpackedChunkFast(chunkX, chunkY, chunkZ); - if (chunk == null) - { - - PPos.Y = i; - PPos.Merge(isp.Entity); - } - } - curBlock = iswa.BlockAccessor.GetBlock(bPos); - - if (curBlock.MatterState == EnumMatterState.Solid) - { - if (lastBlock != null && lastBlock.BlockMaterial == EnumBlockMaterial.Air && - lastAboveLast != null && lastAboveLast.BlockMaterial == EnumBlockMaterial.Air) - { - // Found a valid spot: curBlock is solid, lastBlock & lastAboveLast are gas (air) - PPos.X = bPos.X; - PPos.Y = bPos.Y + 1; - PPos.Z = bPos.Z; - - ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-found", tries)); - - return PPos; - } - } - - lastAboveLast = lastBlock; - lastBlock = curBlock; - } + lastAboveLast = lastBlock; + lastBlock = curBlock; } - original.Merge(isp.Entity); - return null; // Return null if no valid position is found after retries } @@ -138,7 +105,7 @@ public class RTPFactory /// Max distance +/- the current position. public static void TryRTP(IServerPlayer isp, int maxDistance) { - var data = new RTPData(isp, maxDistance, 1000, PlayerPosition.from(isp)); + var data = new RTPData(isp, maxDistance, 100, PlayerPosition.from(isp.Entity)); RTPCache.Add(data); } @@ -147,10 +114,75 @@ public class RTPFactory return MathF.Sqrt(MathF.Pow(pos2.X - pos1.X, 2) + MathF.Pow(pos2.Y - pos1.Y, 2)); } - internal static void ChunkColumnGenerated(Vec2i chunkCoord, IWorldChunk[] chunks) + /// + /// Fired automatically by the internal game timer. This function will handle checking for a RTP Location + /// + /// NOTE: This function will only cause the chunks in question to be force loaded long enough to check their blocks and make sure it is safe to land there. + /// + internal static void HandleRTPChecking() { - throw new NotImplementedException(); + // We want to now loop over the entire cache list. + // We'll then generate a position to check + // We'll also then check the loaded status of the chunk + foreach (var rtp in RTPCache) + { + // Check for any chunks still being checked. + int num = ChunkChecks.Select(x => x.rtp.player.PlayerUID == rtp.player.PlayerUID).Count(); + if (num > 0) continue; + + // Generate a new position + var position = rtp.MakeNewPosition(); + + // Get the world handle, then get chunk size + var worldManager = ServerUtilities.API.WorldManager; + var chunkSize = worldManager.ChunkSize; + + // Generate a chunk load check object. + RTPChunk chunk = new RTPChunk(); + chunk.ChunkX = position.x / chunkSize; + chunk.ChunkZ = position.z / chunkSize; + chunk.dim = position.dimension; + chunk.rtp = rtp; + + // Load the chunk + worldManager.LoadChunkColumnForDimension(chunk.ChunkX, chunk.ChunkZ, chunk.dim); + + // Log the request + ChunkChecks.Add(chunk); + } } + + internal static void ChunkLoaded(Vec2i chunkCoord, IWorldChunk[] chunks) + { + // Get the chunk from the stack + var chunk = ChunkChecks.Where(x => x.ChunkX == chunkCoord.X && x.ChunkZ == chunkCoord.Y).First(); + + // Attempt to find a landing point. + var data = chunk.rtp; + var pos = GetSafePosition(data, data.LastPosition); + + if (pos == null) + { + // Let this get checked again + } + else + { + // Found! Perform teleport and remove the RTP Check + RTPCache.Remove(data); + pos.Merge(data.player.Entity); + } + + // Remove this check + ChunkChecks.Remove(chunk); + } +} + +public class RTPChunk +{ + public int ChunkX; + public int ChunkZ; + public int dim; + public RTPData rtp; } public class RTPData @@ -159,6 +191,7 @@ public class RTPData public int NumTriesRemaining; public int MaxDistance; public PlayerPosition StartPosition; + public RTPPosition LastPosition; public RTPData(IServerPlayer isp, int maxDistance, int tries, PlayerPosition playerPosition) { @@ -171,18 +204,19 @@ public class RTPData public RTPPosition MakeNewPosition() { NumTriesRemaining--; + LastPosition = new RTPPosition((int)player.Entity.Pos.X, (int)player.Entity.Pos.Z, MaxDistance, player.Entity.Pos.Dimension); - return new RTPPosition((int)player.Entity.Pos.X, (int)player.Entity.Pos.Z, MaxDistance, player.Entity.Pos.Dimension); + return LastPosition; } } public class RTPPosition { - int x; - int y; - int z; + public int x; + public int y; + public int z; - int dimension; + public int dimension; public RTPPosition(int x, int z, int maxDist, int dim) { diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 3cf221e..23ebf07 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 1:32 PM MST", - "version": "1.0.6-dev.8", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 10:01 AM MST", + "version": "1.0.6-dev.9", "dependencies": { "game": "" } From 40f8eb40484f96e41025320cc64c6637b23e908f Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 10:07:03 -0700 Subject: [PATCH 32/58] Attempt to fix a crash when no RTP checks are active that match the chunk generated/loaded. --- AriasServerUtils/RTPFactory.cs | 5 +++++ AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 8155b8c..77d9fe0 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -154,6 +154,11 @@ public class RTPFactory internal static void ChunkLoaded(Vec2i chunkCoord, IWorldChunk[] chunks) { + // Check if this is even a valid check + var num = ChunkChecks.Where(x => x.ChunkX == chunkCoord.X && x.ChunkZ == chunkCoord.Y).Count(); + if (num == 0) return; + + // Get the chunk from the stack var chunk = ChunkChecks.Where(x => x.ChunkX == chunkCoord.X && x.ChunkZ == chunkCoord.Y).First(); diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 23ebf07..1dd4911 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 10:01 AM MST", - "version": "1.0.6-dev.9", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 10:06 AM MST", + "version": "1.0.6-dev.10", "dependencies": { "game": "" } From aad44f4c45f3a1c579e3c7e087f39354a3aa4757 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 10:11:33 -0700 Subject: [PATCH 33/58] Ensure the failed rtp gets removed from the list --- AriasServerUtils/RTPFactory.cs | 9 +++++++++ AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 77d9fe0..45cf750 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -149,6 +149,15 @@ public class RTPFactory // Log the request ChunkChecks.Add(chunk); + + if (rtp.NumTriesRemaining <= 0) + { + // Send failure message to the player + ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail")); + // This check needs to be removed from the queue + RTPCache.Remove(rtp); + return; // We modified the list, so abort the loop. + } } } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 1dd4911..3352e71 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 10:06 AM MST", - "version": "1.0.6-dev.10", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 10:08 AM MST", + "version": "1.0.6-dev.11", "dependencies": { "game": "" } From 74d85c57e12071988e0ee9d9067e856435a923b9 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 10:22:58 -0700 Subject: [PATCH 34/58] Patch an infinite loop --- AriasServerUtils/RTPFactory.cs | 2 ++ AriasServerUtils/assets/ariasserverutils/lang/en.json | 1 + AriasServerUtils/modinfo.json | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 45cf750..abddf7a 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -132,6 +132,7 @@ public class RTPFactory // Generate a new position var position = rtp.MakeNewPosition(); + ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-progress")); // Get the world handle, then get chunk size var worldManager = ServerUtilities.API.WorldManager; @@ -178,6 +179,7 @@ public class RTPFactory if (pos == null) { // Let this get checked again + RTPCache.Remove(data); } else { diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index cda0fee..2efe4df 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -34,6 +34,7 @@ "back": "You've been taken back to your last position", "rtp-search": "Searching for a random position...", + "rtp-progress": "Still searchinf for a random position...", "rtp": "You have been teleported [{0}] blocks away!", "rtp-found": "Found a valid landing position after {0} tries.", "rtp-fail": "Giving up on RTP search. No valid position could be found. Try again later", diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 3352e71..fbc64b5 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 10:08 AM MST", - "version": "1.0.6-dev.11", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 10:22 AM MST", + "version": "1.0.6-dev.12", "dependencies": { "game": "" } From 6598eb44da5ced1ec2b502ec3891024e2b6fb08e Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 10:36:41 -0700 Subject: [PATCH 35/58] Change method of finding a safe position --- AriasServerUtils/RTPFactory.cs | 58 ++++--------------- .../assets/ariasserverutils/lang/en.json | 2 +- AriasServerUtils/modinfo.json | 4 +- 3 files changed, 15 insertions(+), 49 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index abddf7a..3f36d9f 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -49,53 +49,18 @@ public class RTPFactory /// A safe position if able to be found public static PlayerPosition GetSafePosition(RTPData data, RTPPosition position) { - Random rng = ServerUtilities.rng; - IServerPlayer isp = data.player; - EntityPos vPos = isp.Entity.Pos; - BlockPos bPos = new BlockPos(isp.Entity.Pos.Dimension); - IServerWorldAccessor iswa = isp.Entity.World as IServerWorldAccessor; + PlayerPosition PPos = PlayerPosition.from(data.player.Entity); + BlockPos check = new( + x: position.x, + y: 1, + z: position.z, + dim: position.dimension + ); - int tries = 10000; - PlayerPosition PPos = PlayerPosition.from(isp.Entity); - //PlayerPosition original = PlayerPosition.from(isp.Entity); + int height = ServerUtilities.API.World.BlockAccessor.GetTerrainMapheightAt(check); - - // Generate random X and Z within max RTP distance - bPos.X = position.x; - bPos.Z = position.z; - bPos.Y = 255; - - Block lastAboveLast = null; - Block lastBlock = null; - Block curBlock; - - // Scan downwards to find a valid landing spot - for (int i = 255; i > 0; i--) - { - bPos.Y = i; - curBlock = iswa.BlockAccessor.GetBlock(bPos); - - if (curBlock.MatterState == EnumMatterState.Solid) - { - if (lastBlock != null && lastBlock.BlockMaterial == EnumBlockMaterial.Air && - lastAboveLast != null && lastAboveLast.BlockMaterial == EnumBlockMaterial.Air) - { - // Found a valid spot: curBlock is solid, lastBlock & lastAboveLast are gas (air) - PPos.X = bPos.X; - PPos.Y = bPos.Y + 1; - PPos.Z = bPos.Z; - - ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-found", tries)); - - return PPos; - } - } - - lastAboveLast = lastBlock; - lastBlock = curBlock; - } - - return null; // Return null if no valid position is found after retries + PPos.Y = height + 1; + return PPos; } /// @@ -179,13 +144,14 @@ public class RTPFactory if (pos == null) { // Let this get checked again - RTPCache.Remove(data); } else { // Found! Perform teleport and remove the RTP Check RTPCache.Remove(data); pos.Merge(data.player.Entity); + + ServerUtilities.SendMessageTo(data.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp", GetDistance(new Vec2i(data.StartPosition.X, data.StartPosition.Z), new Vec2i(pos.X, pos.Z)))); } // Remove this check diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index 2efe4df..6a19efb 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -34,7 +34,7 @@ "back": "You've been taken back to your last position", "rtp-search": "Searching for a random position...", - "rtp-progress": "Still searchinf for a random position...", + "rtp-progress": "Still searching for a random position...", "rtp": "You have been teleported [{0}] blocks away!", "rtp-found": "Found a valid landing position after {0} tries.", "rtp-fail": "Giving up on RTP search. No valid position could be found. Try again later", diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index fbc64b5..cd1afab 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 10:22 AM MST", - "version": "1.0.6-dev.12", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 10:36 AM MST", + "version": "1.0.6-dev.13", "dependencies": { "game": "" } From 3712399a03b577949f9218a28993b19e4b8d0744 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 10:55:04 -0700 Subject: [PATCH 36/58] Optimize by using the existing helper functions --- AriasServerUtils/RTPFactory.cs | 20 ++++++++------------ AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 3f36d9f..5f81d53 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -49,13 +49,9 @@ public class RTPFactory /// A safe position if able to be found public static PlayerPosition GetSafePosition(RTPData data, RTPPosition position) { - PlayerPosition PPos = PlayerPosition.from(data.player.Entity); - BlockPos check = new( - x: position.x, - y: 1, - z: position.z, - dim: position.dimension - ); + PlayerPosition PPos = data.LastPosition.GetPlayerPosition(); + BlockPos check = data.LastPosition.GetBlockPos(); + check.Y = 1; int height = ServerUtilities.API.World.BlockAccessor.GetTerrainMapheightAt(check); @@ -110,12 +106,12 @@ public class RTPFactory chunk.dim = position.dimension; chunk.rtp = rtp; - // Load the chunk - worldManager.LoadChunkColumnForDimension(chunk.ChunkX, chunk.ChunkZ, chunk.dim); - // Log the request ChunkChecks.Add(chunk); + // Load the chunk + worldManager.LoadChunkColumnPriority(chunk.ChunkX, chunk.ChunkZ); + if (rtp.NumTriesRemaining <= 0) { // Send failure message to the player @@ -214,7 +210,7 @@ public class RTPPosition this.dimension = dim; } - PlayerPosition GetPlayerPosition() + public PlayerPosition GetPlayerPosition() { return new PlayerPosition { @@ -225,7 +221,7 @@ public class RTPPosition }; } - BlockPos GetBlockPos() + public BlockPos GetBlockPos() { return new BlockPos(new Vec3i(x, y, z), dimension); } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index cd1afab..9bd42e7 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 10:36 AM MST", - "version": "1.0.6-dev.13", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 10:54 AM MST", + "version": "1.0.6-dev.14", "dependencies": { "game": "" } From 5f99672a9b46e1842e8f20cd79613b6e4b831d90 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 11:04:23 -0700 Subject: [PATCH 37/58] Restore the original RTP search method --- AriasServerUtils/RTPFactory.cs | 37 ++++++++++++++++++++++++++++++++-- AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 5f81d53..d449e6a 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -4,6 +4,7 @@ using System.Data; using System.Linq; using System.Numerics; using AriasServerUtils; +using Microsoft.Win32.SafeHandles; using Vintagestory.API.Common; using Vintagestory.API.Common.Entities; using Vintagestory.API.Config; @@ -53,9 +54,41 @@ public class RTPFactory BlockPos check = data.LastPosition.GetBlockPos(); check.Y = 1; - int height = ServerUtilities.API.World.BlockAccessor.GetTerrainMapheightAt(check); + int Y = 255; + bool lastBlockAir = true; + bool lastLastBlockAir = true; + bool curBlockAir = true; + bool safe = false; + for (Y = 255; Y > 1; Y--) + { + // Manually scan downwards + var BA = ServerUtilities.API.World.BlockAccessor; + check.Y = Y; + var current = BA.GetBlock(check); - PPos.Y = height + 1; + if (current.BlockMaterial != EnumBlockMaterial.Air) + { + curBlockAir = false; + } + + + + lastLastBlockAir = lastBlockAir; + lastBlockAir = curBlockAir; + + + if (!curBlockAir && lastBlockAir && lastLastBlockAir) + { + // We found a safe spot to land + check.Y++; + safe = true; + break; + } + } + + if (!safe) return null; + + PPos.Y = check.Y; return PPos; } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 9bd42e7..a385c42 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 10:54 AM MST", - "version": "1.0.6-dev.14", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 11:04 AM MST", + "version": "1.0.6-dev.15", "dependencies": { "game": "" } From c69e1de64b4926524c5055c4710c645865c63218 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 11:18:45 -0700 Subject: [PATCH 38/58] Take world size into account when finding rtp --- AriasServerUtils/RTPFactory.cs | 45 +++++++++++++++++++++------------- AriasServerUtils/modinfo.json | 4 +-- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index d449e6a..ce8de87 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -99,7 +99,7 @@ public class RTPFactory /// Max distance +/- the current position. public static void TryRTP(IServerPlayer isp, int maxDistance) { - var data = new RTPData(isp, maxDistance, 100, PlayerPosition.from(isp.Entity)); + var data = new RTPData(isp, maxDistance, 10, PlayerPosition.from(isp.Entity)); RTPCache.Add(data); } @@ -124,13 +124,24 @@ public class RTPFactory int num = ChunkChecks.Select(x => x.rtp.player.PlayerUID == rtp.player.PlayerUID).Count(); if (num > 0) continue; - // Generate a new position - var position = rtp.MakeNewPosition(); - ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-progress")); + + if (rtp.NumTriesRemaining <= 0) + { + // Send failure message to the player + ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail")); + // This check needs to be removed from the queue + RTPCache.Remove(rtp); + return; // We modified the list, so abort the loop. + } // Get the world handle, then get chunk size var worldManager = ServerUtilities.API.WorldManager; var chunkSize = worldManager.ChunkSize; + var worldSize = new Vec3i(worldManager.MapSizeX, worldManager.MapSizeY, worldManager.MapSizeZ); + + // Generate a new position + var position = rtp.MakeNewPosition(worldSize); + //ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-progress")); // Generate a chunk load check object. RTPChunk chunk = new RTPChunk(); @@ -145,14 +156,6 @@ public class RTPFactory // Load the chunk worldManager.LoadChunkColumnPriority(chunk.ChunkX, chunk.ChunkZ); - if (rtp.NumTriesRemaining <= 0) - { - // Send failure message to the player - ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail")); - // This check needs to be removed from the queue - RTPCache.Remove(rtp); - return; // We modified the list, so abort the loop. - } } } @@ -212,10 +215,10 @@ public class RTPData StartPosition = playerPosition; } - public RTPPosition MakeNewPosition() + public RTPPosition MakeNewPosition(Vec3i mapSize) { NumTriesRemaining--; - LastPosition = new RTPPosition((int)player.Entity.Pos.X, (int)player.Entity.Pos.Z, MaxDistance, player.Entity.Pos.Dimension); + LastPosition = new RTPPosition((int)player.Entity.Pos.X, (int)player.Entity.Pos.Z, MaxDistance, player.Entity.Pos.Dimension, mapSize); return LastPosition; } @@ -229,16 +232,24 @@ public class RTPPosition public int dimension; - public RTPPosition(int x, int z, int maxDist, int dim) + public RTPPosition(int x, int z, int maxDist, int dim, Vec3i mapSize) { + + int worldx = mapSize.X / 2; + int worldz = mapSize.Z / 2; + + if (maxDist > worldx) maxDist = worldx / 2; + int minX = x - maxDist; int maxX = x + maxDist; int minZ = z - maxDist; int maxZ = z + maxDist; - this.x = ServerUtilities.rng.Next(minX, maxX); + this.x = ServerUtilities.rng.Next(worldx - minX, worldx + maxX); this.y = 1; - this.z = ServerUtilities.rng.Next(minZ, maxZ); + this.z = ServerUtilities.rng.Next(worldz - minZ, worldz + maxZ); + + this.dimension = dim; } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index a385c42..59f8f79 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 11:04 AM MST", - "version": "1.0.6-dev.15", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 11:18 AM MST", + "version": "1.0.6-dev.16", "dependencies": { "game": "" } From cf7084c1647d2b0febfee6332be2ec89544bb519 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 11:52:35 -0700 Subject: [PATCH 39/58] Add a timeout to a chunk check --- AriasServerUtils/RTPFactory.cs | 37 +++++++++++++++---- .../assets/ariasserverutils/lang/en.json | 2 +- AriasServerUtils/modinfo.json | 4 +- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index ce8de87..d1d017e 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -52,7 +52,13 @@ public class RTPFactory { PlayerPosition PPos = data.LastPosition.GetPlayerPosition(); BlockPos check = data.LastPosition.GetBlockPos(); + var BA = ServerUtilities.API.World.BlockAccessor; check.Y = 1; + int height = BA.GetTerrainMapheightAt(check); + if (height >= 0 && height <= 20) return null; + check.Y = height + 1; + PPos.Y = height + 1; + return PPos; int Y = 255; bool lastBlockAir = true; @@ -62,7 +68,6 @@ public class RTPFactory for (Y = 255; Y > 1; Y--) { // Manually scan downwards - var BA = ServerUtilities.API.World.BlockAccessor; check.Y = Y; var current = BA.GetBlock(check); @@ -115,6 +120,15 @@ public class RTPFactory /// internal static void HandleRTPChecking() { + foreach (var chunk in ChunkChecks) + { + chunk.Wait--; + if (chunk.Wait <= 0) + { + ChunkChecks.Remove(chunk); + break; + } + } // We want to now loop over the entire cache list. // We'll then generate a position to check // We'll also then check the loaded status of the chunk @@ -131,6 +145,7 @@ public class RTPFactory ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail")); // This check needs to be removed from the queue RTPCache.Remove(rtp); + HandleRTPChecking(); return; // We modified the list, so abort the loop. } @@ -141,7 +156,7 @@ public class RTPFactory // Generate a new position var position = rtp.MakeNewPosition(worldSize); - //ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-progress")); + ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-progress", rtp.NumTriesRemaining)); // Generate a chunk load check object. RTPChunk chunk = new RTPChunk(); @@ -176,6 +191,7 @@ public class RTPFactory if (pos == null) { // Let this get checked again + ServerUtilities.API.Logger.Notification("position null: resume search"); } else { @@ -184,6 +200,8 @@ public class RTPFactory pos.Merge(data.player.Entity); ServerUtilities.SendMessageTo(data.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp", GetDistance(new Vec2i(data.StartPosition.X, data.StartPosition.Z), new Vec2i(pos.X, pos.Z)))); + + ServerUtilities.API.Logger.Notification("position found"); } // Remove this check @@ -197,6 +215,7 @@ public class RTPChunk public int ChunkZ; public int dim; public RTPData rtp; + public int Wait = 5; } public class RTPData @@ -218,7 +237,7 @@ public class RTPData public RTPPosition MakeNewPosition(Vec3i mapSize) { NumTriesRemaining--; - LastPosition = new RTPPosition((int)player.Entity.Pos.X, (int)player.Entity.Pos.Z, MaxDistance, player.Entity.Pos.Dimension, mapSize); + LastPosition = new RTPPosition((int)player.Entity.Pos.X, (int)player.Entity.Pos.Z, MaxDistance, player.Entity.Pos.Dimension, mapSize, player); return LastPosition; } @@ -232,22 +251,26 @@ public class RTPPosition public int dimension; - public RTPPosition(int x, int z, int maxDist, int dim, Vec3i mapSize) + public RTPPosition(int x, int z, int maxDist, int dim, Vec3i mapSize, IServerPlayer player) { int worldx = mapSize.X / 2; int worldz = mapSize.Z / 2; - if (maxDist > worldx) maxDist = worldx / 2; + if (maxDist > worldx) + { + ServerUtilities.SendMessageTo(player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-capped", maxDist, (worldx))); + maxDist = worldx / 2; + } int minX = x - maxDist; int maxX = x + maxDist; int minZ = z - maxDist; int maxZ = z + maxDist; - this.x = ServerUtilities.rng.Next(worldx - minX, worldx + maxX); + this.x = ServerUtilities.rng.Next(minX, maxX); this.y = 1; - this.z = ServerUtilities.rng.Next(worldz - minZ, worldz + maxZ); + this.z = ServerUtilities.rng.Next(minZ, maxZ); diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index 6a19efb..cf23780 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -34,7 +34,7 @@ "back": "You've been taken back to your last position", "rtp-search": "Searching for a random position...", - "rtp-progress": "Still searching for a random position...", + "rtp-progress": "Still searching for a random position... [{0}] tries remaining...", "rtp": "You have been teleported [{0}] blocks away!", "rtp-found": "Found a valid landing position after {0} tries.", "rtp-fail": "Giving up on RTP search. No valid position could be found. Try again later", diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 59f8f79..db75f3d 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 11:18 AM MST", - "version": "1.0.6-dev.16", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 11:52 AM MST", + "version": "1.0.6-dev.17", "dependencies": { "game": "" } From bda8e49ee1e1e8a1e283106b73bc1fa6d4fa6a58 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 12:03:32 -0700 Subject: [PATCH 40/58] Patch rtp in already loaded chunks --- AriasServerUtils/RTPFactory.cs | 31 +++++++++++++++++++++++++++++-- AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index d1d017e..a891813 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -168,9 +168,36 @@ public class RTPFactory // Log the request ChunkChecks.Add(chunk); - // Load the chunk - worldManager.LoadChunkColumnPriority(chunk.ChunkX, chunk.ChunkZ); + // Check if the chunk's coordinates are loaded + var cxCheck = ServerUtilities.API.World.IsFullyLoadedChunk(position.GetBlockPos()); + if (cxCheck) + { + // Process the check here, no need to load + var posX = GetSafePosition(rtp, position); + if (posX == null) + { + // Let this get checked again + ServerUtilities.API.Logger.Notification("position null: resume search"); + } + else + { + // Found! Perform teleport and remove the RTP Check + RTPCache.Remove(rtp); + posX.Merge(rtp.player.Entity); + + ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp", GetDistance(new Vec2i(rtp.StartPosition.X, rtp.StartPosition.Z), new Vec2i(posX.X, posX.Z)))); + + ServerUtilities.API.Logger.Notification("position found"); + } + + ChunkChecks.Remove(chunk); + } + else + { + // Load the chunk + worldManager.LoadChunkColumnPriority(chunk.ChunkX, chunk.ChunkZ); + } } } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index db75f3d..f4dd3b9 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 11:52 AM MST", - "version": "1.0.6-dev.17", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 11:55 AM MST", + "version": "1.0.6-dev.18", "dependencies": { "game": "" } From caf12dfadec4cf32657c3b8c6b2a2335f1dbb30e Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 12:04:12 -0700 Subject: [PATCH 41/58] Remove debug --- AriasServerUtils/RTPFactory.cs | 8 ++++---- AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index a891813..ef37717 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -177,7 +177,7 @@ public class RTPFactory if (posX == null) { // Let this get checked again - ServerUtilities.API.Logger.Notification("position null: resume search"); + //ServerUtilities.API.Logger.Notification("position null: resume search"); } else { @@ -188,7 +188,7 @@ public class RTPFactory ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp", GetDistance(new Vec2i(rtp.StartPosition.X, rtp.StartPosition.Z), new Vec2i(posX.X, posX.Z)))); - ServerUtilities.API.Logger.Notification("position found"); + //ServerUtilities.API.Logger.Notification("position found"); } ChunkChecks.Remove(chunk); @@ -218,7 +218,7 @@ public class RTPFactory if (pos == null) { // Let this get checked again - ServerUtilities.API.Logger.Notification("position null: resume search"); + //ServerUtilities.API.Logger.Notification("position null: resume search"); } else { @@ -228,7 +228,7 @@ public class RTPFactory ServerUtilities.SendMessageTo(data.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp", GetDistance(new Vec2i(data.StartPosition.X, data.StartPosition.Z), new Vec2i(pos.X, pos.Z)))); - ServerUtilities.API.Logger.Notification("position found"); + //ServerUtilities.API.Logger.Notification("position found"); } // Remove this check diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index f4dd3b9..b94b714 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 11:55 AM MST", - "version": "1.0.6-dev.18", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 12:03 PM MST", + "version": "1.0.6-dev.19", "dependencies": { "game": "" } From c609dde0ee9944fbf8c39adbd95c147f05ea2f00 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 12:04:31 -0700 Subject: [PATCH 42/58] Release 1.0.6 --- AriasServerUtils/modinfo.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index b94b714..e8b5349 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 12:03 PM MST", - "version": "1.0.6-dev.19", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 12:04 PM MST", + "version": "1.0.6", "dependencies": { "game": "" } From 9a8b9d154544e77aae2445254dde6f1afd6cf82d Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 17:17:25 -0700 Subject: [PATCH 43/58] Begin to add the player sleeping percentage system --- AriasServerUtils/ASUModSystem.cs | 50 ++++++++++++++++++++++++++++++++ AriasServerUtils/modinfo.json | 4 +-- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index e2775d2..27ff056 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -38,6 +38,8 @@ namespace AriasServerUtils GlobalConstants.characterInvClassName }; + List SleepingPlayers { get; set; } + /// /// Method to register all mod blocks /// @@ -76,6 +78,7 @@ namespace AriasServerUtils api.Event.ServerRunPhase(EnumServerRunPhase.Shutdown, OnShutdown); api.Event.Timer(OnCheckModDirty, 20); api.Event.Timer(OnCheckPlayerCooldowns, 1); + api.Event.Timer(OnCheckSleepingPlayers, 5); api.Event.Timer(RTPFactory.HandleRTPChecking, 1); api.Event.PlayerDeath += OnPlayerDeath; api.Event.PlayerJoin += OnPlayerJoin; @@ -235,6 +238,53 @@ namespace AriasServerUtils api.ChatCommands.Create("listcooldowns").RequiresPrivilege(Privilege.chat).WithDescription("Lists the cooldown settings on the server, as well as your own active cooldowns if applicable.").HandleWith(Events.HandleListCooldowns); } + private void OnCheckSleepingPlayers() + { + if (API.Side == EnumAppSide.Client) return; // This must only ever be called on the server! + if (config.PlayerSleepingPercentage == 100) return; // Normal behavior + // Iterate over all players, get their entity, check if mounted on a bed. + // If mounted on a bed, check tiredness + int TotalOnline = API.World.AllOnlinePlayers.Length; + int TotalInBed = 0; + + bool isAlreadySleeping = false; + + List BEBs = new(); + + foreach (var player in API.World.AllOnlinePlayers) + { + EntityAgent ePlay = player.Entity; + if (ePlay.MountedOn is BlockEntityBed beb) + { + BEBs.Add(beb); + TotalInBed++; + } + if (ePlay.MountedOn == null) + { + if (SleepingPlayers.Contains(ePlay)) + { + EntityBehaviorTiredness ebt = ePlay.GetBehavior("tiredness") as EntityBehaviorTiredness; + if (ebt != null) + ebt.IsSleeping = false; + } + } + + EntityBehaviorTiredness EBT = ePlay.GetBehavior("tiredness") as EntityBehaviorTiredness; + if (EBT == null) continue; + if (EBT.IsSleeping) isAlreadySleeping = true; + } + + if (isAlreadySleeping) return; // Abort + + SleepingPlayers.Clear(); + + int Percentage = TotalInBed * 100 / TotalOnline; + if (Percentage >= config.PlayerSleepingPercentage) + { + // Call the API to make sleep happen + } + } + private void OnCheckPlayerCooldowns() { foreach (var cdEntry in ServerUtilities.mPlayerData) diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index e8b5349..f30a8d5 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 12:04 PM MST", - "version": "1.0.6", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 4:37 PM MST", + "version": "1.0.7-dev.1", "dependencies": { "game": "" } From 720dafea871be503721cf1f048591a10d36bdaaf Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 18:57:27 -0700 Subject: [PATCH 44/58] Implement experimental player sleeping percentage handling --- AriasServerUtils/ASUModSystem.cs | 48 ++++++++++++++++++++++++++++---- AriasServerUtils/modinfo.json | 4 +-- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index 27ff056..215f848 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -38,7 +38,10 @@ namespace AriasServerUtils GlobalConstants.characterInvClassName }; - List SleepingPlayers { get; set; } + List SleepingPlayers { get; set; } = new(); + float OriginalSpeed { get; set; } = 0.0f; + public double Hours { get; private set; } = 0.0; + bool Sleeping { get; set; } = false; /// /// Method to register all mod blocks @@ -76,10 +79,6 @@ namespace AriasServerUtils api.Event.ServerRunPhase(EnumServerRunPhase.GameReady, OnGameReady); api.Event.ServerRunPhase(EnumServerRunPhase.Shutdown, OnShutdown); - api.Event.Timer(OnCheckModDirty, 20); - api.Event.Timer(OnCheckPlayerCooldowns, 1); - api.Event.Timer(OnCheckSleepingPlayers, 5); - api.Event.Timer(RTPFactory.HandleRTPChecking, 1); api.Event.PlayerDeath += OnPlayerDeath; api.Event.PlayerJoin += OnPlayerJoin; api.Event.PlayerDisconnect += OnPlayerDC; @@ -241,6 +240,22 @@ namespace AriasServerUtils private void OnCheckSleepingPlayers() { if (API.Side == EnumAppSide.Client) return; // This must only ever be called on the server! + if (Sleeping) + { + if (API.World.Calendar.TotalHours - Hours >= 7) + { + Sleeping = false; + foreach (var player in SleepingPlayers) + { + EntityBehaviorTiredness ebt = player.GetBehavior("tiredness") as EntityBehaviorTiredness; + ebt.IsSleeping = false; + } + + SleepingPlayers.Clear(); + API.World.Calendar.CalendarSpeedMul = OriginalSpeed; + } + return; + } if (config.PlayerSleepingPercentage == 100) return; // Normal behavior // Iterate over all players, get their entity, check if mounted on a bed. // If mounted on a bed, check tiredness @@ -282,6 +297,22 @@ namespace AriasServerUtils if (Percentage >= config.PlayerSleepingPercentage) { // Call the API to make sleep happen + foreach (var bed in BEBs) + { + if (bed.MountedBy != null) SleepingPlayers.Add(bed.MountedBy); + + // Start sleep + EntityBehaviorTiredness EBT = bed.MountedBy.GetBehavior("tiredness") as EntityBehaviorTiredness; + + EBT.IsSleeping = true; + + // Get current calendar speed + OriginalSpeed = API.World.Calendar.CalendarSpeedMul; + Hours = API.World.Calendar.TotalHours; + Sleeping = true; + + API.World.Calendar.CalendarSpeedMul = 4; + } } } @@ -445,6 +476,13 @@ namespace AriasServerUtils // -> Step 3. Load Mod Warps <- serverWarps = API.LoadModConfig(GetConfigurationFile("warps", ModConfigType.Global)); if (serverWarps == null) serverWarps = new Warps(); + + + + API.Event.Timer(OnCheckModDirty, 20); + API.Event.Timer(OnCheckPlayerCooldowns, 1); + API.Event.Timer(OnCheckSleepingPlayers, 5); + API.Event.Timer(RTPFactory.HandleRTPChecking, 1); } public string GetConfigurationFile(string sName, ModConfigType type) diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index f30a8d5..6d14c13 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 4:37 PM MST", - "version": "1.0.7-dev.1", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 6:56 PM MST", + "version": "1.0.7-dev.2", "dependencies": { "game": "" } From d2b92f95c51e51021d4a2994de9d436b6543d6db Mon Sep 17 00:00:00 2001 From: zontreck Date: Tue, 11 Mar 2025 00:37:46 -0700 Subject: [PATCH 45/58] Change method of time acceleration --- AriasServerUtils/ModSystems/ASUClient.cs | 34 +++++ .../ASUServer.cs} | 116 +++++++++++++++++- AriasServerUtils/modinfo.json | 4 +- .../network/ASUTimeAccelPacket.cs | 7 ++ 4 files changed, 157 insertions(+), 4 deletions(-) create mode 100644 AriasServerUtils/ModSystems/ASUClient.cs rename AriasServerUtils/{ASUModSystem.cs => ModSystems/ASUServer.cs} (84%) create mode 100644 AriasServerUtils/network/ASUTimeAccelPacket.cs diff --git a/AriasServerUtils/ModSystems/ASUClient.cs b/AriasServerUtils/ModSystems/ASUClient.cs new file mode 100644 index 0000000..2f678b3 --- /dev/null +++ b/AriasServerUtils/ModSystems/ASUClient.cs @@ -0,0 +1,34 @@ +using System; +using Vintagestory.API.Client; +using Vintagestory.API.Common; + +public class ASUModClient : ModSystem +{ + public static ICoreClientAPI CAPI; + bool accel = false; + + public override bool ShouldLoad(EnumAppSide forSide) + { + return forSide == EnumAppSide.Client; + } + + public override void StartClientSide(ICoreClientAPI api) + { + CAPI = api; + api.Network.RegisterChannel("asutimeaccel") + .RegisterMessageType() + .SetMessageHandler(onReceiveTimeAccel); + } + + private void onReceiveTimeAccel(ASUTimeAcceleration packet) + { + // Time acceleration handler + accel = packet.Sleeping; + + if (accel) + { + CAPI.World.Calendar.SetTimeSpeedModifier("asu_psp", 500); + } + else CAPI.World.Calendar.RemoveTimeSpeedModifier("asu_psp"); + } +} \ No newline at end of file diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ModSystems/ASUServer.cs similarity index 84% rename from AriasServerUtils/ASUModSystem.cs rename to AriasServerUtils/ModSystems/ASUServer.cs index 215f848..c5d6d75 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ModSystems/ASUServer.cs @@ -7,6 +7,7 @@ using Vintagestory.API.Common; using Vintagestory.API.Common.CommandAbbr; using Vintagestory.API.Common.Entities; using Vintagestory.API.Config; +using Vintagestory.API.Datastructures; using Vintagestory.API.MathTools; using Vintagestory.API.Server; using Vintagestory.API.Util; @@ -42,6 +43,7 @@ namespace AriasServerUtils float OriginalSpeed { get; set; } = 0.0f; public double Hours { get; private set; } = 0.0; bool Sleeping { get; set; } = false; + public IServerNetworkChannel ServerNetworkChannel { get; private set; } /// /// Method to register all mod blocks @@ -61,6 +63,14 @@ namespace AriasServerUtils { } + + public override bool ShouldLoad(EnumAppSide side) + { + return side == EnumAppSide.Server; + } + + + // Called on server and client public override void Start(ICoreAPI api) { @@ -86,6 +96,10 @@ namespace AriasServerUtils //api.Event.PlayerLeave += OnPlayerDC; + ServerNetworkChannel = api.Network.RegisterChannel("asutimeaccel") + .RegisterMessageType(); + + api.ChatCommands.Create("setspawn").RequiresPrivilege(Privilege.controlserver).HandleWith(Events.HandleSetSpawn); api.ChatCommands.Create("spawn").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleSpawn); @@ -223,6 +237,20 @@ namespace AriasServerUtils .RequiresPrivilege(Privilege.chat) .HandleWith(Events.HandleASU) .WithDescription("Lists all Aria's Server Utils commands") + .EndSubCommand() + .BeginSubCommand("test") + .RequiresPlayer() + .RequiresPrivilege(Privilege.controlserver) + .BeginSubCommand("sleep") + .RequiresPlayer() + .RequiresPrivilege(Privilege.controlserver) + .HandleWith(TestSleep) + .EndSubCommand() + .BeginSubCommand("calendarspeed") + .RequiresPlayer() + .RequiresPrivilege(Privilege.controlserver) + .HandleWith(TestCalendarSpeed) + .EndSubCommand() .EndSubCommand(); api.ChatCommands.Create("setwarp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Creates a new server warp").WithArgs(parsers.OptionalWord("name")).HandleWith(Events.HandleWarpUpdate); @@ -237,6 +265,78 @@ namespace AriasServerUtils api.ChatCommands.Create("listcooldowns").RequiresPrivilege(Privilege.chat).WithDescription("Lists the cooldown settings on the server, as well as your own active cooldowns if applicable.").HandleWith(Events.HandleListCooldowns); } + private TextCommandResult TestSleep(TextCommandCallingArgs args) + { + // Initiate the sleep process + // Basically run all the same commands as we would on a player in bed + OriginalSpeed = API.World.Calendar.CalendarSpeedMul; + if (args.Caller.Player is IServerPlayer isp) + { + Hours = API.World.Calendar.TotalHours; + SleepingPlayers.Add(isp.Entity); + EntityAgent Agent = isp.Entity; + EntityBehaviorTiredness ebt = Agent.GetBehavior("tiredness") as EntityBehaviorTiredness; + ebt.IsSleeping = true; + ebt.Tiredness = 100; + Sleeping = true; + + + ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration + { + Sleeping = true + }); + + API.World.Calendar.SetTimeSpeedModifier("asu_psp", 500); + } + + return TextCommandResult.Success($"Test initiated, original calendar multiplier: '{OriginalSpeed}'"); + } + + private TextCommandResult TestCalendarSpeed(TextCommandCallingArgs args) + { + if (args.Caller.Player is IServerPlayer isp) + { + EntityAgent agent = isp.Entity; + EntityBehaviorTiredness ebt = agent.GetBehavior("tiredness") as EntityBehaviorTiredness; + + SendMessageTo(isp, $"- Current calendar speed: {API.World.Calendar.CalendarSpeedMul}"); + SendMessageTo(isp, $"- Total Hours: {API.World.Calendar.TotalHours}"); + SendMessageTo(isp, $"- Tiredness: {ebt.Tiredness}"); + if (OriginalSpeed == 0) + { + // Apply multiplier + OriginalSpeed = 0.5f; + ebt.IsSleeping = true; + + ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration + { + Sleeping = true + }); + + API.World.Calendar.SetTimeSpeedModifier("asu_psp", 500); + + SendMessageTo(isp, "Applied calendar speed multiplier"); + } + else + { + // Unapply multiplier + OriginalSpeed = 0; + ebt.IsSleeping = false; + + ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration + { + Sleeping = false + }); + + API.World.Calendar.RemoveTimeSpeedModifier("asu_psp"); + + SendMessageTo(isp, "Restored default calendar speed"); + } + } + + return TextCommandResult.Success(); + } + private void OnCheckSleepingPlayers() { if (API.Side == EnumAppSide.Client) return; // This must only ever be called on the server! @@ -252,7 +352,14 @@ namespace AriasServerUtils } SleepingPlayers.Clear(); - API.World.Calendar.CalendarSpeedMul = OriginalSpeed; + + + ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration + { + Sleeping = false + }); + + API.World.Calendar.RemoveTimeSpeedModifier("asu_psp"); } return; } @@ -311,7 +418,12 @@ namespace AriasServerUtils Hours = API.World.Calendar.TotalHours; Sleeping = true; - API.World.Calendar.CalendarSpeedMul = 4; + ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration + { + Sleeping = true + }); + + API.World.Calendar.SetTimeSpeedModifier("asu_psp", 500); } } } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 6d14c13..3aec4e6 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 6:56 PM MST", - "version": "1.0.7-dev.2", + "description": "A collection of server utilities\n\nBuild Date: 03-11-2025 @ 00:37 AM MST", + "version": "1.0.7-dev.3", "dependencies": { "game": "" } diff --git a/AriasServerUtils/network/ASUTimeAccelPacket.cs b/AriasServerUtils/network/ASUTimeAccelPacket.cs new file mode 100644 index 0000000..bb66753 --- /dev/null +++ b/AriasServerUtils/network/ASUTimeAccelPacket.cs @@ -0,0 +1,7 @@ +using System; + +[Serializable] +public class ASUTimeAcceleration +{ + public bool Sleeping = false; +} \ No newline at end of file From 3ab3dc099f7a0bd4ec69ee55a6a350d1cde3982c Mon Sep 17 00:00:00 2001 From: zontreck Date: Tue, 11 Mar 2025 00:55:21 -0700 Subject: [PATCH 46/58] Adds a initial basic version of player sleeping percentage. --- AriasServerUtils/ModSystems/ASUServer.cs | 34 ++++++++++--------- .../assets/ariasserverutils/lang/en.json | 5 ++- AriasServerUtils/modinfo.json | 4 +-- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/AriasServerUtils/ModSystems/ASUServer.cs b/AriasServerUtils/ModSystems/ASUServer.cs index c5d6d75..31b6bab 100644 --- a/AriasServerUtils/ModSystems/ASUServer.cs +++ b/AriasServerUtils/ModSystems/ASUServer.cs @@ -238,7 +238,7 @@ namespace AriasServerUtils .HandleWith(Events.HandleASU) .WithDescription("Lists all Aria's Server Utils commands") .EndSubCommand() - .BeginSubCommand("test") + /*.BeginSubCommand("test") .RequiresPlayer() .RequiresPrivilege(Privilege.controlserver) .BeginSubCommand("sleep") @@ -251,7 +251,7 @@ namespace AriasServerUtils .RequiresPrivilege(Privilege.controlserver) .HandleWith(TestCalendarSpeed) .EndSubCommand() - .EndSubCommand(); + .EndSubCommand()*/ ; api.ChatCommands.Create("setwarp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Creates a new server warp").WithArgs(parsers.OptionalWord("name")).HandleWith(Events.HandleWarpUpdate); api.ChatCommands.Create("warp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Warp to the specified server warp").WithArgs(parsers.OptionalWord("name")).HandleWith(Events.HandleWarp); @@ -286,7 +286,7 @@ namespace AriasServerUtils Sleeping = true }); - API.World.Calendar.SetTimeSpeedModifier("asu_psp", 500); + API.World.Calendar.SetTimeSpeedModifier("asu_psp", 1000); } return TextCommandResult.Success($"Test initiated, original calendar multiplier: '{OriginalSpeed}'"); @@ -313,7 +313,7 @@ namespace AriasServerUtils Sleeping = true }); - API.World.Calendar.SetTimeSpeedModifier("asu_psp", 500); + API.World.Calendar.SetTimeSpeedModifier("asu_psp", 1000); SendMessageTo(isp, "Applied calendar speed multiplier"); } @@ -349,6 +349,7 @@ namespace AriasServerUtils { EntityBehaviorTiredness ebt = player.GetBehavior("tiredness") as EntityBehaviorTiredness; ebt.IsSleeping = false; + ebt.Tiredness = 0; } SleepingPlayers.Clear(); @@ -403,6 +404,14 @@ namespace AriasServerUtils int Percentage = TotalInBed * 100 / TotalOnline; if (Percentage >= config.PlayerSleepingPercentage) { + + ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration + { + Sleeping = true + }); + + API.World.Calendar.SetTimeSpeedModifier("asu_psp", 1000); + // Call the API to make sleep happen foreach (var bed in BEBs) { @@ -412,19 +421,12 @@ namespace AriasServerUtils EntityBehaviorTiredness EBT = bed.MountedBy.GetBehavior("tiredness") as EntityBehaviorTiredness; EBT.IsSleeping = true; - - // Get current calendar speed - OriginalSpeed = API.World.Calendar.CalendarSpeedMul; - Hours = API.World.Calendar.TotalHours; - Sleeping = true; - - ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration - { - Sleeping = true - }); - - API.World.Calendar.SetTimeSpeedModifier("asu_psp", 500); + bed.MountedBy.TryUnmount(); // Stand up. We cant trigger the real sleep phase, but all code for starting time accel has been executed. } + + // Get current calendar speed + Hours = API.World.Calendar.TotalHours; + Sleeping = true; } } diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index cf23780..162d5a9 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -40,5 +40,8 @@ "rtp-fail": "Giving up on RTP search. No valid position could be found. Try again later", "rtp-capped": "The distance you tried to go [{0}] is greater than the maximum allowable by the server [{1}]", - "cmd-cooldown": "[{0}] is currently on cooldown. You can use this command again in [{1}]" + "cmd-cooldown": "[{0}] is currently on cooldown. You can use this command again in [{1}]", + + "psp": "[ASU] PSP Starting... you do not need to stay in bed", + "psp-ending": "[ASU] PSP Complete" } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 3aec4e6..e8035c4 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-11-2025 @ 00:37 AM MST", - "version": "1.0.7-dev.3", + "description": "A collection of server utilities\n\nBuild Date: 03-11-2025 @ 00:52 AM MST", + "version": "1.0.7", "dependencies": { "game": "" } From 37a1c8d3619862a254ba7b1fde79a14622e3083f Mon Sep 17 00:00:00 2001 From: zontreck Date: Tue, 11 Mar 2025 01:05:41 -0700 Subject: [PATCH 47/58] Issue a hotfix for a small issue that happens when no players are online. --- AriasServerUtils/ModSystems/ASUServer.cs | 1 + AriasServerUtils/modinfo.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/AriasServerUtils/ModSystems/ASUServer.cs b/AriasServerUtils/ModSystems/ASUServer.cs index 31b6bab..61a35d8 100644 --- a/AriasServerUtils/ModSystems/ASUServer.cs +++ b/AriasServerUtils/ModSystems/ASUServer.cs @@ -368,6 +368,7 @@ namespace AriasServerUtils // Iterate over all players, get their entity, check if mounted on a bed. // If mounted on a bed, check tiredness int TotalOnline = API.World.AllOnlinePlayers.Length; + if (TotalOnline == 0) return; // No one on, just abort the checks. int TotalInBed = 0; bool isAlreadySleeping = false; diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index e8035c4..0decec5 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -4,7 +4,7 @@ "name": "Aria's Server Utilities", "authors": ["zontreck"], "description": "A collection of server utilities\n\nBuild Date: 03-11-2025 @ 00:52 AM MST", - "version": "1.0.7", + "version": "1.0.7-1", "dependencies": { "game": "" } From 11f52de3f73914c081eb76f2159c26c05a83e9c6 Mon Sep 17 00:00:00 2001 From: zontreck Date: Tue, 11 Mar 2025 01:05:50 -0700 Subject: [PATCH 48/58] Bump version 1.0.8 --- AriasServerUtils/modinfo.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 0decec5..70884e3 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-11-2025 @ 00:52 AM MST", - "version": "1.0.7-1", + "description": "A collection of server utilities\n\nBuild Date: 03-11-2025 @ 1:05 AM MST", + "version": "1.0.8", "dependencies": { "game": "" } From 268834b434f4f73108d2948ed18eec21cdaa907c Mon Sep 17 00:00:00 2001 From: zontreck Date: Thu, 24 Apr 2025 11:35:01 -0700 Subject: [PATCH 49/58] Patch for 1.20.9 --- AriasServerUtils/ModSystems/ASUServer.cs | 8 ++++---- AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/AriasServerUtils/ModSystems/ASUServer.cs b/AriasServerUtils/ModSystems/ASUServer.cs index 61a35d8..b00aa66 100644 --- a/AriasServerUtils/ModSystems/ASUServer.cs +++ b/AriasServerUtils/ModSystems/ASUServer.cs @@ -347,7 +347,7 @@ namespace AriasServerUtils Sleeping = false; foreach (var player in SleepingPlayers) { - EntityBehaviorTiredness ebt = player.GetBehavior("tiredness") as EntityBehaviorTiredness; + EntityBehaviorTiredness ebt = player.GetBehavior(); ebt.IsSleeping = false; ebt.Tiredness = 0; } @@ -387,13 +387,13 @@ namespace AriasServerUtils { if (SleepingPlayers.Contains(ePlay)) { - EntityBehaviorTiredness ebt = ePlay.GetBehavior("tiredness") as EntityBehaviorTiredness; + EntityBehaviorTiredness ebt = ePlay.GetBehavior(); if (ebt != null) ebt.IsSleeping = false; } } - EntityBehaviorTiredness EBT = ePlay.GetBehavior("tiredness") as EntityBehaviorTiredness; + EntityBehaviorTiredness EBT = ePlay.GetBehavior(); if (EBT == null) continue; if (EBT.IsSleeping) isAlreadySleeping = true; } @@ -419,7 +419,7 @@ namespace AriasServerUtils if (bed.MountedBy != null) SleepingPlayers.Add(bed.MountedBy); // Start sleep - EntityBehaviorTiredness EBT = bed.MountedBy.GetBehavior("tiredness") as EntityBehaviorTiredness; + EntityBehaviorTiredness EBT = bed.MountedBy.GetBehavior(); EBT.IsSleeping = true; bed.MountedBy.TryUnmount(); // Stand up. We cant trigger the real sleep phase, but all code for starting time accel has been executed. diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 70884e3..faddc0d 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-11-2025 @ 1:05 AM MST", - "version": "1.0.8", + "description": "A collection of server utilities\n\nBuild Date: 04-24-2025 @ 11:26 AM MST", + "version": "1.0.9", "dependencies": { "game": "" } From 7ca713e42a1921ca69da89b3b4561ff61c4651bb Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 3 May 2025 12:36:01 -0700 Subject: [PATCH 50/58] Fix: #4 --- AriasServerUtils/EventHandler.cs | 2 +- AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 1b5a646..b284c3d 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -344,7 +344,7 @@ namespace AriasServerUtils ServerUtilities.NewBackCacheForPlayer(isp); ServerUtilities.serverWarps.warps[name].Location.Merge(isp.Entity); - ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:warp-set", name)); + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:warp-tp", name)); diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index faddc0d..93e2621 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 04-24-2025 @ 11:26 AM MST", - "version": "1.0.9", + "description": "A collection of server utilities\n\nBuild Date: 05-3-2025 @ 12:34 PM MST", + "version": "1.0.10-dev.1", "dependencies": { "game": "" } From 4c585f647eb8998616a6af35be6167b2337f1ef0 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 3 May 2025 12:40:50 -0700 Subject: [PATCH 51/58] Remove old deprecated code in RTPFactory --- AriasServerUtils/RTPFactory.cs | 36 ---------------------------------- AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 2 insertions(+), 38 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index ef37717..d2544a2 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -59,42 +59,6 @@ public class RTPFactory check.Y = height + 1; PPos.Y = height + 1; return PPos; - - int Y = 255; - bool lastBlockAir = true; - bool lastLastBlockAir = true; - bool curBlockAir = true; - bool safe = false; - for (Y = 255; Y > 1; Y--) - { - // Manually scan downwards - check.Y = Y; - var current = BA.GetBlock(check); - - if (current.BlockMaterial != EnumBlockMaterial.Air) - { - curBlockAir = false; - } - - - - lastLastBlockAir = lastBlockAir; - lastBlockAir = curBlockAir; - - - if (!curBlockAir && lastBlockAir && lastLastBlockAir) - { - // We found a safe spot to land - check.Y++; - safe = true; - break; - } - } - - if (!safe) return null; - - PPos.Y = check.Y; - return PPos; } /// diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 93e2621..bc18a83 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 05-3-2025 @ 12:34 PM MST", - "version": "1.0.10-dev.1", + "description": "A collection of server utilities\n\nBuild Date: 05-3-2025 @ 12:40 PM MST", + "version": "1.0.10-dev.2", "dependencies": { "game": "" } From e56a123cb8daa3b25fd20777a9f45e2adde87633 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 3 May 2025 12:53:44 -0700 Subject: [PATCH 52/58] #5: Add debug to player sleeping percentage --- AriasServerUtils/EventHandler.cs | 11 +++++++++++ AriasServerUtils/ModSystems/ASUClient.cs | 3 ++- AriasServerUtils/ModSystems/ASUServer.cs | 18 +++++++++++------- AriasServerUtils/modinfo.json | 4 ++-- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index b284c3d..b4af602 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -7,6 +7,7 @@ using Vintagestory.API.Config; using Vintagestory.API.MathTools; using Vintagestory.API.Server; using Vintagestory.API.Util; +using Vintagestory.GameContent; namespace AriasServerUtils { @@ -577,5 +578,15 @@ namespace AriasServerUtils } return TextCommandResult.Success(sReturn); } + + internal static TextCommandResult HandleSleepyDebug(TextCommandCallingArgs args) + { + EntityBehaviorTiredness sleepy = args.Caller.Entity.GetBehavior(); + if (sleepy != null) + { + sleepy.Tiredness = 100; + } + return TextCommandResult.Success(); + } } } \ No newline at end of file diff --git a/AriasServerUtils/ModSystems/ASUClient.cs b/AriasServerUtils/ModSystems/ASUClient.cs index 2f678b3..3374d49 100644 --- a/AriasServerUtils/ModSystems/ASUClient.cs +++ b/AriasServerUtils/ModSystems/ASUClient.cs @@ -24,10 +24,11 @@ public class ASUModClient : ModSystem { // Time acceleration handler accel = packet.Sleeping; + CAPI.Logger.Notification("Time acceleration: " + packet.Sleeping); if (accel) { - CAPI.World.Calendar.SetTimeSpeedModifier("asu_psp", 500); + CAPI.World.Calendar.SetTimeSpeedModifier("asu_psp", 1000); } else CAPI.World.Calendar.RemoveTimeSpeedModifier("asu_psp"); } diff --git a/AriasServerUtils/ModSystems/ASUServer.cs b/AriasServerUtils/ModSystems/ASUServer.cs index b00aa66..859f43f 100644 --- a/AriasServerUtils/ModSystems/ASUServer.cs +++ b/AriasServerUtils/ModSystems/ASUServer.cs @@ -238,7 +238,7 @@ namespace AriasServerUtils .HandleWith(Events.HandleASU) .WithDescription("Lists all Aria's Server Utils commands") .EndSubCommand() - /*.BeginSubCommand("test") + .BeginSubCommand("test") .RequiresPlayer() .RequiresPrivilege(Privilege.controlserver) .BeginSubCommand("sleep") @@ -246,12 +246,7 @@ namespace AriasServerUtils .RequiresPrivilege(Privilege.controlserver) .HandleWith(TestSleep) .EndSubCommand() - .BeginSubCommand("calendarspeed") - .RequiresPlayer() - .RequiresPrivilege(Privilege.controlserver) - .HandleWith(TestCalendarSpeed) - .EndSubCommand() - .EndSubCommand()*/ ; + .EndSubCommand(); api.ChatCommands.Create("setwarp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Creates a new server warp").WithArgs(parsers.OptionalWord("name")).HandleWith(Events.HandleWarpUpdate); api.ChatCommands.Create("warp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Warp to the specified server warp").WithArgs(parsers.OptionalWord("name")).HandleWith(Events.HandleWarp); @@ -263,12 +258,16 @@ namespace AriasServerUtils api.ChatCommands.Create("rtp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithArgs(parsers.OptionalInt("maxDist", defaultValue: -1)).WithDescription("Seeks a position possibly thousands of blocks away to teleport to.").HandleWith(Events.HandleRTP); api.ChatCommands.Create("listcooldowns").RequiresPrivilege(Privilege.chat).WithDescription("Lists the cooldown settings on the server, as well as your own active cooldowns if applicable.").HandleWith(Events.HandleListCooldowns); + + api.ChatCommands.Create("debugasu_sleepy").RequiresPlayer().RequiresPrivilege(Privilege.controlserver).WithDescription("Debugging command to test the sleeping system").HandleWith(Events.HandleSleepyDebug); } private TextCommandResult TestSleep(TextCommandCallingArgs args) { // Initiate the sleep process // Basically run all the same commands as we would on a player in bed + Events.HandleSleepyDebug(args); + OriginalSpeed = API.World.Calendar.CalendarSpeedMul; if (args.Caller.Player is IServerPlayer isp) { @@ -361,6 +360,8 @@ namespace AriasServerUtils }); API.World.Calendar.RemoveTimeSpeedModifier("asu_psp"); + + API.Logger.Notification("Stopping PSP Time Acceleration"); } return; } @@ -422,6 +423,9 @@ namespace AriasServerUtils EntityBehaviorTiredness EBT = bed.MountedBy.GetBehavior(); EBT.IsSleeping = true; + + API.Logger.Notification("Starting PSP Time Acceleration"); + bed.MountedBy.TryUnmount(); // Stand up. We cant trigger the real sleep phase, but all code for starting time accel has been executed. } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index bc18a83..be4f659 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 05-3-2025 @ 12:40 PM MST", - "version": "1.0.10-dev.2", + "description": "A collection of server utilities\n\nBuild Date: 05-3-2025 @ 12:53 PM MST", + "version": "1.0.10-dev.3", "dependencies": { "game": "" } From 12d10a9a3c231e057e9d45e848a796eff9ed2846 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 3 May 2025 13:57:36 -0700 Subject: [PATCH 53/58] Attempt to fix time accel on server Part of #5 --- AriasServerUtils/ModSystems/ASUClient.cs | 16 -------- AriasServerUtils/ModSystems/ASUServer.cs | 39 +++---------------- AriasServerUtils/modinfo.json | 4 +- .../network/ASUTimeAccelPacket.cs | 7 ---- 4 files changed, 8 insertions(+), 58 deletions(-) delete mode 100644 AriasServerUtils/network/ASUTimeAccelPacket.cs diff --git a/AriasServerUtils/ModSystems/ASUClient.cs b/AriasServerUtils/ModSystems/ASUClient.cs index 3374d49..2966dc3 100644 --- a/AriasServerUtils/ModSystems/ASUClient.cs +++ b/AriasServerUtils/ModSystems/ASUClient.cs @@ -15,21 +15,5 @@ public class ASUModClient : ModSystem public override void StartClientSide(ICoreClientAPI api) { CAPI = api; - api.Network.RegisterChannel("asutimeaccel") - .RegisterMessageType() - .SetMessageHandler(onReceiveTimeAccel); - } - - private void onReceiveTimeAccel(ASUTimeAcceleration packet) - { - // Time acceleration handler - accel = packet.Sleeping; - CAPI.Logger.Notification("Time acceleration: " + packet.Sleeping); - - if (accel) - { - CAPI.World.Calendar.SetTimeSpeedModifier("asu_psp", 1000); - } - else CAPI.World.Calendar.RemoveTimeSpeedModifier("asu_psp"); } } \ No newline at end of file diff --git a/AriasServerUtils/ModSystems/ASUServer.cs b/AriasServerUtils/ModSystems/ASUServer.cs index 859f43f..8c3becd 100644 --- a/AriasServerUtils/ModSystems/ASUServer.cs +++ b/AriasServerUtils/ModSystems/ASUServer.cs @@ -96,10 +96,6 @@ namespace AriasServerUtils //api.Event.PlayerLeave += OnPlayerDC; - ServerNetworkChannel = api.Network.RegisterChannel("asutimeaccel") - .RegisterMessageType(); - - api.ChatCommands.Create("setspawn").RequiresPrivilege(Privilege.controlserver).HandleWith(Events.HandleSetSpawn); api.ChatCommands.Create("spawn").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleSpawn); @@ -273,18 +269,15 @@ namespace AriasServerUtils { Hours = API.World.Calendar.TotalHours; SleepingPlayers.Add(isp.Entity); + API.Logger.Notification($"Game Hours: {API.World.Calendar.TotalHours}, Difference: {API.World.Calendar.TotalHours - Hours}"); EntityAgent Agent = isp.Entity; - EntityBehaviorTiredness ebt = Agent.GetBehavior("tiredness") as EntityBehaviorTiredness; + + EntityBehaviorTiredness ebt = Agent.GetBehavior(); + ebt.IsSleeping = true; ebt.Tiredness = 100; Sleeping = true; - - ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration - { - Sleeping = true - }); - API.World.Calendar.SetTimeSpeedModifier("asu_psp", 1000); } @@ -307,11 +300,6 @@ namespace AriasServerUtils OriginalSpeed = 0.5f; ebt.IsSleeping = true; - ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration - { - Sleeping = true - }); - API.World.Calendar.SetTimeSpeedModifier("asu_psp", 1000); SendMessageTo(isp, "Applied calendar speed multiplier"); @@ -322,11 +310,6 @@ namespace AriasServerUtils OriginalSpeed = 0; ebt.IsSleeping = false; - ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration - { - Sleeping = false - }); - API.World.Calendar.RemoveTimeSpeedModifier("asu_psp"); SendMessageTo(isp, "Restored default calendar speed"); @@ -341,7 +324,8 @@ namespace AriasServerUtils if (API.Side == EnumAppSide.Client) return; // This must only ever be called on the server! if (Sleeping) { - if (API.World.Calendar.TotalHours - Hours >= 7) + API.Logger.Notification($"Game Hours: {API.World.Calendar.TotalHours}, Difference: {API.World.Calendar.TotalHours - Hours}"); + if (API.World.Calendar.TotalHours - Hours >= 6) { Sleeping = false; foreach (var player in SleepingPlayers) @@ -353,12 +337,6 @@ namespace AriasServerUtils SleepingPlayers.Clear(); - - ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration - { - Sleeping = false - }); - API.World.Calendar.RemoveTimeSpeedModifier("asu_psp"); API.Logger.Notification("Stopping PSP Time Acceleration"); @@ -407,11 +385,6 @@ namespace AriasServerUtils if (Percentage >= config.PlayerSleepingPercentage) { - ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration - { - Sleeping = true - }); - API.World.Calendar.SetTimeSpeedModifier("asu_psp", 1000); // Call the API to make sleep happen diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index be4f659..60ec0b3 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 05-3-2025 @ 12:53 PM MST", - "version": "1.0.10-dev.3", + "description": "A collection of server utilities\n\nBuild Date: 05-3-2025 @ 1:56 PM MST", + "version": "1.0.10-dev.9", "dependencies": { "game": "" } diff --git a/AriasServerUtils/network/ASUTimeAccelPacket.cs b/AriasServerUtils/network/ASUTimeAccelPacket.cs deleted file mode 100644 index bb66753..0000000 --- a/AriasServerUtils/network/ASUTimeAccelPacket.cs +++ /dev/null @@ -1,7 +0,0 @@ -using System; - -[Serializable] -public class ASUTimeAcceleration -{ - public bool Sleeping = false; -} \ No newline at end of file From b00e56fdf74e4a05c87576fe6327231ae69cee8d Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 3 May 2025 14:02:17 -0700 Subject: [PATCH 54/58] Ensure time accel is disabled when world is fully loaded. Part of #5 --- AriasServerUtils/ModSystems/ASUServer.cs | 7 +++++++ AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/AriasServerUtils/ModSystems/ASUServer.cs b/AriasServerUtils/ModSystems/ASUServer.cs index 8c3becd..07b5e45 100644 --- a/AriasServerUtils/ModSystems/ASUServer.cs +++ b/AriasServerUtils/ModSystems/ASUServer.cs @@ -29,6 +29,7 @@ namespace AriasServerUtils internal static Warps serverWarps = new Warps(); internal static Random rng = new Random((int)TimeUtil.GetUnixEpochTimestamp()); + internal bool isFirstStart = true; internal static string[] saveInvTypes = new string[] { @@ -322,6 +323,12 @@ namespace AriasServerUtils private void OnCheckSleepingPlayers() { if (API.Side == EnumAppSide.Client) return; // This must only ever be called on the server! + if (isFirstStart) + { + API.World.Calendar.RemoveTimeSpeedModifier("asu_psp"); + isFirstStart = false; + } + if (Sleeping) { API.Logger.Notification($"Game Hours: {API.World.Calendar.TotalHours}, Difference: {API.World.Calendar.TotalHours - Hours}"); diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 60ec0b3..6d99817 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 05-3-2025 @ 1:56 PM MST", - "version": "1.0.10-dev.9", + "description": "A collection of server utilities\n\nBuild Date: 05-3-2025 @ 2:01 PM MST", + "version": "1.0.10-dev.10", "dependencies": { "game": "" } From 7fb2d38c3d2ebb6ccfcbf0f09a37b5b968eca76e Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 3 May 2025 14:21:28 -0700 Subject: [PATCH 55/58] Fix: #5 --- AriasServerUtils/ModSystems/ASUServer.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/AriasServerUtils/ModSystems/ASUServer.cs b/AriasServerUtils/ModSystems/ASUServer.cs index 07b5e45..df4957e 100644 --- a/AriasServerUtils/ModSystems/ASUServer.cs +++ b/AriasServerUtils/ModSystems/ASUServer.cs @@ -357,8 +357,6 @@ namespace AriasServerUtils if (TotalOnline == 0) return; // No one on, just abort the checks. int TotalInBed = 0; - bool isAlreadySleeping = false; - List BEBs = new(); foreach (var player in API.World.AllOnlinePlayers) @@ -368,9 +366,12 @@ namespace AriasServerUtils { BEBs.Add(beb); TotalInBed++; + //API.Logger.Notification($"Bed found for player {player.PlayerName}"); } if (ePlay.MountedOn == null) { + //API.Logger.Notification($"No bed found for player {player.PlayerName}"); + if (SleepingPlayers.Contains(ePlay)) { EntityBehaviorTiredness ebt = ePlay.GetBehavior(); @@ -378,17 +379,16 @@ namespace AriasServerUtils ebt.IsSleeping = false; } } - - EntityBehaviorTiredness EBT = ePlay.GetBehavior(); - if (EBT == null) continue; - if (EBT.IsSleeping) isAlreadySleeping = true; } - if (isAlreadySleeping) return; // Abort + if (Sleeping) return; // Abort SleepingPlayers.Clear(); int Percentage = TotalInBed * 100 / TotalOnline; + + API.Logger.Notification($"Percentage of players in bed: ${Percentage}, Required percentage: ${config.PlayerSleepingPercentage}"); + if (Percentage >= config.PlayerSleepingPercentage) { From 9715975a48522a3a502201cbbc4527d1f17e3988 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 3 May 2025 14:23:18 -0700 Subject: [PATCH 56/58] Release 1.0.10 --- AriasServerUtils/ModSystems/ASUServer.cs | 15 +++++++++------ AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/AriasServerUtils/ModSystems/ASUServer.cs b/AriasServerUtils/ModSystems/ASUServer.cs index df4957e..680db83 100644 --- a/AriasServerUtils/ModSystems/ASUServer.cs +++ b/AriasServerUtils/ModSystems/ASUServer.cs @@ -243,6 +243,11 @@ namespace AriasServerUtils .RequiresPrivilege(Privilege.controlserver) .HandleWith(TestSleep) .EndSubCommand() + .BeginSubCommand("sleepy") + .RequiresPlayer() + .RequiresPrivilege(Privilege.controlserver) + .HandleWith(Events.HandleSleepyDebug) + .EndSubCommand() .EndSubCommand(); api.ChatCommands.Create("setwarp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Creates a new server warp").WithArgs(parsers.OptionalWord("name")).HandleWith(Events.HandleWarpUpdate); @@ -255,8 +260,6 @@ namespace AriasServerUtils api.ChatCommands.Create("rtp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithArgs(parsers.OptionalInt("maxDist", defaultValue: -1)).WithDescription("Seeks a position possibly thousands of blocks away to teleport to.").HandleWith(Events.HandleRTP); api.ChatCommands.Create("listcooldowns").RequiresPrivilege(Privilege.chat).WithDescription("Lists the cooldown settings on the server, as well as your own active cooldowns if applicable.").HandleWith(Events.HandleListCooldowns); - - api.ChatCommands.Create("debugasu_sleepy").RequiresPlayer().RequiresPrivilege(Privilege.controlserver).WithDescription("Debugging command to test the sleeping system").HandleWith(Events.HandleSleepyDebug); } private TextCommandResult TestSleep(TextCommandCallingArgs args) @@ -331,7 +334,7 @@ namespace AriasServerUtils if (Sleeping) { - API.Logger.Notification($"Game Hours: {API.World.Calendar.TotalHours}, Difference: {API.World.Calendar.TotalHours - Hours}"); + //API.Logger.Notification($"Game Hours: {API.World.Calendar.TotalHours}, Difference: {API.World.Calendar.TotalHours - Hours}"); if (API.World.Calendar.TotalHours - Hours >= 6) { Sleeping = false; @@ -346,7 +349,7 @@ namespace AriasServerUtils API.World.Calendar.RemoveTimeSpeedModifier("asu_psp"); - API.Logger.Notification("Stopping PSP Time Acceleration"); + //API.Logger.Notification("Stopping PSP Time Acceleration"); } return; } @@ -387,7 +390,7 @@ namespace AriasServerUtils int Percentage = TotalInBed * 100 / TotalOnline; - API.Logger.Notification($"Percentage of players in bed: ${Percentage}, Required percentage: ${config.PlayerSleepingPercentage}"); + //API.Logger.Notification($"Percentage of players in bed: {Percentage}, Required percentage: {config.PlayerSleepingPercentage}"); if (Percentage >= config.PlayerSleepingPercentage) { @@ -404,7 +407,7 @@ namespace AriasServerUtils EBT.IsSleeping = true; - API.Logger.Notification("Starting PSP Time Acceleration"); + //API.Logger.Notification("Starting PSP Time Acceleration"); bed.MountedBy.TryUnmount(); // Stand up. We cant trigger the real sleep phase, but all code for starting time accel has been executed. } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 6d99817..594c49e 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 05-3-2025 @ 2:01 PM MST", - "version": "1.0.10-dev.10", + "description": "A collection of server utilities\n\nBuild Date: 05-3-2025 @ 2:23 PM MST", + "version": "1.0.10", "dependencies": { "game": "" } From 419c05dbacd32bebb246c5a50f71115caa0ce35a Mon Sep 17 00:00:00 2001 From: zontreck Date: Wed, 7 May 2025 12:15:23 -0700 Subject: [PATCH 57/58] Add farmland drop --- AriasServerUtils/EventHandler.cs | 80 +++++++++++++++++++ AriasServerUtils/Globals.cs | 16 +++- AriasServerUtils/ModSystems/ASUServer.cs | 13 +++ .../assets/ariasserverutils/lang/en.json | 3 + AriasServerUtils/modinfo.json | 4 +- 5 files changed, 113 insertions(+), 3 deletions(-) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index b4af602..c7fa6c4 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -559,6 +559,38 @@ namespace AriasServerUtils else return TextCommandResult.Success(); } + + internal static TextCommandResult HandleUpdateASUFarmlandDowngrade(TextCommandCallingArgs args) + { + if (args[0] is bool downgrade) + { + // Update the flag + ServerUtilities.config.EnableFarmlandDowngrade = downgrade; + ServerUtilities.MarkDirty(); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } + else + { + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:farmland-downgrade", ServerUtilities.config.EnableFarmlandDowngrade)); + } + } + + + internal static TextCommandResult HandleUpdateASUFarmlandDrop(TextCommandCallingArgs args) + { + if (args[0] is bool drop) + { + // Update the flag + ServerUtilities.config.EnableFarmlandDrop = drop; + ServerUtilities.MarkDirty(); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } + else + { + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:farmland-drop", ServerUtilities.config.EnableFarmlandDrop)); + } + } + internal static TextCommandResult HandleListCooldowns(TextCommandCallingArgs args) { string sReturn = "SERVER COOLDOWN SETTINGS\n"; @@ -588,5 +620,53 @@ namespace AriasServerUtils } return TextCommandResult.Success(); } + + internal static void CheckBreakFarmland(IServerPlayer byPlayer, BlockSelection blockSel, ref float dropQuantityMultiplier, ref EnumHandling handling) + { + if (!ServerUtilities.config.EnableFarmlandDrop) + { + return; // Default behavior + } + + if (blockSel.Block is BlockFarmland farmland) + { + BlockEntityFarmland beFarmland = farmland.GetBlockEntity(blockSel.Position); + string farmlandType = blockSel.Block.LastCodePart(); + + if (ServerUtilities.config.EnableFarmlandDowngrade) + { + + switch (farmlandType) + { + case "verylow": + { // barren + break; // Can't downgrade further + } + case "low": + { + farmlandType = "verylow"; + break; + } + case "medium": + { + farmlandType = "low"; + break; + } + case "compost": + { // high + farmlandType = "medium"; + break; + } + case "high": + { // Terra preta + farmlandType = "compost"; + break; + } + } + } + + byPlayer.Entity.World.SpawnItemEntity(new ItemStack(byPlayer.Entity.World.GetBlock(new AssetLocation($"soil-{farmlandType}-none"))), blockSel.Position.ToVec3d().Add(0.5, 0.5, 0.5)); + } + } } } \ No newline at end of file diff --git a/AriasServerUtils/Globals.cs b/AriasServerUtils/Globals.cs index a98b5cc..3436bbf 100644 --- a/AriasServerUtils/Globals.cs +++ b/AriasServerUtils/Globals.cs @@ -22,7 +22,7 @@ namespace AriasServerUtils { CooldownType.RTP, "30s" }, { CooldownType.Back, "5s" } }; - private static readonly int CURRENT_VERSION = 5; + private static readonly int CURRENT_VERSION = 6; public int Version { get; set; } = 0; @@ -36,11 +36,25 @@ namespace AriasServerUtils public int MaxRTPBlockDistance { get; set; } = 50000; public Dictionary Cooldowns { get; set; } = new Dictionary(); + + /// + /// If true, attempts to downgrade the soil quality when breaking farmland. + /// + public bool EnableFarmlandDowngrade { get; set; } = false; + + /// + /// If true, farmland will drop as soil when broken. + /// + public bool EnableFarmlandDrop { get; set; } = true; + public Dictionary GetDefaultCooldowns() { return m_defaultCD; } + /// + /// Performs some checks against known possible invalid values and sets them to sane values. + /// public void SanityCheck() { foreach (var cd in GetDefaultCooldowns()) diff --git a/AriasServerUtils/ModSystems/ASUServer.cs b/AriasServerUtils/ModSystems/ASUServer.cs index 680db83..36a590d 100644 --- a/AriasServerUtils/ModSystems/ASUServer.cs +++ b/AriasServerUtils/ModSystems/ASUServer.cs @@ -94,6 +94,7 @@ namespace AriasServerUtils api.Event.PlayerJoin += OnPlayerJoin; api.Event.PlayerDisconnect += OnPlayerDC; api.Event.ChunkColumnLoaded += RTPFactory.ChunkLoaded; + api.Event.BreakBlock += Events.CheckBreakFarmland; //api.Event.PlayerLeave += OnPlayerDC; @@ -181,6 +182,18 @@ namespace AriasServerUtils .WithDescription("Update RTP Max block distance. Plus and/or minus this distance from player current position (Default is 50000)") .HandleWith(Events.HandleUpdateASURTPMax) .EndSubCommand() + .BeginSubCommand("farmlandDowngrade") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs(parsers.OptionalBool("downgrade")) + .WithDescription("Enables or disables farmland downgrade when breaking farmland") + .HandleWith(Events.HandleUpdateASUFarmlandDowngrade) + .EndSubCommand() + .BeginSubCommand("farmlandDrop") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs(parsers.OptionalBool("drop")) + .WithDescription("Enables or disables dropping soil when breaking farmland") + .HandleWith(Events.HandleUpdateASUFarmlandDrop) + .EndSubCommand() .BeginSubCommand("cooldowns") .WithDescription("Commands related to all the various cooldowns") .BeginSubCommand("back") diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index 162d5a9..a53ecdf 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -23,6 +23,9 @@ "updatedconfig": "[ASU] server config updated", "config-value-reset": "[ASU] server config value reset to default", + "farmland-downgrade": "The current farmland downgrade setting is {0}", + "farmland-drop": "The current farmland drop setting is {0}", + "warp-tp": "Teleported to warp [{0}]", "warp-set": "Warp [{0}] created!", "warp-no": "You lack permissions to manage a warp", diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 594c49e..f920863 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 05-3-2025 @ 2:23 PM MST", - "version": "1.0.10", + "description": "A collection of server utilities\n\nBuild Date: 05-7-2025 @ 12:15 AM MST", + "version": "1.0.11-dev.1", "dependencies": { "game": "" } From 45b024654a4f5b6f7a7309ffbcdc0c64eead10c6 Mon Sep 17 00:00:00 2001 From: zontreck Date: Wed, 7 May 2025 12:21:23 -0700 Subject: [PATCH 58/58] Ship 1.0.11 with the farmland feature --- AriasServerUtils/EventHandler.cs | 47 ++++++++++++------- .../assets/ariasserverutils/lang/en.json | 2 +- AriasServerUtils/modinfo.json | 4 +- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index c7fa6c4..6869045 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -275,7 +275,7 @@ namespace AriasServerUtils { ServerUtilities.config.AdminsBypassMaxHomes = bypass; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", bypass)); } return TextCommandResult.Success(); @@ -289,7 +289,7 @@ namespace AriasServerUtils ServerUtilities.config.MaxBackCache = max; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", max)); } return TextCommandResult.Success(); @@ -302,7 +302,7 @@ namespace AriasServerUtils ServerUtilities.config.MaxHomes = maxHomes; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", maxHomes)); } return TextCommandResult.Success(); @@ -311,19 +311,32 @@ namespace AriasServerUtils internal static TextCommandResult HandleUpdateASUMgrWarps(TextCommandCallingArgs args) { if (args[0] is bool mgr) + { ServerUtilities.config.onlyAdminsCreateWarps = mgr; + + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", mgr)); + } else ServerUtilities.config.onlyAdminsCreateWarps = true; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", true)); } internal static TextCommandResult HandleUpdateASUPSP(TextCommandCallingArgs args) { - if (args[0] is int psp) ServerUtilities.config.PlayerSleepingPercentage = psp; - ServerUtilities.MarkDirty(); + if (args[0] is int psp) + { + ServerUtilities.config.PlayerSleepingPercentage = psp; + ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", psp)); + } + + return TextCommandResult.Success(); } internal static TextCommandResult HandleWarp(TextCommandCallingArgs args) @@ -431,7 +444,7 @@ namespace AriasServerUtils ServerUtilities.config.MaxRTPBlockDistance = maxDist; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", maxDist)); } return TextCommandResult.Success(); @@ -444,7 +457,7 @@ namespace AriasServerUtils ServerUtilities.config.Cooldowns[CooldownType.Back] = CD; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", CD)); } else { @@ -462,7 +475,7 @@ namespace AriasServerUtils ServerUtilities.config.Cooldowns[CooldownType.Warp] = CD; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", CD)); } else { @@ -480,7 +493,7 @@ namespace AriasServerUtils ServerUtilities.config.Cooldowns[CooldownType.Home] = CD; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", CD)); } else { @@ -498,7 +511,7 @@ namespace AriasServerUtils ServerUtilities.config.Cooldowns[CooldownType.Spawn] = CD; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", CD)); } else { @@ -516,7 +529,7 @@ namespace AriasServerUtils ServerUtilities.config.Cooldowns[CooldownType.RTP] = CD; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", CD)); } else { @@ -542,7 +555,7 @@ namespace AriasServerUtils // Update the bypass ServerUtilities.config.AdminsBypassCooldowns = bypass; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", bypass)); } else return TextCommandResult.Success(); } @@ -554,7 +567,7 @@ namespace AriasServerUtils // Update the flag ServerUtilities.config.AdminsBypassRTPMaxDistance = bypass; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", bypass)); } else return TextCommandResult.Success(); } @@ -567,7 +580,7 @@ namespace AriasServerUtils // Update the flag ServerUtilities.config.EnableFarmlandDowngrade = downgrade; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", downgrade)); } else { @@ -583,7 +596,7 @@ namespace AriasServerUtils // Update the flag ServerUtilities.config.EnableFarmlandDrop = drop; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", drop)); } else { diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index a53ecdf..7f983a4 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -20,7 +20,7 @@ "help": "All Aria's Server Utilities Commands: \n\nMax Homes: {0}; \nAdmins can bypass max homes: {1}\nMax back positions: {2}\n\n{3}", - "updatedconfig": "[ASU] server config updated", + "updatedconfig": "[ASU] server config updated with the new value: {0}", "config-value-reset": "[ASU] server config value reset to default", "farmland-downgrade": "The current farmland downgrade setting is {0}", diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index f920863..cc1577f 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 05-7-2025 @ 12:15 AM MST", - "version": "1.0.11-dev.1", + "description": "A collection of server utilities\n\nBuild Date: 05-7-2025 @ 12:21 PM MST", + "version": "1.0.11", "dependencies": { "game": "" }