internal static void ServerModMenu() { bool exit = false; while (!exit) { Console.WriteLine("Terraria Server " + Main.versionNumber2 + " - " + ModLoader.versionedName); Console.WriteLine(); var mods = ModLoader.FindMods(); for (int k = 0; k < mods.Length; k++) { Console.Write((k + 1) + "\t\t" + mods[k].DisplayName); Console.WriteLine(" (" + (ModLoader.IsEnabled(mods[k].Name) ? "enabled" : "disabled") + ")"); } if (mods.Length == 0) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"No mods were found in: \"{ModLoader.ModPath}\"\nIf you are running a dedicated server, you may wish to use the 'modpath' command line switch or server config setting to specify a custom mods directory.\n"); Console.ResetColor(); } Console.WriteLine("e\t\tEnable All"); Console.WriteLine("d\t\tDisable All"); Console.WriteLine("r\t\tReload and return to world menu"); Console.WriteLine("Type a number to switch between enabled/disabled"); Console.WriteLine(); Console.WriteLine("Type a command: "); string command = Console.ReadLine(); if (command == null) { command = ""; } command = command.ToLower(); Console.Clear(); if (command == "e") { foreach (var mod in mods) { mod.Enabled = true; } } else if (command == "d") { foreach (var mod in mods) { mod.Enabled = false; } } else if (command == "r") { Console.WriteLine("Unloading mods..."); ModLoader.Unload(); ModLoader.do_Load(null); exit = true; } else if (int.TryParse(command, out int value) && value > 0 && value <= mods.Length) { mods[value - 1].Enabled ^= true; } } }
internal static void SetModEnabled(string modName, bool active) { if (active) { EnabledMods.Add(modName); } else { EnabledMods.Remove(modName); } //save Directory.CreateDirectory(ModPath); string path = ModPath + Path.DirectorySeparatorChar + "enabled.json"; _enabledMods.IntersectWith(ModLoader.FindMods().Select(x => x.Name)); // Clear out mods that no longer exist. string json = JsonConvert.SerializeObject(EnabledMods, Formatting.Indented); File.WriteAllText(path, json); }
private static bool CommandLineModPackOverride() { if (commandLineModPack != "") { try { string fileName = UI.UIModPacks.ModListSaveDirectory + Path.DirectorySeparatorChar + commandLineModPack + ".json"; Directory.CreateDirectory(UI.UIModPacks.ModListSaveDirectory); if (File.Exists(fileName)) { using (StreamReader r = new StreamReader(fileName)) { Console.WriteLine($"Loading specified modpack: {commandLineModPack}\n"); string json = r.ReadToEnd(); string[] modsToEnable = JsonConvert.DeserializeObject <string[]>(json); var mods = ModLoader.FindMods(); foreach (var item in mods) { DisableMod(item); } foreach (string modname in modsToEnable) { foreach (var item in mods) { if (item.name == modname) { EnableMod(item); } } } } } else { if (Main.dedServ) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"No modpack named {commandLineModPack} was found in {UI.UIModPacks.ModListSaveDirectory}. Make sure not to include the .json extension.\n"); Console.ResetColor(); } else { Interface.errorMessage.SetMessage($"No modpack named {commandLineModPack} was found in {UI.UIModPacks.ModListSaveDirectory}. Make sure not to include the .json extension."); } commandLineModPack = ""; return(false); } } catch { if (Main.dedServ) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"The {commandLineModPack} modpack failed to be read properly, it might be malformed.\n"); Console.ResetColor(); } else { Interface.errorMessage.SetMessage($"No modpack named {commandLineModPack} was found in {UI.UIModPacks.ModListSaveDirectory}. Make sure not to include the .json extension."); } commandLineModPack = ""; return(false); } } commandLineModPack = ""; return(true); }
internal static void ServerModMenu() { bool exit = false; while (!exit) { Console.WriteLine("Terraria Server " + Main.versionNumber2 + " - " + ModLoader.versionedName); Console.WriteLine(); TmodFile[] mods = ModLoader.FindMods(); for (int k = 0; k < mods.Length; k++) { BuildProperties properties = BuildProperties.ReadModFile(mods[k]); string name = properties.displayName; name = mods[k].name; string line = (k + 1) + "\t\t" + name + "("; line += (ModLoader.IsEnabled(mods[k]) ? "enabled" : "disabled") + ")"; Console.WriteLine(line); } Console.WriteLine("e\t\tEnable All"); Console.WriteLine("d\t\tDisable All"); Console.WriteLine("r\t\tReload and return to world menu"); Console.WriteLine("Type a number to switch between enabled/disabled"); Console.WriteLine(); Console.WriteLine("Type a command: "); string command = Console.ReadLine(); if (command == null) { command = ""; } command = command.ToLower(); Console.Clear(); if (command == "e") { foreach (TmodFile mod in mods) { ModLoader.EnableMod(mod); } } else if (command == "d") { foreach (TmodFile mod in mods) { ModLoader.DisableMod(mod); } } else if (command == "r") { Console.WriteLine("Unloading mods..."); ModLoader.Unload(); ModLoader.do_Load(null); exit = true; } else { int value; if (Int32.TryParse(command, out value)) { value--; if (value >= 0 && value < mods.Length) { ModLoader.SetModActive(mods[value], !ModLoader.IsEnabled(mods[value])); } } } } }
internal static void ServerModMenu() { bool exit = false; while (!exit) { Console.WriteLine("Terraria Server " + Main.versionNumber2 + " - " + ModLoader.versionedName); Console.WriteLine(); TmodFile[] mods = ModLoader.FindMods(); for (int k = 0; k < mods.Length; k++) { BuildProperties properties = BuildProperties.ReadModFile(mods[k]); string name = properties.displayName; name = mods[k].name; string line = (k + 1) + "\t\t" + name + "("; line += (ModLoader.IsEnabled(mods[k]) ? "enabled" : "disabled") + ")"; Console.WriteLine(line); } if (mods.Length == 0) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"No mods were found in: \"{ModLoader.ModPath}\"\nIf you are running a dedicated server, you may wish to use the 'modpath' command line switch or server config setting to specify a custom mods directory.\n"); Console.ResetColor(); } Console.WriteLine("e\t\tEnable All"); Console.WriteLine("d\t\tDisable All"); Console.WriteLine("r\t\tReload and return to world menu"); Console.WriteLine("Type a number to switch between enabled/disabled"); Console.WriteLine(); Console.WriteLine("Type a command: "); string command = Console.ReadLine(); if (command == null) { command = ""; } command = command.ToLower(); Console.Clear(); if (command == "e") { foreach (TmodFile mod in mods) { ModLoader.EnableMod(mod); } } else if (command == "d") { foreach (TmodFile mod in mods) { ModLoader.DisableMod(mod); } } else if (command == "r") { Console.WriteLine("Unloading mods..."); ModLoader.Unload(); ModLoader.do_Load(null); exit = true; } else { int value; if (Int32.TryParse(command, out value)) { value--; if (value >= 0 && value < mods.Length) { ModLoader.SetModActive(mods[value], !ModLoader.IsEnabled(mods[value])); } } } } }
internal static void SyncClientMods(BinaryReader reader) { AllowVanillaClients = reader.ReadBoolean(); Main.statusText = "Syncing Mods"; var clientMods = ModLoader.LoadedMods; var modFiles = ModLoader.FindMods(); var needsReload = false; downloadQueue.Clear(); var syncSet = new HashSet <string>(); var blockedList = new List <ModHeader>(); int n = reader.ReadInt32(); for (int i = 0; i < n; i++) { var header = new ModHeader(reader.ReadString(), new Version(reader.ReadString()), reader.ReadBytes(20), reader.ReadBoolean()); syncSet.Add(header.name); var clientMod = clientMods.SingleOrDefault(m => m.Name == header.name); if (clientMod != null) { if (header.Matches(clientMod.File)) { continue; } header.path = clientMod.File.path; } else { var disabledVersions = modFiles.Where(m => m.name == header.name).ToArray(); var matching = disabledVersions.FirstOrDefault(header.Matches); if (matching != null) { ModLoader.EnableMod(matching); needsReload = true; continue; } if (disabledVersions.Length > 0) { header.path = disabledVersions[0].path; } } if (downloadModsFromServers && (header.signed || !onlyDownloadSignedMods)) { downloadQueue.Enqueue(header); } else { blockedList.Add(header); } } foreach (var mod in clientMods) { if (mod.Side == ModSide.Both && !syncSet.Contains(mod.Name)) { ModLoader.DisableMod(mod.File); needsReload = true; } } if (blockedList.Count > 0) { var msg = "The following mods are installed on the server but cannot be downloaded "; msg += downloadModsFromServers ? "because you only accept mods signed by the mod browser" : "because you have disabled automatic mod downloading"; msg += ".\nYou will need to change your settings or acquire the mods from the server owner.\n"; foreach (var mod in blockedList) { msg += "\n " + mod; } ErrorLogger.LogMissingMods(msg); return; } if (downloadQueue.Count > 0) { DownloadNextMod(); } else { OnModsDownloaded(needsReload); } }
internal static void SyncClientMods(BinaryReader reader) { AllowVanillaClients = reader.ReadBoolean(); Main.statusText = Language.GetTextValue("tModLoader.MPSyncingMods"); var clientMods = ModLoader.LoadedMods; var modFiles = ModLoader.FindMods(); var needsReload = false; downloadQueue.Clear(); var syncSet = new HashSet <string>(); var blockedList = new List <ModHeader>(); int n = reader.ReadInt32(); for (int i = 0; i < n; i++) { var header = new ModHeader(reader.ReadString(), new Version(reader.ReadString()), reader.ReadBytes(20), reader.ReadBoolean()); syncSet.Add(header.name); var clientMod = clientMods.SingleOrDefault(m => m.Name == header.name); if (clientMod != null) { if (header.Matches(clientMod.File)) { continue; } header.path = clientMod.File.path; } else { var disabledVersions = modFiles.Where(m => m.Name == header.name).ToArray(); var matching = disabledVersions.FirstOrDefault(mod => header.Matches(mod.modFile)); if (matching != null) { matching.Enabled = true; needsReload = true; continue; } if (disabledVersions.Length > 0) { header.path = disabledVersions[0].modFile.path; } } if (downloadModsFromServers && (header.signed || !onlyDownloadSignedMods)) { downloadQueue.Enqueue(header); } else { blockedList.Add(header); } } foreach (var mod in clientMods) { if (mod.Side == ModSide.Both && !syncSet.Contains(mod.Name)) { ModLoader.DisableMod(mod.Name); needsReload = true; } } if (blockedList.Count > 0) { var msg = Language.GetTextValue("tModLoader.MPServerModsCantDownload"); msg += downloadModsFromServers ? Language.GetTextValue("tModLoader.MPServerModsCantDownloadReasonSigned") : Language.GetTextValue("tModLoader.MPServerModsCantDownloadReasonAutomaticDownloadDisabled"); msg += ".\n" + Language.GetTextValue("tModLoader.MPServerModsCantDownloadChangeSettingsHint") + "\n"; foreach (var mod in blockedList) { msg += "\n " + mod; } ErrorLogger.LogMissingMods(msg); return; } if (downloadQueue.Count > 0) { DownloadNextMod(); } else { OnModsDownloaded(needsReload); } }