corrade-vassal – Blame information for rev 5
?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; |
||
5 | eva | 70 | private uint _regionRestartDelay = 120000; |
2 | zed | 71 | |
72 | public string Group |
||
73 | { |
||
74 | get |
||
75 | { |
||
76 | lock (VassalConfigurationLock) |
||
77 | { |
||
78 | return _group; |
||
79 | } |
||
80 | } |
||
81 | set |
||
82 | { |
||
83 | lock (VassalConfigurationLock) |
||
84 | { |
||
85 | _group = value; |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 | |||
90 | public string Password |
||
91 | { |
||
92 | get |
||
93 | { |
||
94 | lock (VassalConfigurationLock) |
||
95 | { |
||
96 | return _password; |
||
97 | } |
||
98 | } |
||
99 | set |
||
100 | { |
||
101 | lock (VassalConfigurationLock) |
||
102 | { |
||
103 | _password = value; |
||
104 | } |
||
105 | } |
||
106 | } |
||
107 | |||
108 | public ENIGMA ENIGMA |
||
109 | { |
||
110 | get |
||
111 | { |
||
112 | lock (VassalConfigurationLock) |
||
113 | { |
||
114 | return _enigma; |
||
115 | } |
||
116 | } |
||
117 | set |
||
118 | { |
||
119 | lock (VassalConfigurationLock) |
||
120 | { |
||
121 | _enigma = value; |
||
122 | } |
||
123 | } |
||
124 | } |
||
125 | |||
126 | public string VIGENERESecret |
||
127 | { |
||
128 | get |
||
129 | { |
||
130 | lock (VassalConfigurationLock) |
||
131 | { |
||
132 | return _vigenereSecret; |
||
133 | } |
||
134 | } |
||
135 | set |
||
136 | { |
||
137 | lock (VassalConfigurationLock) |
||
138 | { |
||
139 | _vigenereSecret = value; |
||
140 | } |
||
141 | } |
||
142 | } |
||
143 | |||
144 | public List<Filter> InputFilters |
||
145 | { |
||
146 | get |
||
147 | { |
||
148 | lock (VassalConfigurationLock) |
||
149 | { |
||
150 | return !_inputFilters.Any() ? new List<Filter> { Filter.RFC1738 } : _inputFilters; |
||
151 | } |
||
152 | } |
||
153 | set |
||
154 | { |
||
155 | lock (VassalConfigurationLock) |
||
156 | { |
||
157 | _inputFilters = value; |
||
158 | } |
||
159 | } |
||
160 | } |
||
161 | |||
162 | public List<Filter> OutputFilters |
||
163 | { |
||
164 | get |
||
165 | { |
||
166 | lock (VassalConfigurationLock) |
||
167 | { |
||
168 | return !_outputFilters.Any() ? new List<Filter> { Filter.RFC1738 } : _outputFilters; |
||
169 | } |
||
170 | } |
||
171 | set |
||
172 | { |
||
173 | lock (VassalConfigurationLock) |
||
174 | { |
||
175 | _outputFilters = value; |
||
176 | } |
||
177 | } |
||
178 | } |
||
179 | |||
180 | public string HTTPServerURL |
||
181 | { |
||
182 | get |
||
183 | { |
||
184 | lock (VassalConfigurationLock) |
||
185 | { |
||
186 | return _HTTPServerURL; |
||
187 | } |
||
188 | } |
||
189 | set |
||
190 | { |
||
191 | lock (VassalConfigurationLock) |
||
192 | { |
||
193 | _HTTPServerURL = value; |
||
194 | } |
||
195 | } |
||
196 | } |
||
197 | |||
198 | public uint TeleportTimeout |
||
199 | { |
||
200 | get |
||
201 | { |
||
202 | lock (VassalConfigurationLock) |
||
203 | { |
||
204 | return _teleportTimeout; |
||
205 | } |
||
206 | } |
||
207 | set |
||
208 | { |
||
209 | lock (VassalConfigurationLock) |
||
210 | { |
||
211 | _teleportTimeout = value; |
||
212 | } |
||
213 | } |
||
214 | } |
||
215 | |||
216 | public uint DataTimeout |
||
217 | { |
||
218 | get |
||
219 | { |
||
220 | lock (VassalConfigurationLock) |
||
221 | { |
||
222 | return _dataTimeout; |
||
223 | } |
||
224 | } |
||
225 | set |
||
226 | { |
||
227 | lock (VassalConfigurationLock) |
||
228 | { |
||
229 | _dataTimeout = value; |
||
230 | } |
||
231 | } |
||
232 | } |
||
233 | |||
5 | eva | 234 | public uint RegionRestartDelay |
235 | { |
||
236 | get |
||
237 | { |
||
238 | lock (VassalConfigurationLock) |
||
239 | { |
||
240 | return _regionRestartDelay; |
||
241 | } |
||
242 | } |
||
243 | set |
||
244 | { |
||
245 | lock (VassalConfigurationLock) |
||
246 | { |
||
247 | _regionRestartDelay = value; |
||
248 | } |
||
249 | } |
||
250 | } |
||
251 | |||
2 | zed | 252 | public static void Save(string file, ref VassalConfiguration configuration) |
253 | { |
||
254 | lock (VassalConfigurationLock) |
||
255 | { |
||
256 | using (StreamWriter writer = new StreamWriter(file, false, Encoding.UTF8)) |
||
257 | { |
||
258 | XmlSerializer serializer = new XmlSerializer(typeof(VassalConfiguration)); |
||
259 | serializer.Serialize(writer, configuration); |
||
260 | //writer.Flush(); |
||
261 | } |
||
262 | } |
||
263 | } |
||
264 | |||
265 | public static void Load(string file, ref VassalConfiguration configuration) |
||
266 | { |
||
267 | lock (VassalConfigurationLock) |
||
268 | { |
||
269 | using (StreamReader stream = new StreamReader(file, Encoding.UTF8)) |
||
270 | { |
||
271 | XmlSerializer serializer = |
||
272 | new XmlSerializer(typeof(VassalConfiguration)); |
||
273 | configuration = (VassalConfiguration)serializer.Deserialize(stream); |
||
274 | } |
||
275 | } |
||
276 | } |
||
277 | } |
||
278 | } |