From a715dfa2097c8acb8cf21e3f36ec4b424390c870 Mon Sep 17 00:00:00 2001 From: Byte-Nova <159603018+Byte-Nova@users.noreply.github.com> Date: Wed, 4 Sep 2024 19:44:47 +0200 Subject: [PATCH] Removed update tools and added sort to commands --- .../Updater/DeprecatedDataTypes/Caravan.cs | 24 -- .../DeprecatedDataTypes/DifficultyValues.cs | 96 ------- .../DeprecatedDataTypes/PlayerFactionData.cs | 17 -- .../DeprecatedDataTypes/SettlementData.cs | 17 -- .../Updater/DeprecatedDataTypes/Site.cs | 24 -- .../Updater/DeprecatedDataTypes/User.cs | 41 --- .../DeprecatedDataTypes/WorldValues.cs | 85 ------- .../Server/Managers/Updater/UpdateManager.cs | 239 ------------------ Source/Server/Misc/Commands/CommandStorage.cs | 28 +- 9 files changed, 2 insertions(+), 569 deletions(-) delete mode 100644 Source/Server/Managers/Updater/DeprecatedDataTypes/Caravan.cs delete mode 100644 Source/Server/Managers/Updater/DeprecatedDataTypes/DifficultyValues.cs delete mode 100644 Source/Server/Managers/Updater/DeprecatedDataTypes/PlayerFactionData.cs delete mode 100644 Source/Server/Managers/Updater/DeprecatedDataTypes/SettlementData.cs delete mode 100644 Source/Server/Managers/Updater/DeprecatedDataTypes/Site.cs delete mode 100644 Source/Server/Managers/Updater/DeprecatedDataTypes/User.cs delete mode 100644 Source/Server/Managers/Updater/DeprecatedDataTypes/WorldValues.cs delete mode 100644 Source/Server/Managers/Updater/UpdateManager.cs diff --git a/Source/Server/Managers/Updater/DeprecatedDataTypes/Caravan.cs b/Source/Server/Managers/Updater/DeprecatedDataTypes/Caravan.cs deleted file mode 100644 index 0931eb64..00000000 --- a/Source/Server/Managers/Updater/DeprecatedDataTypes/Caravan.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace GameServer.Updater -{ - public enum CaravanStepMode { Add, Remove, Move } - [Serializable] - public class CaravanDetails - { - public int ID; - public int tile; - public string owner; - public double timeSinceRefresh; - } - [Serializable] - public class CaravanData - { - public CaravanStepMode stepMode; - public CaravanDetails details; - } -} diff --git a/Source/Server/Managers/Updater/DeprecatedDataTypes/DifficultyValues.cs b/Source/Server/Managers/Updater/DeprecatedDataTypes/DifficultyValues.cs deleted file mode 100644 index 1b31937e..00000000 --- a/Source/Server/Managers/Updater/DeprecatedDataTypes/DifficultyValues.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace GameServer.Updater -{ - [Serializable] - public class DifficultyData - { - public float ThreatScale; - - public bool AllowBigThreats; - - public bool AllowViolentQuests; - - public bool AllowIntroThreats; - - public bool PredatorsHuntHumanlikes; - - public bool AllowExtremeWeatherIncidents; - - public float CropYieldFactor; - - public float MineYieldFactor; - - public float ButcherYieldFactor; - - public float ResearchSpeedFactor; - - public float QuestRewardValueFactor; - - public float RaidLootPointsFactor; - - public float TradePriceFactorLoss; - - public float MaintenanceCostFactor; - - public float ScariaRotChance; - - public float EnemyDeathOnDownedChanceFactor; - - public float ColonistMoodOffset; - - public float FoodPoisonChanceFactor; - - public float ManhunterChanceOnDamageFactor; - - public float PlayerPawnInfectionChanceFactor; - - public float DiseaseIntervalFactor; - - public float EnemyReproductionRateFactor; - - public float DeepDrillInfestationChanceFactor; - - public float FriendlyFireChanceFactor; - - public float AllowInstantKillChance; - - public bool PeacefulTemples; - - public bool AllowCaveHives; - - public bool UnwaveringPrisoners; - - public bool AllowTraps; - - public bool AllowTurrets; - - public bool AllowMortars; - - public bool ClassicMortars; - - public float AdaptationEffectFactor; - - public float AdaptationGrowthRateFactorOverZero; - - public bool FixedWealthMode; - - public float LowPopConversionBoost; - - public bool NoBabiesOrChildren; - - public bool BabiesAreHealthy; - - public bool ChildRaidersAllowed; - - public float ChildAgingRate; - - public float AdultAgingRate; - - public float WastepackInfestationChanceFactor; - } -} diff --git a/Source/Server/Managers/Updater/DeprecatedDataTypes/PlayerFactionData.cs b/Source/Server/Managers/Updater/DeprecatedDataTypes/PlayerFactionData.cs deleted file mode 100644 index 7eca91c7..00000000 --- a/Source/Server/Managers/Updater/DeprecatedDataTypes/PlayerFactionData.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace GameServer.Updater -{ - public class FactionFile - { - public string factionName; - - public List factionMembers = new List(); - - public List factionMemberRanks = new List(); - } -} diff --git a/Source/Server/Managers/Updater/DeprecatedDataTypes/SettlementData.cs b/Source/Server/Managers/Updater/DeprecatedDataTypes/SettlementData.cs deleted file mode 100644 index e53f5ee2..00000000 --- a/Source/Server/Managers/Updater/DeprecatedDataTypes/SettlementData.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using static Shared.CommonEnumerators; - -namespace GameServer.Updater -{ - [Serializable] - public class SettlementFile - { - public int tile; - - public string owner; - } -} diff --git a/Source/Server/Managers/Updater/DeprecatedDataTypes/Site.cs b/Source/Server/Managers/Updater/DeprecatedDataTypes/Site.cs deleted file mode 100644 index 913cbccc..00000000 --- a/Source/Server/Managers/Updater/DeprecatedDataTypes/Site.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace GameServer.Updater -{ - [Serializable] - public class SiteFile - { - public int tile; - - public string owner; - - public int type; - - public byte[] workerData; - - public bool isFromFaction; - - public string factionName; - } -} diff --git a/Source/Server/Managers/Updater/DeprecatedDataTypes/User.cs b/Source/Server/Managers/Updater/DeprecatedDataTypes/User.cs deleted file mode 100644 index d0eaf0d5..00000000 --- a/Source/Server/Managers/Updater/DeprecatedDataTypes/User.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace GameServer.Updater -{ - public class UserFile - { - public string Username = "Unknown"; - - public string Password; - - public string Uid; - - public string FactionName; - - public bool HasFaction; - - public bool IsAdmin; - - public bool IsBanned; - - public string SavedIP; - - public double ActivityProtectionTime; - - public double EventProtectionTime; - - public double AidProtectionTime; - - public List RunningMods = new List(); - - public List AllyPlayers = new List(); - - public List EnemyPlayers = new List(); - - [NonSerialized] public Semaphore savingSemaphore = new Semaphore(1, 1); - } -} diff --git a/Source/Server/Managers/Updater/DeprecatedDataTypes/WorldValues.cs b/Source/Server/Managers/Updater/DeprecatedDataTypes/WorldValues.cs deleted file mode 100644 index eab80735..00000000 --- a/Source/Server/Managers/Updater/DeprecatedDataTypes/WorldValues.cs +++ /dev/null @@ -1,85 +0,0 @@ -using static Shared.CommonEnumerators; - -namespace GameServer.Updater -{ - [Serializable] - public class WorldData - { - public WorldStepMode worldStepMode; - - public WorldValuesFile worldValuesFile; - } - [Serializable] - public class WorldValuesFile - { - //Misc - - public int PersistentRandomValue; - - //World Values - - public string SeedString; - public float PlanetCoverage; - public int Rainfall; - public int Temperature; - public int Population; - public float Pollution; - - //World features - - public PlanetFeature[] Features; - - public RoadDetails[] Roads; - - public RiverDetails[] Rivers; - - public PollutionDetails[] PollutedTiles; - - public PlanetNPCFaction[] NPCFactions; - - public PlanetNPCSettlement[] NPCSettlements; - } - - [Serializable] - public class PlanetFeature - { - public string defName; - public string featureName; - public float[] drawCenter; - public float maxDrawSizeInTiles; - } - [Serializable] - public class RoadDetails - { - public string roadDefName; - public int tileA; - public int tileB; - } - [Serializable] - public class RiverDetails - { - public string riverDefName; - public int tileA; - public int tileB; - } - [Serializable] - public class PollutionDetails - { - public int tile; - public float quantity; - } - [Serializable] - public class PlanetNPCFaction - { - public string factionDefName; - public string factionName; - public float[] factionColor; - } - [Serializable] - public class PlanetNPCSettlement - { - public int tile; - public string name; - public string factionDefName; - } -} diff --git a/Source/Server/Managers/Updater/UpdateManager.cs b/Source/Server/Managers/Updater/UpdateManager.cs deleted file mode 100644 index a23f7190..00000000 --- a/Source/Server/Managers/Updater/UpdateManager.cs +++ /dev/null @@ -1,239 +0,0 @@ -using Shared; -using System; -using System.Reflection; -using static Shared.CommonEnumerators; - -namespace GameServer.Updater -{ - public static class Updater - { - private static List factions = new List(); - public static void Update() - { - BackupManager.BackupServer(); - UpdateDifficulty(); - UpdateUserFile(); - UpdateSettlementFiles(); - UpdateSites(); - UpdateCaravan(); - UpdateWorld(); - } - - private static void UpdateDifficulty() - { - string pathToSave = Path.Combine(Master.corePath, "DifficultyValues.json"); - DifficultyData old = Serializer.SerializeFromFile(pathToSave); - - Shared.DifficultyData newDifficulty = new Shared.DifficultyData(); - DifficultyValuesFile newValues = new DifficultyValuesFile(); - - newValues.UseCustomDifficulty = true; - - Type oldType = typeof(DifficultyData); - Type newType = typeof(Shared.DifficultyValuesFile); - FieldInfo[] fields = oldType.GetFields(); - foreach (FieldInfo field in fields) - { - try - { - FieldInfo newField = newType.GetField(field.Name, BindingFlags.Public | BindingFlags.Instance); - newField.SetValue(newDifficulty, field.GetValue(old)); - } catch { } - } - newDifficulty._values = newValues; - Serializer.SerializeToFile(pathToSave, newDifficulty); - } - private static void UpdateUserFile() - { - - string[] userFiles = Directory.GetFiles(Master.usersPath); - foreach(string userFile in userFiles) - { - GameServer.Updater.UserFile old = Serializer.SerializeFromFile(userFile); - GameServer.UserFile newFile = new GameServer.UserFile(); - string[] OldFaction = Directory.GetFiles(Master.factionsPath); - FactionFile oldFactionSite = new FactionFile(); - foreach (string str in OldFaction) - { - FactionFile temp = Serializer.SerializeFromFile(str); - if (temp.factionName == old.FactionName) - { - oldFactionSite = temp; - break; - } - } - newFile.Username = old.Username; - newFile.Password = old.Password; - newFile.Uid = old.Uid; - newFile.IsAdmin = old.IsAdmin; - newFile.IsBanned = old.IsBanned; - newFile.SavedIP = old.SavedIP; - newFile.ActivityProtectionTime = old.ActivityProtectionTime; - newFile.EventProtectionTime = old.EventProtectionTime; - newFile.AidProtectionTime = old.AidProtectionTime; - newFile.RunningMods = old.RunningMods.ToArray(); - Shared.FactionFile factionFile = null; - if (old.HasFaction) { - factionFile = new Shared.FactionFile(); - factionFile.Name = old.FactionName; - factionFile.CurrentMembers = oldFactionSite.factionMembers; - foreach (string str in oldFactionSite.factionMemberRanks) - { - factionFile.CurrentRanks.Add(int.Parse(str)); - } - factions.Add(factionFile); - } - UserRelationshipsFile relationshipsFile = new UserRelationshipsFile(); - relationshipsFile.AllyPlayers = old.AllyPlayers; - relationshipsFile.EnemyPlayers = old.EnemyPlayers; - newFile.FactionFile = factionFile; - newFile.Relationships = relationshipsFile; - Serializer.SerializeToFile(userFile, newFile); - } - } - - private static void UpdateSettlementFiles() - { - string[] userFiles = Directory.GetFiles(Master.settlementsPath); - foreach (string userFile in userFiles) - { - GameServer.Updater.SettlementFile old = Serializer.SerializeFromFile(userFile); - Shared.SettlementFile newfile = new Shared.SettlementFile(); - newfile.Tile = old.tile; - newfile.Owner = old.owner; - newfile.Goodwill = Goodwill.Neutral; - Serializer.SerializeToFile(userFile, newfile); - } - } - - private static void UpdateSites() - { - string[] userFiles = Directory.GetFiles(Master.sitesPath); - foreach (string userFile in userFiles) - { - GameServer.Updater.SiteFile old = Serializer.SerializeFromFile(userFile); - Shared.SiteFile newfile = new Shared.SiteFile(); - newfile.Tile = old.tile; - newfile.Owner = old.owner; - newfile.Type = old.type; - newfile.WorkerData = old.workerData; - Shared.FactionFile faction = null; - if (old.isFromFaction) - { - foreach (Shared.FactionFile file in factions) - { - if (file.Name == old.factionName) - { - faction = file; - break; - } - } - } - newfile.FactionFile = faction; - Serializer.SerializeToFile(userFile, newfile); - } - } - - private static void UpdateCaravan() - { - string[] userFiles = Directory.GetFiles(Master.caravansPath); - foreach (string userFile in userFiles) - { - GameServer.Updater.CaravanDetails old = Serializer.SerializeFromFile(userFile); - Shared.CaravanFile newFile = new Shared.CaravanFile(); - newFile.Tile = old.tile; - newFile.TimeSinceRefresh = old.timeSinceRefresh; - newFile.ID = old.ID; - newFile.Owner = old.owner; - Serializer.SerializeToFile(userFile, newFile); - } - } - - private static void UpdateWorld() - { - string pathToSave = Path.Combine(Master.corePath, "WorldValues.json"); - WorldValuesFile old = Serializer.SerializeFromFile(pathToSave); - - Shared.WorldValuesFile newValues = new Shared.WorldValuesFile(); - - newValues.Pollution = old.Pollution; - newValues.Population = old.Population; - newValues.SeedString = old.SeedString; - newValues.Rainfall = old.Rainfall; - newValues.Temperature = old.Temperature; - newValues.PlanetCoverage = old.PlanetCoverage; - newValues.PersistentRandomValue = old.PersistentRandomValue; - - List newFeatures = new List(); - foreach (PlanetFeature feature in old.Features) - { - Shared.PlanetFeature newfeature = new Shared.PlanetFeature(); - newfeature.defName = feature.defName; - newfeature.name = feature.featureName; - newfeature.drawCenter = feature.drawCenter; - newfeature.maxDrawSizeInTiles = feature.maxDrawSizeInTiles; - newFeatures.Add(newfeature); - } - newValues.Features = newFeatures.ToArray(); - - List newRoads = new List(); - foreach(RoadDetails road in old.Roads) - { - Shared.RoadDetails newRoad = new Shared.RoadDetails(); - newRoad.roadDefName = road.roadDefName; - newRoad.toTile = road.tileB; - newRoad.fromTile = road.tileA; - newRoads.Add(newRoad); - } - newValues.Roads = newRoads.ToArray(); - - List newRivers = new List(); - foreach (RiverDetails river in old.Rivers) - { - Shared.RiverDetails newRiver = new Shared.RiverDetails(); - newRiver.riverDefName = river.riverDefName; - newRiver.fromTile = river.tileA; - newRiver.toTile = river.tileB; - newRivers.Add(newRiver); - } - newValues.Rivers = newRivers.ToArray(); - - List newNpcFactions = new List(); - foreach (PlanetNPCFaction faction in old.NPCFactions) - { - Shared.PlanetNPCFaction newFaction = new Shared.PlanetNPCFaction(); - newFaction.defName = faction.factionDefName; - newFaction.name = faction.factionName; - newFaction.color = faction.factionColor; - newNpcFactions.Add(newFaction); - } - newValues.NPCFactions = newNpcFactions.ToArray(); - - List newNpcSettlement = new List(); - foreach (PlanetNPCSettlement settlement in old.NPCSettlements) - { - Shared.PlanetNPCSettlement newSettlement = new Shared.PlanetNPCSettlement(); - newSettlement.defName = settlement.factionDefName; - newSettlement.name = settlement.name; - newSettlement.tile = settlement.tile; - newNpcSettlement.Add(newSettlement); - } - newValues.NPCSettlements = newNpcSettlement.ToArray(); - - List newPollutedTiles = new List(); - if (old.PollutedTiles != null) - { - foreach (PollutionDetails settlement in old.PollutedTiles) - { - Shared.PollutionDetails newSettlement = new Shared.PollutionDetails(); - newSettlement.tile = settlement.tile; - newSettlement.quantity = settlement.quantity; - newPollutedTiles.Add(newSettlement); - } - } - newValues.PollutedTiles = newPollutedTiles.ToArray(); - - Serializer.SerializeToFile(pathToSave, newValues); - } - } -} diff --git a/Source/Server/Misc/Commands/CommandStorage.cs b/Source/Server/Misc/Commands/CommandStorage.cs index d79e101b..7cd326f2 100644 --- a/Source/Server/Misc/Commands/CommandStorage.cs +++ b/Source/Server/Misc/Commands/CommandStorage.cs @@ -1,4 +1,3 @@ -using GameServer.Updater; using Shared; using static Shared.CommonEnumerators; @@ -10,10 +9,6 @@ public static class CommandStorage "Shows a list of all available commands to use", HelpCommandAction); - private static readonly ServerCommand updateCommand = new ServerCommand("update", 0, - "Update the server from a previous version. DO NOT USE IF ALREADY UP TO DATE", - UpdateCommandAction); - private static readonly ServerCommand backupCommand = new ServerCommand("backup", 0, "Backup the server.", BackupCommandAction); @@ -188,7 +183,6 @@ public static class CommandStorage toggleSyncLocalSaveCommand, toggleUPnPCommand, toggleVerboseLogsCommand, - updateCommand, whitelistAddCommand, whitelistCommand, whitelistRemoveCommand, @@ -199,32 +193,14 @@ private static void HelpCommandAction() { Logger.Title($"List of available commands: [{serverCommands.Count()}]"); Logger.Title("----------------------------------------"); - foreach (ServerCommand command in serverCommands) + + foreach (ServerCommand command in serverCommands.ToList().OrderBy(fetch => fetch.prefix)) { Logger.Warning($"{command.prefix} - {command.description}"); } Logger.Title("----------------------------------------"); } - private static void UpdateCommandAction() - { - //Make sure the user wants to update your world - Logger.Warning("Are you sure you want to update the world? You should only do this if you aren't already up to date."); - Logger.Warning("Please type 'YES' or 'NO'"); - - DeleteWorldQuestion: - string response = Console.ReadLine(); - - if (response == "NO") return; - else if (response != "YES") - { - Logger.Error($"{response} is not a valid option; The options must be capitalized"); - goto DeleteWorldQuestion; - } - Updater.Updater.Update(); - Logger.Warning("Successfully updated world, please restart the server for the changes to fully take effect!"); - } - private static void BackupCommandAction() { BackupManager.BackupServer();