/Vassal/Vassal/VassalForm.cs |
@@ -31,7 +31,6 @@ |
public static System.Timers.Timer overviewTabTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); |
public static System.Timers.Timer topScriptsTabTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); |
public static System.Timers.Timer topCollidersTabTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); |
public static Dictionary<string, Vector3> ConfiguredRegions = new Dictionary<string, Vector3>(); |
public static VassalConfiguration vassalConfiguration = new VassalConfiguration(); |
public static Vassal vassalForm; |
public static readonly object ClientInstanceTeleportLock = new object(); |
@@ -133,8 +132,9 @@ |
.Select(o => o.v) |
.FirstOrDefault(); |
} |
#endregion |
|
#endregion |
|
#region CRYPTOGRAPHY |
|
/////////////////////////////////////////////////////////////////////////// |
@@ -914,16 +914,16 @@ |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
wasKeyValueEscape(new Dictionary<string, string> |
{ |
{"command", "getregiondata"}, |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"data", "Name"} |
{"command", "getregiondata"}, |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"data", "Name"} |
}), 60000); |
bool success; |
if (string.IsNullOrEmpty(result) || |
!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
{ |
vassalForm.BeginInvoke((MethodInvoker)(() => |
vassalForm.BeginInvoke((MethodInvoker) (() => |
{ |
vassalForm.StatusText.Text = @"Failed to query Corrade for current region."; |
})); |
@@ -932,7 +932,7 @@ |
switch (success) |
{ |
case true: |
vassalForm.BeginInvoke((MethodInvoker)(() => |
vassalForm.BeginInvoke((MethodInvoker) (() => |
{ |
vassalForm.CurrentRegionAt.Visible = true; |
vassalForm.CurrentRegionName.Visible = true; |
@@ -941,7 +941,7 @@ |
})); |
break; |
default: |
vassalForm.BeginInvoke((MethodInvoker)(() => |
vassalForm.BeginInvoke((MethodInvoker) (() => |
{ |
vassalForm.CurrentRegionAt.Visible = false; |
vassalForm.CurrentRegionName.Visible = false; |
@@ -953,7 +953,7 @@ |
} |
catch (Exception ex) |
{ |
vassalForm.BeginInvoke((MethodInvoker)(() => |
vassalForm.BeginInvoke((MethodInvoker) (() => |
{ |
vassalForm.StatusText.Text = |
@"Error getting current region: " + |
@@ -970,136 +970,160 @@ |
|
private void RegionSelected(object sender, EventArgs e) |
{ |
ListViewItem listViewItem = null; |
string selectedRegionName = string.Empty; |
Vector3 selectedRegionPosition = Vector3.Zero; |
bool startTeleport = false; |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
listViewItem = LoadedRegions.SelectedItem as ListViewItem; |
ListViewItem listViewItem = LoadedRegions.SelectedItem as ListViewItem; |
switch (listViewItem != null && LoadedRegions.SelectedIndex != -1) |
{ |
case true: |
selectedRegionName = listViewItem.Text; |
selectedRegionPosition = (Vector3)listViewItem.Tag; |
startTeleport = true; |
break; |
default: |
startTeleport = false; |
break; |
} |
})); |
|
switch (listViewItem != null) |
if (!startTeleport) return; |
|
|
// Announce teleport. |
vassalForm.Invoke((MethodInvoker)(() => |
{ |
case true: |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.StatusText.Text = @"Teleporting to " + |
listViewItem.Text; |
})); |
break; |
default: |
return; |
} |
vassalForm.RegionTeleportGroup.Enabled = false; |
vassalForm.StatusProgress.Value = 0; |
vassalForm.StatusText.Text = @"Teleporting to " + selectedRegionName; |
})); |
|
new Thread(() => |
{ |
lock (ClientInstanceTeleportLock) |
Monitor.Enter(ClientInstanceTeleportLock); |
try |
{ |
try |
int elapsedSeconds = 0; |
System.Timers.Timer teleportTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); |
teleportTimer.Elapsed += (o, p) => |
{ |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.RegionTeleportGroup.Enabled = false; |
vassalForm.StatusProgress.Value = 0; |
vassalForm.StatusProgress.Value = |
Math.Min( |
(int) |
(100d* |
(TimeSpan.FromSeconds(++elapsedSeconds).TotalMilliseconds/ |
vassalConfiguration.TeleportTimeout)), 100); |
})); |
int elapsedSeconds = 0; |
System.Timers.Timer teleportTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); |
teleportTimer.Elapsed += (o, p) => |
{ |
}; |
teleportTimer.Start(); |
string result = null; |
ManualResetEvent receivedPOST = new ManualResetEvent(false); |
new Thread(() => |
{ |
result = wasInput(wasPOST(vassalConfiguration.HTTPServerURL, |
wasKeyValueEscape(new Dictionary<string, string> |
{ |
{"command", "teleport"}, |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"region", selectedRegionName}, |
{"position", selectedRegionPosition.ToString()}, |
{"fly", "True"} |
}), vassalConfiguration.TeleportTimeout)); |
receivedPOST.Set(); |
}) {IsBackground = true}.Start(); |
receivedPOST.WaitOne((int) vassalConfiguration.TeleportTimeout, false); |
teleportTimer.Stop(); |
switch (!string.IsNullOrEmpty(result) && wasKeyValueGet("success", result) == "True") |
{ |
case true: |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.StatusProgress.Value = |
Math.Min( |
(int) |
(100d* |
(TimeSpan.FromSeconds(++elapsedSeconds).TotalMilliseconds/ |
vassalConfiguration.TeleportTimeout)), 100); |
vassalForm.StatusText.Text = @"Now at " + selectedRegionName; |
vassalForm.CurrentRegionName.Text = selectedRegionName; |
})); |
}; |
teleportTimer.Start(); |
string result = null; |
ManualResetEvent receivedPOST = new ManualResetEvent(false); |
new Thread(() => |
{ |
result = wasInput(wasPOST(vassalConfiguration.HTTPServerURL, |
wasKeyValueEscape(new Dictionary<string, string> |
{ |
{"command", "teleport"}, |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"region", listViewItem.Text}, |
{"position", ((Vector3) listViewItem.Tag).ToString()}, |
{"fly", "True"} |
}), vassalConfiguration.TeleportTimeout)); |
receivedPOST.Set(); |
}) {IsBackground = true}.Start(); |
receivedPOST.WaitOne((int) vassalConfiguration.TeleportTimeout, false); |
teleportTimer.Stop(); |
switch (!string.IsNullOrEmpty(result) && wasKeyValueGet("success", result) == "True") |
{ |
case true: |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.StatusText.Text = @"Now at " + listViewItem.Text; |
})); |
break; |
default: |
switch (!string.IsNullOrEmpty(result)) |
{ |
case true: |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.StatusText.Text = @"Failed teleporting to " + listViewItem.Text + |
@": " + |
wasKeyValueGet("error", result); |
})); |
break; |
default: |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.StatusText.Text = @"Failed teleporting to " + listViewItem.Text; |
})); |
break; |
} |
break; |
} |
} |
catch (Exception ex) |
{ |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.StatusText.Text = @"Error communicating with Corrade: " + ex.Message; |
})); |
} |
finally |
{ |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.StatusProgress.Value = 100; |
vassalForm.RegionTeleportGroup.Enabled = true; |
// Set the map image to the loading spinner. |
Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); |
System.IO.Stream file = |
thisAssembly.GetManifestResourceStream("Vassal.img.loading.gif"); |
switch (file != null) |
break; |
default: |
switch (!string.IsNullOrEmpty(result)) |
{ |
case true: |
vassalForm.Invoke((MethodInvoker)(() => |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
RegionAvatarsMap.SizeMode = PictureBoxSizeMode.CenterImage; |
RegionAvatarsMap.Image = Image.FromStream(file); |
RegionAvatarsMap.Refresh(); |
vassalForm.StatusText.Text = @"Failed teleporting to " + selectedRegionName + |
@": " + |
wasKeyValueGet("error", result); |
})); |
break; |
default: |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.StatusText.Text = @"Failed teleporting to " + selectedRegionName; |
})); |
break; |
} |
// Clear the top scripts table. |
TopScriptsGridView.Rows.Clear(); |
// Clear the top colliders table. |
TopCollidersGridView.Rows.Clear(); |
})); |
updateCurrentRegionName.BeginInvoke(updateCurrentRegionName.EndInvoke, null); |
break; |
} |
} |
catch (Exception ex) |
{ |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.StatusText.Text = @"Error communicating with Corrade: " + ex.Message; |
})); |
} |
finally |
{ |
Monitor.Exit(ClientInstanceTeleportLock); |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.StatusProgress.Value = 100; |
vassalForm.RegionTeleportGroup.Enabled = true; |
// Set the map image to the loading spinner. |
Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); |
System.IO.Stream file = |
thisAssembly.GetManifestResourceStream("Vassal.img.loading.gif"); |
switch (file != null) |
{ |
case true: |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
RegionAvatarsMap.SizeMode = PictureBoxSizeMode.CenterImage; |
RegionAvatarsMap.Image = Image.FromStream(file); |
RegionAvatarsMap.Refresh(); |
})); |
break; |
} |
// Clear the top scripts table. |
TopScriptsGridView.Rows.Clear(); |
// Clear the top colliders table. |
TopCollidersGridView.Rows.Clear(); |
// Invalidate data for overview tab. |
vassalForm.CurrentRegionAt.Visible = false; |
vassalForm.CurrentRegionName.Visible = false; |
Agents.Text = string.Empty; |
Agents.Enabled = false; |
LastLag.Text = string.Empty; |
LastLag.Enabled = false; |
Dilation.Text = string.Empty; |
Dilation.Enabled = false; |
FPS.Text = string.Empty; |
FPS.Enabled = false; |
PhysicsFPS.Text = string.Empty; |
PhysicsFPS.Enabled = false; |
ActiveScripts.Text = string.Empty; |
ActiveScripts.Enabled = false; |
ScriptTime.Text = string.Empty; |
ScriptTime.Enabled = false; |
Objects.Text = string.Empty; |
Objects.Enabled = false; |
})); |
} |
}).Start(); |
|
|
} |
|
private void SettingsRequested(object sender, EventArgs e) |
@@ -1110,6 +1134,9 @@ |
|
private void VassalShown(object sender, EventArgs e) |
{ |
// Set the version |
vassalForm.Version.Text = @"v" + VASSAL_CONSTANTS.VASSAL_VERSION; |
|
// Get the configuration file settings if it exists. |
if (File.Exists(VASSAL_CONSTANTS.VASSAL_CONFIGURATION_FILE)) |
{ |
@@ -1120,7 +1147,7 @@ |
if (File.Exists(VASSAL_CONSTANTS.VASSAL_REGIONS)) |
{ |
Vector3 localPosition; |
ConfiguredRegions = |
List<KeyValuePair<string, Vector3>> ConfiguredRegions = new List<KeyValuePair<string, Vector3>>( |
File.ReadAllLines(VASSAL_CONSTANTS.VASSAL_REGIONS) |
.Select(o => new List<string>(wasCSVToEnumerable(o))) |
.Where(o => o.Count == 2) |
@@ -1128,19 +1155,20 @@ |
p => |
Vector3.TryParse(p.Last(), out localPosition) |
? localPosition |
: Vector3.Zero).OrderBy(o => o.Key).ToDictionary(o => o.Key, o => o.Value); |
: Vector3.Zero).OrderBy(o => o.Key).ToDictionary(o => o.Key, o => o.Value)); |
// Populate the loaded regions. |
LoadedRegions.Items.Clear(); |
LoadedRegions.Items.AddRange( |
ConfiguredRegions.Select(o => (object)new ListViewItem {Text = o.Key, Tag = o.Value}) |
ConfiguredRegions.Select(o => (object) new ListViewItem {Text = o.Key, Tag = o.Value}) |
.ToArray()); |
// Populate the batch restart grid view. |
BatchRestartGridView.Rows.Clear(); |
foreach (KeyValuePair<string, Vector3> data in ConfiguredRegions) |
{ |
BatchRestartGridView.Rows.Add(data.Key, data.Value.ToString()); |
} |
} |
|
// Update the current region in case the configuration is initialized. |
if (!vassalConfiguration.Equals(default(VassalConfiguration))) |
{ |
updateCurrentRegionName.BeginInvoke(updateCurrentRegionName.EndInvoke, null); |
} |
|
// Set the map image to the loading spinner. |
Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); |
System.IO.Stream file = |
@@ -1148,7 +1176,7 @@ |
switch (file != null) |
{ |
case true: |
vassalForm.Invoke((MethodInvoker)(() => |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
RegionAvatarsMap.SizeMode = PictureBoxSizeMode.CenterImage; |
RegionAvatarsMap.Image = Image.FromStream(file); |
@@ -1189,7 +1217,8 @@ |
"PhysicsFPS", |
"ActiveScripts", |
"ScriptTime", |
"Objects" |
"Objects", |
"Name" |
}) |
} |
}), vassalConfiguration.DataTimeout); |
@@ -1205,16 +1234,30 @@ |
|
vassalForm.Invoke((MethodInvoker) (() => |
{ |
// Show the region name. |
vassalForm.CurrentRegionName.Text = data[data.IndexOf("Name") + 1]; |
vassalForm.CurrentRegionAt.Visible = true; |
vassalForm.CurrentRegionName.Visible = true; |
|
// Populate the overview tab. |
Agents.Text = data[data.IndexOf("Agents") + 1]; |
Agents.Enabled = true; |
LastLag.Text = data[data.IndexOf("LastLag") + 1]; |
LastLag.Enabled = true; |
Dilation.Text = data[data.IndexOf("Dilation") + 1]; |
Dilation.Enabled = true; |
FPS.Text = data[data.IndexOf("FPS") + 1]; |
FPS.Enabled = true; |
PhysicsFPS.Text = data[data.IndexOf("PhysicsFPS") + 1]; |
PhysicsFPS.Enabled = true; |
ActiveScripts.Text = data[data.IndexOf("ActiveScripts") + 1]; |
ActiveScripts.Enabled = true; |
ScriptTime.Text = data[data.IndexOf("ScriptTime") + 1]; |
ScriptTime.Enabled = true; |
Objects.Text = data[data.IndexOf("Objects") + 1]; |
Objects.Enabled = true; |
})); |
|
|
// Get the map image. |
result = wasPOST(vassalConfiguration.HTTPServerURL, |
wasKeyValueEscape(new Dictionary<string, string> |
@@ -1222,9 +1265,9 @@ |
{"command", "getgridregiondata"}, |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{ "data", "MapImageID"} |
{"data", "MapImageID"} |
}), vassalConfiguration.DataTimeout); |
|
|
if (string.IsNullOrEmpty(result) || |
!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
throw new Exception(); |
@@ -1238,9 +1281,9 @@ |
{"command", "download"}, |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"item", data.Last() }, |
{"type", "Texture" }, |
{"format", "Jpeg" }, |
{"item", data.Last()}, |
{"type", "Texture"}, |
{"format", "Jpeg"}, |
}), vassalConfiguration.DataTimeout); |
if (string.IsNullOrEmpty(result) || |
!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
@@ -1259,7 +1302,7 @@ |
{"command", "getavatarpositions"}, |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{ "entity", "region"} |
{"entity", "region"} |
}), vassalConfiguration.DataTimeout); |
|
if (string.IsNullOrEmpty(result) || |
@@ -1267,7 +1310,11 @@ |
throw new Exception(); |
|
// Every thrid element represents a Vecto3 of the avatar position. |
data = wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))).Skip(2).Where((x, i) => i % 3 == 0).ToList(); |
data = |
wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))) |
.Skip(2) |
.Where((x, i) => i%3 == 0) |
.ToList(); |
|
// Draw the avatars onto the map. |
Graphics mapGraphics = Graphics.FromImage(mapImage); |
@@ -1277,7 +1324,8 @@ |
switch (Vector3.TryParse(vector, out position)) |
{ |
case true: |
mapGraphics.FillEllipse(Brushes.Chartreuse, new Rectangle((int)position.X, (int)position.Y, 4, 4)); |
mapGraphics.FillEllipse(Brushes.Chartreuse, |
new Rectangle((int) position.X, (int) position.Y, 4, 4)); |
break; |
} |
} |
@@ -1298,7 +1346,7 @@ |
{ |
Monitor.Exit(ClientInstanceTeleportLock); |
} |
|
|
}; |
overviewTabTimer.Start(); |
|
@@ -1342,35 +1390,39 @@ |
|
vassalForm.Invoke((MethodInvoker) (() => |
{ |
switch (!TopScriptsGridView.Rows.Count.Equals(0)) |
// Remove rows that are not in the data update. |
foreach ( |
int index in |
TopScriptsGridView.Rows.AsParallel().Cast<DataGridViewRow>() |
.Where( |
topScriptsRow => |
!data.Any(q => q[2].Equals(topScriptsRow.Cells["TopScriptsUUID"].Value))) |
.Select(q => q.Index)) |
{ |
case true: |
foreach (DataGridViewRow topScriptsRow in (IEnumerable)TopScriptsGridView.Rows) |
{ |
List<string> updateRowData = |
data.AsParallel() |
.FirstOrDefault(q => q[2].Equals(topScriptsRow.Cells["TopScriptsUUID"].Value.ToString())); |
switch (updateRowData != null && updateRowData.Count.Equals(5)) |
{ |
case true: |
topScriptsRow.Cells["TopScriptsScore"].Value = updateRowData[0]; |
topScriptsRow.Cells["TopScriptsTaskName"].Value = updateRowData[1]; |
topScriptsRow.Cells["TopScriptsUUID"].Value = updateRowData[2]; |
topScriptsRow.Cells["TopScriptsOwner"].Value = updateRowData[3]; |
topScriptsRow.Cells["TopScriptsPosition"].Value = updateRowData[4]; |
break; |
} |
} |
break; |
default: |
foreach (List<string> updateRowData in data) |
{ |
TopScriptsGridView.Rows.Add(updateRowData[0], updateRowData[1], updateRowData[2], |
updateRowData[3], updateRowData[4]); |
} |
break; |
TopScriptsGridView.Rows.RemoveAt(index); |
} |
|
// Now update or add new data. |
foreach (List<string> dataComponents in data.Where(q => q.Count.Equals(5))) |
{ |
DataGridViewRow row = |
TopScriptsGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.FirstOrDefault(q => q.Cells["TopScriptsUUID"].Value.Equals(dataComponents[2])); |
switch (row != null) |
{ |
case true: // the row exists, so update it. |
row.Cells["TopScriptsScore"].Value = dataComponents[0]; |
row.Cells["TopScriptsTaskName"].Value = dataComponents[1]; |
row.Cells["TopScriptsUUID"].Value = dataComponents[2]; |
row.Cells["TopScriptsOwner"].Value = dataComponents[3]; |
row.Cells["TopScriptsPosition"].Value = dataComponents[4]; |
break; |
case false: // the row dosn't exist, so add it. |
TopScriptsGridView.Rows.Add(dataComponents[0], dataComponents[1], dataComponents[2], |
dataComponents[3], dataComponents[4]); |
break; |
} |
} |
})); |
} |
catch (Exception) |
@@ -1393,7 +1445,7 @@ |
try |
{ |
// Do not do anything in case the tab is not selected. |
vassalForm.Invoke((MethodInvoker)(() => |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
if (!Tabs.SelectedTab.Equals(TopCollidersTab)) |
throw new Exception(); |
@@ -1416,42 +1468,47 @@ |
|
HashSet<List<string>> data = |
new HashSet<List<string>>(wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))) |
.Select((x, i) => new { Index = i, Value = x }) |
.GroupBy(x => x.Index / 5) |
.Select((x, i) => new {Index = i, Value = x}) |
.GroupBy(x => x.Index/5) |
.Select(x => x.Select(v => v.Value).ToList())); |
if (data.Count.Equals(0)) |
throw new Exception(); |
|
vassalForm.Invoke((MethodInvoker)(() => |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
switch (!TopCollidersGridView.Rows.Count.Equals(0)) |
// Remove rows that are not in the data update. |
foreach ( |
int index in |
TopCollidersGridView.Rows.AsParallel().Cast<DataGridViewRow>() |
.Where( |
topCollidersRow => |
!data.Any(q => q[2].Equals(topCollidersRow.Cells["TopCollidersUUID"].Value))) |
.Select(q => q.Index)) |
{ |
case true: |
foreach (DataGridViewRow topCollidersRow in (IEnumerable)TopCollidersGridView.Rows) |
{ |
List<string> updateRowData = |
data.AsParallel() |
.FirstOrDefault(q => q[2].Equals(topCollidersRow.Cells["TopCollidersUUID"].Value.ToString())); |
switch (updateRowData != null && updateRowData.Count.Equals(5)) |
{ |
case true: |
topCollidersRow.Cells["TopCollidersScore"].Value = updateRowData[0]; |
topCollidersRow.Cells["TopCollidersTaskName"].Value = updateRowData[1]; |
topCollidersRow.Cells["TopCollidersUUID"].Value = updateRowData[2]; |
topCollidersRow.Cells["TopCollidersOwner"].Value = updateRowData[3]; |
topCollidersRow.Cells["TopCollidersPosition"].Value = updateRowData[4]; |
break; |
} |
} |
break; |
default: |
foreach (List<string> updateRowData in data) |
{ |
TopCollidersGridView.Rows.Add(updateRowData[0], updateRowData[1], updateRowData[2], |
updateRowData[3], updateRowData[4]); |
} |
break; |
TopCollidersGridView.Rows.RemoveAt(index); |
} |
// Now update or add new data. |
foreach (List<string> dataComponents in data.Where(q => q.Count.Equals(5))) |
{ |
DataGridViewRow row = |
TopCollidersGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.FirstOrDefault(q => q.Cells["TopCollidersUUID"].Value.Equals(dataComponents[2])); |
switch (row != null) |
{ |
case true: // the row exists, so update it. |
row.Cells["TopCollidersScore"].Value = dataComponents[0]; |
row.Cells["TopSCollidersTaskName"].Value = dataComponents[1]; |
row.Cells["TopCollidersUUID"].Value = dataComponents[2]; |
row.Cells["TopCollidersOwner"].Value = dataComponents[3]; |
row.Cells["TopCollidersPosition"].Value = dataComponents[4]; |
break; |
case false: // the row dosn't exist, so add it. |
TopCollidersGridView.Rows.Add(dataComponents[0], dataComponents[1], dataComponents[2], |
dataComponents[3], dataComponents[4]); |
break; |
} |
} |
|
})); |
} |
@@ -1471,7 +1528,7 @@ |
{ |
// Clear any selection. |
LoadedRegions.SelectedIndex = -1; |
RegionEditForm regionEditForm = new RegionEditForm { TopMost = true }; |
RegionEditForm regionEditForm = new RegionEditForm {TopMost = true}; |
regionEditForm.Show(); |
} |
|
@@ -1479,5 +1536,516 @@ |
{ |
e.Cancel = !e.TabPage.Enabled; |
} |
|
private void RequestExportTopScripts(object sender, EventArgs e) |
{ |
vassalForm.BeginInvoke((MethodInvoker) (() => |
{ |
switch (vassalForm.ExportCSVDialog.ShowDialog()) |
{ |
case DialogResult.OK: |
string file = vassalForm.ExportCSVDialog.FileName; |
new Thread(() => |
{ |
vassalForm.BeginInvoke((MethodInvoker) (() => |
{ |
try |
{ |
vassalForm.StatusText.Text = @"exporting..."; |
vassalForm.StatusProgress.Value = 0; |
|
using (StreamWriter streamWriter = new StreamWriter(file, false, Encoding.UTF8)) |
{ |
foreach (DataGridViewRow topScriptsRow in TopScriptsGridView.Rows) |
{ |
streamWriter.WriteLine(wasEnumerableToCSV(new[] |
{ |
topScriptsRow.Cells["TopScriptsScore"].Value.ToString(), |
topScriptsRow.Cells["TopScriptsTaskName"].Value.ToString(), |
topScriptsRow.Cells["TopScriptsUUID"].Value.ToString(), |
topScriptsRow.Cells["TopScriptsOwner"].Value.ToString(), |
topScriptsRow.Cells["TopScriptsPosition"].Value.ToString() |
})); |
} |
} |
|
vassalForm.StatusText.Text = @"exported"; |
vassalForm.StatusProgress.Value = 100; |
} |
catch (Exception ex) |
{ |
vassalForm.StatusText.Text = ex.Message; |
} |
})); |
}) |
{IsBackground = true, Priority = ThreadPriority.Normal}.Start(); |
break; |
} |
})); |
} |
|
private void RequestExportTopColliders(object sender, EventArgs e) |
{ |
vassalForm.BeginInvoke((MethodInvoker) (() => |
{ |
switch (vassalForm.ExportCSVDialog.ShowDialog()) |
{ |
case DialogResult.OK: |
string file = vassalForm.ExportCSVDialog.FileName; |
new Thread(() => |
{ |
vassalForm.BeginInvoke((MethodInvoker) (() => |
{ |
try |
{ |
vassalForm.StatusText.Text = @"exporting..."; |
vassalForm.StatusProgress.Value = 0; |
|
using (StreamWriter streamWriter = new StreamWriter(file, false, Encoding.UTF8)) |
{ |
foreach (DataGridViewRow topCollidersRow in TopCollidersGridView.Rows) |
{ |
streamWriter.WriteLine(wasEnumerableToCSV(new[] |
{ |
topCollidersRow.Cells["TopCollidersScore"].Value.ToString(), |
topCollidersRow.Cells["TopCollidersTaskName"].Value.ToString(), |
topCollidersRow.Cells["TopCollidersUUID"].Value.ToString(), |
topCollidersRow.Cells["TopCollidersOwner"].Value.ToString(), |
topCollidersRow.Cells["TopCollidersPosition"].Value.ToString() |
})); |
} |
} |
|
vassalForm.StatusText.Text = @"exported"; |
vassalForm.StatusProgress.Value = 100; |
} |
catch (Exception ex) |
{ |
vassalForm.StatusText.Text = ex.Message; |
} |
})); |
}) |
{IsBackground = true, Priority = ThreadPriority.Normal}.Start(); |
break; |
} |
})); |
} |
|
private void RequestFilterTopScripts(object sender, EventArgs e) |
{ |
vassalForm.BeginInvoke((MethodInvoker) (() => |
{ |
Regex topScriptsRowRegex; |
switch (!string.IsNullOrEmpty(TopScriptsFilter.Text)) |
{ |
case true: |
topScriptsRowRegex = new Regex(TopScriptsFilter.Text, RegexOptions.Compiled); |
break; |
default: |
topScriptsRowRegex = new Regex(@".+?", RegexOptions.Compiled); |
break; |
} |
foreach (DataGridViewRow topScriptsRow in TopScriptsGridView.Rows.AsParallel().Cast<DataGridViewRow>()) |
{ |
topScriptsRow.Visible = |
topScriptsRowRegex.IsMatch(topScriptsRow.Cells["TopScriptsScore"].Value.ToString()) || |
topScriptsRowRegex.IsMatch( |
topScriptsRow.Cells["TopScriptsTaskName"].Value.ToString()) || |
topScriptsRowRegex.IsMatch(topScriptsRow.Cells["TopScriptsUUID"].Value.ToString()) || |
topScriptsRowRegex.IsMatch(topScriptsRow.Cells["TopScriptsOwner"].Value.ToString()) || |
topScriptsRowRegex.IsMatch( |
topScriptsRow.Cells["TopScriptsPosition"].Value.ToString()); |
} |
})); |
} |
|
private void RequestFilterTopColliders(object sender, EventArgs e) |
{ |
vassalForm.BeginInvoke((MethodInvoker)(() => |
{ |
Regex topCollidersRowRegex; |
switch (!string.IsNullOrEmpty(TopScriptsFilter.Text)) |
{ |
case true: |
topCollidersRowRegex = new Regex(TopScriptsFilter.Text, RegexOptions.Compiled); |
break; |
default: |
topCollidersRowRegex = new Regex(@".+?", RegexOptions.Compiled); |
break; |
} |
foreach (DataGridViewRow topCollidersRow in TopCollidersGridView.Rows.AsParallel().Cast<DataGridViewRow>()) |
{ |
topCollidersRow.Visible = |
topCollidersRowRegex.IsMatch(topCollidersRow.Cells["TopCollidersScore"].Value.ToString()) || |
topCollidersRowRegex.IsMatch( |
topCollidersRow.Cells["TopCollidersTaskName"].Value.ToString()) || |
topCollidersRowRegex.IsMatch(topCollidersRow.Cells["TopCollidersUUID"].Value.ToString()) || |
topCollidersRowRegex.IsMatch(topCollidersRow.Cells["TopCollidersOwner"].Value.ToString()) || |
topCollidersRowRegex.IsMatch( |
topCollidersRow.Cells["TopCollidersPosition"].Value.ToString()); |
} |
})); |
} |
|
private void RequestReturnTopScriptsObjects(object sender, EventArgs e) |
{ |
// Block teleports and disable button. |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.ReturnTopScriptsButton.Enabled = false; |
RegionTeleportGroup.Enabled = false; |
})); |
|
// Enqueue all the UUIDs to return. |
Queue<KeyValuePair<UUID, Vector3>> returnUUIDs = new Queue<KeyValuePair<UUID, Vector3>>(); |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
foreach ( |
DataGridViewRow topScriptsRow in |
TopScriptsGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
{ |
Vector3 objectPosition; |
UUID returnUUID; |
if (!UUID.TryParse(topScriptsRow.Cells["TopScriptsUUID"].Value.ToString(), out returnUUID) || |
!Vector3.TryParse(topScriptsRow.Cells["TopScriptsPosition"].Value.ToString(), out objectPosition)) |
continue; |
returnUUIDs.Enqueue(new KeyValuePair<UUID, Vector3>(returnUUID, objectPosition)); |
} |
})); |
|
// If no rows were selected, enable teleports, the return button and return. |
if (returnUUIDs.Count.Equals(0)) |
{ |
vassalForm.Invoke((MethodInvoker)(() => |
{ |
vassalForm.ReturnTopScriptsButton.Enabled = true; |
RegionTeleportGroup.Enabled = true; |
})); |
return; |
} |
|
new Thread(() => |
{ |
Monitor.Enter(ClientInstanceTeleportLock); |
|
try |
{ |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.StatusProgress.Value = 0; |
})); |
int totalObjects = returnUUIDs.Count; |
do |
{ |
// Dequeue the first object. |
KeyValuePair<UUID, Vector3> objectData = returnUUIDs.Dequeue(); |
|
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.StatusText.Text = @"Returning object UUID: " + objectData.Key.ToString(); |
})); |
|
string currentRegionName = string.Empty; |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
currentRegionName = CurrentRegionName.Text; |
})); |
|
// Teleport to the object. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
wasKeyValueEscape(new Dictionary<string, string> |
{ |
{"command", "teleport"}, |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"position", objectData.Value.ToString()}, |
{"region", currentRegionName}, |
{"fly", "True"} |
}), vassalConfiguration.TeleportTimeout); |
|
if (string.IsNullOrEmpty(result)) |
{ |
vassalForm.Invoke((MethodInvoker)(() => |
{ |
vassalForm.StatusText.Text = @"Error communicating with Corrade."; |
})); |
continue; |
} |
|
// Return the object. |
result = wasPOST(vassalConfiguration.HTTPServerURL, |
wasKeyValueEscape(new Dictionary<string, string> |
{ |
{"command", "derez"}, |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"item", objectData.Key.ToString()}, |
{"range", "32" }, // maximal prim size = 64 - middle bounding box at half |
{"type", "ReturnToOwner"} |
}), vassalConfiguration.DataTimeout); |
|
if (string.IsNullOrEmpty(result)) |
{ |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.StatusText.Text = @"Error communicating with Corrade."; |
})); |
continue; |
} |
|
bool success; |
if (!bool.TryParse(wasInput(wasKeyValueGet("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 = @"Returned object: " + objectData.Key.ToString(); |
// Remove the row from the grid view. |
DataGridViewRow row = |
TopScriptsGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.FirstOrDefault( |
o => o.Cells["TopScriptsUUID"].Value.Equals(objectData.Key.ToString())); |
if (row == null) return; |
int i = row.Index; |
TopScriptsGridView.Rows.RemoveAt(i); |
})); |
break; |
case false: |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.StatusText.Text = @"Could not return object " + objectData.Key.ToString() + |
@": " + |
wasInput(wasKeyValueGet("error", result)); |
})); |
break; |
} |
|
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.StatusProgress.Value = |
Math.Min((int) (Math.Abs(returnUUIDs.Count - totalObjects)/ |
(double) totalObjects), 100); |
})); |
} while (!returnUUIDs.Count.Equals(0)); |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.StatusProgress.Value = 100; |
})); |
} |
catch (Exception ex) |
{ |
vassalForm.Invoke((MethodInvoker)(() => |
{ |
vassalForm.StatusText.Text = @"Unexpected error: " + ex.Message; |
})); |
} |
finally |
{ |
Monitor.Exit(ClientInstanceTeleportLock); |
// Allow teleports and enable button. |
vassalForm.BeginInvoke((MethodInvoker)(() => |
{ |
vassalForm.ReturnTopScriptsButton.Enabled = true; |
RegionTeleportGroup.Enabled = true; |
})); |
} |
}) |
{IsBackground = true}.Start(); |
} |
|
private void RequestReturnTopCollidersObjects(object sender, EventArgs e) |
{ |
// Block teleports and disable button. |
vassalForm.Invoke((MethodInvoker)(() => |
{ |
vassalForm.ReturnTopCollidersButton.Enabled = false; |
RegionTeleportGroup.Enabled = false; |
})); |
|
// Enqueue all the UUIDs to return. |
Queue<KeyValuePair<UUID, Vector3>> returnUUIDs = new Queue<KeyValuePair<UUID, Vector3>>(); |
vassalForm.Invoke((MethodInvoker)(() => |
{ |
foreach ( |
DataGridViewRow topCollidersRow in |
TopCollidersGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
{ |
Vector3 objectPosition; |
UUID returnUUID; |
if (!UUID.TryParse(topCollidersRow.Cells["TopCollidersUUID"].Value.ToString(), out returnUUID) || |
!Vector3.TryParse(topCollidersRow.Cells["TopCollidersPosition"].Value.ToString(), out objectPosition)) |
continue; |
returnUUIDs.Enqueue(new KeyValuePair<UUID, Vector3>(returnUUID, objectPosition)); |
} |
})); |
|
// If no rows were selected, enable teleports, the return button and return. |
if (returnUUIDs.Count.Equals(0)) |
{ |
vassalForm.Invoke((MethodInvoker)(() => |
{ |
vassalForm.ReturnTopCollidersButton.Enabled = true; |
RegionTeleportGroup.Enabled = true; |
})); |
return; |
} |
|
new Thread(() => |
{ |
Monitor.Enter(ClientInstanceTeleportLock); |
|
try |
{ |
vassalForm.Invoke((MethodInvoker)(() => |
{ |
vassalForm.StatusProgress.Value = 0; |
})); |
int totalObjects = returnUUIDs.Count; |
do |
{ |
// Dequeue the first object. |
KeyValuePair<UUID, Vector3> objectData = returnUUIDs.Dequeue(); |
|
vassalForm.Invoke((MethodInvoker)(() => |
{ |
vassalForm.StatusText.Text = @"Returning UUID: " + objectData.Key.ToString(); |
})); |
|
string currentRegionName = string.Empty; |
vassalForm.Invoke((MethodInvoker)(() => |
{ |
currentRegionName = CurrentRegionName.Text; |
})); |
|
// Teleport to the object. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
wasKeyValueEscape(new Dictionary<string, string> |
{ |
{"command", "teleport"}, |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"position", objectData.Value.ToString()}, |
{"region", currentRegionName}, |
{"fly", "True"} |
}), vassalConfiguration.DataTimeout); |
|
if (string.IsNullOrEmpty(result)) |
{ |
vassalForm.Invoke((MethodInvoker)(() => |
{ |
vassalForm.StatusText.Text = @"Error communicating with Corrade."; |
})); |
continue; |
} |
|
// Return the object. |
result = wasPOST(vassalConfiguration.HTTPServerURL, |
wasKeyValueEscape(new Dictionary<string, string> |
{ |
{"command", "derez"}, |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"item", objectData.Key.ToString()}, |
{"range", "32" }, // maximal prim size = 64 - middle bounding box at half |
{"type", "ReturnToOwner"} |
}), vassalConfiguration.DataTimeout); |
|
if (string.IsNullOrEmpty(result)) |
{ |
vassalForm.Invoke((MethodInvoker)(() => |
{ |
vassalForm.StatusText.Text = @"Error communicating with Corrade."; |
})); |
continue; |
} |
|
bool success; |
if (!bool.TryParse(wasInput(wasKeyValueGet("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 = @"Returned object: " + objectData.Key.ToString(); |
// Remove the row from the grid view. |
DataGridViewRow row = |
TopCollidersGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.FirstOrDefault( |
o => o.Cells["TopCollidersUUID"].Value.Equals(objectData.Key.ToString())); |
if (row == null) return; |
int i = row.Index; |
TopCollidersGridView.Rows.RemoveAt(i); |
})); |
break; |
case false: |
vassalForm.Invoke((MethodInvoker)(() => |
{ |
vassalForm.StatusText.Text = @"Could not return object " + objectData.Key.ToString() + |
@": " + |
wasInput(wasKeyValueGet("error", result)); |
})); |
break; |
} |
|
vassalForm.Invoke((MethodInvoker)(() => |
{ |
vassalForm.StatusProgress.Value = |
Math.Min((int)(Math.Abs(returnUUIDs.Count - totalObjects) / |
(double)totalObjects), 100); |
})); |
} while (!returnUUIDs.Count.Equals(0)); |
vassalForm.Invoke((MethodInvoker)(() => |
{ |
vassalForm.StatusProgress.Value = 100; |
})); |
} |
catch (Exception ex) |
{ |
vassalForm.Invoke((MethodInvoker)(() => |
{ |
vassalForm.StatusText.Text = @"Unexpected error: " + ex.Message; |
})); |
} |
finally |
{ |
Monitor.Exit(ClientInstanceTeleportLock); |
// Allow teleports and enable button. |
vassalForm.BeginInvoke((MethodInvoker)(() => |
{ |
vassalForm.ReturnTopScriptsButton.Enabled = true; |
RegionTeleportGroup.Enabled = true; |
})); |
} |
}) |
{ IsBackground = true }.Start(); |
} |
|
private void RequestBatchRestart(object sender, EventArgs e) |
{ |
|
} |
} |
} |