corrade-vassal – Blame information for rev 2
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
2 | zed | 1 | using System; |
2 | using System.Collections.Generic; |
||
3 | using System.ComponentModel; |
||
4 | using System.IO; |
||
5 | using System.Linq; |
||
6 | using System.Text; |
||
7 | using System.Threading.Tasks; |
||
8 | using System.Xml.Serialization; |
||
9 | |||
10 | namespace Vassal |
||
11 | { |
||
12 | /// <summary> |
||
13 | /// Possible input and output filters. |
||
14 | /// </summary> |
||
15 | public enum Filter : uint |
||
16 | { |
||
17 | [XmlEnum(Name = "none")] |
||
18 | [Description("none")] |
||
19 | NONE = 0, |
||
20 | [XmlEnum(Name = "RFC1738")] |
||
21 | [Description("RFC1738")] |
||
22 | RFC1738, |
||
23 | [XmlEnum(Name = "RFC3986")] |
||
24 | [Description("RFC3986")] |
||
25 | RFC3986, |
||
26 | [XmlEnum(Name = "ENIGMA")] |
||
27 | [Description("ENIGMA")] |
||
28 | ENIGMA, |
||
29 | [XmlEnum(Name = "VIGENERE")] |
||
30 | [Description("VIGENERE")] |
||
31 | VIGENERE, |
||
32 | [XmlEnum(Name = "ATBASH")] |
||
33 | [Description("ATBASH")] |
||
34 | ATBASH, |
||
35 | [XmlEnum(Name = "BASE64")] |
||
36 | [Description("BASE64")] |
||
37 | BASE64 |
||
38 | } |
||
39 | |||
40 | /// <summary> |
||
41 | /// ENIGMA machine settings. |
||
42 | /// </summary> |
||
43 | public struct ENIGMA |
||
44 | { |
||
45 | public char[] plugs; |
||
46 | public char reflector; |
||
47 | public char[] rotors; |
||
48 | } |
||
49 | |||
50 | [Serializable] |
||
51 | public class VassalConfiguration |
||
52 | { |
||
53 | private static readonly object VassalConfigurationLock = new object(); |
||
54 | |||
55 | private string _HTTPServerURL = @"http://127.0.0.1:8080/"; |
||
56 | private string _group = string.Empty; |
||
57 | private string _password = string.Empty; |
||
58 | |||
59 | private ENIGMA _enigma = new ENIGMA |
||
60 | { |
||
61 | rotors = new[] { '3', 'g', '1' }, |
||
62 | plugs = new[] { 'z', 'p', 'q' }, |
||
63 | reflector = 'b' |
||
64 | }; |
||
65 | private List<Filter> _inputFilters = new List<Filter>(); |
||
66 | private List<Filter> _outputFilters = new List<Filter>(); |
||
67 | private string _vigenereSecret = string.Empty; |
||
68 | private uint _teleportTimeout = 30000; |
||
69 | private uint _dataTimeout = 15000; |
||
70 | |||
71 | public string Group |
||
72 | { |
||
73 | get |
||
74 | { |
||
75 | lock (VassalConfigurationLock) |
||
76 | { |
||
77 | return _group; |
||
78 | } |
||
79 | } |
||
80 | set |
||
81 | { |
||
82 | lock (VassalConfigurationLock) |
||
83 | { |
||
84 | _group = value; |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 | |||
89 | public string Password |
||
90 | { |
||
91 | get |
||
92 | { |
||
93 | lock (VassalConfigurationLock) |
||
94 | { |
||
95 | return _password; |
||
96 | } |
||
97 | } |
||
98 | set |
||
99 | { |
||
100 | lock (VassalConfigurationLock) |
||
101 | { |
||
102 | _password = value; |
||
103 | } |
||
104 | } |
||
105 | } |
||
106 | |||
107 | public ENIGMA ENIGMA |
||
108 | { |
||
109 | get |
||
110 | { |
||
111 | lock (VassalConfigurationLock) |
||
112 | { |
||
113 | return _enigma; |
||
114 | } |
||
115 | } |
||
116 | set |
||
117 | { |
||
118 | lock (VassalConfigurationLock) |
||
119 | { |
||
120 | _enigma = value; |
||
121 | } |
||
122 | } |
||
123 | } |
||
124 | |||
125 | public string VIGENERESecret |
||
126 | { |
||
127 | get |
||
128 | { |
||
129 | lock (VassalConfigurationLock) |
||
130 | { |
||
131 | return _vigenereSecret; |
||
132 | } |
||
133 | } |
||
134 | set |
||
135 | { |
||
136 | lock (VassalConfigurationLock) |
||
137 | { |
||
138 | _vigenereSecret = value; |
||
139 | } |
||
140 | } |
||
141 | } |
||
142 | |||
143 | public List<Filter> InputFilters |
||
144 | { |
||
145 | get |
||
146 | { |
||
147 | lock (VassalConfigurationLock) |
||
148 | { |
||
149 | return !_inputFilters.Any() ? new List<Filter> { Filter.RFC1738 } : _inputFilters; |
||
150 | } |
||
151 | } |
||
152 | set |
||
153 | { |
||
154 | lock (VassalConfigurationLock) |
||
155 | { |
||
156 | _inputFilters = value; |
||
157 | } |
||
158 | } |
||
159 | } |
||
160 | |||
161 | public List<Filter> OutputFilters |
||
162 | { |
||
163 | get |
||
164 | { |
||
165 | lock (VassalConfigurationLock) |
||
166 | { |
||
167 | return !_outputFilters.Any() ? new List<Filter> { Filter.RFC1738 } : _outputFilters; |
||
168 | } |
||
169 | } |
||
170 | set |
||
171 | { |
||
172 | lock (VassalConfigurationLock) |
||
173 | { |
||
174 | _outputFilters = value; |
||
175 | } |
||
176 | } |
||
177 | } |
||
178 | |||
179 | public string HTTPServerURL |
||
180 | { |
||
181 | get |
||
182 | { |
||
183 | lock (VassalConfigurationLock) |
||
184 | { |
||
185 | return _HTTPServerURL; |
||
186 | } |
||
187 | } |
||
188 | set |
||
189 | { |
||
190 | lock (VassalConfigurationLock) |
||
191 | { |
||
192 | _HTTPServerURL = value; |
||
193 | } |
||
194 | } |
||
195 | } |
||
196 | |||
197 | public uint TeleportTimeout |
||
198 | { |
||
199 | get |
||
200 | { |
||
201 | lock (VassalConfigurationLock) |
||
202 | { |
||
203 | return _teleportTimeout; |
||
204 | } |
||
205 | } |
||
206 | set |
||
207 | { |
||
208 | lock (VassalConfigurationLock) |
||
209 | { |
||
210 | _teleportTimeout = value; |
||
211 | } |
||
212 | } |
||
213 | } |
||
214 | |||
215 | public uint DataTimeout |
||
216 | { |
||
217 | get |
||
218 | { |
||
219 | lock (VassalConfigurationLock) |
||
220 | { |
||
221 | return _dataTimeout; |
||
222 | } |
||
223 | } |
||
224 | set |
||
225 | { |
||
226 | lock (VassalConfigurationLock) |
||
227 | { |
||
228 | _dataTimeout = value; |
||
229 | } |
||
230 | } |
||
231 | } |
||
232 | |||
233 | public static void Save(string file, ref VassalConfiguration configuration) |
||
234 | { |
||
235 | lock (VassalConfigurationLock) |
||
236 | { |
||
237 | using (StreamWriter writer = new StreamWriter(file, false, Encoding.UTF8)) |
||
238 | { |
||
239 | XmlSerializer serializer = new XmlSerializer(typeof(VassalConfiguration)); |
||
240 | serializer.Serialize(writer, configuration); |
||
241 | //writer.Flush(); |
||
242 | } |
||
243 | } |
||
244 | } |
||
245 | |||
246 | public static void Load(string file, ref VassalConfiguration configuration) |
||
247 | { |
||
248 | lock (VassalConfigurationLock) |
||
249 | { |
||
250 | using (StreamReader stream = new StreamReader(file, Encoding.UTF8)) |
||
251 | { |
||
252 | XmlSerializer serializer = |
||
253 | new XmlSerializer(typeof(VassalConfiguration)); |
||
254 | configuration = (VassalConfiguration)serializer.Deserialize(stream); |
||
255 | } |
||
256 | } |
||
257 | } |
||
258 | } |
||
259 | } |