/Vassal/Vassal/VassalForm.cs |
@@ -6,6 +6,7 @@ |
|
using System; |
using System.Collections.Generic; |
using System.Diagnostics; |
using System.Drawing; |
using System.Drawing.Imaging; |
using System.IO; |
@@ -499,6 +500,9 @@ |
vassalForm.StatusText.Text = @"Teleporting to " + selectedRegionName; |
})); |
|
// Pause for teleport (10 teleports / 15s allowed). |
Thread.Sleep(700); |
|
int elapsedSeconds = 0; |
Timer teleportTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); |
teleportTimer.Elapsed += (o, p) => |
@@ -619,6 +623,14 @@ |
ActiveScripts.Enabled = false; |
ScriptTime.Text = string.Empty; |
ScriptTime.Enabled = false; |
FrameTime.Text = string.Empty; |
FrameTime.Enabled = false; |
ScriptedObjects.Text = string.Empty; |
ScriptedObjects.Enabled = false; |
PhysicsTime.Text = string.Empty; |
PhysicsTime.Enabled = false; |
NetTime.Text = string.Empty; |
NetTime.Enabled = false; |
Objects.Text = string.Empty; |
Objects.Enabled = false; |
})); |
@@ -653,7 +665,9 @@ |
EstateTopTab.Enabled = false; |
EstateListsTab.Enabled = false; |
ResidentListBanGroup.Enabled = false; |
ResidentListTeleportHomeGroup.Enabled = false; |
EstateTerrainDownloadUploadGroup.Enabled = false; |
EstateVariablesGroup.Enabled = false; |
// Estate textures |
RegionTexturesLowUUIDApplyBox.Enabled = false; |
RegionTexturesLowUUIDApplyButton.Enabled = false; |
@@ -734,6 +748,7 @@ |
break; |
} |
Tabs.Enabled = true; |
RegionTeleportGroup.Enabled = true; |
})); |
} |
catch (Exception) |
@@ -757,6 +772,7 @@ |
break; |
} |
Tabs.Enabled = false; |
RegionTeleportGroup.Enabled = false; |
})); |
} |
|
@@ -799,7 +815,9 @@ |
EstateTopTab.Enabled = true; |
EstateListsTab.Enabled = true; |
ResidentListBanGroup.Enabled = true; |
ResidentListTeleportHomeGroup.Enabled = true; |
EstateTerrainDownloadUploadGroup.Enabled = true; |
EstateVariablesGroup.Enabled = true; |
RegionToolsRegionDebugGroup.Enabled = true; |
RegionToolsRegionInfoGroup.Enabled = true; |
// Estate textures |
@@ -816,7 +834,9 @@ |
EstateTopTab.Enabled = false; |
EstateListsTab.Enabled = false; |
ResidentListBanGroup.Enabled = false; |
ResidentListTeleportHomeGroup.Enabled = false; |
EstateTerrainDownloadUploadGroup.Enabled = false; |
EstateVariablesGroup.Enabled = false; |
RegionToolsRegionDebugGroup.Enabled = false; |
RegionToolsRegionInfoGroup.Enabled = false; |
// Estate textures |
@@ -862,6 +882,9 @@ |
|
try |
{ |
// Start measuring the lag to Corrade. |
Stopwatch stopWatch = new Stopwatch(); |
stopWatch.Start(); |
// Get the statistics. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
wasKeyValueEscape(new Dictionary<string, string> |
@@ -880,10 +903,15 @@ |
"ActiveScripts", |
"ScriptTime", |
"Objects", |
"FrameTime", |
"ScriptedObjects", |
"PhysicsTime", |
"NetTime", |
"AvatarPositions" |
}) |
} |
}), vassalConfiguration.DataTimeout); |
stopWatch.Stop(); |
|
bool success; |
if (string.IsNullOrEmpty(result) || |
@@ -911,8 +939,21 @@ |
ActiveScripts.Enabled = true; |
ScriptTime.Text = data[data.IndexOf("ScriptTime") + 1]; |
ScriptTime.Enabled = true; |
FrameTime.Text = data[data.IndexOf("FrameTime") + 1]; |
FrameTime.Enabled = true; |
ScriptedObjects.Text = data[data.IndexOf("ScriptedObjects") + 1]; |
ScriptedObjects.Enabled = true; |
PhysicsTime.Text = data[data.IndexOf("PhysicsTime") + 1]; |
PhysicsTime.Enabled = true; |
NetTime.Text = data[data.IndexOf("NetTime") + 1]; |
NetTime.Enabled = true; |
Objects.Text = data[data.IndexOf("Objects") + 1]; |
Objects.Enabled = true; |
|
// Show the overview lag time. |
CorradePollTimeDial.Value = |
(float) Math.Min(TimeSpan.FromMilliseconds(stopWatch.ElapsedMilliseconds).TotalSeconds, |
CorradePollTimeDial.MaxValue); |
})); |
|
// Get avatar positions. |
@@ -2037,7 +2078,6 @@ |
vassalForm.Invoke( |
(MethodInvoker) |
(() => { vassalForm.StatusText.Text = @"Teleport succeeded."; })); |
Thread.Sleep(TimeSpan.FromSeconds(1).Milliseconds); |
break; |
default: |
// In case the destination is to close (Corrade status code 37559), |
@@ -2054,11 +2094,13 @@ |
vassalForm.Invoke( |
(MethodInvoker) |
(() => { vassalForm.StatusText.Text = @"Teleport failed."; })); |
Thread.Sleep(10000); |
break; |
} |
break; |
} |
|
// Pause for teleport (10 teleports / 15s allowed). |
Thread.Sleep(700); |
} while (!success && !(--teleportRetries).Equals(0)); |
|
if (!success) |
@@ -2146,6 +2188,11 @@ |
} |
})); |
} |
finally |
{ |
// Pause for teleport (10 teleports / 15s allowed). |
Thread.Sleep(700); |
} |
} while (!restartRegionQueue.Count.Equals(0)); |
} |
catch (Exception) |
@@ -2196,11 +2243,12 @@ |
// Block teleports and disable button. |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
ResidentListTeleportHomeGroup.Enabled = false; |
ResidentListBanGroup.Enabled = false; |
RegionTeleportGroup.Enabled = false; |
})); |
|
// Enqueue all the regions to restart. |
// Enqueue all the agents to ban. |
Queue<UUID> agentsQueue = new Queue<UUID>(); |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
@@ -2256,7 +2304,7 @@ |
vassalForm.Invoke( |
(MethodInvoker) (() => { alsoBan = vassalForm.ResidentBanAllEstatesBox.Checked; })); |
|
// Teleport to the region. |
// Ban the resident. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
wasKeyValueEscape(new Dictionary<string, string> |
{ |
@@ -2322,6 +2370,7 @@ |
// Allow teleports and enable button. |
vassalForm.BeginInvoke((MethodInvoker) (() => |
{ |
ResidentListTeleportHomeGroup.Enabled = true; |
ResidentListBanGroup.Enabled = true; |
RegionTeleportGroup.Enabled = true; |
})); |
@@ -3999,6 +4048,294 @@ |
})); |
} |
|
private void RequestTeleportHome(object sender, EventArgs e) |
{ |
// Block teleports and disable button. |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
ResidentListTeleportHomeGroup.Enabled = false; |
ResidentListBanGroup.Enabled = false; |
RegionTeleportGroup.Enabled = false; |
})); |
|
// Enqueue all the agents to teleport home. |
Queue<UUID> agentsQueue = new Queue<UUID>(); |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
foreach ( |
DataGridViewRow residentListRow in |
ResidentListGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
{ |
UUID agentUUID; |
if (!UUID.TryParse(residentListRow.Cells["ResidentListUUID"].Value.ToString(), out agentUUID)) |
continue; |
agentsQueue.Enqueue(agentUUID); |
} |
})); |
|
// If no rows were selected, enable teleports, the return button and return. |
if (agentsQueue.Count.Equals(0)) |
{ |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
ResidentListBanGroup.Enabled = true; |
RegionTeleportGroup.Enabled = true; |
})); |
return; |
} |
|
new Thread(() => |
{ |
Monitor.Enter(ClientInstanceTeleportLock); |
try |
{ |
do |
{ |
// Dequeue the first object. |
UUID agentUUID = agentsQueue.Dequeue(); |
DataGridViewRow currentDataGridViewRow = null; |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
currentDataGridViewRow = vassalForm.ResidentListGridView.Rows.AsParallel() |
.Cast<DataGridViewRow>() |
.FirstOrDefault( |
o => |
o.Cells["ResidentListUUID"].Value.ToString() |
.Equals(agentUUID.ToString(), StringComparison.OrdinalIgnoreCase)); |
})); |
|
if (currentDataGridViewRow == null) continue; |
|
try |
{ |
// Teleport the user home. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
wasKeyValueEscape(new Dictionary<string, string> |
{ |
{"command", "estateteleportusershome"}, |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"avatars", agentUUID.ToString()} |
}), vassalConfiguration.DataTimeout); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade."); |
|
bool success; |
if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
throw new Exception("No success status could be retrieved."); |
|
switch (success) |
{ |
case true: |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.StatusText.Text = @"Resident teleported home."; |
currentDataGridViewRow.Selected = false; |
currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightGreen; |
foreach ( |
DataGridViewCell cell in |
currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
{ |
cell.ToolTipText = @"Resident teleported home."; |
} |
})); |
break; |
default: |
throw new Exception("Unable to teleport resident home."); |
} |
} |
catch (Exception ex) |
{ |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
vassalForm.StatusText.Text = ex.Message; |
currentDataGridViewRow.Selected = false; |
currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightPink; |
foreach ( |
DataGridViewCell cell in |
currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
{ |
cell.ToolTipText = ex.Message; |
} |
})); |
} |
} while (agentsQueue.Count.Equals(0)); |
} |
catch (Exception) |
{ |
} |
finally |
{ |
Monitor.Exit(ClientInstanceTeleportLock); |
// Allow teleports and enable button. |
vassalForm.BeginInvoke((MethodInvoker) (() => |
{ |
ResidentListTeleportHomeGroup.Enabled = true; |
ResidentListBanGroup.Enabled = true; |
RegionTeleportGroup.Enabled = true; |
})); |
} |
}) |
{IsBackground = true}.Start(); |
} |
|
private void RequestSetVariables(object sender, EventArgs e) |
{ |
// Block teleports and disable button. |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
RegionTeleportGroup.Enabled = false; |
SetTerrainVariablesButton.Enabled = false; |
})); |
|
new Thread(() => |
{ |
try |
{ |
Monitor.Enter(ClientInstanceTeleportLock); |
|
int waterHeight = 10; |
int terrainRaiseLimit = 100; |
int terrainLowerLimit = -100; |
bool useEstateSun = true; |
bool fixedSun = false; |
int sunPosition = 18; |
|
bool run = false; |
|
vassalForm.Invoke((MethodInvoker) (() => |
{ |
useEstateSun = TerrainToolsUseEstateSunBox.Checked; |
fixedSun = TerrainToolsFixedSunBox.Checked; |
switch (!int.TryParse(TerrainToolsWaterHeightBox.Text, out waterHeight)) |
{ |
case true: |
TerrainToolsWaterHeightBox.BackColor = Color.MistyRose; |
return; |
default: |
TerrainToolsWaterHeightBox.BackColor = Color.Empty; |
break; |
} |
switch (!int.TryParse(TerrainToolsTerrainRaiseLimitBox.Text, out terrainRaiseLimit)) |
{ |
case true: |
TerrainToolsTerrainRaiseLimitBox.BackColor = Color.MistyRose; |
return; |
default: |
TerrainToolsTerrainRaiseLimitBox.BackColor = Color.Empty; |
break; |
} |
switch (!int.TryParse(TerrainToolsTerrainLowerLimitBox.Text, out terrainLowerLimit)) |
{ |
case true: |
TerrainToolsTerrainLowerLimitBox.BackColor = Color.MistyRose; |
return; |
default: |
TerrainToolsTerrainLowerLimitBox.BackColor = Color.Empty; |
break; |
} |
switch (!int.TryParse(TerrainToolsSunPositionBox.Text, out sunPosition)) |
{ |
case true: |
TerrainToolsSunPositionBox.BackColor = Color.MistyRose; |
return; |
default: |
TerrainToolsSunPositionBox.BackColor = Color.Empty; |
break; |
} |
|
run = true; |
})); |
|
if (!run) return; |
|
// Set the terrain variables. |
string result = wasPOST(vassalConfiguration.HTTPServerURL, |
wasKeyValueEscape(new Dictionary<string, string> |
{ |
{"command", "setregionterrainvariables"}, |
{"group", vassalConfiguration.Group}, |
{"password", vassalConfiguration.Password}, |
{"waterheight", waterHeight.ToString()}, |
{"terrainraiselimit", terrainRaiseLimit.ToString()}, |
{"terrainlowerlimit", terrainLowerLimit.ToString()}, |
{"useestatesun", useEstateSun.ToString()}, |
{"fixedsun", fixedSun.ToString()}, |
{"sunposition", sunPosition.ToString()} |
}), vassalConfiguration.DataTimeout); |
|
if (string.IsNullOrEmpty(result)) |
throw new Exception("Error communicating with Corrade"); |
|
bool success; |
if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
throw new Exception("No success status could be retrieved"); |
|
if (!success) |
throw new Exception("Unable to set region variables"); |
} |
catch (Exception ex) |
{ |
vassalForm.Invoke((MethodInvoker) (() => { StatusText.Text = ex.Message; })); |
} |
finally |
{ |
Monitor.Exit(ClientInstanceTeleportLock); |
} |
|
// Block teleports and disable button. |
vassalForm.Invoke((MethodInvoker) (() => |
{ |
RegionTeleportGroup.Enabled = true; |
SetTerrainVariablesButton.Enabled = true; |
})); |
}) |
{IsBackground = true}.Start(); |
} |
|
private void ReconnectRequested(object sender, EventArgs e) |
{ |
// Spawn a thread to check Corrade's connection status. |
new Thread(() => |
{ |
TcpClient tcpClient = new TcpClient(); |
try |
{ |
Uri uri = new Uri(vassalConfiguration.HTTPServerURL); |
tcpClient.Connect(uri.Host, uri.Port); |
// port open |
vassalForm.BeginInvoke((MethodInvoker) (() => { vassalForm.Tabs.Enabled = true; })); |
// set the loading spinner |
if (vassalForm.RegionAvatarsMap.Image == null) |
{ |
Assembly thisAssembly = Assembly.GetExecutingAssembly(); |
Stream file = |
thisAssembly.GetManifestResourceStream("Vassal.img.loading.gif"); |
switch (file != null) |
{ |
case true: |
vassalForm.BeginInvoke((MethodInvoker) (() => |
{ |
vassalForm.RegionAvatarsMap.SizeMode = PictureBoxSizeMode.CenterImage; |
vassalForm.RegionAvatarsMap.Image = Image.FromStream(file); |
vassalForm.RegionAvatarsMap.Refresh(); |
})); |
break; |
} |
} |
} |
catch (Exception) |
{ |
// port closed |
vassalForm.BeginInvoke((MethodInvoker) (() => { vassalForm.Tabs.Enabled = false; })); |
} |
}) |
{IsBackground = true}.Start(); |
} |
|
/// <summary> |
/// Linden constants. |
/// </summary> |