corrade-vassal – Diff between revs 2 and 3

Subversion Repositories:
Rev:
Show entire fileRegard whitespace
Rev 2 Rev 3
Line 29... Line 29...
29 public partial class Vassal : Form 29 public partial class Vassal : Form
30 { 30 {
31 public static System.Timers.Timer overviewTabTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); 31 public static System.Timers.Timer overviewTabTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds);
32 public static System.Timers.Timer topScriptsTabTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); 32 public static System.Timers.Timer topScriptsTabTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds);
33 public static System.Timers.Timer topCollidersTabTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); 33 public static System.Timers.Timer topCollidersTabTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds);
34 public static Dictionary<string, Vector3> ConfiguredRegions = new Dictionary<string, Vector3>(); -  
35 public static VassalConfiguration vassalConfiguration = new VassalConfiguration(); 34 public static VassalConfiguration vassalConfiguration = new VassalConfiguration();
36 public static Vassal vassalForm; 35 public static Vassal vassalForm;
37 public static readonly object ClientInstanceTeleportLock = new object(); 36 public static readonly object ClientInstanceTeleportLock = new object();
Line 38... Line 37...
38   37  
Line 131... Line 130...
131 }) 130 })
132 .Where(o => o.k.Equals(key)) 131 .Where(o => o.k.Equals(key))
133 .Select(o => o.v) 132 .Select(o => o.v)
134 .FirstOrDefault(); 133 .FirstOrDefault();
135 } 134 }
-   135  
136 #endregion 136 #endregion
Line 137... Line 137...
137   137  
Line 138... Line 138...
138 #region CRYPTOGRAPHY 138 #region CRYPTOGRAPHY
Line 968... Line 968...
968 vassalForm = this; 968 vassalForm = this;
969 } 969 }
Line 970... Line 970...
970   970  
971 private void RegionSelected(object sender, EventArgs e) 971 private void RegionSelected(object sender, EventArgs e)
-   972 {
-   973 string selectedRegionName = string.Empty;
972 { 974 Vector3 selectedRegionPosition = Vector3.Zero;
973 ListViewItem listViewItem = null; 975 bool startTeleport = false;
974 vassalForm.Invoke((MethodInvoker) (() => 976 vassalForm.Invoke((MethodInvoker) (() =>
975 { 977 {
976 listViewItem = LoadedRegions.SelectedItem as ListViewItem; -  
977 })); -  
978   978 ListViewItem listViewItem = LoadedRegions.SelectedItem as ListViewItem;
979 switch (listViewItem != null) 979 switch (listViewItem != null && LoadedRegions.SelectedIndex != -1)
980 { 980 {
981 case true: -  
982 vassalForm.Invoke((MethodInvoker) (() => -  
983 { 981 case true:
984 vassalForm.StatusText.Text = @"Teleporting to " + 982 selectedRegionName = listViewItem.Text;
985 listViewItem.Text; 983 selectedRegionPosition = (Vector3)listViewItem.Tag;
986 })); 984 startTeleport = true;
987 break; 985 break;
-   986 default:
988 default: 987 startTeleport = false;
989 return; 988 break;
-   989 }
Line 990... Line 990...
990 } 990 }));
991   991  
992 new Thread(() => -  
993 { -  
-   992 if (!startTeleport) return;
994 lock (ClientInstanceTeleportLock) 993
995 { -  
996 try 994  
997 { 995 // Announce teleport.
998 vassalForm.Invoke((MethodInvoker) (() => 996 vassalForm.Invoke((MethodInvoker)(() =>
999 { 997 {
-   998 vassalForm.RegionTeleportGroup.Enabled = false;
1000 vassalForm.RegionTeleportGroup.Enabled = false; 999 vassalForm.StatusProgress.Value = 0;
-   1000 vassalForm.StatusText.Text = @"Teleporting to " + selectedRegionName;
-   1001 }));
-   1002  
-   1003 new Thread(() =>
-   1004 {
-   1005 Monitor.Enter(ClientInstanceTeleportLock);
1001 vassalForm.StatusProgress.Value = 0; 1006 try
1002 })); 1007 {
1003 int elapsedSeconds = 0; 1008 int elapsedSeconds = 0;
1004 System.Timers.Timer teleportTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); 1009 System.Timers.Timer teleportTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds);
1005 teleportTimer.Elapsed += (o, p) => 1010 teleportTimer.Elapsed += (o, p) =>
Line 1023... Line 1028...
1023 wasKeyValueEscape(new Dictionary<string, string> 1028 wasKeyValueEscape(new Dictionary<string, string>
1024 { 1029 {
1025 {"command", "teleport"}, 1030 {"command", "teleport"},
1026 {"group", vassalConfiguration.Group}, 1031 {"group", vassalConfiguration.Group},
1027 {"password", vassalConfiguration.Password}, 1032 {"password", vassalConfiguration.Password},
1028 {"region", listViewItem.Text}, 1033 {"region", selectedRegionName},
1029 {"position", ((Vector3) listViewItem.Tag).ToString()}, 1034 {"position", selectedRegionPosition.ToString()},
1030 {"fly", "True"} 1035 {"fly", "True"}
1031 }), vassalConfiguration.TeleportTimeout)); 1036 }), vassalConfiguration.TeleportTimeout));
1032 receivedPOST.Set(); 1037 receivedPOST.Set();
1033 }) {IsBackground = true}.Start(); 1038 }) {IsBackground = true}.Start();
1034 receivedPOST.WaitOne((int) vassalConfiguration.TeleportTimeout, false); 1039 receivedPOST.WaitOne((int) vassalConfiguration.TeleportTimeout, false);
Line 1036... Line 1041...
1036 switch (!string.IsNullOrEmpty(result) && wasKeyValueGet("success", result) == "True") 1041 switch (!string.IsNullOrEmpty(result) && wasKeyValueGet("success", result) == "True")
1037 { 1042 {
1038 case true: 1043 case true:
1039 vassalForm.Invoke((MethodInvoker) (() => 1044 vassalForm.Invoke((MethodInvoker) (() =>
1040 { 1045 {
1041 vassalForm.StatusText.Text = @"Now at " + listViewItem.Text; 1046 vassalForm.StatusText.Text = @"Now at " + selectedRegionName;
-   1047 vassalForm.CurrentRegionName.Text = selectedRegionName;
1042 })); 1048 }));
1043 break; 1049 break;
1044 default: 1050 default:
1045 switch (!string.IsNullOrEmpty(result)) 1051 switch (!string.IsNullOrEmpty(result))
1046 { 1052 {
1047 case true: 1053 case true:
1048 vassalForm.Invoke((MethodInvoker) (() => 1054 vassalForm.Invoke((MethodInvoker) (() =>
1049 { 1055 {
1050 vassalForm.StatusText.Text = @"Failed teleporting to " + listViewItem.Text + 1056 vassalForm.StatusText.Text = @"Failed teleporting to " + selectedRegionName +
1051 @": " + 1057 @": " +
1052 wasKeyValueGet("error", result); 1058 wasKeyValueGet("error", result);
1053 })); 1059 }));
1054 break; 1060 break;
1055 default: 1061 default:
1056 vassalForm.Invoke((MethodInvoker) (() => 1062 vassalForm.Invoke((MethodInvoker) (() =>
1057 { 1063 {
1058 vassalForm.StatusText.Text = @"Failed teleporting to " + listViewItem.Text; 1064 vassalForm.StatusText.Text = @"Failed teleporting to " + selectedRegionName;
1059 })); 1065 }));
1060 break; 1066 break;
1061 } 1067 }
1062 break; 1068 break;
1063 } 1069 }
Line 1069... Line 1075...
1069 vassalForm.StatusText.Text = @"Error communicating with Corrade: " + ex.Message; 1075 vassalForm.StatusText.Text = @"Error communicating with Corrade: " + ex.Message;
1070 })); 1076 }));
1071 } 1077 }
1072 finally 1078 finally
1073 { 1079 {
-   1080 Monitor.Exit(ClientInstanceTeleportLock);
1074 vassalForm.Invoke((MethodInvoker) (() => 1081 vassalForm.Invoke((MethodInvoker) (() =>
1075 { 1082 {
1076 vassalForm.StatusProgress.Value = 100; 1083 vassalForm.StatusProgress.Value = 100;
1077 vassalForm.RegionTeleportGroup.Enabled = true; 1084 vassalForm.RegionTeleportGroup.Enabled = true;
1078 // Set the map image to the loading spinner. 1085 // Set the map image to the loading spinner.
Line 1092... Line 1099...
1092 } 1099 }
1093 // Clear the top scripts table. 1100 // Clear the top scripts table.
1094 TopScriptsGridView.Rows.Clear(); 1101 TopScriptsGridView.Rows.Clear();
1095 // Clear the top colliders table. 1102 // Clear the top colliders table.
1096 TopCollidersGridView.Rows.Clear(); 1103 TopCollidersGridView.Rows.Clear();
-   1104 // Invalidate data for overview tab.
-   1105 vassalForm.CurrentRegionAt.Visible = false;
-   1106 vassalForm.CurrentRegionName.Visible = false;
-   1107 Agents.Text = string.Empty;
-   1108 Agents.Enabled = false;
-   1109 LastLag.Text = string.Empty;
-   1110 LastLag.Enabled = false;
-   1111 Dilation.Text = string.Empty;
-   1112 Dilation.Enabled = false;
-   1113 FPS.Text = string.Empty;
-   1114 FPS.Enabled = false;
-   1115 PhysicsFPS.Text = string.Empty;
-   1116 PhysicsFPS.Enabled = false;
-   1117 ActiveScripts.Text = string.Empty;
-   1118 ActiveScripts.Enabled = false;
-   1119 ScriptTime.Text = string.Empty;
-   1120 ScriptTime.Enabled = false;
-   1121 Objects.Text = string.Empty;
-   1122 Objects.Enabled = false;
1097 })); 1123 }));
1098 updateCurrentRegionName.BeginInvoke(updateCurrentRegionName.EndInvoke, null); -  
1099 } -  
1100 } 1124 }
1101 }).Start(); 1125 }).Start();
Line 1102... Line 1126...
1102 1126  
Line 1108... Line 1132...
1108 settingsForm.Show(); 1132 settingsForm.Show();
1109 } 1133 }
Line 1110... Line 1134...
1110   1134  
1111 private void VassalShown(object sender, EventArgs e) 1135 private void VassalShown(object sender, EventArgs e)
-   1136 {
-   1137 // Set the version
-   1138 vassalForm.Version.Text = @"v" + VASSAL_CONSTANTS.VASSAL_VERSION;
1112 { 1139  
1113 // Get the configuration file settings if it exists. 1140 // Get the configuration file settings if it exists.
1114 if (File.Exists(VASSAL_CONSTANTS.VASSAL_CONFIGURATION_FILE)) 1141 if (File.Exists(VASSAL_CONSTANTS.VASSAL_CONFIGURATION_FILE))
1115 { 1142 {
1116 VassalConfiguration.Load(VASSAL_CONSTANTS.VASSAL_CONFIGURATION_FILE, ref vassalConfiguration); 1143 VassalConfiguration.Load(VASSAL_CONSTANTS.VASSAL_CONFIGURATION_FILE, ref vassalConfiguration);
Line 1117... Line 1144...
1117 } 1144 }
1118   1145  
1119 // Get all the regions if they exist. 1146 // Get all the regions if they exist.
1120 if (File.Exists(VASSAL_CONSTANTS.VASSAL_REGIONS)) 1147 if (File.Exists(VASSAL_CONSTANTS.VASSAL_REGIONS))
1121 { 1148 {
1122 Vector3 localPosition; 1149 Vector3 localPosition;
1123 ConfiguredRegions = 1150 List<KeyValuePair<string, Vector3>> ConfiguredRegions = new List<KeyValuePair<string, Vector3>>(
1124 File.ReadAllLines(VASSAL_CONSTANTS.VASSAL_REGIONS) 1151 File.ReadAllLines(VASSAL_CONSTANTS.VASSAL_REGIONS)
1125 .Select(o => new List<string>(wasCSVToEnumerable(o))) 1152 .Select(o => new List<string>(wasCSVToEnumerable(o)))
1126 .Where(o => o.Count == 2) 1153 .Where(o => o.Count == 2)
1127 .ToDictionary(o => o.First(), 1154 .ToDictionary(o => o.First(),
1128 p => 1155 p =>
1129 Vector3.TryParse(p.Last(), out localPosition) 1156 Vector3.TryParse(p.Last(), out localPosition)
-   1157 ? localPosition
1130 ? localPosition 1158 : Vector3.Zero).OrderBy(o => o.Key).ToDictionary(o => o.Key, o => o.Value));
1131 : Vector3.Zero).OrderBy(o => o.Key).ToDictionary(o => o.Key, o => o.Value); 1159 // Populate the loaded regions.
1132 LoadedRegions.Items.Clear(); 1160 LoadedRegions.Items.Clear();
1133 LoadedRegions.Items.AddRange( 1161 LoadedRegions.Items.AddRange(
1134 ConfiguredRegions.Select(o => (object)new ListViewItem {Text = o.Key, Tag = o.Value}) 1162 ConfiguredRegions.Select(o => (object) new ListViewItem {Text = o.Key, Tag = o.Value})
1135 .ToArray()); -  
1136 } 1163 .ToArray());
1137   1164 // Populate the batch restart grid view.
1138 // Update the current region in case the configuration is initialized. 1165 BatchRestartGridView.Rows.Clear();
1139 if (!vassalConfiguration.Equals(default(VassalConfiguration))) 1166 foreach (KeyValuePair<string, Vector3> data in ConfiguredRegions)
-   1167 {
1140 { 1168 BatchRestartGridView.Rows.Add(data.Key, data.Value.ToString());
Line 1141... Line 1169...
1141 updateCurrentRegionName.BeginInvoke(updateCurrentRegionName.EndInvoke, null); 1169 }
1142 } 1170 }
1143   1171  
Line 1187... Line 1215...
1187 "Dilation", 1215 "Dilation",
1188 "FPS", 1216 "FPS",
1189 "PhysicsFPS", 1217 "PhysicsFPS",
1190 "ActiveScripts", 1218 "ActiveScripts",
1191 "ScriptTime", 1219 "ScriptTime",
1192 "Objects" 1220 "Objects",
-   1221 "Name"
1193 }) 1222 })
1194 } 1223 }
1195 }), vassalConfiguration.DataTimeout); 1224 }), vassalConfiguration.DataTimeout);
Line 1196... Line 1225...
1196   1225  
Line 1203... Line 1232...
1203 if (data.Count.Equals(0)) 1232 if (data.Count.Equals(0))
1204 throw new Exception(); 1233 throw new Exception();
Line 1205... Line 1234...
1205   1234  
1206 vassalForm.Invoke((MethodInvoker) (() => 1235 vassalForm.Invoke((MethodInvoker) (() =>
-   1236 {
-   1237 // Show the region name.
-   1238 vassalForm.CurrentRegionName.Text = data[data.IndexOf("Name") + 1];
-   1239 vassalForm.CurrentRegionAt.Visible = true;
-   1240 vassalForm.CurrentRegionName.Visible = true;
-   1241  
1207 { 1242 // Populate the overview tab.
-   1243 Agents.Text = data[data.IndexOf("Agents") + 1];
1208 Agents.Text = data[data.IndexOf("Agents") + 1]; 1244 Agents.Enabled = true;
-   1245 LastLag.Text = data[data.IndexOf("LastLag") + 1];
1209 LastLag.Text = data[data.IndexOf("LastLag") + 1]; 1246 LastLag.Enabled = true;
-   1247 Dilation.Text = data[data.IndexOf("Dilation") + 1];
1210 Dilation.Text = data[data.IndexOf("Dilation") + 1]; 1248 Dilation.Enabled = true;
-   1249 FPS.Text = data[data.IndexOf("FPS") + 1];
1211 FPS.Text = data[data.IndexOf("FPS") + 1]; 1250 FPS.Enabled = true;
-   1251 PhysicsFPS.Text = data[data.IndexOf("PhysicsFPS") + 1];
1212 PhysicsFPS.Text = data[data.IndexOf("PhysicsFPS") + 1]; 1252 PhysicsFPS.Enabled = true;
-   1253 ActiveScripts.Text = data[data.IndexOf("ActiveScripts") + 1];
1213 ActiveScripts.Text = data[data.IndexOf("ActiveScripts") + 1]; 1254 ActiveScripts.Enabled = true;
-   1255 ScriptTime.Text = data[data.IndexOf("ScriptTime") + 1];
1214 ScriptTime.Text = data[data.IndexOf("ScriptTime") + 1]; 1256 ScriptTime.Enabled = true;
-   1257 Objects.Text = data[data.IndexOf("Objects") + 1];
1215 Objects.Text = data[data.IndexOf("Objects") + 1]; 1258 Objects.Enabled = true;
Line 1216... Line 1259...
1216 })); 1259 }));
1217 1260  
1218 // Get the map image. 1261 // Get the map image.
Line 1265... Line 1308...
1265 if (string.IsNullOrEmpty(result) || 1308 if (string.IsNullOrEmpty(result) ||
1266 !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) 1309 !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success))
1267 throw new Exception(); 1310 throw new Exception();
Line 1268... Line 1311...
1268   1311  
-   1312 // Every thrid element represents a Vecto3 of the avatar position.
1269 // Every thrid element represents a Vecto3 of the avatar position. 1313 data =
-   1314 wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result)))
-   1315 .Skip(2)
-   1316 .Where((x, i) => i%3 == 0)
Line 1270... Line 1317...
1270 data = wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))).Skip(2).Where((x, i) => i % 3 == 0).ToList(); 1317 .ToList();
1271   1318  
1272 // Draw the avatars onto the map. 1319 // Draw the avatars onto the map.
1273 Graphics mapGraphics = Graphics.FromImage(mapImage); 1320 Graphics mapGraphics = Graphics.FromImage(mapImage);
1274 Vector3 position; 1321 Vector3 position;
1275 foreach (string vector in data) 1322 foreach (string vector in data)
1276 { 1323 {
1277 switch (Vector3.TryParse(vector, out position)) 1324 switch (Vector3.TryParse(vector, out position))
-   1325 {
1278 { 1326 case true:
1279 case true: 1327 mapGraphics.FillEllipse(Brushes.Chartreuse,
1280 mapGraphics.FillEllipse(Brushes.Chartreuse, new Rectangle((int)position.X, (int)position.Y, 4, 4)); 1328 new Rectangle((int) position.X, (int) position.Y, 4, 4));
1281 break; 1329 break;
1282 } 1330 }
Line 1340... Line 1388...
1340 if (data.Count.Equals(0)) 1388 if (data.Count.Equals(0))
1341 throw new Exception(); 1389 throw new Exception();
Line 1342... Line 1390...
1342   1390  
1343 vassalForm.Invoke((MethodInvoker) (() => 1391 vassalForm.Invoke((MethodInvoker) (() =>
-   1392 {
-   1393 // Remove rows that are not in the data update.
-   1394 foreach (
-   1395 int index in
-   1396 TopScriptsGridView.Rows.AsParallel().Cast<DataGridViewRow>()
-   1397 .Where(
-   1398 topScriptsRow =>
-   1399 !data.Any(q => q[2].Equals(topScriptsRow.Cells["TopScriptsUUID"].Value)))
-   1400 .Select(q => q.Index))
1344 { 1401 {
1345 switch (!TopScriptsGridView.Rows.Count.Equals(0)) 1402 TopScriptsGridView.Rows.RemoveAt(index);
1346 { 1403 }
1347 case true: 1404 // Now update or add new data.
1348 foreach (DataGridViewRow topScriptsRow in (IEnumerable)TopScriptsGridView.Rows) 1405 foreach (List<string> dataComponents in data.Where(q => q.Count.Equals(5)))
-   1406 {
1349 { 1407 DataGridViewRow row =
1350 List<string> updateRowData = 1408 TopScriptsGridView.Rows.AsParallel()
1351 data.AsParallel() 1409 .Cast<DataGridViewRow>()
1352 .FirstOrDefault(q => q[2].Equals(topScriptsRow.Cells["TopScriptsUUID"].Value.ToString())); 1410 .FirstOrDefault(q => q.Cells["TopScriptsUUID"].Value.Equals(dataComponents[2]));
1353 switch (updateRowData != null && updateRowData.Count.Equals(5)) 1411 switch (row != null)
1354 { 1412 {
1355 case true: 1413 case true: // the row exists, so update it.
1356 topScriptsRow.Cells["TopScriptsScore"].Value = updateRowData[0]; 1414 row.Cells["TopScriptsScore"].Value = dataComponents[0];
1357 topScriptsRow.Cells["TopScriptsTaskName"].Value = updateRowData[1]; 1415 row.Cells["TopScriptsTaskName"].Value = dataComponents[1];
1358 topScriptsRow.Cells["TopScriptsUUID"].Value = updateRowData[2]; 1416 row.Cells["TopScriptsUUID"].Value = dataComponents[2];
1359 topScriptsRow.Cells["TopScriptsOwner"].Value = updateRowData[3]; 1417 row.Cells["TopScriptsOwner"].Value = dataComponents[3];
1360 topScriptsRow.Cells["TopScriptsPosition"].Value = updateRowData[4]; 1418 row.Cells["TopScriptsPosition"].Value = dataComponents[4];
1361 break; 1419 break;
-   1420 case false: // the row dosn't exist, so add it.
1362 } 1421 TopScriptsGridView.Rows.Add(dataComponents[0], dataComponents[1], dataComponents[2],
1363 } 1422 dataComponents[3], dataComponents[4]);
1364 break; -  
1365 default: -  
1366 foreach (List<string> updateRowData in data) -  
1367 { -  
1368 TopScriptsGridView.Rows.Add(updateRowData[0], updateRowData[1], updateRowData[2], -  
1369 updateRowData[3], updateRowData[4]); 1423 break;
1370 } -  
1371 break; 1424 }
1372 } -  
1373 1425 }
1374 })); 1426 }));
1375 } 1427 }
1376 catch (Exception) 1428 catch (Exception)
Line 1422... Line 1474...
1422 if (data.Count.Equals(0)) 1474 if (data.Count.Equals(0))
1423 throw new Exception(); 1475 throw new Exception();
Line 1424... Line 1476...
1424   1476  
1425 vassalForm.Invoke((MethodInvoker)(() => 1477 vassalForm.Invoke((MethodInvoker) (() =>
-   1478 {
-   1479 // Remove rows that are not in the data update.
-   1480 foreach (
-   1481 int index in
-   1482 TopCollidersGridView.Rows.AsParallel().Cast<DataGridViewRow>()
-   1483 .Where(
-   1484 topCollidersRow =>
-   1485 !data.Any(q => q[2].Equals(topCollidersRow.Cells["TopCollidersUUID"].Value)))
-   1486 .Select(q => q.Index))
1426 { 1487 {
1427 switch (!TopCollidersGridView.Rows.Count.Equals(0)) 1488 TopCollidersGridView.Rows.RemoveAt(index);
1428 { 1489 }
1429 case true: 1490 // Now update or add new data.
1430 foreach (DataGridViewRow topCollidersRow in (IEnumerable)TopCollidersGridView.Rows) 1491 foreach (List<string> dataComponents in data.Where(q => q.Count.Equals(5)))
1431 { 1492 {
-   1493 DataGridViewRow row =
1432 List<string> updateRowData = 1494 TopCollidersGridView.Rows.AsParallel()
1433 data.AsParallel() 1495 .Cast<DataGridViewRow>()
1434 .FirstOrDefault(q => q[2].Equals(topCollidersRow.Cells["TopCollidersUUID"].Value.ToString())); 1496 .FirstOrDefault(q => q.Cells["TopCollidersUUID"].Value.Equals(dataComponents[2]));
1435 switch (updateRowData != null && updateRowData.Count.Equals(5)) 1497 switch (row != null)
1436 { 1498 {
1437 case true: 1499 case true: // the row exists, so update it.
1438 topCollidersRow.Cells["TopCollidersScore"].Value = updateRowData[0]; 1500 row.Cells["TopCollidersScore"].Value = dataComponents[0];
1439 topCollidersRow.Cells["TopCollidersTaskName"].Value = updateRowData[1]; 1501 row.Cells["TopSCollidersTaskName"].Value = dataComponents[1];
1440 topCollidersRow.Cells["TopCollidersUUID"].Value = updateRowData[2]; 1502 row.Cells["TopCollidersUUID"].Value = dataComponents[2];
1441 topCollidersRow.Cells["TopCollidersOwner"].Value = updateRowData[3]; 1503 row.Cells["TopCollidersOwner"].Value = dataComponents[3];
1442 topCollidersRow.Cells["TopCollidersPosition"].Value = updateRowData[4]; 1504 row.Cells["TopCollidersPosition"].Value = dataComponents[4];
1443 break; 1505 break;
-   1506 case false: // the row dosn't exist, so add it.
1444 } 1507 TopCollidersGridView.Rows.Add(dataComponents[0], dataComponents[1], dataComponents[2],
1445 } 1508 dataComponents[3], dataComponents[4]);
1446 break; -  
1447 default: -  
1448 foreach (List<string> updateRowData in data) -  
1449 { -  
1450 TopCollidersGridView.Rows.Add(updateRowData[0], updateRowData[1], updateRowData[2], -  
1451 updateRowData[3], updateRowData[4]); 1509 break;
1452 } -  
1453 break; 1510 }
Line 1454... Line 1511...
1454 } 1511 }
1455   1512  
1456 })); 1513 }));
Line 1477... Line 1534...
1477   1534  
1478 private void RequestSelecting(object sender, TabControlCancelEventArgs e) 1535 private void RequestSelecting(object sender, TabControlCancelEventArgs e)
1479 { 1536 {
1480 e.Cancel = !e.TabPage.Enabled; 1537 e.Cancel = !e.TabPage.Enabled;
-   1538 }
-   1539  
-   1540 private void RequestExportTopScripts(object sender, EventArgs e)
-   1541 {
-   1542 vassalForm.BeginInvoke((MethodInvoker) (() =>
-   1543 {
-   1544 switch (vassalForm.ExportCSVDialog.ShowDialog())
-   1545 {
-   1546 case DialogResult.OK:
-   1547 string file = vassalForm.ExportCSVDialog.FileName;
-   1548 new Thread(() =>
-   1549 {
-   1550 vassalForm.BeginInvoke((MethodInvoker) (() =>
-   1551 {
-   1552 try
-   1553 {
-   1554 vassalForm.StatusText.Text = @"exporting...";
-   1555 vassalForm.StatusProgress.Value = 0;
-   1556  
-   1557 using (StreamWriter streamWriter = new StreamWriter(file, false, Encoding.UTF8))
-   1558 {
-   1559 foreach (DataGridViewRow topScriptsRow in TopScriptsGridView.Rows)
-   1560 {
-   1561 streamWriter.WriteLine(wasEnumerableToCSV(new[]
-   1562 {
-   1563 topScriptsRow.Cells["TopScriptsScore"].Value.ToString(),
-   1564 topScriptsRow.Cells["TopScriptsTaskName"].Value.ToString(),
-   1565 topScriptsRow.Cells["TopScriptsUUID"].Value.ToString(),
-   1566 topScriptsRow.Cells["TopScriptsOwner"].Value.ToString(),
-   1567 topScriptsRow.Cells["TopScriptsPosition"].Value.ToString()
-   1568 }));
-   1569 }
-   1570 }
-   1571  
-   1572 vassalForm.StatusText.Text = @"exported";
-   1573 vassalForm.StatusProgress.Value = 100;
-   1574 }
-   1575 catch (Exception ex)
-   1576 {
-   1577 vassalForm.StatusText.Text = ex.Message;
-   1578 }
-   1579 }));
-   1580 })
-   1581 {IsBackground = true, Priority = ThreadPriority.Normal}.Start();
-   1582 break;
-   1583 }
-   1584 }));
-   1585 }
-   1586  
-   1587 private void RequestExportTopColliders(object sender, EventArgs e)
-   1588 {
-   1589 vassalForm.BeginInvoke((MethodInvoker) (() =>
-   1590 {
-   1591 switch (vassalForm.ExportCSVDialog.ShowDialog())
-   1592 {
-   1593 case DialogResult.OK:
-   1594 string file = vassalForm.ExportCSVDialog.FileName;
-   1595 new Thread(() =>
-   1596 {
-   1597 vassalForm.BeginInvoke((MethodInvoker) (() =>
-   1598 {
-   1599 try
-   1600 {
-   1601 vassalForm.StatusText.Text = @"exporting...";
-   1602 vassalForm.StatusProgress.Value = 0;
-   1603  
-   1604 using (StreamWriter streamWriter = new StreamWriter(file, false, Encoding.UTF8))
-   1605 {
-   1606 foreach (DataGridViewRow topCollidersRow in TopCollidersGridView.Rows)
-   1607 {
-   1608 streamWriter.WriteLine(wasEnumerableToCSV(new[]
-   1609 {
-   1610 topCollidersRow.Cells["TopCollidersScore"].Value.ToString(),
-   1611 topCollidersRow.Cells["TopCollidersTaskName"].Value.ToString(),
-   1612 topCollidersRow.Cells["TopCollidersUUID"].Value.ToString(),
-   1613 topCollidersRow.Cells["TopCollidersOwner"].Value.ToString(),
-   1614 topCollidersRow.Cells["TopCollidersPosition"].Value.ToString()
-   1615 }));
-   1616 }
-   1617 }
-   1618  
-   1619 vassalForm.StatusText.Text = @"exported";
-   1620 vassalForm.StatusProgress.Value = 100;
-   1621 }
-   1622 catch (Exception ex)
-   1623 {
-   1624 vassalForm.StatusText.Text = ex.Message;
-   1625 }
-   1626 }));
-   1627 })
-   1628 {IsBackground = true, Priority = ThreadPriority.Normal}.Start();
-   1629 break;
-   1630 }
-   1631 }));
-   1632 }
-   1633  
-   1634 private void RequestFilterTopScripts(object sender, EventArgs e)
-   1635 {
-   1636 vassalForm.BeginInvoke((MethodInvoker) (() =>
-   1637 {
-   1638 Regex topScriptsRowRegex;
-   1639 switch (!string.IsNullOrEmpty(TopScriptsFilter.Text))
-   1640 {
-   1641 case true:
-   1642 topScriptsRowRegex = new Regex(TopScriptsFilter.Text, RegexOptions.Compiled);
-   1643 break;
-   1644 default:
-   1645 topScriptsRowRegex = new Regex(@".+?", RegexOptions.Compiled);
-   1646 break;
-   1647 }
-   1648 foreach (DataGridViewRow topScriptsRow in TopScriptsGridView.Rows.AsParallel().Cast<DataGridViewRow>())
-   1649 {
-   1650 topScriptsRow.Visible =
-   1651 topScriptsRowRegex.IsMatch(topScriptsRow.Cells["TopScriptsScore"].Value.ToString()) ||
-   1652 topScriptsRowRegex.IsMatch(
-   1653 topScriptsRow.Cells["TopScriptsTaskName"].Value.ToString()) ||
-   1654 topScriptsRowRegex.IsMatch(topScriptsRow.Cells["TopScriptsUUID"].Value.ToString()) ||
-   1655 topScriptsRowRegex.IsMatch(topScriptsRow.Cells["TopScriptsOwner"].Value.ToString()) ||
-   1656 topScriptsRowRegex.IsMatch(
-   1657 topScriptsRow.Cells["TopScriptsPosition"].Value.ToString());
-   1658 }
-   1659 }));
-   1660 }
-   1661  
-   1662 private void RequestFilterTopColliders(object sender, EventArgs e)
-   1663 {
-   1664 vassalForm.BeginInvoke((MethodInvoker)(() =>
-   1665 {
-   1666 Regex topCollidersRowRegex;
-   1667 switch (!string.IsNullOrEmpty(TopScriptsFilter.Text))
-   1668 {
-   1669 case true:
-   1670 topCollidersRowRegex = new Regex(TopScriptsFilter.Text, RegexOptions.Compiled);
-   1671 break;
-   1672 default:
-   1673 topCollidersRowRegex = new Regex(@".+?", RegexOptions.Compiled);
-   1674 break;
-   1675 }
-   1676 foreach (DataGridViewRow topCollidersRow in TopCollidersGridView.Rows.AsParallel().Cast<DataGridViewRow>())
-   1677 {
-   1678 topCollidersRow.Visible =
-   1679 topCollidersRowRegex.IsMatch(topCollidersRow.Cells["TopCollidersScore"].Value.ToString()) ||
-   1680 topCollidersRowRegex.IsMatch(
-   1681 topCollidersRow.Cells["TopCollidersTaskName"].Value.ToString()) ||
-   1682 topCollidersRowRegex.IsMatch(topCollidersRow.Cells["TopCollidersUUID"].Value.ToString()) ||
-   1683 topCollidersRowRegex.IsMatch(topCollidersRow.Cells["TopCollidersOwner"].Value.ToString()) ||
-   1684 topCollidersRowRegex.IsMatch(
-   1685 topCollidersRow.Cells["TopCollidersPosition"].Value.ToString());
-   1686 }
-   1687 }));
-   1688 }
-   1689  
-   1690 private void RequestReturnTopScriptsObjects(object sender, EventArgs e)
-   1691 {
-   1692 // Block teleports and disable button.
-   1693 vassalForm.Invoke((MethodInvoker) (() =>
-   1694 {
-   1695 vassalForm.ReturnTopScriptsButton.Enabled = false;
-   1696 RegionTeleportGroup.Enabled = false;
-   1697 }));
-   1698  
-   1699 // Enqueue all the UUIDs to return.
-   1700 Queue<KeyValuePair<UUID, Vector3>> returnUUIDs = new Queue<KeyValuePair<UUID, Vector3>>();
-   1701 vassalForm.Invoke((MethodInvoker) (() =>
-   1702 {
-   1703 foreach (
-   1704 DataGridViewRow topScriptsRow in
-   1705 TopScriptsGridView.Rows.AsParallel()
-   1706 .Cast<DataGridViewRow>()
-   1707 .Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected)))
-   1708 {
-   1709 Vector3 objectPosition;
-   1710 UUID returnUUID;
-   1711 if (!UUID.TryParse(topScriptsRow.Cells["TopScriptsUUID"].Value.ToString(), out returnUUID) ||
-   1712 !Vector3.TryParse(topScriptsRow.Cells["TopScriptsPosition"].Value.ToString(), out objectPosition))
-   1713 continue;
-   1714 returnUUIDs.Enqueue(new KeyValuePair<UUID, Vector3>(returnUUID, objectPosition));
-   1715 }
-   1716 }));
-   1717  
-   1718 // If no rows were selected, enable teleports, the return button and return.
-   1719 if (returnUUIDs.Count.Equals(0))
-   1720 {
-   1721 vassalForm.Invoke((MethodInvoker)(() =>
-   1722 {
-   1723 vassalForm.ReturnTopScriptsButton.Enabled = true;
-   1724 RegionTeleportGroup.Enabled = true;
-   1725 }));
-   1726 return;
-   1727 }
-   1728  
-   1729 new Thread(() =>
-   1730 {
-   1731 Monitor.Enter(ClientInstanceTeleportLock);
-   1732  
-   1733 try
-   1734 {
-   1735 vassalForm.Invoke((MethodInvoker) (() =>
-   1736 {
-   1737 vassalForm.StatusProgress.Value = 0;
-   1738 }));
-   1739 int totalObjects = returnUUIDs.Count;
-   1740 do
-   1741 {
-   1742 // Dequeue the first object.
-   1743 KeyValuePair<UUID, Vector3> objectData = returnUUIDs.Dequeue();
-   1744  
-   1745 vassalForm.Invoke((MethodInvoker) (() =>
-   1746 {
-   1747 vassalForm.StatusText.Text = @"Returning object UUID: " + objectData.Key.ToString();
-   1748 }));
-   1749  
-   1750 string currentRegionName = string.Empty;
-   1751 vassalForm.Invoke((MethodInvoker) (() =>
-   1752 {
-   1753 currentRegionName = CurrentRegionName.Text;
-   1754 }));
-   1755
-   1756 // Teleport to the object.
-   1757 string result = wasPOST(vassalConfiguration.HTTPServerURL,
-   1758 wasKeyValueEscape(new Dictionary<string, string>
-   1759 {
-   1760 {"command", "teleport"},
-   1761 {"group", vassalConfiguration.Group},
-   1762 {"password", vassalConfiguration.Password},
-   1763 {"position", objectData.Value.ToString()},
-   1764 {"region", currentRegionName},
-   1765 {"fly", "True"}
-   1766 }), vassalConfiguration.TeleportTimeout);
-   1767  
-   1768 if (string.IsNullOrEmpty(result))
-   1769 {
-   1770 vassalForm.Invoke((MethodInvoker)(() =>
-   1771 {
-   1772 vassalForm.StatusText.Text = @"Error communicating with Corrade.";
-   1773 }));
-   1774 continue;
-   1775 }
-   1776  
-   1777 // Return the object.
-   1778 result = wasPOST(vassalConfiguration.HTTPServerURL,
-   1779 wasKeyValueEscape(new Dictionary<string, string>
-   1780 {
-   1781 {"command", "derez"},
-   1782 {"group", vassalConfiguration.Group},
-   1783 {"password", vassalConfiguration.Password},
-   1784 {"item", objectData.Key.ToString()},
-   1785 {"range", "32" }, // maximal prim size = 64 - middle bounding box at half
-   1786 {"type", "ReturnToOwner"}
-   1787 }), vassalConfiguration.DataTimeout);
-   1788  
-   1789 if (string.IsNullOrEmpty(result))
-   1790 {
-   1791 vassalForm.Invoke((MethodInvoker) (() =>
-   1792 {
-   1793 vassalForm.StatusText.Text = @"Error communicating with Corrade.";
-   1794 }));
-   1795 continue;
-   1796 }
-   1797  
-   1798 bool success;
-   1799 if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success))
-   1800 {
-   1801 vassalForm.Invoke((MethodInvoker) (() =>
-   1802 {
-   1803 vassalForm.StatusText.Text = @"No success status could be retrieved. ";
-   1804 }));
-   1805 continue;
-   1806 }
-   1807  
-   1808 switch (success)
-   1809 {
-   1810 case true:
-   1811 vassalForm.Invoke((MethodInvoker) (() =>
-   1812 {
-   1813 vassalForm.StatusText.Text = @"Returned object: " + objectData.Key.ToString();
-   1814 // Remove the row from the grid view.
-   1815 DataGridViewRow row =
-   1816 TopScriptsGridView.Rows.AsParallel()
-   1817 .Cast<DataGridViewRow>()
-   1818 .FirstOrDefault(
-   1819 o => o.Cells["TopScriptsUUID"].Value.Equals(objectData.Key.ToString()));
-   1820 if (row == null) return;
-   1821 int i = row.Index;
-   1822 TopScriptsGridView.Rows.RemoveAt(i);
-   1823 }));
-   1824 break;
-   1825 case false:
-   1826 vassalForm.Invoke((MethodInvoker) (() =>
-   1827 {
-   1828 vassalForm.StatusText.Text = @"Could not return object " + objectData.Key.ToString() +
-   1829 @": " +
-   1830 wasInput(wasKeyValueGet("error", result));
-   1831 }));
-   1832 break;
-   1833 }
-   1834  
-   1835 vassalForm.Invoke((MethodInvoker) (() =>
-   1836 {
-   1837 vassalForm.StatusProgress.Value =
-   1838 Math.Min((int) (Math.Abs(returnUUIDs.Count - totalObjects)/
-   1839 (double) totalObjects), 100);
-   1840 }));
-   1841 } while (!returnUUIDs.Count.Equals(0));
-   1842 vassalForm.Invoke((MethodInvoker) (() =>
-   1843 {
-   1844 vassalForm.StatusProgress.Value = 100;
-   1845 }));
-   1846 }
-   1847 catch (Exception ex)
-   1848 {
-   1849 vassalForm.Invoke((MethodInvoker)(() =>
-   1850 {
-   1851 vassalForm.StatusText.Text = @"Unexpected error: " + ex.Message;
-   1852 }));
-   1853 }
-   1854 finally
-   1855 {
-   1856 Monitor.Exit(ClientInstanceTeleportLock);
-   1857 // Allow teleports and enable button.
-   1858 vassalForm.BeginInvoke((MethodInvoker)(() =>
-   1859 {
-   1860 vassalForm.ReturnTopScriptsButton.Enabled = true;
-   1861 RegionTeleportGroup.Enabled = true;
-   1862 }));
-   1863 }
-   1864 })
-   1865 {IsBackground = true}.Start();
-   1866 }
-   1867  
-   1868 private void RequestReturnTopCollidersObjects(object sender, EventArgs e)
-   1869 {
-   1870 // Block teleports and disable button.
-   1871 vassalForm.Invoke((MethodInvoker)(() =>
-   1872 {
-   1873 vassalForm.ReturnTopCollidersButton.Enabled = false;
-   1874 RegionTeleportGroup.Enabled = false;
-   1875 }));
-   1876  
-   1877 // Enqueue all the UUIDs to return.
-   1878 Queue<KeyValuePair<UUID, Vector3>> returnUUIDs = new Queue<KeyValuePair<UUID, Vector3>>();
-   1879 vassalForm.Invoke((MethodInvoker)(() =>
-   1880 {
-   1881 foreach (
-   1882 DataGridViewRow topCollidersRow in
-   1883 TopCollidersGridView.Rows.AsParallel()
-   1884 .Cast<DataGridViewRow>()
-   1885 .Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected)))
-   1886 {
-   1887 Vector3 objectPosition;
-   1888 UUID returnUUID;
-   1889 if (!UUID.TryParse(topCollidersRow.Cells["TopCollidersUUID"].Value.ToString(), out returnUUID) ||
-   1890 !Vector3.TryParse(topCollidersRow.Cells["TopCollidersPosition"].Value.ToString(), out objectPosition))
-   1891 continue;
-   1892 returnUUIDs.Enqueue(new KeyValuePair<UUID, Vector3>(returnUUID, objectPosition));
-   1893 }
-   1894 }));
-   1895  
-   1896 // If no rows were selected, enable teleports, the return button and return.
-   1897 if (returnUUIDs.Count.Equals(0))
-   1898 {
-   1899 vassalForm.Invoke((MethodInvoker)(() =>
-   1900 {
-   1901 vassalForm.ReturnTopCollidersButton.Enabled = true;
-   1902 RegionTeleportGroup.Enabled = true;
-   1903 }));
-   1904 return;
-   1905 }
-   1906  
-   1907 new Thread(() =>
-   1908 {
-   1909 Monitor.Enter(ClientInstanceTeleportLock);
-   1910  
-   1911 try
-   1912 {
-   1913 vassalForm.Invoke((MethodInvoker)(() =>
-   1914 {
-   1915 vassalForm.StatusProgress.Value = 0;
-   1916 }));
-   1917 int totalObjects = returnUUIDs.Count;
-   1918 do
-   1919 {
-   1920 // Dequeue the first object.
-   1921 KeyValuePair<UUID, Vector3> objectData = returnUUIDs.Dequeue();
-   1922  
-   1923 vassalForm.Invoke((MethodInvoker)(() =>
-   1924 {
-   1925 vassalForm.StatusText.Text = @"Returning UUID: " + objectData.Key.ToString();
-   1926 }));
-   1927  
-   1928 string currentRegionName = string.Empty;
-   1929 vassalForm.Invoke((MethodInvoker)(() =>
-   1930 {
-   1931 currentRegionName = CurrentRegionName.Text;
-   1932 }));
-   1933  
-   1934 // Teleport to the object.
-   1935 string result = wasPOST(vassalConfiguration.HTTPServerURL,
-   1936 wasKeyValueEscape(new Dictionary<string, string>
-   1937 {
-   1938 {"command", "teleport"},
-   1939 {"group", vassalConfiguration.Group},
-   1940 {"password", vassalConfiguration.Password},
-   1941 {"position", objectData.Value.ToString()},
-   1942 {"region", currentRegionName},
-   1943 {"fly", "True"}
-   1944 }), vassalConfiguration.DataTimeout);
-   1945  
-   1946 if (string.IsNullOrEmpty(result))
-   1947 {
-   1948 vassalForm.Invoke((MethodInvoker)(() =>
-   1949 {
-   1950 vassalForm.StatusText.Text = @"Error communicating with Corrade.";
-   1951 }));
-   1952 continue;
-   1953 }
-   1954  
-   1955 // Return the object.
-   1956 result = wasPOST(vassalConfiguration.HTTPServerURL,
-   1957 wasKeyValueEscape(new Dictionary<string, string>
-   1958 {
-   1959 {"command", "derez"},
-   1960 {"group", vassalConfiguration.Group},
-   1961 {"password", vassalConfiguration.Password},
-   1962 {"item", objectData.Key.ToString()},
-   1963 {"range", "32" }, // maximal prim size = 64 - middle bounding box at half
-   1964 {"type", "ReturnToOwner"}
-   1965 }), vassalConfiguration.DataTimeout);
-   1966  
-   1967 if (string.IsNullOrEmpty(result))
-   1968 {
-   1969 vassalForm.Invoke((MethodInvoker)(() =>
-   1970 {
-   1971 vassalForm.StatusText.Text = @"Error communicating with Corrade.";
-   1972 }));
-   1973 continue;
-   1974 }
-   1975  
-   1976 bool success;
-   1977 if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success))
-   1978 {
-   1979 vassalForm.Invoke((MethodInvoker)(() =>
-   1980 {
-   1981 vassalForm.StatusText.Text = @"No success status could be retrieved. ";
-   1982 }));
-   1983 continue;
-   1984 }
-   1985  
-   1986 switch (success)
-   1987 {
-   1988 case true:
-   1989 vassalForm.Invoke((MethodInvoker)(() =>
-   1990 {
-   1991 vassalForm.StatusText.Text = @"Returned object: " + objectData.Key.ToString();
-   1992 // Remove the row from the grid view.
-   1993 DataGridViewRow row =
-   1994 TopCollidersGridView.Rows.AsParallel()
-   1995 .Cast<DataGridViewRow>()
-   1996 .FirstOrDefault(
-   1997 o => o.Cells["TopCollidersUUID"].Value.Equals(objectData.Key.ToString()));
-   1998 if (row == null) return;
-   1999 int i = row.Index;
-   2000 TopCollidersGridView.Rows.RemoveAt(i);
-   2001 }));
-   2002 break;
-   2003 case false:
-   2004 vassalForm.Invoke((MethodInvoker)(() =>
-   2005 {
-   2006 vassalForm.StatusText.Text = @"Could not return object " + objectData.Key.ToString() +
-   2007 @": " +
-   2008 wasInput(wasKeyValueGet("error", result));
-   2009 }));
-   2010 break;
-   2011 }
-   2012  
-   2013 vassalForm.Invoke((MethodInvoker)(() =>
-   2014 {
-   2015 vassalForm.StatusProgress.Value =
-   2016 Math.Min((int)(Math.Abs(returnUUIDs.Count - totalObjects) /
-   2017 (double)totalObjects), 100);
-   2018 }));
-   2019 } while (!returnUUIDs.Count.Equals(0));
-   2020 vassalForm.Invoke((MethodInvoker)(() =>
-   2021 {
-   2022 vassalForm.StatusProgress.Value = 100;
-   2023 }));
-   2024 }
-   2025 catch (Exception ex)
-   2026 {
-   2027 vassalForm.Invoke((MethodInvoker)(() =>
-   2028 {
-   2029 vassalForm.StatusText.Text = @"Unexpected error: " + ex.Message;
-   2030 }));
-   2031 }
-   2032 finally
-   2033 {
-   2034 Monitor.Exit(ClientInstanceTeleportLock);
-   2035 // Allow teleports and enable button.
-   2036 vassalForm.BeginInvoke((MethodInvoker)(() =>
-   2037 {
-   2038 vassalForm.ReturnTopScriptsButton.Enabled = true;
-   2039 RegionTeleportGroup.Enabled = true;
-   2040 }));
-   2041 }
-   2042 })
-   2043 { IsBackground = true }.Start();
-   2044 }
-   2045  
-   2046 private void RequestBatchRestart(object sender, EventArgs e)
-   2047 {
-   2048  
1481 } 2049 }
1482 } 2050 }