/////////////////////////////////////////////////////////////////////////// // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 // // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // // rights of fair usage, the disclaimer and warranty conditions. // /////////////////////////////////////////////////////////////////////////// using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Text; using System.Xml.Serialization; namespace Vassal { /// /// Possible input and output filters. /// public enum Filter : uint { [XmlEnum(Name = "none")] [Description("none")] NONE = 0, [XmlEnum(Name = "RFC1738")] [Description("RFC1738")] RFC1738, [XmlEnum(Name = "RFC3986")] [Description("RFC3986")] RFC3986, [XmlEnum(Name = "ENIGMA")] [Description("ENIGMA")] ENIGMA, [XmlEnum(Name = "VIGENERE")] [Description("VIGENERE")] VIGENERE, [XmlEnum(Name = "ATBASH")] [Description("ATBASH")] ATBASH, [XmlEnum(Name = "BASE64")] [Description("BASE64")] BASE64 } /// /// ENIGMA machine settings. /// public struct ENIGMA { public char[] plugs; public char reflector; public char[] rotors; } [Serializable] public class VassalConfiguration { private static readonly object VassalConfigurationLock = new object(); private ENIGMA _enigma = new ENIGMA { rotors = new[] {'3', 'g', '1'}, plugs = new[] {'z', 'p', 'q'}, reflector = 'b' }; private string _group = string.Empty; private string _HTTPServerURL = @"http://127.0.0.1:8080/"; private List _inputFilters = new List(); private List _outputFilters = new List(); private string _password = string.Empty; private uint _regionRestartDelay = 120; private uint _servicesTimeout = 60000; private uint _teleportTimeout = 30000; private string _vigenereSecret = string.Empty; public string Group { get { lock (VassalConfigurationLock) { return _group; } } set { lock (VassalConfigurationLock) { _group = value; } } } public string Password { get { lock (VassalConfigurationLock) { return _password; } } set { lock (VassalConfigurationLock) { _password = value; } } } public ENIGMA ENIGMA { get { lock (VassalConfigurationLock) { return _enigma; } } set { lock (VassalConfigurationLock) { _enigma = value; } } } public string VIGENERESecret { get { lock (VassalConfigurationLock) { return _vigenereSecret; } } set { lock (VassalConfigurationLock) { _vigenereSecret = value; } } } public List InputFilters { get { lock (VassalConfigurationLock) { return _inputFilters; } } set { lock (VassalConfigurationLock) { _inputFilters = value; } } } public List OutputFilters { get { lock (VassalConfigurationLock) { return _outputFilters; } } set { lock (VassalConfigurationLock) { _outputFilters = value; } } } public string HTTPServerURL { get { lock (VassalConfigurationLock) { return _HTTPServerURL; } } set { lock (VassalConfigurationLock) { _HTTPServerURL = value; } } } public uint TeleportTimeout { get { lock (VassalConfigurationLock) { return _teleportTimeout; } } set { lock (VassalConfigurationLock) { _teleportTimeout = value; } } } public uint ServicesTimeout { get { lock (VassalConfigurationLock) { return _servicesTimeout; } } set { lock (VassalConfigurationLock) { _servicesTimeout = value; } } } public uint RegionRestartDelay { get { lock (VassalConfigurationLock) { return _regionRestartDelay; } } set { lock (VassalConfigurationLock) { _regionRestartDelay = value; } } } public static void Save(string file, ref VassalConfiguration configuration) { lock (VassalConfigurationLock) { using (var writer = new StreamWriter(file, false, Encoding.UTF8)) { var serializer = new XmlSerializer(typeof(VassalConfiguration)); serializer.Serialize(writer, configuration); //writer.Flush(); } } } public static void Load(string file, ref VassalConfiguration configuration) { lock (VassalConfigurationLock) { using (var stream = new StreamReader(file, Encoding.UTF8)) { var serializer = new XmlSerializer(typeof(VassalConfiguration)); configuration = (VassalConfiguration) serializer.Deserialize(stream); } } } } }