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