/Vassal/Vassal/VassalForm.cs |
@@ -12,6 +12,7 @@ |
using System.IO; |
using System.Linq; |
using System.Net; |
using System.Net.Http.Headers; |
using System.Net.Sockets; |
using System.Reflection; |
using System.Text; |
@@ -39,8 +40,14 @@ |
public static Vassal vassalForm; |
public static readonly object ClientInstanceTeleportLock = new object(); |
public static readonly object RegionsStateCheckLock = new object(); |
public static Web.wasHTTPClient HTTPClient; |
|
/// <summary> |
/// Corrade version. |
/// </summary> |
public static readonly string VASSAL_VERSION = Assembly.GetEntryAssembly().GetName().Version.ToString(); |
|
/// <summary> |
/// Corrade's input filter function. |
/// </summary> |
private static readonly Func<string, string> wasInput = o => |
@@ -47,7 +54,7 @@ |
{ |
if (string.IsNullOrEmpty(o)) return string.Empty; |
|
foreach (Filter filter in vassalConfiguration.InputFilters) |
foreach (var filter in vassalConfiguration.InputFilters) |
{ |
switch (filter) |
{ |
@@ -83,7 +90,7 @@ |
{ |
if (string.IsNullOrEmpty(o)) return string.Empty; |
|
foreach (Filter filter in vassalConfiguration.OutputFilters) |
foreach (var filter in vassalConfiguration.OutputFilters) |
{ |
switch (filter) |
{ |
@@ -116,7 +123,7 @@ |
{ |
try |
{ |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "getregiondata"}, |
@@ -123,7 +130,7 @@ |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"data", "Name"} |
}, wasOutput), 60000); |
}, wasOutput)).Result); |
bool success; |
if (string.IsNullOrEmpty(result) || |
!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
@@ -172,69 +179,17 @@ |
vassalForm = this; |
} |
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
/// <summary> |
/// Sends a post request to an URL with set key-value pairs. |
/// </summary> |
/// <param name="URL">the url to send the message to</param> |
/// <param name="message">key-value pairs to send</param> |
/// <param name="millisecondsTimeout">the time in milliseconds for the request to timeout</param> |
private static string wasPOST(string URL, Dictionary<string, string> message, uint millisecondsTimeout) |
private void ShowToolTip(object sender, EventArgs e) |
{ |
try |
{ |
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(URL); |
request.UserAgent = VASSAL_CONSTANTS.USER_AGENT; |
request.Proxy = WebRequest.DefaultWebProxy; |
request.Pipelined = true; |
request.KeepAlive = true; |
request.Timeout = (int) millisecondsTimeout; |
request.ReadWriteTimeout = (int) millisecondsTimeout; |
request.AllowAutoRedirect = true; |
request.AllowWriteStreamBuffering = true; |
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; |
request.Method = WebRequestMethods.Http.Post; |
// set the content type based on chosen output filers |
switch (vassalConfiguration.OutputFilters.Last()) |
vassalForm.BeginInvoke( |
(Action)(() => |
{ |
case Filter.RFC1738: |
request.ContentType = VASSAL_CONSTANTS.CONTENT_TYPE.WWW_FORM_URLENCODED; |
break; |
default: |
request.ContentType = VASSAL_CONSTANTS.CONTENT_TYPE.TEXT_PLAIN; |
break; |
} |
// send request |
using (Stream requestStream = request.GetRequestStream()) |
{ |
using (StreamWriter dataStream = new StreamWriter(requestStream)) |
PictureBox pictureBox = sender as PictureBox; |
if (pictureBox != null) |
{ |
dataStream.Write(KeyValue.Encode(message)); |
toolTip1.Show(toolTip1.GetToolTip(pictureBox), pictureBox); |
} |
} |
// read response |
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) |
{ |
using (Stream responseStream = response.GetResponseStream()) |
{ |
if (responseStream != null) |
{ |
using ( |
StreamReader streamReader = new StreamReader(responseStream)) |
{ |
return streamReader.ReadToEnd(); |
} |
} |
} |
} |
} |
catch (Exception) |
{ |
} |
|
return null; |
})); |
} |
|
private void RegionSelected(object sender, EventArgs e) |
@@ -253,12 +208,12 @@ |
|
Monitor.Enter(ClientInstanceTeleportLock); |
|
string selectedRegionName = string.Empty; |
Vector3 selectedRegionPosition = Vector3.Zero; |
bool startTeleport = false; |
var selectedRegionName = string.Empty; |
var selectedRegionPosition = Vector3.Zero; |
var startTeleport = false; |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
ListViewItem listViewItem = LoadedRegionsBox.SelectedItem as ListViewItem; |
var listViewItem = LoadedRegionsBox.SelectedItem as ListViewItem; |
switch (listViewItem != null && LoadedRegionsBox.SelectedIndex != -1) |
{ |
case true: |
@@ -285,8 +240,8 @@ |
// Pause for teleport (10 teleports / 15s allowed). |
Thread.Sleep(700); |
|
int elapsedSeconds = 0; |
Timer teleportTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); |
var elapsedSeconds = 0; |
var teleportTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); |
teleportTimer.Elapsed += (o, p) => |
{ |
vassalForm.Invoke((MethodInvoker) (() => |
@@ -301,10 +256,10 @@ |
}; |
teleportTimer.Start(); |
string result = null; |
ManualResetEvent receivedPOST = new ManualResetEvent(false); |
var receivedPOST = new ManualResetEvent(false); |
new Thread(() => |
{ |
result = wasInput(wasPOST(vassalConfiguration.HTTPServerURL, |
result = wasInput(Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "teleport"}, |
@@ -313,7 +268,7 @@ |
{"region", selectedRegionName}, |
{"position", selectedRegionPosition.ToString()}, |
{"fly", "True"} |
}, wasOutput), vassalConfiguration.TeleportTimeout)); |
}, wasOutput)).Result)); |
receivedPOST.Set(); |
}) {IsBackground = true}.Start(); |
receivedPOST.WaitOne((int) vassalConfiguration.TeleportTimeout, false); |
@@ -364,8 +319,8 @@ |
vassalForm.StatusProgress.Value = 100; |
vassalForm.RegionTeleportGroup.Enabled = true; |
// Set the map image to the loading spinner. |
Assembly thisAssembly = Assembly.GetExecutingAssembly(); |
Stream file = |
var thisAssembly = Assembly.GetExecutingAssembly(); |
var file = |
thisAssembly.GetManifestResourceStream("Vassal.img.loading.gif"); |
switch (file != null) |
{ |
@@ -434,7 +389,7 @@ |
private void SettingsRequested(object sender, EventArgs e) |
{ |
vassalForm.BeginInvoke((MethodInvoker) (() => { VassalStatusGroup.Enabled = false; })); |
SettingsForm settingsForm = new SettingsForm {TopMost = true}; |
var settingsForm = new SettingsForm {TopMost = true}; |
settingsForm.Show(); |
} |
|
@@ -467,6 +422,20 @@ |
VassalConfiguration.Load(VASSAL_CONSTANTS.VASSAL_CONFIGURATION_FILE, ref vassalConfiguration); |
// Apply settings |
RegionRestartDelayBox.Text = vassalConfiguration.RegionRestartDelay.ToString(Utils.EnUsCulture); |
// HTTP |
string mediaType; |
switch (vassalConfiguration.InputFilters.LastOrDefault()) |
{ |
case Filter.RFC1738: |
mediaType = @"application/x-www-form-urlencoded"; |
break; |
default: |
mediaType = @"text/plain"; |
break; |
} |
// Create HTTP Client |
Vassal.HTTPClient = new Web.wasHTTPClient(new ProductInfoHeaderValue(@"Vassal", |
Vassal.VASSAL_VERSION), new CookieContainer(), mediaType, vassalConfiguration.ServicesTimeout); |
} |
|
// Get all the regions if they exist. |
@@ -473,7 +442,7 @@ |
if (File.Exists(VASSAL_CONSTANTS.VASSAL_REGIONS)) |
{ |
Vector3 localPosition; |
List<KeyValuePair<string, Vector3>> ConfiguredRegions = new List<KeyValuePair<string, Vector3>>( |
var ConfiguredRegions = new List<KeyValuePair<string, Vector3>>( |
File.ReadAllLines(VASSAL_CONSTANTS.VASSAL_REGIONS) |
.Select(o => new List<string>(CSV.ToEnumerable(o))) |
.Where(o => o.Count == 2) |
@@ -489,12 +458,18 @@ |
.ToArray()); |
// Populate the batch restart grid view. |
BatchRestartGridView.Rows.Clear(); |
foreach (KeyValuePair<string, Vector3> data in ConfiguredRegions) |
foreach (var data in ConfiguredRegions) |
{ |
BatchRestartGridView.Rows.Add(data.Key, data.Value.ToString()); |
} |
// Populate the batch covenant grid view. |
BatchSetCovenantGridView.Rows.Clear(); |
foreach (var data in ConfiguredRegions) |
{ |
BatchSetCovenantGridView.Rows.Add(data.Key, data.Value.ToString()); |
} |
// Populate the regions state grid view. |
foreach (KeyValuePair<string, Vector3> data in ConfiguredRegions) |
foreach (var data in ConfiguredRegions) |
{ |
RegionsStateGridView.Rows.Add(data.Key, "Check pening..."); |
} |
@@ -508,8 +483,8 @@ |
try |
{ |
// Check Corrade connection status. |
TcpClient tcpClient = new TcpClient(); |
Uri uri = new Uri(vassalConfiguration.HTTPServerURL); |
var tcpClient = new TcpClient(); |
var uri = new Uri(vassalConfiguration.HTTPServerURL); |
tcpClient.Connect(uri.Host, uri.Port); |
// port open |
vassalForm.BeginInvoke((MethodInvoker) (() => |
@@ -516,8 +491,8 @@ |
{ |
vassalForm.CurrentRegionAt.Visible = true; |
vassalForm.CurrentRegionName.Visible = true; |
Assembly thisAssembly = Assembly.GetExecutingAssembly(); |
Stream file = |
var thisAssembly = Assembly.GetExecutingAssembly(); |
var file = |
thisAssembly.GetManifestResourceStream("Vassal.img.online.png"); |
switch (file != null) |
{ |
@@ -540,8 +515,8 @@ |
{ |
vassalForm.CurrentRegionAt.Visible = false; |
vassalForm.CurrentRegionName.Visible = false; |
Assembly thisAssembly = Assembly.GetExecutingAssembly(); |
Stream file = |
var thisAssembly = Assembly.GetExecutingAssembly(); |
var file = |
thisAssembly.GetManifestResourceStream("Vassal.img.offline.png"); |
switch (file != null) |
{ |
@@ -561,7 +536,7 @@ |
try |
{ |
// Get the simulator name and if we are an estate manager. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "getregiondata"}, |
@@ -574,7 +549,7 @@ |
"IsEstateManager" |
}) |
} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
bool success; |
if (string.IsNullOrEmpty(result) || |
@@ -581,7 +556,7 @@ |
!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
throw new Exception(); |
|
List<string> data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
var data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
if (data.Count.Equals(0)) |
throw new Exception(); |
|
@@ -651,7 +626,7 @@ |
overviewTabTimer.Elapsed += (o, p) => |
{ |
// Do not do anything in case the tab is not selected. |
bool run = false; |
var run = false; |
vassalForm.Invoke((MethodInvoker) (() => { run = Tabs.SelectedTab.Equals(OverviewTab); })); |
|
if (!run) |
@@ -665,10 +640,10 @@ |
try |
{ |
// Start measuring the lag to Corrade. |
Stopwatch stopWatch = new Stopwatch(); |
var stopWatch = new Stopwatch(); |
stopWatch.Start(); |
// Get the statistics. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "getregiondata"}, |
@@ -692,7 +667,7 @@ |
"AvatarPositions" |
}) |
} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
stopWatch.Stop(); |
|
bool success; |
@@ -700,7 +675,7 @@ |
!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
throw new Exception(); |
|
List<string> data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
var data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
if (data.Count.Equals(0)) |
throw new Exception(); |
|
@@ -741,7 +716,7 @@ |
// Get avatar positions. |
// Pattern: [...], X, 10, Y, 63, Z, 200, [...], X, 52, Y, 73, Z, 55, [...[...]] |
float X = 0, Y = 0, Z = 0; |
List<Vector3> positions = data.Select((x, i) => new {Item = x, Index = i}) |
var positions = data.Select((x, i) => new {Item = x, Index = i}) |
.Where(x => x.Item.Equals("X") || x.Item.Equals("Y") || x.Item.Equals("Z")) |
.Select(z => data[z.Index + 1]).Select((x, i) => new {Value = x, Index = i}) |
.GroupBy(x => x.Index/3) |
@@ -754,7 +729,7 @@ |
.ToList(); |
|
// Get the map image. |
result = wasPOST(vassalConfiguration.HTTPServerURL, |
result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "getgridregiondata"}, |
@@ -761,7 +736,7 @@ |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"data", "MapImageID"} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result) || |
!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
@@ -770,7 +745,7 @@ |
data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
if (!data.Count.Equals(2)) |
throw new Exception(); |
result = wasPOST(vassalConfiguration.HTTPServerURL, |
result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "download"}, |
@@ -779,20 +754,20 @@ |
{"item", data.Last()}, |
{"type", "Texture"}, |
{"format", "Jpeg"} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
if (string.IsNullOrEmpty(result) || |
!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
throw new Exception(); |
byte[] mapImageBytes = Convert.FromBase64String(wasInput(KeyValue.Get("data", result))); |
var mapImageBytes = Convert.FromBase64String(wasInput(KeyValue.Get("data", result))); |
Image mapImage; |
using (MemoryStream memoryStream = new MemoryStream(mapImageBytes, 0, mapImageBytes.Length)) |
using (var memoryStream = new MemoryStream(mapImageBytes, 0, mapImageBytes.Length)) |
{ |
mapImage = Image.FromStream(memoryStream); |
} |
|
// Draw the avatars onto the map. |
Graphics mapGraphics = Graphics.FromImage(mapImage); |
foreach (Vector3 position in positions) |
var mapGraphics = Graphics.FromImage(mapImage); |
foreach (var position in positions) |
{ |
mapGraphics.FillEllipse(Brushes.Chartreuse, |
new Rectangle((int) position.X, (int) position.Y, 4, 4)); |
@@ -817,7 +792,7 @@ |
regionsStateTabTimer.Elapsed += (o, p) => |
{ |
// Do not do anything in case the tab is not selected. |
bool run = false; |
var run = false; |
vassalForm.Invoke((MethodInvoker) (() => { run = Tabs.SelectedTab.Equals(RegionsStateTab); })); |
|
if (!run) |
@@ -830,7 +805,7 @@ |
|
try |
{ |
string regionName = string.Empty; |
var regionName = string.Empty; |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
regionName = |
@@ -844,7 +819,7 @@ |
throw new Exception(); |
|
// Get the region status. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "getgridregiondata"}, |
@@ -852,7 +827,7 @@ |
{"password", vassalConfiguration.Password}, |
{"region", regionName}, |
{"data", "Access"} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
bool success; |
if (string.IsNullOrEmpty(result) || |
@@ -859,11 +834,11 @@ |
!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
throw new Exception(); |
|
List<string> data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
var data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
if (!data.Count.Equals(2)) |
throw new Exception(); |
|
string status = data.Last(); |
var status = data.Last(); |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
switch (status) |
@@ -911,7 +886,7 @@ |
estateTopTabTimer.Elapsed += (o, p) => |
{ |
// Do not do anything in case the tab is not selected. |
bool run = false; |
var run = false; |
vassalForm.Invoke((MethodInvoker) (() => { run = Tabs.SelectedTab.Equals(EstateTopTab); })); |
|
if (!run) |
@@ -925,7 +900,7 @@ |
try |
{ |
// Get the top scripts. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "getregiontop"}, |
@@ -932,7 +907,7 @@ |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"type", "scripts"} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
bool success; |
if (string.IsNullOrEmpty(result) || |
@@ -939,7 +914,7 @@ |
!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
throw new Exception(); |
|
HashSet<List<string>> data = |
var data = |
new HashSet<List<string>>(CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
.Select((x, i) => new {Index = i, Value = x}) |
.GroupBy(x => x.Index/5) |
@@ -951,7 +926,7 @@ |
{ |
// Remove rows that are not in the data update. |
foreach ( |
int index in |
var index in |
TopScriptsGridView.Rows.AsParallel().Cast<DataGridViewRow>() |
.Where( |
topScriptsRow => |
@@ -961,9 +936,9 @@ |
TopScriptsGridView.Rows.RemoveAt(index); |
} |
// Now update or add new data. |
foreach (List<string> dataComponents in data.Where(q => q.Count.Equals(5))) |
foreach (var dataComponents in data.Where(q => q.Count.Equals(5))) |
{ |
DataGridViewRow row = |
var row = |
TopScriptsGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.FirstOrDefault(q => q.Cells["TopScriptsUUID"].Value.Equals(dataComponents[2])); |
@@ -985,7 +960,7 @@ |
})); |
|
// Get the top colliders. |
result = wasPOST(vassalConfiguration.HTTPServerURL, |
result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "getregiontop"}, |
@@ -992,7 +967,7 @@ |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"type", "colliders"} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result) || |
!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
@@ -1009,7 +984,7 @@ |
{ |
// Remove rows that are not in the data update. |
foreach ( |
int index in |
var index in |
TopCollidersGridView.Rows.AsParallel().Cast<DataGridViewRow>() |
.Where( |
topCollidersRow => |
@@ -1019,9 +994,9 @@ |
TopCollidersGridView.Rows.RemoveAt(index); |
} |
// Now update or add new data. |
foreach (List<string> dataComponents in data.Where(q => q.Count.Equals(5))) |
foreach (var dataComponents in data.Where(q => q.Count.Equals(5))) |
{ |
DataGridViewRow row = |
var row = |
TopCollidersGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.FirstOrDefault(q => q.Cells["TopCollidersUUID"].Value.Equals(dataComponents[2])); |
@@ -1055,7 +1030,7 @@ |
residentListTabTimer.Elapsed += (o, p) => |
{ |
// Do not do anything in case the tab is not selected. |
bool run = false; |
var run = false; |
vassalForm.Invoke((MethodInvoker) (() => { run = Tabs.SelectedTab.Equals(ResidentListTab); })); |
|
if (!run) |
@@ -1069,7 +1044,7 @@ |
try |
{ |
// Get the avatar positions. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "getavatarpositions"}, |
@@ -1076,7 +1051,7 @@ |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"entity", "region"} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
bool success; |
if (string.IsNullOrEmpty(result) || |
@@ -1083,7 +1058,7 @@ |
!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
throw new Exception(); |
|
HashSet<List<string>> data = |
var data = |
new HashSet<List<string>>(CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
.Select((x, i) => new {Index = i, Value = x}) |
.GroupBy(x => x.Index/3) |
@@ -1095,7 +1070,7 @@ |
{ |
// Remove rows that are not in the data update. |
foreach ( |
int index in |
var index in |
ResidentListGridView.Rows.AsParallel().Cast<DataGridViewRow>() |
.Where( |
residentListRow => |
@@ -1105,9 +1080,9 @@ |
ResidentListGridView.Rows.RemoveAt(index); |
} |
// Now update or add new data. |
foreach (List<string> dataComponents in data.Where(q => q.Count.Equals(3))) |
foreach (var dataComponents in data.Where(q => q.Count.Equals(3))) |
{ |
DataGridViewRow row = |
var row = |
ResidentListGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.FirstOrDefault(q => q.Cells["ResidentListUUID"].Value.Equals(dataComponents[1])); |
@@ -1137,7 +1112,7 @@ |
estateTexturesTabTimer.Elapsed += (o, p) => |
{ |
// Do not do anything in case the tab is not selected. |
bool run = false; |
var run = false; |
vassalForm.Invoke((MethodInvoker) (() => { run = Tabs.SelectedTab.Equals(EstateTexturesTab); })); |
|
if (!run) |
@@ -1151,13 +1126,13 @@ |
try |
{ |
// Get the region terrain texture UUIDs. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "getregionterraintextures"}, |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
bool success; |
if (string.IsNullOrEmpty(result) || |
@@ -1164,7 +1139,7 @@ |
!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
throw new Exception(); |
|
List<string> data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
var data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
if (!data.Count.Equals(4)) |
throw new Exception(); |
|
@@ -1194,7 +1169,7 @@ |
|
Parallel.ForEach(Enumerable.Range(0, 4), i => |
{ |
result = wasPOST(vassalConfiguration.HTTPServerURL, |
result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "download"}, |
@@ -1203,14 +1178,14 @@ |
{"item", data[i]}, |
{"type", "Texture"}, |
{"format", "Jpeg"} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result) || |
!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
return; |
|
byte[] mapImageBytes = Convert.FromBase64String(wasInput(KeyValue.Get("data", result))); |
using (MemoryStream memoryStream = new MemoryStream(mapImageBytes, 0, mapImageBytes.Length)) |
var mapImageBytes = Convert.FromBase64String(wasInput(KeyValue.Get("data", result))); |
using (var memoryStream = new MemoryStream(mapImageBytes, 0, mapImageBytes.Length)) |
{ |
groundTextureImages[i] = Image.FromStream(memoryStream); |
} |
@@ -1255,7 +1230,7 @@ |
{ |
// Clear any selection. |
LoadedRegionsBox.SelectedIndex = -1; |
RegionEditForm regionEditForm = new RegionEditForm {TopMost = true}; |
var regionEditForm = new RegionEditForm {TopMost = true}; |
regionEditForm.Show(); |
} |
|
@@ -1271,7 +1246,7 @@ |
switch (vassalForm.ExportCSVDialog.ShowDialog()) |
{ |
case DialogResult.OK: |
string file = vassalForm.ExportCSVDialog.FileName; |
var file = vassalForm.ExportCSVDialog.FileName; |
new Thread(() => |
{ |
vassalForm.BeginInvoke((MethodInvoker) (() => |
@@ -1281,7 +1256,7 @@ |
vassalForm.StatusText.Text = @"exporting..."; |
vassalForm.StatusProgress.Value = 0; |
|
using (StreamWriter streamWriter = new StreamWriter(file, false, Encoding.UTF8)) |
using (var streamWriter = new StreamWriter(file, false, Encoding.UTF8)) |
{ |
foreach (DataGridViewRow topScriptsRow in TopScriptsGridView.Rows) |
{ |
@@ -1318,7 +1293,7 @@ |
switch (vassalForm.ExportCSVDialog.ShowDialog()) |
{ |
case DialogResult.OK: |
string file = vassalForm.ExportCSVDialog.FileName; |
var file = vassalForm.ExportCSVDialog.FileName; |
new Thread(() => |
{ |
vassalForm.BeginInvoke((MethodInvoker) (() => |
@@ -1328,7 +1303,7 @@ |
vassalForm.StatusText.Text = @"exporting..."; |
vassalForm.StatusProgress.Value = 0; |
|
using (StreamWriter streamWriter = new StreamWriter(file, false, Encoding.UTF8)) |
using (var streamWriter = new StreamWriter(file, false, Encoding.UTF8)) |
{ |
foreach (DataGridViewRow topCollidersRow in TopCollidersGridView.Rows) |
{ |
@@ -1372,7 +1347,7 @@ |
topScriptsRowRegex = new Regex(@".+?", RegexOptions.Compiled); |
break; |
} |
foreach (DataGridViewRow topScriptsRow in TopScriptsGridView.Rows.AsParallel().Cast<DataGridViewRow>()) |
foreach (var topScriptsRow in TopScriptsGridView.Rows.AsParallel().Cast<DataGridViewRow>()) |
{ |
topScriptsRow.Visible = |
topScriptsRowRegex.IsMatch(topScriptsRow.Cells["TopScriptsScore"].Value.ToString()) || |
@@ -1401,7 +1376,7 @@ |
break; |
} |
foreach ( |
DataGridViewRow topCollidersRow in TopCollidersGridView.Rows.AsParallel().Cast<DataGridViewRow>()) |
var topCollidersRow in TopCollidersGridView.Rows.AsParallel().Cast<DataGridViewRow>()) |
{ |
topCollidersRow.Visible = |
topCollidersRowRegex.IsMatch(topCollidersRow.Cells["TopCollidersScore"].Value.ToString()) || |
@@ -1425,11 +1400,11 @@ |
})); |
|
// Enqueue all the UUIDs to return. |
Queue<KeyValuePair<UUID, Vector3>> returnUUIDs = new Queue<KeyValuePair<UUID, Vector3>>(); |
var returnUUIDs = new Queue<KeyValuePair<UUID, Vector3>>(); |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
foreach ( |
DataGridViewRow topScriptsRow in |
var topScriptsRow in |
TopScriptsGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
@@ -1461,21 +1436,21 @@ |
try |
{ |
vassalForm.Invoke((MethodInvoker) (() => { vassalForm.StatusProgress.Value = 0; })); |
int totalObjects = returnUUIDs.Count; |
var totalObjects = returnUUIDs.Count; |
do |
{ |
// Dequeue the first object. |
KeyValuePair<UUID, Vector3> objectData = returnUUIDs.Dequeue(); |
var objectData = returnUUIDs.Dequeue(); |
|
vassalForm.Invoke( |
(MethodInvoker) |
(() => { vassalForm.StatusText.Text = @"Returning object UUID: " + objectData.Key; })); |
|
string currentRegionName = string.Empty; |
var currentRegionName = string.Empty; |
vassalForm.Invoke((MethodInvoker) (() => { currentRegionName = CurrentRegionName.Text; })); |
|
// Teleport to the object. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "teleport"}, |
@@ -1484,7 +1459,7 @@ |
{"position", objectData.Value.ToString()}, |
{"region", currentRegionName}, |
{"fly", "True"} |
}, wasOutput), vassalConfiguration.TeleportTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
{ |
@@ -1495,7 +1470,7 @@ |
} |
|
// Return the object. |
result = wasPOST(vassalConfiguration.HTTPServerURL, |
result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "derez"}, |
@@ -1504,7 +1479,7 @@ |
{"item", objectData.Key.ToString()}, |
{"range", "32"}, // maximal prim size = 64 - middle bounding box at half |
{"type", "ReturnToOwner"} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
{ |
@@ -1530,13 +1505,13 @@ |
{ |
vassalForm.StatusText.Text = @"Returned object: " + objectData.Key; |
// Remove the row from the grid view. |
DataGridViewRow row = |
var row = |
TopScriptsGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.FirstOrDefault( |
o => o.Cells["TopScriptsUUID"].Value.Equals(objectData.Key.ToString())); |
if (row == null) return; |
int i = row.Index; |
var i = row.Index; |
TopScriptsGridView.Rows.RemoveAt(i); |
})); |
break; |
@@ -1586,11 +1561,11 @@ |
})); |
|
// Enqueue all the UUIDs to return. |
Queue<KeyValuePair<UUID, Vector3>> returnObjectUUIDQueue = new Queue<KeyValuePair<UUID, Vector3>>(); |
var returnObjectUUIDQueue = new Queue<KeyValuePair<UUID, Vector3>>(); |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
foreach ( |
DataGridViewRow topCollidersRow in |
var topCollidersRow in |
TopCollidersGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
@@ -1623,21 +1598,21 @@ |
try |
{ |
vassalForm.Invoke((MethodInvoker) (() => { vassalForm.StatusProgress.Value = 0; })); |
int totalObjects = returnObjectUUIDQueue.Count; |
var totalObjects = returnObjectUUIDQueue.Count; |
do |
{ |
// Dequeue the first object. |
KeyValuePair<UUID, Vector3> objectData = returnObjectUUIDQueue.Dequeue(); |
var objectData = returnObjectUUIDQueue.Dequeue(); |
|
vassalForm.Invoke( |
(MethodInvoker) |
(() => { vassalForm.StatusText.Text = @"Returning UUID: " + objectData.Key; })); |
|
string currentRegionName = string.Empty; |
var currentRegionName = string.Empty; |
vassalForm.Invoke((MethodInvoker) (() => { currentRegionName = CurrentRegionName.Text; })); |
|
// Teleport to the object. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "teleport"}, |
@@ -1646,7 +1621,7 @@ |
{"position", objectData.Value.ToString()}, |
{"region", currentRegionName}, |
{"fly", "True"} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
{ |
@@ -1657,7 +1632,7 @@ |
} |
|
// Return the object. |
result = wasPOST(vassalConfiguration.HTTPServerURL, |
result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "derez"}, |
@@ -1666,7 +1641,7 @@ |
{"item", objectData.Key.ToString()}, |
{"range", "32"}, // maximal prim size = 64 - middle bounding box at half |
{"type", "ReturnToOwner"} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
{ |
@@ -1692,13 +1667,13 @@ |
{ |
vassalForm.StatusText.Text = @"Returned object: " + objectData.Key; |
// Remove the row from the grid view. |
DataGridViewRow row = |
var row = |
TopCollidersGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.FirstOrDefault( |
o => o.Cells["TopCollidersUUID"].Value.Equals(objectData.Key.ToString())); |
if (row == null) return; |
int i = row.Index; |
var i = row.Index; |
TopCollidersGridView.Rows.RemoveAt(i); |
})); |
break; |
@@ -1745,21 +1720,22 @@ |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.BatchRestartButton.Enabled = false; |
vassalForm.RegionRestartDelayBox.Enabled = false; |
RegionTeleportGroup.Enabled = false; |
})); |
|
// Enqueue all the regions to restart. |
Queue<KeyValuePair<string, Vector3>> restartRegionQueue = new Queue<KeyValuePair<string, Vector3>>(); |
var restartRegionQueue = new Queue<KeyValuePair<string, Vector3>>(); |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
foreach ( |
DataGridViewRow topCollidersRow in |
var topCollidersRow in |
BatchRestartGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
{ |
Vector3 objectPosition; |
string regionName = topCollidersRow.Cells["BatchRestartRegionName"].Value.ToString(); |
var regionName = topCollidersRow.Cells["BatchRestartRegionName"].Value.ToString(); |
if (string.IsNullOrEmpty(regionName) || |
!Vector3.TryParse(topCollidersRow.Cells["BatchRestartPosition"].Value.ToString(), |
out objectPosition)) |
@@ -1774,6 +1750,7 @@ |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.BatchRestartButton.Enabled = true; |
vassalForm.RegionRestartDelayBox.Enabled = true; |
RegionTeleportGroup.Enabled = true; |
})); |
return; |
@@ -1788,7 +1765,7 @@ |
do |
{ |
// Dequeue the first object. |
KeyValuePair<string, Vector3> restartRegionData = restartRegionQueue.Dequeue(); |
var restartRegionData = restartRegionQueue.Dequeue(); |
DataGridViewRow currentDataGridViewRow = null; |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
@@ -1807,11 +1784,11 @@ |
|
try |
{ |
bool success = false; |
var success = false; |
string result; |
|
// Retry to teleport to each region a few times. |
int teleportRetries = 3; |
var teleportRetries = 3; |
do |
{ |
vassalForm.Invoke((MethodInvoker) (() => |
@@ -1823,7 +1800,7 @@ |
})); |
|
// Teleport to the region. |
result = wasPOST(vassalConfiguration.HTTPServerURL, |
result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "teleport"}, |
@@ -1832,7 +1809,7 @@ |
{"position", restartRegionData.Value.ToString()}, |
{"region", restartRegionData.Key}, |
{"fly", "True"} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
{ |
@@ -1888,7 +1865,7 @@ |
if (!success) |
throw new Exception("Failed to teleport to region."); |
|
result = wasPOST(vassalConfiguration.HTTPServerURL, |
result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "getregiondata"}, |
@@ -1895,7 +1872,7 @@ |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"data", "IsEstateManager"} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade."); |
@@ -1906,7 +1883,7 @@ |
if (!success) |
throw new Exception("Could not retrieve estate rights."); |
|
List<string> data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
var data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
if (!data.Count.Equals(2)) |
throw new Exception("Could not retrieve estate rights."); |
|
@@ -1916,7 +1893,7 @@ |
isEstateManager) |
{ |
case true: // we are an estate manager |
result = wasPOST(vassalConfiguration.HTTPServerURL, |
result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "restartregion"}, |
@@ -1925,9 +1902,9 @@ |
{"action", "restart"}, |
{ |
"delay", |
vassalConfiguration.RegionRestartDelay.ToString(Utils.EnUsCulture) |
vassalForm.RegionRestartDelayBox.Text |
} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade."); |
@@ -1944,7 +1921,7 @@ |
currentDataGridViewRow.Selected = false; |
currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightGreen; |
foreach ( |
DataGridViewCell cell in |
var cell in |
currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
{ |
cell.ToolTipText = @"Region scheduled for restart."; |
@@ -1963,7 +1940,7 @@ |
currentDataGridViewRow.Selected = false; |
currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightPink; |
foreach ( |
DataGridViewCell cell in |
var cell in |
currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
{ |
cell.ToolTipText = ex.Message; |
@@ -1987,6 +1964,7 @@ |
vassalForm.BeginInvoke((MethodInvoker) (() => |
{ |
vassalForm.BatchRestartButton.Enabled = true; |
vassalForm.RegionRestartDelayBox.Enabled = true; |
RegionTeleportGroup.Enabled = true; |
})); |
} |
@@ -2009,7 +1987,7 @@ |
break; |
} |
foreach ( |
DataGridViewRow residentListRow in ResidentListGridView.Rows.AsParallel().Cast<DataGridViewRow>()) |
var residentListRow in ResidentListGridView.Rows.AsParallel().Cast<DataGridViewRow>()) |
{ |
residentListRow.Visible = |
residentListRowRegex.IsMatch(residentListRow.Cells["ResidentListName"].Value.ToString()) || |
@@ -2031,11 +2009,11 @@ |
})); |
|
// Enqueue all the agents to ban. |
Queue<UUID> agentsQueue = new Queue<UUID>(); |
var agentsQueue = new Queue<UUID>(); |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
foreach ( |
DataGridViewRow residentListRow in |
var residentListRow in |
ResidentListGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
@@ -2066,7 +2044,7 @@ |
do |
{ |
// Dequeue the first object. |
UUID agentUUID = agentsQueue.Dequeue(); |
var agentUUID = agentsQueue.Dequeue(); |
DataGridViewRow currentDataGridViewRow = null; |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
@@ -2082,12 +2060,12 @@ |
|
try |
{ |
bool alsoBan = false; |
var alsoBan = false; |
vassalForm.Invoke( |
(MethodInvoker) (() => { alsoBan = vassalForm.ResidentBanAllEstatesBox.Checked; })); |
|
// Ban the resident. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "setestatelist"}, |
@@ -2097,7 +2075,7 @@ |
{"action", "add"}, |
{"agent", agentUUID.ToString()}, |
{"all", alsoBan.ToString()} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade."); |
@@ -2115,7 +2093,7 @@ |
currentDataGridViewRow.Selected = false; |
currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightGreen; |
foreach ( |
DataGridViewCell cell in |
var cell in |
currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
{ |
cell.ToolTipText = @"Resident banned."; |
@@ -2134,7 +2112,7 @@ |
currentDataGridViewRow.Selected = false; |
currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightPink; |
foreach ( |
DataGridViewCell cell in |
var cell in |
currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
{ |
cell.ToolTipText = ex.Message; |
@@ -2177,7 +2155,7 @@ |
try |
{ |
// Get the map heights. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "getterrainheight"}, |
@@ -2184,7 +2162,7 @@ |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"entity", "region"} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade."); |
@@ -2196,8 +2174,8 @@ |
if (!success) |
throw new Exception("Could not get terrain heights."); |
|
List<double> heights = new List<double>(); |
foreach (string map in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result)))) |
var heights = new List<double>(); |
foreach (var map in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result)))) |
{ |
double height; |
if (!double.TryParse(map, out height)) |
@@ -2207,12 +2185,12 @@ |
if (heights.Count.Equals(0)) |
throw new Exception("Could not get terrain heights."); |
|
double maxHeight = heights.Max(); |
using (Bitmap bitmap = new Bitmap(256, 256)) |
var maxHeight = heights.Max(); |
using (var bitmap = new Bitmap(256, 256)) |
{ |
foreach (int x in Enumerable.Range(1, 255)) |
foreach (var x in Enumerable.Range(1, 255)) |
{ |
foreach (int y in Enumerable.Range(1, 255)) |
foreach (var y in Enumerable.Range(1, 255)) |
{ |
bitmap.SetPixel(x, 256 - y, |
Color.FromArgb( |
@@ -2221,13 +2199,13 @@ |
0, 0)); |
} |
} |
Bitmap closureBitmap = (Bitmap) bitmap.Clone(); |
var closureBitmap = (Bitmap) bitmap.Clone(); |
vassalForm.BeginInvoke((MethodInvoker) (() => |
{ |
switch (vassalForm.SavePNGFileDialog.ShowDialog()) |
{ |
case DialogResult.OK: |
string file = vassalForm.SavePNGFileDialog.FileName; |
var file = vassalForm.SavePNGFileDialog.FileName; |
new Thread(() => |
{ |
vassalForm.BeginInvoke((MethodInvoker) (() => |
@@ -2290,7 +2268,7 @@ |
try |
{ |
// Download the terrain. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "terrain"}, |
@@ -2297,7 +2275,7 @@ |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"action", "get"} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade."); |
@@ -2309,7 +2287,7 @@ |
if (!success) |
throw new Exception("Could not download terrain."); |
|
byte[] data = Convert.FromBase64String(wasInput(KeyValue.Get("data", result))); |
var data = Convert.FromBase64String(wasInput(KeyValue.Get("data", result))); |
|
vassalForm.BeginInvoke((MethodInvoker) (() => |
{ |
@@ -2316,7 +2294,7 @@ |
switch (vassalForm.SaveRawFileDialog.ShowDialog()) |
{ |
case DialogResult.OK: |
string file = vassalForm.SaveRawFileDialog.FileName; |
var file = vassalForm.SaveRawFileDialog.FileName; |
new Thread(() => |
{ |
vassalForm.BeginInvoke((MethodInvoker) (() => |
@@ -2380,7 +2358,7 @@ |
switch (vassalForm.LoadRawFileDialog.ShowDialog()) |
{ |
case DialogResult.OK: |
string file = vassalForm.LoadRawFileDialog.FileName; |
var file = vassalForm.LoadRawFileDialog.FileName; |
vassalForm.StatusText.Text = @"loading terrain..."; |
vassalForm.StatusProgress.Value = 0; |
|
@@ -2393,7 +2371,7 @@ |
})); |
|
// Upload the terrain. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "terrain"}, |
@@ -2401,7 +2379,7 @@ |
{"password", vassalConfiguration.Password}, |
{"action", "set"}, |
{"data", Convert.ToBase64String(data)} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade."); |
@@ -2480,7 +2458,7 @@ |
estateListRowRegex = new Regex(@".+?", RegexOptions.Compiled); |
break; |
} |
foreach (DataGridViewRow estateListRow in EstateListGridView.Rows.AsParallel().Cast<DataGridViewRow>()) |
foreach (var estateListRow in EstateListGridView.Rows.AsParallel().Cast<DataGridViewRow>()) |
{ |
estateListRow.Visible = |
estateListRowRegex.IsMatch(estateListRow.Cells["EstateListName"].Value.ToString()); |
@@ -2490,8 +2468,8 @@ |
|
private void EstateListSelected(object sender, EventArgs e) |
{ |
string selectedEstateListType = string.Empty; |
bool queryEstateList = false; |
var selectedEstateListType = string.Empty; |
var queryEstateList = false; |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
if (vassalForm.EstateListSelectBox.SelectedItem == null) return; |
@@ -2527,7 +2505,7 @@ |
})); |
|
// Get the selected estate list. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "getestatelist"}, |
@@ -2534,7 +2512,7 @@ |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"type", selectedEstateListType} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade."); |
@@ -2547,7 +2525,7 @@ |
throw new Exception("Could not retrieve estate list."); |
|
vassalForm.Invoke((MethodInvoker) (() => { EstateListGridView.Rows.Clear(); })); |
foreach (List<string> data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
foreach (var data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
.Where(x => !string.IsNullOrEmpty(x)) |
.Select((x, i) => new {Index = i, Value = x}) |
.GroupBy(x => x.Index/2) |
@@ -2591,8 +2569,8 @@ |
private void RequestRemoveEstateListMember(object sender, EventArgs e) |
{ |
// Get the estate list type. |
string selectedEstateListType = string.Empty; |
bool queryEstateList = false; |
var selectedEstateListType = string.Empty; |
var queryEstateList = false; |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
if (vassalForm.EstateListSelectBox.SelectedItem == null) |
@@ -2617,11 +2595,11 @@ |
if (!queryEstateList) return; |
|
// Enqueue all the regions to restart. |
Queue<UUID> estateListMembersQueue = new Queue<UUID>(); |
var estateListMembersQueue = new Queue<UUID>(); |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
foreach ( |
DataGridViewRow estateListRow in |
var estateListRow in |
EstateListGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
@@ -2649,7 +2627,7 @@ |
try |
{ |
Monitor.Enter(ClientInstanceTeleportLock); |
UUID memberUUID = UUID.Zero; |
var memberUUID = UUID.Zero; |
do |
{ |
try |
@@ -2657,7 +2635,7 @@ |
memberUUID = estateListMembersQueue.Dequeue(); |
|
// Remove the agent or group from the list. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "setestatelist"}, |
@@ -2666,7 +2644,7 @@ |
{"type", selectedEstateListType}, |
{"action", "remove"}, |
{selectedEstateListType.Equals("group") ? "target" : "agent", memberUUID.ToString()} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade"); |
@@ -2681,7 +2659,7 @@ |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
foreach ( |
int i in |
var i in |
EstateListGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.Where( |
@@ -2722,8 +2700,8 @@ |
private void RequestEstateListsAddResident(object sender, EventArgs e) |
{ |
// Get the estate list type. |
string selectedEstateListType = string.Empty; |
bool queryEstateList = false; |
var selectedEstateListType = string.Empty; |
var queryEstateList = false; |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
selectedEstateListType = vassalForm.EstateListSelectBox.SelectedItem.ToString(); |
@@ -2742,8 +2720,8 @@ |
// If not estate list type is selected then return. |
if (!queryEstateList) return; |
|
string firstName = string.Empty; |
string lastName = string.Empty; |
var firstName = string.Empty; |
var lastName = string.Empty; |
|
vassalForm.Invoke((MethodInvoker) (() => |
{ |
@@ -2785,7 +2763,7 @@ |
Monitor.Enter(ClientInstanceTeleportLock); |
|
// Add the resident to the list. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "setestatelist"}, |
@@ -2795,7 +2773,7 @@ |
{"action", "add"}, |
{"firstname", firstName}, |
{"lastname", lastName} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade"); |
@@ -2808,7 +2786,7 @@ |
throw new Exception("Unable to add resident"); |
|
// Retrieve the estate list for updates. |
result = wasPOST(vassalConfiguration.HTTPServerURL, |
result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "getestatelist"}, |
@@ -2815,7 +2793,7 @@ |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"type", selectedEstateListType} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade."); |
@@ -2827,7 +2805,7 @@ |
throw new Exception("Could not retrieve estate list."); |
|
vassalForm.Invoke((MethodInvoker) (() => { EstateListGridView.Rows.Clear(); })); |
foreach (List<string> data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
foreach (var data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
.Where(x => !string.IsNullOrEmpty(x)) |
.Select((x, i) => new {Index = i, Value = x}) |
.GroupBy(x => x.Index/2) |
@@ -2859,8 +2837,8 @@ |
private void RequestEstateListsAddGroup(object sender, EventArgs e) |
{ |
// Get the estate list type. |
string selectedEstateListType = string.Empty; |
bool queryEstateList = false; |
var selectedEstateListType = string.Empty; |
var queryEstateList = false; |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
selectedEstateListType = vassalForm.EstateListSelectBox.SelectedItem.ToString(); |
@@ -2879,7 +2857,7 @@ |
// If not estate list type is selected then return. |
if (!queryEstateList) return; |
|
string target = string.Empty; |
var target = string.Empty; |
|
vassalForm.Invoke((MethodInvoker) (() => |
{ |
@@ -2911,7 +2889,7 @@ |
Monitor.Enter(ClientInstanceTeleportLock); |
|
// Add the group to the list. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "setestatelist"}, |
@@ -2920,7 +2898,7 @@ |
{"type", selectedEstateListType}, |
{"action", "add"}, |
{"target", target} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade"); |
@@ -2933,7 +2911,7 @@ |
throw new Exception("Unable to add group"); |
|
// Retrieve the estate list for updates. |
result = wasPOST(vassalConfiguration.HTTPServerURL, |
result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "getestatelist"}, |
@@ -2940,7 +2918,7 @@ |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"type", selectedEstateListType} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade."); |
@@ -2952,7 +2930,7 @@ |
throw new Exception("Could not retrieve estate list."); |
|
vassalForm.Invoke((MethodInvoker) (() => { EstateListGridView.Rows.Clear(); })); |
foreach (List<string> data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
foreach (var data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
.Where(x => !string.IsNullOrEmpty(x)) |
.Select((x, i) => new {Index = i, Value = x}) |
.GroupBy(x => x.Index/2) |
@@ -2995,9 +2973,9 @@ |
{ |
Monitor.Enter(ClientInstanceTeleportLock); |
|
bool scripts = false; |
bool collisons = false; |
bool physics = false; |
var scripts = false; |
var collisons = false; |
var physics = false; |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
scripts = RegionDebugScriptsBox.Checked; |
@@ -3006,7 +2984,7 @@ |
})); |
|
// Set the debug settings. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "setregiondebug"}, |
@@ -3015,7 +2993,7 @@ |
{"scripts", scripts.ToString()}, |
{"collisions", collisons.ToString()}, |
{"physics", physics.ToString()} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade"); |
@@ -3061,17 +3039,17 @@ |
{ |
Monitor.Enter(ClientInstanceTeleportLock); |
|
bool terraform = false; |
bool fly = false; |
bool damage = false; |
bool resell = false; |
bool push = false; |
bool parcel = false; |
bool mature = false; |
var terraform = false; |
var fly = false; |
var damage = false; |
var resell = false; |
var push = false; |
var parcel = false; |
var mature = false; |
uint agentLimit = 20; |
double objectBonus = 2.0; |
var objectBonus = 2.0; |
|
bool run = false; |
var run = false; |
|
vassalForm.Invoke((MethodInvoker) (() => |
{ |
@@ -3108,7 +3086,7 @@ |
if (!run) return; |
|
// Set the debug settings. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "setregioninfo"}, |
@@ -3123,7 +3101,7 @@ |
{"mature", mature.ToString()}, |
{"limit", agentLimit.ToString(Utils.EnUsCulture)}, |
{"bonus", objectBonus.ToString(Utils.EnUsCulture)} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade"); |
@@ -3156,7 +3134,7 @@ |
|
private void RequestEstateTexturesApply(object sender, EventArgs e) |
{ |
List<UUID> groundTextureUUIDs = new List<UUID>(); |
var groundTextureUUIDs = new List<UUID>(); |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
UUID textureUUID; |
@@ -3221,7 +3199,7 @@ |
Monitor.Enter(ClientInstanceTeleportLock); |
|
// Set the debug settings. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "setregionterraintextures"}, |
@@ -3228,7 +3206,7 @@ |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"data", CSV.FromEnumerable(groundTextureUUIDs.Select(o => o.ToString()))} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade"); |
@@ -3261,12 +3239,12 @@ |
|
private void RequestDownloadRegionTexture(object sender, EventArgs e) |
{ |
string textureName = string.Empty; |
UUID textureUUID = UUID.Zero; |
bool run = false; |
var textureName = string.Empty; |
var textureUUID = UUID.Zero; |
var run = false; |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
Button button = sender as Button; |
var button = sender as Button; |
if (button == null) |
{ |
run = false; |
@@ -3322,7 +3300,7 @@ |
{ |
Monitor.Enter(ClientInstanceTeleportLock); |
|
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "download"}, |
@@ -3331,7 +3309,7 @@ |
{"item", textureUUID.ToString()}, |
{"type", "Texture"}, |
{"format", "Png"} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade"); |
@@ -3340,9 +3318,9 @@ |
if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
throw new Exception("No success status could be retrieved"); |
|
byte[] mapImageBytes = Convert.FromBase64String(wasInput(KeyValue.Get("data", result))); |
var mapImageBytes = Convert.FromBase64String(wasInput(KeyValue.Get("data", result))); |
Image mapImage; |
using (MemoryStream memoryStream = new MemoryStream(mapImageBytes, 0, mapImageBytes.Length)) |
using (var memoryStream = new MemoryStream(mapImageBytes, 0, mapImageBytes.Length)) |
{ |
mapImage = Image.FromStream(memoryStream); |
} |
@@ -3352,7 +3330,7 @@ |
switch (vassalForm.SavePNGFileDialog.ShowDialog()) |
{ |
case DialogResult.OK: |
string file = vassalForm.SavePNGFileDialog.FileName; |
var file = vassalForm.SavePNGFileDialog.FileName; |
new Thread(() => |
{ |
vassalForm.BeginInvoke((MethodInvoker) (() => |
@@ -3404,8 +3382,8 @@ |
private void RequestEstateListsAddGroupsFromCSV(object sender, EventArgs e) |
{ |
// Get the estate list type. |
string selectedEstateListType = string.Empty; |
bool queryEstateList = false; |
var selectedEstateListType = string.Empty; |
var queryEstateList = false; |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
if (vassalForm.EstateListSelectBox.SelectedItem == null) return; |
@@ -3425,7 +3403,7 @@ |
// If not estate list type is selected then return. |
if (!queryEstateList) return; |
|
Queue<KeyValuePair<string, UUID>> targets = new Queue<KeyValuePair<string, UUID>>(); |
var targets = new Queue<KeyValuePair<string, UUID>>(); |
|
vassalForm.Invoke((MethodInvoker) (() => |
{ |
@@ -3432,7 +3410,7 @@ |
switch (vassalForm.LoadCSVFile.ShowDialog()) |
{ |
case DialogResult.OK: |
string file = vassalForm.LoadCSVFile.FileName; |
var file = vassalForm.LoadCSVFile.FileName; |
try |
{ |
vassalForm.StatusText.Text = @"loading group list..."; |
@@ -3440,7 +3418,7 @@ |
|
// import groups |
UUID targetUUID; |
foreach (KeyValuePair<string, UUID> target in |
foreach (var target in |
File.ReadAllLines(file) |
.AsParallel() |
.Select(o => new List<string>(CSV.ToEnumerable(o))) |
@@ -3466,7 +3444,7 @@ |
})); |
|
if (targets.Count.Equals(0)) return; |
int initialQueueSize = targets.Count; |
var initialQueueSize = targets.Count; |
|
// Block teleports and disable button. |
vassalForm.Invoke((MethodInvoker) (() => |
@@ -3483,7 +3461,7 @@ |
|
do |
{ |
KeyValuePair<string, UUID> target = targets.Dequeue(); |
var target = targets.Dequeue(); |
|
vassalForm.Invoke((MethodInvoker) (() => |
{ |
@@ -3493,7 +3471,7 @@ |
})); |
|
// Skip any items that already exist. |
bool run = false; |
var run = false; |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
run = |
@@ -3509,7 +3487,7 @@ |
try |
{ |
// Add the group to the list. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "setestatelist"}, |
@@ -3518,7 +3496,7 @@ |
{"type", selectedEstateListType}, |
{"action", "add"}, |
{"target", target.Value.ToString()} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade"); |
@@ -3541,7 +3519,7 @@ |
try |
{ |
// Retrieve the estate list for updates. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "getestatelist"}, |
@@ -3548,7 +3526,7 @@ |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"type", selectedEstateListType} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade."); |
@@ -3561,7 +3539,7 @@ |
throw new Exception("Could not retrieve estate list."); |
|
vassalForm.Invoke((MethodInvoker) (() => { EstateListGridView.Rows.Clear(); })); |
foreach (List<string> data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
foreach (var data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
.Where(x => !string.IsNullOrEmpty(x)) |
.Select((x, i) => new {Index = i, Value = x}) |
.GroupBy(x => x.Index/2) |
@@ -3597,8 +3575,8 @@ |
private void RequestEstateListsAddResidentsFromCSV(object sender, EventArgs e) |
{ |
// Get the estate list type. |
string selectedEstateListType = string.Empty; |
bool queryEstateList = false; |
var selectedEstateListType = string.Empty; |
var queryEstateList = false; |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
if (vassalForm.EstateListSelectBox.SelectedItem == null) return; |
@@ -3618,7 +3596,7 @@ |
// If not estate list type is selected then return. |
if (!queryEstateList) return; |
|
Queue<KeyValuePair<string, UUID>> targets = new Queue<KeyValuePair<string, UUID>>(); |
var targets = new Queue<KeyValuePair<string, UUID>>(); |
|
vassalForm.Invoke((MethodInvoker) (() => |
{ |
@@ -3625,7 +3603,7 @@ |
switch (vassalForm.LoadCSVFile.ShowDialog()) |
{ |
case DialogResult.OK: |
string file = vassalForm.LoadCSVFile.FileName; |
var file = vassalForm.LoadCSVFile.FileName; |
try |
{ |
vassalForm.StatusText.Text = @"loading residents list..."; |
@@ -3633,7 +3611,7 @@ |
|
// import groups |
UUID targetUUID; |
foreach (KeyValuePair<string, UUID> target in |
foreach (var target in |
File.ReadAllLines(file) |
.AsParallel() |
.Select(o => new List<string>(CSV.ToEnumerable(o))) |
@@ -3659,7 +3637,7 @@ |
})); |
|
if (targets.Count.Equals(0)) return; |
int initialQueueSize = targets.Count; |
var initialQueueSize = targets.Count; |
|
// Block teleports and disable button. |
vassalForm.Invoke((MethodInvoker) (() => |
@@ -3676,7 +3654,7 @@ |
|
do |
{ |
KeyValuePair<string, UUID> target = targets.Dequeue(); |
var target = targets.Dequeue(); |
|
vassalForm.Invoke((MethodInvoker) (() => |
{ |
@@ -3686,7 +3664,7 @@ |
})); |
|
// Skip any items that already exist. |
bool run = false; |
var run = false; |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
run = |
@@ -3702,7 +3680,7 @@ |
try |
{ |
// Add the group to the list. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "setestatelist"}, |
@@ -3711,7 +3689,7 @@ |
{"type", selectedEstateListType}, |
{"action", "add"}, |
{"agent", target.Value.ToString()} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade"); |
@@ -3734,7 +3712,7 @@ |
try |
{ |
// Retrieve the estate list for updates. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "getestatelist"}, |
@@ -3741,7 +3719,7 @@ |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"type", selectedEstateListType} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade."); |
@@ -3754,7 +3732,7 @@ |
throw new Exception("Could not retrieve estate list."); |
|
vassalForm.Invoke((MethodInvoker) (() => { EstateListGridView.Rows.Clear(); })); |
foreach (List<string> data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
foreach (var data in CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))) |
.Where(x => !string.IsNullOrEmpty(x)) |
.Select((x, i) => new {Index = i, Value = x}) |
.GroupBy(x => x.Index/2) |
@@ -3794,7 +3772,7 @@ |
switch (vassalForm.ExportCSVDialog.ShowDialog()) |
{ |
case DialogResult.OK: |
string file = vassalForm.ExportCSVDialog.FileName; |
var file = vassalForm.ExportCSVDialog.FileName; |
new Thread(() => |
{ |
vassalForm.BeginInvoke((MethodInvoker) (() => |
@@ -3804,7 +3782,7 @@ |
vassalForm.StatusText.Text = @"exporting..."; |
vassalForm.StatusProgress.Value = 0; |
|
using (StreamWriter streamWriter = new StreamWriter(file, false, Encoding.UTF8)) |
using (var streamWriter = new StreamWriter(file, false, Encoding.UTF8)) |
{ |
foreach (DataGridViewRow estateListRow in EstateListGridView.Rows) |
{ |
@@ -3842,11 +3820,11 @@ |
})); |
|
// Enqueue all the agents to teleport home. |
Queue<UUID> agentsQueue = new Queue<UUID>(); |
var agentsQueue = new Queue<UUID>(); |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
foreach ( |
DataGridViewRow residentListRow in |
var residentListRow in |
ResidentListGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
@@ -3877,7 +3855,7 @@ |
do |
{ |
// Dequeue the first object. |
UUID agentUUID = agentsQueue.Dequeue(); |
var agentUUID = agentsQueue.Dequeue(); |
DataGridViewRow currentDataGridViewRow = null; |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
@@ -3894,7 +3872,7 @@ |
try |
{ |
// Teleport the user home. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "estateteleportusershome"}, |
@@ -3901,7 +3879,7 @@ |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"avatars", agentUUID.ToString()} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade."); |
@@ -3919,7 +3897,7 @@ |
currentDataGridViewRow.Selected = false; |
currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightGreen; |
foreach ( |
DataGridViewCell cell in |
var cell in |
currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
{ |
cell.ToolTipText = @"Resident teleported home."; |
@@ -3938,7 +3916,7 @@ |
currentDataGridViewRow.Selected = false; |
currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightPink; |
foreach ( |
DataGridViewCell cell in |
var cell in |
currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
{ |
cell.ToolTipText = ex.Message; |
@@ -3980,14 +3958,14 @@ |
{ |
Monitor.Enter(ClientInstanceTeleportLock); |
|
int waterHeight = 10; |
int terrainRaiseLimit = 100; |
int terrainLowerLimit = -100; |
bool useEstateSun = true; |
bool fixedSun = false; |
int sunPosition = 18; |
var waterHeight = 10; |
var terrainRaiseLimit = 100; |
var terrainLowerLimit = -100; |
var useEstateSun = true; |
var fixedSun = false; |
var sunPosition = 18; |
|
bool run = false; |
var run = false; |
|
vassalForm.Invoke((MethodInvoker) (() => |
{ |
@@ -4036,7 +4014,7 @@ |
if (!run) return; |
|
// Set the terrain variables. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
var result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "setregionterrainvariables"}, |
@@ -4048,7 +4026,7 @@ |
{"useestatesun", useEstateSun.ToString()}, |
{"fixedsun", fixedSun.ToString()}, |
{"sunposition", sunPosition.ToString()} |
}, wasOutput), vassalConfiguration.DataTimeout); |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade"); |
@@ -4084,10 +4062,10 @@ |
// Spawn a thread to check Corrade's connection status. |
new Thread(() => |
{ |
TcpClient tcpClient = new TcpClient(); |
var tcpClient = new TcpClient(); |
try |
{ |
Uri uri = new Uri(vassalConfiguration.HTTPServerURL); |
var uri = new Uri(vassalConfiguration.HTTPServerURL); |
tcpClient.Connect(uri.Host, uri.Port); |
// port open |
vassalForm.BeginInvoke((MethodInvoker) (() => { vassalForm.Tabs.Enabled = true; })); |
@@ -4094,8 +4072,8 @@ |
// set the loading spinner |
if (vassalForm.RegionAvatarsMap.Image == null) |
{ |
Assembly thisAssembly = Assembly.GetExecutingAssembly(); |
Stream file = |
var thisAssembly = Assembly.GetExecutingAssembly(); |
var file = |
thisAssembly.GetManifestResourceStream("Vassal.img.loading.gif"); |
switch (file != null) |
{ |
@@ -4343,8 +4321,258 @@ |
} |
} |
|
#region CRYPTOGRAPHY |
private void RequestBatchSetCovenant(object sender, EventArgs e) |
{ |
// Block teleports and disable button. |
vassalForm.Invoke((MethodInvoker)(() => |
{ |
vassalForm.BatchSetCovenantButton.Enabled = false; |
vassalForm.SetCovenantNotecardUUIDBox.Enabled = false; |
RegionTeleportGroup.Enabled = false; |
})); |
|
#endregion |
// Enqueue all the regions to set covenant. |
var batchSetCovenantQueue = new Queue<KeyValuePair<string, Vector3>>(); |
vassalForm.Invoke((MethodInvoker)(() => |
{ |
foreach ( |
var topCollidersRow in |
BatchSetCovenantGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
{ |
Vector3 objectPosition; |
var regionName = topCollidersRow.Cells["BatchSetCovenantRegionName"].Value.ToString(); |
if (string.IsNullOrEmpty(regionName) || |
!Vector3.TryParse(topCollidersRow.Cells["BatchSetCovenantPosition"].Value.ToString(), |
out objectPosition)) |
continue; |
batchSetCovenantQueue.Enqueue(new KeyValuePair<string, Vector3>(regionName, objectPosition)); |
} |
})); |
|
// If no rows were selected, enable teleports, the return button and return. |
if (batchSetCovenantQueue.Count.Equals(0)) |
{ |
vassalForm.Invoke((MethodInvoker)(() => |
{ |
vassalForm.BatchSetCovenantButton.Enabled = true; |
vassalForm.SetCovenantNotecardUUIDBox.Enabled = true; |
RegionTeleportGroup.Enabled = true; |
})); |
return; |
} |
|
new Thread(() => |
{ |
Monitor.Enter(ClientInstanceTeleportLock); |
|
try |
{ |
do |
{ |
// Dequeue the first object. |
var batchSetCovenantRegionData = batchSetCovenantQueue.Dequeue(); |
DataGridViewRow currentDataGridViewRow = null; |
vassalForm.Invoke((MethodInvoker)(() => |
{ |
currentDataGridViewRow = vassalForm.BatchSetCovenantGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.FirstOrDefault( |
o => |
o.Cells["BatchSetCovenantRegionName"].Value.ToString() |
.Equals(batchSetCovenantRegionData.Key, StringComparison.OrdinalIgnoreCase) && |
o.Cells["BatchSetCovenantPosition"].Value.ToString() |
.Equals(batchSetCovenantRegionData.Value.ToString(), |
StringComparison.OrdinalIgnoreCase)); |
})); |
|
if (currentDataGridViewRow == null) continue; |
|
try |
{ |
var success = false; |
string result; |
|
// Retry to teleport to each region a few times. |
var teleportRetries = 3; |
do |
{ |
vassalForm.Invoke((MethodInvoker)(() => |
{ |
vassalForm.StatusText.Text = @"Attempting to teleport to " + batchSetCovenantRegionData.Key + |
@" " + @"(" + |
teleportRetries.ToString(Utils.EnUsCulture) + |
@")"; |
})); |
|
// Teleport to the region. |
result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "teleport"}, |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"position", batchSetCovenantRegionData.Value.ToString()}, |
{"region", batchSetCovenantRegionData.Key}, |
{"fly", "True"} |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
{ |
vassalForm.Invoke( |
(MethodInvoker) |
(() => |
{ |
vassalForm.StatusText.Text = @"Error communicating with Corrade."; |
})); |
continue; |
} |
if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
{ |
vassalForm.Invoke( |
(MethodInvoker) |
(() => |
{ |
vassalForm.StatusText.Text = @"No success status could be retrieved. "; |
})); |
continue; |
} |
switch (success) |
{ |
case true: |
vassalForm.Invoke( |
(MethodInvoker) |
(() => { vassalForm.StatusText.Text = @"Teleport succeeded."; })); |
break; |
default: |
// In case the destination is to close (Corrade status code 37559), |
// then we are on the same region so no need to retry. |
uint status; //37559 |
switch ( |
uint.TryParse(wasInput(KeyValue.Get("status", result)), out status) && |
status.Equals(37559)) |
{ |
case true: // We are on the region already! |
success = true; |
break; |
default: |
vassalForm.Invoke( |
(MethodInvoker) |
(() => { vassalForm.StatusText.Text = @"Teleport failed."; })); |
break; |
} |
break; |
} |
|
// Pause for teleport (10 teleports / 15s allowed). |
Thread.Sleep(700); |
} while (!success && !(--teleportRetries).Equals(0)); |
|
if (!success) |
throw new Exception("Failed to teleport to region."); |
|
result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "getregiondata"}, |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"data", "IsEstateManager"} |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade."); |
|
if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
throw new Exception("No success status could be retrieved."); |
|
if (!success) |
throw new Exception("Could not retrieve estate rights."); |
|
var data = CSV.ToEnumerable(wasInput(KeyValue.Get("data", result))).ToList(); |
if (!data.Count.Equals(2)) |
throw new Exception("Could not retrieve estate rights."); |
|
bool isEstateManager; |
switch ( |
bool.TryParse(data[data.IndexOf("IsEstateManager") + 1], out isEstateManager) && |
isEstateManager) |
{ |
case true: // we are an estate manager |
result = Encoding.UTF8.GetString(HTTPClient.POST(vassalConfiguration.HTTPServerURL, |
KeyValue.Escape(new Dictionary<string, string> |
{ |
{"command", "setestatecovenant"}, |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"item", vassalForm.SetCovenantNotecardUUIDBox.Text} |
}, wasOutput)).Result); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade."); |
|
if (!bool.TryParse(wasInput(KeyValue.Get("success", result)), out success)) |
throw new Exception("No success status could be retrieved."); |
|
if (!success) |
throw new Exception("Could not set region covenant."); |
|
vassalForm.Invoke((MethodInvoker)(() => |
{ |
vassalForm.StatusText.Text = @"Region covenant set."; |
currentDataGridViewRow.Selected = false; |
currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightGreen; |
foreach ( |
var cell in |
currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
{ |
cell.ToolTipText = @"Region covenant set."; |
} |
})); |
break; |
default: |
throw new Exception("No estate manager rights for setting covenant."); |
} |
} |
catch (Exception ex) |
{ |
vassalForm.Invoke((MethodInvoker)(() => |
{ |
vassalForm.StatusText.Text = ex.Message; |
currentDataGridViewRow.Selected = false; |
currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightPink; |
foreach ( |
var cell in |
currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
{ |
cell.ToolTipText = ex.Message; |
} |
})); |
} |
finally |
{ |
// Pause for teleport (10 teleports / 15s allowed). |
Thread.Sleep(700); |
} |
} while (!batchSetCovenantQueue.Count.Equals(0)); |
} |
catch (Exception) |
{ |
} |
finally |
{ |
Monitor.Exit(ClientInstanceTeleportLock); |
// Allow teleports and enable button. |
vassalForm.BeginInvoke((MethodInvoker)(() => |
{ |
vassalForm.BatchSetCovenantButton.Enabled = true; |
vassalForm.SetCovenantNotecardUUIDBox.Enabled = true; |
RegionTeleportGroup.Enabled = true; |
})); |
} |
}) |
{ IsBackground = true }.Start(); |
} |
} |
} |