public LocationTree(string fileName, Map map) { LastBranch = new Dictionary <Mobile, GoCategory>(); Map = map; var path = Path.Combine($"Data/Locations/{fileName}.json"); if (!File.Exists(path)) { Console.WriteLine("Go Locations: {0} does not exist", path); return; } try { Root = JsonConfig.Deserialize <GoCategory>(path); if (Root == null) { throw new JsonException($"Failed to deserialize {path}."); } SetParents(Root); } catch (Exception e) { Console.WriteLine("Go Locations: Error in deserializing {0}", path); Console.WriteLine(e); } }
public static IList <UIServerDataElement> GetListFromJsonStr(UITheme theme, string json_str, Func <UIServerDataElement, UIServerDataElement, int> comparator, Action <string, int> pre_join, out bool success) { IList <UIServerDataElement> list; try { var data = JsonConfig <IDictionary <string, ServerBrowserEntry> > .Deserialize(json_str); list = new List <UIServerDataElement>(data.Count); foreach (var kv in data) { list.Add(new UIServerDataElement(theme, kv.Value, comparator, pre_join)); } success = true; } catch (Exception e) { list = new List <UIServerDataElement>(); int len = json_str.Length > 64 ? 64 : json_str.Length; LogHelpers.Log("!ServerBrowser.UIServerBrowserList.GetListFromJsonStr - " + e.ToString() + " - " + json_str.Substring(0, len)); success = false; } return(list); }
public void LoadFrom(TagCompound tags) { if (tags.ContainsKey("tile_data")) { this.DowsedTiles = JsonConfig <IDictionary <int, DowsedTiles> > .Deserialize(tags.GetString("tile_data")); } }
private static void GenerateSpawners_OnCommand(CommandEventArgs e) { Mobile from = e.Mobile; if (e.Arguments.Length == 0) { from.SendMessage("Usage: [GenerateSpawners <path|search pattern>"); return; } var di = new DirectoryInfo(Core.BaseDirectory); var files = di.GetFiles(e.Arguments[0], SearchOption.AllDirectories); if (files.Length == 0) { from.SendMessage("GenerateSpawners: No files found matching the pattern"); return; } JsonSerializerOptions options = new JsonSerializerOptions(); options.Converters.Add(new MapConverterFactory()); options.Converters.Add(new Point3DConverterFactory()); options.Converters.Add(new TimeSpanConverterFactory()); options.Converters.Add(new TextDefinitionConverterFactory()); for (int i = 0; i < files.Length; i++) { var file = files[i]; from.SendMessage("GenerateSpawners: Generating spawners for {0}...", file.Name); List <DynamicJson> spawners = JsonConfig.Deserialize <List <DynamicJson> >(file.FullName); ParseSpawnerList(from, spawners, options); } }
private static int[] Load() { var path = "Data/shrink.json"; var table = JsonConfig.Deserialize <Dictionary <string, string> >(path); if (table == null) { throw new JsonException($"Failed to deserialize {path}."); } int length = 0; foreach (var key in table.Keys) { var index = Utility.ToInt32(key); length = Math.Max(length, index + 1); } var list = new int[length]; foreach (var(body, item) in table) { var index = Utility.ToInt32(body); list[index] = Utility.ToInt32(item); } return(list); }
public void DeserializeInvalidJson_ThrowsError() { #region arrange - given var json = @"settings : [ {name:'Item1',value:'Value1'}, {name:'Item2',value:'Value2'} ]}"; var settingsShouldMatchThis = new[] { new[] { "Item1", "Value1" }, new[] { "Item2", "Value2" } }; #endregion #region act - when var failure = false; try { JsonConfig.Deserialize <JsonConfig>(json); } catch (Exception ex) { Assert.AreEqual(ConfigMessages.DeserializationError, ex.Message); failure = true; } #endregion #region assert - then Assert.IsTrue(failure, "A failure did not occur and the configuration should not have been deserializable."); #endregion }
public void DeserializeDirtyJson_CleansAndCreatesValidConfigObject() { #region arrange - given var json = @"{settings : [ {name:'Item1',value:'Value1'}, {name:'Item2',value:'Value2'} ]}"; var settingsShouldMatchThis = new[] { new[] { "Item1", "Value1" }, new[] { "Item2", "Value2" } }; #endregion #region act - when var config = JsonConfig.Deserialize <JsonConfig>(json); #endregion #region assert - then AssertConfigurationIsValid(config, settingsShouldMatchThis, "Json configuration did not parse settings correctly."); #endregion }
static ExpansionInfo() { var path = Path.Combine(Core.BaseDirectory, "Data/expansion.json"); var expansions = JsonConfig.Deserialize <List <ExpansionConfig> >(path); Table = new ExpansionInfo[expansions.Count]; for (var i = 0; i < expansions.Count; i++) { var expansion = expansions[i]; if (expansion.ClientVersion != null) { Table[i] = new ExpansionInfo( i, expansion.Name, expansion.ClientVersion, expansion.FeatureFlags, expansion.CharacterListFlags, expansion.HousingFlags ); } else { Table[i] = new ExpansionInfo( i, expansion.Name, expansion.ClientFlags ?? ClientFlags.None, expansion.FeatureFlags, expansion.CharacterListFlags, expansion.HousingFlags ); } } }
public static void Generate(string filePattern) { var di = new DirectoryInfo(Core.BaseDirectory); var files = di.GetFiles(filePattern, SearchOption.AllDirectories); if (files.Length == 0) { World.Broadcast(0x35, true, "GenerateSpawners: No files found matching the pattern"); return; } var options = JsonConfig.GetOptions(new TextDefinitionConverterFactory()); foreach (var file in files) { World.Broadcast(0x35, true, "GenerateSpawners: Generating spawners for {0}...", file.Name); try { var spawners = JsonConfig.Deserialize <List <DynamicJson> >(file.FullName); ParseSpawnerList(spawners, options); } catch (JsonException) { World.Broadcast(0x35, true, "GenerateSpawners: Exception parsing {0}, file may not be in the correct format.", file.FullName); } } }
// If mock is enabled we skip the console readline. public static void Load(bool mocked = false) { m_Mocked = mocked; var updated = false; if (File.Exists(m_FilePath)) { Console.Write($"Core: Reading server configuration from {m_RelPath}..."); m_Settings = JsonConfig.Deserialize <ServerSettings>(m_FilePath); if (m_Settings == null) { Utility.PushColor(ConsoleColor.Red); Console.WriteLine("failed"); Utility.PopColor(); throw new FileNotFoundException($"Failed to deserialize {m_FilePath}."); } Utility.PushColor(ConsoleColor.Green); Console.WriteLine("done"); Utility.PopColor(); } else { updated = true; m_Settings = new ServerSettings(); } if (mocked) { return; } if (m_Settings.dataDirectories.Count == 0) { updated = true; Utility.PushColor(ConsoleColor.DarkYellow); Console.WriteLine("Core: Server configuration is missing data directories."); Utility.PopColor(); m_Settings.dataDirectories.AddRange(GetDataDirectories()); } if (m_Settings.listeners.Count == 0) { updated = true; Utility.PushColor(ConsoleColor.DarkYellow); Console.WriteLine("Core: Server is missing socket listener IP addresses."); Utility.PopColor(); m_Settings.listeners.AddRange(GetListeners()); } if (updated) { Save(); Utility.PushColor(ConsoleColor.Green); Console.WriteLine($"Core: Server configuration saved to {m_RelPath}."); Utility.PopColor(); } }
public static void Configure() { var failures = new List <string>(); var count = 0; var path = Path.Combine(Core.BaseDirectory, "Data/map-definitions.json"); logger.Information("Loading Map Definitions"); var stopwatch = Stopwatch.StartNew(); var maps = JsonConfig.Deserialize <List <MapDefinition> >(path); if (maps == null) { throw new JsonException($"Failed to deserialize {path}."); } foreach (var def in maps) { try { RegisterMap(def); count++; } catch (Exception ex) { #if DEBUG Console.WriteLine(ex); #endif failures.Add($"\tInvalid map definition {def.Name} ({def.Id})"); } } stopwatch.Stop(); if (failures.Count > 0) { logger.Warning( "Map Definitions loaded with failures ({0} maps, {1} failures) ({2:F2} seconds)", count, failures.Count, stopwatch.Elapsed.TotalSeconds ); logger.Warning(string.Join(Environment.NewLine, failures)); } else { logger.Information( "Map Definitions loaded successfully ({0} maps, {1} failures) ({2:F2} seconds)", count, failures.Count, stopwatch.Elapsed.TotalSeconds ); } }
internal static void LoadRegions() { var path = Path.Join(Core.BaseDirectory, "Data/regions.json"); var failures = new List <string>(); var count = 0; logger.Information("Loading regions"); var stopwatch = Stopwatch.StartNew(); var regions = JsonConfig.Deserialize <List <DynamicJson> >(path); if (regions == null) { throw new JsonException($"Failed to deserialize {path}."); } foreach (var json in regions) { var type = AssemblyHandler.FindTypeByName(json.Type); if (type == null || !typeof(Region).IsAssignableFrom(type)) { failures.Add($"\tInvalid region type {json.Type}"); continue; } var region = type.CreateInstance <Region>(json, JsonConfig.DefaultOptions); region?.Register(); count++; } stopwatch.Stop(); if (failures.Count == 0) { logger.Information( "Regions loaded ({Count} regions, {FailureCount} failures) ({Duration:F2} seconds)", count, failures.Count, stopwatch.Elapsed.TotalSeconds ); } else { logger.Warning( "Failed loading regions ({Count} regions, {FailureCount} failures) ({Duration:F2} seconds)", count, failures.Count, stopwatch.Elapsed.TotalSeconds ); logger.Warning("{Failures}", failures); } }
public static void Configure() { var failures = new List <string>(); var count = 0; var path = Path.Combine(Core.BaseDirectory, "Data/map-definitions.json"); logger.Information("Loading Map Definitions"); var stopwatch = Stopwatch.StartNew(); var maps = JsonConfig.Deserialize <List <MapDefinition> >(path); if (maps == null) { throw new JsonException($"Failed to deserialize {path}."); } foreach (var def in maps) { try { RegisterMap(def); count++; } catch (Exception ex) { logger.Debug(ex, "Failed to load map definition {MapDefName} ({MapDefId})", def.Name, def.Id); failures.Add($"\tInvalid map definition {def.Name} ({def.Id})"); } } stopwatch.Stop(); if (failures.Count > 0) { logger.Warning( "Map Definitions loaded with failures ({Count} maps, {FailureCount} failures) ({Duration:F2} seconds)", count, failures.Count, stopwatch.Elapsed.TotalSeconds ); logger.Warning("Map load failures: {Failure}", failures); } else { logger.Information( "Map Definitions loaded successfully ({Count} maps, {FailureCount} failures) ({Duration:F2} seconds)", count, failures.Count, stopwatch.Elapsed.TotalSeconds ); } }
/* Here we configure all maps. Some notes: * * 1) The first 32 maps are reserved for core use. * 2) Map 127 is reserved for core use. * 3) Map 255 is reserved for core use. * 4) Changing or removing any predefined maps may cause server instability. * * Map definitions are modified in Data/map-definitions.json: * - <index> : An unreserved unique index for this map * - <id> : An identification number used in client communications. For any visible maps, this value must be from 0-5 * - <fileIndex> : A file identification number. For any visible maps, this value must be from 0-5 * - <width>, <height> : Size of the map (in tiles) * - <season> : Season of the map. 0 = Spring, 1 = Summer, 2 = Fall, 3 = Winter, 4 = Desolation * - <name> : Reference name for the map, used in props gump, get/set commands, region loading, etc * - <rules> : Rules and restrictions associated with the map. See documentation for details */ internal static void LoadMaps() { var failures = new List <string>(); var count = 0; var path = Path.Combine(Core.BaseDirectory, "Data/map-definitions.json"); Console.Write("Map Definitions: Loading..."); var stopwatch = Stopwatch.StartNew(); var maps = JsonConfig.Deserialize <List <MapDefinition> >(path); if (maps == null) { throw new JsonException($"Failed to deserialize {path}."); } foreach (var def in maps) { try { RegisterMap(def); count++; } catch (Exception ex) { #if DEBUG Console.WriteLine(ex); #endif failures.Add($"\tInvalid map definition {def.Name} ({def.Id})"); } } stopwatch.Stop(); Utility.PushColor(failures.Count > 0 ? ConsoleColor.Yellow : ConsoleColor.Green); Console.Write(failures.Count > 0 ? "done with failures" : "done"); Utility.PopColor(); Console.WriteLine( " ({0} maps, {1} failures) ({2:F2} seconds)", count, failures.Count, stopwatch.Elapsed.TotalSeconds ); if (failures.Count > 0) { Utility.PushColor(ConsoleColor.Red); Console.WriteLine(string.Join(Environment.NewLine, failures)); Utility.PopColor(); } }
public static void Configure() { // TODO: Turn this into a command so it can be updated in-game string filePath = Path.Combine(Core.BaseDirectory, "Data/names.json"); List <NameList> nameLists = JsonConfig.Deserialize <List <NameList> >(filePath); foreach (var nameList in nameLists) { nameList.FixNames(); m_Table.Add(nameList.Type, nameList); } }
internal static void LoadRegions() { var path = Path.Join(Core.BaseDirectory, "Data/regions.json"); var failures = new List <string>(); var count = 0; Console.Write("Regions: Loading..."); var stopwatch = Stopwatch.StartNew(); var regions = JsonConfig.Deserialize <List <DynamicJson> >(path); if (regions == null) { throw new JsonException($"Failed to deserialize {path}."); } foreach (var json in regions) { var type = AssemblyHandler.FindTypeByName(json.Type); if (type == null || !typeof(Region).IsAssignableFrom(type)) { failures.Add($"\tInvalid region type {json.Type}"); continue; } var region = type.CreateInstance <Region>(json, JsonConfig.DefaultOptions); region?.Register(); count++; } stopwatch.Stop(); Utility.PushColor(failures.Count > 0 ? ConsoleColor.Yellow : ConsoleColor.Green); Console.Write(failures.Count > 0 ? "done with failures" : "done"); Utility.PopColor(); Console.WriteLine( " ({0} regions, {1} failures) ({2:F2} seconds)", count, failures.Count, stopwatch.Elapsed.TotalSeconds ); if (failures.Count > 0) { Utility.PushColor(ConsoleColor.Red); Console.WriteLine(string.Join(Environment.NewLine, failures)); Utility.PopColor(); } }
public static CAGCategory Load() { var root = new CAGCategory("Add Menu"); var path = Path.Combine(Core.BaseDirectory, "Data/categorization.json"); var list = JsonConfig.Deserialize <List <CAGJson> >(path); if (list == null) { throw new JsonException($"Failed to deserialize {path}."); } // Not an optimized solution foreach (var cag in list) { var parent = root; // Navigate through the dot notation categories until we find the last one var categories = cag.Category.Split("."); for (var i = 0; i < categories.Length; i++) { var category = categories[i]; // No children, so let's make one if (parent.Nodes == null) { var cat = new CAGCategory(category, parent); parent.Nodes = new CAGNode[] { cat }; parent = cat; continue; } var oldParent = parent; for (var j = 0; j < parent.Nodes.Length; j++) { var node = parent.Nodes[j]; if (category == node.Title && node is CAGCategory cat) { parent = cat; break; } } // Didn't find the child, let's add it if (oldParent == parent) { var nodes = parent.Nodes; parent.Nodes = new CAGNode[nodes.Length + 1]; Array.Copy(nodes, parent.Nodes, nodes.Length); var cat = new CAGCategory(category, parent); parent.Nodes[^ 1] = cat;
private static void LoadQuests(Mobile from) { if (Quests.Count > 0) { Quests.Clear(); } var di = new DirectoryInfo(Core.BaseDirectory); var files = di.GetFiles("questsystemadvanced.json", SearchOption.AllDirectories); if (files.Length == 0) { if (from != null) { from.SendMessage("QuestSystem: No files found."); } return; } var options = JsonConfig.GetOptions(new TextDefinitionConverterFactory()); for (var i = 0; i < files.Length; i++) { var file = files[i]; if (from != null) { from.SendMessage("Generating quests from: {0}", file.Name); } NetState.FlushAll(); try { var quests = JsonConfig.Deserialize <List <DynamicJson> >(file.FullName); ParseQuestList(from, quests, options); } catch (JsonException) { if (from != null) { from.SendMessage( "QuestSystem: Exception parsing {0}, file may not be in the correct format.", file.FullName ); } } } }
private static bool ProcessTeleporterData(Mobile m, Action <TeleporterDefinition> processor) { try { JsonConfig.Deserialize <List <TeleporterDefinition> >(TeleporterJsonDataPath).ForEach(processor); } catch (Exception ex) { Console.WriteLine(ex.ToString()); m.SendMessage(ErrorHue, $"Failed to load/process data file '{TeleporterJsonDataPath}'"); return(false); } return(true); }
public static void Configure() { var path = Path.Join(Core.BaseDirectory, _serverAccessConfigurationPath); if (!File.Exists(path)) { SaveConfiguration(); return; } ServerAccessConfiguration = JsonConfig.Deserialize <ServerAccessConfiguration>(path); var protectedAccounts = string.Join(", ", ServerAccessConfiguration.ProtectedAccounts); logger.Information("Protected accounts registered: {0}", protectedAccounts); }
public static void LoadRegions() { var path = Path.Join(Core.BaseDirectory, "Data/regions.json"); // Json Deserialization options for custom objects JsonSerializerOptions options = new JsonSerializerOptions(); options.Converters.Add(new MapConverterFactory()); options.Converters.Add(new Point3DConverterFactory()); options.Converters.Add(new Rectangle3DConverterFactory()); List <string> failures = new List <string>(); int count = 0; Console.Write("Regions: Loading..."); var stopwatch = Stopwatch.StartNew(); List <DynamicJson> regions = JsonConfig.Deserialize <List <DynamicJson> >(path); foreach (var json in regions) { Type type = AssemblyHandler.FindFirstTypeForName(json.Type); if (type == null || !typeof(Region).IsAssignableFrom(type)) { failures.Add($"\tInvalid region type {json.Type}"); continue; } var region = ActivatorUtil.CreateInstance(type, json, options) as Region; region?.Register(); count++; } stopwatch.Stop(); Console.ForegroundColor = failures.Count > 0 ? ConsoleColor.Yellow : ConsoleColor.Green; Console.Write("done{0}. ", failures.Count > 0 ? " with failures" : ""); Console.ResetColor(); Console.WriteLine("({0} regions, {1} failures) ({2:F2} seconds)", count, failures.Count, stopwatch.Elapsed.TotalSeconds); if (failures.Count > 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(string.Join("\n", failures)); Console.ResetColor(); } }
public static CAGCategory Load() { var root = new CAGCategory("Add Menu"); var path = Path.Combine(Core.BaseDirectory, "Data/objects.json"); var list = JsonConfig.Deserialize <List <CAGJson> >(path); // Not an optimized solution foreach (var cag in list) { var parent = root; // Navigate through the dot notation categories until we find the last one var categories = cag.Category.Split("."); for (var i = 0; i < categories.Length; i++) { var category = categories[i]; var oldParent = parent; for (var j = 0; j < parent.Nodes.Length; j++) { var node = parent.Nodes[i]; if (category == node.Title && node is CAGCategory cat) { parent = cat; break; } } if (parent == oldParent) { parent = new CAGCategory(category, parent); } } // Set the objects associated with the child most node parent.Nodes = new CAGNode[cag.Objects.Length]; for (var i = 0; i < cag.Objects.Length; i++) { var obj = cag.Objects[i]; obj.Parent = parent; parent.Nodes[i] = obj; } } return(root); }
// If mock is enabled we skip the console readline. public static void Load(bool mocked = false) { m_Mocked = mocked; bool updated = false; if (File.Exists(m_FilePath)) { Console.Write($"Core: Reading configuration from {m_RelPath}..."); m_Settings = JsonConfig.Deserialize <ServerSettings>(m_FilePath); if (m_Settings == null) { Utility.PushColor(ConsoleColor.Red); Console.WriteLine("failed"); Utility.PopColor(); throw new Exception("Core: Server configuration failed to deserialize."); } Console.WriteLine("done"); } else { updated = true; m_Settings = new ServerSettings(); } if (mocked) { return; } if (m_Settings.dataDirectories.Count == 0) { updated = true; Console.WriteLine("Core: Server configuration is missing data directories."); m_Settings.dataDirectories.Add(GetDataDirectory()); } if (updated) { Save(); Utility.PushColor(ConsoleColor.Green); Console.WriteLine($"Core: Configuration saved to {m_RelPath}."); Utility.PopColor(); } }
public static void LoadRegions() { var path = Path.Join(Core.BaseDirectory, "Data/regions.json"); var failures = new List <string>(); var count = 0; Console.Write("Regions: Loading..."); var stopwatch = Stopwatch.StartNew(); var regions = JsonConfig.Deserialize <List <DynamicJson> >(path); foreach (var json in regions) { var type = AssemblyHandler.FindFirstTypeForName(json.Type); if (type == null || !typeof(Region).IsAssignableFrom(type)) { failures.Add($"\tInvalid region type {json.Type}"); continue; } var region = type.CreateInstance <Region>(json, JsonConfig.DefaultOptions); region?.Register(); count++; } stopwatch.Stop(); Console.ForegroundColor = failures.Count > 0 ? ConsoleColor.Yellow : ConsoleColor.Green; Console.Write("done{0}. ", failures.Count > 0 ? " with failures" : ""); Console.ResetColor(); Console.WriteLine( "({0} regions, {1} failures) ({2:F2} seconds)", count, failures.Count, stopwatch.Elapsed.TotalSeconds ); if (failures.Count > 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(string.Join("\n", failures)); Console.ResetColor(); } }
private static void GenerateSpawners_OnCommand(CommandEventArgs e) { var from = e.Mobile; if (e.Arguments.Length == 0) { from.SendMessage("Usage: [GenerateSpawners <path|search pattern>"); return; } var di = new DirectoryInfo(Core.BaseDirectory); var files = di.GetFiles(e.Arguments[0], SearchOption.AllDirectories); if (files.Length == 0) { from.SendMessage("GenerateSpawners: No files found matching the pattern"); return; } var options = JsonConfig.GetOptions(new TextDefinitionConverterFactory()); for (var i = 0; i < files.Length; i++) { var file = files[i]; from.SendMessage("GenerateSpawners: Generating spawners for {0}...", file.Name); NetState.FlushAll(); try { var spawners = JsonConfig.Deserialize <List <DynamicJson> >(file.FullName); ParseSpawnerList(from, spawners, options); } catch (JsonException) { from.SendMessage( "GenerateSpawners: Exception parsing {0}, file may not be in the correct format.", file.FullName ); } } }
public static void Configure() { var path = Path.Join(Core.BaseDirectory, m_RelPath); Settings settings; if (File.Exists(path)) { Console.Write($"Core: Reading email configuration from {m_RelPath}..."); settings = JsonConfig.Deserialize <Settings>(path); if (settings == null) { Utility.PushColor(ConsoleColor.Red); Console.WriteLine("failed"); Utility.PopColor(); throw new JsonException($"Failed to deserialize {path}."); } Utility.PushColor(ConsoleColor.Green); Console.WriteLine("done"); Utility.PopColor(); } else { settings = new Settings(); JsonConfig.Serialize(path, settings); Utility.PushColor(ConsoleColor.Green); Console.WriteLine($"Core: Email Configuration saved to {m_RelPath}."); Utility.PopColor(); } EmailEnabled = settings.enabled; FromAddress = new MailboxAddress(settings.fromName, settings.fromAddress); CrashAddress = new MailboxAddress(settings.crashName, settings.crashAddress); SpeechLogPageAddress = new MailboxAddress(settings.speechLogPageName, settings.speechLogPageAddress); EmailServer = settings.emailServer; EmailPort = settings.emailPort; EmailServerUsername = settings.emailUsername; EmailServerPassword = settings.emailPassword; EmailSendRetryCount = settings.emailSendRetryCount; EmailSendRetryDelay = settings.emailSendRetryDelay; }
public static readonly int EmailSendRetryDelay = 2; // seconds static EmailConfiguration() { string filePath = Path.Join(Core.BaseDirectory, "Configuration/email-settings.json"); Settings settings = JsonConfig.Deserialize <Settings>(filePath) ?? new Settings(); if (settings.emailServer == null || settings.fromAddress == null) { JsonConfig.Serialize(filePath, settings); return; } EmailEnabled = true; FromAddress = new MailboxAddress(settings.fromName, settings.fromAddress); CrashAddress = new MailboxAddress(settings.crashName, settings.crashAddress); SpeechLogPageAddress = new MailboxAddress(settings.speechLogPageName, settings.speechLogPageAddress); EmailServer = settings.emailServer; EmailPort = settings.emailPort; EmailServerUsername = settings.emailUsername; EmailServerPassword = settings.emailPassword; }
public static void Initialize() { CommandSystem.Register("GetThrottle", AccessLevel.Administrator, GetThrottle); CommandSystem.Register("SetThrottle", AccessLevel.Administrator, SetThrottle); var configPath = ThrottlesConfiguration; var path = Path.Join(Core.BaseDirectory, configPath); if (File.Exists(path)) { var throttles = JsonConfig.Deserialize <SortedDictionary <string, int> >(path); foreach (var(k, v) in throttles) { if (!Utility.ToInt32(k, out var packetId)) { Utility.PushColor(ConsoleColor.DarkYellow); Console.WriteLine("Packet Throttles: Error deserializing {0} from {1}", k, configPath); Utility.PopColor(); continue; } Delays[packetId] = v; } } else { Delays[0x03] = 5; // Speech Delays[0xAD] = 5; // Speech Delays[0x75] = 500; // Rename request } for (int i = 0; i < 0x100; i++) { if (Delays[i] > 0) { IncomingPackets.RegisterThrottler(i, Throttle); } } SaveDelays(); }
public static void Configure() { var path = Path.Join(Core.BaseDirectory, _path); if (File.Exists(path)) { Settings = JsonConfig.Deserialize<AssistantSettings>(path); } else { Settings = new AssistantSettings { WarnOnFailure = true, KickOnFailure = true, DisallowedFeatures = AssistantFeatures.None, DisconnectDelay = TimeSpan.FromSeconds(15.0), WarningMessage = _defaultWarningMessage }; Save(path); } }
public void DeserializeSerializedJsonConfig_CreatesValidConfigObject() { #region arrange - given var json = SerializeJsonConfig(); var settingsShouldMatchThis = new[] { new[] { "Item1", "Value1" }, new[] { "Item2", "Value2" } }; #endregion #region act - when var config = JsonConfig.Deserialize <JsonConfig>(json); #endregion #region assert - then AssertConfigurationIsValid(config, settingsShouldMatchThis, "Json configuration did not parse settings correctly."); #endregion }