corrade-vassal – Diff between revs 2 and 3

Subversion Repositories:
Rev:
Show entire fileIgnore 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
139   139  
Line 912... Line 912...
912 try 912 try
913 { 913 {
914 string result = wasPOST(vassalConfiguration.HTTPServerURL, 914 string result = wasPOST(vassalConfiguration.HTTPServerURL,
915 wasKeyValueEscape(new Dictionary<string, string> 915 wasKeyValueEscape(new Dictionary<string, string>
916 { 916 {
917 {"command", "getregiondata"}, 917 {"command", "getregiondata"},
918 {"group", vassalConfiguration.Group}, 918 {"group", vassalConfiguration.Group},
919 {"password", vassalConfiguration.Password}, 919 {"password", vassalConfiguration.Password},
920 {"data", "Name"} 920 {"data", "Name"}
921 }), 60000); 921 }), 60000);
922 bool success; 922 bool success;
923 if (string.IsNullOrEmpty(result) || 923 if (string.IsNullOrEmpty(result) ||
924 !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) 924 !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success))
925 { 925 {
926 vassalForm.BeginInvoke((MethodInvoker)(() => 926 vassalForm.BeginInvoke((MethodInvoker) (() =>
927 { 927 {
928 vassalForm.StatusText.Text = @"Failed to query Corrade for current region."; 928 vassalForm.StatusText.Text = @"Failed to query Corrade for current region.";
929 })); 929 }));
930 return; 930 return;
931 } 931 }
932 switch (success) 932 switch (success)
933 { 933 {
934 case true: 934 case true:
935 vassalForm.BeginInvoke((MethodInvoker)(() => 935 vassalForm.BeginInvoke((MethodInvoker) (() =>
936 { 936 {
937 vassalForm.CurrentRegionAt.Visible = true; 937 vassalForm.CurrentRegionAt.Visible = true;
938 vassalForm.CurrentRegionName.Visible = true; 938 vassalForm.CurrentRegionName.Visible = true;
939 vassalForm.CurrentRegionName.Text = 939 vassalForm.CurrentRegionName.Text =
940 wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))).Last(); 940 wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))).Last();
941 })); 941 }));
942 break; 942 break;
943 default: 943 default:
944 vassalForm.BeginInvoke((MethodInvoker)(() => 944 vassalForm.BeginInvoke((MethodInvoker) (() =>
945 { 945 {
946 vassalForm.CurrentRegionAt.Visible = false; 946 vassalForm.CurrentRegionAt.Visible = false;
947 vassalForm.CurrentRegionName.Visible = false; 947 vassalForm.CurrentRegionName.Visible = false;
948 vassalForm.StatusText.Text = @"Error getting current region: " + 948 vassalForm.StatusText.Text = @"Error getting current region: " +
949 wasInput(wasKeyValueGet("error", result)); 949 wasInput(wasKeyValueGet("error", result));
Line 951... Line 951...
951 break; 951 break;
952 } 952 }
953 } 953 }
954 catch (Exception ex) 954 catch (Exception ex)
955 { 955 {
956 vassalForm.BeginInvoke((MethodInvoker)(() => 956 vassalForm.BeginInvoke((MethodInvoker) (() =>
957 { 957 {
958 vassalForm.StatusText.Text = 958 vassalForm.StatusText.Text =
959 @"Error getting current region: " + 959 @"Error getting current region: " +
960 ex.Message; 960 ex.Message;
961 })); 961 }));
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 {
-   978 ListViewItem listViewItem = LoadedRegions.SelectedItem as ListViewItem;
-   979 switch (listViewItem != null && LoadedRegions.SelectedIndex != -1)
-   980 {
-   981 case true:
-   982 selectedRegionName = listViewItem.Text;
-   983 selectedRegionPosition = (Vector3)listViewItem.Tag;
-   984 startTeleport = true;
-   985 break;
-   986 default:
-   987 startTeleport = false;
-   988 break;
976 listViewItem = LoadedRegions.SelectedItem as ListViewItem; 989 }
Line 977... Line 990...
977 })); 990 }));
-   991  
-   992 if (!startTeleport) return;
-   993
-   994  
978   995 // Announce teleport.
979 switch (listViewItem != null) 996 vassalForm.Invoke((MethodInvoker)(() =>
980 { 997 {
981 case true: -  
982 vassalForm.Invoke((MethodInvoker) (() => 998 vassalForm.RegionTeleportGroup.Enabled = false;
983 { -  
984 vassalForm.StatusText.Text = @"Teleporting to " + -  
985 listViewItem.Text; -  
986 })); -  
987 break; -  
988 default: 999 vassalForm.StatusProgress.Value = 0;
Line 989... Line 1000...
989 return; 1000 vassalForm.StatusText.Text = @"Teleporting to " + selectedRegionName;
990 } 1001 }));
991   1002  
-   1003 new Thread(() =>
992 new Thread(() => 1004 {
993 { 1005 Monitor.Enter(ClientInstanceTeleportLock);
-   1006 try
-   1007 {
994 lock (ClientInstanceTeleportLock) 1008 int elapsedSeconds = 0;
995 { 1009 System.Timers.Timer teleportTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds);
996 try 1010 teleportTimer.Elapsed += (o, p) =>
997 { 1011 {
-   1012 vassalForm.Invoke((MethodInvoker) (() =>
-   1013 {
-   1014 vassalForm.StatusProgress.Value =
-   1015 Math.Min(
998 vassalForm.Invoke((MethodInvoker) (() => 1016 (int)
999 { 1017 (100d*
-   1018 (TimeSpan.FromSeconds(++elapsedSeconds).TotalMilliseconds/
-   1019 vassalConfiguration.TeleportTimeout)), 100);
-   1020 }));
-   1021 };
-   1022 teleportTimer.Start();
-   1023 string result = null;
-   1024 ManualResetEvent receivedPOST = new ManualResetEvent(false);
-   1025 new Thread(() =>
-   1026 {
-   1027 result = wasInput(wasPOST(vassalConfiguration.HTTPServerURL,
-   1028 wasKeyValueEscape(new Dictionary<string, string>
-   1029 {
-   1030 {"command", "teleport"},
-   1031 {"group", vassalConfiguration.Group},
-   1032 {"password", vassalConfiguration.Password},
-   1033 {"region", selectedRegionName},
1000 vassalForm.RegionTeleportGroup.Enabled = false; 1034 {"position", selectedRegionPosition.ToString()},
-   1035 {"fly", "True"}
1001 vassalForm.StatusProgress.Value = 0; 1036 }), vassalConfiguration.TeleportTimeout));
1002 })); 1037 receivedPOST.Set();
-   1038 }) {IsBackground = true}.Start();
1003 int elapsedSeconds = 0; 1039 receivedPOST.WaitOne((int) vassalConfiguration.TeleportTimeout, false);
-   1040 teleportTimer.Stop();
1004 System.Timers.Timer teleportTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); 1041 switch (!string.IsNullOrEmpty(result) && wasKeyValueGet("success", result) == "True")
1005 teleportTimer.Elapsed += (o, p) => 1042 {
1006 { 1043 case true:
1007 vassalForm.Invoke((MethodInvoker) (() => -  
1008 { -  
1009 vassalForm.StatusProgress.Value = -  
1010 Math.Min( -  
1011 (int) 1044 vassalForm.Invoke((MethodInvoker) (() =>
1012 (100d* 1045 {
1013 (TimeSpan.FromSeconds(++elapsedSeconds).TotalMilliseconds/ -  
1014 vassalConfiguration.TeleportTimeout)), 100); -  
1015 })); -  
1016 }; -  
1017 teleportTimer.Start(); -  
1018 string result = null; -  
1019 ManualResetEvent receivedPOST = new ManualResetEvent(false); -  
1020 new Thread(() => -  
1021 { -  
1022 result = wasInput(wasPOST(vassalConfiguration.HTTPServerURL, -  
1023 wasKeyValueEscape(new Dictionary<string, string> -  
1024 { -  
1025 {"command", "teleport"}, -  
1026 {"group", vassalConfiguration.Group}, -  
1027 {"password", vassalConfiguration.Password}, -  
1028 {"region", listViewItem.Text}, -  
1029 {"position", ((Vector3) listViewItem.Tag).ToString()}, -  
1030 {"fly", "True"} -  
1031 }), vassalConfiguration.TeleportTimeout)); -  
1032 receivedPOST.Set(); -  
1033 }) {IsBackground = true}.Start(); -  
1034 receivedPOST.WaitOne((int) vassalConfiguration.TeleportTimeout, false); -  
1035 teleportTimer.Stop(); -  
1036 switch (!string.IsNullOrEmpty(result) && wasKeyValueGet("success", result) == "True") -  
1037 { -  
1038 case true: -  
1039 vassalForm.Invoke((MethodInvoker) (() => -  
1040 { 1046 vassalForm.StatusText.Text = @"Now at " + selectedRegionName;
1041 vassalForm.StatusText.Text = @"Now at " + listViewItem.Text; 1047 vassalForm.CurrentRegionName.Text = selectedRegionName;
1042 })); 1048 }));
1043 break; -  
1044 default: -  
1045 switch (!string.IsNullOrEmpty(result)) -  
1046 { -  
1047 case true: -  
1048 vassalForm.Invoke((MethodInvoker) (() => -  
1049 { -  
1050 vassalForm.StatusText.Text = @"Failed teleporting to " + listViewItem.Text + -  
1051 @": " + -  
1052 wasKeyValueGet("error", result); -  
1053 })); -  
1054 break; -  
1055 default: -  
1056 vassalForm.Invoke((MethodInvoker) (() => -  
1057 { -  
1058 vassalForm.StatusText.Text = @"Failed teleporting to " + listViewItem.Text; -  
1059 })); -  
1060 break; -  
1061 } -  
1062 break; -  
1063 } -  
1064 } -  
1065 catch (Exception ex) -  
1066 { -  
1067 vassalForm.Invoke((MethodInvoker) (() => -  
1068 { -  
1069 vassalForm.StatusText.Text = @"Error communicating with Corrade: " + ex.Message; -  
1070 })); -  
1071 } -  
1072 finally -  
1073 { -  
1074 vassalForm.Invoke((MethodInvoker) (() => -  
1075 { -  
1076 vassalForm.StatusProgress.Value = 100; -  
1077 vassalForm.RegionTeleportGroup.Enabled = true; -  
1078 // Set the map image to the loading spinner. -  
1079 Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); -  
1080 System.IO.Stream file = 1049 break;
1081 thisAssembly.GetManifestResourceStream("Vassal.img.loading.gif"); 1050 default:
1082 switch (file != null) 1051 switch (!string.IsNullOrEmpty(result))
-   1052 {
-   1053 case true:
-   1054 vassalForm.Invoke((MethodInvoker) (() =>
-   1055 {
-   1056 vassalForm.StatusText.Text = @"Failed teleporting to " + selectedRegionName +
-   1057 @": " +
-   1058 wasKeyValueGet("error", result);
-   1059 }));
1083 { 1060 break;
1084 case true: 1061 default:
1085 vassalForm.Invoke((MethodInvoker)(() => -  
1086 { -  
1087 RegionAvatarsMap.SizeMode = PictureBoxSizeMode.CenterImage; 1062 vassalForm.Invoke((MethodInvoker) (() =>
1088 RegionAvatarsMap.Image = Image.FromStream(file); 1063 {
1089 RegionAvatarsMap.Refresh(); 1064 vassalForm.StatusText.Text = @"Failed teleporting to " + selectedRegionName;
1090 })); -  
1091 break; -  
1092 } -  
1093 // Clear the top scripts table. -  
1094 TopScriptsGridView.Rows.Clear(); 1065 }));
1095 // Clear the top colliders table. -  
1096 TopCollidersGridView.Rows.Clear(); 1066 break;
1097 })); 1067 }
-   1068 break;
-   1069 }
-   1070 }
-   1071 catch (Exception ex)
-   1072 {
-   1073 vassalForm.Invoke((MethodInvoker) (() =>
-   1074 {
-   1075 vassalForm.StatusText.Text = @"Error communicating with Corrade: " + ex.Message;
-   1076 }));
-   1077 }
-   1078 finally
-   1079 {
-   1080 Monitor.Exit(ClientInstanceTeleportLock);
-   1081 vassalForm.Invoke((MethodInvoker) (() =>
-   1082 {
-   1083 vassalForm.StatusProgress.Value = 100;
-   1084 vassalForm.RegionTeleportGroup.Enabled = true;
-   1085 // Set the map image to the loading spinner.
-   1086 Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly();
-   1087 System.IO.Stream file =
-   1088 thisAssembly.GetManifestResourceStream("Vassal.img.loading.gif");
-   1089 switch (file != null)
-   1090 {
-   1091 case true:
-   1092 vassalForm.Invoke((MethodInvoker) (() =>
-   1093 {
-   1094 RegionAvatarsMap.SizeMode = PictureBoxSizeMode.CenterImage;
-   1095 RegionAvatarsMap.Image = Image.FromStream(file);
-   1096 RegionAvatarsMap.Refresh();
-   1097 }));
-   1098 break;
-   1099 }
-   1100 // Clear the top scripts table.
-   1101 TopScriptsGridView.Rows.Clear();
-   1102 // Clear the top colliders table.
-   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;
1098 updateCurrentRegionName.BeginInvoke(updateCurrentRegionName.EndInvoke, null); 1122 Objects.Enabled = false;
1099 } 1123 }));
1100 } 1124 }
Line 1101... Line 1125...
1101 }).Start(); 1125 }).Start();
1102 1126  
1103 } 1127 }
1104   1128  
1105 private void SettingsRequested(object sender, EventArgs e) 1129 private void SettingsRequested(object sender, EventArgs e)
Line 1106... Line 1130...
1106 { 1130 {
1107 SettingsForm settingsForm = new SettingsForm {TopMost = true}; 1131 SettingsForm settingsForm = new SettingsForm {TopMost = true};
-   1132 settingsForm.Show();
-   1133 }
-   1134  
1108 settingsForm.Show(); 1135 private void VassalShown(object sender, EventArgs e)
1109 } 1136 {
1110   1137 // Set the version
1111 private void VassalShown(object sender, EventArgs e) 1138 vassalForm.Version.Text = @"v" + VASSAL_CONSTANTS.VASSAL_VERSION;
1112 { 1139  
Line 1113... Line 1140...
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);
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)))
-   1153 .Where(o => o.Count == 2)
1126 .Where(o => o.Count == 2) 1154 .ToDictionary(o => o.First(),
1127 .ToDictionary(o => o.First(), 1155 p =>
1128 p => 1156 Vector3.TryParse(p.Last(), out localPosition)
1129 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); -  
1132 LoadedRegions.Items.Clear(); 1159 // Populate the loaded regions.
1133 LoadedRegions.Items.AddRange( 1160 LoadedRegions.Items.Clear();
1134 ConfiguredRegions.Select(o => (object)new ListViewItem {Text = o.Key, Tag = o.Value}) 1161 LoadedRegions.Items.AddRange(
1135 .ToArray()); 1162 ConfiguredRegions.Select(o => (object) new ListViewItem {Text = o.Key, Tag = o.Value})
-   1163 .ToArray());
1136 } 1164 // Populate the batch restart grid view.
Line 1137... Line 1165...
1137   1165 BatchRestartGridView.Rows.Clear();
1138 // Update the current region in case the configuration is initialized. 1166 foreach (KeyValuePair<string, Vector3> data in ConfiguredRegions)
1139 if (!vassalConfiguration.Equals(default(VassalConfiguration))) 1167 {
1140 { 1168 BatchRestartGridView.Rows.Add(data.Key, data.Value.ToString());
1141 updateCurrentRegionName.BeginInvoke(updateCurrentRegionName.EndInvoke, null); 1169 }
1142 } 1170 }
1143   1171  
1144 // Set the map image to the loading spinner. 1172 // Set the map image to the loading spinner.
1145 Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); 1173 Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly();
1146 System.IO.Stream file = 1174 System.IO.Stream file =
1147 thisAssembly.GetManifestResourceStream("Vassal.img.loading.gif"); 1175 thisAssembly.GetManifestResourceStream("Vassal.img.loading.gif");
1148 switch (file != null) 1176 switch (file != null)
1149 { 1177 {
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;
1216 })); 1259 }));
1217 1260  
1218 // Get the map image. 1261 // Get the map image.
1219 result = wasPOST(vassalConfiguration.HTTPServerURL, 1262 result = wasPOST(vassalConfiguration.HTTPServerURL,
1220 wasKeyValueEscape(new Dictionary<string, string> 1263 wasKeyValueEscape(new Dictionary<string, string>
1221 { 1264 {
1222 {"command", "getgridregiondata"}, 1265 {"command", "getgridregiondata"},
1223 {"group", vassalConfiguration.Group}, 1266 {"group", vassalConfiguration.Group},
1224 {"password", vassalConfiguration.Password}, 1267 {"password", vassalConfiguration.Password},
1225 { "data", "MapImageID"} 1268 {"data", "MapImageID"}
1226 }), vassalConfiguration.DataTimeout); 1269 }), vassalConfiguration.DataTimeout);
1227 1270  
1228 if (string.IsNullOrEmpty(result) || 1271 if (string.IsNullOrEmpty(result) ||
1229 !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) 1272 !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success))
Line 1230... Line 1273...
1230 throw new Exception(); 1273 throw new Exception();
Line 1236... Line 1279...
1236 wasKeyValueEscape(new Dictionary<string, string> 1279 wasKeyValueEscape(new Dictionary<string, string>
1237 { 1280 {
1238 {"command", "download"}, 1281 {"command", "download"},
1239 {"group", vassalConfiguration.Group}, 1282 {"group", vassalConfiguration.Group},
1240 {"password", vassalConfiguration.Password}, 1283 {"password", vassalConfiguration.Password},
1241 {"item", data.Last() }, 1284 {"item", data.Last()},
1242 {"type", "Texture" }, 1285 {"type", "Texture"},
1243 {"format", "Jpeg" }, 1286 {"format", "Jpeg"},
1244 }), vassalConfiguration.DataTimeout); 1287 }), vassalConfiguration.DataTimeout);
1245 if (string.IsNullOrEmpty(result) || 1288 if (string.IsNullOrEmpty(result) ||
1246 !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) 1289 !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success))
1247 throw new Exception(); 1290 throw new Exception();
1248 byte[] mapImageBytes = Convert.FromBase64String(wasInput(wasKeyValueGet("data", result))); 1291 byte[] mapImageBytes = Convert.FromBase64String(wasInput(wasKeyValueGet("data", result)));
Line 1257... Line 1300...
1257 wasKeyValueEscape(new Dictionary<string, string> 1300 wasKeyValueEscape(new Dictionary<string, string>
1258 { 1301 {
1259 {"command", "getavatarpositions"}, 1302 {"command", "getavatarpositions"},
1260 {"group", vassalConfiguration.Group}, 1303 {"group", vassalConfiguration.Group},
1261 {"password", vassalConfiguration.Password}, 1304 {"password", vassalConfiguration.Password},
1262 { "entity", "region"} 1305 {"entity", "region"}
1263 }), vassalConfiguration.DataTimeout); 1306 }), vassalConfiguration.DataTimeout);
Line 1264... Line 1307...
1264   1307  
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))
Line 1267... Line 1310...
1267 throw new Exception(); 1310 throw new Exception();
-   1311  
1268   1312 // Every thrid element represents a Vecto3 of the avatar position.
-   1313 data =
-   1314 wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result)))
-   1315 .Skip(2)
Line 1269... Line 1316...
1269 // Every thrid element represents a Vecto3 of the avatar position. 1316 .Where((x, i) => i%3 == 0)
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 {
-   1324 switch (Vector3.TryParse(vector, out position))
1277 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;
Line 1296... Line 1344...
1296 } 1344 }
1297 finally 1345 finally
1298 { 1346 {
1299 Monitor.Exit(ClientInstanceTeleportLock); 1347 Monitor.Exit(ClientInstanceTeleportLock);
1300 } 1348 }
1301 1349  
1302 }; 1350 };
1303 overviewTabTimer.Start(); 1351 overviewTabTimer.Start();
Line 1304... Line 1352...
1304   1352  
1305 // Start the top scores timer. 1353 // Start the top scores timer.
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 (
1344 { 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)))
1345 switch (!TopScriptsGridView.Rows.Count.Equals(0)) 1400 .Select(q => q.Index))
-   1401 {
1346 { 1402 TopScriptsGridView.Rows.RemoveAt(index);
-   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]; -  
1361 break; -  
1362 } -  
1363 } 1418 row.Cells["TopScriptsPosition"].Value = dataComponents[4];
1364 break; -  
1365 default: 1419 break;
1366 foreach (List<string> updateRowData in data) -  
1367 { 1420 case false: // the row dosn't exist, so add it.
1368 TopScriptsGridView.Rows.Add(updateRowData[0], updateRowData[1], updateRowData[2], 1421 TopScriptsGridView.Rows.Add(dataComponents[0], dataComponents[1], dataComponents[2],
1369 updateRowData[3], updateRowData[4]); 1422 dataComponents[3], dataComponents[4]);
1370 } 1423 break;
1371 break; 1424 }
1372 } -  
1373 1425 }
1374 })); 1426 }));
1375 } 1427 }
1376 catch (Exception) 1428 catch (Exception)
Line 1391... Line 1443...
1391 return; 1443 return;
Line 1392... Line 1444...
1392   1444  
1393 try 1445 try
1394 { 1446 {
1395 // Do not do anything in case the tab is not selected. 1447 // Do not do anything in case the tab is not selected.
1396 vassalForm.Invoke((MethodInvoker)(() => 1448 vassalForm.Invoke((MethodInvoker) (() =>
1397 { 1449 {
1398 if (!Tabs.SelectedTab.Equals(TopCollidersTab)) 1450 if (!Tabs.SelectedTab.Equals(TopCollidersTab))
1399 throw new Exception(); 1451 throw new Exception();
Line 1414... Line 1466...
1414 !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) 1466 !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success))
1415 throw new Exception(); 1467 throw new Exception();
Line 1416... Line 1468...
1416   1468  
1417 HashSet<List<string>> data = 1469 HashSet<List<string>> data =
1418 new HashSet<List<string>>(wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))) 1470 new HashSet<List<string>>(wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result)))
1419 .Select((x, i) => new { Index = i, Value = x }) 1471 .Select((x, i) => new {Index = i, Value = x})
1420 .GroupBy(x => x.Index / 5) 1472 .GroupBy(x => x.Index/5)
1421 .Select(x => x.Select(v => v.Value).ToList())); 1473 .Select(x => x.Select(v => v.Value).ToList()));
1422 if (data.Count.Equals(0)) 1474 if (data.Count.Equals(0))
Line 1423... Line 1475...
1423 throw new Exception(); 1475 throw new Exception();
1424   1476  
-   1477 vassalForm.Invoke((MethodInvoker) (() =>
-   1478 {
-   1479 // Remove rows that are not in the data update.
1425 vassalForm.Invoke((MethodInvoker)(() => 1480 foreach (
-   1481 int index in
-   1482 TopCollidersGridView.Rows.AsParallel().Cast<DataGridViewRow>()
-   1483 .Where(
-   1484 topCollidersRow =>
1426 { 1485 !data.Any(q => q[2].Equals(topCollidersRow.Cells["TopCollidersUUID"].Value)))
-   1486 .Select(q => q.Index))
1427 switch (!TopCollidersGridView.Rows.Count.Equals(0)) 1487 {
-   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)))
-   1492 {
1431 { 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]; -  
1442 topCollidersRow.Cells["TopCollidersPosition"].Value = updateRowData[4]; -  
1443 break; -  
1444 } 1503 row.Cells["TopCollidersOwner"].Value = dataComponents[3];
1445 } -  
1446 break; 1504 row.Cells["TopCollidersPosition"].Value = dataComponents[4];
1447 default: -  
1448 foreach (List<string> updateRowData in data) 1505 break;
1449 { 1506 case false: // the row dosn't exist, so add it.
1450 TopCollidersGridView.Rows.Add(updateRowData[0], updateRowData[1], updateRowData[2], 1507 TopCollidersGridView.Rows.Add(dataComponents[0], dataComponents[1], dataComponents[2],
1451 updateRowData[3], updateRowData[4]); 1508 dataComponents[3], dataComponents[4]);
1452 } 1509 break;
Line 1453... Line 1510...
1453 break; 1510 }
1454 } 1511 }
1455   1512  
Line 1469... Line 1526...
1469   1526  
1470 private void RequestedEditRegions(object sender, EventArgs e) 1527 private void RequestedEditRegions(object sender, EventArgs e)
1471 { 1528 {
1472 // Clear any selection. 1529 // Clear any selection.
1473 LoadedRegions.SelectedIndex = -1; 1530 LoadedRegions.SelectedIndex = -1;
1474 RegionEditForm regionEditForm = new RegionEditForm { TopMost = true }; 1531 RegionEditForm regionEditForm = new RegionEditForm {TopMost = true};
1475 regionEditForm.Show(); 1532 regionEditForm.Show();
Line 1476... Line 1533...
1476 } 1533 }
1477   1534  
1478 private void RequestSelecting(object sender, TabControlCancelEventArgs e) 1535 private void RequestSelecting(object sender, TabControlCancelEventArgs e)
1479 { 1536 {
-   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 {
1480 e.Cancel = !e.TabPage.Enabled; 2048  
1481 } 2049 }