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