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