corrade-vassal – Diff between revs 13 and 16
?pathlinks?
Rev 13 | Rev 16 | |||
---|---|---|---|---|
Line 10... | Line 10... | |||
10 | using System.Drawing; |
10 | using System.Drawing; |
|
11 | using System.Drawing.Imaging; |
11 | using System.Drawing.Imaging; |
|
12 | using System.IO; |
12 | using System.IO; |
|
13 | using System.Linq; |
13 | using System.Linq; |
|
14 | using System.Net; |
14 | using System.Net; |
|
- | 15 | using System.Net.Http.Headers; |
||
15 | using System.Net.Sockets; |
16 | using System.Net.Sockets; |
|
16 | using System.Reflection; |
17 | using System.Reflection; |
|
17 | using System.Text; |
18 | using System.Text; |
|
18 | using System.Text.RegularExpressions; |
19 | using System.Text.RegularExpressions; |
|
19 | using System.Threading; |
20 | using System.Threading; |
|
Line 37... | Line 38... | |||
37 | public static volatile int regionsStateCheckIndex; |
38 | public static volatile int regionsStateCheckIndex; |
|
38 | public static VassalConfiguration vassalConfiguration = new VassalConfiguration(); |
39 | public static VassalConfiguration vassalConfiguration = new VassalConfiguration(); |
|
39 | public static Vassal vassalForm; |
40 | public static Vassal vassalForm; |
|
40 | public static readonly object ClientInstanceTeleportLock = new object(); |
41 | public static readonly object ClientInstanceTeleportLock = new object(); |
|
41 | public static readonly object RegionsStateCheckLock = new object(); |
42 | public static readonly object RegionsStateCheckLock = new object(); |
|
- | 43 | public static Web.wasHTTPClient HTTPClient; |
||
- | 44 | |
||
- | 45 | /// <summary> |
||
- | 46 | /// Corrade version. |
||
- | 47 | /// </summary> |
||
- | 48 | public static readonly string VASSAL_VERSION = Assembly.GetEntryAssembly().GetName().Version.ToString(); |
||
Line 42... | Line 49... | |||
42 | |
49 | |
|
43 | /// <summary> |
50 | /// <summary> |
|
44 | /// Corrade's input filter function. |
51 | /// Corrade's input filter function. |
|
45 | /// </summary> |
52 | /// </summary> |
|
46 | private static readonly Func<string, string> wasInput = o => |
53 | private static readonly Func<string, string> wasInput = o => |
|
47 | { |
54 | { |
|
Line 48... | Line 55... | |||
48 | if (string.IsNullOrEmpty(o)) return string.Empty; |
55 | if (string.IsNullOrEmpty(o)) return string.Empty; |
|
49 | |
56 | |
|
50 | foreach (Filter filter in vassalConfiguration.InputFilters) |
57 | foreach (var filter in vassalConfiguration.InputFilters) |
|
51 | { |
58 | { |
|
52 | switch (filter) |
59 | switch (filter) |
|
53 | { |
60 | { |
|
Line 81... | Line 88... | |||
81 | /// </summary> |
88 | /// </summary> |
|
82 | private static readonly Func<string, string> wasOutput = o => |
89 | private static readonly Func<string, string> wasOutput = o => |
|
83 | { |
90 | { |
|
84 | if (string.IsNullOrEmpty(o)) return string.Empty; |
91 | if (string.IsNullOrEmpty(o)) return string.Empty; |
|
Line 85... | Line 92... | |||
85 | |
92 | |
|
86 | foreach (Filter filter in vassalConfiguration.OutputFilters) |
93 | foreach (var filter in vassalConfiguration.OutputFilters) |
|
87 | { |
94 | { |
|
88 | switch (filter) |
95 | switch (filter) |
|
89 | { |
96 | { |
|
90 | case Filter.RFC1738: |
97 | case Filter.RFC1738: |
|
Line 114... | Line 121... | |||
114 | |
121 | |
|
115 | private static readonly Action updateCurrentRegionName = () => |
122 | private static readonly Action updateCurrentRegionName = () => |
|
116 | { |
123 | { |
|
117 | try |
124 | try |
|
118 | { |
125 | { |
|
119 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
126 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
120 | KeyValue.Escape(new Dictionary<string, string> |
127 | KeyValue.Escape(new Dictionary<string, string> |
|
121 | { |
128 | { |
|
122 | {"command", "getregiondata"}, |
129 | {"command", "getregiondata"}, |
|
123 | {"group", vassalConfiguration.Group}, |
130 | {"group", vassalConfiguration.Group}, |
|
124 | {"password", vassalConfiguration.Password}, |
131 | {"password", vassalConfiguration.Password}, |
|
125 | {"data", "Name"} |
132 | {"data", "Name"} |
|
126 | }, wasOutput), 60000); |
133 | }, wasOutput)).Result); |
|
127 | bool success; |
134 | bool success; |
|
128 | if (string.IsNullOrEmpty(result) || |
135 | if (string.IsNullOrEmpty(result) || |
|
129 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
136 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
130 | { |
137 | { |
|
Line 170... | Line 177... | |||
170 | { |
177 | { |
|
171 | InitializeComponent(); |
178 | InitializeComponent(); |
|
172 | vassalForm = this; |
179 | vassalForm = this; |
|
173 | } |
180 | } |
|
Line 174... | Line -... | |||
174 | |
- | ||
175 | /////////////////////////////////////////////////////////////////////////// |
- | ||
176 | // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // |
- | ||
177 | /////////////////////////////////////////////////////////////////////////// |
- | ||
178 | /// <summary> |
- | ||
179 | /// Sends a post request to an URL with set key-value pairs. |
- | ||
180 | /// </summary> |
181 | |
|
181 | /// <param name="URL">the url to send the message to</param> |
- | ||
182 | /// <param name="message">key-value pairs to send</param> |
- | ||
183 | /// <param name="millisecondsTimeout">the time in milliseconds for the request to timeout</param> |
- | ||
184 | private static string wasPOST(string URL, Dictionary<string, string> message, uint millisecondsTimeout) |
182 | private void ShowToolTip(object sender, EventArgs e) |
|
185 | { |
- | ||
186 | try |
- | ||
187 | { |
- | ||
188 | HttpWebRequest request = (HttpWebRequest) WebRequest.Create(URL); |
- | ||
189 | request.UserAgent = VASSAL_CONSTANTS.USER_AGENT; |
- | ||
190 | request.Proxy = WebRequest.DefaultWebProxy; |
183 | { |
|
191 | request.Pipelined = true; |
- | ||
192 | request.KeepAlive = true; |
- | ||
193 | request.Timeout = (int) millisecondsTimeout; |
- | ||
194 | request.ReadWriteTimeout = (int) millisecondsTimeout; |
- | ||
195 | request.AllowAutoRedirect = true; |
- | ||
196 | request.AllowWriteStreamBuffering = true; |
- | ||
197 | request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; |
- | ||
198 | request.Method = WebRequestMethods.Http.Post; |
- | ||
199 | // set the content type based on chosen output filers |
- | ||
200 | switch (vassalConfiguration.OutputFilters.Last()) |
- | ||
201 | { |
- | ||
202 | case Filter.RFC1738: |
- | ||
203 | request.ContentType = VASSAL_CONSTANTS.CONTENT_TYPE.WWW_FORM_URLENCODED; |
- | ||
204 | break; |
- | ||
205 | default: |
- | ||
206 | request.ContentType = VASSAL_CONSTANTS.CONTENT_TYPE.TEXT_PLAIN; |
184 | vassalForm.BeginInvoke( |
|
207 | break; |
- | ||
208 | } |
- | ||
209 | // send request |
- | ||
210 | using (Stream requestStream = request.GetRequestStream()) |
- | ||
211 | { |
- | ||
212 | using (StreamWriter dataStream = new StreamWriter(requestStream)) |
- | ||
213 | { |
- | ||
214 | dataStream.Write(KeyValue.Encode(message)); |
- | ||
215 | } |
- | ||
216 | } |
- | ||
217 | // read response |
- | ||
218 | using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) |
185 | (Action)(() => |
|
219 | { |
186 | { |
|
- | 187 | PictureBox pictureBox = sender as PictureBox; |
||
220 | using (Stream responseStream = response.GetResponseStream()) |
188 | if (pictureBox != null) |
|
221 | { |
- | ||
222 | if (responseStream != null) |
- | ||
223 | { |
- | ||
224 | using ( |
189 | { |
|
225 | StreamReader streamReader = new StreamReader(responseStream)) |
- | ||
226 | { |
- | ||
227 | return streamReader.ReadToEnd(); |
- | ||
228 | } |
- | ||
229 | } |
190 | toolTip1.Show(toolTip1.GetToolTip(pictureBox), pictureBox); |
|
230 | } |
191 | } |
|
231 | } |
- | ||
232 | } |
- | ||
233 | catch (Exception) |
- | ||
234 | { |
- | ||
235 | } |
- | ||
236 | |
- | ||
237 | return null; |
192 | })); |
|
Line 238... | Line 193... | |||
238 | } |
193 | } |
|
239 | |
194 | |
|
240 | private void RegionSelected(object sender, EventArgs e) |
195 | private void RegionSelected(object sender, EventArgs e) |
|
Line 251... | Line 206... | |||
251 | estateTopTabTimer.Stop(); |
206 | estateTopTabTimer.Stop(); |
|
252 | estateTexturesTabTimer.Stop(); |
207 | estateTexturesTabTimer.Stop(); |
|
Line 253... | Line 208... | |||
253 | |
208 | |
|
Line 254... | Line 209... | |||
254 | Monitor.Enter(ClientInstanceTeleportLock); |
209 | Monitor.Enter(ClientInstanceTeleportLock); |
|
255 | |
210 | |
|
256 | string selectedRegionName = string.Empty; |
211 | var selectedRegionName = string.Empty; |
|
257 | Vector3 selectedRegionPosition = Vector3.Zero; |
212 | var selectedRegionPosition = Vector3.Zero; |
|
258 | bool startTeleport = false; |
213 | var startTeleport = false; |
|
259 | vassalForm.Invoke((MethodInvoker) (() => |
214 | vassalForm.Invoke((MethodInvoker) (() => |
|
260 | { |
215 | { |
|
261 | ListViewItem listViewItem = LoadedRegionsBox.SelectedItem as ListViewItem; |
216 | var listViewItem = LoadedRegionsBox.SelectedItem as ListViewItem; |
|
262 | switch (listViewItem != null && LoadedRegionsBox.SelectedIndex != -1) |
217 | switch (listViewItem != null && LoadedRegionsBox.SelectedIndex != -1) |
|
263 | { |
218 | { |
|
264 | case true: |
219 | case true: |
|
Line 283... | Line 238... | |||
283 | })); |
238 | })); |
|
Line 284... | Line 239... | |||
284 | |
239 | |
|
285 | // Pause for teleport (10 teleports / 15s allowed). |
240 | // Pause for teleport (10 teleports / 15s allowed). |
|
Line 286... | Line 241... | |||
286 | Thread.Sleep(700); |
241 | Thread.Sleep(700); |
|
287 | |
242 | |
|
288 | int elapsedSeconds = 0; |
243 | var elapsedSeconds = 0; |
|
289 | Timer teleportTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); |
244 | var teleportTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); |
|
290 | teleportTimer.Elapsed += (o, p) => |
245 | teleportTimer.Elapsed += (o, p) => |
|
291 | { |
246 | { |
|
292 | vassalForm.Invoke((MethodInvoker) (() => |
247 | vassalForm.Invoke((MethodInvoker) (() => |
|
Line 299... | Line 254... | |||
299 | vassalConfiguration.TeleportTimeout)), 100); |
254 | vassalConfiguration.TeleportTimeout)), 100); |
|
300 | })); |
255 | })); |
|
301 | }; |
256 | }; |
|
302 | teleportTimer.Start(); |
257 | teleportTimer.Start(); |
|
303 | string result = null; |
258 | string result = null; |
|
304 | ManualResetEvent receivedPOST = new ManualResetEvent(false); |
259 | var receivedPOST = new ManualResetEvent(false); |
|
305 | new Thread(() => |
260 | new Thread(() => |
|
306 | { |
261 | { |
|
307 | result = wasInput(wasPOST(vassalConfiguration.HTTPServerURL, |
262 | result = wasInput(Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
308 | KeyValue.Escape(new Dictionary<string, string> |
263 | KeyValue.Escape(new Dictionary<string, string> |
|
309 | { |
264 | { |
|
310 | {"command", "teleport"}, |
265 | {"command", "teleport"}, |
|
311 | {"group", vassalConfiguration.Group}, |
266 | {"group", vassalConfiguration.Group}, |
|
312 | {"password", vassalConfiguration.Password}, |
267 | {"password", vassalConfiguration.Password}, |
|
313 | {"region", selectedRegionName}, |
268 | {"region", selectedRegionName}, |
|
314 | {"position", selectedRegionPosition.ToString()}, |
269 | {"position", selectedRegionPosition.ToString()}, |
|
315 | {"fly", "True"} |
270 | {"fly", "True"} |
|
316 | }, wasOutput), vassalConfiguration.TeleportTimeout)); |
271 | }, wasOutput)).Result)); |
|
317 | receivedPOST.Set(); |
272 | receivedPOST.Set(); |
|
318 | }) {IsBackground = true}.Start(); |
273 | }) {IsBackground = true}.Start(); |
|
319 | receivedPOST.WaitOne((int) vassalConfiguration.TeleportTimeout, false); |
274 | receivedPOST.WaitOne((int) vassalConfiguration.TeleportTimeout, false); |
|
320 | teleportTimer.Stop(); |
275 | teleportTimer.Stop(); |
|
321 | switch (!string.IsNullOrEmpty(result) && KeyValue.Get("success", result) == "True") |
276 | switch (!string.IsNullOrEmpty(result) && KeyValue.Get("success", result) == "True") |
|
Line 362... | Line 317... | |||
362 | vassalForm.BeginInvoke((MethodInvoker) (() => |
317 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
363 | { |
318 | { |
|
364 | vassalForm.StatusProgress.Value = 100; |
319 | vassalForm.StatusProgress.Value = 100; |
|
365 | vassalForm.RegionTeleportGroup.Enabled = true; |
320 | vassalForm.RegionTeleportGroup.Enabled = true; |
|
366 | // Set the map image to the loading spinner. |
321 | // Set the map image to the loading spinner. |
|
367 | Assembly thisAssembly = Assembly.GetExecutingAssembly(); |
322 | var thisAssembly = Assembly.GetExecutingAssembly(); |
|
368 | Stream file = |
323 | var file = |
|
369 | thisAssembly.GetManifestResourceStream("Vassal.img.loading.gif"); |
324 | thisAssembly.GetManifestResourceStream("Vassal.img.loading.gif"); |
|
370 | switch (file != null) |
325 | switch (file != null) |
|
371 | { |
326 | { |
|
372 | case true: |
327 | case true: |
|
373 | vassalForm.Invoke((MethodInvoker) (() => |
328 | vassalForm.Invoke((MethodInvoker) (() => |
|
Line 432... | Line 387... | |||
432 | } |
387 | } |
|
Line 433... | Line 388... | |||
433 | |
388 | |
|
434 | private void SettingsRequested(object sender, EventArgs e) |
389 | private void SettingsRequested(object sender, EventArgs e) |
|
435 | { |
390 | { |
|
436 | vassalForm.BeginInvoke((MethodInvoker) (() => { VassalStatusGroup.Enabled = false; })); |
391 | vassalForm.BeginInvoke((MethodInvoker) (() => { VassalStatusGroup.Enabled = false; })); |
|
437 | SettingsForm settingsForm = new SettingsForm {TopMost = true}; |
392 | var settingsForm = new SettingsForm {TopMost = true}; |
|
438 | settingsForm.Show(); |
393 | settingsForm.Show(); |
|
Line 439... | Line 394... | |||
439 | } |
394 | } |
|
440 | |
395 | |
|
Line 465... | Line 420... | |||
465 | { |
420 | { |
|
466 | // Load the configuration. |
421 | // Load the configuration. |
|
467 | VassalConfiguration.Load(VASSAL_CONSTANTS.VASSAL_CONFIGURATION_FILE, ref vassalConfiguration); |
422 | VassalConfiguration.Load(VASSAL_CONSTANTS.VASSAL_CONFIGURATION_FILE, ref vassalConfiguration); |
|
468 | // Apply settings |
423 | // Apply settings |
|
469 | RegionRestartDelayBox.Text = vassalConfiguration.RegionRestartDelay.ToString(Utils.EnUsCulture); |
424 | RegionRestartDelayBox.Text = vassalConfiguration.RegionRestartDelay.ToString(Utils.EnUsCulture); |
|
- | 425 | // HTTP |
||
- | 426 | string mediaType; |
||
- | 427 | switch (vassalConfiguration.InputFilters.LastOrDefault()) |
||
- | 428 | { |
||
- | 429 | case Filter.RFC1738: |
||
- | 430 | mediaType = @"application/x-www-form-urlencoded"; |
||
- | 431 | break; |
||
- | 432 | default: |
||
- | 433 | mediaType = @"text/plain"; |
||
- | 434 | break; |
||
- | 435 | } |
||
- | 436 | // Create HTTP Client |
||
- | 437 | Vassal.HTTPClient = new Web.wasHTTPClient(new ProductInfoHeaderValue(@"Vassal", |
||
- | 438 | Vassal.VASSAL_VERSION), new CookieContainer(), mediaType, vassalConfiguration.ServicesTimeout); |
||
470 | } |
439 | } |
|
Line 471... | Line 440... | |||
471 | |
440 | |
|
472 | // Get all the regions if they exist. |
441 | // Get all the regions if they exist. |
|
473 | if (File.Exists(VASSAL_CONSTANTS.VASSAL_REGIONS)) |
442 | if (File.Exists(VASSAL_CONSTANTS.VASSAL_REGIONS)) |
|
474 | { |
443 | { |
|
475 | Vector3 localPosition; |
444 | Vector3 localPosition; |
|
476 | List<KeyValuePair<string, Vector3>> ConfiguredRegions = new List<KeyValuePair<string, Vector3>>( |
445 | var ConfiguredRegions = new List<KeyValuePair<string, Vector3>>( |
|
477 | File.ReadAllLines(VASSAL_CONSTANTS.VASSAL_REGIONS) |
446 | File.ReadAllLines(VASSAL_CONSTANTS.VASSAL_REGIONS) |
|
478 | .Select(o => new List<string>(CSV.ToEnumerable(o))) |
447 | .Select(o => new List<string>(CSV.ToEnumerable(o))) |
|
479 | .Where(o => o.Count == 2) |
448 | .Where(o => o.Count == 2) |
|
480 | .ToDictionary(o => o.First(), |
449 | .ToDictionary(o => o.First(), |
|
Line 487... | Line 456... | |||
487 | LoadedRegionsBox.Items.AddRange( |
456 | LoadedRegionsBox.Items.AddRange( |
|
488 | ConfiguredRegions.Select(o => (object) new ListViewItem {Text = o.Key, Tag = o.Value}) |
457 | ConfiguredRegions.Select(o => (object) new ListViewItem {Text = o.Key, Tag = o.Value}) |
|
489 | .ToArray()); |
458 | .ToArray()); |
|
490 | // Populate the batch restart grid view. |
459 | // Populate the batch restart grid view. |
|
491 | BatchRestartGridView.Rows.Clear(); |
460 | BatchRestartGridView.Rows.Clear(); |
|
492 | foreach (KeyValuePair<string, Vector3> data in ConfiguredRegions) |
461 | foreach (var data in ConfiguredRegions) |
|
493 | { |
462 | { |
|
494 | BatchRestartGridView.Rows.Add(data.Key, data.Value.ToString()); |
463 | BatchRestartGridView.Rows.Add(data.Key, data.Value.ToString()); |
|
495 | } |
464 | } |
|
- | 465 | // Populate the batch covenant grid view. |
||
- | 466 | BatchSetCovenantGridView.Rows.Clear(); |
||
- | 467 | foreach (var data in ConfiguredRegions) |
||
- | 468 | { |
||
- | 469 | BatchSetCovenantGridView.Rows.Add(data.Key, data.Value.ToString()); |
||
- | 470 | } |
||
496 | // Populate the regions state grid view. |
471 | // Populate the regions state grid view. |
|
497 | foreach (KeyValuePair<string, Vector3> data in ConfiguredRegions) |
472 | foreach (var data in ConfiguredRegions) |
|
498 | { |
473 | { |
|
499 | RegionsStateGridView.Rows.Add(data.Key, "Check pening..."); |
474 | RegionsStateGridView.Rows.Add(data.Key, "Check pening..."); |
|
500 | } |
475 | } |
|
501 | } |
476 | } |
|
Line 506... | Line 481... | |||
506 | if (!Monitor.TryEnter(ClientInstanceTeleportLock)) |
481 | if (!Monitor.TryEnter(ClientInstanceTeleportLock)) |
|
507 | return; |
482 | return; |
|
508 | try |
483 | try |
|
509 | { |
484 | { |
|
510 | // Check Corrade connection status. |
485 | // Check Corrade connection status. |
|
511 | TcpClient tcpClient = new TcpClient(); |
486 | var tcpClient = new TcpClient(); |
|
512 | Uri uri = new Uri(vassalConfiguration.HTTPServerURL); |
487 | var uri = new Uri(vassalConfiguration.HTTPServerURL); |
|
513 | tcpClient.Connect(uri.Host, uri.Port); |
488 | tcpClient.Connect(uri.Host, uri.Port); |
|
514 | // port open |
489 | // port open |
|
515 | vassalForm.BeginInvoke((MethodInvoker) (() => |
490 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
516 | { |
491 | { |
|
517 | vassalForm.CurrentRegionAt.Visible = true; |
492 | vassalForm.CurrentRegionAt.Visible = true; |
|
518 | vassalForm.CurrentRegionName.Visible = true; |
493 | vassalForm.CurrentRegionName.Visible = true; |
|
519 | Assembly thisAssembly = Assembly.GetExecutingAssembly(); |
494 | var thisAssembly = Assembly.GetExecutingAssembly(); |
|
520 | Stream file = |
495 | var file = |
|
521 | thisAssembly.GetManifestResourceStream("Vassal.img.online.png"); |
496 | thisAssembly.GetManifestResourceStream("Vassal.img.online.png"); |
|
522 | switch (file != null) |
497 | switch (file != null) |
|
523 | { |
498 | { |
|
524 | case true: |
499 | case true: |
|
525 | vassalForm.BeginInvoke((MethodInvoker) (() => |
500 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
Line 538... | Line 513... | |||
538 | // port closed |
513 | // port closed |
|
539 | vassalForm.BeginInvoke((MethodInvoker) (() => |
514 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
540 | { |
515 | { |
|
541 | vassalForm.CurrentRegionAt.Visible = false; |
516 | vassalForm.CurrentRegionAt.Visible = false; |
|
542 | vassalForm.CurrentRegionName.Visible = false; |
517 | vassalForm.CurrentRegionName.Visible = false; |
|
543 | Assembly thisAssembly = Assembly.GetExecutingAssembly(); |
518 | var thisAssembly = Assembly.GetExecutingAssembly(); |
|
544 | Stream file = |
519 | var file = |
|
545 | thisAssembly.GetManifestResourceStream("Vassal.img.offline.png"); |
520 | thisAssembly.GetManifestResourceStream("Vassal.img.offline.png"); |
|
546 | switch (file != null) |
521 | switch (file != null) |
|
547 | { |
522 | { |
|
548 | case true: |
523 | case true: |
|
549 | vassalForm.BeginInvoke((MethodInvoker) (() => |
524 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
Line 559... | Line 534... | |||
559 | } |
534 | } |
|
Line 560... | Line 535... | |||
560 | |
535 | |
|
561 | try |
536 | try |
|
562 | { |
537 | { |
|
563 | // Get the simulator name and if we are an estate manager. |
538 | // Get the simulator name and if we are an estate manager. |
|
564 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
539 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
565 | KeyValue.Escape(new Dictionary<string, string> |
540 | KeyValue.Escape(new Dictionary<string, string> |
|
566 | { |
541 | { |
|
567 | {"command", "getregiondata"}, |
542 | {"command", "getregiondata"}, |
|
568 | {"group", vassalConfiguration.Group}, |
543 | {"group", vassalConfiguration.Group}, |
|
Line 572... | Line 547... | |||
572 | { |
547 | { |
|
573 | "Name", |
548 | "Name", |
|
574 | "IsEstateManager" |
549 | "IsEstateManager" |
|
575 | }) |
550 | }) |
|
576 | } |
551 | } |
|
577 | }, wasOutput), vassalConfiguration.DataTimeout); |
552 | }, wasOutput)).Result); |
|
Line 578... | Line 553... | |||
578 | |
553 | |
|
579 | bool success; |
554 | bool success; |
|
580 | if (string.IsNullOrEmpty(result) || |
555 | if (string.IsNullOrEmpty(result) || |
|
581 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
556 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
Line 582... | Line 557... | |||
582 | throw new Exception(); |
557 | throw new Exception(); |
|
583 | |
558 | |
|
584 | List<string> data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
559 | var data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
|
Line 585... | Line 560... | |||
585 | if (data.Count.Equals(0)) |
560 | if (data.Count.Equals(0)) |
|
586 | throw new Exception(); |
561 | throw new Exception(); |
|
Line 649... | Line 624... | |||
649 | |
624 | |
|
650 | // Start the overview timer. |
625 | // Start the overview timer. |
|
651 | overviewTabTimer.Elapsed += (o, p) => |
626 | overviewTabTimer.Elapsed += (o, p) => |
|
652 | { |
627 | { |
|
653 | // Do not do anything in case the tab is not selected. |
628 | // Do not do anything in case the tab is not selected. |
|
654 | bool run = false; |
629 | var run = false; |
|
Line 655... | Line 630... | |||
655 | vassalForm.Invoke((MethodInvoker) (() => { run = Tabs.SelectedTab.Equals(OverviewTab); })); |
630 | vassalForm.Invoke((MethodInvoker) (() => { run = Tabs.SelectedTab.Equals(OverviewTab); })); |
|
656 | |
631 | |
|
657 | if (!run) |
632 | if (!run) |
|
Line 663... | Line 638... | |||
663 | overviewTabTimer.Stop(); |
638 | overviewTabTimer.Stop(); |
|
Line 664... | Line 639... | |||
664 | |
639 | |
|
665 | try |
640 | try |
|
666 | { |
641 | { |
|
667 | // Start measuring the lag to Corrade. |
642 | // Start measuring the lag to Corrade. |
|
668 | Stopwatch stopWatch = new Stopwatch(); |
643 | var stopWatch = new Stopwatch(); |
|
669 | stopWatch.Start(); |
644 | stopWatch.Start(); |
|
670 | // Get the statistics. |
645 | // Get the statistics. |
|
671 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
646 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
672 | KeyValue.Escape(new Dictionary<string, string> |
647 | KeyValue.Escape(new Dictionary<string, string> |
|
673 | { |
648 | { |
|
674 | {"command", "getregiondata"}, |
649 | {"command", "getregiondata"}, |
|
675 | {"group", vassalConfiguration.Group}, |
650 | {"group", vassalConfiguration.Group}, |
|
Line 690... | Line 665... | |||
690 | "PhysicsTime", |
665 | "PhysicsTime", |
|
691 | "NetTime", |
666 | "NetTime", |
|
692 | "AvatarPositions" |
667 | "AvatarPositions" |
|
693 | }) |
668 | }) |
|
694 | } |
669 | } |
|
695 | }, wasOutput), vassalConfiguration.DataTimeout); |
670 | }, wasOutput)).Result); |
|
696 | stopWatch.Stop(); |
671 | stopWatch.Stop(); |
|
Line 697... | Line 672... | |||
697 | |
672 | |
|
698 | bool success; |
673 | bool success; |
|
699 | if (string.IsNullOrEmpty(result) || |
674 | if (string.IsNullOrEmpty(result) || |
|
700 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
675 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
Line 701... | Line 676... | |||
701 | throw new Exception(); |
676 | throw new Exception(); |
|
702 | |
677 | |
|
703 | List<string> data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
678 | var data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
|
Line 704... | Line 679... | |||
704 | if (data.Count.Equals(0)) |
679 | if (data.Count.Equals(0)) |
|
705 | throw new Exception(); |
680 | throw new Exception(); |
|
Line 739... | Line 714... | |||
739 | })); |
714 | })); |
|
Line 740... | Line 715... | |||
740 | |
715 | |
|
741 | // Get avatar positions. |
716 | // Get avatar positions. |
|
742 | // Pattern: [...], X, 10, Y, 63, Z, 200, [...], X, 52, Y, 73, Z, 55, [...[...]] |
717 | // Pattern: [...], X, 10, Y, 63, Z, 200, [...], X, 52, Y, 73, Z, 55, [...[...]] |
|
743 | float X = 0, Y = 0, Z = 0; |
718 | float X = 0, Y = 0, Z = 0; |
|
744 | List<Vector3> positions = data.Select((x, i) => new {Item = x, Index = i}) |
719 | var positions = data.Select((x, i) => new {Item = x, Index = i}) |
|
745 | .Where(x => x.Item.Equals("X") || x.Item.Equals("Y") || x.Item.Equals("Z")) |
720 | .Where(x => x.Item.Equals("X") || x.Item.Equals("Y") || x.Item.Equals("Z")) |
|
746 | .Select(z => data[z.Index + 1]).Select((x, i) => new {Value = x, Index = i}) |
721 | .Select(z => data[z.Index + 1]).Select((x, i) => new {Value = x, Index = i}) |
|
747 | .GroupBy(x => x.Index/3) |
722 | .GroupBy(x => x.Index/3) |
|
748 | .Select(x => x.Select(v => v.Value).ToList()) |
723 | .Select(x => x.Select(v => v.Value).ToList()) |
|
Line 752... | Line 727... | |||
752 | float.TryParse(x[2], out Z)) |
727 | float.TryParse(x[2], out Z)) |
|
753 | .Select(x => new Vector3(X, Y, Z)) |
728 | .Select(x => new Vector3(X, Y, Z)) |
|
754 | .ToList(); |
729 | .ToList(); |
|
Line 755... | Line 730... | |||
755 | |
730 | |
|
756 | // Get the map image. |
731 | // Get the map image. |
|
757 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
732 | result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
758 | KeyValue.Escape(new Dictionary<string, string> |
733 | KeyValue.Escape(new Dictionary<string, string> |
|
759 | { |
734 | { |
|
760 | {"command", "getgridregiondata"}, |
735 | {"command", "getgridregiondata"}, |
|
761 | {"group", vassalConfiguration.Group}, |
736 | {"group", vassalConfiguration.Group}, |
|
762 | {"password", vassalConfiguration.Password}, |
737 | {"password", vassalConfiguration.Password}, |
|
763 | {"data", "MapImageID"} |
738 | {"data", "MapImageID"} |
|
Line 764... | Line 739... | |||
764 | }, wasOutput), vassalConfiguration.DataTimeout); |
739 | }, wasOutput)).Result); |
|
765 | |
740 | |
|
766 | if (string.IsNullOrEmpty(result) || |
741 | if (string.IsNullOrEmpty(result) || |
|
Line 767... | Line 742... | |||
767 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
742 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
768 | throw new Exception(); |
743 | throw new Exception(); |
|
769 | |
744 | |
|
770 | data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
745 | data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
|
771 | if (!data.Count.Equals(2)) |
746 | if (!data.Count.Equals(2)) |
|
772 | throw new Exception(); |
747 | throw new Exception(); |
|
773 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
748 | result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
774 | KeyValue.Escape(new Dictionary<string, string> |
749 | KeyValue.Escape(new Dictionary<string, string> |
|
775 | { |
750 | { |
|
776 | {"command", "download"}, |
751 | {"command", "download"}, |
|
777 | {"group", vassalConfiguration.Group}, |
752 | {"group", vassalConfiguration.Group}, |
|
778 | {"password", vassalConfiguration.Password}, |
753 | {"password", vassalConfiguration.Password}, |
|
779 | {"item", data.Last()}, |
754 | {"item", data.Last()}, |
|
780 | {"type", "Texture"}, |
755 | {"type", "Texture"}, |
|
781 | {"format", "Jpeg"} |
756 | {"format", "Jpeg"} |
|
782 | }, wasOutput), vassalConfiguration.DataTimeout); |
757 | }, wasOutput)).Result); |
|
783 | if (string.IsNullOrEmpty(result) || |
758 | if (string.IsNullOrEmpty(result) || |
|
784 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
759 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
785 | throw new Exception(); |
760 | throw new Exception(); |
|
786 | byte[] mapImageBytes = Convert.FromBase64String(wasInput(KeyValue.Get("data", result))); |
761 | var mapImageBytes = Convert.FromBase64String(wasInput(KeyValue.Get("data", result))); |
|
787 | Image mapImage; |
762 | Image mapImage; |
|
788 | using (MemoryStream memoryStream = new MemoryStream(mapImageBytes, 0, mapImageBytes.Length)) |
763 | using (var memoryStream = new MemoryStream(mapImageBytes, 0, mapImageBytes.Length)) |
|
Line 789... | Line 764... | |||
789 | { |
764 | { |
|
790 | mapImage = Image.FromStream(memoryStream); |
765 | mapImage = Image.FromStream(memoryStream); |
|
791 | } |
766 | } |
|
792 | |
767 | |
|
793 | // Draw the avatars onto the map. |
768 | // Draw the avatars onto the map. |
|
794 | Graphics mapGraphics = Graphics.FromImage(mapImage); |
769 | var mapGraphics = Graphics.FromImage(mapImage); |
|
795 | foreach (Vector3 position in positions) |
770 | foreach (var position in positions) |
|
796 | { |
771 | { |
|
Line 815... | Line 790... | |||
815 | overviewTabTimer.Start(); |
790 | overviewTabTimer.Start(); |
|
Line 816... | Line 791... | |||
816 | |
791 | |
|
817 | regionsStateTabTimer.Elapsed += (o, p) => |
792 | regionsStateTabTimer.Elapsed += (o, p) => |
|
818 | { |
793 | { |
|
819 | // Do not do anything in case the tab is not selected. |
794 | // Do not do anything in case the tab is not selected. |
|
820 | bool run = false; |
795 | var run = false; |
|
Line 821... | Line 796... | |||
821 | vassalForm.Invoke((MethodInvoker) (() => { run = Tabs.SelectedTab.Equals(RegionsStateTab); })); |
796 | vassalForm.Invoke((MethodInvoker) (() => { run = Tabs.SelectedTab.Equals(RegionsStateTab); })); |
|
822 | |
797 | |
|
823 | if (!run) |
798 | if (!run) |
|
Line 828... | Line 803... | |||
828 | |
803 | |
|
Line 829... | Line 804... | |||
829 | regionsStateTabTimer.Stop(); |
804 | regionsStateTabTimer.Stop(); |
|
830 | |
805 | |
|
831 | try |
806 | try |
|
832 | { |
807 | { |
|
833 | string regionName = string.Empty; |
808 | var regionName = string.Empty; |
|
834 | vassalForm.Invoke((MethodInvoker) (() => |
809 | vassalForm.Invoke((MethodInvoker) (() => |
|
835 | { |
810 | { |
|
836 | regionName = |
811 | regionName = |
|
Line 842... | Line 817... | |||
842 | |
817 | |
|
843 | if (string.IsNullOrEmpty(regionName)) |
818 | if (string.IsNullOrEmpty(regionName)) |
|
Line 844... | Line 819... | |||
844 | throw new Exception(); |
819 | throw new Exception(); |
|
845 | |
820 | |
|
846 | // Get the region status. |
821 | // Get the region status. |
|
847 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
822 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
848 | KeyValue.Escape(new Dictionary<string, string> |
823 | KeyValue.Escape(new Dictionary<string, string> |
|
849 | { |
824 | { |
|
850 | {"command", "getgridregiondata"}, |
825 | {"command", "getgridregiondata"}, |
|
851 | {"group", vassalConfiguration.Group}, |
826 | {"group", vassalConfiguration.Group}, |
|
852 | {"password", vassalConfiguration.Password}, |
827 | {"password", vassalConfiguration.Password}, |
|
853 | {"region", regionName}, |
828 | {"region", regionName}, |
|
Line 854... | Line 829... | |||
854 | {"data", "Access"} |
829 | {"data", "Access"} |
|
855 | }, wasOutput), vassalConfiguration.DataTimeout); |
830 | }, wasOutput)).Result); |
|
856 | |
831 | |
|
857 | bool success; |
832 | bool success; |
|
Line 858... | Line 833... | |||
858 | if (string.IsNullOrEmpty(result) || |
833 | if (string.IsNullOrEmpty(result) || |
|
859 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
834 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
860 | throw new Exception(); |
835 | throw new Exception(); |
|
Line 861... | Line 836... | |||
861 | |
836 | |
|
862 | List<string> data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
837 | var data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
|
863 | if (!data.Count.Equals(2)) |
838 | if (!data.Count.Equals(2)) |
|
864 | throw new Exception(); |
839 | throw new Exception(); |
|
865 | |
840 | |
|
866 | string status = data.Last(); |
841 | var status = data.Last(); |
|
Line 909... | Line 884... | |||
909 | |
884 | |
|
910 | // Start the top scores timer. |
885 | // Start the top scores timer. |
|
911 | estateTopTabTimer.Elapsed += (o, p) => |
886 | estateTopTabTimer.Elapsed += (o, p) => |
|
912 | { |
887 | { |
|
913 | // Do not do anything in case the tab is not selected. |
888 | // Do not do anything in case the tab is not selected. |
|
914 | bool run = false; |
889 | var run = false; |
|
Line 915... | Line 890... | |||
915 | vassalForm.Invoke((MethodInvoker) (() => { run = Tabs.SelectedTab.Equals(EstateTopTab); })); |
890 | vassalForm.Invoke((MethodInvoker) (() => { run = Tabs.SelectedTab.Equals(EstateTopTab); })); |
|
916 | |
891 | |
|
917 | if (!run) |
892 | if (!run) |
|
Line 923... | Line 898... | |||
923 | estateTopTabTimer.Stop(); |
898 | estateTopTabTimer.Stop(); |
|
Line 924... | Line 899... | |||
924 | |
899 | |
|
925 | try |
900 | try |
|
926 | { |
901 | { |
|
927 | // Get the top scripts. |
902 | // Get the top scripts. |
|
928 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
903 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
929 | KeyValue.Escape(new Dictionary<string, string> |
904 | KeyValue.Escape(new Dictionary<string, string> |
|
930 | { |
905 | { |
|
931 | {"command", "getregiontop"}, |
906 | {"command", "getregiontop"}, |
|
932 | {"group", vassalConfiguration.Group}, |
907 | {"group", vassalConfiguration.Group}, |
|
933 | {"password", vassalConfiguration.Password}, |
908 | {"password", vassalConfiguration.Password}, |
|
934 | {"type", "scripts"} |
909 | {"type", "scripts"} |
|
Line 935... | Line 910... | |||
935 | }, wasOutput), vassalConfiguration.DataTimeout); |
910 | }, wasOutput)).Result); |
|
936 | |
911 | |
|
937 | bool success; |
912 | bool success; |
|
938 | if (string.IsNullOrEmpty(result) || |
913 | if (string.IsNullOrEmpty(result) || |
|
Line 939... | Line 914... | |||
939 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
914 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
940 | throw new Exception(); |
915 | throw new Exception(); |
|
941 | |
916 | |
|
942 | HashSet<List<string>> data = |
917 | var data = |
|
943 | new HashSet<List<string>>(CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
918 | new HashSet<List<string>>(CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
|
944 | .Select((x, i) => new {Index = i, Value = x}) |
919 | .Select((x, i) => new {Index = i, Value = x}) |
|
Line 949... | Line 924... | |||
949 | |
924 | |
|
950 | vassalForm.Invoke((MethodInvoker) (() => |
925 | vassalForm.Invoke((MethodInvoker) (() => |
|
951 | { |
926 | { |
|
952 | // Remove rows that are not in the data update. |
927 | // Remove rows that are not in the data update. |
|
953 | foreach ( |
928 | foreach ( |
|
954 | int index in |
929 | var index in |
|
955 | TopScriptsGridView.Rows.AsParallel().Cast<DataGridViewRow>() |
930 | TopScriptsGridView.Rows.AsParallel().Cast<DataGridViewRow>() |
|
956 | .Where( |
931 | .Where( |
|
957 | topScriptsRow => |
932 | topScriptsRow => |
|
958 | !data.Any(q => q[2].Equals(topScriptsRow.Cells["TopScriptsUUID"].Value))) |
933 | !data.Any(q => q[2].Equals(topScriptsRow.Cells["TopScriptsUUID"].Value))) |
|
959 | .Select(q => q.Index)) |
934 | .Select(q => q.Index)) |
|
960 | { |
935 | { |
|
961 | TopScriptsGridView.Rows.RemoveAt(index); |
936 | TopScriptsGridView.Rows.RemoveAt(index); |
|
962 | } |
937 | } |
|
963 | // Now update or add new data. |
938 | // Now update or add new data. |
|
964 | foreach (List<string> dataComponents in data.Where(q => q.Count.Equals(5))) |
939 | foreach (var dataComponents in data.Where(q => q.Count.Equals(5))) |
|
965 | { |
940 | { |
|
966 | DataGridViewRow row = |
941 | var row = |
|
967 | TopScriptsGridView.Rows.AsParallel() |
942 | TopScriptsGridView.Rows.AsParallel() |
|
968 | .Cast<DataGridViewRow>() |
943 | .Cast<DataGridViewRow>() |
|
969 | .FirstOrDefault(q => q.Cells["TopScriptsUUID"].Value.Equals(dataComponents[2])); |
944 | .FirstOrDefault(q => q.Cells["TopScriptsUUID"].Value.Equals(dataComponents[2])); |
|
970 | switch (row != null) |
945 | switch (row != null) |
|
Line 983... | Line 958... | |||
983 | } |
958 | } |
|
984 | } |
959 | } |
|
985 | })); |
960 | })); |
|
Line 986... | Line 961... | |||
986 | |
961 | |
|
987 | // Get the top colliders. |
962 | // Get the top colliders. |
|
988 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
963 | result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
989 | KeyValue.Escape(new Dictionary<string, string> |
964 | KeyValue.Escape(new Dictionary<string, string> |
|
990 | { |
965 | { |
|
991 | {"command", "getregiontop"}, |
966 | {"command", "getregiontop"}, |
|
992 | {"group", vassalConfiguration.Group}, |
967 | {"group", vassalConfiguration.Group}, |
|
993 | {"password", vassalConfiguration.Password}, |
968 | {"password", vassalConfiguration.Password}, |
|
994 | {"type", "colliders"} |
969 | {"type", "colliders"} |
|
Line 995... | Line 970... | |||
995 | }, wasOutput), vassalConfiguration.DataTimeout); |
970 | }, wasOutput)).Result); |
|
996 | |
971 | |
|
997 | if (string.IsNullOrEmpty(result) || |
972 | if (string.IsNullOrEmpty(result) || |
|
Line 1007... | Line 982... | |||
1007 | |
982 | |
|
1008 | vassalForm.Invoke((MethodInvoker) (() => |
983 | vassalForm.Invoke((MethodInvoker) (() => |
|
1009 | { |
984 | { |
|
1010 | // Remove rows that are not in the data update. |
985 | // Remove rows that are not in the data update. |
|
1011 | foreach ( |
986 | foreach ( |
|
1012 | int index in |
987 | var index in |
|
1013 | TopCollidersGridView.Rows.AsParallel().Cast<DataGridViewRow>() |
988 | TopCollidersGridView.Rows.AsParallel().Cast<DataGridViewRow>() |
|
1014 | .Where( |
989 | .Where( |
|
1015 | topCollidersRow => |
990 | topCollidersRow => |
|
1016 | !data.Any(q => q[2].Equals(topCollidersRow.Cells["TopCollidersUUID"].Value))) |
991 | !data.Any(q => q[2].Equals(topCollidersRow.Cells["TopCollidersUUID"].Value))) |
|
1017 | .Select(q => q.Index)) |
992 | .Select(q => q.Index)) |
|
1018 | { |
993 | { |
|
1019 | TopCollidersGridView.Rows.RemoveAt(index); |
994 | TopCollidersGridView.Rows.RemoveAt(index); |
|
1020 | } |
995 | } |
|
1021 | // Now update or add new data. |
996 | // Now update or add new data. |
|
1022 | foreach (List<string> dataComponents in data.Where(q => q.Count.Equals(5))) |
997 | foreach (var dataComponents in data.Where(q => q.Count.Equals(5))) |
|
1023 | { |
998 | { |
|
1024 | DataGridViewRow row = |
999 | var row = |
|
1025 | TopCollidersGridView.Rows.AsParallel() |
1000 | TopCollidersGridView.Rows.AsParallel() |
|
1026 | .Cast<DataGridViewRow>() |
1001 | .Cast<DataGridViewRow>() |
|
1027 | .FirstOrDefault(q => q.Cells["TopCollidersUUID"].Value.Equals(dataComponents[2])); |
1002 | .FirstOrDefault(q => q.Cells["TopCollidersUUID"].Value.Equals(dataComponents[2])); |
|
1028 | switch (row != null) |
1003 | switch (row != null) |
|
Line 1053... | Line 1028... | |||
1053 | |
1028 | |
|
1054 | // Start the resident list timer. |
1029 | // Start the resident list timer. |
|
1055 | residentListTabTimer.Elapsed += (o, p) => |
1030 | residentListTabTimer.Elapsed += (o, p) => |
|
1056 | { |
1031 | { |
|
1057 | // Do not do anything in case the tab is not selected. |
1032 | // Do not do anything in case the tab is not selected. |
|
1058 | bool run = false; |
1033 | var run = false; |
|
Line 1059... | Line 1034... | |||
1059 | vassalForm.Invoke((MethodInvoker) (() => { run = Tabs.SelectedTab.Equals(ResidentListTab); })); |
1034 | vassalForm.Invoke((MethodInvoker) (() => { run = Tabs.SelectedTab.Equals(ResidentListTab); })); |
|
1060 | |
1035 | |
|
1061 | if (!run) |
1036 | if (!run) |
|
Line 1067... | Line 1042... | |||
1067 | residentListTabTimer.Stop(); |
1042 | residentListTabTimer.Stop(); |
|
Line 1068... | Line 1043... | |||
1068 | |
1043 | |
|
1069 | try |
1044 | try |
|
1070 | { |
1045 | { |
|
1071 | // Get the avatar positions. |
1046 | // Get the avatar positions. |
|
1072 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
1047 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
1073 | KeyValue.Escape(new Dictionary<string, string> |
1048 | KeyValue.Escape(new Dictionary<string, string> |
|
1074 | { |
1049 | { |
|
1075 | {"command", "getavatarpositions"}, |
1050 | {"command", "getavatarpositions"}, |
|
1076 | {"group", vassalConfiguration.Group}, |
1051 | {"group", vassalConfiguration.Group}, |
|
1077 | {"password", vassalConfiguration.Password}, |
1052 | {"password", vassalConfiguration.Password}, |
|
1078 | {"entity", "region"} |
1053 | {"entity", "region"} |
|
Line 1079... | Line 1054... | |||
1079 | }, wasOutput), vassalConfiguration.DataTimeout); |
1054 | }, wasOutput)).Result); |
|
1080 | |
1055 | |
|
1081 | bool success; |
1056 | bool success; |
|
1082 | if (string.IsNullOrEmpty(result) || |
1057 | if (string.IsNullOrEmpty(result) || |
|
Line 1083... | Line 1058... | |||
1083 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
1058 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
1084 | throw new Exception(); |
1059 | throw new Exception(); |
|
1085 | |
1060 | |
|
1086 | HashSet<List<string>> data = |
1061 | var data = |
|
1087 | new HashSet<List<string>>(CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
1062 | new HashSet<List<string>>(CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
|
1088 | .Select((x, i) => new {Index = i, Value = x}) |
1063 | .Select((x, i) => new {Index = i, Value = x}) |
|
Line 1093... | Line 1068... | |||
1093 | |
1068 | |
|
1094 | vassalForm.Invoke((MethodInvoker) (() => |
1069 | vassalForm.Invoke((MethodInvoker) (() => |
|
1095 | { |
1070 | { |
|
1096 | // Remove rows that are not in the data update. |
1071 | // Remove rows that are not in the data update. |
|
1097 | foreach ( |
1072 | foreach ( |
|
1098 | int index in |
1073 | var index in |
|
1099 | ResidentListGridView.Rows.AsParallel().Cast<DataGridViewRow>() |
1074 | ResidentListGridView.Rows.AsParallel().Cast<DataGridViewRow>() |
|
1100 | .Where( |
1075 | .Where( |
|
1101 | residentListRow => |
1076 | residentListRow => |
|
1102 | !data.Any(q => q[1].Equals(residentListRow.Cells["ResidentListUUID"].Value))) |
1077 | !data.Any(q => q[1].Equals(residentListRow.Cells["ResidentListUUID"].Value))) |
|
1103 | .Select(q => q.Index)) |
1078 | .Select(q => q.Index)) |
|
1104 | { |
1079 | { |
|
1105 | ResidentListGridView.Rows.RemoveAt(index); |
1080 | ResidentListGridView.Rows.RemoveAt(index); |
|
1106 | } |
1081 | } |
|
1107 | // Now update or add new data. |
1082 | // Now update or add new data. |
|
1108 | foreach (List<string> dataComponents in data.Where(q => q.Count.Equals(3))) |
1083 | foreach (var dataComponents in data.Where(q => q.Count.Equals(3))) |
|
1109 | { |
1084 | { |
|
1110 | DataGridViewRow row = |
1085 | var row = |
|
1111 | ResidentListGridView.Rows.AsParallel() |
1086 | ResidentListGridView.Rows.AsParallel() |
|
1112 | .Cast<DataGridViewRow>() |
1087 | .Cast<DataGridViewRow>() |
|
1113 | .FirstOrDefault(q => q.Cells["ResidentListUUID"].Value.Equals(dataComponents[1])); |
1088 | .FirstOrDefault(q => q.Cells["ResidentListUUID"].Value.Equals(dataComponents[1])); |
|
1114 | switch (row != null) |
1089 | switch (row != null) |
|
Line 1135... | Line 1110... | |||
1135 | residentListTabTimer.Start(); |
1110 | residentListTabTimer.Start(); |
|
Line 1136... | Line 1111... | |||
1136 | |
1111 | |
|
1137 | estateTexturesTabTimer.Elapsed += (o, p) => |
1112 | estateTexturesTabTimer.Elapsed += (o, p) => |
|
1138 | { |
1113 | { |
|
1139 | // Do not do anything in case the tab is not selected. |
1114 | // Do not do anything in case the tab is not selected. |
|
1140 | bool run = false; |
1115 | var run = false; |
|
Line 1141... | Line 1116... | |||
1141 | vassalForm.Invoke((MethodInvoker) (() => { run = Tabs.SelectedTab.Equals(EstateTexturesTab); })); |
1116 | vassalForm.Invoke((MethodInvoker) (() => { run = Tabs.SelectedTab.Equals(EstateTexturesTab); })); |
|
1142 | |
1117 | |
|
1143 | if (!run) |
1118 | if (!run) |
|
Line 1149... | Line 1124... | |||
1149 | estateTexturesTabTimer.Stop(); |
1124 | estateTexturesTabTimer.Stop(); |
|
Line 1150... | Line 1125... | |||
1150 | |
1125 | |
|
1151 | try |
1126 | try |
|
1152 | { |
1127 | { |
|
1153 | // Get the region terrain texture UUIDs. |
1128 | // Get the region terrain texture UUIDs. |
|
1154 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
1129 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
1155 | KeyValue.Escape(new Dictionary<string, string> |
1130 | KeyValue.Escape(new Dictionary<string, string> |
|
1156 | { |
1131 | { |
|
1157 | {"command", "getregionterraintextures"}, |
1132 | {"command", "getregionterraintextures"}, |
|
1158 | {"group", vassalConfiguration.Group}, |
1133 | {"group", vassalConfiguration.Group}, |
|
1159 | {"password", vassalConfiguration.Password} |
1134 | {"password", vassalConfiguration.Password} |
|
Line 1160... | Line 1135... | |||
1160 | }, wasOutput), vassalConfiguration.DataTimeout); |
1135 | }, wasOutput)).Result); |
|
1161 | |
1136 | |
|
1162 | bool success; |
1137 | bool success; |
|
1163 | if (string.IsNullOrEmpty(result) || |
1138 | if (string.IsNullOrEmpty(result) || |
|
Line 1164... | Line 1139... | |||
1164 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
1139 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
1165 | throw new Exception(); |
1140 | throw new Exception(); |
|
1166 | |
1141 | |
|
Line 1167... | Line 1142... | |||
1167 | List<string> data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
1142 | var data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
|
1168 | if (!data.Count.Equals(4)) |
1143 | if (!data.Count.Equals(4)) |
|
Line 1192... | Line 1167... | |||
1192 | } |
1167 | } |
|
1193 | })); |
1168 | })); |
|
Line 1194... | Line 1169... | |||
1194 | |
1169 | |
|
1195 | Parallel.ForEach(Enumerable.Range(0, 4), i => |
1170 | Parallel.ForEach(Enumerable.Range(0, 4), i => |
|
1196 | { |
1171 | { |
|
1197 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
1172 | result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
1198 | KeyValue.Escape(new Dictionary<string, string> |
1173 | KeyValue.Escape(new Dictionary<string, string> |
|
1199 | { |
1174 | { |
|
1200 | {"command", "download"}, |
1175 | {"command", "download"}, |
|
1201 | {"group", vassalConfiguration.Group}, |
1176 | {"group", vassalConfiguration.Group}, |
|
1202 | {"password", vassalConfiguration.Password}, |
1177 | {"password", vassalConfiguration.Password}, |
|
1203 | {"item", data[i]}, |
1178 | {"item", data[i]}, |
|
1204 | {"type", "Texture"}, |
1179 | {"type", "Texture"}, |
|
1205 | {"format", "Jpeg"} |
1180 | {"format", "Jpeg"} |
|
Line 1206... | Line 1181... | |||
1206 | }, wasOutput), vassalConfiguration.DataTimeout); |
1181 | }, wasOutput)).Result); |
|
1207 | |
1182 | |
|
1208 | if (string.IsNullOrEmpty(result) || |
1183 | if (string.IsNullOrEmpty(result) || |
|
Line 1209... | Line 1184... | |||
1209 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
1184 | !bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
1210 | return; |
1185 | return; |
|
1211 | |
1186 | |
|
1212 | byte[] mapImageBytes = Convert.FromBase64String(wasInput(KeyValue.Get("data", result))); |
1187 | var mapImageBytes = Convert.FromBase64String(wasInput(KeyValue.Get("data", result))); |
|
1213 | using (MemoryStream memoryStream = new MemoryStream(mapImageBytes, 0, mapImageBytes.Length)) |
1188 | using (var memoryStream = new MemoryStream(mapImageBytes, 0, mapImageBytes.Length)) |
|
Line 1214... | Line 1189... | |||
1214 | { |
1189 | { |
|
Line 1253... | Line 1228... | |||
1253 | |
1228 | |
|
1254 | private void RequestedEditRegions(object sender, EventArgs e) |
1229 | private void RequestedEditRegions(object sender, EventArgs e) |
|
1255 | { |
1230 | { |
|
1256 | // Clear any selection. |
1231 | // Clear any selection. |
|
1257 | LoadedRegionsBox.SelectedIndex = -1; |
1232 | LoadedRegionsBox.SelectedIndex = -1; |
|
1258 | RegionEditForm regionEditForm = new RegionEditForm {TopMost = true}; |
1233 | var regionEditForm = new RegionEditForm {TopMost = true}; |
|
1259 | regionEditForm.Show(); |
1234 | regionEditForm.Show(); |
|
Line 1260... | Line 1235... | |||
1260 | } |
1235 | } |
|
1261 | |
1236 | |
|
Line 1269... | Line 1244... | |||
1269 | vassalForm.BeginInvoke((MethodInvoker) (() => |
1244 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
1270 | { |
1245 | { |
|
1271 | switch (vassalForm.ExportCSVDialog.ShowDialog()) |
1246 | switch (vassalForm.ExportCSVDialog.ShowDialog()) |
|
1272 | { |
1247 | { |
|
1273 | case DialogResult.OK: |
1248 | case DialogResult.OK: |
|
1274 | string file = vassalForm.ExportCSVDialog.FileName; |
1249 | var file = vassalForm.ExportCSVDialog.FileName; |
|
1275 | new Thread(() => |
1250 | new Thread(() => |
|
1276 | { |
1251 | { |
|
1277 | vassalForm.BeginInvoke((MethodInvoker) (() => |
1252 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
1278 | { |
1253 | { |
|
1279 | try |
1254 | try |
|
1280 | { |
1255 | { |
|
1281 | vassalForm.StatusText.Text = @"exporting..."; |
1256 | vassalForm.StatusText.Text = @"exporting..."; |
|
1282 | vassalForm.StatusProgress.Value = 0; |
1257 | vassalForm.StatusProgress.Value = 0; |
|
Line 1283... | Line 1258... | |||
1283 | |
1258 | |
|
1284 | using (StreamWriter streamWriter = new StreamWriter(file, false, Encoding.UTF8)) |
1259 | using (var streamWriter = new StreamWriter(file, false, Encoding.UTF8)) |
|
1285 | { |
1260 | { |
|
1286 | foreach (DataGridViewRow topScriptsRow in TopScriptsGridView.Rows) |
1261 | foreach (DataGridViewRow topScriptsRow in TopScriptsGridView.Rows) |
|
1287 | { |
1262 | { |
|
1288 | streamWriter.WriteLine(CSV.FromEnumerable(new[] |
1263 | streamWriter.WriteLine(CSV.FromEnumerable(new[] |
|
Line 1316... | Line 1291... | |||
1316 | vassalForm.BeginInvoke((MethodInvoker) (() => |
1291 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
1317 | { |
1292 | { |
|
1318 | switch (vassalForm.ExportCSVDialog.ShowDialog()) |
1293 | switch (vassalForm.ExportCSVDialog.ShowDialog()) |
|
1319 | { |
1294 | { |
|
1320 | case DialogResult.OK: |
1295 | case DialogResult.OK: |
|
1321 | string file = vassalForm.ExportCSVDialog.FileName; |
1296 | var file = vassalForm.ExportCSVDialog.FileName; |
|
1322 | new Thread(() => |
1297 | new Thread(() => |
|
1323 | { |
1298 | { |
|
1324 | vassalForm.BeginInvoke((MethodInvoker) (() => |
1299 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
1325 | { |
1300 | { |
|
1326 | try |
1301 | try |
|
1327 | { |
1302 | { |
|
1328 | vassalForm.StatusText.Text = @"exporting..."; |
1303 | vassalForm.StatusText.Text = @"exporting..."; |
|
1329 | vassalForm.StatusProgress.Value = 0; |
1304 | vassalForm.StatusProgress.Value = 0; |
|
Line 1330... | Line 1305... | |||
1330 | |
1305 | |
|
1331 | using (StreamWriter streamWriter = new StreamWriter(file, false, Encoding.UTF8)) |
1306 | using (var streamWriter = new StreamWriter(file, false, Encoding.UTF8)) |
|
1332 | { |
1307 | { |
|
1333 | foreach (DataGridViewRow topCollidersRow in TopCollidersGridView.Rows) |
1308 | foreach (DataGridViewRow topCollidersRow in TopCollidersGridView.Rows) |
|
1334 | { |
1309 | { |
|
1335 | streamWriter.WriteLine(CSV.FromEnumerable(new[] |
1310 | streamWriter.WriteLine(CSV.FromEnumerable(new[] |
|
Line 1370... | Line 1345... | |||
1370 | break; |
1345 | break; |
|
1371 | default: |
1346 | default: |
|
1372 | topScriptsRowRegex = new Regex(@".+?", RegexOptions.Compiled); |
1347 | topScriptsRowRegex = new Regex(@".+?", RegexOptions.Compiled); |
|
1373 | break; |
1348 | break; |
|
1374 | } |
1349 | } |
|
1375 | foreach (DataGridViewRow topScriptsRow in TopScriptsGridView.Rows.AsParallel().Cast<DataGridViewRow>()) |
1350 | foreach (var topScriptsRow in TopScriptsGridView.Rows.AsParallel().Cast<DataGridViewRow>()) |
|
1376 | { |
1351 | { |
|
1377 | topScriptsRow.Visible = |
1352 | topScriptsRow.Visible = |
|
1378 | topScriptsRowRegex.IsMatch(topScriptsRow.Cells["TopScriptsScore"].Value.ToString()) || |
1353 | topScriptsRowRegex.IsMatch(topScriptsRow.Cells["TopScriptsScore"].Value.ToString()) || |
|
1379 | topScriptsRowRegex.IsMatch( |
1354 | topScriptsRowRegex.IsMatch( |
|
1380 | topScriptsRow.Cells["TopScriptsTaskName"].Value.ToString()) || |
1355 | topScriptsRow.Cells["TopScriptsTaskName"].Value.ToString()) || |
|
Line 1399... | Line 1374... | |||
1399 | default: |
1374 | default: |
|
1400 | topCollidersRowRegex = new Regex(@".+?", RegexOptions.Compiled); |
1375 | topCollidersRowRegex = new Regex(@".+?", RegexOptions.Compiled); |
|
1401 | break; |
1376 | break; |
|
1402 | } |
1377 | } |
|
1403 | foreach ( |
1378 | foreach ( |
|
1404 | DataGridViewRow topCollidersRow in TopCollidersGridView.Rows.AsParallel().Cast<DataGridViewRow>()) |
1379 | var topCollidersRow in TopCollidersGridView.Rows.AsParallel().Cast<DataGridViewRow>()) |
|
1405 | { |
1380 | { |
|
1406 | topCollidersRow.Visible = |
1381 | topCollidersRow.Visible = |
|
1407 | topCollidersRowRegex.IsMatch(topCollidersRow.Cells["TopCollidersScore"].Value.ToString()) || |
1382 | topCollidersRowRegex.IsMatch(topCollidersRow.Cells["TopCollidersScore"].Value.ToString()) || |
|
1408 | topCollidersRowRegex.IsMatch( |
1383 | topCollidersRowRegex.IsMatch( |
|
1409 | topCollidersRow.Cells["TopCollidersTaskName"].Value.ToString()) || |
1384 | topCollidersRow.Cells["TopCollidersTaskName"].Value.ToString()) || |
|
Line 1423... | Line 1398... | |||
1423 | vassalForm.ReturnTopScriptsButton.Enabled = false; |
1398 | vassalForm.ReturnTopScriptsButton.Enabled = false; |
|
1424 | RegionTeleportGroup.Enabled = false; |
1399 | RegionTeleportGroup.Enabled = false; |
|
1425 | })); |
1400 | })); |
|
Line 1426... | Line 1401... | |||
1426 | |
1401 | |
|
1427 | // Enqueue all the UUIDs to return. |
1402 | // Enqueue all the UUIDs to return. |
|
1428 | Queue<KeyValuePair<UUID, Vector3>> returnUUIDs = new Queue<KeyValuePair<UUID, Vector3>>(); |
1403 | var returnUUIDs = new Queue<KeyValuePair<UUID, Vector3>>(); |
|
1429 | vassalForm.Invoke((MethodInvoker) (() => |
1404 | vassalForm.Invoke((MethodInvoker) (() => |
|
1430 | { |
1405 | { |
|
1431 | foreach ( |
1406 | foreach ( |
|
1432 | DataGridViewRow topScriptsRow in |
1407 | var topScriptsRow in |
|
1433 | TopScriptsGridView.Rows.AsParallel() |
1408 | TopScriptsGridView.Rows.AsParallel() |
|
1434 | .Cast<DataGridViewRow>() |
1409 | .Cast<DataGridViewRow>() |
|
1435 | .Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
1410 | .Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
|
1436 | { |
1411 | { |
|
Line 1459... | Line 1434... | |||
1459 | Monitor.Enter(ClientInstanceTeleportLock); |
1434 | Monitor.Enter(ClientInstanceTeleportLock); |
|
Line 1460... | Line 1435... | |||
1460 | |
1435 | |
|
1461 | try |
1436 | try |
|
1462 | { |
1437 | { |
|
1463 | vassalForm.Invoke((MethodInvoker) (() => { vassalForm.StatusProgress.Value = 0; })); |
1438 | vassalForm.Invoke((MethodInvoker) (() => { vassalForm.StatusProgress.Value = 0; })); |
|
1464 | int totalObjects = returnUUIDs.Count; |
1439 | var totalObjects = returnUUIDs.Count; |
|
1465 | do |
1440 | do |
|
1466 | { |
1441 | { |
|
1467 | // Dequeue the first object. |
1442 | // Dequeue the first object. |
|
Line 1468... | Line 1443... | |||
1468 | KeyValuePair<UUID, Vector3> objectData = returnUUIDs.Dequeue(); |
1443 | var objectData = returnUUIDs.Dequeue(); |
|
1469 | |
1444 | |
|
1470 | vassalForm.Invoke( |
1445 | vassalForm.Invoke( |
|
Line 1471... | Line 1446... | |||
1471 | (MethodInvoker) |
1446 | (MethodInvoker) |
|
1472 | (() => { vassalForm.StatusText.Text = @"Returning object UUID: " + objectData.Key; })); |
1447 | (() => { vassalForm.StatusText.Text = @"Returning object UUID: " + objectData.Key; })); |
|
Line 1473... | Line 1448... | |||
1473 | |
1448 | |
|
1474 | string currentRegionName = string.Empty; |
1449 | var currentRegionName = string.Empty; |
|
1475 | vassalForm.Invoke((MethodInvoker) (() => { currentRegionName = CurrentRegionName.Text; })); |
1450 | vassalForm.Invoke((MethodInvoker) (() => { currentRegionName = CurrentRegionName.Text; })); |
|
1476 | |
1451 | |
|
1477 | // Teleport to the object. |
1452 | // Teleport to the object. |
|
1478 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
1453 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
1479 | KeyValue.Escape(new Dictionary<string, string> |
1454 | KeyValue.Escape(new Dictionary<string, string> |
|
1480 | { |
1455 | { |
|
1481 | {"command", "teleport"}, |
1456 | {"command", "teleport"}, |
|
1482 | {"group", vassalConfiguration.Group}, |
1457 | {"group", vassalConfiguration.Group}, |
|
1483 | {"password", vassalConfiguration.Password}, |
1458 | {"password", vassalConfiguration.Password}, |
|
Line 1484... | Line 1459... | |||
1484 | {"position", objectData.Value.ToString()}, |
1459 | {"position", objectData.Value.ToString()}, |
|
1485 | {"region", currentRegionName}, |
1460 | {"region", currentRegionName}, |
|
1486 | {"fly", "True"} |
1461 | {"fly", "True"} |
|
1487 | }, wasOutput), vassalConfiguration.TeleportTimeout); |
1462 | }, wasOutput)).Result); |
|
1488 | |
1463 | |
|
1489 | if (string.IsNullOrEmpty(result)) |
1464 | if (string.IsNullOrEmpty(result)) |
|
1490 | { |
1465 | { |
|
Line 1491... | Line 1466... | |||
1491 | vassalForm.Invoke( |
1466 | vassalForm.Invoke( |
|
1492 | (MethodInvoker) |
1467 | (MethodInvoker) |
|
1493 | (() => { vassalForm.StatusText.Text = @"Error communicating with Corrade."; })); |
1468 | (() => { vassalForm.StatusText.Text = @"Error communicating with Corrade."; })); |
|
1494 | continue; |
1469 | continue; |
|
1495 | } |
1470 | } |
|
1496 | |
1471 | |
|
1497 | // Return the object. |
1472 | // Return the object. |
|
1498 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
1473 | result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
1499 | KeyValue.Escape(new Dictionary<string, string> |
1474 | KeyValue.Escape(new Dictionary<string, string> |
|
1500 | { |
1475 | { |
|
1501 | {"command", "derez"}, |
1476 | {"command", "derez"}, |
|
Line 1502... | Line 1477... | |||
1502 | {"group", vassalConfiguration.Group}, |
1477 | {"group", vassalConfiguration.Group}, |
|
1503 | {"password", vassalConfiguration.Password}, |
1478 | {"password", vassalConfiguration.Password}, |
|
1504 | {"item", objectData.Key.ToString()}, |
1479 | {"item", objectData.Key.ToString()}, |
|
1505 | {"range", "32"}, // maximal prim size = 64 - middle bounding box at half |
1480 | {"range", "32"}, // maximal prim size = 64 - middle bounding box at half |
|
Line 1528... | Line 1503... | |||
1528 | case true: |
1503 | case true: |
|
1529 | vassalForm.Invoke((MethodInvoker) (() => |
1504 | vassalForm.Invoke((MethodInvoker) (() => |
|
1530 | { |
1505 | { |
|
1531 | vassalForm.StatusText.Text = @"Returned object: " + objectData.Key; |
1506 | vassalForm.StatusText.Text = @"Returned object: " + objectData.Key; |
|
1532 | // Remove the row from the grid view. |
1507 | // Remove the row from the grid view. |
|
1533 | DataGridViewRow row = |
1508 | var row = |
|
1534 | TopScriptsGridView.Rows.AsParallel() |
1509 | TopScriptsGridView.Rows.AsParallel() |
|
1535 | .Cast<DataGridViewRow>() |
1510 | .Cast<DataGridViewRow>() |
|
1536 | .FirstOrDefault( |
1511 | .FirstOrDefault( |
|
1537 | o => o.Cells["TopScriptsUUID"].Value.Equals(objectData.Key.ToString())); |
1512 | o => o.Cells["TopScriptsUUID"].Value.Equals(objectData.Key.ToString())); |
|
1538 | if (row == null) return; |
1513 | if (row == null) return; |
|
1539 | int i = row.Index; |
1514 | var i = row.Index; |
|
1540 | TopScriptsGridView.Rows.RemoveAt(i); |
1515 | TopScriptsGridView.Rows.RemoveAt(i); |
|
1541 | })); |
1516 | })); |
|
1542 | break; |
1517 | break; |
|
1543 | case false: |
1518 | case false: |
|
1544 | vassalForm.Invoke((MethodInvoker) (() => |
1519 | vassalForm.Invoke((MethodInvoker) (() => |
|
Line 1584... | Line 1559... | |||
1584 | vassalForm.ReturnTopCollidersButton.Enabled = false; |
1559 | vassalForm.ReturnTopCollidersButton.Enabled = false; |
|
1585 | RegionTeleportGroup.Enabled = false; |
1560 | RegionTeleportGroup.Enabled = false; |
|
1586 | })); |
1561 | })); |
|
Line 1587... | Line 1562... | |||
1587 | |
1562 | |
|
1588 | // Enqueue all the UUIDs to return. |
1563 | // Enqueue all the UUIDs to return. |
|
1589 | Queue<KeyValuePair<UUID, Vector3>> returnObjectUUIDQueue = new Queue<KeyValuePair<UUID, Vector3>>(); |
1564 | var returnObjectUUIDQueue = new Queue<KeyValuePair<UUID, Vector3>>(); |
|
1590 | vassalForm.Invoke((MethodInvoker) (() => |
1565 | vassalForm.Invoke((MethodInvoker) (() => |
|
1591 | { |
1566 | { |
|
1592 | foreach ( |
1567 | foreach ( |
|
1593 | DataGridViewRow topCollidersRow in |
1568 | var topCollidersRow in |
|
1594 | TopCollidersGridView.Rows.AsParallel() |
1569 | TopCollidersGridView.Rows.AsParallel() |
|
1595 | .Cast<DataGridViewRow>() |
1570 | .Cast<DataGridViewRow>() |
|
1596 | .Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
1571 | .Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
|
1597 | { |
1572 | { |
|
Line 1621... | Line 1596... | |||
1621 | Monitor.Enter(ClientInstanceTeleportLock); |
1596 | Monitor.Enter(ClientInstanceTeleportLock); |
|
Line 1622... | Line 1597... | |||
1622 | |
1597 | |
|
1623 | try |
1598 | try |
|
1624 | { |
1599 | { |
|
1625 | vassalForm.Invoke((MethodInvoker) (() => { vassalForm.StatusProgress.Value = 0; })); |
1600 | vassalForm.Invoke((MethodInvoker) (() => { vassalForm.StatusProgress.Value = 0; })); |
|
1626 | int totalObjects = returnObjectUUIDQueue.Count; |
1601 | var totalObjects = returnObjectUUIDQueue.Count; |
|
1627 | do |
1602 | do |
|
1628 | { |
1603 | { |
|
1629 | // Dequeue the first object. |
1604 | // Dequeue the first object. |
|
Line 1630... | Line 1605... | |||
1630 | KeyValuePair<UUID, Vector3> objectData = returnObjectUUIDQueue.Dequeue(); |
1605 | var objectData = returnObjectUUIDQueue.Dequeue(); |
|
1631 | |
1606 | |
|
1632 | vassalForm.Invoke( |
1607 | vassalForm.Invoke( |
|
Line 1633... | Line 1608... | |||
1633 | (MethodInvoker) |
1608 | (MethodInvoker) |
|
1634 | (() => { vassalForm.StatusText.Text = @"Returning UUID: " + objectData.Key; })); |
1609 | (() => { vassalForm.StatusText.Text = @"Returning UUID: " + objectData.Key; })); |
|
Line 1635... | Line 1610... | |||
1635 | |
1610 | |
|
1636 | string currentRegionName = string.Empty; |
1611 | var currentRegionName = string.Empty; |
|
1637 | vassalForm.Invoke((MethodInvoker) (() => { currentRegionName = CurrentRegionName.Text; })); |
1612 | vassalForm.Invoke((MethodInvoker) (() => { currentRegionName = CurrentRegionName.Text; })); |
|
1638 | |
1613 | |
|
1639 | // Teleport to the object. |
1614 | // Teleport to the object. |
|
1640 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
1615 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
1641 | KeyValue.Escape(new Dictionary<string, string> |
1616 | KeyValue.Escape(new Dictionary<string, string> |
|
1642 | { |
1617 | { |
|
1643 | {"command", "teleport"}, |
1618 | {"command", "teleport"}, |
|
1644 | {"group", vassalConfiguration.Group}, |
1619 | {"group", vassalConfiguration.Group}, |
|
1645 | {"password", vassalConfiguration.Password}, |
1620 | {"password", vassalConfiguration.Password}, |
|
Line 1646... | Line 1621... | |||
1646 | {"position", objectData.Value.ToString()}, |
1621 | {"position", objectData.Value.ToString()}, |
|
1647 | {"region", currentRegionName}, |
1622 | {"region", currentRegionName}, |
|
1648 | {"fly", "True"} |
1623 | {"fly", "True"} |
|
1649 | }, wasOutput), vassalConfiguration.DataTimeout); |
1624 | }, wasOutput)).Result); |
|
1650 | |
1625 | |
|
1651 | if (string.IsNullOrEmpty(result)) |
1626 | if (string.IsNullOrEmpty(result)) |
|
1652 | { |
1627 | { |
|
Line 1653... | Line 1628... | |||
1653 | vassalForm.Invoke( |
1628 | vassalForm.Invoke( |
|
1654 | (MethodInvoker) |
1629 | (MethodInvoker) |
|
1655 | (() => { vassalForm.StatusText.Text = @"Error communicating with Corrade."; })); |
1630 | (() => { vassalForm.StatusText.Text = @"Error communicating with Corrade."; })); |
|
1656 | continue; |
1631 | continue; |
|
1657 | } |
1632 | } |
|
1658 | |
1633 | |
|
1659 | // Return the object. |
1634 | // Return the object. |
|
1660 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
1635 | result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
1661 | KeyValue.Escape(new Dictionary<string, string> |
1636 | KeyValue.Escape(new Dictionary<string, string> |
|
1662 | { |
1637 | { |
|
1663 | {"command", "derez"}, |
1638 | {"command", "derez"}, |
|
Line 1664... | Line 1639... | |||
1664 | {"group", vassalConfiguration.Group}, |
1639 | {"group", vassalConfiguration.Group}, |
|
1665 | {"password", vassalConfiguration.Password}, |
1640 | {"password", vassalConfiguration.Password}, |
|
1666 | {"item", objectData.Key.ToString()}, |
1641 | {"item", objectData.Key.ToString()}, |
|
1667 | {"range", "32"}, // maximal prim size = 64 - middle bounding box at half |
1642 | {"range", "32"}, // maximal prim size = 64 - middle bounding box at half |
|
Line 1690... | Line 1665... | |||
1690 | case true: |
1665 | case true: |
|
1691 | vassalForm.Invoke((MethodInvoker) (() => |
1666 | vassalForm.Invoke((MethodInvoker) (() => |
|
1692 | { |
1667 | { |
|
1693 | vassalForm.StatusText.Text = @"Returned object: " + objectData.Key; |
1668 | vassalForm.StatusText.Text = @"Returned object: " + objectData.Key; |
|
1694 | // Remove the row from the grid view. |
1669 | // Remove the row from the grid view. |
|
1695 | DataGridViewRow row = |
1670 | var row = |
|
1696 | TopCollidersGridView.Rows.AsParallel() |
1671 | TopCollidersGridView.Rows.AsParallel() |
|
1697 | .Cast<DataGridViewRow>() |
1672 | .Cast<DataGridViewRow>() |
|
1698 | .FirstOrDefault( |
1673 | .FirstOrDefault( |
|
1699 | o => o.Cells["TopCollidersUUID"].Value.Equals(objectData.Key.ToString())); |
1674 | o => o.Cells["TopCollidersUUID"].Value.Equals(objectData.Key.ToString())); |
|
1700 | if (row == null) return; |
1675 | if (row == null) return; |
|
1701 | int i = row.Index; |
1676 | var i = row.Index; |
|
1702 | TopCollidersGridView.Rows.RemoveAt(i); |
1677 | TopCollidersGridView.Rows.RemoveAt(i); |
|
1703 | })); |
1678 | })); |
|
1704 | break; |
1679 | break; |
|
1705 | case false: |
1680 | case false: |
|
1706 | vassalForm.Invoke((MethodInvoker) (() => |
1681 | vassalForm.Invoke((MethodInvoker) (() => |
|
Line 1743... | Line 1718... | |||
1743 | { |
1718 | { |
|
1744 | // Block teleports and disable button. |
1719 | // Block teleports and disable button. |
|
1745 | vassalForm.Invoke((MethodInvoker) (() => |
1720 | vassalForm.Invoke((MethodInvoker) (() => |
|
1746 | { |
1721 | { |
|
1747 | vassalForm.BatchRestartButton.Enabled = false; |
1722 | vassalForm.BatchRestartButton.Enabled = false; |
|
- | 1723 | vassalForm.RegionRestartDelayBox.Enabled = false; |
||
1748 | RegionTeleportGroup.Enabled = false; |
1724 | RegionTeleportGroup.Enabled = false; |
|
1749 | })); |
1725 | })); |
|
Line 1750... | Line 1726... | |||
1750 | |
1726 | |
|
1751 | // Enqueue all the regions to restart. |
1727 | // Enqueue all the regions to restart. |
|
1752 | Queue<KeyValuePair<string, Vector3>> restartRegionQueue = new Queue<KeyValuePair<string, Vector3>>(); |
1728 | var restartRegionQueue = new Queue<KeyValuePair<string, Vector3>>(); |
|
1753 | vassalForm.Invoke((MethodInvoker) (() => |
1729 | vassalForm.Invoke((MethodInvoker) (() => |
|
1754 | { |
1730 | { |
|
1755 | foreach ( |
1731 | foreach ( |
|
1756 | DataGridViewRow topCollidersRow in |
1732 | var topCollidersRow in |
|
1757 | BatchRestartGridView.Rows.AsParallel() |
1733 | BatchRestartGridView.Rows.AsParallel() |
|
1758 | .Cast<DataGridViewRow>() |
1734 | .Cast<DataGridViewRow>() |
|
1759 | .Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
1735 | .Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
|
1760 | { |
1736 | { |
|
1761 | Vector3 objectPosition; |
1737 | Vector3 objectPosition; |
|
1762 | string regionName = topCollidersRow.Cells["BatchRestartRegionName"].Value.ToString(); |
1738 | var regionName = topCollidersRow.Cells["BatchRestartRegionName"].Value.ToString(); |
|
1763 | if (string.IsNullOrEmpty(regionName) || |
1739 | if (string.IsNullOrEmpty(regionName) || |
|
1764 | !Vector3.TryParse(topCollidersRow.Cells["BatchRestartPosition"].Value.ToString(), |
1740 | !Vector3.TryParse(topCollidersRow.Cells["BatchRestartPosition"].Value.ToString(), |
|
1765 | out objectPosition)) |
1741 | out objectPosition)) |
|
1766 | continue; |
1742 | continue; |
|
Line 1772... | Line 1748... | |||
1772 | if (restartRegionQueue.Count.Equals(0)) |
1748 | if (restartRegionQueue.Count.Equals(0)) |
|
1773 | { |
1749 | { |
|
1774 | vassalForm.Invoke((MethodInvoker) (() => |
1750 | vassalForm.Invoke((MethodInvoker) (() => |
|
1775 | { |
1751 | { |
|
1776 | vassalForm.BatchRestartButton.Enabled = true; |
1752 | vassalForm.BatchRestartButton.Enabled = true; |
|
- | 1753 | vassalForm.RegionRestartDelayBox.Enabled = true; |
||
1777 | RegionTeleportGroup.Enabled = true; |
1754 | RegionTeleportGroup.Enabled = true; |
|
1778 | })); |
1755 | })); |
|
1779 | return; |
1756 | return; |
|
1780 | } |
1757 | } |
|
Line 1786... | Line 1763... | |||
1786 | try |
1763 | try |
|
1787 | { |
1764 | { |
|
1788 | do |
1765 | do |
|
1789 | { |
1766 | { |
|
1790 | // Dequeue the first object. |
1767 | // Dequeue the first object. |
|
1791 | KeyValuePair<string, Vector3> restartRegionData = restartRegionQueue.Dequeue(); |
1768 | var restartRegionData = restartRegionQueue.Dequeue(); |
|
1792 | DataGridViewRow currentDataGridViewRow = null; |
1769 | DataGridViewRow currentDataGridViewRow = null; |
|
1793 | vassalForm.Invoke((MethodInvoker) (() => |
1770 | vassalForm.Invoke((MethodInvoker) (() => |
|
1794 | { |
1771 | { |
|
1795 | currentDataGridViewRow = vassalForm.BatchRestartGridView.Rows.AsParallel() |
1772 | currentDataGridViewRow = vassalForm.BatchRestartGridView.Rows.AsParallel() |
|
1796 | .Cast<DataGridViewRow>() |
1773 | .Cast<DataGridViewRow>() |
|
Line 1805... | Line 1782... | |||
1805 | |
1782 | |
|
Line 1806... | Line 1783... | |||
1806 | if (currentDataGridViewRow == null) continue; |
1783 | if (currentDataGridViewRow == null) continue; |
|
1807 | |
1784 | |
|
1808 | try |
1785 | try |
|
1809 | { |
1786 | { |
|
Line 1810... | Line 1787... | |||
1810 | bool success = false; |
1787 | var success = false; |
|
1811 | string result; |
1788 | string result; |
|
1812 | |
1789 | |
|
1813 | // Retry to teleport to each region a few times. |
1790 | // Retry to teleport to each region a few times. |
|
1814 | int teleportRetries = 3; |
1791 | var teleportRetries = 3; |
|
1815 | do |
1792 | do |
|
1816 | { |
1793 | { |
|
Line 1821... | Line 1798... | |||
1821 | teleportRetries.ToString(Utils.EnUsCulture) + |
1798 | teleportRetries.ToString(Utils.EnUsCulture) + |
|
1822 | @")"; |
1799 | @")"; |
|
1823 | })); |
1800 | })); |
|
Line 1824... | Line 1801... | |||
1824 | |
1801 | |
|
1825 | // Teleport to the region. |
1802 | // Teleport to the region. |
|
1826 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
1803 | result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
1827 | KeyValue.Escape(new Dictionary<string, string> |
1804 | KeyValue.Escape(new Dictionary<string, string> |
|
1828 | { |
1805 | { |
|
1829 | {"command", "teleport"}, |
1806 | {"command", "teleport"}, |
|
1830 | {"group", vassalConfiguration.Group}, |
1807 | {"group", vassalConfiguration.Group}, |
|
1831 | {"password", vassalConfiguration.Password}, |
1808 | {"password", vassalConfiguration.Password}, |
|
1832 | {"position", restartRegionData.Value.ToString()}, |
1809 | {"position", restartRegionData.Value.ToString()}, |
|
1833 | {"region", restartRegionData.Key}, |
1810 | {"region", restartRegionData.Key}, |
|
1834 | {"fly", "True"} |
1811 | {"fly", "True"} |
|
Line 1835... | Line 1812... | |||
1835 | }, wasOutput), vassalConfiguration.DataTimeout); |
1812 | }, wasOutput)).Result); |
|
1836 | |
1813 | |
|
1837 | if (string.IsNullOrEmpty(result)) |
1814 | if (string.IsNullOrEmpty(result)) |
|
1838 | { |
1815 | { |
|
Line 1886... | Line 1863... | |||
1886 | } while (!success && !(--teleportRetries).Equals(0)); |
1863 | } while (!success && !(--teleportRetries).Equals(0)); |
|
Line 1887... | Line 1864... | |||
1887 | |
1864 | |
|
1888 | if (!success) |
1865 | if (!success) |
|
Line 1889... | Line 1866... | |||
1889 | throw new Exception("Failed to teleport to region."); |
1866 | throw new Exception("Failed to teleport to region."); |
|
1890 | |
1867 | |
|
1891 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
1868 | result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
1892 | KeyValue.Escape(new Dictionary<string, string> |
1869 | KeyValue.Escape(new Dictionary<string, string> |
|
1893 | { |
1870 | { |
|
1894 | {"command", "getregiondata"}, |
1871 | {"command", "getregiondata"}, |
|
1895 | {"group", vassalConfiguration.Group}, |
1872 | {"group", vassalConfiguration.Group}, |
|
1896 | {"password", vassalConfiguration.Password}, |
1873 | {"password", vassalConfiguration.Password}, |
|
Line 1897... | Line 1874... | |||
1897 | {"data", "IsEstateManager"} |
1874 | {"data", "IsEstateManager"} |
|
1898 | }, wasOutput), vassalConfiguration.DataTimeout); |
1875 | }, wasOutput)).Result); |
|
Line 1899... | Line 1876... | |||
1899 | |
1876 | |
|
1900 | if (string.IsNullOrEmpty(result)) |
1877 | if (string.IsNullOrEmpty(result)) |
|
Line 1901... | Line 1878... | |||
1901 | throw new Exception("Error communicating with Corrade."); |
1878 | throw new Exception("Error communicating with Corrade."); |
|
1902 | |
1879 | |
|
Line 1903... | Line 1880... | |||
1903 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
1880 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
1904 | throw new Exception("No success status could be retrieved."); |
1881 | throw new Exception("No success status could be retrieved."); |
|
1905 | |
1882 | |
|
Line 1906... | Line 1883... | |||
1906 | if (!success) |
1883 | if (!success) |
|
1907 | throw new Exception("Could not retrieve estate rights."); |
1884 | throw new Exception("Could not retrieve estate rights."); |
|
1908 | |
1885 | |
|
1909 | List<string> data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
1886 | var data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
|
1910 | if (!data.Count.Equals(2)) |
1887 | if (!data.Count.Equals(2)) |
|
1911 | throw new Exception("Could not retrieve estate rights."); |
1888 | throw new Exception("Could not retrieve estate rights."); |
|
1912 | |
1889 | |
|
1913 | bool isEstateManager; |
1890 | bool isEstateManager; |
|
1914 | switch ( |
1891 | switch ( |
|
1915 | bool.TryParse(data[data.IndexOf("IsEstateManager") + 1], out isEstateManager) && |
1892 | bool.TryParse(data[data.IndexOf("IsEstateManager") + 1], out isEstateManager) && |
|
1916 | isEstateManager) |
1893 | isEstateManager) |
|
1917 | { |
1894 | { |
|
1918 | case true: // we are an estate manager |
1895 | case true: // we are an estate manager |
|
1919 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
1896 | result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
1920 | KeyValue.Escape(new Dictionary<string, string> |
1897 | KeyValue.Escape(new Dictionary<string, string> |
|
1921 | { |
1898 | { |
|
1922 | {"command", "restartregion"}, |
1899 | {"command", "restartregion"}, |
|
1923 | {"group", vassalConfiguration.Group}, |
1900 | {"group", vassalConfiguration.Group}, |
|
Line 1924... | Line 1901... | |||
1924 | {"password", vassalConfiguration.Password}, |
1901 | {"password", vassalConfiguration.Password}, |
|
1925 | {"action", "restart"}, |
1902 | {"action", "restart"}, |
|
Line 1926... | Line 1903... | |||
1926 | { |
1903 | { |
|
Line 1942... | Line 1919... | |||
1942 | { |
1919 | { |
|
1943 | vassalForm.StatusText.Text = @"Region scheduled for restart."; |
1920 | vassalForm.StatusText.Text = @"Region scheduled for restart."; |
|
1944 | currentDataGridViewRow.Selected = false; |
1921 | currentDataGridViewRow.Selected = false; |
|
1945 | currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightGreen; |
1922 | currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightGreen; |
|
1946 | foreach ( |
1923 | foreach ( |
|
1947 | DataGridViewCell cell in |
1924 | var cell in |
|
1948 | currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
1925 | currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
|
1949 | { |
1926 | { |
|
1950 | cell.ToolTipText = @"Region scheduled for restart."; |
1927 | cell.ToolTipText = @"Region scheduled for restart."; |
|
1951 | } |
1928 | } |
|
1952 | })); |
1929 | })); |
|
Line 1961... | Line 1938... | |||
1961 | { |
1938 | { |
|
1962 | vassalForm.StatusText.Text = ex.Message; |
1939 | vassalForm.StatusText.Text = ex.Message; |
|
1963 | currentDataGridViewRow.Selected = false; |
1940 | currentDataGridViewRow.Selected = false; |
|
1964 | currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightPink; |
1941 | currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightPink; |
|
1965 | foreach ( |
1942 | foreach ( |
|
1966 | DataGridViewCell cell in |
1943 | var cell in |
|
1967 | currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
1944 | currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
|
1968 | { |
1945 | { |
|
1969 | cell.ToolTipText = ex.Message; |
1946 | cell.ToolTipText = ex.Message; |
|
1970 | } |
1947 | } |
|
1971 | })); |
1948 | })); |
|
Line 1985... | Line 1962... | |||
1985 | Monitor.Exit(ClientInstanceTeleportLock); |
1962 | Monitor.Exit(ClientInstanceTeleportLock); |
|
1986 | // Allow teleports and enable button. |
1963 | // Allow teleports and enable button. |
|
1987 | vassalForm.BeginInvoke((MethodInvoker) (() => |
1964 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
1988 | { |
1965 | { |
|
1989 | vassalForm.BatchRestartButton.Enabled = true; |
1966 | vassalForm.BatchRestartButton.Enabled = true; |
|
- | 1967 | vassalForm.RegionRestartDelayBox.Enabled = true; |
||
1990 | RegionTeleportGroup.Enabled = true; |
1968 | RegionTeleportGroup.Enabled = true; |
|
1991 | })); |
1969 | })); |
|
1992 | } |
1970 | } |
|
1993 | }) |
1971 | }) |
|
1994 | {IsBackground = true}.Start(); |
1972 | {IsBackground = true}.Start(); |
|
Line 2007... | Line 1985... | |||
2007 | default: |
1985 | default: |
|
2008 | residentListRowRegex = new Regex(@".+?", RegexOptions.Compiled); |
1986 | residentListRowRegex = new Regex(@".+?", RegexOptions.Compiled); |
|
2009 | break; |
1987 | break; |
|
2010 | } |
1988 | } |
|
2011 | foreach ( |
1989 | foreach ( |
|
2012 | DataGridViewRow residentListRow in ResidentListGridView.Rows.AsParallel().Cast<DataGridViewRow>()) |
1990 | var residentListRow in ResidentListGridView.Rows.AsParallel().Cast<DataGridViewRow>()) |
|
2013 | { |
1991 | { |
|
2014 | residentListRow.Visible = |
1992 | residentListRow.Visible = |
|
2015 | residentListRowRegex.IsMatch(residentListRow.Cells["ResidentListName"].Value.ToString()) || |
1993 | residentListRowRegex.IsMatch(residentListRow.Cells["ResidentListName"].Value.ToString()) || |
|
2016 | residentListRowRegex.IsMatch( |
1994 | residentListRowRegex.IsMatch( |
|
2017 | residentListRow.Cells["ResidentListUUID"].Value.ToString()) || |
1995 | residentListRow.Cells["ResidentListUUID"].Value.ToString()) || |
|
Line 2029... | Line 2007... | |||
2029 | ResidentListBanGroup.Enabled = false; |
2007 | ResidentListBanGroup.Enabled = false; |
|
2030 | RegionTeleportGroup.Enabled = false; |
2008 | RegionTeleportGroup.Enabled = false; |
|
2031 | })); |
2009 | })); |
|
Line 2032... | Line 2010... | |||
2032 | |
2010 | |
|
2033 | // Enqueue all the agents to ban. |
2011 | // Enqueue all the agents to ban. |
|
2034 | Queue<UUID> agentsQueue = new Queue<UUID>(); |
2012 | var agentsQueue = new Queue<UUID>(); |
|
2035 | vassalForm.Invoke((MethodInvoker) (() => |
2013 | vassalForm.Invoke((MethodInvoker) (() => |
|
2036 | { |
2014 | { |
|
2037 | foreach ( |
2015 | foreach ( |
|
2038 | DataGridViewRow residentListRow in |
2016 | var residentListRow in |
|
2039 | ResidentListGridView.Rows.AsParallel() |
2017 | ResidentListGridView.Rows.AsParallel() |
|
2040 | .Cast<DataGridViewRow>() |
2018 | .Cast<DataGridViewRow>() |
|
2041 | .Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
2019 | .Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
|
2042 | { |
2020 | { |
|
Line 2064... | Line 2042... | |||
2064 | try |
2042 | try |
|
2065 | { |
2043 | { |
|
2066 | do |
2044 | do |
|
2067 | { |
2045 | { |
|
2068 | // Dequeue the first object. |
2046 | // Dequeue the first object. |
|
2069 | UUID agentUUID = agentsQueue.Dequeue(); |
2047 | var agentUUID = agentsQueue.Dequeue(); |
|
2070 | DataGridViewRow currentDataGridViewRow = null; |
2048 | DataGridViewRow currentDataGridViewRow = null; |
|
2071 | vassalForm.Invoke((MethodInvoker) (() => |
2049 | vassalForm.Invoke((MethodInvoker) (() => |
|
2072 | { |
2050 | { |
|
2073 | currentDataGridViewRow = vassalForm.ResidentListGridView.Rows.AsParallel() |
2051 | currentDataGridViewRow = vassalForm.ResidentListGridView.Rows.AsParallel() |
|
2074 | .Cast<DataGridViewRow>() |
2052 | .Cast<DataGridViewRow>() |
|
Line 2080... | Line 2058... | |||
2080 | |
2058 | |
|
Line 2081... | Line 2059... | |||
2081 | if (currentDataGridViewRow == null) continue; |
2059 | if (currentDataGridViewRow == null) continue; |
|
2082 | |
2060 | |
|
2083 | try |
2061 | try |
|
2084 | { |
2062 | { |
|
2085 | bool alsoBan = false; |
2063 | var alsoBan = false; |
|
Line 2086... | Line 2064... | |||
2086 | vassalForm.Invoke( |
2064 | vassalForm.Invoke( |
|
2087 | (MethodInvoker) (() => { alsoBan = vassalForm.ResidentBanAllEstatesBox.Checked; })); |
2065 | (MethodInvoker) (() => { alsoBan = vassalForm.ResidentBanAllEstatesBox.Checked; })); |
|
2088 | |
2066 | |
|
2089 | // Ban the resident. |
2067 | // Ban the resident. |
|
2090 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
2068 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
2091 | KeyValue.Escape(new Dictionary<string, string> |
2069 | KeyValue.Escape(new Dictionary<string, string> |
|
2092 | { |
2070 | { |
|
2093 | {"command", "setestatelist"}, |
2071 | {"command", "setestatelist"}, |
|
2094 | {"group", vassalConfiguration.Group}, |
2072 | {"group", vassalConfiguration.Group}, |
|
2095 | {"password", vassalConfiguration.Password}, |
2073 | {"password", vassalConfiguration.Password}, |
|
2096 | {"type", "ban"}, |
2074 | {"type", "ban"}, |
|
2097 | {"action", "add"}, |
2075 | {"action", "add"}, |
|
Line 2098... | Line 2076... | |||
2098 | {"agent", agentUUID.ToString()}, |
2076 | {"agent", agentUUID.ToString()}, |
|
2099 | {"all", alsoBan.ToString()} |
2077 | {"all", alsoBan.ToString()} |
|
Line 2100... | Line 2078... | |||
2100 | }, wasOutput), vassalConfiguration.DataTimeout); |
2078 | }, wasOutput)).Result); |
|
Line 2113... | Line 2091... | |||
2113 | { |
2091 | { |
|
2114 | vassalForm.StatusText.Text = @"Resident banned."; |
2092 | vassalForm.StatusText.Text = @"Resident banned."; |
|
2115 | currentDataGridViewRow.Selected = false; |
2093 | currentDataGridViewRow.Selected = false; |
|
2116 | currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightGreen; |
2094 | currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightGreen; |
|
2117 | foreach ( |
2095 | foreach ( |
|
2118 | DataGridViewCell cell in |
2096 | var cell in |
|
2119 | currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
2097 | currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
|
2120 | { |
2098 | { |
|
2121 | cell.ToolTipText = @"Resident banned."; |
2099 | cell.ToolTipText = @"Resident banned."; |
|
2122 | } |
2100 | } |
|
2123 | })); |
2101 | })); |
|
Line 2132... | Line 2110... | |||
2132 | { |
2110 | { |
|
2133 | vassalForm.StatusText.Text = ex.Message; |
2111 | vassalForm.StatusText.Text = ex.Message; |
|
2134 | currentDataGridViewRow.Selected = false; |
2112 | currentDataGridViewRow.Selected = false; |
|
2135 | currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightPink; |
2113 | currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightPink; |
|
2136 | foreach ( |
2114 | foreach ( |
|
2137 | DataGridViewCell cell in |
2115 | var cell in |
|
2138 | currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
2116 | currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
|
2139 | { |
2117 | { |
|
2140 | cell.ToolTipText = ex.Message; |
2118 | cell.ToolTipText = ex.Message; |
|
2141 | } |
2119 | } |
|
2142 | })); |
2120 | })); |
|
Line 2175... | Line 2153... | |||
2175 | Monitor.Enter(ClientInstanceTeleportLock); |
2153 | Monitor.Enter(ClientInstanceTeleportLock); |
|
Line 2176... | Line 2154... | |||
2176 | |
2154 | |
|
2177 | try |
2155 | try |
|
2178 | { |
2156 | { |
|
2179 | // Get the map heights. |
2157 | // Get the map heights. |
|
2180 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
2158 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
2181 | KeyValue.Escape(new Dictionary<string, string> |
2159 | KeyValue.Escape(new Dictionary<string, string> |
|
2182 | { |
2160 | { |
|
2183 | {"command", "getterrainheight"}, |
2161 | {"command", "getterrainheight"}, |
|
2184 | {"group", vassalConfiguration.Group}, |
2162 | {"group", vassalConfiguration.Group}, |
|
2185 | {"password", vassalConfiguration.Password}, |
2163 | {"password", vassalConfiguration.Password}, |
|
2186 | {"entity", "region"} |
2164 | {"entity", "region"} |
|
Line 2187... | Line 2165... | |||
2187 | }, wasOutput), vassalConfiguration.DataTimeout); |
2165 | }, wasOutput)).Result); |
|
2188 | |
2166 | |
|
Line 2189... | Line 2167... | |||
2189 | if (string.IsNullOrEmpty(result)) |
2167 | if (string.IsNullOrEmpty(result)) |
|
Line 2194... | Line 2172... | |||
2194 | throw new Exception("No success status could be retrieved."); |
2172 | throw new Exception("No success status could be retrieved."); |
|
Line 2195... | Line 2173... | |||
2195 | |
2173 | |
|
2196 | if (!success) |
2174 | if (!success) |
|
Line 2197... | Line 2175... | |||
2197 | throw new Exception("Could not get terrain heights."); |
2175 | throw new Exception("Could not get terrain heights."); |
|
2198 | |
2176 | |
|
2199 | List<double> heights = new List<double>(); |
2177 | var heights = new List<double>(); |
|
2200 | foreach (string map in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result)))) |
2178 | foreach (var map in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result)))) |
|
2201 | { |
2179 | { |
|
2202 | double height; |
2180 | double height; |
|
2203 | if (!double.TryParse(map, out height)) |
2181 | if (!double.TryParse(map, out height)) |
|
2204 | continue; |
2182 | continue; |
|
2205 | heights.Add(height); |
2183 | heights.Add(height); |
|
2206 | } |
2184 | } |
|
Line 2207... | Line 2185... | |||
2207 | if (heights.Count.Equals(0)) |
2185 | if (heights.Count.Equals(0)) |
|
2208 | throw new Exception("Could not get terrain heights."); |
2186 | throw new Exception("Could not get terrain heights."); |
|
2209 | |
2187 | |
|
2210 | double maxHeight = heights.Max(); |
2188 | var maxHeight = heights.Max(); |
|
2211 | using (Bitmap bitmap = new Bitmap(256, 256)) |
2189 | using (var bitmap = new Bitmap(256, 256)) |
|
2212 | { |
2190 | { |
|
2213 | foreach (int x in Enumerable.Range(1, 255)) |
2191 | foreach (var x in Enumerable.Range(1, 255)) |
|
2214 | { |
2192 | { |
|
2215 | foreach (int y in Enumerable.Range(1, 255)) |
2193 | foreach (var y in Enumerable.Range(1, 255)) |
|
2216 | { |
2194 | { |
|
2217 | bitmap.SetPixel(x, 256 - y, |
2195 | bitmap.SetPixel(x, 256 - y, |
|
2218 | Color.FromArgb( |
2196 | Color.FromArgb( |
|
2219 | Math.Max( |
2197 | Math.Max( |
|
2220 | (int) Numerics.MapValueToRange(heights[256*x + y], 0, maxHeight, 0, 255), 0), |
2198 | (int) Numerics.MapValueToRange(heights[256*x + y], 0, maxHeight, 0, 255), 0), |
|
2221 | 0, 0)); |
2199 | 0, 0)); |
|
2222 | } |
2200 | } |
|
2223 | } |
2201 | } |
|
2224 | Bitmap closureBitmap = (Bitmap) bitmap.Clone(); |
2202 | var closureBitmap = (Bitmap) bitmap.Clone(); |
|
2225 | vassalForm.BeginInvoke((MethodInvoker) (() => |
2203 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
2226 | { |
2204 | { |
|
2227 | switch (vassalForm.SavePNGFileDialog.ShowDialog()) |
2205 | switch (vassalForm.SavePNGFileDialog.ShowDialog()) |
|
2228 | { |
2206 | { |
|
2229 | case DialogResult.OK: |
2207 | case DialogResult.OK: |
|
2230 | string file = vassalForm.SavePNGFileDialog.FileName; |
2208 | var file = vassalForm.SavePNGFileDialog.FileName; |
|
2231 | new Thread(() => |
2209 | new Thread(() => |
|
2232 | { |
2210 | { |
|
Line 2288... | Line 2266... | |||
2288 | Monitor.Enter(ClientInstanceTeleportLock); |
2266 | Monitor.Enter(ClientInstanceTeleportLock); |
|
Line 2289... | Line 2267... | |||
2289 | |
2267 | |
|
2290 | try |
2268 | try |
|
2291 | { |
2269 | { |
|
2292 | // Download the terrain. |
2270 | // Download the terrain. |
|
2293 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
2271 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
2294 | KeyValue.Escape(new Dictionary<string, string> |
2272 | KeyValue.Escape(new Dictionary<string, string> |
|
2295 | { |
2273 | { |
|
2296 | {"command", "terrain"}, |
2274 | {"command", "terrain"}, |
|
2297 | {"group", vassalConfiguration.Group}, |
2275 | {"group", vassalConfiguration.Group}, |
|
2298 | {"password", vassalConfiguration.Password}, |
2276 | {"password", vassalConfiguration.Password}, |
|
2299 | {"action", "get"} |
2277 | {"action", "get"} |
|
Line 2300... | Line 2278... | |||
2300 | }, wasOutput), vassalConfiguration.DataTimeout); |
2278 | }, wasOutput)).Result); |
|
2301 | |
2279 | |
|
Line 2302... | Line 2280... | |||
2302 | if (string.IsNullOrEmpty(result)) |
2280 | if (string.IsNullOrEmpty(result)) |
|
Line 2307... | Line 2285... | |||
2307 | throw new Exception("No success status could be retrieved."); |
2285 | throw new Exception("No success status could be retrieved."); |
|
Line 2308... | Line 2286... | |||
2308 | |
2286 | |
|
2309 | if (!success) |
2287 | if (!success) |
|
Line 2310... | Line 2288... | |||
2310 | throw new Exception("Could not download terrain."); |
2288 | throw new Exception("Could not download terrain."); |
|
Line 2311... | Line 2289... | |||
2311 | |
2289 | |
|
2312 | byte[] data = Convert.FromBase64String(wasInput(KeyValue.Get("data", result))); |
2290 | var data = Convert.FromBase64String(wasInput(KeyValue.Get("data", result))); |
|
2313 | |
2291 | |
|
2314 | vassalForm.BeginInvoke((MethodInvoker) (() => |
2292 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
2315 | { |
2293 | { |
|
2316 | switch (vassalForm.SaveRawFileDialog.ShowDialog()) |
2294 | switch (vassalForm.SaveRawFileDialog.ShowDialog()) |
|
2317 | { |
2295 | { |
|
2318 | case DialogResult.OK: |
2296 | case DialogResult.OK: |
|
2319 | string file = vassalForm.SaveRawFileDialog.FileName; |
2297 | var file = vassalForm.SaveRawFileDialog.FileName; |
|
2320 | new Thread(() => |
2298 | new Thread(() => |
|
2321 | { |
2299 | { |
|
Line 2378... | Line 2356... | |||
2378 | vassalForm.Invoke((MethodInvoker) (() => |
2356 | vassalForm.Invoke((MethodInvoker) (() => |
|
2379 | { |
2357 | { |
|
2380 | switch (vassalForm.LoadRawFileDialog.ShowDialog()) |
2358 | switch (vassalForm.LoadRawFileDialog.ShowDialog()) |
|
2381 | { |
2359 | { |
|
2382 | case DialogResult.OK: |
2360 | case DialogResult.OK: |
|
2383 | string file = vassalForm.LoadRawFileDialog.FileName; |
2361 | var file = vassalForm.LoadRawFileDialog.FileName; |
|
2384 | vassalForm.StatusText.Text = @"loading terrain..."; |
2362 | vassalForm.StatusText.Text = @"loading terrain..."; |
|
2385 | vassalForm.StatusProgress.Value = 0; |
2363 | vassalForm.StatusProgress.Value = 0; |
|
Line 2386... | Line 2364... | |||
2386 | |
2364 | |
|
Line 2391... | Line 2369... | |||
2391 | break; |
2369 | break; |
|
2392 | } |
2370 | } |
|
2393 | })); |
2371 | })); |
|
Line 2394... | Line 2372... | |||
2394 | |
2372 | |
|
2395 | // Upload the terrain. |
2373 | // Upload the terrain. |
|
2396 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
2374 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
2397 | KeyValue.Escape(new Dictionary<string, string> |
2375 | KeyValue.Escape(new Dictionary<string, string> |
|
2398 | { |
2376 | { |
|
2399 | {"command", "terrain"}, |
2377 | {"command", "terrain"}, |
|
2400 | {"group", vassalConfiguration.Group}, |
2378 | {"group", vassalConfiguration.Group}, |
|
2401 | {"password", vassalConfiguration.Password}, |
2379 | {"password", vassalConfiguration.Password}, |
|
2402 | {"action", "set"}, |
2380 | {"action", "set"}, |
|
2403 | {"data", Convert.ToBase64String(data)} |
2381 | {"data", Convert.ToBase64String(data)} |
|
Line 2404... | Line 2382... | |||
2404 | }, wasOutput), vassalConfiguration.DataTimeout); |
2382 | }, wasOutput)).Result); |
|
2405 | |
2383 | |
|
Line 2406... | Line 2384... | |||
2406 | if (string.IsNullOrEmpty(result)) |
2384 | if (string.IsNullOrEmpty(result)) |
|
Line 2478... | Line 2456... | |||
2478 | break; |
2456 | break; |
|
2479 | default: |
2457 | default: |
|
2480 | estateListRowRegex = new Regex(@".+?", RegexOptions.Compiled); |
2458 | estateListRowRegex = new Regex(@".+?", RegexOptions.Compiled); |
|
2481 | break; |
2459 | break; |
|
2482 | } |
2460 | } |
|
2483 | foreach (DataGridViewRow estateListRow in EstateListGridView.Rows.AsParallel().Cast<DataGridViewRow>()) |
2461 | foreach (var estateListRow in EstateListGridView.Rows.AsParallel().Cast<DataGridViewRow>()) |
|
2484 | { |
2462 | { |
|
2485 | estateListRow.Visible = |
2463 | estateListRow.Visible = |
|
2486 | estateListRowRegex.IsMatch(estateListRow.Cells["EstateListName"].Value.ToString()); |
2464 | estateListRowRegex.IsMatch(estateListRow.Cells["EstateListName"].Value.ToString()); |
|
2487 | } |
2465 | } |
|
2488 | })); |
2466 | })); |
|
2489 | } |
2467 | } |
|
Line 2490... | Line 2468... | |||
2490 | |
2468 | |
|
2491 | private void EstateListSelected(object sender, EventArgs e) |
2469 | private void EstateListSelected(object sender, EventArgs e) |
|
2492 | { |
2470 | { |
|
2493 | string selectedEstateListType = string.Empty; |
2471 | var selectedEstateListType = string.Empty; |
|
2494 | bool queryEstateList = false; |
2472 | var queryEstateList = false; |
|
2495 | vassalForm.Invoke((MethodInvoker) (() => |
2473 | vassalForm.Invoke((MethodInvoker) (() => |
|
2496 | { |
2474 | { |
|
2497 | if (vassalForm.EstateListSelectBox.SelectedItem == null) return; |
2475 | if (vassalForm.EstateListSelectBox.SelectedItem == null) return; |
|
2498 | selectedEstateListType = vassalForm.EstateListSelectBox.SelectedItem.ToString(); |
2476 | selectedEstateListType = vassalForm.EstateListSelectBox.SelectedItem.ToString(); |
|
Line 2525... | Line 2503... | |||
2525 | EstateListsResidentsGroup.Enabled = false; |
2503 | EstateListsResidentsGroup.Enabled = false; |
|
2526 | EstateListsGroupsGroup.Enabled = false; |
2504 | EstateListsGroupsGroup.Enabled = false; |
|
2527 | })); |
2505 | })); |
|
Line 2528... | Line 2506... | |||
2528 | |
2506 | |
|
2529 | // Get the selected estate list. |
2507 | // Get the selected estate list. |
|
2530 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
2508 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
2531 | KeyValue.Escape(new Dictionary<string, string> |
2509 | KeyValue.Escape(new Dictionary<string, string> |
|
2532 | { |
2510 | { |
|
2533 | {"command", "getestatelist"}, |
2511 | {"command", "getestatelist"}, |
|
2534 | {"group", vassalConfiguration.Group}, |
2512 | {"group", vassalConfiguration.Group}, |
|
2535 | {"password", vassalConfiguration.Password}, |
2513 | {"password", vassalConfiguration.Password}, |
|
2536 | {"type", selectedEstateListType} |
2514 | {"type", selectedEstateListType} |
|
Line 2537... | Line 2515... | |||
2537 | }, wasOutput), vassalConfiguration.DataTimeout); |
2515 | }, wasOutput)).Result); |
|
2538 | |
2516 | |
|
Line 2539... | Line 2517... | |||
2539 | if (string.IsNullOrEmpty(result)) |
2517 | if (string.IsNullOrEmpty(result)) |
|
Line 2545... | Line 2523... | |||
2545 | |
2523 | |
|
2546 | if (!success) |
2524 | if (!success) |
|
Line 2547... | Line 2525... | |||
2547 | throw new Exception("Could not retrieve estate list."); |
2525 | throw new Exception("Could not retrieve estate list."); |
|
2548 | |
2526 | |
|
2549 | vassalForm.Invoke((MethodInvoker) (() => { EstateListGridView.Rows.Clear(); })); |
2527 | vassalForm.Invoke((MethodInvoker) (() => { EstateListGridView.Rows.Clear(); })); |
|
2550 | foreach (List<string> data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
2528 | foreach (var data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
|
2551 | .Where(x => !string.IsNullOrEmpty(x)) |
2529 | .Where(x => !string.IsNullOrEmpty(x)) |
|
2552 | .Select((x, i) => new {Index = i, Value = x}) |
2530 | .Select((x, i) => new {Index = i, Value = x}) |
|
2553 | .GroupBy(x => x.Index/2) |
2531 | .GroupBy(x => x.Index/2) |
|
Line 2589... | Line 2567... | |||
2589 | } |
2567 | } |
|
Line 2590... | Line 2568... | |||
2590 | |
2568 | |
|
2591 | private void RequestRemoveEstateListMember(object sender, EventArgs e) |
2569 | private void RequestRemoveEstateListMember(object sender, EventArgs e) |
|
2592 | { |
2570 | { |
|
2593 | // Get the estate list type. |
2571 | // Get the estate list type. |
|
2594 | string selectedEstateListType = string.Empty; |
2572 | var selectedEstateListType = string.Empty; |
|
2595 | bool queryEstateList = false; |
2573 | var queryEstateList = false; |
|
2596 | vassalForm.Invoke((MethodInvoker) (() => |
2574 | vassalForm.Invoke((MethodInvoker) (() => |
|
2597 | { |
2575 | { |
|
2598 | if (vassalForm.EstateListSelectBox.SelectedItem == null) |
2576 | if (vassalForm.EstateListSelectBox.SelectedItem == null) |
|
2599 | { |
2577 | { |
|
Line 2615... | Line 2593... | |||
2615 | |
2593 | |
|
2616 | // If not estate list type is selected then return. |
2594 | // If not estate list type is selected then return. |
|
Line 2617... | Line 2595... | |||
2617 | if (!queryEstateList) return; |
2595 | if (!queryEstateList) return; |
|
2618 | |
2596 | |
|
2619 | // Enqueue all the regions to restart. |
2597 | // Enqueue all the regions to restart. |
|
2620 | Queue<UUID> estateListMembersQueue = new Queue<UUID>(); |
2598 | var estateListMembersQueue = new Queue<UUID>(); |
|
2621 | vassalForm.Invoke((MethodInvoker) (() => |
2599 | vassalForm.Invoke((MethodInvoker) (() => |
|
2622 | { |
2600 | { |
|
2623 | foreach ( |
2601 | foreach ( |
|
2624 | DataGridViewRow estateListRow in |
2602 | var estateListRow in |
|
2625 | EstateListGridView.Rows.AsParallel() |
2603 | EstateListGridView.Rows.AsParallel() |
|
2626 | .Cast<DataGridViewRow>() |
2604 | .Cast<DataGridViewRow>() |
|
2627 | .Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
2605 | .Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
|
Line 2647... | Line 2625... | |||
2647 | new Thread(() => |
2625 | new Thread(() => |
|
2648 | { |
2626 | { |
|
2649 | try |
2627 | try |
|
2650 | { |
2628 | { |
|
2651 | Monitor.Enter(ClientInstanceTeleportLock); |
2629 | Monitor.Enter(ClientInstanceTeleportLock); |
|
2652 | UUID memberUUID = UUID.Zero; |
2630 | var memberUUID = UUID.Zero; |
|
2653 | do |
2631 | do |
|
2654 | { |
2632 | { |
|
2655 | try |
2633 | try |
|
2656 | { |
2634 | { |
|
2657 | memberUUID = estateListMembersQueue.Dequeue(); |
2635 | memberUUID = estateListMembersQueue.Dequeue(); |
|
Line 2658... | Line 2636... | |||
2658 | |
2636 | |
|
2659 | // Remove the agent or group from the list. |
2637 | // Remove the agent or group from the list. |
|
2660 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
2638 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
2661 | KeyValue.Escape(new Dictionary<string, string> |
2639 | KeyValue.Escape(new Dictionary<string, string> |
|
2662 | { |
2640 | { |
|
2663 | {"command", "setestatelist"}, |
2641 | {"command", "setestatelist"}, |
|
2664 | {"group", vassalConfiguration.Group}, |
2642 | {"group", vassalConfiguration.Group}, |
|
2665 | {"password", vassalConfiguration.Password}, |
2643 | {"password", vassalConfiguration.Password}, |
|
2666 | {"type", selectedEstateListType}, |
2644 | {"type", selectedEstateListType}, |
|
2667 | {"action", "remove"}, |
2645 | {"action", "remove"}, |
|
2668 | {selectedEstateListType.Equals("group") ? "target" : "agent", memberUUID.ToString()} |
2646 | {selectedEstateListType.Equals("group") ? "target" : "agent", memberUUID.ToString()} |
|
Line 2669... | Line 2647... | |||
2669 | }, wasOutput), vassalConfiguration.DataTimeout); |
2647 | }, wasOutput)).Result); |
|
2670 | |
2648 | |
|
Line 2671... | Line 2649... | |||
2671 | if (string.IsNullOrEmpty(result)) |
2649 | if (string.IsNullOrEmpty(result)) |
|
Line 2679... | Line 2657... | |||
2679 | throw new Exception("Unable to remove member"); |
2657 | throw new Exception("Unable to remove member"); |
|
Line 2680... | Line 2658... | |||
2680 | |
2658 | |
|
2681 | vassalForm.Invoke((MethodInvoker) (() => |
2659 | vassalForm.Invoke((MethodInvoker) (() => |
|
2682 | { |
2660 | { |
|
2683 | foreach ( |
2661 | foreach ( |
|
2684 | int i in |
2662 | var i in |
|
2685 | EstateListGridView.Rows.AsParallel() |
2663 | EstateListGridView.Rows.AsParallel() |
|
2686 | .Cast<DataGridViewRow>() |
2664 | .Cast<DataGridViewRow>() |
|
2687 | .Where( |
2665 | .Where( |
|
2688 | o => |
2666 | o => |
|
Line 2720... | Line 2698... | |||
2720 | } |
2698 | } |
|
Line 2721... | Line 2699... | |||
2721 | |
2699 | |
|
2722 | private void RequestEstateListsAddResident(object sender, EventArgs e) |
2700 | private void RequestEstateListsAddResident(object sender, EventArgs e) |
|
2723 | { |
2701 | { |
|
2724 | // Get the estate list type. |
2702 | // Get the estate list type. |
|
2725 | string selectedEstateListType = string.Empty; |
2703 | var selectedEstateListType = string.Empty; |
|
2726 | bool queryEstateList = false; |
2704 | var queryEstateList = false; |
|
2727 | vassalForm.Invoke((MethodInvoker) (() => |
2705 | vassalForm.Invoke((MethodInvoker) (() => |
|
2728 | { |
2706 | { |
|
2729 | selectedEstateListType = vassalForm.EstateListSelectBox.SelectedItem.ToString(); |
2707 | selectedEstateListType = vassalForm.EstateListSelectBox.SelectedItem.ToString(); |
|
2730 | switch ( |
2708 | switch ( |
|
Line 2740... | Line 2718... | |||
2740 | })); |
2718 | })); |
|
Line 2741... | Line 2719... | |||
2741 | |
2719 | |
|
2742 | // If not estate list type is selected then return. |
2720 | // If not estate list type is selected then return. |
|
Line 2743... | Line 2721... | |||
2743 | if (!queryEstateList) return; |
2721 | if (!queryEstateList) return; |
|
2744 | |
2722 | |
|
Line 2745... | Line 2723... | |||
2745 | string firstName = string.Empty; |
2723 | var firstName = string.Empty; |
|
2746 | string lastName = string.Empty; |
2724 | var lastName = string.Empty; |
|
2747 | |
2725 | |
|
2748 | vassalForm.Invoke((MethodInvoker) (() => |
2726 | vassalForm.Invoke((MethodInvoker) (() => |
|
Line 2783... | Line 2761... | |||
2783 | try |
2761 | try |
|
2784 | { |
2762 | { |
|
2785 | Monitor.Enter(ClientInstanceTeleportLock); |
2763 | Monitor.Enter(ClientInstanceTeleportLock); |
|
Line 2786... | Line 2764... | |||
2786 | |
2764 | |
|
2787 | // Add the resident to the list. |
2765 | // Add the resident to the list. |
|
2788 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
2766 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
2789 | KeyValue.Escape(new Dictionary<string, string> |
2767 | KeyValue.Escape(new Dictionary<string, string> |
|
2790 | { |
2768 | { |
|
2791 | {"command", "setestatelist"}, |
2769 | {"command", "setestatelist"}, |
|
2792 | {"group", vassalConfiguration.Group}, |
2770 | {"group", vassalConfiguration.Group}, |
|
2793 | {"password", vassalConfiguration.Password}, |
2771 | {"password", vassalConfiguration.Password}, |
|
2794 | {"type", selectedEstateListType}, |
2772 | {"type", selectedEstateListType}, |
|
2795 | {"action", "add"}, |
2773 | {"action", "add"}, |
|
2796 | {"firstname", firstName}, |
2774 | {"firstname", firstName}, |
|
2797 | {"lastname", lastName} |
2775 | {"lastname", lastName} |
|
Line 2798... | Line 2776... | |||
2798 | }, wasOutput), vassalConfiguration.DataTimeout); |
2776 | }, wasOutput)).Result); |
|
2799 | |
2777 | |
|
Line 2800... | Line 2778... | |||
2800 | if (string.IsNullOrEmpty(result)) |
2778 | if (string.IsNullOrEmpty(result)) |
|
Line 2806... | Line 2784... | |||
2806 | |
2784 | |
|
2807 | if (!success) |
2785 | if (!success) |
|
Line 2808... | Line 2786... | |||
2808 | throw new Exception("Unable to add resident"); |
2786 | throw new Exception("Unable to add resident"); |
|
2809 | |
2787 | |
|
2810 | // Retrieve the estate list for updates. |
2788 | // Retrieve the estate list for updates. |
|
2811 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
2789 | result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
2812 | KeyValue.Escape(new Dictionary<string, string> |
2790 | KeyValue.Escape(new Dictionary<string, string> |
|
2813 | { |
2791 | { |
|
2814 | {"command", "getestatelist"}, |
2792 | {"command", "getestatelist"}, |
|
2815 | {"group", vassalConfiguration.Group}, |
2793 | {"group", vassalConfiguration.Group}, |
|
2816 | {"password", vassalConfiguration.Password}, |
2794 | {"password", vassalConfiguration.Password}, |
|
Line 2817... | Line 2795... | |||
2817 | {"type", selectedEstateListType} |
2795 | {"type", selectedEstateListType} |
|
2818 | }, wasOutput), vassalConfiguration.DataTimeout); |
2796 | }, wasOutput)).Result); |
|
Line 2819... | Line 2797... | |||
2819 | |
2797 | |
|
Line 2825... | Line 2803... | |||
2825 | |
2803 | |
|
2826 | if (!success) |
2804 | if (!success) |
|
Line 2827... | Line 2805... | |||
2827 | throw new Exception("Could not retrieve estate list."); |
2805 | throw new Exception("Could not retrieve estate list."); |
|
2828 | |
2806 | |
|
2829 | vassalForm.Invoke((MethodInvoker) (() => { EstateListGridView.Rows.Clear(); })); |
2807 | vassalForm.Invoke((MethodInvoker) (() => { EstateListGridView.Rows.Clear(); })); |
|
2830 | foreach (List<string> data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
2808 | foreach (var data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
|
2831 | .Where(x => !string.IsNullOrEmpty(x)) |
2809 | .Where(x => !string.IsNullOrEmpty(x)) |
|
2832 | .Select((x, i) => new {Index = i, Value = x}) |
2810 | .Select((x, i) => new {Index = i, Value = x}) |
|
2833 | .GroupBy(x => x.Index/2) |
2811 | .GroupBy(x => x.Index/2) |
|
Line 2857... | Line 2835... | |||
2857 | } |
2835 | } |
|
Line 2858... | Line 2836... | |||
2858 | |
2836 | |
|
2859 | private void RequestEstateListsAddGroup(object sender, EventArgs e) |
2837 | private void RequestEstateListsAddGroup(object sender, EventArgs e) |
|
2860 | { |
2838 | { |
|
2861 | // Get the estate list type. |
2839 | // Get the estate list type. |
|
2862 | string selectedEstateListType = string.Empty; |
2840 | var selectedEstateListType = string.Empty; |
|
2863 | bool queryEstateList = false; |
2841 | var queryEstateList = false; |
|
2864 | vassalForm.Invoke((MethodInvoker) (() => |
2842 | vassalForm.Invoke((MethodInvoker) (() => |
|
2865 | { |
2843 | { |
|
2866 | selectedEstateListType = vassalForm.EstateListSelectBox.SelectedItem.ToString(); |
2844 | selectedEstateListType = vassalForm.EstateListSelectBox.SelectedItem.ToString(); |
|
2867 | switch ( |
2845 | switch ( |
|
Line 2877... | Line 2855... | |||
2877 | })); |
2855 | })); |
|
Line 2878... | Line 2856... | |||
2878 | |
2856 | |
|
2879 | // If not estate list type is selected then return. |
2857 | // If not estate list type is selected then return. |
|
Line 2880... | Line 2858... | |||
2880 | if (!queryEstateList) return; |
2858 | if (!queryEstateList) return; |
|
Line 2881... | Line 2859... | |||
2881 | |
2859 | |
|
2882 | string target = string.Empty; |
2860 | var target = string.Empty; |
|
2883 | |
2861 | |
|
2884 | vassalForm.Invoke((MethodInvoker) (() => |
2862 | vassalForm.Invoke((MethodInvoker) (() => |
|
Line 2909... | Line 2887... | |||
2909 | try |
2887 | try |
|
2910 | { |
2888 | { |
|
2911 | Monitor.Enter(ClientInstanceTeleportLock); |
2889 | Monitor.Enter(ClientInstanceTeleportLock); |
|
Line 2912... | Line 2890... | |||
2912 | |
2890 | |
|
2913 | // Add the group to the list. |
2891 | // Add the group to the list. |
|
2914 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
2892 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
2915 | KeyValue.Escape(new Dictionary<string, string> |
2893 | KeyValue.Escape(new Dictionary<string, string> |
|
2916 | { |
2894 | { |
|
2917 | {"command", "setestatelist"}, |
2895 | {"command", "setestatelist"}, |
|
2918 | {"group", vassalConfiguration.Group}, |
2896 | {"group", vassalConfiguration.Group}, |
|
2919 | {"password", vassalConfiguration.Password}, |
2897 | {"password", vassalConfiguration.Password}, |
|
2920 | {"type", selectedEstateListType}, |
2898 | {"type", selectedEstateListType}, |
|
2921 | {"action", "add"}, |
2899 | {"action", "add"}, |
|
2922 | {"target", target} |
2900 | {"target", target} |
|
Line 2923... | Line 2901... | |||
2923 | }, wasOutput), vassalConfiguration.DataTimeout); |
2901 | }, wasOutput)).Result); |
|
2924 | |
2902 | |
|
Line 2925... | Line 2903... | |||
2925 | if (string.IsNullOrEmpty(result)) |
2903 | if (string.IsNullOrEmpty(result)) |
|
Line 2931... | Line 2909... | |||
2931 | |
2909 | |
|
2932 | if (!success) |
2910 | if (!success) |
|
Line 2933... | Line 2911... | |||
2933 | throw new Exception("Unable to add group"); |
2911 | throw new Exception("Unable to add group"); |
|
2934 | |
2912 | |
|
2935 | // Retrieve the estate list for updates. |
2913 | // Retrieve the estate list for updates. |
|
2936 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
2914 | result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
2937 | KeyValue.Escape(new Dictionary<string, string> |
2915 | KeyValue.Escape(new Dictionary<string, string> |
|
2938 | { |
2916 | { |
|
2939 | {"command", "getestatelist"}, |
2917 | {"command", "getestatelist"}, |
|
2940 | {"group", vassalConfiguration.Group}, |
2918 | {"group", vassalConfiguration.Group}, |
|
2941 | {"password", vassalConfiguration.Password}, |
2919 | {"password", vassalConfiguration.Password}, |
|
Line 2942... | Line 2920... | |||
2942 | {"type", selectedEstateListType} |
2920 | {"type", selectedEstateListType} |
|
2943 | }, wasOutput), vassalConfiguration.DataTimeout); |
2921 | }, wasOutput)).Result); |
|
Line 2944... | Line 2922... | |||
2944 | |
2922 | |
|
Line 2950... | Line 2928... | |||
2950 | |
2928 | |
|
2951 | if (!success) |
2929 | if (!success) |
|
Line 2952... | Line 2930... | |||
2952 | throw new Exception("Could not retrieve estate list."); |
2930 | throw new Exception("Could not retrieve estate list."); |
|
2953 | |
2931 | |
|
2954 | vassalForm.Invoke((MethodInvoker) (() => { EstateListGridView.Rows.Clear(); })); |
2932 | vassalForm.Invoke((MethodInvoker) (() => { EstateListGridView.Rows.Clear(); })); |
|
2955 | foreach (List<string> data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
2933 | foreach (var data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
|
2956 | .Where(x => !string.IsNullOrEmpty(x)) |
2934 | .Where(x => !string.IsNullOrEmpty(x)) |
|
2957 | .Select((x, i) => new {Index = i, Value = x}) |
2935 | .Select((x, i) => new {Index = i, Value = x}) |
|
2958 | .GroupBy(x => x.Index/2) |
2936 | .GroupBy(x => x.Index/2) |
|
Line 2993... | Line 2971... | |||
2993 | { |
2971 | { |
|
2994 | try |
2972 | try |
|
2995 | { |
2973 | { |
|
2996 | Monitor.Enter(ClientInstanceTeleportLock); |
2974 | Monitor.Enter(ClientInstanceTeleportLock); |
|
Line 2997... | Line 2975... | |||
2997 | |
2975 | |
|
2998 | bool scripts = false; |
2976 | var scripts = false; |
|
2999 | bool collisons = false; |
2977 | var collisons = false; |
|
3000 | bool physics = false; |
2978 | var physics = false; |
|
3001 | vassalForm.Invoke((MethodInvoker) (() => |
2979 | vassalForm.Invoke((MethodInvoker) (() => |
|
3002 | { |
2980 | { |
|
3003 | scripts = RegionDebugScriptsBox.Checked; |
2981 | scripts = RegionDebugScriptsBox.Checked; |
|
3004 | collisons = RegionDebugCollisionsBox.Checked; |
2982 | collisons = RegionDebugCollisionsBox.Checked; |
|
3005 | physics = RegionDebugPhysicsBox.Checked; |
2983 | physics = RegionDebugPhysicsBox.Checked; |
|
Line 3006... | Line 2984... | |||
3006 | })); |
2984 | })); |
|
3007 | |
2985 | |
|
3008 | // Set the debug settings. |
2986 | // Set the debug settings. |
|
3009 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
2987 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
3010 | KeyValue.Escape(new Dictionary<string, string> |
2988 | KeyValue.Escape(new Dictionary<string, string> |
|
3011 | { |
2989 | { |
|
3012 | {"command", "setregiondebug"}, |
2990 | {"command", "setregiondebug"}, |
|
3013 | {"group", vassalConfiguration.Group}, |
2991 | {"group", vassalConfiguration.Group}, |
|
3014 | {"password", vassalConfiguration.Password}, |
2992 | {"password", vassalConfiguration.Password}, |
|
3015 | {"scripts", scripts.ToString()}, |
2993 | {"scripts", scripts.ToString()}, |
|
3016 | {"collisions", collisons.ToString()}, |
2994 | {"collisions", collisons.ToString()}, |
|
Line 3017... | Line 2995... | |||
3017 | {"physics", physics.ToString()} |
2995 | {"physics", physics.ToString()} |
|
3018 | }, wasOutput), vassalConfiguration.DataTimeout); |
2996 | }, wasOutput)).Result); |
|
Line 3019... | Line 2997... | |||
3019 | |
2997 | |
|
Line 3059... | Line 3037... | |||
3059 | { |
3037 | { |
|
3060 | try |
3038 | try |
|
3061 | { |
3039 | { |
|
3062 | Monitor.Enter(ClientInstanceTeleportLock); |
3040 | Monitor.Enter(ClientInstanceTeleportLock); |
|
Line 3063... | Line 3041... | |||
3063 | |
3041 | |
|
3064 | bool terraform = false; |
3042 | var terraform = false; |
|
3065 | bool fly = false; |
3043 | var fly = false; |
|
3066 | bool damage = false; |
3044 | var damage = false; |
|
3067 | bool resell = false; |
3045 | var resell = false; |
|
3068 | bool push = false; |
3046 | var push = false; |
|
3069 | bool parcel = false; |
3047 | var parcel = false; |
|
3070 | bool mature = false; |
3048 | var mature = false; |
|
3071 | uint agentLimit = 20; |
3049 | uint agentLimit = 20; |
|
Line 3072... | Line 3050... | |||
3072 | double objectBonus = 2.0; |
3050 | var objectBonus = 2.0; |
|
Line 3073... | Line 3051... | |||
3073 | |
3051 | |
|
3074 | bool run = false; |
3052 | var run = false; |
|
3075 | |
3053 | |
|
3076 | vassalForm.Invoke((MethodInvoker) (() => |
3054 | vassalForm.Invoke((MethodInvoker) (() => |
|
Line 3106... | Line 3084... | |||
3106 | })); |
3084 | })); |
|
Line 3107... | Line 3085... | |||
3107 | |
3085 | |
|
Line 3108... | Line 3086... | |||
3108 | if (!run) return; |
3086 | if (!run) return; |
|
3109 | |
3087 | |
|
3110 | // Set the debug settings. |
3088 | // Set the debug settings. |
|
3111 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
3089 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
3112 | KeyValue.Escape(new Dictionary<string, string> |
3090 | KeyValue.Escape(new Dictionary<string, string> |
|
3113 | { |
3091 | { |
|
3114 | {"command", "setregioninfo"}, |
3092 | {"command", "setregioninfo"}, |
|
Line 3121... | Line 3099... | |||
3121 | {"push", push.ToString()}, |
3099 | {"push", push.ToString()}, |
|
3122 | {"parcel", parcel.ToString()}, |
3100 | {"parcel", parcel.ToString()}, |
|
3123 | {"mature", mature.ToString()}, |
3101 | {"mature", mature.ToString()}, |
|
3124 | {"limit", agentLimit.ToString(Utils.EnUsCulture)}, |
3102 | {"limit", agentLimit.ToString(Utils.EnUsCulture)}, |
|
3125 | {"bonus", objectBonus.ToString(Utils.EnUsCulture)} |
3103 | {"bonus", objectBonus.ToString(Utils.EnUsCulture)} |
|
3126 | }, wasOutput), vassalConfiguration.DataTimeout); |
3104 | }, wasOutput)).Result); |
|
Line 3127... | Line 3105... | |||
3127 | |
3105 | |
|
3128 | if (string.IsNullOrEmpty(result)) |
3106 | if (string.IsNullOrEmpty(result)) |
|
Line 3129... | Line 3107... | |||
3129 | throw new Exception("Error communicating with Corrade"); |
3107 | throw new Exception("Error communicating with Corrade"); |
|
Line 3154... | Line 3132... | |||
3154 | {IsBackground = true}.Start(); |
3132 | {IsBackground = true}.Start(); |
|
3155 | } |
3133 | } |
|
Line 3156... | Line 3134... | |||
3156 | |
3134 | |
|
3157 | private void RequestEstateTexturesApply(object sender, EventArgs e) |
3135 | private void RequestEstateTexturesApply(object sender, EventArgs e) |
|
3158 | { |
3136 | { |
|
3159 | List<UUID> groundTextureUUIDs = new List<UUID>(); |
3137 | var groundTextureUUIDs = new List<UUID>(); |
|
3160 | vassalForm.Invoke((MethodInvoker) (() => |
3138 | vassalForm.Invoke((MethodInvoker) (() => |
|
3161 | { |
3139 | { |
|
3162 | UUID textureUUID; |
3140 | UUID textureUUID; |
|
3163 | switch (!UUID.TryParse(RegionTexturesLowUUIDApplyBox.Text, out textureUUID)) |
3141 | switch (!UUID.TryParse(RegionTexturesLowUUIDApplyBox.Text, out textureUUID)) |
|
Line 3219... | Line 3197... | |||
3219 | try |
3197 | try |
|
3220 | { |
3198 | { |
|
3221 | Monitor.Enter(ClientInstanceTeleportLock); |
3199 | Monitor.Enter(ClientInstanceTeleportLock); |
|
Line 3222... | Line 3200... | |||
3222 | |
3200 | |
|
3223 | // Set the debug settings. |
3201 | // Set the debug settings. |
|
3224 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
3202 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
3225 | KeyValue.Escape(new Dictionary<string, string> |
3203 | KeyValue.Escape(new Dictionary<string, string> |
|
3226 | { |
3204 | { |
|
3227 | {"command", "setregionterraintextures"}, |
3205 | {"command", "setregionterraintextures"}, |
|
3228 | {"group", vassalConfiguration.Group}, |
3206 | {"group", vassalConfiguration.Group}, |
|
3229 | {"password", vassalConfiguration.Password}, |
3207 | {"password", vassalConfiguration.Password}, |
|
3230 | {"data", CSV.FromEnumerable(groundTextureUUIDs.Select(o => o.ToString()))} |
3208 | {"data", CSV.FromEnumerable(groundTextureUUIDs.Select(o => o.ToString()))} |
|
Line 3231... | Line 3209... | |||
3231 | }, wasOutput), vassalConfiguration.DataTimeout); |
3209 | }, wasOutput)).Result); |
|
3232 | |
3210 | |
|
Line 3233... | Line 3211... | |||
3233 | if (string.IsNullOrEmpty(result)) |
3211 | if (string.IsNullOrEmpty(result)) |
|
Line 3259... | Line 3237... | |||
3259 | {IsBackground = true}; |
3237 | {IsBackground = true}; |
|
3260 | } |
3238 | } |
|
Line 3261... | Line 3239... | |||
3261 | |
3239 | |
|
3262 | private void RequestDownloadRegionTexture(object sender, EventArgs e) |
3240 | private void RequestDownloadRegionTexture(object sender, EventArgs e) |
|
3263 | { |
3241 | { |
|
3264 | string textureName = string.Empty; |
3242 | var textureName = string.Empty; |
|
3265 | UUID textureUUID = UUID.Zero; |
3243 | var textureUUID = UUID.Zero; |
|
3266 | bool run = false; |
3244 | var run = false; |
|
3267 | vassalForm.Invoke((MethodInvoker) (() => |
3245 | vassalForm.Invoke((MethodInvoker) (() => |
|
3268 | { |
3246 | { |
|
3269 | Button button = sender as Button; |
3247 | var button = sender as Button; |
|
3270 | if (button == null) |
3248 | if (button == null) |
|
3271 | { |
3249 | { |
|
3272 | run = false; |
3250 | run = false; |
|
3273 | return; |
3251 | return; |
|
Line 3320... | Line 3298... | |||
3320 | { |
3298 | { |
|
3321 | try |
3299 | try |
|
3322 | { |
3300 | { |
|
3323 | Monitor.Enter(ClientInstanceTeleportLock); |
3301 | Monitor.Enter(ClientInstanceTeleportLock); |
|
Line 3324... | Line 3302... | |||
3324 | |
3302 | |
|
3325 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
3303 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
3326 | KeyValue.Escape(new Dictionary<string, string> |
3304 | KeyValue.Escape(new Dictionary<string, string> |
|
3327 | { |
3305 | { |
|
3328 | {"command", "download"}, |
3306 | {"command", "download"}, |
|
3329 | {"group", vassalConfiguration.Group}, |
3307 | {"group", vassalConfiguration.Group}, |
|
3330 | {"password", vassalConfiguration.Password}, |
3308 | {"password", vassalConfiguration.Password}, |
|
3331 | {"item", textureUUID.ToString()}, |
3309 | {"item", textureUUID.ToString()}, |
|
3332 | {"type", "Texture"}, |
3310 | {"type", "Texture"}, |
|
3333 | {"format", "Png"} |
3311 | {"format", "Png"} |
|
Line 3334... | Line 3312... | |||
3334 | }, wasOutput), vassalConfiguration.DataTimeout); |
3312 | }, wasOutput)).Result); |
|
3335 | |
3313 | |
|
Line 3336... | Line 3314... | |||
3336 | if (string.IsNullOrEmpty(result)) |
3314 | if (string.IsNullOrEmpty(result)) |
|
3337 | throw new Exception("Error communicating with Corrade"); |
3315 | throw new Exception("Error communicating with Corrade"); |
|
3338 | |
3316 | |
|
Line 3339... | Line 3317... | |||
3339 | bool success; |
3317 | bool success; |
|
3340 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
3318 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
|
3341 | throw new Exception("No success status could be retrieved"); |
3319 | throw new Exception("No success status could be retrieved"); |
|
3342 | |
3320 | |
|
3343 | byte[] mapImageBytes = Convert.FromBase64String(wasInput(KeyValue.Get("data", result))); |
3321 | var mapImageBytes = Convert.FromBase64String(wasInput(KeyValue.Get("data", result))); |
|
3344 | Image mapImage; |
3322 | Image mapImage; |
|
Line 3345... | Line 3323... | |||
3345 | using (MemoryStream memoryStream = new MemoryStream(mapImageBytes, 0, mapImageBytes.Length)) |
3323 | using (var memoryStream = new MemoryStream(mapImageBytes, 0, mapImageBytes.Length)) |
|
3346 | { |
3324 | { |
|
3347 | mapImage = Image.FromStream(memoryStream); |
3325 | mapImage = Image.FromStream(memoryStream); |
|
3348 | } |
3326 | } |
|
3349 | |
3327 | |
|
3350 | vassalForm.BeginInvoke((MethodInvoker) (() => |
3328 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
3351 | { |
3329 | { |
|
3352 | switch (vassalForm.SavePNGFileDialog.ShowDialog()) |
3330 | switch (vassalForm.SavePNGFileDialog.ShowDialog()) |
|
3353 | { |
3331 | { |
|
3354 | case DialogResult.OK: |
3332 | case DialogResult.OK: |
|
3355 | string file = vassalForm.SavePNGFileDialog.FileName; |
3333 | var file = vassalForm.SavePNGFileDialog.FileName; |
|
Line 3402... | Line 3380... | |||
3402 | } |
3380 | } |
|
Line 3403... | Line 3381... | |||
3403 | |
3381 | |
|
3404 | private void RequestEstateListsAddGroupsFromCSV(object sender, EventArgs e) |
3382 | private void RequestEstateListsAddGroupsFromCSV(object sender, EventArgs e) |
|
3405 | { |
3383 | { |
|
3406 | // Get the estate list type. |
3384 | // Get the estate list type. |
|
3407 | string selectedEstateListType = string.Empty; |
3385 | var selectedEstateListType = string.Empty; |
|
3408 | bool queryEstateList = false; |
3386 | var queryEstateList = false; |
|
3409 | vassalForm.Invoke((MethodInvoker) (() => |
3387 | vassalForm.Invoke((MethodInvoker) (() => |
|
3410 | { |
3388 | { |
|
3411 | if (vassalForm.EstateListSelectBox.SelectedItem == null) return; |
3389 | if (vassalForm.EstateListSelectBox.SelectedItem == null) return; |
|
3412 | selectedEstateListType = vassalForm.EstateListSelectBox.SelectedItem.ToString(); |
3390 | selectedEstateListType = vassalForm.EstateListSelectBox.SelectedItem.ToString(); |
|
Line 3423... | Line 3401... | |||
3423 | })); |
3401 | })); |
|
Line 3424... | Line 3402... | |||
3424 | |
3402 | |
|
3425 | // If not estate list type is selected then return. |
3403 | // If not estate list type is selected then return. |
|
Line 3426... | Line 3404... | |||
3426 | if (!queryEstateList) return; |
3404 | if (!queryEstateList) return; |
|
Line 3427... | Line 3405... | |||
3427 | |
3405 | |
|
3428 | Queue<KeyValuePair<string, UUID>> targets = new Queue<KeyValuePair<string, UUID>>(); |
3406 | var targets = new Queue<KeyValuePair<string, UUID>>(); |
|
3429 | |
3407 | |
|
3430 | vassalForm.Invoke((MethodInvoker) (() => |
3408 | vassalForm.Invoke((MethodInvoker) (() => |
|
3431 | { |
3409 | { |
|
3432 | switch (vassalForm.LoadCSVFile.ShowDialog()) |
3410 | switch (vassalForm.LoadCSVFile.ShowDialog()) |
|
3433 | { |
3411 | { |
|
3434 | case DialogResult.OK: |
3412 | case DialogResult.OK: |
|
3435 | string file = vassalForm.LoadCSVFile.FileName; |
3413 | var file = vassalForm.LoadCSVFile.FileName; |
|
3436 | try |
3414 | try |
|
Line 3437... | Line 3415... | |||
3437 | { |
3415 | { |
|
3438 | vassalForm.StatusText.Text = @"loading group list..."; |
3416 | vassalForm.StatusText.Text = @"loading group list..."; |
|
3439 | vassalForm.StatusProgress.Value = 0; |
3417 | vassalForm.StatusProgress.Value = 0; |
|
3440 | |
3418 | |
|
3441 | // import groups |
3419 | // import groups |
|
3442 | UUID targetUUID; |
3420 | UUID targetUUID; |
|
3443 | foreach (KeyValuePair<string, UUID> target in |
3421 | foreach (var target in |
|
3444 | File.ReadAllLines(file) |
3422 | File.ReadAllLines(file) |
|
Line 3464... | Line 3442... | |||
3464 | break; |
3442 | break; |
|
3465 | } |
3443 | } |
|
3466 | })); |
3444 | })); |
|
Line 3467... | Line 3445... | |||
3467 | |
3445 | |
|
3468 | if (targets.Count.Equals(0)) return; |
3446 | if (targets.Count.Equals(0)) return; |
|
Line 3469... | Line 3447... | |||
3469 | int initialQueueSize = targets.Count; |
3447 | var initialQueueSize = targets.Count; |
|
3470 | |
3448 | |
|
3471 | // Block teleports and disable button. |
3449 | // Block teleports and disable button. |
|
3472 | vassalForm.Invoke((MethodInvoker) (() => |
3450 | vassalForm.Invoke((MethodInvoker) (() => |
|
Line 3481... | Line 3459... | |||
3481 | { |
3459 | { |
|
3482 | Monitor.Enter(ClientInstanceTeleportLock); |
3460 | Monitor.Enter(ClientInstanceTeleportLock); |
|
Line 3483... | Line 3461... | |||
3483 | |
3461 | |
|
3484 | do |
3462 | do |
|
3485 | { |
3463 | { |
|
Line 3486... | Line 3464... | |||
3486 | KeyValuePair<string, UUID> target = targets.Dequeue(); |
3464 | var target = targets.Dequeue(); |
|
3487 | |
3465 | |
|
3488 | vassalForm.Invoke((MethodInvoker) (() => |
3466 | vassalForm.Invoke((MethodInvoker) (() => |
|
3489 | { |
3467 | { |
|
3490 | StatusText.Text = @"Adding to estate list: " + target.Key; |
3468 | StatusText.Text = @"Adding to estate list: " + target.Key; |
|
3491 | vassalForm.StatusProgress.Value = |
3469 | vassalForm.StatusProgress.Value = |
|
Line 3492... | Line 3470... | |||
3492 | Math.Min((int) (100d*Math.Abs(targets.Count - initialQueueSize)/initialQueueSize), 100); |
3470 | Math.Min((int) (100d*Math.Abs(targets.Count - initialQueueSize)/initialQueueSize), 100); |
|
3493 | })); |
3471 | })); |
|
3494 | |
3472 | |
|
3495 | // Skip any items that already exist. |
3473 | // Skip any items that already exist. |
|
3496 | bool run = false; |
3474 | var run = false; |
|
3497 | vassalForm.Invoke((MethodInvoker) (() => |
3475 | vassalForm.Invoke((MethodInvoker) (() => |
|
3498 | { |
3476 | { |
|
Line 3507... | Line 3485... | |||
3507 | if (target.Value.Equals(UUID.Zero)) continue; |
3485 | if (target.Value.Equals(UUID.Zero)) continue; |
|
Line 3508... | Line 3486... | |||
3508 | |
3486 | |
|
3509 | try |
3487 | try |
|
3510 | { |
3488 | { |
|
3511 | // Add the group to the list. |
3489 | // Add the group to the list. |
|
3512 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
3490 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
3513 | KeyValue.Escape(new Dictionary<string, string> |
3491 | KeyValue.Escape(new Dictionary<string, string> |
|
3514 | { |
3492 | { |
|
3515 | {"command", "setestatelist"}, |
3493 | {"command", "setestatelist"}, |
|
3516 | {"group", vassalConfiguration.Group}, |
3494 | {"group", vassalConfiguration.Group}, |
|
3517 | {"password", vassalConfiguration.Password}, |
3495 | {"password", vassalConfiguration.Password}, |
|
3518 | {"type", selectedEstateListType}, |
3496 | {"type", selectedEstateListType}, |
|
3519 | {"action", "add"}, |
3497 | {"action", "add"}, |
|
3520 | {"target", target.Value.ToString()} |
3498 | {"target", target.Value.ToString()} |
|
Line 3521... | Line 3499... | |||
3521 | }, wasOutput), vassalConfiguration.DataTimeout); |
3499 | }, wasOutput)).Result); |
|
3522 | |
3500 | |
|
Line 3523... | Line 3501... | |||
3523 | if (string.IsNullOrEmpty(result)) |
3501 | if (string.IsNullOrEmpty(result)) |
|
Line 3539... | Line 3517... | |||
3539 | |
3517 | |
|
3540 | // Retrieve the estate list. |
3518 | // Retrieve the estate list. |
|
3541 | try |
3519 | try |
|
3542 | { |
3520 | { |
|
3543 | // Retrieve the estate list for updates. |
3521 | // Retrieve the estate list for updates. |
|
3544 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
3522 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
3545 | KeyValue.Escape(new Dictionary<string, string> |
3523 | KeyValue.Escape(new Dictionary<string, string> |
|
3546 | { |
3524 | { |
|
3547 | {"command", "getestatelist"}, |
3525 | {"command", "getestatelist"}, |
|
3548 | {"group", vassalConfiguration.Group}, |
3526 | {"group", vassalConfiguration.Group}, |
|
3549 | {"password", vassalConfiguration.Password}, |
3527 | {"password", vassalConfiguration.Password}, |
|
3550 | {"type", selectedEstateListType} |
3528 | {"type", selectedEstateListType} |
|
Line 3551... | Line 3529... | |||
3551 | }, wasOutput), vassalConfiguration.DataTimeout); |
3529 | }, wasOutput)).Result); |
|
3552 | |
3530 | |
|
Line 3553... | Line 3531... | |||
3553 | if (string.IsNullOrEmpty(result)) |
3531 | if (string.IsNullOrEmpty(result)) |
|
Line 3559... | Line 3537... | |||
3559 | |
3537 | |
|
3560 | if (!success) |
3538 | if (!success) |
|
Line 3561... | Line 3539... | |||
3561 | throw new Exception("Could not retrieve estate list."); |
3539 | throw new Exception("Could not retrieve estate list."); |
|
3562 | |
3540 | |
|
3563 | vassalForm.Invoke((MethodInvoker) (() => { EstateListGridView.Rows.Clear(); })); |
3541 | vassalForm.Invoke((MethodInvoker) (() => { EstateListGridView.Rows.Clear(); })); |
|
3564 | foreach (List<string> data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
3542 | foreach (var data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
|
3565 | .Where(x => !string.IsNullOrEmpty(x)) |
3543 | .Where(x => !string.IsNullOrEmpty(x)) |
|
3566 | .Select((x, i) => new {Index = i, Value = x}) |
3544 | .Select((x, i) => new {Index = i, Value = x}) |
|
3567 | .GroupBy(x => x.Index/2) |
3545 | .GroupBy(x => x.Index/2) |
|
Line 3595... | Line 3573... | |||
3595 | } |
3573 | } |
|
Line 3596... | Line 3574... | |||
3596 | |
3574 | |
|
3597 | private void RequestEstateListsAddResidentsFromCSV(object sender, EventArgs e) |
3575 | private void RequestEstateListsAddResidentsFromCSV(object sender, EventArgs e) |
|
3598 | { |
3576 | { |
|
3599 | // Get the estate list type. |
3577 | // Get the estate list type. |
|
3600 | string selectedEstateListType = string.Empty; |
3578 | var selectedEstateListType = string.Empty; |
|
3601 | bool queryEstateList = false; |
3579 | var queryEstateList = false; |
|
3602 | vassalForm.Invoke((MethodInvoker) (() => |
3580 | vassalForm.Invoke((MethodInvoker) (() => |
|
3603 | { |
3581 | { |
|
3604 | if (vassalForm.EstateListSelectBox.SelectedItem == null) return; |
3582 | if (vassalForm.EstateListSelectBox.SelectedItem == null) return; |
|
3605 | selectedEstateListType = vassalForm.EstateListSelectBox.SelectedItem.ToString(); |
3583 | selectedEstateListType = vassalForm.EstateListSelectBox.SelectedItem.ToString(); |
|
Line 3616... | Line 3594... | |||
3616 | })); |
3594 | })); |
|
Line 3617... | Line 3595... | |||
3617 | |
3595 | |
|
3618 | // If not estate list type is selected then return. |
3596 | // If not estate list type is selected then return. |
|
Line 3619... | Line 3597... | |||
3619 | if (!queryEstateList) return; |
3597 | if (!queryEstateList) return; |
|
Line 3620... | Line 3598... | |||
3620 | |
3598 | |
|
3621 | Queue<KeyValuePair<string, UUID>> targets = new Queue<KeyValuePair<string, UUID>>(); |
3599 | var targets = new Queue<KeyValuePair<string, UUID>>(); |
|
3622 | |
3600 | |
|
3623 | vassalForm.Invoke((MethodInvoker) (() => |
3601 | vassalForm.Invoke((MethodInvoker) (() => |
|
3624 | { |
3602 | { |
|
3625 | switch (vassalForm.LoadCSVFile.ShowDialog()) |
3603 | switch (vassalForm.LoadCSVFile.ShowDialog()) |
|
3626 | { |
3604 | { |
|
3627 | case DialogResult.OK: |
3605 | case DialogResult.OK: |
|
3628 | string file = vassalForm.LoadCSVFile.FileName; |
3606 | var file = vassalForm.LoadCSVFile.FileName; |
|
3629 | try |
3607 | try |
|
Line 3630... | Line 3608... | |||
3630 | { |
3608 | { |
|
3631 | vassalForm.StatusText.Text = @"loading residents list..."; |
3609 | vassalForm.StatusText.Text = @"loading residents list..."; |
|
3632 | vassalForm.StatusProgress.Value = 0; |
3610 | vassalForm.StatusProgress.Value = 0; |
|
3633 | |
3611 | |
|
3634 | // import groups |
3612 | // import groups |
|
3635 | UUID targetUUID; |
3613 | UUID targetUUID; |
|
3636 | foreach (KeyValuePair<string, UUID> target in |
3614 | foreach (var target in |
|
3637 | File.ReadAllLines(file) |
3615 | File.ReadAllLines(file) |
|
Line 3657... | Line 3635... | |||
3657 | break; |
3635 | break; |
|
3658 | } |
3636 | } |
|
3659 | })); |
3637 | })); |
|
Line 3660... | Line 3638... | |||
3660 | |
3638 | |
|
3661 | if (targets.Count.Equals(0)) return; |
3639 | if (targets.Count.Equals(0)) return; |
|
Line 3662... | Line 3640... | |||
3662 | int initialQueueSize = targets.Count; |
3640 | var initialQueueSize = targets.Count; |
|
3663 | |
3641 | |
|
3664 | // Block teleports and disable button. |
3642 | // Block teleports and disable button. |
|
3665 | vassalForm.Invoke((MethodInvoker) (() => |
3643 | vassalForm.Invoke((MethodInvoker) (() => |
|
Line 3674... | Line 3652... | |||
3674 | { |
3652 | { |
|
3675 | Monitor.Enter(ClientInstanceTeleportLock); |
3653 | Monitor.Enter(ClientInstanceTeleportLock); |
|
Line 3676... | Line 3654... | |||
3676 | |
3654 | |
|
3677 | do |
3655 | do |
|
3678 | { |
3656 | { |
|
Line 3679... | Line 3657... | |||
3679 | KeyValuePair<string, UUID> target = targets.Dequeue(); |
3657 | var target = targets.Dequeue(); |
|
3680 | |
3658 | |
|
3681 | vassalForm.Invoke((MethodInvoker) (() => |
3659 | vassalForm.Invoke((MethodInvoker) (() => |
|
3682 | { |
3660 | { |
|
3683 | StatusText.Text = @"Adding to estate list: " + target.Key; |
3661 | StatusText.Text = @"Adding to estate list: " + target.Key; |
|
3684 | vassalForm.StatusProgress.Value = |
3662 | vassalForm.StatusProgress.Value = |
|
Line 3685... | Line 3663... | |||
3685 | Math.Min((int) (100d*Math.Abs(targets.Count - initialQueueSize)/initialQueueSize), 100); |
3663 | Math.Min((int) (100d*Math.Abs(targets.Count - initialQueueSize)/initialQueueSize), 100); |
|
3686 | })); |
3664 | })); |
|
3687 | |
3665 | |
|
3688 | // Skip any items that already exist. |
3666 | // Skip any items that already exist. |
|
3689 | bool run = false; |
3667 | var run = false; |
|
3690 | vassalForm.Invoke((MethodInvoker) (() => |
3668 | vassalForm.Invoke((MethodInvoker) (() => |
|
3691 | { |
3669 | { |
|
Line 3700... | Line 3678... | |||
3700 | if (target.Value.Equals(UUID.Zero)) continue; |
3678 | if (target.Value.Equals(UUID.Zero)) continue; |
|
Line 3701... | Line 3679... | |||
3701 | |
3679 | |
|
3702 | try |
3680 | try |
|
3703 | { |
3681 | { |
|
3704 | // Add the group to the list. |
3682 | // Add the group to the list. |
|
3705 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
3683 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
3706 | KeyValue.Escape(new Dictionary<string, string> |
3684 | KeyValue.Escape(new Dictionary<string, string> |
|
3707 | { |
3685 | { |
|
3708 | {"command", "setestatelist"}, |
3686 | {"command", "setestatelist"}, |
|
3709 | {"group", vassalConfiguration.Group}, |
3687 | {"group", vassalConfiguration.Group}, |
|
3710 | {"password", vassalConfiguration.Password}, |
3688 | {"password", vassalConfiguration.Password}, |
|
3711 | {"type", selectedEstateListType}, |
3689 | {"type", selectedEstateListType}, |
|
3712 | {"action", "add"}, |
3690 | {"action", "add"}, |
|
3713 | {"agent", target.Value.ToString()} |
3691 | {"agent", target.Value.ToString()} |
|
Line 3714... | Line 3692... | |||
3714 | }, wasOutput), vassalConfiguration.DataTimeout); |
3692 | }, wasOutput)).Result); |
|
3715 | |
3693 | |
|
Line 3716... | Line 3694... | |||
3716 | if (string.IsNullOrEmpty(result)) |
3694 | if (string.IsNullOrEmpty(result)) |
|
Line 3732... | Line 3710... | |||
3732 | |
3710 | |
|
3733 | // Retrieve the estate list. |
3711 | // Retrieve the estate list. |
|
3734 | try |
3712 | try |
|
3735 | { |
3713 | { |
|
3736 | // Retrieve the estate list for updates. |
3714 | // Retrieve the estate list for updates. |
|
3737 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
3715 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
3738 | KeyValue.Escape(new Dictionary<string, string> |
3716 | KeyValue.Escape(new Dictionary<string, string> |
|
3739 | { |
3717 | { |
|
3740 | {"command", "getestatelist"}, |
3718 | {"command", "getestatelist"}, |
|
3741 | {"group", vassalConfiguration.Group}, |
3719 | {"group", vassalConfiguration.Group}, |
|
3742 | {"password", vassalConfiguration.Password}, |
3720 | {"password", vassalConfiguration.Password}, |
|
3743 | {"type", selectedEstateListType} |
3721 | {"type", selectedEstateListType} |
|
Line 3744... | Line 3722... | |||
3744 | }, wasOutput), vassalConfiguration.DataTimeout); |
3722 | }, wasOutput)).Result); |
|
3745 | |
3723 | |
|
Line 3746... | Line 3724... | |||
3746 | if (string.IsNullOrEmpty(result)) |
3724 | if (string.IsNullOrEmpty(result)) |
|
Line 3752... | Line 3730... | |||
3752 | |
3730 | |
|
3753 | if (!success) |
3731 | if (!success) |
|
Line 3754... | Line 3732... | |||
3754 | throw new Exception("Could not retrieve estate list."); |
3732 | throw new Exception("Could not retrieve estate list."); |
|
3755 | |
3733 | |
|
3756 | vassalForm.Invoke((MethodInvoker) (() => { EstateListGridView.Rows.Clear(); })); |
3734 | vassalForm.Invoke((MethodInvoker) (() => { EstateListGridView.Rows.Clear(); })); |
|
3757 | foreach (List<string> data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
3735 | foreach (var data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
|
3758 | .Where(x => !string.IsNullOrEmpty(x)) |
3736 | .Where(x => !string.IsNullOrEmpty(x)) |
|
3759 | .Select((x, i) => new {Index = i, Value = x}) |
3737 | .Select((x, i) => new {Index = i, Value = x}) |
|
3760 | .GroupBy(x => x.Index/2) |
3738 | .GroupBy(x => x.Index/2) |
|
Line 3792... | Line 3770... | |||
3792 | vassalForm.BeginInvoke((MethodInvoker) (() => |
3770 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
3793 | { |
3771 | { |
|
3794 | switch (vassalForm.ExportCSVDialog.ShowDialog()) |
3772 | switch (vassalForm.ExportCSVDialog.ShowDialog()) |
|
3795 | { |
3773 | { |
|
3796 | case DialogResult.OK: |
3774 | case DialogResult.OK: |
|
3797 | string file = vassalForm.ExportCSVDialog.FileName; |
3775 | var file = vassalForm.ExportCSVDialog.FileName; |
|
3798 | new Thread(() => |
3776 | new Thread(() => |
|
3799 | { |
3777 | { |
|
3800 | vassalForm.BeginInvoke((MethodInvoker) (() => |
3778 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
3801 | { |
3779 | { |
|
3802 | try |
3780 | try |
|
3803 | { |
3781 | { |
|
3804 | vassalForm.StatusText.Text = @"exporting..."; |
3782 | vassalForm.StatusText.Text = @"exporting..."; |
|
3805 | vassalForm.StatusProgress.Value = 0; |
3783 | vassalForm.StatusProgress.Value = 0; |
|
Line 3806... | Line 3784... | |||
3806 | |
3784 | |
|
3807 | using (StreamWriter streamWriter = new StreamWriter(file, false, Encoding.UTF8)) |
3785 | using (var streamWriter = new StreamWriter(file, false, Encoding.UTF8)) |
|
3808 | { |
3786 | { |
|
3809 | foreach (DataGridViewRow estateListRow in EstateListGridView.Rows) |
3787 | foreach (DataGridViewRow estateListRow in EstateListGridView.Rows) |
|
3810 | { |
3788 | { |
|
3811 | streamWriter.WriteLine(CSV.FromEnumerable(new[] |
3789 | streamWriter.WriteLine(CSV.FromEnumerable(new[] |
|
Line 3840... | Line 3818... | |||
3840 | ResidentListBanGroup.Enabled = false; |
3818 | ResidentListBanGroup.Enabled = false; |
|
3841 | RegionTeleportGroup.Enabled = false; |
3819 | RegionTeleportGroup.Enabled = false; |
|
3842 | })); |
3820 | })); |
|
Line 3843... | Line 3821... | |||
3843 | |
3821 | |
|
3844 | // Enqueue all the agents to teleport home. |
3822 | // Enqueue all the agents to teleport home. |
|
3845 | Queue<UUID> agentsQueue = new Queue<UUID>(); |
3823 | var agentsQueue = new Queue<UUID>(); |
|
3846 | vassalForm.Invoke((MethodInvoker) (() => |
3824 | vassalForm.Invoke((MethodInvoker) (() => |
|
3847 | { |
3825 | { |
|
3848 | foreach ( |
3826 | foreach ( |
|
3849 | DataGridViewRow residentListRow in |
3827 | var residentListRow in |
|
3850 | ResidentListGridView.Rows.AsParallel() |
3828 | ResidentListGridView.Rows.AsParallel() |
|
3851 | .Cast<DataGridViewRow>() |
3829 | .Cast<DataGridViewRow>() |
|
3852 | .Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
3830 | .Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
|
3853 | { |
3831 | { |
|
Line 3875... | Line 3853... | |||
3875 | try |
3853 | try |
|
3876 | { |
3854 | { |
|
3877 | do |
3855 | do |
|
3878 | { |
3856 | { |
|
3879 | // Dequeue the first object. |
3857 | // Dequeue the first object. |
|
3880 | UUID agentUUID = agentsQueue.Dequeue(); |
3858 | var agentUUID = agentsQueue.Dequeue(); |
|
3881 | DataGridViewRow currentDataGridViewRow = null; |
3859 | DataGridViewRow currentDataGridViewRow = null; |
|
3882 | vassalForm.Invoke((MethodInvoker) (() => |
3860 | vassalForm.Invoke((MethodInvoker) (() => |
|
3883 | { |
3861 | { |
|
3884 | currentDataGridViewRow = vassalForm.ResidentListGridView.Rows.AsParallel() |
3862 | currentDataGridViewRow = vassalForm.ResidentListGridView.Rows.AsParallel() |
|
3885 | .Cast<DataGridViewRow>() |
3863 | .Cast<DataGridViewRow>() |
|
Line 3892... | Line 3870... | |||
3892 | if (currentDataGridViewRow == null) continue; |
3870 | if (currentDataGridViewRow == null) continue; |
|
Line 3893... | Line 3871... | |||
3893 | |
3871 | |
|
3894 | try |
3872 | try |
|
3895 | { |
3873 | { |
|
3896 | // Teleport the user home. |
3874 | // Teleport the user home. |
|
3897 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
3875 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
3898 | KeyValue.Escape(new Dictionary<string, string> |
3876 | KeyValue.Escape(new Dictionary<string, string> |
|
3899 | { |
3877 | { |
|
3900 | {"command", "estateteleportusershome"}, |
3878 | {"command", "estateteleportusershome"}, |
|
3901 | {"group", vassalConfiguration.Group}, |
3879 | {"group", vassalConfiguration.Group}, |
|
3902 | {"password", vassalConfiguration.Password}, |
3880 | {"password", vassalConfiguration.Password}, |
|
3903 | {"avatars", agentUUID.ToString()} |
3881 | {"avatars", agentUUID.ToString()} |
|
Line 3904... | Line 3882... | |||
3904 | }, wasOutput), vassalConfiguration.DataTimeout); |
3882 | }, wasOutput)).Result); |
|
3905 | |
3883 | |
|
Line 3906... | Line 3884... | |||
3906 | if (string.IsNullOrEmpty(result)) |
3884 | if (string.IsNullOrEmpty(result)) |
|
Line 3917... | Line 3895... | |||
3917 | { |
3895 | { |
|
3918 | vassalForm.StatusText.Text = @"Resident teleported home."; |
3896 | vassalForm.StatusText.Text = @"Resident teleported home."; |
|
3919 | currentDataGridViewRow.Selected = false; |
3897 | currentDataGridViewRow.Selected = false; |
|
3920 | currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightGreen; |
3898 | currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightGreen; |
|
3921 | foreach ( |
3899 | foreach ( |
|
3922 | DataGridViewCell cell in |
3900 | var cell in |
|
3923 | currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
3901 | currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
|
3924 | { |
3902 | { |
|
3925 | cell.ToolTipText = @"Resident teleported home."; |
3903 | cell.ToolTipText = @"Resident teleported home."; |
|
3926 | } |
3904 | } |
|
3927 | })); |
3905 | })); |
|
Line 3936... | Line 3914... | |||
3936 | { |
3914 | { |
|
3937 | vassalForm.StatusText.Text = ex.Message; |
3915 | vassalForm.StatusText.Text = ex.Message; |
|
3938 | currentDataGridViewRow.Selected = false; |
3916 | currentDataGridViewRow.Selected = false; |
|
3939 | currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightPink; |
3917 | currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightPink; |
|
3940 | foreach ( |
3918 | foreach ( |
|
3941 | DataGridViewCell cell in |
3919 | var cell in |
|
3942 | currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
3920 | currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
|
3943 | { |
3921 | { |
|
3944 | cell.ToolTipText = ex.Message; |
3922 | cell.ToolTipText = ex.Message; |
|
3945 | } |
3923 | } |
|
3946 | })); |
3924 | })); |
|
Line 3978... | Line 3956... | |||
3978 | { |
3956 | { |
|
3979 | try |
3957 | try |
|
3980 | { |
3958 | { |
|
3981 | Monitor.Enter(ClientInstanceTeleportLock); |
3959 | Monitor.Enter(ClientInstanceTeleportLock); |
|
Line 3982... | Line 3960... | |||
3982 | |
3960 | |
|
3983 | int waterHeight = 10; |
3961 | var waterHeight = 10; |
|
3984 | int terrainRaiseLimit = 100; |
3962 | var terrainRaiseLimit = 100; |
|
3985 | int terrainLowerLimit = -100; |
3963 | var terrainLowerLimit = -100; |
|
3986 | bool useEstateSun = true; |
3964 | var useEstateSun = true; |
|
3987 | bool fixedSun = false; |
3965 | var fixedSun = false; |
|
Line 3988... | Line 3966... | |||
3988 | int sunPosition = 18; |
3966 | var sunPosition = 18; |
|
Line 3989... | Line 3967... | |||
3989 | |
3967 | |
|
3990 | bool run = false; |
3968 | var run = false; |
|
3991 | |
3969 | |
|
3992 | vassalForm.Invoke((MethodInvoker) (() => |
3970 | vassalForm.Invoke((MethodInvoker) (() => |
|
Line 4034... | Line 4012... | |||
4034 | })); |
4012 | })); |
|
Line 4035... | Line 4013... | |||
4035 | |
4013 | |
|
Line 4036... | Line 4014... | |||
4036 | if (!run) return; |
4014 | if (!run) return; |
|
4037 | |
4015 | |
|
4038 | // Set the terrain variables. |
4016 | // Set the terrain variables. |
|
4039 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
4017 | var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
|
4040 | KeyValue.Escape(new Dictionary<string, string> |
4018 | KeyValue.Escape(new Dictionary<string, string> |
|
4041 | { |
4019 | { |
|
4042 | {"command", "setregionterrainvariables"}, |
4020 | {"command", "setregionterrainvariables"}, |
|
Line 4046... | Line 4024... | |||
4046 | {"terrainraiselimit", terrainRaiseLimit.ToString()}, |
4024 | {"terrainraiselimit", terrainRaiseLimit.ToString()}, |
|
4047 | {"terrainlowerlimit", terrainLowerLimit.ToString()}, |
4025 | {"terrainlowerlimit", terrainLowerLimit.ToString()}, |
|
4048 | {"useestatesun", useEstateSun.ToString()}, |
4026 | {"useestatesun", useEstateSun.ToString()}, |
|
4049 | {"fixedsun", fixedSun.ToString()}, |
4027 | {"fixedsun", fixedSun.ToString()}, |
|
4050 | {"sunposition", sunPosition.ToString()} |
4028 | {"sunposition", sunPosition.ToString()} |
|
4051 | }, wasOutput), vassalConfiguration.DataTimeout); |
4029 | }, wasOutput)).Result); |
|
Line 4052... | Line 4030... | |||
4052 | |
4030 | |
|
4053 | if (string.IsNullOrEmpty(result)) |
4031 | if (string.IsNullOrEmpty(result)) |
|
Line 4054... | Line 4032... | |||
4054 | throw new Exception("Error communicating with Corrade"); |
4032 | throw new Exception("Error communicating with Corrade"); |
|
Line 4082... | Line 4060... | |||
4082 | private void ReconnectRequested(object sender, EventArgs e) |
4060 | private void ReconnectRequested(object sender, EventArgs e) |
|
4083 | { |
4061 | { |
|
4084 | // Spawn a thread to check Corrade's connection status. |
4062 | // Spawn a thread to check Corrade's connection status. |
|
4085 | new Thread(() => |
4063 | new Thread(() => |
|
4086 | { |
4064 | { |
|
4087 | TcpClient tcpClient = new TcpClient(); |
4065 | var tcpClient = new TcpClient(); |
|
4088 | try |
4066 | try |
|
4089 | { |
4067 | { |
|
4090 | Uri uri = new Uri(vassalConfiguration.HTTPServerURL); |
4068 | var uri = new Uri(vassalConfiguration.HTTPServerURL); |
|
4091 | tcpClient.Connect(uri.Host, uri.Port); |
4069 | tcpClient.Connect(uri.Host, uri.Port); |
|
4092 | // port open |
4070 | // port open |
|
4093 | vassalForm.BeginInvoke((MethodInvoker) (() => { vassalForm.Tabs.Enabled = true; })); |
4071 | vassalForm.BeginInvoke((MethodInvoker) (() => { vassalForm.Tabs.Enabled = true; })); |
|
4094 | // set the loading spinner |
4072 | // set the loading spinner |
|
4095 | if (vassalForm.RegionAvatarsMap.Image == null) |
4073 | if (vassalForm.RegionAvatarsMap.Image == null) |
|
4096 | { |
4074 | { |
|
4097 | Assembly thisAssembly = Assembly.GetExecutingAssembly(); |
4075 | var thisAssembly = Assembly.GetExecutingAssembly(); |
|
4098 | Stream file = |
4076 | var file = |
|
4099 | thisAssembly.GetManifestResourceStream("Vassal.img.loading.gif"); |
4077 | thisAssembly.GetManifestResourceStream("Vassal.img.loading.gif"); |
|
4100 | switch (file != null) |
4078 | switch (file != null) |
|
4101 | { |
4079 | { |
|
4102 | case true: |
4080 | case true: |
|
4103 | vassalForm.BeginInvoke((MethodInvoker) (() => |
4081 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
Line 4341... | Line 4319... | |||
4341 | public const string TEXT_PLAIN = @"text/plain"; |
4319 | public const string TEXT_PLAIN = @"text/plain"; |
|
4342 | public const string WWW_FORM_URLENCODED = @"application/x-www-form-urlencoded"; |
4320 | public const string WWW_FORM_URLENCODED = @"application/x-www-form-urlencoded"; |
|
4343 | } |
4321 | } |
|
4344 | } |
4322 | } |
|
Line -... | Line 4323... | |||
- | 4323 | |
||
- | 4324 | private void RequestBatchSetCovenant(object sender, EventArgs e) |
||
- | 4325 | { |
||
- | 4326 | // Block teleports and disable button. |
||
- | 4327 | vassalForm.Invoke((MethodInvoker)(() => |
||
- | 4328 | { |
||
- | 4329 | vassalForm.BatchSetCovenantButton.Enabled = false; |
||
- | 4330 | vassalForm.SetCovenantNotecardUUIDBox.Enabled = false; |
||
- | 4331 | RegionTeleportGroup.Enabled = false; |
||
- | 4332 | })); |
||
- | 4333 | |
||
- | 4334 | // Enqueue all the regions to set covenant. |
||
- | 4335 | var batchSetCovenantQueue = new Queue<KeyValuePair<string, Vector3>>(); |
||
- | 4336 | vassalForm.Invoke((MethodInvoker)(() => |
||
- | 4337 | { |
||
- | 4338 | foreach ( |
||
- | 4339 | var topCollidersRow in |
||
- | 4340 | BatchSetCovenantGridView.Rows.AsParallel() |
||
- | 4341 | .Cast<DataGridViewRow>() |
||
- | 4342 | .Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
||
- | 4343 | { |
||
- | 4344 | Vector3 objectPosition; |
||
- | 4345 | var regionName = topCollidersRow.Cells["BatchSetCovenantRegionName"].Value.ToString(); |
||
- | 4346 | if (string.IsNullOrEmpty(regionName) || |
||
- | 4347 | !Vector3.TryParse(topCollidersRow.Cells["BatchSetCovenantPosition"].Value.ToString(), |
||
- | 4348 | out objectPosition)) |
||
- | 4349 | continue; |
||
- | 4350 | batchSetCovenantQueue.Enqueue(new KeyValuePair<string, Vector3>(regionName, objectPosition)); |
||
- | 4351 | } |
||
- | 4352 | })); |
||
- | 4353 | |
||
- | 4354 | // If no rows were selected, enable teleports, the return button and return. |
||
- | 4355 | if (batchSetCovenantQueue.Count.Equals(0)) |
||
- | 4356 | { |
||
- | 4357 | vassalForm.Invoke((MethodInvoker)(() => |
||
- | 4358 | { |
||
- | 4359 | vassalForm.BatchSetCovenantButton.Enabled = true; |
||
- | 4360 | vassalForm.SetCovenantNotecardUUIDBox.Enabled = true; |
||
- | 4361 | RegionTeleportGroup.Enabled = true; |
||
- | 4362 | })); |
||
- | 4363 | return; |
||
- | 4364 | } |
||
- | 4365 | |
||
- | 4366 | new Thread(() => |
||
- | 4367 | { |
||
- | 4368 | Monitor.Enter(ClientInstanceTeleportLock); |
||
- | 4369 | |
||
- | 4370 | try |
||
- | 4371 | { |
||
- | 4372 | do |
||
- | 4373 | { |
||
- | 4374 | // Dequeue the first object. |
||
- | 4375 | var batchSetCovenantRegionData = batchSetCovenantQueue.Dequeue(); |
||
- | 4376 | DataGridViewRow currentDataGridViewRow = null; |
||
- | 4377 | vassalForm.Invoke((MethodInvoker)(() => |
||
- | 4378 | { |
||
- | 4379 | currentDataGridViewRow = vassalForm.BatchSetCovenantGridView.Rows.AsParallel() |
||
- | 4380 | .Cast<DataGridViewRow>() |
||
- | 4381 | .FirstOrDefault( |
||
- | 4382 | o => |
||
- | 4383 | o.Cells["BatchSetCovenantRegionName"].Value.ToString() |
||
- | 4384 | .Equals(batchSetCovenantRegionData.Key, StringComparison.OrdinalIgnoreCase) && |
||
- | 4385 | o.Cells["BatchSetCovenantPosition"].Value.ToString() |
||
- | 4386 | .Equals(batchSetCovenantRegionData.Value.ToString(), |
||
4345 | |
4387 | StringComparison.OrdinalIgnoreCase)); |
|
- | 4388 | })); |
||
- | 4389 | |
||
- | 4390 | if (currentDataGridViewRow == null) continue; |
||
- | 4391 | |
||
- | 4392 | try |
||
- | 4393 | { |
||
- | 4394 | var success = false; |
||
- | 4395 | string result; |
||
- | 4396 | |
||
- | 4397 | // Retry to teleport to each region a few times. |
||
- | 4398 | var teleportRetries = 3; |
||
- | 4399 | do |
||
- | 4400 | { |
||
- | 4401 | vassalForm.Invoke((MethodInvoker)(() => |
||
- | 4402 | { |
||
- | 4403 | vassalForm.StatusText.Text = @"Attempting to teleport to " + batchSetCovenantRegionData.Key + |
||
- | 4404 | @" " + @"(" + |
||
- | 4405 | teleportRetries.ToString(Utils.EnUsCulture) + |
||
- | 4406 | @")"; |
||
- | 4407 | })); |
||
- | 4408 | |
||
- | 4409 | // Teleport to the region. |
||
- | 4410 | result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
||
- | 4411 | KeyValue.Escape(new Dictionary<string, string> |
||
- | 4412 | { |
||
- | 4413 | {"command", "teleport"}, |
||
- | 4414 | {"group", vassalConfiguration.Group}, |
||
- | 4415 | {"password", vassalConfiguration.Password}, |
||
- | 4416 | {"position", batchSetCovenantRegionData.Value.ToString()}, |
||
- | 4417 | {"region", batchSetCovenantRegionData.Key}, |
||
- | 4418 | {"fly", "True"} |
||
- | 4419 | }, wasOutput)).Result); |
||
- | 4420 | |
||
- | 4421 | if (string.IsNullOrEmpty(result)) |
||
- | 4422 | { |
||
- | 4423 | vassalForm.Invoke( |
||
- | 4424 | (MethodInvoker) |
||
- | 4425 | (() => |
||
- | 4426 | { |
||
- | 4427 | vassalForm.StatusText.Text = @"Error communicating with Corrade."; |
||
- | 4428 | })); |
||
- | 4429 | continue; |
||
- | 4430 | } |
||
- | 4431 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
||
- | 4432 | { |
||
- | 4433 | vassalForm.Invoke( |
||
- | 4434 | (MethodInvoker) |
||
- | 4435 | (() => |
||
- | 4436 | { |
||
- | 4437 | vassalForm.StatusText.Text = @"No success status could be retrieved. "; |
||
- | 4438 | })); |
||
- | 4439 | continue; |
||
- | 4440 | } |
||
- | 4441 | switch (success) |
||
- | 4442 | { |
||
- | 4443 | case true: |
||
- | 4444 | vassalForm.Invoke( |
||
- | 4445 | (MethodInvoker) |
||
- | 4446 | (() => { vassalForm.StatusText.Text = @"Teleport succeeded."; })); |
||
- | 4447 | break; |
||
- | 4448 | default: |
||
- | 4449 | // In case the destination is to close (Corrade status code 37559), |
||
- | 4450 | // then we are on the same region so no need to retry. |
||
- | 4451 | uint status; //37559 |
||
- | 4452 | switch ( |
||
- | 4453 | uint.TryParse(wasInput(KeyValue.Get("status", result)), out status) && |
||
- | 4454 | status.Equals(37559)) |
||
- | 4455 | { |
||
- | 4456 | case true: // We are on the region already! |
||
- | 4457 | success = true; |
||
- | 4458 | break; |
||
- | 4459 | default: |
||
- | 4460 | vassalForm.Invoke( |
||
- | 4461 | (MethodInvoker) |
||
- | 4462 | (() => { vassalForm.StatusText.Text = @"Teleport failed."; })); |
||
- | 4463 | break; |
||
- | 4464 | } |
||
- | 4465 | break; |
||
- | 4466 | } |
||
- | 4467 | |
||
- | 4468 | // Pause for teleport (10 teleports / 15s allowed). |
||
- | 4469 | Thread.Sleep(700); |
||
- | 4470 | } while (!success && !(--teleportRetries).Equals(0)); |
||
- | 4471 | |
||
- | 4472 | if (!success) |
||
- | 4473 | throw new Exception("Failed to teleport to region."); |
||
- | 4474 | |
||
- | 4475 | result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
||
- | 4476 | KeyValue.Escape(new Dictionary<string, string> |
||
- | 4477 | { |
||
- | 4478 | {"command", "getregiondata"}, |
||
- | 4479 | {"group", vassalConfiguration.Group}, |
||
- | 4480 | {"password", vassalConfiguration.Password}, |
||
- | 4481 | {"data", "IsEstateManager"} |
||
- | 4482 | }, wasOutput)).Result); |
||
- | 4483 | |
||
- | 4484 | if (string.IsNullOrEmpty(result)) |
||
- | 4485 | throw new Exception("Error communicating with Corrade."); |
||
- | 4486 | |
||
- | 4487 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
||
- | 4488 | throw new Exception("No success status could be retrieved."); |
||
- | 4489 | |
||
- | 4490 | if (!success) |
||
- | 4491 | throw new Exception("Could not retrieve estate rights."); |
||
- | 4492 | |
||
- | 4493 | var data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
||
- | 4494 | if (!data.Count.Equals(2)) |
||
- | 4495 | throw new Exception("Could not retrieve estate rights."); |
||
- | 4496 | |
||
- | 4497 | bool isEstateManager; |
||
- | 4498 | switch ( |
||
- | 4499 | bool.TryParse(data[data.IndexOf("IsEstateManager") + 1], out isEstateManager) && |
||
- | 4500 | isEstateManager) |
||
- | 4501 | { |
||
- | 4502 | case true: // we are an estate manager |
||
- | 4503 | result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
||
- | 4504 | KeyValue.Escape(new Dictionary<string, string> |
||
- | 4505 | { |
||
- | 4506 | {"command", "setestatecovenant"}, |
||
- | 4507 | {"group", vassalConfiguration.Group}, |
||
- | 4508 | {"password", vassalConfiguration.Password}, |
||
- | 4509 | {"item", vassalForm.SetCovenantNotecardUUIDBox.Text} |
||
- | 4510 | }, wasOutput)).Result); |
||
- | 4511 | |
||
- | 4512 | if (string.IsNullOrEmpty(result)) |
||
- | 4513 | throw new Exception("Error communicating with Corrade."); |
||
- | 4514 | |
||
- | 4515 | if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
||
- | 4516 | throw new Exception("No success status could be retrieved."); |
||
- | 4517 | |
||
- | 4518 | if (!success) |
||
Line -... | Line 4519... | |||
- | 4519 | throw new Exception("Could not set region covenant."); |
||
- | 4520 | |
||
- | 4521 | vassalForm.Invoke((MethodInvoker)(() => |
||
- | 4522 | { |
||
- | 4523 | vassalForm.StatusText.Text = @"Region covenant set."; |
||
- | 4524 | currentDataGridViewRow.Selected = false; |
||
- | 4525 | currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightGreen; |
||
- | 4526 | foreach ( |
||
- | 4527 | var cell in |
||
- | 4528 | currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
||
- | 4529 | { |
||
- | 4530 | cell.ToolTipText = @"Region covenant set."; |
||
- | 4531 | } |
||
- | 4532 | })); |
||
- | 4533 | break; |
||
- | 4534 | default: |
||
- | 4535 | throw new Exception("No estate manager rights for setting covenant."); |
||
- | 4536 | } |
||
- | 4537 | } |
||
- | 4538 | catch (Exception ex) |
||
- | 4539 | { |
||
- | 4540 | vassalForm.Invoke((MethodInvoker)(() => |
||
- | 4541 | { |
||
- | 4542 | vassalForm.StatusText.Text = ex.Message; |
||
- | 4543 | currentDataGridViewRow.Selected = false; |
||
- | 4544 | currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightPink; |
||
- | 4545 | foreach ( |
||
- | 4546 | var cell in |
||
- | 4547 | currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
||
- | 4548 | { |
||
- | 4549 | cell.ToolTipText = ex.Message; |
||
- | 4550 | } |
||
- | 4551 | })); |
||
- | 4552 | } |
||
- | 4553 | finally |
||
- | 4554 | { |
||
- | 4555 | // Pause for teleport (10 teleports / 15s allowed). |
||
- | 4556 | Thread.Sleep(700); |
||
- | 4557 | } |
||
- | 4558 | } while (!batchSetCovenantQueue.Count.Equals(0)); |
||
- | 4559 | } |
||
- | 4560 | catch (Exception) |
||
- | 4561 | { |
||
- | 4562 | } |
||
- | 4563 | finally |
||
- | 4564 | { |
||
- | 4565 | Monitor.Exit(ClientInstanceTeleportLock); |
||
- | 4566 | // Allow teleports and enable button. |
||
- | 4567 | vassalForm.BeginInvoke((MethodInvoker)(() => |
||
- | 4568 | { |
||
- | 4569 | vassalForm.BatchSetCovenantButton.Enabled = true; |
||
- | 4570 | vassalForm.SetCovenantNotecardUUIDBox.Enabled = true; |
||
4346 | #region CRYPTOGRAPHY |
4571 | RegionTeleportGroup.Enabled = true; |
|
- | 4572 | })); |
||
- | 4573 | } |
||
- | 4574 | }) |
||
4347 | |
4575 | { IsBackground = true }.Start(); |
|
4348 | #endregion |
4576 | } |
|
4349 | } |
4577 | } |