corrade-vassal – Diff between revs 12 and 13
?pathlinks?
Rev 12 | Rev 13 | |||
---|---|---|---|---|
Line 15... | Line 15... | |||
15 | using System.Net.Sockets; |
15 | using System.Net.Sockets; |
|
16 | using System.Reflection; |
16 | using System.Reflection; |
|
17 | using System.Text; |
17 | using System.Text; |
|
18 | using System.Text.RegularExpressions; |
18 | using System.Text.RegularExpressions; |
|
19 | using System.Threading; |
19 | using System.Threading; |
|
20 | using System.Web; |
- | ||
21 | using System.Windows.Forms; |
20 | using System.Windows.Forms; |
|
22 | using OpenMetaverse; |
21 | using OpenMetaverse; |
|
- | 22 | using wasSharp; |
||
23 | using Parallel = System.Threading.Tasks.Parallel; |
23 | using Parallel = System.Threading.Tasks.Parallel; |
|
24 | using Timer = System.Timers.Timer; |
24 | using Timer = System.Timers.Timer; |
|
Line 25... | Line 25... | |||
25 | |
25 | |
|
26 | namespace Vassal |
26 | namespace Vassal |
|
Line 50... | Line 50... | |||
50 | foreach (Filter filter in vassalConfiguration.InputFilters) |
50 | foreach (Filter filter in vassalConfiguration.InputFilters) |
|
51 | { |
51 | { |
|
52 | switch (filter) |
52 | switch (filter) |
|
53 | { |
53 | { |
|
54 | case Filter.RFC1738: |
54 | case Filter.RFC1738: |
|
55 | o = wasURLUnescapeDataString(o); |
55 | o = Web.URLUnescapeDataString(o); |
|
56 | break; |
56 | break; |
|
57 | case Filter.RFC3986: |
57 | case Filter.RFC3986: |
|
58 | o = wasURIUnescapeDataString(o); |
58 | o = Web.URIUnescapeDataString(o); |
|
59 | break; |
59 | break; |
|
60 | case Filter.ENIGMA: |
60 | case Filter.ENIGMA: |
|
61 | o = wasEnigma(o, vassalConfiguration.ENIGMA.rotors.ToArray(), |
61 | o = Cryptography.ENIGMA(o, vassalConfiguration.ENIGMA.rotors.ToArray(), |
|
62 | vassalConfiguration.ENIGMA.plugs.ToArray(), |
62 | vassalConfiguration.ENIGMA.plugs.ToArray(), |
|
63 | vassalConfiguration.ENIGMA.reflector); |
63 | vassalConfiguration.ENIGMA.reflector); |
|
64 | break; |
64 | break; |
|
65 | case Filter.VIGENERE: |
65 | case Filter.VIGENERE: |
|
66 | o = wasDecryptVIGENERE(o, vassalConfiguration.VIGENERESecret); |
66 | o = Cryptography.DecryptVIGENERE(o, vassalConfiguration.VIGENERESecret); |
|
67 | break; |
67 | break; |
|
68 | case Filter.ATBASH: |
68 | case Filter.ATBASH: |
|
69 | o = wasATBASH(o); |
69 | o = Cryptography.ATBASH(o); |
|
70 | break; |
70 | break; |
|
71 | case Filter.BASE64: |
71 | case Filter.BASE64: |
|
72 | o = Encoding.UTF8.GetString(Convert.FromBase64String(o)); |
72 | o = Encoding.UTF8.GetString(Convert.FromBase64String(o)); |
|
73 | break; |
73 | break; |
|
74 | } |
74 | } |
|
Line 86... | Line 86... | |||
86 | foreach (Filter filter in vassalConfiguration.OutputFilters) |
86 | foreach (Filter filter in vassalConfiguration.OutputFilters) |
|
87 | { |
87 | { |
|
88 | switch (filter) |
88 | switch (filter) |
|
89 | { |
89 | { |
|
90 | case Filter.RFC1738: |
90 | case Filter.RFC1738: |
|
91 | o = wasURLEscapeDataString(o); |
91 | o = Web.URLEscapeDataString(o); |
|
92 | break; |
92 | break; |
|
93 | case Filter.RFC3986: |
93 | case Filter.RFC3986: |
|
94 | o = wasURIEscapeDataString(o); |
94 | o = Web.URIEscapeDataString(o); |
|
95 | break; |
95 | break; |
|
96 | case Filter.ENIGMA: |
96 | case Filter.ENIGMA: |
|
97 | o = wasEnigma(o, vassalConfiguration.ENIGMA.rotors.ToArray(), |
97 | o = Cryptography.ENIGMA(o, vassalConfiguration.ENIGMA.rotors.ToArray(), |
|
98 | vassalConfiguration.ENIGMA.plugs.ToArray(), |
98 | vassalConfiguration.ENIGMA.plugs.ToArray(), |
|
99 | vassalConfiguration.ENIGMA.reflector); |
99 | vassalConfiguration.ENIGMA.reflector); |
|
100 | break; |
100 | break; |
|
101 | case Filter.VIGENERE: |
101 | case Filter.VIGENERE: |
|
102 | o = wasEncryptVIGENERE(o, vassalConfiguration.VIGENERESecret); |
102 | o = Cryptography.EncryptVIGENERE(o, vassalConfiguration.VIGENERESecret); |
|
103 | break; |
103 | break; |
|
104 | case Filter.ATBASH: |
104 | case Filter.ATBASH: |
|
105 | o = wasATBASH(o); |
105 | o = Cryptography.ATBASH(o); |
|
106 | break; |
106 | break; |
|
107 | case Filter.BASE64: |
107 | case Filter.BASE64: |
|
108 | o = Convert.ToBase64String(Encoding.UTF8.GetBytes(o)); |
108 | o = Convert.ToBase64String(Encoding.UTF8.GetBytes(o)); |
|
109 | break; |
109 | break; |
|
110 | } |
110 | } |
|
Line 115... | Line 115... | |||
115 | private static readonly Action updateCurrentRegionName = () => |
115 | private static readonly Action updateCurrentRegionName = () => |
|
116 | { |
116 | { |
|
117 | try |
117 | try |
|
118 | { |
118 | { |
|
119 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
119 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
120 | wasKeyValueEscape(new Dictionary<string, string> |
120 | KeyValue.Escape(new Dictionary<string, string> |
|
121 | { |
121 | { |
|
122 | {"command", "getregiondata"}, |
122 | {"command", "getregiondata"}, |
|
123 | {"group", vassalConfiguration.Group}, |
123 | {"group", vassalConfiguration.Group}, |
|
124 | {"password", vassalConfiguration.Password}, |
124 | {"password", vassalConfiguration.Password}, |
|
125 | {"data", "Name"} |
125 | {"data", "Name"} |
|
126 | }), 60000); |
126 | }, wasOutput), 60000); |
|
127 | bool success; |
127 | bool success; |
|
128 | if (string.IsNullOrEmpty(result) || |
128 | if (string.IsNullOrEmpty(result) || |
|
129 | !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
129 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
130 | { |
130 | { |
|
131 | vassalForm.BeginInvoke( |
131 | vassalForm.BeginInvoke( |
|
132 | (MethodInvoker) |
132 | (MethodInvoker) |
|
133 | (() => { vassalForm.StatusText.Text = @"Failed to query Corrade for current region."; })); |
133 | (() => { vassalForm.StatusText.Text = @"Failed to query Corrade for current region."; })); |
|
134 | return; |
134 | return; |
|
Line 139... | Line 139... | |||
139 | vassalForm.BeginInvoke((MethodInvoker) (() => |
139 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
140 | { |
140 | { |
|
141 | vassalForm.CurrentRegionAt.Visible = true; |
141 | vassalForm.CurrentRegionAt.Visible = true; |
|
142 | vassalForm.CurrentRegionName.Visible = true; |
142 | vassalForm.CurrentRegionName.Visible = true; |
|
143 | vassalForm.CurrentRegionName.Text = |
143 | vassalForm.CurrentRegionName.Text = |
|
144 | wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))).Last(); |
144 | CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).Last(); |
|
145 | })); |
145 | })); |
|
146 | break; |
146 | break; |
|
147 | default: |
147 | default: |
|
148 | vassalForm.BeginInvoke((MethodInvoker) (() => |
148 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
149 | { |
149 | { |
|
150 | vassalForm.CurrentRegionAt.Visible = false; |
150 | vassalForm.CurrentRegionAt.Visible = false; |
|
151 | vassalForm.CurrentRegionName.Visible = false; |
151 | vassalForm.CurrentRegionName.Visible = false; |
|
152 | vassalForm.StatusText.Text = @"Error getting current region: " + |
152 | vassalForm.StatusText.Text = @"Error getting current region: " + |
|
153 | wasInput(wasKeyValueGet("error", result)); |
153 | wasInput(KeyValue.Get("error", result)); |
|
154 | })); |
154 | })); |
|
155 | break; |
155 | break; |
|
156 | } |
156 | } |
|
157 | } |
157 | } |
|
158 | catch (Exception ex) |
158 | catch (Exception ex) |
|
Line 171... | Line 171... | |||
171 | InitializeComponent(); |
171 | InitializeComponent(); |
|
172 | vassalForm = this; |
172 | vassalForm = this; |
|
173 | } |
173 | } |
|
Line 174... | Line 174... | |||
174 | |
174 | |
|
175 | /////////////////////////////////////////////////////////////////////////// |
- | ||
176 | // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 // |
- | ||
177 | /////////////////////////////////////////////////////////////////////////// |
- | ||
178 | private static double wasMapValueToRange(double value, double xMin, double xMax, double yMin, double yMax) |
- | ||
179 | { |
- | ||
180 | return yMin + ( |
- | ||
181 | ( |
- | ||
182 | yMax - yMin |
- | ||
183 | ) |
- | ||
184 | * |
- | ||
185 | ( |
- | ||
186 | value - xMin |
- | ||
187 | ) |
- | ||
188 | / |
- | ||
189 | ( |
- | ||
190 | xMax - xMin |
- | ||
191 | ) |
- | ||
192 | ); |
- | ||
193 | } |
- | ||
194 | |
- | ||
195 | /////////////////////////////////////////////////////////////////////////// |
- | ||
196 | // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 // |
- | ||
197 | /////////////////////////////////////////////////////////////////////////// |
- | ||
198 | /// <summary>RFC1738 URL Escapes a string</summary> |
- | ||
199 | /// <param name="data">a string to escape</param> |
- | ||
200 | /// <returns>an RFC1738 escaped string</returns> |
- | ||
201 | private static string wasURLEscapeDataString(string data) |
- | ||
202 | { |
- | ||
203 | return HttpUtility.UrlEncode(data); |
- | ||
204 | } |
- | ||
205 | |
- | ||
206 | /////////////////////////////////////////////////////////////////////////// |
- | ||
207 | // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 // |
- | ||
208 | /////////////////////////////////////////////////////////////////////////// |
- | ||
209 | /// <summary>RFC1738 URL Unescape a string</summary> |
- | ||
210 | /// <param name="data">a string to unescape</param> |
- | ||
211 | /// <returns>an RFC1738 unescaped string</returns> |
- | ||
212 | private static string wasURLUnescapeDataString(string data) |
- | ||
213 | { |
- | ||
214 | return HttpUtility.UrlDecode(data); |
- | ||
215 | } |
- | ||
216 | |
- | ||
217 | /////////////////////////////////////////////////////////////////////////// |
- | ||
218 | // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // |
- | ||
219 | /////////////////////////////////////////////////////////////////////////// |
- | ||
220 | /// <summary>URI unescapes an RFC3986 URI escaped string</summary> |
- | ||
221 | /// <param name="data">a string to unescape</param> |
- | ||
222 | /// <returns>the resulting string</returns> |
- | ||
223 | private static string wasURIUnescapeDataString(string data) |
- | ||
224 | { |
- | ||
225 | // Uri.UnescapeDataString can only handle 32766 characters at a time |
- | ||
226 | return string.Join("", Enumerable.Range(0, (data.Length + 32765)/32766) |
- | ||
227 | .Select(o => Uri.UnescapeDataString(data.Substring(o*32766, Math.Min(32766, data.Length - (o*32766))))) |
- | ||
228 | .ToArray()); |
- | ||
229 | } |
- | ||
230 | |
- | ||
231 | /////////////////////////////////////////////////////////////////////////// |
- | ||
232 | // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // |
- | ||
233 | /////////////////////////////////////////////////////////////////////////// |
- | ||
234 | /// <summary>RFC3986 URI Escapes a string</summary> |
- | ||
235 | /// <param name="data">a string to escape</param> |
- | ||
236 | /// <returns>an RFC3986 escaped string</returns> |
- | ||
237 | private static string wasURIEscapeDataString(string data) |
- | ||
238 | { |
- | ||
239 | // Uri.EscapeDataString can only handle 32766 characters at a time |
- | ||
240 | return string.Join("", Enumerable.Range(0, (data.Length + 32765)/32766) |
- | ||
241 | .Select(o => Uri.EscapeDataString(data.Substring(o*32766, Math.Min(32766, data.Length - (o*32766))))) |
- | ||
242 | .ToArray()); |
- | ||
243 | } |
- | ||
244 | |
- | ||
245 | /////////////////////////////////////////////////////////////////////////// |
- | ||
246 | // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // |
- | ||
247 | /////////////////////////////////////////////////////////////////////////// |
- | ||
248 | /// <summary> |
- | ||
249 | /// Gets an array element at a given modulo index. |
- | ||
250 | /// </summary> |
- | ||
251 | /// <typeparam name="T">the array type</typeparam> |
- | ||
252 | /// <param name="index">a positive or negative index of the element</param> |
- | ||
253 | /// <param name="data">the array</param> |
- | ||
254 | /// <return>an array element</return> |
- | ||
255 | public static T wasGetElementAt<T>(T[] data, int index) |
- | ||
256 | { |
- | ||
257 | switch (index < 0) |
- | ||
258 | { |
- | ||
259 | case true: |
- | ||
260 | return data[((index%data.Length) + data.Length)%data.Length]; |
- | ||
261 | default: |
- | ||
262 | return data[index%data.Length]; |
- | ||
263 | } |
- | ||
264 | } |
- | ||
265 | |
- | ||
266 | #region KEY-VALUE DATA |
- | ||
267 | |
- | ||
268 | /////////////////////////////////////////////////////////////////////////// |
- | ||
269 | // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // |
- | ||
270 | /////////////////////////////////////////////////////////////////////////// |
- | ||
271 | /// <summary> |
- | ||
272 | /// Returns the value of a key from a key-value data string. |
- | ||
273 | /// </summary> |
- | ||
274 | /// <param name="key">the key of the value</param> |
- | ||
275 | /// <param name="data">the key-value data segment</param> |
- | ||
276 | /// <returns>true if the key was found in data</returns> |
- | ||
277 | private static string wasKeyValueGet(string key, string data) |
- | ||
278 | { |
- | ||
279 | return data.Split('&') |
- | ||
280 | .AsParallel() |
- | ||
281 | .Select(o => o.Split('=').ToList()) |
- | ||
282 | .Where(o => o.Count.Equals(2)) |
- | ||
283 | .Select(o => new |
- | ||
284 | { |
- | ||
285 | k = o.First(), |
- | ||
286 | v = o.Last() |
- | ||
287 | }) |
- | ||
288 | .Where(o => o.k.Equals(key)) |
- | ||
289 | .Select(o => o.v) |
- | ||
290 | .FirstOrDefault(); |
- | ||
291 | } |
- | ||
292 | |
- | ||
293 | #endregion |
- | ||
294 | |
- | ||
295 | /////////////////////////////////////////////////////////////////////////// |
- | ||
296 | // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // |
- | ||
297 | /////////////////////////////////////////////////////////////////////////// |
- | ||
298 | /// <summary>Escapes a dictionary's keys and values for sending as POST data.</summary> |
- | ||
299 | /// <param name="data">A dictionary containing keys and values to be escaped</param> |
- | ||
300 | private static Dictionary<string, string> wasKeyValueEscape(Dictionary<string, string> data) |
- | ||
301 | { |
- | ||
302 | return data.AsParallel().ToDictionary(o => wasOutput(o.Key), p => wasOutput(p.Value)); |
- | ||
303 | } |
- | ||
304 | |
- | ||
305 | /////////////////////////////////////////////////////////////////////////// |
- | ||
306 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
- | ||
307 | /////////////////////////////////////////////////////////////////////////// |
- | ||
308 | /// <summary> |
- | ||
309 | /// Converts a list of string to a comma-separated values string. |
- | ||
310 | /// </summary> |
- | ||
311 | /// <param name="l">a list of strings</param> |
- | ||
312 | /// <returns>a commma-separated list of values</returns> |
- | ||
313 | /// <remarks>compliant with RFC 4180</remarks> |
- | ||
314 | public static string wasEnumerableToCSV(IEnumerable<string> l) |
- | ||
315 | { |
- | ||
316 | string[] csv = l.Select(o => o.Clone() as string).ToArray(); |
- | ||
317 | Parallel.ForEach(csv.Select((v, i) => new {i, v}), o => |
- | ||
318 | { |
- | ||
319 | string cell = o.v.Replace("\"", "\"\""); |
- | ||
320 | switch (new[] {'"', ' ', ',', '\r', '\n'}.Any(p => cell.Contains(p))) |
- | ||
321 | { |
- | ||
322 | case true: |
- | ||
323 | csv[o.i] = "\"" + cell + "\""; |
- | ||
324 | break; |
- | ||
325 | default: |
- | ||
326 | csv[o.i] = cell; |
- | ||
327 | break; |
- | ||
328 | } |
- | ||
329 | }); |
- | ||
330 | return string.Join(",", csv); |
- | ||
331 | } |
- | ||
332 | |
- | ||
333 | /////////////////////////////////////////////////////////////////////////// |
- | ||
334 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
- | ||
335 | /////////////////////////////////////////////////////////////////////////// |
- | ||
336 | /// <summary> |
- | ||
337 | /// Converts a comma-separated list of values to a list of strings. |
- | ||
338 | /// </summary> |
- | ||
339 | /// <param name="csv">a comma-separated list of values</param> |
- | ||
340 | /// <returns>a list of strings</returns> |
- | ||
341 | /// <remarks>compliant with RFC 4180</remarks> |
- | ||
342 | public static IEnumerable<string> wasCSVToEnumerable(string csv) |
- | ||
343 | { |
- | ||
344 | Stack<char> s = new Stack<char>(); |
- | ||
345 | StringBuilder m = new StringBuilder(); |
- | ||
346 | for (int i = 0; i < csv.Length; ++i) |
- | ||
347 | { |
- | ||
348 | switch (csv[i]) |
- | ||
349 | { |
- | ||
350 | case ',': |
- | ||
351 | if (!s.Any() || !s.Peek().Equals('"')) |
- | ||
352 | { |
- | ||
353 | yield return m.ToString(); |
- | ||
354 | m = new StringBuilder(); |
- | ||
355 | continue; |
- | ||
356 | } |
- | ||
357 | m.Append(csv[i]); |
- | ||
358 | continue; |
- | ||
359 | case '"': |
- | ||
360 | if (i + 1 < csv.Length && csv[i].Equals(csv[i + 1])) |
- | ||
361 | { |
- | ||
362 | m.Append(csv[i]); |
- | ||
363 | ++i; |
- | ||
364 | continue; |
- | ||
365 | } |
- | ||
366 | if (!s.Any() || !s.Peek().Equals(csv[i])) |
- | ||
367 | { |
- | ||
368 | s.Push(csv[i]); |
- | ||
369 | continue; |
- | ||
370 | } |
- | ||
371 | s.Pop(); |
- | ||
372 | continue; |
- | ||
373 | } |
- | ||
374 | m.Append(csv[i]); |
- | ||
375 | } |
- | ||
376 | |
- | ||
377 | yield return m.ToString(); |
- | ||
378 | } |
- | ||
379 | |
- | ||
380 | /////////////////////////////////////////////////////////////////////////// |
- | ||
381 | // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // |
- | ||
382 | /////////////////////////////////////////////////////////////////////////// |
- | ||
383 | /// <summary> |
- | ||
384 | /// Serialises a dictionary to key-value data. |
- | ||
385 | /// </summary> |
- | ||
386 | /// <param name="data">a dictionary</param> |
- | ||
387 | /// <returns>a key-value data encoded string</returns> |
- | ||
388 | private static string wasKeyValueEncode(Dictionary<string, string> data) |
- | ||
389 | { |
- | ||
390 | return string.Join("&", data.AsParallel().Select(o => string.Join("=", o.Key, o.Value))); |
- | ||
391 | } |
- | ||
392 | |
- | ||
393 | /////////////////////////////////////////////////////////////////////////// |
175 | /////////////////////////////////////////////////////////////////////////// |
|
394 | // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // |
176 | // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // |
|
395 | /////////////////////////////////////////////////////////////////////////// |
177 | /////////////////////////////////////////////////////////////////////////// |
|
396 | /// <summary> |
178 | /// <summary> |
|
397 | /// Sends a post request to an URL with set key-value pairs. |
179 | /// Sends a post request to an URL with set key-value pairs. |
|
Line 427... | Line 209... | |||
427 | // send request |
209 | // send request |
|
428 | using (Stream requestStream = request.GetRequestStream()) |
210 | using (Stream requestStream = request.GetRequestStream()) |
|
429 | { |
211 | { |
|
430 | using (StreamWriter dataStream = new StreamWriter(requestStream)) |
212 | using (StreamWriter dataStream = new StreamWriter(requestStream)) |
|
431 | { |
213 | { |
|
432 | dataStream.Write(wasKeyValueEncode(message)); |
214 | dataStream.Write(KeyValue.Encode(message)); |
|
433 | } |
215 | } |
|
434 | } |
216 | } |
|
435 | // read response |
217 | // read response |
|
436 | using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) |
218 | using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) |
|
437 | { |
219 | { |
|
Line 521... | Line 303... | |||
521 | string result = null; |
303 | string result = null; |
|
522 | ManualResetEvent receivedPOST = new ManualResetEvent(false); |
304 | ManualResetEvent receivedPOST = new ManualResetEvent(false); |
|
523 | new Thread(() => |
305 | new Thread(() => |
|
524 | { |
306 | { |
|
525 | result = wasInput(wasPOST(vassalConfiguration.HTTPServerURL, |
307 | result = wasInput(wasPOST(vassalConfiguration.HTTPServerURL, |
|
526 | wasKeyValueEscape(new Dictionary<string, string> |
308 | KeyValue.Escape(new Dictionary<string, string> |
|
527 | { |
309 | { |
|
528 | {"command", "teleport"}, |
310 | {"command", "teleport"}, |
|
529 | {"group", vassalConfiguration.Group}, |
311 | {"group", vassalConfiguration.Group}, |
|
530 | {"password", vassalConfiguration.Password}, |
312 | {"password", vassalConfiguration.Password}, |
|
531 | {"region", selectedRegionName}, |
313 | {"region", selectedRegionName}, |
|
532 | {"position", selectedRegionPosition.ToString()}, |
314 | {"position", selectedRegionPosition.ToString()}, |
|
533 | {"fly", "True"} |
315 | {"fly", "True"} |
|
534 | }), vassalConfiguration.TeleportTimeout)); |
316 | }, wasOutput), vassalConfiguration.TeleportTimeout)); |
|
535 | receivedPOST.Set(); |
317 | receivedPOST.Set(); |
|
536 | }) {IsBackground = true}.Start(); |
318 | }) {IsBackground = true}.Start(); |
|
537 | receivedPOST.WaitOne((int) vassalConfiguration.TeleportTimeout, false); |
319 | receivedPOST.WaitOne((int) vassalConfiguration.TeleportTimeout, false); |
|
538 | teleportTimer.Stop(); |
320 | teleportTimer.Stop(); |
|
539 | switch (!string.IsNullOrEmpty(result) && wasKeyValueGet("success", result) == "True") |
321 | switch (!string.IsNullOrEmpty(result) && KeyValue.Get("success", result) == "True") |
|
540 | { |
322 | { |
|
541 | case true: |
323 | case true: |
|
542 | vassalForm.Invoke((MethodInvoker) (() => |
324 | vassalForm.Invoke((MethodInvoker) (() => |
|
543 | { |
325 | { |
|
544 | vassalForm.StatusText.Text = @"Now at " + selectedRegionName; |
326 | vassalForm.StatusText.Text = @"Now at " + selectedRegionName; |
|
Line 551... | Line 333... | |||
551 | case true: |
333 | case true: |
|
552 | vassalForm.Invoke((MethodInvoker) (() => |
334 | vassalForm.Invoke((MethodInvoker) (() => |
|
553 | { |
335 | { |
|
554 | vassalForm.StatusText.Text = @"Failed teleporting to " + selectedRegionName + |
336 | vassalForm.StatusText.Text = @"Failed teleporting to " + selectedRegionName + |
|
555 | @": " + |
337 | @": " + |
|
556 | wasKeyValueGet("error", result); |
338 | KeyValue.Get("error", result); |
|
557 | })); |
339 | })); |
|
558 | break; |
340 | break; |
|
559 | default: |
341 | default: |
|
560 | vassalForm.Invoke( |
342 | vassalForm.Invoke( |
|
561 | (MethodInvoker) |
343 | (MethodInvoker) |
|
Line 691... | Line 473... | |||
691 | if (File.Exists(VASSAL_CONSTANTS.VASSAL_REGIONS)) |
473 | if (File.Exists(VASSAL_CONSTANTS.VASSAL_REGIONS)) |
|
692 | { |
474 | { |
|
693 | Vector3 localPosition; |
475 | Vector3 localPosition; |
|
694 | List<KeyValuePair<string, Vector3>> ConfiguredRegions = new List<KeyValuePair<string, Vector3>>( |
476 | List<KeyValuePair<string, Vector3>> ConfiguredRegions = new List<KeyValuePair<string, Vector3>>( |
|
695 | File.ReadAllLines(VASSAL_CONSTANTS.VASSAL_REGIONS) |
477 | File.ReadAllLines(VASSAL_CONSTANTS.VASSAL_REGIONS) |
|
696 | .Select(o => new List<string>(wasCSVToEnumerable(o))) |
478 | .Select(o => new List<string>(CSV.ToEnumerable(o))) |
|
697 | .Where(o => o.Count == 2) |
479 | .Where(o => o.Count == 2) |
|
698 | .ToDictionary(o => o.First(), |
480 | .ToDictionary(o => o.First(), |
|
699 | p => |
481 | p => |
|
700 | Vector3.TryParse(p.Last(), out localPosition) |
482 | Vector3.TryParse(p.Last(), out localPosition) |
|
701 | ? localPosition |
483 | ? localPosition |
|
Line 778... | Line 560... | |||
778 | |
560 | |
|
779 | try |
561 | try |
|
780 | { |
562 | { |
|
781 | // Get the simulator name and if we are an estate manager. |
563 | // Get the simulator name and if we are an estate manager. |
|
782 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
564 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
783 | wasKeyValueEscape(new Dictionary<string, string> |
565 | KeyValue.Escape(new Dictionary<string, string> |
|
784 | { |
566 | { |
|
785 | {"command", "getregiondata"}, |
567 | {"command", "getregiondata"}, |
|
786 | {"group", vassalConfiguration.Group}, |
568 | {"group", vassalConfiguration.Group}, |
|
787 | {"password", vassalConfiguration.Password}, |
569 | {"password", vassalConfiguration.Password}, |
|
788 | { |
570 | { |
|
789 | "data", wasEnumerableToCSV(new[] |
571 | "data", CSV.FromEnumerable(new[] |
|
790 | { |
572 | { |
|
791 | "Name", |
573 | "Name", |
|
792 | "IsEstateManager" |
574 | "IsEstateManager" |
|
793 | }) |
575 | }) |
|
794 | } |
576 | } |
|
Line 795... | Line 577... | |||
795 | }), vassalConfiguration.DataTimeout); |
577 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
796 | |
578 | |
|
797 | bool success; |
579 | bool success; |
|
798 | if (string.IsNullOrEmpty(result) || |
580 | if (string.IsNullOrEmpty(result) || |
|
Line 799... | Line 581... | |||
799 | !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
581 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
800 | throw new Exception(); |
582 | throw new Exception(); |
|
801 | |
583 | |
|
Line 802... | Line 584... | |||
802 | List<string> data = wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))).ToList(); |
584 | List<string> data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
|
803 | if (data.Count.Equals(0)) |
585 | if (data.Count.Equals(0)) |
|
Line 885... | Line 667... | |||
885 | // Start measuring the lag to Corrade. |
667 | // Start measuring the lag to Corrade. |
|
886 | Stopwatch stopWatch = new Stopwatch(); |
668 | Stopwatch stopWatch = new Stopwatch(); |
|
887 | stopWatch.Start(); |
669 | stopWatch.Start(); |
|
888 | // Get the statistics. |
670 | // Get the statistics. |
|
889 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
671 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
890 | wasKeyValueEscape(new Dictionary<string, string> |
672 | KeyValue.Escape(new Dictionary<string, string> |
|
891 | { |
673 | { |
|
892 | {"command", "getregiondata"}, |
674 | {"command", "getregiondata"}, |
|
893 | {"group", vassalConfiguration.Group}, |
675 | {"group", vassalConfiguration.Group}, |
|
894 | {"password", vassalConfiguration.Password}, |
676 | {"password", vassalConfiguration.Password}, |
|
895 | { |
677 | { |
|
896 | "data", wasEnumerableToCSV(new[] |
678 | "data", CSV.FromEnumerable(new[] |
|
897 | { |
679 | { |
|
898 | "Agents", |
680 | "Agents", |
|
899 | "LastLag", |
681 | "LastLag", |
|
900 | "Dilation", |
682 | "Dilation", |
|
901 | "FPS", |
683 | "FPS", |
|
Line 908... | Line 690... | |||
908 | "PhysicsTime", |
690 | "PhysicsTime", |
|
909 | "NetTime", |
691 | "NetTime", |
|
910 | "AvatarPositions" |
692 | "AvatarPositions" |
|
911 | }) |
693 | }) |
|
912 | } |
694 | } |
|
913 | }), vassalConfiguration.DataTimeout); |
695 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
914 | stopWatch.Stop(); |
696 | stopWatch.Stop(); |
|
Line 915... | Line 697... | |||
915 | |
697 | |
|
916 | bool success; |
698 | bool success; |
|
917 | if (string.IsNullOrEmpty(result) || |
699 | if (string.IsNullOrEmpty(result) || |
|
918 | !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
700 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
Line 919... | Line 701... | |||
919 | throw new Exception(); |
701 | throw new Exception(); |
|
920 | |
702 | |
|
921 | List<string> data = wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))).ToList(); |
703 | List<string> data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
|
Line 922... | Line 704... | |||
922 | if (data.Count.Equals(0)) |
704 | if (data.Count.Equals(0)) |
|
923 | throw new Exception(); |
705 | throw new Exception(); |
|
Line 971... | Line 753... | |||
971 | .Select(x => new Vector3(X, Y, Z)) |
753 | .Select(x => new Vector3(X, Y, Z)) |
|
972 | .ToList(); |
754 | .ToList(); |
|
Line 973... | Line 755... | |||
973 | |
755 | |
|
974 | // Get the map image. |
756 | // Get the map image. |
|
975 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
757 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
976 | wasKeyValueEscape(new Dictionary<string, string> |
758 | KeyValue.Escape(new Dictionary<string, string> |
|
977 | { |
759 | { |
|
978 | {"command", "getgridregiondata"}, |
760 | {"command", "getgridregiondata"}, |
|
979 | {"group", vassalConfiguration.Group}, |
761 | {"group", vassalConfiguration.Group}, |
|
980 | {"password", vassalConfiguration.Password}, |
762 | {"password", vassalConfiguration.Password}, |
|
981 | {"data", "MapImageID"} |
763 | {"data", "MapImageID"} |
|
Line 982... | Line 764... | |||
982 | }), vassalConfiguration.DataTimeout); |
764 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
983 | |
765 | |
|
984 | if (string.IsNullOrEmpty(result) || |
766 | if (string.IsNullOrEmpty(result) || |
|
Line 985... | Line 767... | |||
985 | !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
767 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
986 | throw new Exception(); |
768 | throw new Exception(); |
|
987 | |
769 | |
|
988 | data = wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))).ToList(); |
770 | data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
|
989 | if (!data.Count.Equals(2)) |
771 | if (!data.Count.Equals(2)) |
|
990 | throw new Exception(); |
772 | throw new Exception(); |
|
991 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
773 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
992 | wasKeyValueEscape(new Dictionary<string, string> |
774 | KeyValue.Escape(new Dictionary<string, string> |
|
993 | { |
775 | { |
|
994 | {"command", "download"}, |
776 | {"command", "download"}, |
|
995 | {"group", vassalConfiguration.Group}, |
777 | {"group", vassalConfiguration.Group}, |
|
996 | {"password", vassalConfiguration.Password}, |
778 | {"password", vassalConfiguration.Password}, |
|
997 | {"item", data.Last()}, |
779 | {"item", data.Last()}, |
|
998 | {"type", "Texture"}, |
780 | {"type", "Texture"}, |
|
999 | {"format", "Jpeg"} |
781 | {"format", "Jpeg"} |
|
1000 | }), vassalConfiguration.DataTimeout); |
782 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
1001 | if (string.IsNullOrEmpty(result) || |
783 | if (string.IsNullOrEmpty(result) || |
|
1002 | !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
784 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
1003 | throw new Exception(); |
785 | throw new Exception(); |
|
1004 | byte[] mapImageBytes = Convert.FromBase64String(wasInput(wasKeyValueGet("data", result))); |
786 | byte[] mapImageBytes = Convert.FromBase64String(wasInput(KeyValue.Get("data", result))); |
|
1005 | Image mapImage; |
787 | Image mapImage; |
|
1006 | using (MemoryStream memoryStream = new MemoryStream(mapImageBytes, 0, mapImageBytes.Length)) |
788 | using (MemoryStream memoryStream = new MemoryStream(mapImageBytes, 0, mapImageBytes.Length)) |
|
Line 1061... | Line 843... | |||
1061 | if (string.IsNullOrEmpty(regionName)) |
843 | if (string.IsNullOrEmpty(regionName)) |
|
1062 | throw new Exception(); |
844 | throw new Exception(); |
|
Line 1063... | Line 845... | |||
1063 | |
845 | |
|
1064 | // Get the region status. |
846 | // Get the region status. |
|
1065 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
847 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
1066 | wasKeyValueEscape(new Dictionary<string, string> |
848 | KeyValue.Escape(new Dictionary<string, string> |
|
1067 | { |
849 | { |
|
1068 | {"command", "getgridregiondata"}, |
850 | {"command", "getgridregiondata"}, |
|
1069 | {"group", vassalConfiguration.Group}, |
851 | {"group", vassalConfiguration.Group}, |
|
1070 | {"password", vassalConfiguration.Password}, |
852 | {"password", vassalConfiguration.Password}, |
|
1071 | {"region", regionName}, |
853 | {"region", regionName}, |
|
1072 | {"data", "Access"} |
854 | {"data", "Access"} |
|
Line 1073... | Line 855... | |||
1073 | }), vassalConfiguration.DataTimeout); |
855 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
1074 | |
856 | |
|
1075 | bool success; |
857 | bool success; |
|
1076 | if (string.IsNullOrEmpty(result) || |
858 | if (string.IsNullOrEmpty(result) || |
|
Line 1077... | Line 859... | |||
1077 | !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
859 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
1078 | throw new Exception(); |
860 | throw new Exception(); |
|
1079 | |
861 | |
|
Line 1080... | Line 862... | |||
1080 | List<string> data = wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))).ToList(); |
862 | List<string> data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
|
1081 | if (!data.Count.Equals(2)) |
863 | if (!data.Count.Equals(2)) |
|
Line 1142... | Line 924... | |||
1142 | |
924 | |
|
1143 | try |
925 | try |
|
1144 | { |
926 | { |
|
1145 | // Get the top scripts. |
927 | // Get the top scripts. |
|
1146 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
928 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
1147 | wasKeyValueEscape(new Dictionary<string, string> |
929 | KeyValue.Escape(new Dictionary<string, string> |
|
1148 | { |
930 | { |
|
1149 | {"command", "getregiontop"}, |
931 | {"command", "getregiontop"}, |
|
1150 | {"group", vassalConfiguration.Group}, |
932 | {"group", vassalConfiguration.Group}, |
|
1151 | {"password", vassalConfiguration.Password}, |
933 | {"password", vassalConfiguration.Password}, |
|
1152 | {"type", "scripts"} |
934 | {"type", "scripts"} |
|
Line 1153... | Line 935... | |||
1153 | }), vassalConfiguration.DataTimeout); |
935 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
1154 | |
936 | |
|
1155 | bool success; |
937 | bool success; |
|
1156 | if (string.IsNullOrEmpty(result) || |
938 | if (string.IsNullOrEmpty(result) || |
|
Line 1157... | Line 939... | |||
1157 | !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
939 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
1158 | throw new Exception(); |
940 | throw new Exception(); |
|
1159 | |
941 | |
|
1160 | HashSet<List<string>> data = |
942 | HashSet<List<string>> data = |
|
1161 | new HashSet<List<string>>(wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))) |
943 | new HashSet<List<string>>(CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
|
1162 | .Select((x, i) => new {Index = i, Value = x}) |
944 | .Select((x, i) => new {Index = i, Value = x}) |
|
1163 | .GroupBy(x => x.Index/5) |
945 | .GroupBy(x => x.Index/5) |
|
Line 1202... | Line 984... | |||
1202 | } |
984 | } |
|
1203 | })); |
985 | })); |
|
Line 1204... | Line 986... | |||
1204 | |
986 | |
|
1205 | // Get the top colliders. |
987 | // Get the top colliders. |
|
1206 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
988 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
1207 | wasKeyValueEscape(new Dictionary<string, string> |
989 | KeyValue.Escape(new Dictionary<string, string> |
|
1208 | { |
990 | { |
|
1209 | {"command", "getregiontop"}, |
991 | {"command", "getregiontop"}, |
|
1210 | {"group", vassalConfiguration.Group}, |
992 | {"group", vassalConfiguration.Group}, |
|
1211 | {"password", vassalConfiguration.Password}, |
993 | {"password", vassalConfiguration.Password}, |
|
1212 | {"type", "colliders"} |
994 | {"type", "colliders"} |
|
Line 1213... | Line 995... | |||
1213 | }), vassalConfiguration.DataTimeout); |
995 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
1214 | |
996 | |
|
1215 | if (string.IsNullOrEmpty(result) || |
997 | if (string.IsNullOrEmpty(result) || |
|
Line 1216... | Line 998... | |||
1216 | !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
998 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
1217 | throw new Exception(); |
999 | throw new Exception(); |
|
1218 | |
1000 | |
|
1219 | data = new HashSet<List<string>>(wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))) |
1001 | data = new HashSet<List<string>>(CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
|
1220 | .Select((x, i) => new {Index = i, Value = x}) |
1002 | .Select((x, i) => new {Index = i, Value = x}) |
|
1221 | .GroupBy(x => x.Index/5) |
1003 | .GroupBy(x => x.Index/5) |
|
Line 1286... | Line 1068... | |||
1286 | |
1068 | |
|
1287 | try |
1069 | try |
|
1288 | { |
1070 | { |
|
1289 | // Get the avatar positions. |
1071 | // Get the avatar positions. |
|
1290 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
1072 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
1291 | wasKeyValueEscape(new Dictionary<string, string> |
1073 | KeyValue.Escape(new Dictionary<string, string> |
|
1292 | { |
1074 | { |
|
1293 | {"command", "getavatarpositions"}, |
1075 | {"command", "getavatarpositions"}, |
|
1294 | {"group", vassalConfiguration.Group}, |
1076 | {"group", vassalConfiguration.Group}, |
|
1295 | {"password", vassalConfiguration.Password}, |
1077 | {"password", vassalConfiguration.Password}, |
|
1296 | {"entity", "region"} |
1078 | {"entity", "region"} |
|
Line 1297... | Line 1079... | |||
1297 | }), vassalConfiguration.DataTimeout); |
1079 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
1298 | |
1080 | |
|
1299 | bool success; |
1081 | bool success; |
|
1300 | if (string.IsNullOrEmpty(result) || |
1082 | if (string.IsNullOrEmpty(result) || |
|
Line 1301... | Line 1083... | |||
1301 | !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
1083 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
1302 | throw new Exception(); |
1084 | throw new Exception(); |
|
1303 | |
1085 | |
|
1304 | HashSet<List<string>> data = |
1086 | HashSet<List<string>> data = |
|
1305 | new HashSet<List<string>>(wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))) |
1087 | new HashSet<List<string>>(CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
|
1306 | .Select((x, i) => new {Index = i, Value = x}) |
1088 | .Select((x, i) => new {Index = i, Value = x}) |
|
1307 | .GroupBy(x => x.Index/3) |
1089 | .GroupBy(x => x.Index/3) |
|
Line 1368... | Line 1150... | |||
1368 | |
1150 | |
|
1369 | try |
1151 | try |
|
1370 | { |
1152 | { |
|
1371 | // Get the region terrain texture UUIDs. |
1153 | // Get the region terrain texture UUIDs. |
|
1372 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
1154 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
1373 | wasKeyValueEscape(new Dictionary<string, string> |
1155 | KeyValue.Escape(new Dictionary<string, string> |
|
1374 | { |
1156 | { |
|
1375 | {"command", "getregionterraintextures"}, |
1157 | {"command", "getregionterraintextures"}, |
|
1376 | {"group", vassalConfiguration.Group}, |
1158 | {"group", vassalConfiguration.Group}, |
|
1377 | {"password", vassalConfiguration.Password} |
1159 | {"password", vassalConfiguration.Password} |
|
Line 1378... | Line 1160... | |||
1378 | }), vassalConfiguration.DataTimeout); |
1160 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
1379 | |
1161 | |
|
1380 | bool success; |
1162 | bool success; |
|
1381 | if (string.IsNullOrEmpty(result) || |
1163 | if (string.IsNullOrEmpty(result) || |
|
Line 1382... | Line 1164... | |||
1382 | !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
1164 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
1383 | throw new Exception(); |
1165 | throw new Exception(); |
|
1384 | |
1166 | |
|
Line 1385... | Line 1167... | |||
1385 | List<string> data = wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))).ToList(); |
1167 | List<string> data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
|
1386 | if (!data.Count.Equals(4)) |
1168 | if (!data.Count.Equals(4)) |
|
Line 1411... | Line 1193... | |||
1411 | })); |
1193 | })); |
|
Line 1412... | Line 1194... | |||
1412 | |
1194 | |
|
1413 | Parallel.ForEach(Enumerable.Range(0, 4), i => |
1195 | Parallel.ForEach(Enumerable.Range(0, 4), i => |
|
1414 | { |
1196 | { |
|
1415 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
1197 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
1416 | wasKeyValueEscape(new Dictionary<string, string> |
1198 | KeyValue.Escape(new Dictionary<string, string> |
|
1417 | { |
1199 | { |
|
1418 | {"command", "download"}, |
1200 | {"command", "download"}, |
|
1419 | {"group", vassalConfiguration.Group}, |
1201 | {"group", vassalConfiguration.Group}, |
|
1420 | {"password", vassalConfiguration.Password}, |
1202 | {"password", vassalConfiguration.Password}, |
|
1421 | {"item", data[i]}, |
1203 | {"item", data[i]}, |
|
1422 | {"type", "Texture"}, |
1204 | {"type", "Texture"}, |
|
1423 | {"format", "Jpeg"} |
1205 | {"format", "Jpeg"} |
|
Line 1424... | Line 1206... | |||
1424 | }), vassalConfiguration.DataTimeout); |
1206 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
1425 | |
1207 | |
|
1426 | if (string.IsNullOrEmpty(result) || |
1208 | if (string.IsNullOrEmpty(result) || |
|
Line 1427... | Line 1209... | |||
1427 | !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
1209 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
1428 | return; |
1210 | return; |
|
1429 | |
1211 | |
|
1430 | byte[] mapImageBytes = Convert.FromBase64String(wasInput(wasKeyValueGet("data", result))); |
1212 | byte[] mapImageBytes = Convert.FromBase64String(wasInput(KeyValue.Get("data", result))); |
|
1431 | using (MemoryStream memoryStream = new MemoryStream(mapImageBytes, 0, mapImageBytes.Length)) |
1213 | using (MemoryStream memoryStream = new MemoryStream(mapImageBytes, 0, mapImageBytes.Length)) |
|
Line 1501... | Line 1283... | |||
1501 | |
1283 | |
|
1502 | using (StreamWriter streamWriter = new StreamWriter(file, false, Encoding.UTF8)) |
1284 | using (StreamWriter streamWriter = new StreamWriter(file, false, Encoding.UTF8)) |
|
1503 | { |
1285 | { |
|
1504 | foreach (DataGridViewRow topScriptsRow in TopScriptsGridView.Rows) |
1286 | foreach (DataGridViewRow topScriptsRow in TopScriptsGridView.Rows) |
|
1505 | { |
1287 | { |
|
1506 | streamWriter.WriteLine(wasEnumerableToCSV(new[] |
1288 | streamWriter.WriteLine(CSV.FromEnumerable(new[] |
|
1507 | { |
1289 | { |
|
1508 | topScriptsRow.Cells["TopScriptsScore"].Value.ToString(), |
1290 | topScriptsRow.Cells["TopScriptsScore"].Value.ToString(), |
|
1509 | topScriptsRow.Cells["TopScriptsTaskName"].Value.ToString(), |
1291 | topScriptsRow.Cells["TopScriptsTaskName"].Value.ToString(), |
|
1510 | topScriptsRow.Cells["TopScriptsUUID"].Value.ToString(), |
1292 | topScriptsRow.Cells["TopScriptsUUID"].Value.ToString(), |
|
Line 1548... | Line 1330... | |||
1548 | |
1330 | |
|
1549 | using (StreamWriter streamWriter = new StreamWriter(file, false, Encoding.UTF8)) |
1331 | using (StreamWriter streamWriter = new StreamWriter(file, false, Encoding.UTF8)) |
|
1550 | { |
1332 | { |
|
1551 | foreach (DataGridViewRow topCollidersRow in TopCollidersGridView.Rows) |
1333 | foreach (DataGridViewRow topCollidersRow in TopCollidersGridView.Rows) |
|
1552 | { |
1334 | { |
|
1553 | streamWriter.WriteLine(wasEnumerableToCSV(new[] |
1335 | streamWriter.WriteLine(CSV.FromEnumerable(new[] |
|
1554 | { |
1336 | { |
|
1555 | topCollidersRow.Cells["TopCollidersScore"].Value.ToString(), |
1337 | topCollidersRow.Cells["TopCollidersScore"].Value.ToString(), |
|
1556 | topCollidersRow.Cells["TopCollidersTaskName"].Value.ToString(), |
1338 | topCollidersRow.Cells["TopCollidersTaskName"].Value.ToString(), |
|
1557 | topCollidersRow.Cells["TopCollidersUUID"].Value.ToString(), |
1339 | topCollidersRow.Cells["TopCollidersUUID"].Value.ToString(), |
|
Line 1692... | Line 1474... | |||
1692 | string currentRegionName = string.Empty; |
1474 | string currentRegionName = string.Empty; |
|
1693 | vassalForm.Invoke((MethodInvoker) (() => { currentRegionName = CurrentRegionName.Text; })); |
1475 | vassalForm.Invoke((MethodInvoker) (() => { currentRegionName = CurrentRegionName.Text; })); |
|
Line 1694... | Line 1476... | |||
1694 | |
1476 | |
|
1695 | // Teleport to the object. |
1477 | // Teleport to the object. |
|
1696 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
1478 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
1697 | wasKeyValueEscape(new Dictionary<string, string> |
1479 | KeyValue.Escape(new Dictionary<string, string> |
|
1698 | { |
1480 | { |
|
1699 | {"command", "teleport"}, |
1481 | {"command", "teleport"}, |
|
1700 | {"group", vassalConfiguration.Group}, |
1482 | {"group", vassalConfiguration.Group}, |
|
1701 | {"password", vassalConfiguration.Password}, |
1483 | {"password", vassalConfiguration.Password}, |
|
1702 | {"position", objectData.Value.ToString()}, |
1484 | {"position", objectData.Value.ToString()}, |
|
1703 | {"region", currentRegionName}, |
1485 | {"region", currentRegionName}, |
|
1704 | {"fly", "True"} |
1486 | {"fly", "True"} |
|
Line 1705... | Line 1487... | |||
1705 | }), vassalConfiguration.TeleportTimeout); |
1487 | }, wasOutput), vassalConfiguration.TeleportTimeout); |
|
1706 | |
1488 | |
|
1707 | if (string.IsNullOrEmpty(result)) |
1489 | if (string.IsNullOrEmpty(result)) |
|
1708 | { |
1490 | { |
|
Line 1712... | Line 1494... | |||
1712 | continue; |
1494 | continue; |
|
1713 | } |
1495 | } |
|
Line 1714... | Line 1496... | |||
1714 | |
1496 | |
|
1715 | // Return the object. |
1497 | // Return the object. |
|
1716 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
1498 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
1717 | wasKeyValueEscape(new Dictionary<string, string> |
1499 | KeyValue.Escape(new Dictionary<string, string> |
|
1718 | { |
1500 | { |
|
1719 | {"command", "derez"}, |
1501 | {"command", "derez"}, |
|
1720 | {"group", vassalConfiguration.Group}, |
1502 | {"group", vassalConfiguration.Group}, |
|
1721 | {"password", vassalConfiguration.Password}, |
1503 | {"password", vassalConfiguration.Password}, |
|
1722 | {"item", objectData.Key.ToString()}, |
1504 | {"item", objectData.Key.ToString()}, |
|
1723 | {"range", "32"}, // maximal prim size = 64 - middle bounding box at half |
1505 | {"range", "32"}, // maximal prim size = 64 - middle bounding box at half |
|
1724 | {"type", "ReturnToOwner"} |
1506 | {"type", "ReturnToOwner"} |
|
Line 1725... | Line 1507... | |||
1725 | }), vassalConfiguration.DataTimeout); |
1507 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
1726 | |
1508 | |
|
1727 | if (string.IsNullOrEmpty(result)) |
1509 | if (string.IsNullOrEmpty(result)) |
|
1728 | { |
1510 | { |
|
1729 | vassalForm.Invoke( |
1511 | vassalForm.Invoke( |
|
1730 | (MethodInvoker) |
1512 | (MethodInvoker) |
|
1731 | (() => { vassalForm.StatusText.Text = @"Error communicating with Corrade."; })); |
1513 | (() => { vassalForm.StatusText.Text = @"Error communicating with Corrade."; })); |
|
Line 1732... | Line 1514... | |||
1732 | continue; |
1514 | continue; |
|
1733 | } |
1515 | } |
|
1734 | |
1516 | |
|
1735 | bool success; |
1517 | bool success; |
|
1736 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
1518 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
1737 | { |
1519 | { |
|
1738 | vassalForm.Invoke( |
1520 | vassalForm.Invoke( |
|
Line 1761... | Line 1543... | |||
1761 | case false: |
1543 | case false: |
|
1762 | vassalForm.Invoke((MethodInvoker) (() => |
1544 | vassalForm.Invoke((MethodInvoker) (() => |
|
1763 | { |
1545 | { |
|
1764 | vassalForm.StatusText.Text = @"Could not return object " + objectData.Key + |
1546 | vassalForm.StatusText.Text = @"Could not return object " + objectData.Key + |
|
1765 | @": " + |
1547 | @": " + |
|
1766 | wasInput(wasKeyValueGet("error", result)); |
1548 | wasInput(KeyValue.Get("error", result)); |
|
1767 | })); |
1549 | })); |
|
1768 | break; |
1550 | break; |
|
1769 | } |
1551 | } |
|
1770 | vassalForm.Invoke((MethodInvoker) (() => |
1552 | vassalForm.Invoke((MethodInvoker) (() => |
|
1771 | { |
1553 | { |
|
Line 1854... | Line 1636... | |||
1854 | string currentRegionName = string.Empty; |
1636 | string currentRegionName = string.Empty; |
|
1855 | vassalForm.Invoke((MethodInvoker) (() => { currentRegionName = CurrentRegionName.Text; })); |
1637 | vassalForm.Invoke((MethodInvoker) (() => { currentRegionName = CurrentRegionName.Text; })); |
|
Line 1856... | Line 1638... | |||
1856 | |
1638 | |
|
1857 | // Teleport to the object. |
1639 | // Teleport to the object. |
|
1858 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
1640 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
1859 | wasKeyValueEscape(new Dictionary<string, string> |
1641 | KeyValue.Escape(new Dictionary<string, string> |
|
1860 | { |
1642 | { |
|
1861 | {"command", "teleport"}, |
1643 | {"command", "teleport"}, |
|
1862 | {"group", vassalConfiguration.Group}, |
1644 | {"group", vassalConfiguration.Group}, |
|
1863 | {"password", vassalConfiguration.Password}, |
1645 | {"password", vassalConfiguration.Password}, |
|
1864 | {"position", objectData.Value.ToString()}, |
1646 | {"position", objectData.Value.ToString()}, |
|
1865 | {"region", currentRegionName}, |
1647 | {"region", currentRegionName}, |
|
1866 | {"fly", "True"} |
1648 | {"fly", "True"} |
|
Line 1867... | Line 1649... | |||
1867 | }), vassalConfiguration.DataTimeout); |
1649 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
1868 | |
1650 | |
|
1869 | if (string.IsNullOrEmpty(result)) |
1651 | if (string.IsNullOrEmpty(result)) |
|
1870 | { |
1652 | { |
|
Line 1874... | Line 1656... | |||
1874 | continue; |
1656 | continue; |
|
1875 | } |
1657 | } |
|
Line 1876... | Line 1658... | |||
1876 | |
1658 | |
|
1877 | // Return the object. |
1659 | // Return the object. |
|
1878 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
1660 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
1879 | wasKeyValueEscape(new Dictionary<string, string> |
1661 | KeyValue.Escape(new Dictionary<string, string> |
|
1880 | { |
1662 | { |
|
1881 | {"command", "derez"}, |
1663 | {"command", "derez"}, |
|
1882 | {"group", vassalConfiguration.Group}, |
1664 | {"group", vassalConfiguration.Group}, |
|
1883 | {"password", vassalConfiguration.Password}, |
1665 | {"password", vassalConfiguration.Password}, |
|
1884 | {"item", objectData.Key.ToString()}, |
1666 | {"item", objectData.Key.ToString()}, |
|
1885 | {"range", "32"}, // maximal prim size = 64 - middle bounding box at half |
1667 | {"range", "32"}, // maximal prim size = 64 - middle bounding box at half |
|
1886 | {"type", "ReturnToOwner"} |
1668 | {"type", "ReturnToOwner"} |
|
Line 1887... | Line 1669... | |||
1887 | }), vassalConfiguration.DataTimeout); |
1669 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
1888 | |
1670 | |
|
1889 | if (string.IsNullOrEmpty(result)) |
1671 | if (string.IsNullOrEmpty(result)) |
|
1890 | { |
1672 | { |
|
1891 | vassalForm.Invoke( |
1673 | vassalForm.Invoke( |
|
1892 | (MethodInvoker) |
1674 | (MethodInvoker) |
|
1893 | (() => { vassalForm.StatusText.Text = @"Error communicating with Corrade."; })); |
1675 | (() => { vassalForm.StatusText.Text = @"Error communicating with Corrade."; })); |
|
Line 1894... | Line 1676... | |||
1894 | continue; |
1676 | continue; |
|
1895 | } |
1677 | } |
|
1896 | |
1678 | |
|
1897 | bool success; |
1679 | bool success; |
|
1898 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
1680 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
1899 | { |
1681 | { |
|
1900 | vassalForm.Invoke( |
1682 | vassalForm.Invoke( |
|
Line 1923... | Line 1705... | |||
1923 | case false: |
1705 | case false: |
|
1924 | vassalForm.Invoke((MethodInvoker) (() => |
1706 | vassalForm.Invoke((MethodInvoker) (() => |
|
1925 | { |
1707 | { |
|
1926 | vassalForm.StatusText.Text = @"Could not return object " + objectData.Key + |
1708 | vassalForm.StatusText.Text = @"Could not return object " + objectData.Key + |
|
1927 | @": " + |
1709 | @": " + |
|
1928 | wasInput(wasKeyValueGet("error", result)); |
1710 | wasInput(KeyValue.Get("error", result)); |
|
1929 | })); |
1711 | })); |
|
1930 | break; |
1712 | break; |
|
1931 | } |
1713 | } |
|
1932 | vassalForm.Invoke((MethodInvoker) (() => |
1714 | vassalForm.Invoke((MethodInvoker) (() => |
|
1933 | { |
1715 | { |
|
Line 2040... | Line 1822... | |||
2040 | @")"; |
1822 | @")"; |
|
2041 | })); |
1823 | })); |
|
Line 2042... | Line 1824... | |||
2042 | |
1824 | |
|
2043 | // Teleport to the region. |
1825 | // Teleport to the region. |
|
2044 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
1826 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
2045 | wasKeyValueEscape(new Dictionary<string, string> |
1827 | KeyValue.Escape(new Dictionary<string, string> |
|
2046 | { |
1828 | { |
|
2047 | {"command", "teleport"}, |
1829 | {"command", "teleport"}, |
|
2048 | {"group", vassalConfiguration.Group}, |
1830 | {"group", vassalConfiguration.Group}, |
|
2049 | {"password", vassalConfiguration.Password}, |
1831 | {"password", vassalConfiguration.Password}, |
|
2050 | {"position", restartRegionData.Value.ToString()}, |
1832 | {"position", restartRegionData.Value.ToString()}, |
|
2051 | {"region", restartRegionData.Key}, |
1833 | {"region", restartRegionData.Key}, |
|
2052 | {"fly", "True"} |
1834 | {"fly", "True"} |
|
Line 2053... | Line 1835... | |||
2053 | }), vassalConfiguration.DataTimeout); |
1835 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
2054 | |
1836 | |
|
2055 | if (string.IsNullOrEmpty(result)) |
1837 | if (string.IsNullOrEmpty(result)) |
|
2056 | { |
1838 | { |
|
Line 2060... | Line 1842... | |||
2060 | { |
1842 | { |
|
2061 | vassalForm.StatusText.Text = @"Error communicating with Corrade."; |
1843 | vassalForm.StatusText.Text = @"Error communicating with Corrade."; |
|
2062 | })); |
1844 | })); |
|
2063 | continue; |
1845 | continue; |
|
2064 | } |
1846 | } |
|
2065 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
1847 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
2066 | { |
1848 | { |
|
2067 | vassalForm.Invoke( |
1849 | vassalForm.Invoke( |
|
2068 | (MethodInvoker) |
1850 | (MethodInvoker) |
|
2069 | (() => |
1851 | (() => |
|
2070 | { |
1852 | { |
|
Line 2082... | Line 1864... | |||
2082 | default: |
1864 | default: |
|
2083 | // In case the destination is to close (Corrade status code 37559), |
1865 | // In case the destination is to close (Corrade status code 37559), |
|
2084 | // then we are on the same region so no need to retry. |
1866 | // then we are on the same region so no need to retry. |
|
2085 | uint status; //37559 |
1867 | uint status; //37559 |
|
2086 | switch ( |
1868 | switch ( |
|
2087 | uint.TryParse(wasInput(wasKeyValueGet("status", result)), out status) && |
1869 | uint.TryParse(wasInput(KeyValue.Get("status", result)), out status) && |
|
2088 | status.Equals(37559)) |
1870 | status.Equals(37559)) |
|
2089 | { |
1871 | { |
|
2090 | case true: // We are on the region already! |
1872 | case true: // We are on the region already! |
|
2091 | success = true; |
1873 | success = true; |
|
2092 | break; |
1874 | break; |
|
Line 2105... | Line 1887... | |||
2105 | |
1887 | |
|
2106 | if (!success) |
1888 | if (!success) |
|
Line 2107... | Line 1889... | |||
2107 | throw new Exception("Failed to teleport to region."); |
1889 | throw new Exception("Failed to teleport to region."); |
|
2108 | |
1890 | |
|
2109 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
1891 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
2110 | wasKeyValueEscape(new Dictionary<string, string> |
1892 | KeyValue.Escape(new Dictionary<string, string> |
|
2111 | { |
1893 | { |
|
2112 | {"command", "getregiondata"}, |
1894 | {"command", "getregiondata"}, |
|
2113 | {"group", vassalConfiguration.Group}, |
1895 | {"group", vassalConfiguration.Group}, |
|
2114 | {"password", vassalConfiguration.Password}, |
1896 | {"password", vassalConfiguration.Password}, |
|
Line 2115... | Line 1897... | |||
2115 | {"data", "IsEstateManager"} |
1897 | {"data", "IsEstateManager"} |
|
2116 | }), vassalConfiguration.DataTimeout); |
1898 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
Line 2117... | Line 1899... | |||
2117 | |
1899 | |
|
2118 | if (string.IsNullOrEmpty(result)) |
1900 | if (string.IsNullOrEmpty(result)) |
|
Line 2119... | Line 1901... | |||
2119 | throw new Exception("Error communicating with Corrade."); |
1901 | throw new Exception("Error communicating with Corrade."); |
|
2120 | |
1902 | |
|
Line 2121... | Line 1903... | |||
2121 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
1903 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
2122 | throw new Exception("No success status could be retrieved."); |
1904 | throw new Exception("No success status could be retrieved."); |
|
2123 | |
1905 | |
|
Line 2124... | Line 1906... | |||
2124 | if (!success) |
1906 | if (!success) |
|
2125 | throw new Exception("Could not retrieve estate rights."); |
1907 | throw new Exception("Could not retrieve estate rights."); |
|
2126 | |
1908 | |
|
2127 | List<string> data = wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))).ToList(); |
1909 | List<string> data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
|
2128 | if (!data.Count.Equals(2)) |
1910 | if (!data.Count.Equals(2)) |
|
2129 | throw new Exception("Could not retrieve estate rights."); |
1911 | throw new Exception("Could not retrieve estate rights."); |
|
2130 | |
1912 | |
|
2131 | bool isEstateManager; |
1913 | bool isEstateManager; |
|
2132 | switch ( |
1914 | switch ( |
|
2133 | bool.TryParse(data[data.IndexOf("IsEstateManager") + 1], out isEstateManager) && |
1915 | bool.TryParse(data[data.IndexOf("IsEstateManager") + 1], out isEstateManager) && |
|
2134 | isEstateManager) |
1916 | isEstateManager) |
|
2135 | { |
1917 | { |
|
2136 | case true: // we are an estate manager |
1918 | case true: // we are an estate manager |
|
2137 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
1919 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
2138 | wasKeyValueEscape(new Dictionary<string, string> |
1920 | KeyValue.Escape(new Dictionary<string, string> |
|
2139 | { |
1921 | { |
|
2140 | {"command", "restartregion"}, |
1922 | {"command", "restartregion"}, |
|
2141 | {"group", vassalConfiguration.Group}, |
1923 | {"group", vassalConfiguration.Group}, |
|
Line 2142... | Line 1924... | |||
2142 | {"password", vassalConfiguration.Password}, |
1924 | {"password", vassalConfiguration.Password}, |
|
2143 | {"action", "restart"}, |
1925 | {"action", "restart"}, |
|
Line 2144... | Line 1926... | |||
2144 | { |
1926 | { |
|
2145 | "delay", |
1927 | "delay", |
|
Line 2146... | Line 1928... | |||
2146 | vassalConfiguration.RegionRestartDelay.ToString(Utils.EnUsCulture) |
1928 | vassalConfiguration.RegionRestartDelay.ToString(Utils.EnUsCulture) |
|
2147 | } |
1929 | } |
|
Line 2304... | Line 2086... | |||
2304 | vassalForm.Invoke( |
2086 | vassalForm.Invoke( |
|
2305 | (MethodInvoker) (() => { alsoBan = vassalForm.ResidentBanAllEstatesBox.Checked; })); |
2087 | (MethodInvoker) (() => { alsoBan = vassalForm.ResidentBanAllEstatesBox.Checked; })); |
|
Line 2306... | Line 2088... | |||
2306 | |
2088 | |
|
2307 | // Ban the resident. |
2089 | // Ban the resident. |
|
2308 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
2090 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
2309 | wasKeyValueEscape(new Dictionary<string, string> |
2091 | KeyValue.Escape(new Dictionary<string, string> |
|
2310 | { |
2092 | { |
|
2311 | {"command", "setestatelist"}, |
2093 | {"command", "setestatelist"}, |
|
2312 | {"group", vassalConfiguration.Group}, |
2094 | {"group", vassalConfiguration.Group}, |
|
2313 | {"password", vassalConfiguration.Password}, |
2095 | {"password", vassalConfiguration.Password}, |
|
2314 | {"type", "ban"}, |
2096 | {"type", "ban"}, |
|
2315 | {"action", "add"}, |
2097 | {"action", "add"}, |
|
2316 | {"agent", agentUUID.ToString()}, |
2098 | {"agent", agentUUID.ToString()}, |
|
2317 | {"all", alsoBan.ToString()} |
2099 | {"all", alsoBan.ToString()} |
|
Line 2318... | Line 2100... | |||
2318 | }), vassalConfiguration.DataTimeout); |
2100 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
2319 | |
2101 | |
|
Line 2320... | Line 2102... | |||
2320 | if (string.IsNullOrEmpty(result)) |
2102 | if (string.IsNullOrEmpty(result)) |
|
2321 | throw new Exception("Error communicating with Corrade."); |
2103 | throw new Exception("Error communicating with Corrade."); |
|
2322 | |
2104 | |
|
Line 2323... | Line 2105... | |||
2323 | bool success; |
2105 | bool success; |
|
2324 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
2106 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
2325 | throw new Exception("No success status could be retrieved."); |
2107 | throw new Exception("No success status could be retrieved."); |
|
Line 2394... | Line 2176... | |||
2394 | |
2176 | |
|
2395 | try |
2177 | try |
|
2396 | { |
2178 | { |
|
2397 | // Get the map heights. |
2179 | // Get the map heights. |
|
2398 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
2180 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
2399 | wasKeyValueEscape(new Dictionary<string, string> |
2181 | KeyValue.Escape(new Dictionary<string, string> |
|
2400 | { |
2182 | { |
|
2401 | {"command", "getterrainheight"}, |
2183 | {"command", "getterrainheight"}, |
|
2402 | {"group", vassalConfiguration.Group}, |
2184 | {"group", vassalConfiguration.Group}, |
|
2403 | {"password", vassalConfiguration.Password}, |
2185 | {"password", vassalConfiguration.Password}, |
|
2404 | {"entity", "region"} |
2186 | {"entity", "region"} |
|
Line 2405... | Line 2187... | |||
2405 | }), vassalConfiguration.DataTimeout); |
2187 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
2406 | |
2188 | |
|
Line 2407... | Line 2189... | |||
2407 | if (string.IsNullOrEmpty(result)) |
2189 | if (string.IsNullOrEmpty(result)) |
|
2408 | throw new Exception("Error communicating with Corrade."); |
2190 | throw new Exception("Error communicating with Corrade."); |
|
2409 | |
2191 | |
|
Line 2410... | Line 2192... | |||
2410 | bool success; |
2192 | bool success; |
|
2411 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
2193 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
Line 2412... | Line 2194... | |||
2412 | throw new Exception("No success status could be retrieved."); |
2194 | throw new Exception("No success status could be retrieved."); |
|
2413 | |
2195 | |
|
2414 | if (!success) |
2196 | if (!success) |
|
2415 | throw new Exception("Could not get terrain heights."); |
2197 | throw new Exception("Could not get terrain heights."); |
|
2416 | |
2198 | |
|
2417 | List<double> heights = new List<double>(); |
2199 | List<double> heights = new List<double>(); |
|
2418 | foreach (string map in wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result)))) |
2200 | foreach (string map in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result)))) |
|
Line 2432... | Line 2214... | |||
2432 | { |
2214 | { |
|
2433 | foreach (int y in Enumerable.Range(1, 255)) |
2215 | foreach (int y in Enumerable.Range(1, 255)) |
|
2434 | { |
2216 | { |
|
2435 | bitmap.SetPixel(x, 256 - y, |
2217 | bitmap.SetPixel(x, 256 - y, |
|
2436 | Color.FromArgb( |
2218 | Color.FromArgb( |
|
- | 2219 | Math.Max( |
||
2437 | Math.Max((int) wasMapValueToRange(heights[256*x + y], 0, maxHeight, 0, 255), 0), |
2220 | (int) Numerics.MapValueToRange(heights[256*x + y], 0, maxHeight, 0, 255), 0), |
|
2438 | 0, 0)); |
2221 | 0, 0)); |
|
2439 | } |
2222 | } |
|
2440 | } |
2223 | } |
|
2441 | Bitmap closureBitmap = (Bitmap) bitmap.Clone(); |
2224 | Bitmap closureBitmap = (Bitmap) bitmap.Clone(); |
|
2442 | vassalForm.BeginInvoke((MethodInvoker) (() => |
2225 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
Line 2506... | Line 2289... | |||
2506 | |
2289 | |
|
2507 | try |
2290 | try |
|
2508 | { |
2291 | { |
|
2509 | // Download the terrain. |
2292 | // Download the terrain. |
|
2510 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
2293 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
2511 | wasKeyValueEscape(new Dictionary<string, string> |
2294 | KeyValue.Escape(new Dictionary<string, string> |
|
2512 | { |
2295 | { |
|
2513 | {"command", "terrain"}, |
2296 | {"command", "terrain"}, |
|
2514 | {"group", vassalConfiguration.Group}, |
2297 | {"group", vassalConfiguration.Group}, |
|
2515 | {"password", vassalConfiguration.Password}, |
2298 | {"password", vassalConfiguration.Password}, |
|
2516 | {"action", "get"} |
2299 | {"action", "get"} |
|
Line 2517... | Line 2300... | |||
2517 | }), vassalConfiguration.DataTimeout); |
2300 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
2518 | |
2301 | |
|
Line 2519... | Line 2302... | |||
2519 | if (string.IsNullOrEmpty(result)) |
2302 | if (string.IsNullOrEmpty(result)) |
|
2520 | throw new Exception("Error communicating with Corrade."); |
2303 | throw new Exception("Error communicating with Corrade."); |
|
2521 | |
2304 | |
|
Line 2522... | Line 2305... | |||
2522 | bool success; |
2305 | bool success; |
|
2523 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
2306 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
Line 2524... | Line 2307... | |||
2524 | throw new Exception("No success status could be retrieved."); |
2307 | throw new Exception("No success status could be retrieved."); |
|
Line 2525... | Line 2308... | |||
2525 | |
2308 | |
|
2526 | if (!success) |
2309 | if (!success) |
|
2527 | throw new Exception("Could not download terrain."); |
2310 | throw new Exception("Could not download terrain."); |
|
2528 | |
2311 | |
|
Line 2609... | Line 2392... | |||
2609 | } |
2392 | } |
|
2610 | })); |
2393 | })); |
|
Line 2611... | Line 2394... | |||
2611 | |
2394 | |
|
2612 | // Upload the terrain. |
2395 | // Upload the terrain. |
|
2613 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
2396 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
2614 | wasKeyValueEscape(new Dictionary<string, string> |
2397 | KeyValue.Escape(new Dictionary<string, string> |
|
2615 | { |
2398 | { |
|
2616 | {"command", "terrain"}, |
2399 | {"command", "terrain"}, |
|
2617 | {"group", vassalConfiguration.Group}, |
2400 | {"group", vassalConfiguration.Group}, |
|
2618 | {"password", vassalConfiguration.Password}, |
2401 | {"password", vassalConfiguration.Password}, |
|
2619 | {"action", "set"}, |
2402 | {"action", "set"}, |
|
2620 | {"data", Convert.ToBase64String(data)} |
2403 | {"data", Convert.ToBase64String(data)} |
|
Line 2621... | Line 2404... | |||
2621 | }), vassalConfiguration.DataTimeout); |
2404 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
2622 | |
2405 | |
|
Line 2623... | Line 2406... | |||
2623 | if (string.IsNullOrEmpty(result)) |
2406 | if (string.IsNullOrEmpty(result)) |
|
2624 | throw new Exception("Error communicating with Corrade."); |
2407 | throw new Exception("Error communicating with Corrade."); |
|
2625 | |
2408 | |
|
Line 2626... | Line 2409... | |||
2626 | bool success; |
2409 | bool success; |
|
2627 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
2410 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
2628 | throw new Exception("No success status could be retrieved."); |
2411 | throw new Exception("No success status could be retrieved."); |
|
Line 2743... | Line 2526... | |||
2743 | EstateListsGroupsGroup.Enabled = false; |
2526 | EstateListsGroupsGroup.Enabled = false; |
|
2744 | })); |
2527 | })); |
|
Line 2745... | Line 2528... | |||
2745 | |
2528 | |
|
2746 | // Get the selected estate list. |
2529 | // Get the selected estate list. |
|
2747 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
2530 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
2748 | wasKeyValueEscape(new Dictionary<string, string> |
2531 | KeyValue.Escape(new Dictionary<string, string> |
|
2749 | { |
2532 | { |
|
2750 | {"command", "getestatelist"}, |
2533 | {"command", "getestatelist"}, |
|
2751 | {"group", vassalConfiguration.Group}, |
2534 | {"group", vassalConfiguration.Group}, |
|
2752 | {"password", vassalConfiguration.Password}, |
2535 | {"password", vassalConfiguration.Password}, |
|
2753 | {"type", selectedEstateListType} |
2536 | {"type", selectedEstateListType} |
|
Line 2754... | Line 2537... | |||
2754 | }), vassalConfiguration.DataTimeout); |
2537 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
2755 | |
2538 | |
|
Line 2756... | Line 2539... | |||
2756 | if (string.IsNullOrEmpty(result)) |
2539 | if (string.IsNullOrEmpty(result)) |
|
2757 | throw new Exception("Error communicating with Corrade."); |
2540 | throw new Exception("Error communicating with Corrade."); |
|
2758 | |
2541 | |
|
Line 2759... | Line 2542... | |||
2759 | bool success; |
2542 | bool success; |
|
2760 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
2543 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
Line 2761... | Line 2544... | |||
2761 | throw new Exception("No success status could be retrieved."); |
2544 | throw new Exception("No success status could be retrieved."); |
|
2762 | |
2545 | |
|
2763 | if (!success) |
2546 | if (!success) |
|
2764 | throw new Exception("Could not retrieve estate list."); |
2547 | throw new Exception("Could not retrieve estate list."); |
|
2765 | |
2548 | |
|
2766 | vassalForm.Invoke((MethodInvoker) (() => { EstateListGridView.Rows.Clear(); })); |
2549 | vassalForm.Invoke((MethodInvoker) (() => { EstateListGridView.Rows.Clear(); })); |
|
2767 | foreach (List<string> data in wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))) |
2550 | foreach (List<string> data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
|
Line 2873... | Line 2656... | |||
2873 | { |
2656 | { |
|
2874 | memberUUID = estateListMembersQueue.Dequeue(); |
2657 | memberUUID = estateListMembersQueue.Dequeue(); |
|
Line 2875... | Line 2658... | |||
2875 | |
2658 | |
|
2876 | // Remove the agent or group from the list. |
2659 | // Remove the agent or group from the list. |
|
2877 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
2660 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
2878 | wasKeyValueEscape(new Dictionary<string, string> |
2661 | KeyValue.Escape(new Dictionary<string, string> |
|
2879 | { |
2662 | { |
|
2880 | {"command", "setestatelist"}, |
2663 | {"command", "setestatelist"}, |
|
2881 | {"group", vassalConfiguration.Group}, |
2664 | {"group", vassalConfiguration.Group}, |
|
2882 | {"password", vassalConfiguration.Password}, |
2665 | {"password", vassalConfiguration.Password}, |
|
2883 | {"type", selectedEstateListType}, |
2666 | {"type", selectedEstateListType}, |
|
2884 | {"action", "remove"}, |
2667 | {"action", "remove"}, |
|
2885 | {selectedEstateListType.Equals("group") ? "target" : "agent", memberUUID.ToString()} |
2668 | {selectedEstateListType.Equals("group") ? "target" : "agent", memberUUID.ToString()} |
|
Line 2886... | Line 2669... | |||
2886 | }), vassalConfiguration.DataTimeout); |
2669 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
2887 | |
2670 | |
|
Line 2888... | Line 2671... | |||
2888 | if (string.IsNullOrEmpty(result)) |
2671 | if (string.IsNullOrEmpty(result)) |
|
2889 | throw new Exception("Error communicating with Corrade"); |
2672 | throw new Exception("Error communicating with Corrade"); |
|
2890 | |
2673 | |
|
Line 2891... | Line 2674... | |||
2891 | bool success; |
2674 | bool success; |
|
2892 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
2675 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
Line 3001... | Line 2784... | |||
3001 | { |
2784 | { |
|
3002 | Monitor.Enter(ClientInstanceTeleportLock); |
2785 | Monitor.Enter(ClientInstanceTeleportLock); |
|
Line 3003... | Line 2786... | |||
3003 | |
2786 | |
|
3004 | // Add the resident to the list. |
2787 | // Add the resident to the list. |
|
3005 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
2788 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
3006 | wasKeyValueEscape(new Dictionary<string, string> |
2789 | KeyValue.Escape(new Dictionary<string, string> |
|
3007 | { |
2790 | { |
|
3008 | {"command", "setestatelist"}, |
2791 | {"command", "setestatelist"}, |
|
3009 | {"group", vassalConfiguration.Group}, |
2792 | {"group", vassalConfiguration.Group}, |
|
3010 | {"password", vassalConfiguration.Password}, |
2793 | {"password", vassalConfiguration.Password}, |
|
3011 | {"type", selectedEstateListType}, |
2794 | {"type", selectedEstateListType}, |
|
3012 | {"action", "add"}, |
2795 | {"action", "add"}, |
|
3013 | {"firstname", firstName}, |
2796 | {"firstname", firstName}, |
|
3014 | {"lastname", lastName} |
2797 | {"lastname", lastName} |
|
Line 3015... | Line 2798... | |||
3015 | }), vassalConfiguration.DataTimeout); |
2798 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
3016 | |
2799 | |
|
Line 3017... | Line 2800... | |||
3017 | if (string.IsNullOrEmpty(result)) |
2800 | if (string.IsNullOrEmpty(result)) |
|
3018 | throw new Exception("Error communicating with Corrade"); |
2801 | throw new Exception("Error communicating with Corrade"); |
|
3019 | |
2802 | |
|
Line 3020... | Line 2803... | |||
3020 | bool success; |
2803 | bool success; |
|
3021 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
2804 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
Line 3022... | Line 2805... | |||
3022 | throw new Exception("No success status could be retrieved"); |
2805 | throw new Exception("No success status could be retrieved"); |
|
3023 | |
2806 | |
|
3024 | if (!success) |
2807 | if (!success) |
|
3025 | throw new Exception("Unable to add resident"); |
2808 | throw new Exception("Unable to add resident"); |
|
3026 | |
2809 | |
|
3027 | // Retrieve the estate list for updates. |
2810 | // Retrieve the estate list for updates. |
|
3028 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
2811 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
3029 | wasKeyValueEscape(new Dictionary<string, string> |
2812 | KeyValue.Escape(new Dictionary<string, string> |
|
3030 | { |
2813 | { |
|
Line 3031... | Line 2814... | |||
3031 | {"command", "getestatelist"}, |
2814 | {"command", "getestatelist"}, |
|
3032 | {"group", vassalConfiguration.Group}, |
2815 | {"group", vassalConfiguration.Group}, |
|
Line 3033... | Line 2816... | |||
3033 | {"password", vassalConfiguration.Password}, |
2816 | {"password", vassalConfiguration.Password}, |
|
3034 | {"type", selectedEstateListType} |
2817 | {"type", selectedEstateListType} |
|
Line 3035... | Line 2818... | |||
3035 | }), vassalConfiguration.DataTimeout); |
2818 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
3036 | |
2819 | |
|
Line 3037... | Line 2820... | |||
3037 | if (string.IsNullOrEmpty(result)) |
2820 | if (string.IsNullOrEmpty(result)) |
|
3038 | throw new Exception("Error communicating with Corrade."); |
2821 | throw new Exception("Error communicating with Corrade."); |
|
3039 | |
2822 | |
|
3040 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
2823 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
3041 | throw new Exception("No success status could be retrieved."); |
2824 | throw new Exception("No success status could be retrieved."); |
|
3042 | |
2825 | |
|
3043 | if (!success) |
2826 | if (!success) |
|
Line 3127... | Line 2910... | |||
3127 | { |
2910 | { |
|
3128 | Monitor.Enter(ClientInstanceTeleportLock); |
2911 | Monitor.Enter(ClientInstanceTeleportLock); |
|
Line 3129... | Line 2912... | |||
3129 | |
2912 | |
|
3130 | // Add the group to the list. |
2913 | // Add the group to the list. |
|
3131 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
2914 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
3132 | wasKeyValueEscape(new Dictionary<string, string> |
2915 | KeyValue.Escape(new Dictionary<string, string> |
|
3133 | { |
2916 | { |
|
3134 | {"command", "setestatelist"}, |
2917 | {"command", "setestatelist"}, |
|
3135 | {"group", vassalConfiguration.Group}, |
2918 | {"group", vassalConfiguration.Group}, |
|
3136 | {"password", vassalConfiguration.Password}, |
2919 | {"password", vassalConfiguration.Password}, |
|
3137 | {"type", selectedEstateListType}, |
2920 | {"type", selectedEstateListType}, |
|
3138 | {"action", "add"}, |
2921 | {"action", "add"}, |
|
3139 | {"target", target} |
2922 | {"target", target} |
|
Line 3140... | Line 2923... | |||
3140 | }), vassalConfiguration.DataTimeout); |
2923 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
3141 | |
2924 | |
|
Line 3142... | Line 2925... | |||
3142 | if (string.IsNullOrEmpty(result)) |
2925 | if (string.IsNullOrEmpty(result)) |
|
3143 | throw new Exception("Error communicating with Corrade"); |
2926 | throw new Exception("Error communicating with Corrade"); |
|
3144 | |
2927 | |
|
Line 3145... | Line 2928... | |||
3145 | bool success; |
2928 | bool success; |
|
3146 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
2929 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
Line 3147... | Line 2930... | |||
3147 | throw new Exception("No success status could be retrieved"); |
2930 | throw new Exception("No success status could be retrieved"); |
|
3148 | |
2931 | |
|
3149 | if (!success) |
2932 | if (!success) |
|
3150 | throw new Exception("Unable to add group"); |
2933 | throw new Exception("Unable to add group"); |
|
3151 | |
2934 | |
|
3152 | // Retrieve the estate list for updates. |
2935 | // Retrieve the estate list for updates. |
|
3153 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
2936 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
3154 | wasKeyValueEscape(new Dictionary<string, string> |
2937 | KeyValue.Escape(new Dictionary<string, string> |
|
3155 | { |
2938 | { |
|
Line 3156... | Line 2939... | |||
3156 | {"command", "getestatelist"}, |
2939 | {"command", "getestatelist"}, |
|
3157 | {"group", vassalConfiguration.Group}, |
2940 | {"group", vassalConfiguration.Group}, |
|
Line 3158... | Line 2941... | |||
3158 | {"password", vassalConfiguration.Password}, |
2941 | {"password", vassalConfiguration.Password}, |
|
3159 | {"type", selectedEstateListType} |
2942 | {"type", selectedEstateListType} |
|
Line 3160... | Line 2943... | |||
3160 | }), vassalConfiguration.DataTimeout); |
2943 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
3161 | |
2944 | |
|
Line 3162... | Line 2945... | |||
3162 | if (string.IsNullOrEmpty(result)) |
2945 | if (string.IsNullOrEmpty(result)) |
|
3163 | throw new Exception("Error communicating with Corrade."); |
2946 | throw new Exception("Error communicating with Corrade."); |
|
3164 | |
2947 | |
|
3165 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
2948 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
3166 | throw new Exception("No success status could be retrieved."); |
2949 | throw new Exception("No success status could be retrieved."); |
|
3167 | |
2950 | |
|
3168 | if (!success) |
2951 | if (!success) |
|
Line 3222... | Line 3005... | |||
3222 | physics = RegionDebugPhysicsBox.Checked; |
3005 | physics = RegionDebugPhysicsBox.Checked; |
|
3223 | })); |
3006 | })); |
|
Line 3224... | Line 3007... | |||
3224 | |
3007 | |
|
3225 | // Set the debug settings. |
3008 | // Set the debug settings. |
|
3226 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
3009 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
3227 | wasKeyValueEscape(new Dictionary<string, string> |
3010 | KeyValue.Escape(new Dictionary<string, string> |
|
3228 | { |
3011 | { |
|
3229 | {"command", "setregiondebug"}, |
3012 | {"command", "setregiondebug"}, |
|
3230 | {"group", vassalConfiguration.Group}, |
3013 | {"group", vassalConfiguration.Group}, |
|
3231 | {"password", vassalConfiguration.Password}, |
3014 | {"password", vassalConfiguration.Password}, |
|
3232 | {"scripts", scripts.ToString()}, |
3015 | {"scripts", scripts.ToString()}, |
|
3233 | {"collisions", collisons.ToString()}, |
3016 | {"collisions", collisons.ToString()}, |
|
3234 | {"physics", physics.ToString()} |
3017 | {"physics", physics.ToString()} |
|
Line 3235... | Line 3018... | |||
3235 | }), vassalConfiguration.DataTimeout); |
3018 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
3236 | |
3019 | |
|
Line 3237... | Line 3020... | |||
3237 | if (string.IsNullOrEmpty(result)) |
3020 | if (string.IsNullOrEmpty(result)) |
|
3238 | throw new Exception("Error communicating with Corrade"); |
3021 | throw new Exception("Error communicating with Corrade"); |
|
3239 | |
3022 | |
|
Line 3240... | Line 3023... | |||
3240 | bool success; |
3023 | bool success; |
|
3241 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
3024 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
3242 | throw new Exception("No success status could be retrieved"); |
3025 | throw new Exception("No success status could be retrieved"); |
|
Line 3324... | Line 3107... | |||
3324 | |
3107 | |
|
Line 3325... | Line 3108... | |||
3325 | if (!run) return; |
3108 | if (!run) return; |
|
3326 | |
3109 | |
|
3327 | // Set the debug settings. |
3110 | // Set the debug settings. |
|
3328 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
3111 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
3329 | wasKeyValueEscape(new Dictionary<string, string> |
3112 | KeyValue.Escape(new Dictionary<string, string> |
|
3330 | { |
3113 | { |
|
3331 | {"command", "setregioninfo"}, |
3114 | {"command", "setregioninfo"}, |
|
3332 | {"group", vassalConfiguration.Group}, |
3115 | {"group", vassalConfiguration.Group}, |
|
Line 3338... | Line 3121... | |||
3338 | {"push", push.ToString()}, |
3121 | {"push", push.ToString()}, |
|
3339 | {"parcel", parcel.ToString()}, |
3122 | {"parcel", parcel.ToString()}, |
|
3340 | {"mature", mature.ToString()}, |
3123 | {"mature", mature.ToString()}, |
|
3341 | {"limit", agentLimit.ToString(Utils.EnUsCulture)}, |
3124 | {"limit", agentLimit.ToString(Utils.EnUsCulture)}, |
|
3342 | {"bonus", objectBonus.ToString(Utils.EnUsCulture)} |
3125 | {"bonus", objectBonus.ToString(Utils.EnUsCulture)} |
|
3343 | }), vassalConfiguration.DataTimeout); |
3126 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
Line 3344... | Line 3127... | |||
3344 | |
3127 | |
|
3345 | if (string.IsNullOrEmpty(result)) |
3128 | if (string.IsNullOrEmpty(result)) |
|
Line 3346... | Line 3129... | |||
3346 | throw new Exception("Error communicating with Corrade"); |
3129 | throw new Exception("Error communicating with Corrade"); |
|
3347 | |
3130 | |
|
3348 | bool success; |
3131 | bool success; |
|
Line 3349... | Line 3132... | |||
3349 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
3132 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
3350 | throw new Exception("No success status could be retrieved"); |
3133 | throw new Exception("No success status could be retrieved"); |
|
3351 | |
3134 | |
|
Line 3437... | Line 3220... | |||
3437 | { |
3220 | { |
|
3438 | Monitor.Enter(ClientInstanceTeleportLock); |
3221 | Monitor.Enter(ClientInstanceTeleportLock); |
|
Line 3439... | Line 3222... | |||
3439 | |
3222 | |
|
3440 | // Set the debug settings. |
3223 | // Set the debug settings. |
|
3441 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
3224 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
3442 | wasKeyValueEscape(new Dictionary<string, string> |
3225 | KeyValue.Escape(new Dictionary<string, string> |
|
3443 | { |
3226 | { |
|
3444 | {"command", "setregionterraintextures"}, |
3227 | {"command", "setregionterraintextures"}, |
|
3445 | {"group", vassalConfiguration.Group}, |
3228 | {"group", vassalConfiguration.Group}, |
|
3446 | {"password", vassalConfiguration.Password}, |
3229 | {"password", vassalConfiguration.Password}, |
|
3447 | {"data", wasEnumerableToCSV(groundTextureUUIDs.Select(o => o.ToString()))} |
3230 | {"data", CSV.FromEnumerable(groundTextureUUIDs.Select(o => o.ToString()))} |
|
Line 3448... | Line 3231... | |||
3448 | }), vassalConfiguration.DataTimeout); |
3231 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
3449 | |
3232 | |
|
Line 3450... | Line 3233... | |||
3450 | if (string.IsNullOrEmpty(result)) |
3233 | if (string.IsNullOrEmpty(result)) |
|
3451 | throw new Exception("Error communicating with Corrade"); |
3234 | throw new Exception("Error communicating with Corrade"); |
|
3452 | |
3235 | |
|
Line 3453... | Line 3236... | |||
3453 | bool success; |
3236 | bool success; |
|
3454 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
3237 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
3455 | throw new Exception("No success status could be retrieved"); |
3238 | throw new Exception("No success status could be retrieved"); |
|
Line 3538... | Line 3321... | |||
3538 | try |
3321 | try |
|
3539 | { |
3322 | { |
|
3540 | Monitor.Enter(ClientInstanceTeleportLock); |
3323 | Monitor.Enter(ClientInstanceTeleportLock); |
|
Line 3541... | Line 3324... | |||
3541 | |
3324 | |
|
3542 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
3325 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
3543 | wasKeyValueEscape(new Dictionary<string, string> |
3326 | KeyValue.Escape(new Dictionary<string, string> |
|
3544 | { |
3327 | { |
|
3545 | {"command", "download"}, |
3328 | {"command", "download"}, |
|
3546 | {"group", vassalConfiguration.Group}, |
3329 | {"group", vassalConfiguration.Group}, |
|
3547 | {"password", vassalConfiguration.Password}, |
3330 | {"password", vassalConfiguration.Password}, |
|
3548 | {"item", textureUUID.ToString()}, |
3331 | {"item", textureUUID.ToString()}, |
|
3549 | {"type", "Texture"}, |
3332 | {"type", "Texture"}, |
|
3550 | {"format", "Png"} |
3333 | {"format", "Png"} |
|
Line 3551... | Line 3334... | |||
3551 | }), vassalConfiguration.DataTimeout); |
3334 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
3552 | |
3335 | |
|
Line 3553... | Line 3336... | |||
3553 | if (string.IsNullOrEmpty(result)) |
3336 | if (string.IsNullOrEmpty(result)) |
|
3554 | throw new Exception("Error communicating with Corrade"); |
3337 | throw new Exception("Error communicating with Corrade"); |
|
3555 | |
3338 | |
|
Line 3556... | Line 3339... | |||
3556 | bool success; |
3339 | bool success; |
|
3557 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
3340 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
3558 | throw new Exception("No success status could be retrieved"); |
3341 | throw new Exception("No success status could be retrieved"); |
|
3559 | |
3342 | |
|
3560 | byte[] mapImageBytes = Convert.FromBase64String(wasInput(wasKeyValueGet("data", result))); |
3343 | byte[] mapImageBytes = Convert.FromBase64String(wasInput(KeyValue.Get("data", result))); |
|
3561 | Image mapImage; |
3344 | Image mapImage; |
|
Line 3658... | Line 3441... | |||
3658 | // import groups |
3441 | // import groups |
|
3659 | UUID targetUUID; |
3442 | UUID targetUUID; |
|
3660 | foreach (KeyValuePair<string, UUID> target in |
3443 | foreach (KeyValuePair<string, UUID> target in |
|
3661 | File.ReadAllLines(file) |
3444 | File.ReadAllLines(file) |
|
3662 | .AsParallel() |
3445 | .AsParallel() |
|
3663 | .Select(o => new List<string>(wasCSVToEnumerable(o))) |
3446 | .Select(o => new List<string>(CSV.ToEnumerable(o))) |
|
3664 | .Where(o => o.Count == 2) |
3447 | .Where(o => o.Count == 2) |
|
3665 | .ToDictionary(o => o.First(), |
3448 | .ToDictionary(o => o.First(), |
|
3666 | p => |
3449 | p => |
|
3667 | UUID.TryParse(p.Last(), out targetUUID) |
3450 | UUID.TryParse(p.Last(), out targetUUID) |
|
3668 | ? targetUUID |
3451 | ? targetUUID |
|
Line 3725... | Line 3508... | |||
3725 | |
3508 | |
|
3726 | try |
3509 | try |
|
3727 | { |
3510 | { |
|
3728 | // Add the group to the list. |
3511 | // Add the group to the list. |
|
3729 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
3512 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
3730 | wasKeyValueEscape(new Dictionary<string, string> |
3513 | KeyValue.Escape(new Dictionary<string, string> |
|
3731 | { |
3514 | { |
|
3732 | {"command", "setestatelist"}, |
3515 | {"command", "setestatelist"}, |
|
3733 | {"group", vassalConfiguration.Group}, |
3516 | {"group", vassalConfiguration.Group}, |
|
3734 | {"password", vassalConfiguration.Password}, |
3517 | {"password", vassalConfiguration.Password}, |
|
3735 | {"type", selectedEstateListType}, |
3518 | {"type", selectedEstateListType}, |
|
3736 | {"action", "add"}, |
3519 | {"action", "add"}, |
|
3737 | {"target", target.Value.ToString()} |
3520 | {"target", target.Value.ToString()} |
|
Line 3738... | Line 3521... | |||
3738 | }), vassalConfiguration.DataTimeout); |
3521 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
3739 | |
3522 | |
|
Line 3740... | Line 3523... | |||
3740 | if (string.IsNullOrEmpty(result)) |
3523 | if (string.IsNullOrEmpty(result)) |
|
3741 | throw new Exception("Error communicating with Corrade"); |
3524 | throw new Exception("Error communicating with Corrade"); |
|
3742 | |
3525 | |
|
Line 3743... | Line 3526... | |||
3743 | bool success; |
3526 | bool success; |
|
3744 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
3527 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
3745 | throw new Exception("No success status could be retrieved"); |
3528 | throw new Exception("No success status could be retrieved"); |
|
Line 3757... | Line 3540... | |||
3757 | // Retrieve the estate list. |
3540 | // Retrieve the estate list. |
|
3758 | try |
3541 | try |
|
3759 | { |
3542 | { |
|
3760 | // Retrieve the estate list for updates. |
3543 | // Retrieve the estate list for updates. |
|
3761 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
3544 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
3762 | wasKeyValueEscape(new Dictionary<string, string> |
3545 | KeyValue.Escape(new Dictionary<string, string> |
|
3763 | { |
3546 | { |
|
3764 | {"command", "getestatelist"}, |
3547 | {"command", "getestatelist"}, |
|
3765 | {"group", vassalConfiguration.Group}, |
3548 | {"group", vassalConfiguration.Group}, |
|
3766 | {"password", vassalConfiguration.Password}, |
3549 | {"password", vassalConfiguration.Password}, |
|
3767 | {"type", selectedEstateListType} |
3550 | {"type", selectedEstateListType} |
|
3768 | }), vassalConfiguration.DataTimeout); |
3551 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
Line 3769... | Line 3552... | |||
3769 | |
3552 | |
|
3770 | if (string.IsNullOrEmpty(result)) |
3553 | if (string.IsNullOrEmpty(result)) |
|
Line 3771... | Line 3554... | |||
3771 | throw new Exception("Error communicating with Corrade."); |
3554 | throw new Exception("Error communicating with Corrade."); |
|
3772 | |
3555 | |
|
3773 | bool success; |
3556 | bool success; |
|
Line 3774... | Line 3557... | |||
3774 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
3557 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
3775 | throw new Exception("No success status could be retrieved."); |
3558 | throw new Exception("No success status could be retrieved."); |
|
Line 3776... | Line 3559... | |||
3776 | |
3559 | |
|
3777 | if (!success) |
3560 | if (!success) |
|
3778 | throw new Exception("Could not retrieve estate list."); |
3561 | throw new Exception("Could not retrieve estate list."); |
|
3779 | |
3562 | |
|
3780 | vassalForm.Invoke((MethodInvoker) (() => { EstateListGridView.Rows.Clear(); })); |
3563 | vassalForm.Invoke((MethodInvoker) (() => { EstateListGridView.Rows.Clear(); })); |
|
3781 | foreach (List<string> data in wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))) |
3564 | foreach (List<string> data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
|
3782 | .Where(x => !string.IsNullOrEmpty(x)) |
3565 | .Where(x => !string.IsNullOrEmpty(x)) |
|
Line 3851... | Line 3634... | |||
3851 | // import groups |
3634 | // import groups |
|
3852 | UUID targetUUID; |
3635 | UUID targetUUID; |
|
3853 | foreach (KeyValuePair<string, UUID> target in |
3636 | foreach (KeyValuePair<string, UUID> target in |
|
3854 | File.ReadAllLines(file) |
3637 | File.ReadAllLines(file) |
|
3855 | .AsParallel() |
3638 | .AsParallel() |
|
3856 | .Select(o => new List<string>(wasCSVToEnumerable(o))) |
3639 | .Select(o => new List<string>(CSV.ToEnumerable(o))) |
|
3857 | .Where(o => o.Count == 2) |
3640 | .Where(o => o.Count == 2) |
|
3858 | .ToDictionary(o => o.First(), |
3641 | .ToDictionary(o => o.First(), |
|
3859 | p => |
3642 | p => |
|
3860 | UUID.TryParse(p.Last(), out targetUUID) |
3643 | UUID.TryParse(p.Last(), out targetUUID) |
|
3861 | ? targetUUID |
3644 | ? targetUUID |
|
Line 3918... | Line 3701... | |||
3918 | |
3701 | |
|
3919 | try |
3702 | try |
|
3920 | { |
3703 | { |
|
3921 | // Add the group to the list. |
3704 | // Add the group to the list. |
|
3922 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
3705 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
3923 | wasKeyValueEscape(new Dictionary<string, string> |
3706 | KeyValue.Escape(new Dictionary<string, string> |
|
3924 | { |
3707 | { |
|
3925 | {"command", "setestatelist"}, |
3708 | {"command", "setestatelist"}, |
|
3926 | {"group", vassalConfiguration.Group}, |
3709 | {"group", vassalConfiguration.Group}, |
|
3927 | {"password", vassalConfiguration.Password}, |
3710 | {"password", vassalConfiguration.Password}, |
|
3928 | {"type", selectedEstateListType}, |
3711 | {"type", selectedEstateListType}, |
|
3929 | {"action", "add"}, |
3712 | {"action", "add"}, |
|
3930 | {"agent", target.Value.ToString()} |
3713 | {"agent", target.Value.ToString()} |
|
Line 3931... | Line 3714... | |||
3931 | }), vassalConfiguration.DataTimeout); |
3714 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
3932 | |
3715 | |
|
Line 3933... | Line 3716... | |||
3933 | if (string.IsNullOrEmpty(result)) |
3716 | if (string.IsNullOrEmpty(result)) |
|
3934 | throw new Exception("Error communicating with Corrade"); |
3717 | throw new Exception("Error communicating with Corrade"); |
|
3935 | |
3718 | |
|
Line 3936... | Line 3719... | |||
3936 | bool success; |
3719 | bool success; |
|
3937 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
3720 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
3938 | throw new Exception("No success status could be retrieved"); |
3721 | throw new Exception("No success status could be retrieved"); |
|
Line 3950... | Line 3733... | |||
3950 | // Retrieve the estate list. |
3733 | // Retrieve the estate list. |
|
3951 | try |
3734 | try |
|
3952 | { |
3735 | { |
|
3953 | // Retrieve the estate list for updates. |
3736 | // Retrieve the estate list for updates. |
|
3954 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
3737 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
3955 | wasKeyValueEscape(new Dictionary<string, string> |
3738 | KeyValue.Escape(new Dictionary<string, string> |
|
3956 | { |
3739 | { |
|
3957 | {"command", "getestatelist"}, |
3740 | {"command", "getestatelist"}, |
|
3958 | {"group", vassalConfiguration.Group}, |
3741 | {"group", vassalConfiguration.Group}, |
|
3959 | {"password", vassalConfiguration.Password}, |
3742 | {"password", vassalConfiguration.Password}, |
|
3960 | {"type", selectedEstateListType} |
3743 | {"type", selectedEstateListType} |
|
3961 | }), vassalConfiguration.DataTimeout); |
3744 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
Line 3962... | Line 3745... | |||
3962 | |
3745 | |
|
3963 | if (string.IsNullOrEmpty(result)) |
3746 | if (string.IsNullOrEmpty(result)) |
|
Line 3964... | Line 3747... | |||
3964 | throw new Exception("Error communicating with Corrade."); |
3747 | throw new Exception("Error communicating with Corrade."); |
|
3965 | |
3748 | |
|
3966 | bool success; |
3749 | bool success; |
|
Line 3967... | Line 3750... | |||
3967 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
3750 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
3968 | throw new Exception("No success status could be retrieved."); |
3751 | throw new Exception("No success status could be retrieved."); |
|
Line 3969... | Line 3752... | |||
3969 | |
3752 | |
|
3970 | if (!success) |
3753 | if (!success) |
|
3971 | throw new Exception("Could not retrieve estate list."); |
3754 | throw new Exception("Could not retrieve estate list."); |
|
3972 | |
3755 | |
|
3973 | vassalForm.Invoke((MethodInvoker) (() => { EstateListGridView.Rows.Clear(); })); |
3756 | vassalForm.Invoke((MethodInvoker) (() => { EstateListGridView.Rows.Clear(); })); |
|
3974 | foreach (List<string> data in wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))) |
3757 | foreach (List<string> data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
|
3975 | .Where(x => !string.IsNullOrEmpty(x)) |
3758 | .Where(x => !string.IsNullOrEmpty(x)) |
|
Line 4023... | Line 3806... | |||
4023 | |
3806 | |
|
4024 | using (StreamWriter streamWriter = new StreamWriter(file, false, Encoding.UTF8)) |
3807 | using (StreamWriter streamWriter = new StreamWriter(file, false, Encoding.UTF8)) |
|
4025 | { |
3808 | { |
|
4026 | foreach (DataGridViewRow estateListRow in EstateListGridView.Rows) |
3809 | foreach (DataGridViewRow estateListRow in EstateListGridView.Rows) |
|
4027 | { |
3810 | { |
|
4028 | streamWriter.WriteLine(wasEnumerableToCSV(new[] |
3811 | streamWriter.WriteLine(CSV.FromEnumerable(new[] |
|
4029 | { |
3812 | { |
|
4030 | estateListRow.Cells["EstateListName"].Value.ToString(), |
3813 | estateListRow.Cells["EstateListName"].Value.ToString(), |
|
4031 | estateListRow.Cells["EstateListUUID"].Value.ToString() |
3814 | estateListRow.Cells["EstateListUUID"].Value.ToString() |
|
4032 | })); |
3815 | })); |
|
Line 4110... | Line 3893... | |||
4110 | |
3893 | |
|
4111 | try |
3894 | try |
|
4112 | { |
3895 | { |
|
4113 | // Teleport the user home. |
3896 | // Teleport the user home. |
|
4114 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
3897 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
4115 | wasKeyValueEscape(new Dictionary<string, string> |
3898 | KeyValue.Escape(new Dictionary<string, string> |
|
4116 | { |
3899 | { |
|
4117 | {"command", "estateteleportusershome"}, |
3900 | {"command", "estateteleportusershome"}, |
|
4118 | {"group", vassalConfiguration.Group}, |
3901 | {"group", vassalConfiguration.Group}, |
|
4119 | {"password", vassalConfiguration.Password}, |
3902 | {"password", vassalConfiguration.Password}, |
|
4120 | {"avatars", agentUUID.ToString()} |
3903 | {"avatars", agentUUID.ToString()} |
|
Line 4121... | Line 3904... | |||
4121 | }), vassalConfiguration.DataTimeout); |
3904 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
4122 | |
3905 | |
|
Line 4123... | Line 3906... | |||
4123 | if (string.IsNullOrEmpty(result)) |
3906 | if (string.IsNullOrEmpty(result)) |
|
4124 | throw new Exception("Error communicating with Corrade."); |
3907 | throw new Exception("Error communicating with Corrade."); |
|
4125 | |
3908 | |
|
Line 4126... | Line 3909... | |||
4126 | bool success; |
3909 | bool success; |
|
4127 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
3910 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
4128 | throw new Exception("No success status could be retrieved."); |
3911 | throw new Exception("No success status could be retrieved."); |
|
Line 4252... | Line 4035... | |||
4252 | |
4035 | |
|
Line 4253... | Line 4036... | |||
4253 | if (!run) return; |
4036 | if (!run) return; |
|
4254 | |
4037 | |
|
4255 | // Set the terrain variables. |
4038 | // Set the terrain variables. |
|
4256 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
4039 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
4257 | wasKeyValueEscape(new Dictionary<string, string> |
4040 | KeyValue.Escape(new Dictionary<string, string> |
|
4258 | { |
4041 | { |
|
4259 | {"command", "setregionterrainvariables"}, |
4042 | {"command", "setregionterrainvariables"}, |
|
4260 | {"group", vassalConfiguration.Group}, |
4043 | {"group", vassalConfiguration.Group}, |
|
4261 | {"password", vassalConfiguration.Password}, |
4044 | {"password", vassalConfiguration.Password}, |
|
4262 | {"waterheight", waterHeight.ToString()}, |
4045 | {"waterheight", waterHeight.ToString()}, |
|
4263 | {"terrainraiselimit", terrainRaiseLimit.ToString()}, |
4046 | {"terrainraiselimit", terrainRaiseLimit.ToString()}, |
|
4264 | {"terrainlowerlimit", terrainLowerLimit.ToString()}, |
4047 | {"terrainlowerlimit", terrainLowerLimit.ToString()}, |
|
4265 | {"useestatesun", useEstateSun.ToString()}, |
4048 | {"useestatesun", useEstateSun.ToString()}, |
|
4266 | {"fixedsun", fixedSun.ToString()}, |
4049 | {"fixedsun", fixedSun.ToString()}, |
|
Line 4267... | Line 4050... | |||
4267 | {"sunposition", sunPosition.ToString()} |
4050 | {"sunposition", sunPosition.ToString()} |
|
4268 | }), vassalConfiguration.DataTimeout); |
4051 | }, wasOutput), vassalConfiguration.DataTimeout); |
|
Line 4269... | Line 4052... | |||
4269 | |
4052 | |
|
4270 | if (string.IsNullOrEmpty(result)) |
4053 | if (string.IsNullOrEmpty(result)) |
|
4271 | throw new Exception("Error communicating with Corrade"); |
4054 | throw new Exception("Error communicating with Corrade"); |
|
Line 4272... | Line 4055... | |||
4272 | |
4055 | |
|
4273 | bool success; |
4056 | bool success; |
|
4274 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
4057 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
Line 4560... | Line 4343... | |||
4560 | } |
4343 | } |
|
4561 | } |
4344 | } |
|
Line 4562... | Line 4345... | |||
4562 | |
4345 | |
|
Line 4563... | Line -... | |||
4563 | #region CRYPTOGRAPHY |
- | ||
4564 | |
- | ||
4565 | /////////////////////////////////////////////////////////////////////////// |
- | ||
4566 | // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // |
- | ||
4567 | /////////////////////////////////////////////////////////////////////////// |
- | ||
4568 | /// <summary> |
- | ||
4569 | /// Gets a sub-array from an array. |
- | ||
4570 | /// </summary> |
- | ||
4571 | /// <typeparam name="T">the array type</typeparam> |
- | ||
4572 | /// <param name="data">the array</param> |
- | ||
4573 | /// <param name="start">the start index</param> |
- | ||
4574 | /// <param name="stop">the stop index (-1 denotes the end)</param> |
- | ||
4575 | /// <returns>the array slice between start and stop</returns> |
- | ||
4576 | public static T[] wasGetSubArray<T>(T[] data, int start, int stop) |
- | ||
4577 | { |
- | ||
4578 | if (stop.Equals(-1)) |
- | ||
4579 | stop = data.Length - 1; |
- | ||
4580 | T[] result = new T[stop - start + 1]; |
- | ||
4581 | Array.Copy(data, start, result, 0, stop - start + 1); |
- | ||
4582 | return result; |
- | ||
4583 | } |
- | ||
4584 | |
- | ||
4585 | /////////////////////////////////////////////////////////////////////////// |
- | ||
4586 | // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // |
- | ||
4587 | /////////////////////////////////////////////////////////////////////////// |
- | ||
4588 | /// <summary> |
- | ||
4589 | /// Delete a sub-array and return the result. |
- | ||
4590 | /// </summary> |
- | ||
4591 | /// <typeparam name="T">the array type</typeparam> |
- | ||
4592 | /// <param name="data">the array</param> |
- | ||
4593 | /// <param name="start">the start index</param> |
- | ||
4594 | /// <param name="stop">the stop index (-1 denotes the end)</param> |
- | ||
4595 | /// <returns>the array without elements between start and stop</returns> |
- | ||
4596 | public static T[] wasDeleteSubArray<T>(T[] data, int start, int stop) |
- | ||
4597 | { |
- | ||
4598 | if (stop.Equals(-1)) |
- | ||
4599 | stop = data.Length - 1; |
- | ||
4600 | T[] result = new T[data.Length - (stop - start) - 1]; |
- | ||
4601 | Array.Copy(data, 0, result, 0, start); |
- | ||
4602 | Array.Copy(data, stop + 1, result, start, data.Length - stop - 1); |
- | ||
4603 | return result; |
- | ||
4604 | } |
- | ||
4605 | |
- | ||
4606 | /////////////////////////////////////////////////////////////////////////// |
- | ||
4607 | // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // |
- | ||
4608 | /////////////////////////////////////////////////////////////////////////// |
- | ||
4609 | /// <summary> |
- | ||
4610 | /// Concatenate multiple arrays. |
- | ||
4611 | /// </summary> |
- | ||
4612 | /// <typeparam name="T">the array type</typeparam> |
- | ||
4613 | /// <param name="arrays">multiple arrays</param> |
- | ||
4614 | /// <returns>a flat array with all arrays concatenated</returns> |
- | ||
4615 | public static T[] wasConcatenateArrays<T>(params T[][] arrays) |
- | ||
4616 | { |
- | ||
4617 | int resultLength = 0; |
- | ||
4618 | foreach (T[] o in arrays) |
- | ||
4619 | { |
- | ||
4620 | resultLength += o.Length; |
- | ||
4621 | } |
- | ||
4622 | T[] result = new T[resultLength]; |
- | ||
4623 | int offset = 0; |
- | ||
4624 | for (int x = 0; x < arrays.Length; x++) |
- | ||
4625 | { |
- | ||
4626 | arrays[x].CopyTo(result, offset); |
- | ||
4627 | offset += arrays[x].Length; |
- | ||
4628 | } |
- | ||
4629 | return result; |
- | ||
4630 | } |
- | ||
4631 | |
- | ||
4632 | /////////////////////////////////////////////////////////////////////////// |
- | ||
4633 | // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // |
- | ||
4634 | /////////////////////////////////////////////////////////////////////////// |
- | ||
4635 | /// <summary> |
- | ||
4636 | /// Permutes an array in reverse a given number of times. |
- | ||
4637 | /// </summary> |
- | ||
4638 | /// <typeparam name="T">the array type</typeparam> |
- | ||
4639 | /// <param name="input">the array</param> |
- | ||
4640 | /// <param name="times">the number of times to permute</param> |
- | ||
4641 | /// <returns>the array with the elements permuted</returns> |
- | ||
4642 | private static T[] wasReversePermuteArrayElements<T>(T[] input, int times) |
- | ||
4643 | { |
- | ||
4644 | if (times.Equals(0)) return input; |
- | ||
4645 | T[] slice = new T[input.Length]; |
- | ||
4646 | Array.Copy(input, 1, slice, 0, input.Length - 1); |
- | ||
4647 | Array.Copy(input, 0, slice, input.Length - 1, 1); |
- | ||
4648 | return wasReversePermuteArrayElements(slice, --times); |
- | ||
4649 | } |
- | ||
4650 | |
- | ||
4651 | /////////////////////////////////////////////////////////////////////////// |
- | ||
4652 | // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // |
- | ||
4653 | /////////////////////////////////////////////////////////////////////////// |
- | ||
4654 | /// <summary> |
- | ||
4655 | /// Permutes an array forward a given number of times. |
- | ||
4656 | /// </summary> |
- | ||
4657 | /// <typeparam name="T">the array type</typeparam> |
- | ||
4658 | /// <param name="input">the array</param> |
- | ||
4659 | /// <param name="times">the number of times to permute</param> |
- | ||
4660 | /// <returns>the array with the elements permuted</returns> |
- | ||
4661 | private static T[] wasForwardPermuteArrayElements<T>(T[] input, int times) |
- | ||
4662 | { |
- | ||
4663 | if (times.Equals(0)) return input; |
- | ||
4664 | T[] slice = new T[input.Length]; |
- | ||
4665 | Array.Copy(input, input.Length - 1, slice, 0, 1); |
- | ||
4666 | Array.Copy(input, 0, slice, 1, input.Length - 1); |
- | ||
4667 | return wasForwardPermuteArrayElements(slice, --times); |
- | ||
4668 | } |
- | ||
4669 | |
- | ||
4670 | /////////////////////////////////////////////////////////////////////////// |
- | ||
4671 | // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // |
- | ||
4672 | /////////////////////////////////////////////////////////////////////////// |
- | ||
4673 | /// <summary> |
- | ||
4674 | /// Encrypt or decrypt a message given a set of rotors, plugs and a reflector. |
- | ||
4675 | /// </summary> |
- | ||
4676 | /// <param name="message">the message to encyrpt or decrypt</param> |
- | ||
4677 | /// <param name="rotors">any combination of: 1, 2, 3, 4, 5, 6, 7, 8, b, g</param> |
- | ||
4678 | /// <param name="plugs">the letter representing the start character for the rotor</param> |
- | ||
4679 | /// <param name="reflector">any one of: B, b, C, c</param> |
- | ||
4680 | /// <returns>either a decrypted or encrypted string</returns> |
- | ||
4681 | private static string wasEnigma(string message, char[] rotors, char[] plugs, char reflector) |
- | ||
4682 | { |
- | ||
4683 | Dictionary<char, char[]> def_rotors = new Dictionary<char, char[]> |
- | ||
4684 | { |
- | ||
4685 | { |
- | ||
4686 | '1', new[] |
- | ||
4687 | { |
- | ||
4688 | 'e', 'k', 'm', 'f', 'l', |
- | ||
4689 | 'g', 'd', 'q', 'v', 'z', |
- | ||
4690 | 'n', 't', 'o', 'w', 'y', |
- | ||
4691 | 'h', 'x', 'u', 's', 'p', |
- | ||
4692 | 'a', 'i', 'b', 'r', 'c', |
- | ||
4693 | 'j' |
- | ||
4694 | } |
- | ||
4695 | }, |
- | ||
4696 | { |
- | ||
4697 | '2', new[] |
- | ||
4698 | { |
- | ||
4699 | 'a', 'j', 'd', 'k', 's', |
- | ||
4700 | 'i', 'r', 'u', 'x', 'b', |
- | ||
4701 | 'l', 'h', 'w', 't', 'm', |
- | ||
4702 | 'c', 'q', 'g', 'z', 'n', |
- | ||
4703 | 'p', 'y', 'f', 'v', 'o', |
- | ||
4704 | 'e' |
- | ||
4705 | } |
- | ||
4706 | }, |
- | ||
4707 | { |
- | ||
4708 | '3', new[] |
- | ||
4709 | { |
- | ||
4710 | 'b', 'd', 'f', 'h', 'j', |
- | ||
4711 | 'l', 'c', 'p', 'r', 't', |
- | ||
4712 | 'x', 'v', 'z', 'n', 'y', |
- | ||
4713 | 'e', 'i', 'w', 'g', 'a', |
- | ||
4714 | 'k', 'm', 'u', 's', 'q', |
- | ||
4715 | 'o' |
- | ||
4716 | } |
- | ||
4717 | }, |
- | ||
4718 | { |
- | ||
4719 | '4', new[] |
- | ||
4720 | { |
- | ||
4721 | 'e', 's', 'o', 'v', 'p', |
- | ||
4722 | 'z', 'j', 'a', 'y', 'q', |
- | ||
4723 | 'u', 'i', 'r', 'h', 'x', |
- | ||
4724 | 'l', 'n', 'f', 't', 'g', |
- | ||
4725 | 'k', 'd', 'c', 'm', 'w', |
- | ||
4726 | 'b' |
- | ||
4727 | } |
- | ||
4728 | }, |
- | ||
4729 | { |
- | ||
4730 | '5', new[] |
- | ||
4731 | { |
- | ||
4732 | 'v', 'z', 'b', 'r', 'g', |
- | ||
4733 | 'i', 't', 'y', 'u', 'p', |
- | ||
4734 | 's', 'd', 'n', 'h', 'l', |
- | ||
4735 | 'x', 'a', 'w', 'm', 'j', |
- | ||
4736 | 'q', 'o', 'f', 'e', 'c', |
- | ||
4737 | 'k' |
- | ||
4738 | } |
- | ||
4739 | }, |
- | ||
4740 | { |
- | ||
4741 | '6', new[] |
- | ||
4742 | { |
- | ||
4743 | 'j', 'p', 'g', 'v', 'o', |
- | ||
4744 | 'u', 'm', 'f', 'y', 'q', |
- | ||
4745 | 'b', 'e', 'n', 'h', 'z', |
- | ||
4746 | 'r', 'd', 'k', 'a', 's', |
- | ||
4747 | 'x', 'l', 'i', 'c', 't', |
- | ||
4748 | 'w' |
- | ||
4749 | } |
- | ||
4750 | }, |
- | ||
4751 | { |
- | ||
4752 | '7', new[] |
- | ||
4753 | { |
- | ||
4754 | 'n', 'z', 'j', 'h', 'g', |
- | ||
4755 | 'r', 'c', 'x', 'm', 'y', |
- | ||
4756 | 's', 'w', 'b', 'o', 'u', |
- | ||
4757 | 'f', 'a', 'i', 'v', 'l', |
- | ||
4758 | 'p', 'e', 'k', 'q', 'd', |
- | ||
4759 | 't' |
- | ||
4760 | } |
- | ||
4761 | }, |
- | ||
4762 | { |
- | ||
4763 | '8', new[] |
- | ||
4764 | { |
- | ||
4765 | 'f', 'k', 'q', 'h', 't', |
- | ||
4766 | 'l', 'x', 'o', 'c', 'b', |
- | ||
4767 | 'j', 's', 'p', 'd', 'z', |
- | ||
4768 | 'r', 'a', 'm', 'e', 'w', |
- | ||
4769 | 'n', 'i', 'u', 'y', 'g', |
- | ||
4770 | 'v' |
- | ||
4771 | } |
- | ||
4772 | }, |
- | ||
4773 | { |
- | ||
4774 | 'b', new[] |
- | ||
4775 | { |
- | ||
4776 | 'l', 'e', 'y', 'j', 'v', |
- | ||
4777 | 'c', 'n', 'i', 'x', 'w', |
- | ||
4778 | 'p', 'b', 'q', 'm', 'd', |
- | ||
4779 | 'r', 't', 'a', 'k', 'z', |
- | ||
4780 | 'g', 'f', 'u', 'h', 'o', |
- | ||
4781 | 's' |
- | ||
4782 | } |
- | ||
4783 | }, |
- | ||
4784 | { |
- | ||
4785 | 'g', new[] |
- | ||
4786 | { |
- | ||
4787 | 'f', 's', 'o', 'k', 'a', |
- | ||
4788 | 'n', 'u', 'e', 'r', 'h', |
- | ||
4789 | 'm', 'b', 't', 'i', 'y', |
- | ||
4790 | 'c', 'w', 'l', 'q', 'p', |
- | ||
4791 | 'z', 'x', 'v', 'g', 'j', |
- | ||
4792 | 'd' |
- | ||
4793 | } |
- | ||
4794 | } |
- | ||
4795 | }; |
- | ||
4796 | |
- | ||
4797 | Dictionary<char, char[]> def_reflectors = new Dictionary<char, char[]> |
- | ||
4798 | { |
- | ||
4799 | { |
- | ||
4800 | 'B', new[] |
- | ||
4801 | { |
- | ||
4802 | 'a', 'y', 'b', 'r', 'c', 'u', 'd', 'h', |
- | ||
4803 | 'e', 'q', 'f', 's', 'g', 'l', 'i', 'p', |
- | ||
4804 | 'j', 'x', 'k', 'n', 'm', 'o', 't', 'z', |
- | ||
4805 | 'v', 'w' |
- | ||
4806 | } |
- | ||
4807 | }, |
- | ||
4808 | { |
- | ||
4809 | 'b', new[] |
- | ||
4810 | { |
- | ||
4811 | 'a', 'e', 'b', 'n', 'c', 'k', 'd', 'q', |
- | ||
4812 | 'f', 'u', 'g', 'y', 'h', 'w', 'i', 'j', |
- | ||
4813 | 'l', 'o', 'm', 'p', 'r', 'x', 's', 'z', |
- | ||
4814 | 't', 'v' |
- | ||
4815 | } |
- | ||
4816 | }, |
- | ||
4817 | { |
- | ||
4818 | 'C', new[] |
- | ||
4819 | { |
- | ||
4820 | 'a', 'f', 'b', 'v', 'c', 'p', 'd', 'j', |
- | ||
4821 | 'e', 'i', 'g', 'o', 'h', 'y', 'k', 'r', |
- | ||
4822 | 'l', 'z', 'm', 'x', 'n', 'w', 't', 'q', |
- | ||
4823 | 's', 'u' |
- | ||
4824 | } |
- | ||
4825 | }, |
- | ||
4826 | { |
- | ||
4827 | 'c', new[] |
- | ||
4828 | { |
- | ||
4829 | 'a', 'r', 'b', 'd', 'c', 'o', 'e', 'j', |
- | ||
4830 | 'f', 'n', 'g', 't', 'h', 'k', 'i', 'v', |
- | ||
4831 | 'l', 'm', 'p', 'w', 'q', 'z', 's', 'x', |
- | ||
4832 | 'u', 'y' |
- | ||
4833 | } |
- | ||
4834 | } |
- | ||
4835 | }; |
- | ||
4836 | |
- | ||
4837 | // Setup rotors from plugs. |
- | ||
4838 | foreach (char rotor in rotors) |
- | ||
4839 | { |
- | ||
4840 | char plug = plugs[Array.IndexOf(rotors, rotor)]; |
- | ||
4841 | int i = Array.IndexOf(def_rotors[rotor], plug); |
- | ||
4842 | if (i.Equals(0)) continue; |
- | ||
4843 | def_rotors[rotor] = wasConcatenateArrays(new[] {plug}, |
- | ||
4844 | wasGetSubArray(wasDeleteSubArray(def_rotors[rotor], i, i), i, -1), |
- | ||
4845 | wasGetSubArray(wasDeleteSubArray(def_rotors[rotor], i + 1, -1), 0, i - 1)); |
- | ||
4846 | } |
- | ||
4847 | |
- | ||
4848 | StringBuilder result = new StringBuilder(); |
- | ||
4849 | foreach (char c in message) |
- | ||
4850 | { |
- | ||
4851 | if (!char.IsLetter(c)) |
- | ||
4852 | { |
- | ||
4853 | result.Append(c); |
- | ||
4854 | continue; |
- | ||
4855 | } |
- | ||
4856 | |
- | ||
4857 | // Normalize to lower. |
- | ||
4858 | char l = char.ToLower(c); |
- | ||
4859 | |
- | ||
4860 | Action<char[]> rotate = o => |
- | ||
4861 | { |
- | ||
4862 | int i = o.Length - 1; |
- | ||
4863 | do |
- | ||
4864 | { |
- | ||
4865 | def_rotors[o[0]] = wasForwardPermuteArrayElements(def_rotors[o[0]], 1); |
- | ||
4866 | if (i.Equals(0)) |
- | ||
4867 | { |
- | ||
4868 | rotors = wasReversePermuteArrayElements(o, 1); |
- | ||
4869 | continue; |
- | ||
4870 | } |
- | ||
4871 | l = wasGetElementAt(def_rotors[o[1]], Array.IndexOf(def_rotors[o[0]], l) - 1); |
- | ||
4872 | o = wasReversePermuteArrayElements(o, 1); |
- | ||
4873 | } while (--i > -1); |
- | ||
4874 | }; |
- | ||
4875 | |
- | ||
4876 | // Forward pass through the Enigma's rotors. |
- | ||
4877 | rotate.Invoke(rotors); |
- | ||
4878 | |
- | ||
4879 | // Reflect |
- | ||
4880 | int x = Array.IndexOf(def_reflectors[reflector], l); |
- | ||
4881 | l = (x + 1)%2 == 0 ? def_reflectors[reflector][x - 1] : def_reflectors[reflector][x + 1]; |
- | ||
4882 | |
- | ||
4883 | // Reverse the order of the rotors. |
- | ||
4884 | Array.Reverse(rotors); |
- | ||
4885 | |
- | ||
4886 | // Reverse pass through the Enigma's rotors. |
- | ||
4887 | rotate.Invoke(rotors); |
- | ||
4888 | |
- | ||
4889 | if (char.IsUpper(c)) |
- | ||
4890 | { |
- | ||
4891 | l = char.ToUpper(l); |
- | ||
4892 | } |
- | ||
4893 | result.Append(l); |
- | ||
4894 | } |
- | ||
4895 | |
- | ||
4896 | return result.ToString(); |
- | ||
4897 | } |
- | ||
4898 | |
- | ||
4899 | /////////////////////////////////////////////////////////////////////////// |
- | ||
4900 | // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // |
- | ||
4901 | /////////////////////////////////////////////////////////////////////////// |
- | ||
4902 | /// <summary> |
- | ||
4903 | /// Expand the VIGENRE key to the length of the input. |
- | ||
4904 | /// </summary> |
- | ||
4905 | /// <param name="input">the input to expand to</param> |
- | ||
4906 | /// <param name="enc_key">the key to expand</param> |
- | ||
4907 | /// <returns>the expanded key</returns> |
- | ||
4908 | private static string wasVigenereExpandKey(string input, string enc_key) |
- | ||
4909 | { |
- | ||
4910 | string exp_key = string.Empty; |
- | ||
4911 | int i = 0, j = 0; |
- | ||
4912 | do |
- | ||
4913 | { |
- | ||
4914 | char p = input[i]; |
- | ||
4915 | if (!char.IsLetter(p)) |
- | ||
4916 | { |
- | ||
4917 | exp_key += p; |
- | ||
4918 | ++i; |
- | ||
4919 | continue; |
- | ||
4920 | } |
- | ||
4921 | int m = j%enc_key.Length; |
- | ||
4922 | exp_key += enc_key[m]; |
- | ||
4923 | ++j; |
- | ||
4924 | ++i; |
- | ||
4925 | } while (i < input.Length); |
- | ||
4926 | return exp_key; |
- | ||
4927 | } |
- | ||
4928 | |
- | ||
4929 | /////////////////////////////////////////////////////////////////////////// |
- | ||
4930 | // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // |
- | ||
4931 | /////////////////////////////////////////////////////////////////////////// |
- | ||
4932 | /// <summary> |
- | ||
4933 | /// Encrypt using VIGENERE. |
- | ||
4934 | /// </summary> |
- | ||
4935 | /// <param name="input">the input to encrypt</param> |
- | ||
4936 | /// <param name="enc_key">the key to encrypt with</param> |
- | ||
4937 | /// <returns>the encrypted input</returns> |
- | ||
4938 | private static string wasEncryptVIGENERE(string input, string enc_key) |
- | ||
4939 | { |
- | ||
4940 | char[] a = |
- | ||
4941 | { |
- | ||
4942 | 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', |
- | ||
4943 | 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' |
- | ||
4944 | }; |
- | ||
4945 | |
- | ||
4946 | enc_key = wasVigenereExpandKey(input, enc_key); |
- | ||
4947 | string result = string.Empty; |
- | ||
4948 | int i = 0; |
- | ||
4949 | do |
- | ||
4950 | { |
- | ||
4951 | char p = input[i]; |
- | ||
4952 | if (!char.IsLetter(p)) |
- | ||
4953 | { |
- | ||
4954 | result += p; |
- | ||
4955 | ++i; |
- | ||
4956 | continue; |
- | ||
4957 | } |
- | ||
4958 | char q = |
- | ||
4959 | wasReversePermuteArrayElements(a, Array.IndexOf(a, enc_key[i]))[ |
- | ||
4960 | Array.IndexOf(a, char.ToLowerInvariant(p))]; |
- | ||
4961 | if (char.IsUpper(p)) |
- | ||
4962 | { |
- | ||
4963 | q = char.ToUpperInvariant(q); |
- | ||
4964 | } |
- | ||
4965 | result += q; |
- | ||
4966 | ++i; |
- | ||
4967 | } while (i < input.Length); |
- | ||
4968 | return result; |
- | ||
4969 | } |
- | ||
4970 | |
- | ||
4971 | /////////////////////////////////////////////////////////////////////////// |
- | ||
4972 | // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // |
- | ||
4973 | /////////////////////////////////////////////////////////////////////////// |
- | ||
4974 | /// <summary> |
- | ||
4975 | /// Decrypt using VIGENERE. |
- | ||
4976 | /// </summary> |
- | ||
4977 | /// <param name="input">the input to decrypt</param> |
- | ||
4978 | /// <param name="enc_key">the key to decrypt with</param> |
- | ||
4979 | /// <returns>the decrypted input</returns> |
- | ||
4980 | private static string wasDecryptVIGENERE(string input, string enc_key) |
- | ||
4981 | { |
- | ||
4982 | char[] a = |
- | ||
4983 | { |
- | ||
4984 | 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', |
- | ||
4985 | 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' |
- | ||
4986 | }; |
- | ||
4987 | |
- | ||
4988 | enc_key = wasVigenereExpandKey(input, enc_key); |
- | ||
4989 | string result = string.Empty; |
- | ||
4990 | int i = 0; |
- | ||
4991 | do |
- | ||
4992 | { |
- | ||
4993 | char p = input[i]; |
- | ||
4994 | if (!char.IsLetter(p)) |
- | ||
4995 | { |
- | ||
4996 | result += p; |
- | ||
4997 | ++i; |
- | ||
4998 | continue; |
- | ||
4999 | } |
- | ||
5000 | char q = |
- | ||
5001 | a[ |
- | ||
5002 | Array.IndexOf(wasReversePermuteArrayElements(a, Array.IndexOf(a, enc_key[i])), |
- | ||
5003 | char.ToLowerInvariant(p))]; |
- | ||
5004 | if (char.IsUpper(p)) |
- | ||
5005 | { |
- | ||
5006 | q = char.ToUpperInvariant(q); |
- | ||
5007 | } |
- | ||
5008 | result += q; |
- | ||
5009 | ++i; |
- | ||
5010 | } while (i < input.Length); |
- | ||
5011 | return result; |
- | ||
5012 | } |
- | ||
5013 | |
- | ||
5014 | /////////////////////////////////////////////////////////////////////////// |
- | ||
5015 | // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 // |
- | ||
5016 | /////////////////////////////////////////////////////////////////////////// |
- | ||
5017 | /// <summary> |
- | ||
5018 | /// An implementation of the ATBASH cypher for latin alphabets. |
- | ||
5019 | /// </summary> |
- | ||
5020 | /// <param name="data">the data to encrypt or decrypt</param> |
- | ||
5021 | /// <returns>the encrypted or decrypted data</returns> |
- | ||
5022 | private static string wasATBASH(string data) |
- | ||
5023 | { |
- | ||
5024 | char[] a = |
- | ||
5025 | { |
- | ||
5026 | 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', |
- | ||
5027 | 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' |
- | ||
5028 | }; |
- | ||
5029 | |
- | ||
5030 | char[] input = data.ToArray(); |
- | ||
5031 | |
- | ||
5032 | Parallel.ForEach(Enumerable.Range(0, data.Length), i => |
- | ||
5033 | { |
- | ||
5034 | char e = input[i]; |
- | ||
5035 | if (!char.IsLetter(e)) return; |
- | ||
5036 | int x = 25 - Array.BinarySearch(a, char.ToLowerInvariant(e)); |
- | ||
5037 | if (!char.IsUpper(e)) |
- | ||
5038 | { |
- | ||
5039 | input[i] = a[x]; |
- | ||
5040 | return; |
- | ||
5041 | } |
- | ||
5042 | input[i] = char.ToUpperInvariant(a[x]); |
- | ||
5043 | }); |
- | ||
5044 | |
- | ||
5045 | return new string(input); |
- | ||
5046 | } |
4346 | #region CRYPTOGRAPHY |
|
5047 | |
4347 | |
|
5048 | #endregion |
4348 | #endregion |
|
5049 | } |
4349 | } |