corrade-vassal – Diff between revs 5 and 7
?pathlinks?
Rev 5 | Rev 7 | |||
---|---|---|---|---|
Line 8... | Line 8... | |||
8 | using System.Collections; |
8 | using System.Collections; |
|
9 | using System.Collections.Generic; |
9 | using System.Collections.Generic; |
|
10 | using System.ComponentModel; |
10 | using System.ComponentModel; |
|
11 | using System.Data; |
11 | using System.Data; |
|
12 | using System.Drawing; |
12 | using System.Drawing; |
|
- | 13 | using System.Drawing.Imaging; |
||
13 | using System.IO; |
14 | using System.IO; |
|
14 | using System.Linq; |
15 | using System.Linq; |
|
15 | using System.Net; |
16 | using System.Net; |
|
- | 17 | using System.Net.Sockets; |
||
16 | using System.Reflection; |
18 | using System.Reflection; |
|
17 | using System.Text; |
19 | using System.Text; |
|
18 | using System.Text.RegularExpressions; |
20 | using System.Text.RegularExpressions; |
|
19 | using System.Timers; |
21 | using System.Timers; |
|
20 | using System.Threading; |
22 | using System.Threading; |
|
Line 27... | Line 29... | |||
27 | namespace Vassal |
29 | namespace Vassal |
|
28 | { |
30 | { |
|
29 | public partial class Vassal : Form |
31 | public partial class Vassal : Form |
|
30 | { |
32 | { |
|
31 | public static System.Timers.Timer overviewTabTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); |
33 | public static System.Timers.Timer overviewTabTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); |
|
- | 34 | public static System.Timers.Timer residentListTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); |
||
32 | public static System.Timers.Timer topScriptsTabTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); |
35 | 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); |
36 | public static System.Timers.Timer topCollidersTabTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); |
|
- | 37 | public static System.Timers.Timer regionsStateTabTimer = new Timer(TimeSpan.FromSeconds(1).TotalMilliseconds); |
||
- | 38 | public static volatile int regionsStateCheckIndex = 0; |
||
34 | public static VassalConfiguration vassalConfiguration = new VassalConfiguration(); |
39 | public static VassalConfiguration vassalConfiguration = new VassalConfiguration(); |
|
35 | public static Vassal vassalForm; |
40 | public static Vassal vassalForm; |
|
36 | public static readonly object ClientInstanceTeleportLock = new object(); |
41 | public static readonly object ClientInstanceTeleportLock = new object(); |
|
- | 42 | public static readonly object RegionsStateCheckLock = new object(); |
||
- | 43 | |
||
- | 44 | /// <summary> |
||
- | 45 | /// Linden constants. |
||
- | 46 | /// </summary> |
||
- | 47 | public struct LINDEN_CONSTANTS |
||
- | 48 | { |
||
- | 49 | public struct ALERTS |
||
- | 50 | { |
||
- | 51 | public const string NO_ROOM_TO_SIT_HERE = @"No room to sit here, try another spot."; |
||
- | 52 | |
||
- | 53 | public const string UNABLE_TO_SET_HOME = |
||
- | 54 | @"You can only set your 'Home Location' on your land or at a mainland Infohub."; |
||
- | 55 | |
||
- | 56 | public const string HOME_SET = @"Home position set."; |
||
- | 57 | } |
||
- | 58 | |
||
- | 59 | public struct ASSETS |
||
- | 60 | { |
||
- | 61 | public struct NOTECARD |
||
- | 62 | { |
||
- | 63 | public const string NEWLINE = "\n"; |
||
- | 64 | public const uint MAXIMUM_BODY_LENTH = 65536; |
||
- | 65 | } |
||
- | 66 | } |
||
- | 67 | |
||
- | 68 | public struct AVATARS |
||
- | 69 | { |
||
- | 70 | public const uint SET_DISPLAY_NAME_SUCCESS = 200; |
||
- | 71 | public const string LASTNAME_PLACEHOLDER = @"Resident"; |
||
- | 72 | public const uint MAXIMUM_DISPLAY_NAME_CHARACTERS = 31; |
||
- | 73 | public const uint MINIMUM_DISPLAY_NAME_CHARACTERS = 1; |
||
- | 74 | public const uint MAXIMUM_NUMBER_OF_ATTACHMENTS = 38; |
||
- | 75 | |
||
- | 76 | public struct PROFILE |
||
- | 77 | { |
||
- | 78 | public const uint SECOND_LIFE_TEXT_SIZE = 510; |
||
- | 79 | public const uint FIRST_LIFE_TEXT_SIZE = 253; |
||
- | 80 | } |
||
- | 81 | |
||
- | 82 | public struct PICKS |
||
- | 83 | { |
||
- | 84 | public const uint MAXIMUM_PICKS = 10; |
||
- | 85 | public const uint MAXIMUM_PICK_DESCRIPTION_SIZE = 1022; |
||
- | 86 | } |
||
- | 87 | |
||
- | 88 | public struct CLASSIFIEDS |
||
- | 89 | { |
||
- | 90 | public const uint MAXIMUM_CLASSIFIEDS = 100; |
||
- | 91 | } |
||
- | 92 | } |
||
- | 93 | |
||
- | 94 | public struct PRIMITIVES |
||
- | 95 | { |
||
- | 96 | public const uint MAXIMUM_NAME_SIZE = 63; |
||
- | 97 | public const uint MAXIMUM_DESCRIPTION_SIZE = 127; |
||
- | 98 | public const double MAXIMUM_REZ_HEIGHT = 4096.0; |
||
- | 99 | public const double MINIMUM_SIZE_X = 0.01; |
||
- | 100 | public const double MINIMUM_SIZE_Y = 0.01; |
||
- | 101 | public const double MINIMUM_SIZE_Z = 0.01; |
||
- | 102 | public const double MAXIMUM_SIZE_X = 64.0; |
||
- | 103 | public const double MAXIMUM_SIZE_Y = 64.0; |
||
- | 104 | public const double MAXIMUM_SIZE_Z = 64.0; |
||
- | 105 | } |
||
- | 106 | |
||
- | 107 | public struct OBJECTS |
||
- | 108 | { |
||
- | 109 | public const uint MAXIMUM_PRIMITIVE_COUNT = 256; |
||
- | 110 | } |
||
- | 111 | |
||
- | 112 | public struct DIRECTORY |
||
- | 113 | { |
||
- | 114 | public struct EVENT |
||
- | 115 | { |
||
- | 116 | public const uint SEARCH_RESULTS_COUNT = 200; |
||
- | 117 | } |
||
- | 118 | |
||
- | 119 | public struct GROUP |
||
- | 120 | { |
||
- | 121 | public const uint SEARCH_RESULTS_COUNT = 100; |
||
- | 122 | } |
||
- | 123 | |
||
- | 124 | public struct LAND |
||
- | 125 | { |
||
- | 126 | public const uint SEARCH_RESULTS_COUNT = 100; |
||
- | 127 | } |
||
- | 128 | |
||
- | 129 | public struct PEOPLE |
||
- | 130 | { |
||
- | 131 | public const uint SEARCH_RESULTS_COUNT = 100; |
||
- | 132 | } |
||
- | 133 | } |
||
- | 134 | |
||
- | 135 | public struct ESTATE |
||
- | 136 | { |
||
- | 137 | public const uint REGION_RESTART_DELAY = 120; |
||
- | 138 | public const uint MAXIMUM_BAN_LIST_LENGTH = 500; |
||
- | 139 | public const uint MAXIMUM_GROUP_LIST_LENGTH = 63; |
||
- | 140 | public const uint MAXIMUM_USER_LIST_LENGTH = 500; |
||
- | 141 | public const uint MAXIMUM_MANAGER_LIST_LENGTH = 10; |
||
- | 142 | |
||
- | 143 | public struct MESSAGES |
||
- | 144 | { |
||
- | 145 | public const string REGION_RESTART_MESSAGE = @"restart"; |
||
- | 146 | } |
||
- | 147 | } |
||
- | 148 | |
||
- | 149 | public struct PARCELS |
||
- | 150 | { |
||
- | 151 | public const double MAXIMUM_AUTO_RETURN_TIME = 999999; |
||
- | 152 | public const uint MINIMUM_AUTO_RETURN_TIME = 0; |
||
- | 153 | public const uint MAXIMUM_NAME_LENGTH = 63; |
||
- | 154 | public const uint MAXIMUM_DESCRIPTION_LENGTH = 255; |
||
- | 155 | } |
||
- | 156 | |
||
- | 157 | public struct GRID |
||
- | 158 | { |
||
- | 159 | public const string SECOND_LIFE = @"Second Life"; |
||
- | 160 | public const string TIME_ZONE = @"Pacific Standard Time"; |
||
- | 161 | } |
||
- | 162 | |
||
- | 163 | public struct CHAT |
||
- | 164 | { |
||
- | 165 | public const uint MAXIMUM_MESSAGE_LENGTH = 1024; |
||
- | 166 | } |
||
- | 167 | |
||
- | 168 | public struct GROUPS |
||
- | 169 | { |
||
- | 170 | public const uint MAXIMUM_NUMBER_OF_ROLES = 10; |
||
- | 171 | public const string EVERYONE_ROLE_NAME = @"Everyone"; |
||
- | 172 | public const uint MAXIMUM_GROUP_NAME_LENGTH = 35; |
||
- | 173 | public const uint MAXIMUM_GROUP_TITLE_LENGTH = 20; |
||
- | 174 | } |
||
- | 175 | |
||
- | 176 | public struct NOTICES |
||
- | 177 | { |
||
- | 178 | public const uint MAXIMUM_NOTICE_MESSAGE_LENGTH = 512; |
||
- | 179 | } |
||
- | 180 | |
||
- | 181 | public struct LSL |
||
- | 182 | { |
||
- | 183 | public const string CSV_DELIMITER = @", "; |
||
- | 184 | public const float SENSOR_RANGE = 96; |
||
- | 185 | public const string DATE_TIME_STAMP = @"yyy-MM-ddTHH:mm:ss.ffffffZ"; |
||
- | 186 | } |
||
- | 187 | |
||
- | 188 | public struct REGION |
||
- | 189 | { |
||
- | 190 | public const float TELEPORT_MINIMUM_DISTANCE = 1; |
||
- | 191 | public const float DEFAULT_AGENT_LIMIT = 40; |
||
- | 192 | public const float DEFAULT_OBJECT_BONUS = 1; |
||
- | 193 | public const bool DEFAULT_FIXED_SUN = false; |
||
- | 194 | public const float DEFAULT_TERRAIN_LOWER_LIMIT = -4; |
||
- | 195 | public const float DEFAULT_TERRAIN_RAISE_LIMIT = 4; |
||
- | 196 | public const bool DEFAULT_USE_ESTATE_SUN = true; |
||
- | 197 | public const float DEFAULT_WATER_HEIGHT = 20; |
||
- | 198 | public const float SUNRISE = 6; |
||
- | 199 | } |
||
- | 200 | |
||
- | 201 | public struct VIEWER |
||
- | 202 | { |
||
- | 203 | public const float MAXIMUM_DRAW_DISTANCE = 4096; |
||
- | 204 | } |
||
- | 205 | |
||
- | 206 | public struct TELEPORTS |
||
- | 207 | { |
||
- | 208 | public struct THROTTLE |
||
- | 209 | { |
||
- | 210 | public const uint MAX_TELEPORTS = 10; |
||
- | 211 | public const uint GRACE_SECONDS = 15; |
||
- | 212 | } |
||
- | 213 | } |
||
- | 214 | } |
||
- | 215 | |
||
- | 216 | /////////////////////////////////////////////////////////////////////////// |
||
- | 217 | // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 // |
||
- | 218 | /////////////////////////////////////////////////////////////////////////// |
||
- | 219 | private static double wasMapValueToRange(double value, double xMin, double xMax, double yMin, double yMax) |
||
- | 220 | { |
||
- | 221 | return yMin + ( |
||
- | 222 | ( |
||
- | 223 | yMax - yMin |
||
- | 224 | ) |
||
- | 225 | * |
||
- | 226 | ( |
||
- | 227 | value - xMin |
||
- | 228 | ) |
||
- | 229 | / |
||
- | 230 | ( |
||
- | 231 | xMax - xMin |
||
- | 232 | ) |
||
- | 233 | ); |
||
- | 234 | } |
||
Line 37... | Line 235... | |||
37 | |
235 | |
|
38 | /////////////////////////////////////////////////////////////////////////// |
236 | /////////////////////////////////////////////////////////////////////////// |
|
39 | // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 // |
237 | // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 // |
|
40 | /////////////////////////////////////////////////////////////////////////// |
238 | /////////////////////////////////////////////////////////////////////////// |
|
Line 978... | Line 1176... | |||
978 | ListViewItem listViewItem = LoadedRegions.SelectedItem as ListViewItem; |
1176 | ListViewItem listViewItem = LoadedRegions.SelectedItem as ListViewItem; |
|
979 | switch (listViewItem != null && LoadedRegions.SelectedIndex != -1) |
1177 | switch (listViewItem != null && LoadedRegions.SelectedIndex != -1) |
|
980 | { |
1178 | { |
|
981 | case true: |
1179 | case true: |
|
982 | selectedRegionName = listViewItem.Text; |
1180 | selectedRegionName = listViewItem.Text; |
|
983 | selectedRegionPosition = (Vector3)listViewItem.Tag; |
1181 | selectedRegionPosition = (Vector3) listViewItem.Tag; |
|
984 | startTeleport = true; |
1182 | startTeleport = true; |
|
985 | break; |
1183 | break; |
|
986 | default: |
1184 | default: |
|
987 | startTeleport = false; |
1185 | startTeleport = false; |
|
988 | break; |
1186 | break; |
|
989 | } |
1187 | } |
|
990 | })); |
1188 | })); |
|
Line 991... | Line 1189... | |||
991 | |
1189 | |
|
992 | if (!startTeleport) return; |
1190 | if (!startTeleport) return; |
|
Line 993... | Line 1191... | |||
993 | |
1191 | |
|
994 | |
1192 | |
|
995 | // Announce teleport. |
1193 | // Announce teleport. |
|
996 | vassalForm.Invoke((MethodInvoker)(() => |
1194 | vassalForm.Invoke((MethodInvoker) (() => |
|
997 | { |
1195 | { |
|
998 | vassalForm.RegionTeleportGroup.Enabled = false; |
1196 | vassalForm.RegionTeleportGroup.Enabled = false; |
|
999 | vassalForm.StatusProgress.Value = 0; |
1197 | vassalForm.StatusProgress.Value = 0; |
|
Line 1076... | Line 1274... | |||
1076 | })); |
1274 | })); |
|
1077 | } |
1275 | } |
|
1078 | finally |
1276 | finally |
|
1079 | { |
1277 | { |
|
1080 | Monitor.Exit(ClientInstanceTeleportLock); |
1278 | Monitor.Exit(ClientInstanceTeleportLock); |
|
1081 | vassalForm.Invoke((MethodInvoker) (() => |
1279 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
1082 | { |
1280 | { |
|
1083 | vassalForm.StatusProgress.Value = 100; |
1281 | vassalForm.StatusProgress.Value = 100; |
|
1084 | vassalForm.RegionTeleportGroup.Enabled = true; |
1282 | vassalForm.RegionTeleportGroup.Enabled = true; |
|
1085 | // Set the map image to the loading spinner. |
1283 | // Set the map image to the loading spinner. |
|
1086 | Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); |
1284 | Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); |
|
Line 1095... | Line 1293... | |||
1095 | RegionAvatarsMap.Image = Image.FromStream(file); |
1293 | RegionAvatarsMap.Image = Image.FromStream(file); |
|
1096 | RegionAvatarsMap.Refresh(); |
1294 | RegionAvatarsMap.Refresh(); |
|
1097 | })); |
1295 | })); |
|
1098 | break; |
1296 | break; |
|
1099 | } |
1297 | } |
|
- | 1298 | // Clear the resident list table. |
||
- | 1299 | ResidentListGridView.Rows.Clear(); |
||
1100 | // Clear the top scripts table. |
1300 | // Clear the top scripts table. |
|
1101 | TopScriptsGridView.Rows.Clear(); |
1301 | TopScriptsGridView.Rows.Clear(); |
|
1102 | // Clear the top colliders table. |
1302 | // Clear the top colliders table. |
|
1103 | TopCollidersGridView.Rows.Clear(); |
1303 | TopCollidersGridView.Rows.Clear(); |
|
1104 | // Invalidate data for overview tab. |
1304 | // Invalidate data for overview tab. |
|
Line 1120... | Line 1320... | |||
1120 | ScriptTime.Enabled = false; |
1320 | ScriptTime.Enabled = false; |
|
1121 | Objects.Text = string.Empty; |
1321 | Objects.Text = string.Empty; |
|
1122 | Objects.Enabled = false; |
1322 | Objects.Enabled = false; |
|
1123 | })); |
1323 | })); |
|
1124 | } |
1324 | } |
|
1125 | }).Start(); |
1325 | }) |
|
1126 | |
- | ||
- | 1326 | {IsBackground = true}.Start(); |
||
1127 | } |
1327 | } |
|
Line 1128... | Line 1328... | |||
1128 | |
1328 | |
|
1129 | private void SettingsRequested(object sender, EventArgs e) |
1329 | private void SettingsRequested(object sender, EventArgs e) |
|
1130 | { |
1330 | { |
|
Line 1138... | Line 1338... | |||
1138 | vassalForm.Version.Text = @"v" + VASSAL_CONSTANTS.VASSAL_VERSION; |
1338 | vassalForm.Version.Text = @"v" + VASSAL_CONSTANTS.VASSAL_VERSION; |
|
Line 1139... | Line 1339... | |||
1139 | |
1339 | |
|
1140 | // Disable estate manager tabs since we will enable these dynamically. |
1340 | // Disable estate manager tabs since we will enable these dynamically. |
|
1141 | TopScriptsTab.Enabled = false; |
1341 | TopScriptsTab.Enabled = false; |
|
- | 1342 | TopCollidersTab.Enabled = false; |
||
Line 1142... | Line 1343... | |||
1142 | TopCollidersTab.Enabled = false; |
1343 | ResidentListBanGroup.Enabled = false; |
|
1143 | |
1344 | |
|
1144 | // Get the configuration file settings if it exists. |
1345 | // Get the configuration file settings if it exists. |
|
1145 | if (File.Exists(VASSAL_CONSTANTS.VASSAL_CONFIGURATION_FILE)) |
1346 | if (File.Exists(VASSAL_CONSTANTS.VASSAL_CONFIGURATION_FILE)) |
|
1146 | { |
1347 | { |
|
1147 | // Load the configuration. |
1348 | // Load the configuration. |
|
1148 | VassalConfiguration.Load(VASSAL_CONSTANTS.VASSAL_CONFIGURATION_FILE, ref vassalConfiguration); |
1349 | VassalConfiguration.Load(VASSAL_CONSTANTS.VASSAL_CONFIGURATION_FILE, ref vassalConfiguration); |
|
1149 | // Apply settings |
1350 | // Apply settings |
|
Line -... | Line 1351... | |||
- | 1351 | RegionRestartDelayBox.Text = vassalConfiguration.RegionRestartDelay.ToString(Utils.EnUsCulture); |
||
- | 1352 | } |
||
- | 1353 | |
||
- | 1354 | // Spawn a thread to check Corrade's connection status. |
||
- | 1355 | new Thread(() => |
||
- | 1356 | { |
||
- | 1357 | TcpClient tcpClient = new TcpClient(); |
||
- | 1358 | try |
||
- | 1359 | { |
||
- | 1360 | System.Uri uri = new System.Uri(vassalConfiguration.HTTPServerURL); |
||
- | 1361 | tcpClient.Connect(uri.Host, uri.Port); |
||
- | 1362 | // port open |
||
- | 1363 | vassalForm.BeginInvoke((MethodInvoker) (() => { Tabs.Enabled = true; })); |
||
- | 1364 | // set the loading spinner |
||
- | 1365 | Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); |
||
- | 1366 | System.IO.Stream file = |
||
- | 1367 | thisAssembly.GetManifestResourceStream("Vassal.img.loading.gif"); |
||
- | 1368 | switch (file != null) |
||
- | 1369 | { |
||
- | 1370 | case true: |
||
- | 1371 | vassalForm.BeginInvoke((MethodInvoker) (() => |
||
- | 1372 | { |
||
- | 1373 | RegionAvatarsMap.SizeMode = PictureBoxSizeMode.CenterImage; |
||
- | 1374 | RegionAvatarsMap.Image = Image.FromStream(file); |
||
- | 1375 | RegionAvatarsMap.Refresh(); |
||
- | 1376 | })); |
||
- | 1377 | break; |
||
- | 1378 | } |
||
- | 1379 | } |
||
- | 1380 | catch (Exception) |
||
- | 1381 | { |
||
- | 1382 | // port closed |
||
- | 1383 | vassalForm.BeginInvoke((MethodInvoker) (() => { Tabs.Enabled = false; })); |
||
- | 1384 | } |
||
1150 | RegionRestartDelayBox.Text = vassalConfiguration.RegionRestartDelay.ToString(Utils.EnUsCulture); |
1385 | }) |
|
1151 | } |
1386 | {IsBackground = true}.Start(); |
|
1152 | |
1387 | |
|
1153 | // Get all the regions if they exist. |
1388 | // Get all the regions if they exist. |
|
1154 | if (File.Exists(VASSAL_CONSTANTS.VASSAL_REGIONS)) |
1389 | if (File.Exists(VASSAL_CONSTANTS.VASSAL_REGIONS)) |
|
Line 1172... | Line 1407... | |||
1172 | BatchRestartGridView.Rows.Clear(); |
1407 | BatchRestartGridView.Rows.Clear(); |
|
1173 | foreach (KeyValuePair<string, Vector3> data in ConfiguredRegions) |
1408 | foreach (KeyValuePair<string, Vector3> data in ConfiguredRegions) |
|
1174 | { |
1409 | { |
|
1175 | BatchRestartGridView.Rows.Add(data.Key, data.Value.ToString()); |
1410 | BatchRestartGridView.Rows.Add(data.Key, data.Value.ToString()); |
|
1176 | } |
1411 | } |
|
1177 | } |
- | ||
1178 | |
- | ||
1179 | // Set the map image to the loading spinner. |
1412 | // Populate the regions state grid view. |
|
1180 | Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); |
- | ||
1181 | System.IO.Stream file = |
- | ||
1182 | thisAssembly.GetManifestResourceStream("Vassal.img.loading.gif"); |
1413 | foreach (KeyValuePair<string, Vector3> data in ConfiguredRegions) |
|
1183 | switch (file != null) |
- | ||
1184 | { |
- | ||
1185 | case true: |
- | ||
1186 | vassalForm.Invoke((MethodInvoker) (() => |
- | ||
1187 | { |
1414 | { |
|
1188 | RegionAvatarsMap.SizeMode = PictureBoxSizeMode.CenterImage; |
1415 | RegionsStateGridView.Rows.Add(data.Key, "Check pening..."); |
|
1189 | RegionAvatarsMap.Image = Image.FromStream(file); |
- | ||
1190 | RegionAvatarsMap.Refresh(); |
- | ||
1191 | })); |
1416 | } |
|
1192 | break; |
- | ||
1193 | } |
1417 | } |
|
Line 1194... | Line 1418... | |||
1194 | |
1418 | |
|
1195 | // Start the overview timer. |
1419 | // Start the overview timer. |
|
1196 | overviewTabTimer.Elapsed += (o, p) => |
1420 | overviewTabTimer.Elapsed += (o, p) => |
|
1197 | { |
1421 | { |
|
1198 | if (!Monitor.TryEnter(ClientInstanceTeleportLock)) |
1422 | if (!Monitor.TryEnter(ClientInstanceTeleportLock)) |
|
Line 1199... | Line 1423... | |||
1199 | return; |
1423 | return; |
|
1200 | |
1424 | |
|
1201 | try |
1425 | try |
|
1202 | { |
- | ||
1203 | // Do not do anything in case the tab is not selected. |
- | ||
1204 | vassalForm.Invoke((MethodInvoker) (() => |
- | ||
1205 | { |
- | ||
1206 | if (!Tabs.SelectedTab.Equals(OverviewTab)) |
- | ||
Line 1207... | Line 1426... | |||
1207 | throw new Exception(); |
1426 | { |
|
1208 | })); |
1427 | // Always run the overview regardless which tab is active. |
|
1209 | |
1428 | |
|
1210 | // Get the statistics. |
1429 | // Get the statistics. |
|
Line 1238... | Line 1457... | |||
1238 | |
1457 | |
|
1239 | List<string> data = wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))).ToList(); |
1458 | List<string> data = wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))).ToList(); |
|
1240 | if (data.Count.Equals(0)) |
1459 | if (data.Count.Equals(0)) |
|
Line 1241... | Line 1460... | |||
1241 | throw new Exception(); |
1460 | throw new Exception(); |
|
1242 | |
1461 | |
|
1243 | vassalForm.Invoke((MethodInvoker) (() => |
1462 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
1244 | { |
1463 | { |
|
1245 | // Drop access to features if we are not estate managers. |
1464 | // Drop access to features if we are not estate managers. |
|
1246 | bool isEstateManager; |
1465 | bool isEstateManager; |
|
1247 | switch ( |
1466 | switch ( |
|
1248 | bool.TryParse(data[data.IndexOf("IsEstateManager") + 1], out isEstateManager) && |
1467 | bool.TryParse(data[data.IndexOf("IsEstateManager") + 1], out isEstateManager) && |
|
1249 | isEstateManager) |
1468 | isEstateManager) |
|
1250 | { |
1469 | { |
|
1251 | case true: // we are an estate manager |
1470 | case true: // we are an estate manager |
|
- | 1471 | TopScriptsTab.Enabled = true; |
||
1252 | TopScriptsTab.Enabled = true; |
1472 | TopCollidersTab.Enabled = true; |
|
1253 | TopCollidersTab.Enabled = true; |
1473 | ResidentListBanGroup.Enabled = true; |
|
1254 | break; |
1474 | break; |
|
1255 | default: |
1475 | default: |
|
- | 1476 | TopScriptsTab.Enabled = false; |
||
1256 | TopScriptsTab.Enabled = false; |
1477 | TopCollidersTab.Enabled = false; |
|
1257 | TopCollidersTab.Enabled = false; |
1478 | ResidentListBanGroup.Enabled = false; |
|
Line 1258... | Line 1479... | |||
1258 | break; |
1479 | break; |
|
1259 | } |
1480 | } |
|
Line 1353... | Line 1574... | |||
1353 | break; |
1574 | break; |
|
1354 | } |
1575 | } |
|
1355 | } |
1576 | } |
|
1356 | mapGraphics.DrawImage(mapImage, new Point(0, 0)); |
1577 | mapGraphics.DrawImage(mapImage, new Point(0, 0)); |
|
Line 1357... | Line 1578... | |||
1357 | |
1578 | |
|
1358 | vassalForm.Invoke((MethodInvoker) (() => |
1579 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
1359 | { |
1580 | { |
|
1360 | RegionAvatarsMap.SizeMode = PictureBoxSizeMode.StretchImage; |
1581 | RegionAvatarsMap.SizeMode = PictureBoxSizeMode.StretchImage; |
|
1361 | RegionAvatarsMap.Image = mapImage; |
1582 | RegionAvatarsMap.Image = mapImage; |
|
1362 | RegionAvatarsMap.Refresh(); |
1583 | RegionAvatarsMap.Refresh(); |
|
Line 1372... | Line 1593... | |||
1372 | } |
1593 | } |
|
Line 1373... | Line 1594... | |||
1373 | |
1594 | |
|
1374 | }; |
1595 | }; |
|
Line 1375... | Line -... | |||
1375 | overviewTabTimer.Start(); |
- | ||
1376 | |
1596 | overviewTabTimer.Start(); |
|
1377 | // Start the top scores timer. |
1597 | |
|
- | 1598 | regionsStateTabTimer.Elapsed += (o, p) => |
||
- | 1599 | { |
||
- | 1600 | // Do not do anything in case the tab is not selected. |
||
- | 1601 | bool run = false; |
||
- | 1602 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 1603 | { |
||
- | 1604 | run = Tabs.SelectedTab.Equals(RegionsStateTab); |
||
- | 1605 | })); |
||
1378 | topScriptsTabTimer.Elapsed += (o, p) => |
1606 | if (!run) return; |
|
1379 | { |
1607 | |
|
Line 1380... | Line 1608... | |||
1380 | if (!Monitor.TryEnter(ClientInstanceTeleportLock)) |
1608 | if (!Monitor.TryEnter(RegionsStateCheckLock)) |
|
1381 | return; |
1609 | return; |
|
- | 1610 | |
||
- | 1611 | try |
||
- | 1612 | { |
||
- | 1613 | string regionName = string.Empty; |
||
- | 1614 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 1615 | { |
||
- | 1616 | regionName = |
||
- | 1617 | RegionsStateGridView.Rows[regionsStateCheckIndex].Cells["RegionsStateRegionName"].Value |
||
- | 1618 | .ToString(); |
||
- | 1619 | })); |
||
- | 1620 | |
||
- | 1621 | if (string.IsNullOrEmpty(regionName)) |
||
- | 1622 | throw new Exception(); |
||
- | 1623 | |
||
- | 1624 | // Get the region status. |
||
- | 1625 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
||
- | 1626 | wasKeyValueEscape(new Dictionary<string, string> |
||
- | 1627 | { |
||
- | 1628 | {"command", "getgridregiondata"}, |
||
- | 1629 | {"group", vassalConfiguration.Group}, |
||
- | 1630 | {"password", vassalConfiguration.Password}, |
||
- | 1631 | {"region", regionName}, |
||
- | 1632 | {"data", "Access"} |
||
- | 1633 | }), vassalConfiguration.DataTimeout); |
||
- | 1634 | |
||
- | 1635 | bool success; |
||
- | 1636 | if (string.IsNullOrEmpty(result) || |
||
- | 1637 | !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
||
- | 1638 | throw new Exception(); |
||
- | 1639 | |
||
- | 1640 | List<string> data = wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))).ToList(); |
||
- | 1641 | if (!data.Count.Equals(2)) |
||
- | 1642 | throw new Exception(); |
||
- | 1643 | |
||
- | 1644 | string status = data.Last(); |
||
- | 1645 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 1646 | { |
||
- | 1647 | switch (status) |
||
1382 | |
1648 | { |
|
- | 1649 | case "Unknown": |
||
- | 1650 | case "Down": |
||
- | 1651 | case "NonExistent": |
||
- | 1652 | RegionsStateGridView.Rows[regionsStateCheckIndex].DefaultCellStyle.BackColor = |
||
- | 1653 | Color.LightPink; |
||
- | 1654 | RegionsStateGridView.Rows[regionsStateCheckIndex].Cells["RegionsStateLastState"].Value = |
||
- | 1655 | status; |
||
- | 1656 | break; |
||
- | 1657 | default: |
||
- | 1658 | RegionsStateGridView.Rows[regionsStateCheckIndex].DefaultCellStyle.BackColor = |
||
- | 1659 | Color.LightGreen; |
||
- | 1660 | RegionsStateGridView.Rows[regionsStateCheckIndex].Cells["RegionsStateLastState"].Value = |
||
- | 1661 | "Up"; |
||
- | 1662 | break; |
||
- | 1663 | } |
||
- | 1664 | RegionsStateGridView.Rows[regionsStateCheckIndex].Cells["RegionsStateLastCheck"].Value = DateTime |
||
- | 1665 | .Now.ToUniversalTime() |
||
- | 1666 | .ToString(Vassal.LINDEN_CONSTANTS.LSL.DATE_TIME_STAMP); |
||
- | 1667 | |
||
- | 1668 | })); |
||
- | 1669 | } |
||
- | 1670 | catch (Exception) |
||
- | 1671 | { |
||
- | 1672 | |
||
- | 1673 | } |
||
- | 1674 | finally |
||
1383 | try |
1675 | { |
|
1384 | { |
1676 | Monitor.Exit(RegionsStateCheckLock); |
|
1385 | // Do not do anything in case the tab is not selected. |
1677 | ++regionsStateCheckIndex; |
|
- | 1678 | vassalForm.Invoke((MethodInvoker) (() => |
||
1386 | vassalForm.Invoke((MethodInvoker) (() => |
1679 | { |
|
- | 1680 | if (regionsStateCheckIndex >= RegionsStateGridView.Rows.Count) |
||
1387 | { |
1681 | { |
|
- | 1682 | regionsStateCheckIndex = 0; |
||
- | 1683 | } |
||
- | 1684 | })); |
||
- | 1685 | } |
||
- | 1686 | }; |
||
- | 1687 | regionsStateTabTimer.Start(); |
||
- | 1688 | |
||
- | 1689 | // Start the top scores timer. |
||
- | 1690 | topScriptsTabTimer.Elapsed += (o, p) => |
||
- | 1691 | { |
||
- | 1692 | // Do not do anything in case the tab is not selected. |
||
- | 1693 | bool run = false; |
||
- | 1694 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 1695 | { |
||
- | 1696 | run = Tabs.SelectedTab.Equals(TopScriptsTab); |
||
- | 1697 | })); |
||
- | 1698 | if (!run) return; |
||
Line -... | Line 1699... | |||
- | 1699 | |
||
- | 1700 | if (!Monitor.TryEnter(ClientInstanceTeleportLock)) |
||
1388 | if (!Tabs.SelectedTab.Equals(TopScriptsTab)) |
1701 | return; |
|
1389 | throw new Exception(); |
1702 | |
|
1390 | })); |
1703 | try |
|
1391 | |
1704 | { |
|
1392 | // Get the statistics. |
1705 | // Get the statistics. |
|
Line 1461... | Line 1774... | |||
1461 | topScriptsTabTimer.Start(); |
1774 | topScriptsTabTimer.Start(); |
|
Line 1462... | Line 1775... | |||
1462 | |
1775 | |
|
1463 | // Start the top colliders timer. |
1776 | // Start the top colliders timer. |
|
1464 | topCollidersTabTimer.Elapsed += (o, p) => |
1777 | topCollidersTabTimer.Elapsed += (o, p) => |
|
- | 1778 | { |
||
- | 1779 | // Do not do anything in case the tab is not selected. |
||
- | 1780 | bool run = false; |
||
- | 1781 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 1782 | { |
||
- | 1783 | run = Tabs.SelectedTab.Equals(TopCollidersTab); |
||
- | 1784 | })); |
||
- | 1785 | if (!run) return; |
||
1465 | { |
1786 | |
|
1466 | if (!Monitor.TryEnter(ClientInstanceTeleportLock)) |
1787 | if (!Monitor.TryEnter(ClientInstanceTeleportLock)) |
|
Line 1467... | Line 1788... | |||
1467 | return; |
1788 | return; |
|
1468 | |
1789 | |
|
1469 | try |
- | ||
1470 | { |
- | ||
1471 | // Do not do anything in case the tab is not selected. |
- | ||
1472 | vassalForm.Invoke((MethodInvoker) (() => |
- | ||
1473 | { |
- | ||
1474 | if (!Tabs.SelectedTab.Equals(TopCollidersTab)) |
- | ||
1475 | throw new Exception(); |
- | ||
1476 | })); |
1790 | try |
|
1477 | |
1791 | { |
|
1478 | // Get the statistics. |
1792 | // Get the statistics. |
|
1479 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
1793 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
1480 | wasKeyValueEscape(new Dictionary<string, string> |
1794 | wasKeyValueEscape(new Dictionary<string, string> |
|
Line 1526... | Line 1840... | |||
1526 | row.Cells["TopCollidersUUID"].Value = dataComponents[2]; |
1840 | row.Cells["TopCollidersUUID"].Value = dataComponents[2]; |
|
1527 | row.Cells["TopCollidersOwner"].Value = dataComponents[3]; |
1841 | row.Cells["TopCollidersOwner"].Value = dataComponents[3]; |
|
1528 | row.Cells["TopCollidersPosition"].Value = dataComponents[4]; |
1842 | row.Cells["TopCollidersPosition"].Value = dataComponents[4]; |
|
1529 | break; |
1843 | break; |
|
1530 | case false: // the row dosn't exist, so add it. |
1844 | case false: // the row dosn't exist, so add it. |
|
1531 | TopCollidersGridView.Rows.Add(dataComponents[0], dataComponents[1], dataComponents[2], |
1845 | TopCollidersGridView.Rows.Add(dataComponents[0], dataComponents[1], |
|
- | 1846 | dataComponents[2], |
||
1532 | dataComponents[3], dataComponents[4]); |
1847 | dataComponents[3], dataComponents[4]); |
|
1533 | break; |
1848 | break; |
|
1534 | } |
1849 | } |
|
1535 | } |
1850 | } |
|
Line 1544... | Line 1859... | |||
1544 | { |
1859 | { |
|
1545 | Monitor.Exit(ClientInstanceTeleportLock); |
1860 | Monitor.Exit(ClientInstanceTeleportLock); |
|
1546 | } |
1861 | } |
|
1547 | }; |
1862 | }; |
|
1548 | topCollidersTabTimer.Start(); |
1863 | topCollidersTabTimer.Start(); |
|
- | 1864 | |
||
- | 1865 | // Start the resident list timer. |
||
- | 1866 | residentListTimer.Elapsed += (o, p) => |
||
- | 1867 | { |
||
- | 1868 | // Do not do anything in case the tab is not selected. |
||
- | 1869 | bool run = false; |
||
- | 1870 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 1871 | { |
||
- | 1872 | run = Tabs.SelectedTab.Equals(ResidentListTab); |
||
- | 1873 | })); |
||
- | 1874 | if (!run) return; |
||
- | 1875 | |
||
- | 1876 | if (!Monitor.TryEnter(ClientInstanceTeleportLock)) |
||
- | 1877 | return; |
||
- | 1878 | |
||
- | 1879 | try |
||
- | 1880 | { |
||
- | 1881 | // Get the avatar positions. |
||
- | 1882 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
||
- | 1883 | wasKeyValueEscape(new Dictionary<string, string> |
||
- | 1884 | { |
||
- | 1885 | {"command", "getavatarpositions"}, |
||
- | 1886 | {"group", vassalConfiguration.Group}, |
||
- | 1887 | {"password", vassalConfiguration.Password}, |
||
- | 1888 | {"entity", "region"} |
||
- | 1889 | }), vassalConfiguration.DataTimeout); |
||
- | 1890 | |
||
- | 1891 | bool success; |
||
- | 1892 | if (string.IsNullOrEmpty(result) || |
||
- | 1893 | !bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
||
- | 1894 | throw new Exception(); |
||
- | 1895 | |
||
- | 1896 | HashSet<List<string>> data = |
||
- | 1897 | new HashSet<List<string>>(wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))) |
||
- | 1898 | .Select((x, i) => new {Index = i, Value = x}) |
||
- | 1899 | .GroupBy(x => x.Index/3) |
||
- | 1900 | .Select(x => x.Select(v => v.Value).ToList())); |
||
- | 1901 | if (data.Count.Equals(0)) |
||
- | 1902 | throw new Exception(); |
||
- | 1903 | |
||
- | 1904 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 1905 | { |
||
- | 1906 | // Remove rows that are not in the data update. |
||
- | 1907 | foreach ( |
||
- | 1908 | int index in |
||
- | 1909 | ResidentListGridView.Rows.AsParallel().Cast<DataGridViewRow>() |
||
- | 1910 | .Where( |
||
- | 1911 | residentListRow => |
||
- | 1912 | !data.Any(q => q[1].Equals(residentListRow.Cells["ResidentListUUID"].Value))) |
||
- | 1913 | .Select(q => q.Index)) |
||
- | 1914 | { |
||
- | 1915 | ResidentListGridView.Rows.RemoveAt(index); |
||
- | 1916 | } |
||
- | 1917 | // Now update or add new data. |
||
- | 1918 | foreach (List<string> dataComponents in data.Where(q => q.Count.Equals(3))) |
||
- | 1919 | { |
||
- | 1920 | DataGridViewRow row = |
||
- | 1921 | ResidentListGridView.Rows.AsParallel() |
||
- | 1922 | .Cast<DataGridViewRow>() |
||
- | 1923 | .FirstOrDefault(q => q.Cells["ResidentListUUID"].Value.Equals(dataComponents[1])); |
||
- | 1924 | switch (row != null) |
||
- | 1925 | { |
||
- | 1926 | case true: // the row exists, so update it. |
||
- | 1927 | row.Cells["ResidentListName"].Value = dataComponents[0]; |
||
- | 1928 | row.Cells["ResidentListUUID"].Value = dataComponents[1]; |
||
- | 1929 | row.Cells["ResidentListPosition"].Value = dataComponents[2]; |
||
- | 1930 | break; |
||
- | 1931 | case false: // the row dosn't exist, so add it. |
||
- | 1932 | ResidentListGridView.Rows.Add(dataComponents[0], dataComponents[1], |
||
- | 1933 | dataComponents[2]); |
||
- | 1934 | break; |
||
- | 1935 | } |
||
- | 1936 | } |
||
- | 1937 | |
||
- | 1938 | })); |
||
- | 1939 | } |
||
- | 1940 | catch (Exception) |
||
- | 1941 | { |
||
- | 1942 | |
||
- | 1943 | } |
||
- | 1944 | finally |
||
- | 1945 | { |
||
- | 1946 | Monitor.Exit(ClientInstanceTeleportLock); |
||
- | 1947 | } |
||
- | 1948 | }; |
||
- | 1949 | residentListTimer.Start(); |
||
1549 | } |
1950 | } |
|
Line 1550... | Line 1951... | |||
1550 | |
1951 | |
|
1551 | private void RequestedEditRegions(object sender, EventArgs e) |
1952 | private void RequestedEditRegions(object sender, EventArgs e) |
|
1552 | { |
1953 | { |
|
Line 1600... | Line 2001... | |||
1600 | { |
2001 | { |
|
1601 | vassalForm.StatusText.Text = ex.Message; |
2002 | vassalForm.StatusText.Text = ex.Message; |
|
1602 | } |
2003 | } |
|
1603 | })); |
2004 | })); |
|
1604 | }) |
2005 | }) |
|
1605 | {IsBackground = true, Priority = ThreadPriority.Normal}.Start(); |
2006 | {IsBackground = true}.Start(); |
|
1606 | break; |
2007 | break; |
|
1607 | } |
2008 | } |
|
1608 | })); |
2009 | })); |
|
1609 | } |
2010 | } |
|
Line 1647... | Line 2048... | |||
1647 | { |
2048 | { |
|
1648 | vassalForm.StatusText.Text = ex.Message; |
2049 | vassalForm.StatusText.Text = ex.Message; |
|
1649 | } |
2050 | } |
|
1650 | })); |
2051 | })); |
|
1651 | }) |
2052 | }) |
|
1652 | {IsBackground = true, Priority = ThreadPriority.Normal}.Start(); |
2053 | {IsBackground = true}.Start(); |
|
1653 | break; |
2054 | break; |
|
1654 | } |
2055 | } |
|
1655 | })); |
2056 | })); |
|
1656 | } |
2057 | } |
|
Line 1683... | Line 2084... | |||
1683 | })); |
2084 | })); |
|
1684 | } |
2085 | } |
|
Line 1685... | Line 2086... | |||
1685 | |
2086 | |
|
1686 | private void RequestFilterTopColliders(object sender, EventArgs e) |
2087 | private void RequestFilterTopColliders(object sender, EventArgs e) |
|
1687 | { |
2088 | { |
|
1688 | vassalForm.BeginInvoke((MethodInvoker)(() => |
2089 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
1689 | { |
2090 | { |
|
1690 | Regex topCollidersRowRegex; |
2091 | Regex topCollidersRowRegex; |
|
1691 | switch (!string.IsNullOrEmpty(TopScriptsFilter.Text)) |
2092 | switch (!string.IsNullOrEmpty(TopScriptsFilter.Text)) |
|
1692 | { |
2093 | { |
|
Line 1695... | Line 2096... | |||
1695 | break; |
2096 | break; |
|
1696 | default: |
2097 | default: |
|
1697 | topCollidersRowRegex = new Regex(@".+?", RegexOptions.Compiled); |
2098 | topCollidersRowRegex = new Regex(@".+?", RegexOptions.Compiled); |
|
1698 | break; |
2099 | break; |
|
1699 | } |
2100 | } |
|
- | 2101 | foreach ( |
||
1700 | foreach (DataGridViewRow topCollidersRow in TopCollidersGridView.Rows.AsParallel().Cast<DataGridViewRow>()) |
2102 | DataGridViewRow topCollidersRow in TopCollidersGridView.Rows.AsParallel().Cast<DataGridViewRow>()) |
|
1701 | { |
2103 | { |
|
1702 | topCollidersRow.Visible = |
2104 | topCollidersRow.Visible = |
|
1703 | topCollidersRowRegex.IsMatch(topCollidersRow.Cells["TopCollidersScore"].Value.ToString()) || |
2105 | topCollidersRowRegex.IsMatch(topCollidersRow.Cells["TopCollidersScore"].Value.ToString()) || |
|
1704 | topCollidersRowRegex.IsMatch( |
2106 | topCollidersRowRegex.IsMatch( |
|
1705 | topCollidersRow.Cells["TopCollidersTaskName"].Value.ToString()) || |
2107 | topCollidersRow.Cells["TopCollidersTaskName"].Value.ToString()) || |
|
Line 1740... | Line 2142... | |||
1740 | })); |
2142 | })); |
|
Line 1741... | Line 2143... | |||
1741 | |
2143 | |
|
1742 | // If no rows were selected, enable teleports, the return button and return. |
2144 | // If no rows were selected, enable teleports, the return button and return. |
|
1743 | if (returnUUIDs.Count.Equals(0)) |
2145 | if (returnUUIDs.Count.Equals(0)) |
|
1744 | { |
2146 | { |
|
1745 | vassalForm.Invoke((MethodInvoker)(() => |
2147 | vassalForm.Invoke((MethodInvoker) (() => |
|
1746 | { |
2148 | { |
|
1747 | vassalForm.ReturnTopScriptsButton.Enabled = true; |
2149 | vassalForm.ReturnTopScriptsButton.Enabled = true; |
|
1748 | RegionTeleportGroup.Enabled = true; |
2150 | RegionTeleportGroup.Enabled = true; |
|
1749 | })); |
2151 | })); |
|
Line 1774... | Line 2176... | |||
1774 | string currentRegionName = string.Empty; |
2176 | string currentRegionName = string.Empty; |
|
1775 | vassalForm.Invoke((MethodInvoker) (() => |
2177 | vassalForm.Invoke((MethodInvoker) (() => |
|
1776 | { |
2178 | { |
|
1777 | currentRegionName = CurrentRegionName.Text; |
2179 | currentRegionName = CurrentRegionName.Text; |
|
1778 | })); |
2180 | })); |
|
1779 | |
2181 | |
|
1780 | // Teleport to the object. |
2182 | // Teleport to the object. |
|
1781 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
2183 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
|
1782 | wasKeyValueEscape(new Dictionary<string, string> |
2184 | wasKeyValueEscape(new Dictionary<string, string> |
|
1783 | { |
2185 | { |
|
1784 | {"command", "teleport"}, |
2186 | {"command", "teleport"}, |
|
Line 1789... | Line 2191... | |||
1789 | {"fly", "True"} |
2191 | {"fly", "True"} |
|
1790 | }), vassalConfiguration.TeleportTimeout); |
2192 | }), vassalConfiguration.TeleportTimeout); |
|
Line 1791... | Line 2193... | |||
1791 | |
2193 | |
|
1792 | if (string.IsNullOrEmpty(result)) |
2194 | if (string.IsNullOrEmpty(result)) |
|
1793 | { |
2195 | { |
|
1794 | vassalForm.Invoke((MethodInvoker)(() => |
2196 | vassalForm.Invoke((MethodInvoker) (() => |
|
1795 | { |
2197 | { |
|
1796 | vassalForm.StatusText.Text = @"Error communicating with Corrade."; |
2198 | vassalForm.StatusText.Text = @"Error communicating with Corrade."; |
|
1797 | })); |
2199 | })); |
|
1798 | continue; |
2200 | continue; |
|
Line 1804... | Line 2206... | |||
1804 | { |
2206 | { |
|
1805 | {"command", "derez"}, |
2207 | {"command", "derez"}, |
|
1806 | {"group", vassalConfiguration.Group}, |
2208 | {"group", vassalConfiguration.Group}, |
|
1807 | {"password", vassalConfiguration.Password}, |
2209 | {"password", vassalConfiguration.Password}, |
|
1808 | {"item", objectData.Key.ToString()}, |
2210 | {"item", objectData.Key.ToString()}, |
|
1809 | {"range", "32" }, // maximal prim size = 64 - middle bounding box at half |
2211 | {"range", "32"}, // maximal prim size = 64 - middle bounding box at half |
|
1810 | {"type", "ReturnToOwner"} |
2212 | {"type", "ReturnToOwner"} |
|
1811 | }), vassalConfiguration.DataTimeout); |
2213 | }), vassalConfiguration.DataTimeout); |
|
Line 1812... | Line 2214... | |||
1812 | |
2214 | |
|
1813 | if (string.IsNullOrEmpty(result)) |
2215 | if (string.IsNullOrEmpty(result)) |
|
Line 1834... | Line 2236... | |||
1834 | case true: |
2236 | case true: |
|
1835 | vassalForm.Invoke((MethodInvoker) (() => |
2237 | vassalForm.Invoke((MethodInvoker) (() => |
|
1836 | { |
2238 | { |
|
1837 | vassalForm.StatusText.Text = @"Returned object: " + objectData.Key.ToString(); |
2239 | vassalForm.StatusText.Text = @"Returned object: " + objectData.Key.ToString(); |
|
1838 | // Remove the row from the grid view. |
2240 | // Remove the row from the grid view. |
|
1839 | DataGridViewRow row = |
2241 | DataGridViewRow row = |
|
1840 | TopScriptsGridView.Rows.AsParallel() |
2242 | TopScriptsGridView.Rows.AsParallel() |
|
1841 | .Cast<DataGridViewRow>() |
2243 | .Cast<DataGridViewRow>() |
|
1842 | .FirstOrDefault( |
2244 | .FirstOrDefault( |
|
1843 | o => o.Cells["TopScriptsUUID"].Value.Equals(objectData.Key.ToString())); |
2245 | o => o.Cells["TopScriptsUUID"].Value.Equals(objectData.Key.ToString())); |
|
1844 | if (row == null) return; |
2246 | if (row == null) return; |
|
1845 | int i = row.Index; |
2247 | int i = row.Index; |
|
1846 | TopScriptsGridView.Rows.RemoveAt(i); |
2248 | TopScriptsGridView.Rows.RemoveAt(i); |
|
1847 | })); |
2249 | })); |
|
1848 | break; |
2250 | break; |
|
Line 1868... | Line 2270... | |||
1868 | vassalForm.StatusProgress.Value = 100; |
2270 | vassalForm.StatusProgress.Value = 100; |
|
1869 | })); |
2271 | })); |
|
1870 | } |
2272 | } |
|
1871 | catch (Exception ex) |
2273 | catch (Exception ex) |
|
1872 | { |
2274 | { |
|
1873 | vassalForm.Invoke((MethodInvoker)(() => |
2275 | vassalForm.Invoke((MethodInvoker) (() => |
|
1874 | { |
2276 | { |
|
1875 | vassalForm.StatusText.Text = @"Unexpected error: " + ex.Message; |
2277 | vassalForm.StatusText.Text = @"Unexpected error: " + ex.Message; |
|
1876 | })); |
2278 | })); |
|
1877 | } |
2279 | } |
|
1878 | finally |
2280 | finally |
|
1879 | { |
2281 | { |
|
1880 | Monitor.Exit(ClientInstanceTeleportLock); |
2282 | Monitor.Exit(ClientInstanceTeleportLock); |
|
1881 | // Allow teleports and enable button. |
2283 | // Allow teleports and enable button. |
|
1882 | vassalForm.BeginInvoke((MethodInvoker)(() => |
2284 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
1883 | { |
2285 | { |
|
1884 | vassalForm.ReturnTopScriptsButton.Enabled = true; |
2286 | vassalForm.ReturnTopScriptsButton.Enabled = true; |
|
1885 | RegionTeleportGroup.Enabled = true; |
2287 | RegionTeleportGroup.Enabled = true; |
|
1886 | })); |
2288 | })); |
|
1887 | } |
2289 | } |
|
Line 1890... | Line 2292... | |||
1890 | } |
2292 | } |
|
Line 1891... | Line 2293... | |||
1891 | |
2293 | |
|
1892 | private void RequestReturnTopCollidersObjects(object sender, EventArgs e) |
2294 | private void RequestReturnTopCollidersObjects(object sender, EventArgs e) |
|
1893 | { |
2295 | { |
|
1894 | // Block teleports and disable button. |
2296 | // Block teleports and disable button. |
|
1895 | vassalForm.Invoke((MethodInvoker)(() => |
2297 | vassalForm.Invoke((MethodInvoker) (() => |
|
1896 | { |
2298 | { |
|
1897 | vassalForm.ReturnTopCollidersButton.Enabled = false; |
2299 | vassalForm.ReturnTopCollidersButton.Enabled = false; |
|
1898 | RegionTeleportGroup.Enabled = false; |
2300 | RegionTeleportGroup.Enabled = false; |
|
Line 1899... | Line 2301... | |||
1899 | })); |
2301 | })); |
|
1900 | |
2302 | |
|
1901 | // Enqueue all the UUIDs to return. |
2303 | // Enqueue all the UUIDs to return. |
|
1902 | Queue<KeyValuePair<UUID, Vector3>> returnUUIDs = new Queue<KeyValuePair<UUID, Vector3>>(); |
2304 | Queue<KeyValuePair<UUID, Vector3>> returnObjectUUIDQueue = new Queue<KeyValuePair<UUID, Vector3>>(); |
|
1903 | vassalForm.Invoke((MethodInvoker)(() => |
2305 | vassalForm.Invoke((MethodInvoker) (() => |
|
1904 | { |
2306 | { |
|
1905 | foreach ( |
2307 | foreach ( |
|
1906 | DataGridViewRow topCollidersRow in |
2308 | DataGridViewRow topCollidersRow in |
|
1907 | TopCollidersGridView.Rows.AsParallel() |
2309 | TopCollidersGridView.Rows.AsParallel() |
|
1908 | .Cast<DataGridViewRow>() |
2310 | .Cast<DataGridViewRow>() |
|
1909 | .Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
2311 | .Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
|
1910 | { |
2312 | { |
|
1911 | Vector3 objectPosition; |
2313 | Vector3 objectPosition; |
|
1912 | UUID returnUUID; |
2314 | UUID returnUUID; |
|
- | 2315 | if (!UUID.TryParse(topCollidersRow.Cells["TopCollidersUUID"].Value.ToString(), out returnUUID) || |
||
1913 | if (!UUID.TryParse(topCollidersRow.Cells["TopCollidersUUID"].Value.ToString(), out returnUUID) || |
2316 | !Vector3.TryParse(topCollidersRow.Cells["TopCollidersPosition"].Value.ToString(), |
|
1914 | !Vector3.TryParse(topCollidersRow.Cells["TopCollidersPosition"].Value.ToString(), out objectPosition)) |
2317 | out objectPosition)) |
|
1915 | continue; |
2318 | continue; |
|
1916 | returnUUIDs.Enqueue(new KeyValuePair<UUID, Vector3>(returnUUID, objectPosition)); |
2319 | returnObjectUUIDQueue.Enqueue(new KeyValuePair<UUID, Vector3>(returnUUID, objectPosition)); |
|
Line 1917... | Line 2320... | |||
1917 | } |
2320 | } |
|
1918 | })); |
2321 | })); |
|
1919 | |
2322 | |
|
1920 | // If no rows were selected, enable teleports, the return button and return. |
2323 | // If no rows were selected, enable teleports, the return button and return. |
|
1921 | if (returnUUIDs.Count.Equals(0)) |
2324 | if (returnObjectUUIDQueue.Count.Equals(0)) |
|
1922 | { |
2325 | { |
|
1923 | vassalForm.Invoke((MethodInvoker)(() => |
2326 | vassalForm.Invoke((MethodInvoker) (() => |
|
1924 | { |
2327 | { |
|
1925 | vassalForm.ReturnTopCollidersButton.Enabled = true; |
2328 | vassalForm.ReturnTopCollidersButton.Enabled = true; |
|
Line 1932... | Line 2335... | |||
1932 | { |
2335 | { |
|
1933 | Monitor.Enter(ClientInstanceTeleportLock); |
2336 | Monitor.Enter(ClientInstanceTeleportLock); |
|
Line 1934... | Line 2337... | |||
1934 | |
2337 | |
|
1935 | try |
2338 | try |
|
1936 | { |
2339 | { |
|
1937 | vassalForm.Invoke((MethodInvoker)(() => |
2340 | vassalForm.Invoke((MethodInvoker) (() => |
|
1938 | { |
2341 | { |
|
1939 | vassalForm.StatusProgress.Value = 0; |
2342 | vassalForm.StatusProgress.Value = 0; |
|
1940 | })); |
2343 | })); |
|
1941 | int totalObjects = returnUUIDs.Count; |
2344 | int totalObjects = returnObjectUUIDQueue.Count; |
|
1942 | do |
2345 | do |
|
1943 | { |
2346 | { |
|
1944 | // Dequeue the first object. |
2347 | // Dequeue the first object. |
|
Line 1945... | Line 2348... | |||
1945 | KeyValuePair<UUID, Vector3> objectData = returnUUIDs.Dequeue(); |
2348 | KeyValuePair<UUID, Vector3> objectData = returnObjectUUIDQueue.Dequeue(); |
|
1946 | |
2349 | |
|
1947 | vassalForm.Invoke((MethodInvoker)(() => |
2350 | vassalForm.Invoke((MethodInvoker) (() => |
|
1948 | { |
2351 | { |
|
Line 1949... | Line 2352... | |||
1949 | vassalForm.StatusText.Text = @"Returning UUID: " + objectData.Key.ToString(); |
2352 | vassalForm.StatusText.Text = @"Returning UUID: " + objectData.Key.ToString(); |
|
1950 | })); |
2353 | })); |
|
1951 | |
2354 | |
|
1952 | string currentRegionName = string.Empty; |
2355 | string currentRegionName = string.Empty; |
|
1953 | vassalForm.Invoke((MethodInvoker)(() => |
2356 | vassalForm.Invoke((MethodInvoker) (() => |
|
Line 1954... | Line 2357... | |||
1954 | { |
2357 | { |
|
Line 1967... | Line 2370... | |||
1967 | {"fly", "True"} |
2370 | {"fly", "True"} |
|
1968 | }), vassalConfiguration.DataTimeout); |
2371 | }), vassalConfiguration.DataTimeout); |
|
Line 1969... | Line 2372... | |||
1969 | |
2372 | |
|
1970 | if (string.IsNullOrEmpty(result)) |
2373 | if (string.IsNullOrEmpty(result)) |
|
1971 | { |
2374 | { |
|
1972 | vassalForm.Invoke((MethodInvoker)(() => |
2375 | vassalForm.Invoke((MethodInvoker) (() => |
|
1973 | { |
2376 | { |
|
1974 | vassalForm.StatusText.Text = @"Error communicating with Corrade."; |
2377 | vassalForm.StatusText.Text = @"Error communicating with Corrade."; |
|
1975 | })); |
2378 | })); |
|
1976 | continue; |
2379 | continue; |
|
Line 1982... | Line 2385... | |||
1982 | { |
2385 | { |
|
1983 | {"command", "derez"}, |
2386 | {"command", "derez"}, |
|
1984 | {"group", vassalConfiguration.Group}, |
2387 | {"group", vassalConfiguration.Group}, |
|
1985 | {"password", vassalConfiguration.Password}, |
2388 | {"password", vassalConfiguration.Password}, |
|
1986 | {"item", objectData.Key.ToString()}, |
2389 | {"item", objectData.Key.ToString()}, |
|
1987 | {"range", "32" }, // maximal prim size = 64 - middle bounding box at half |
2390 | {"range", "32"}, // maximal prim size = 64 - middle bounding box at half |
|
1988 | {"type", "ReturnToOwner"} |
2391 | {"type", "ReturnToOwner"} |
|
1989 | }), vassalConfiguration.DataTimeout); |
2392 | }), vassalConfiguration.DataTimeout); |
|
Line 1990... | Line 2393... | |||
1990 | |
2393 | |
|
1991 | if (string.IsNullOrEmpty(result)) |
2394 | if (string.IsNullOrEmpty(result)) |
|
1992 | { |
2395 | { |
|
1993 | vassalForm.Invoke((MethodInvoker)(() => |
2396 | vassalForm.Invoke((MethodInvoker) (() => |
|
1994 | { |
2397 | { |
|
1995 | vassalForm.StatusText.Text = @"Error communicating with Corrade."; |
2398 | vassalForm.StatusText.Text = @"Error communicating with Corrade."; |
|
1996 | })); |
2399 | })); |
|
1997 | continue; |
2400 | continue; |
|
Line 1998... | Line 2401... | |||
1998 | } |
2401 | } |
|
1999 | |
2402 | |
|
2000 | bool success; |
2403 | bool success; |
|
2001 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
2404 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
|
2002 | { |
2405 | { |
|
2003 | vassalForm.Invoke((MethodInvoker)(() => |
2406 | vassalForm.Invoke((MethodInvoker) (() => |
|
2004 | { |
2407 | { |
|
2005 | vassalForm.StatusText.Text = @"No success status could be retrieved. "; |
2408 | vassalForm.StatusText.Text = @"No success status could be retrieved. "; |
|
2006 | })); |
2409 | })); |
|
Line 2007... | Line 2410... | |||
2007 | continue; |
2410 | continue; |
|
2008 | } |
2411 | } |
|
2009 | |
2412 | |
|
2010 | switch (success) |
2413 | switch (success) |
|
2011 | { |
2414 | { |
|
2012 | case true: |
2415 | case true: |
|
2013 | vassalForm.Invoke((MethodInvoker)(() => |
2416 | vassalForm.Invoke((MethodInvoker) (() => |
|
2014 | { |
2417 | { |
|
2015 | vassalForm.StatusText.Text = @"Returned object: " + objectData.Key.ToString(); |
2418 | vassalForm.StatusText.Text = @"Returned object: " + objectData.Key.ToString(); |
|
2016 | // Remove the row from the grid view. |
2419 | // Remove the row from the grid view. |
|
2017 | DataGridViewRow row = |
2420 | DataGridViewRow row = |
|
2018 | TopCollidersGridView.Rows.AsParallel() |
2421 | TopCollidersGridView.Rows.AsParallel() |
|
2019 | .Cast<DataGridViewRow>() |
2422 | .Cast<DataGridViewRow>() |
|
2020 | .FirstOrDefault( |
2423 | .FirstOrDefault( |
|
2021 | o => o.Cells["TopCollidersUUID"].Value.Equals(objectData.Key.ToString())); |
2424 | o => o.Cells["TopCollidersUUID"].Value.Equals(objectData.Key.ToString())); |
|
2022 | if (row == null) return; |
2425 | if (row == null) return; |
|
2023 | int i = row.Index; |
2426 | int i = row.Index; |
|
2024 | TopCollidersGridView.Rows.RemoveAt(i); |
2427 | TopCollidersGridView.Rows.RemoveAt(i); |
|
2025 | })); |
2428 | })); |
|
2026 | break; |
2429 | break; |
|
2027 | case false: |
2430 | case false: |
|
2028 | vassalForm.Invoke((MethodInvoker)(() => |
2431 | vassalForm.Invoke((MethodInvoker) (() => |
|
2029 | { |
2432 | { |
|
2030 | vassalForm.StatusText.Text = @"Could not return object " + objectData.Key.ToString() + |
2433 | vassalForm.StatusText.Text = @"Could not return object " + objectData.Key.ToString() + |
|
2031 | @": " + |
2434 | @": " + |
|
2032 | wasInput(wasKeyValueGet("error", result)); |
2435 | wasInput(wasKeyValueGet("error", result)); |
|
Line 2033... | Line 2436... | |||
2033 | })); |
2436 | })); |
|
2034 | break; |
2437 | break; |
|
2035 | } |
2438 | } |
|
2036 | |
2439 | |
|
2037 | vassalForm.Invoke((MethodInvoker)(() => |
2440 | vassalForm.Invoke((MethodInvoker) (() => |
|
2038 | { |
2441 | { |
|
2039 | vassalForm.StatusProgress.Value = |
2442 | vassalForm.StatusProgress.Value = |
|
2040 | Math.Min((int)(Math.Abs(returnUUIDs.Count - totalObjects) / |
2443 | Math.Min((int) (Math.Abs(returnObjectUUIDQueue.Count - totalObjects)/ |
|
2041 | (double)totalObjects), 100); |
2444 | (double) totalObjects), 100); |
|
2042 | })); |
2445 | })); |
|
2043 | } while (!returnUUIDs.Count.Equals(0)); |
2446 | } while (!returnObjectUUIDQueue.Count.Equals(0)); |
|
2044 | vassalForm.Invoke((MethodInvoker)(() => |
2447 | vassalForm.Invoke((MethodInvoker) (() => |
|
2045 | { |
2448 | { |
|
2046 | vassalForm.StatusProgress.Value = 100; |
2449 | vassalForm.StatusProgress.Value = 100; |
|
2047 | })); |
2450 | })); |
|
2048 | } |
2451 | } |
|
2049 | catch (Exception ex) |
2452 | catch (Exception ex) |
|
2050 | { |
2453 | { |
|
2051 | vassalForm.Invoke((MethodInvoker)(() => |
2454 | vassalForm.Invoke((MethodInvoker) (() => |
|
2052 | { |
2455 | { |
|
2053 | vassalForm.StatusText.Text = @"Unexpected error: " + ex.Message; |
2456 | vassalForm.StatusText.Text = @"Unexpected error: " + ex.Message; |
|
2054 | })); |
2457 | })); |
|
2055 | } |
2458 | } |
|
2056 | finally |
2459 | finally |
|
2057 | { |
2460 | { |
|
2058 | Monitor.Exit(ClientInstanceTeleportLock); |
2461 | Monitor.Exit(ClientInstanceTeleportLock); |
|
2059 | // Allow teleports and enable button. |
2462 | // Allow teleports and enable button. |
|
2060 | vassalForm.BeginInvoke((MethodInvoker)(() => |
2463 | vassalForm.BeginInvoke((MethodInvoker) (() => |
|
2061 | { |
2464 | { |
|
2062 | vassalForm.ReturnTopScriptsButton.Enabled = true; |
2465 | vassalForm.ReturnTopScriptsButton.Enabled = true; |
|
2063 | RegionTeleportGroup.Enabled = true; |
2466 | RegionTeleportGroup.Enabled = true; |
|
2064 | })); |
2467 | })); |
|
Line 2065... | Line 2468... | |||
2065 | } |
2468 | } |
|
2066 | }) |
2469 | }) |
|
- | 2470 | {IsBackground = true}.Start(); |
||
- | 2471 | } |
||
- | 2472 | |
||
- | 2473 | private void RequestBatchRestart(object sender, EventArgs e) |
||
- | 2474 | { |
||
- | 2475 | // Block teleports and disable button. |
||
- | 2476 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 2477 | { |
||
- | 2478 | vassalForm.BatchRestartButton.Enabled = false; |
||
- | 2479 | RegionTeleportGroup.Enabled = false; |
||
- | 2480 | })); |
||
- | 2481 | |
||
- | 2482 | // Enqueue all the regions to restart. |
||
- | 2483 | Queue<KeyValuePair<string, Vector3>> restartRegionQueue = new Queue<KeyValuePair<string, Vector3>>(); |
||
- | 2484 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 2485 | { |
||
- | 2486 | foreach ( |
||
- | 2487 | DataGridViewRow topCollidersRow in |
||
- | 2488 | BatchRestartGridView.Rows.AsParallel() |
||
- | 2489 | .Cast<DataGridViewRow>() |
||
- | 2490 | .Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
||
- | 2491 | { |
||
- | 2492 | Vector3 objectPosition; |
||
- | 2493 | string regionName = topCollidersRow.Cells["BatchRestartRegionName"].Value.ToString(); |
||
- | 2494 | if (string.IsNullOrEmpty(regionName) || |
||
- | 2495 | !Vector3.TryParse(topCollidersRow.Cells["BatchRestartPosition"].Value.ToString(), |
||
- | 2496 | out objectPosition)) |
||
- | 2497 | continue; |
||
- | 2498 | restartRegionQueue.Enqueue(new KeyValuePair<string, Vector3>(regionName, objectPosition)); |
||
- | 2499 | } |
||
- | 2500 | })); |
||
- | 2501 | |
||
- | 2502 | // If no rows were selected, enable teleports, the return button and return. |
||
- | 2503 | if (restartRegionQueue.Count.Equals(0)) |
||
- | 2504 | { |
||
- | 2505 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 2506 | { |
||
- | 2507 | vassalForm.BatchRestartButton.Enabled = true; |
||
- | 2508 | RegionTeleportGroup.Enabled = true; |
||
- | 2509 | })); |
||
- | 2510 | return; |
||
- | 2511 | } |
||
- | 2512 | |
||
- | 2513 | new Thread(() => |
||
- | 2514 | { |
||
- | 2515 | Monitor.Enter(ClientInstanceTeleportLock); |
||
- | 2516 | |
||
- | 2517 | try |
||
- | 2518 | { |
||
- | 2519 | do |
||
- | 2520 | { |
||
- | 2521 | // Dequeue the first object. |
||
- | 2522 | KeyValuePair<string, Vector3> restartRegionData = restartRegionQueue.Dequeue(); |
||
- | 2523 | DataGridViewRow currentDataGridViewRow = null; |
||
- | 2524 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 2525 | { |
||
- | 2526 | currentDataGridViewRow = vassalForm.BatchRestartGridView.Rows.AsParallel() |
||
- | 2527 | .Cast<DataGridViewRow>() |
||
- | 2528 | .FirstOrDefault( |
||
- | 2529 | o => |
||
- | 2530 | o.Cells["BatchRestartRegionName"].Value.ToString() |
||
- | 2531 | .Equals(restartRegionData.Key, StringComparison.OrdinalIgnoreCase) && |
||
- | 2532 | o.Cells["BatchRestartPosition"].Value.ToString() |
||
- | 2533 | .Equals(restartRegionData.Value.ToString(), |
||
- | 2534 | StringComparison.OrdinalIgnoreCase)); |
||
- | 2535 | })); |
||
- | 2536 | |
||
- | 2537 | if (currentDataGridViewRow == null) continue; |
||
- | 2538 | |
||
- | 2539 | try |
||
- | 2540 | { |
||
- | 2541 | bool success = false; |
||
- | 2542 | string result; |
||
- | 2543 | |
||
- | 2544 | // Retry to teleport to each region a few times. |
||
- | 2545 | int teleportRetries = 3; |
||
- | 2546 | do |
||
- | 2547 | { |
||
- | 2548 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 2549 | { |
||
- | 2550 | vassalForm.StatusText.Text = @"Attempting to teleport to " + restartRegionData.Key + |
||
- | 2551 | @" " + @"(" + |
||
- | 2552 | teleportRetries.ToString(Utils.EnUsCulture) + |
||
- | 2553 | @")"; |
||
- | 2554 | })); |
||
- | 2555 | |
||
- | 2556 | // Teleport to the region. |
||
- | 2557 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
||
- | 2558 | wasKeyValueEscape(new Dictionary<string, string> |
||
- | 2559 | { |
||
- | 2560 | {"command", "teleport"}, |
||
- | 2561 | {"group", vassalConfiguration.Group}, |
||
- | 2562 | {"password", vassalConfiguration.Password}, |
||
- | 2563 | {"position", restartRegionData.Value.ToString()}, |
||
- | 2564 | {"region", restartRegionData.Key}, |
||
- | 2565 | {"fly", "True"} |
||
- | 2566 | }), vassalConfiguration.DataTimeout); |
||
- | 2567 | |
||
- | 2568 | if (string.IsNullOrEmpty(result)) |
||
- | 2569 | { |
||
- | 2570 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 2571 | { |
||
- | 2572 | vassalForm.StatusText.Text = @"Error communicating with Corrade."; |
||
- | 2573 | })); |
||
- | 2574 | continue; |
||
- | 2575 | } |
||
- | 2576 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
||
- | 2577 | { |
||
- | 2578 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 2579 | { |
||
- | 2580 | vassalForm.StatusText.Text = @"No success status could be retrieved. "; |
||
- | 2581 | })); |
||
- | 2582 | continue; |
||
- | 2583 | } |
||
- | 2584 | switch (success) |
||
- | 2585 | { |
||
- | 2586 | case true: |
||
- | 2587 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 2588 | { |
||
- | 2589 | vassalForm.StatusText.Text = @"Teleport succeeded."; |
||
- | 2590 | })); |
||
- | 2591 | Thread.Sleep(TimeSpan.FromSeconds(1).Milliseconds); |
||
- | 2592 | break; |
||
- | 2593 | default: |
||
- | 2594 | // In case the destination is to close (Corrade status code 37559), |
||
- | 2595 | // then we are on the same region so no need to retry. |
||
- | 2596 | uint status; //37559 |
||
- | 2597 | switch ( |
||
- | 2598 | uint.TryParse(wasInput(wasKeyValueGet("status", result)), out status) && |
||
- | 2599 | status.Equals(37559)) |
||
- | 2600 | { |
||
- | 2601 | case true: // We are on the region already! |
||
- | 2602 | success = true; |
||
- | 2603 | break; |
||
- | 2604 | default: |
||
- | 2605 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 2606 | { |
||
- | 2607 | vassalForm.StatusText.Text = @"Teleport failed."; |
||
- | 2608 | })); |
||
- | 2609 | Thread.Sleep(10000); |
||
- | 2610 | break; |
||
- | 2611 | } |
||
- | 2612 | break; |
||
- | 2613 | } |
||
- | 2614 | } while (!success && !(--teleportRetries).Equals(0)); |
||
- | 2615 | |
||
- | 2616 | if (!success) |
||
- | 2617 | throw new Exception("Failed to teleport to region."); |
||
- | 2618 | |
||
- | 2619 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
||
- | 2620 | wasKeyValueEscape(new Dictionary<string, string> |
||
- | 2621 | { |
||
- | 2622 | {"command", "getregiondata"}, |
||
- | 2623 | {"group", vassalConfiguration.Group}, |
||
- | 2624 | {"password", vassalConfiguration.Password}, |
||
- | 2625 | {"data", "IsEstateManager"} |
||
- | 2626 | }), vassalConfiguration.DataTimeout); |
||
- | 2627 | |
||
- | 2628 | if (string.IsNullOrEmpty(result)) |
||
- | 2629 | throw new Exception("Error communicating with Corrade."); |
||
- | 2630 | |
||
- | 2631 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
||
- | 2632 | throw new Exception("No success status could be retrieved."); |
||
- | 2633 | |
||
- | 2634 | if (!success) |
||
- | 2635 | throw new Exception("Could not retrieve estate rights."); |
||
- | 2636 | |
||
- | 2637 | List<string> data = wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result))).ToList(); |
||
- | 2638 | if (!data.Count.Equals(2)) |
||
- | 2639 | throw new Exception("Could not retrieve estate rights."); |
||
- | 2640 | |
||
- | 2641 | bool isEstateManager; |
||
- | 2642 | switch ( |
||
- | 2643 | bool.TryParse(data[data.IndexOf("IsEstateManager") + 1], out isEstateManager) && |
||
- | 2644 | isEstateManager) |
||
- | 2645 | { |
||
- | 2646 | case true: // we are an estate manager |
||
- | 2647 | result = wasPOST(vassalConfiguration.HTTPServerURL, |
||
- | 2648 | wasKeyValueEscape(new Dictionary<string, string> |
||
- | 2649 | { |
||
- | 2650 | {"command", "restartregion"}, |
||
- | 2651 | {"group", vassalConfiguration.Group}, |
||
- | 2652 | {"password", vassalConfiguration.Password}, |
||
- | 2653 | {"action", "restart"}, |
||
- | 2654 | { |
||
- | 2655 | "delay", vassalConfiguration.RegionRestartDelay.ToString(Utils.EnUsCulture) |
||
- | 2656 | } |
||
- | 2657 | }), vassalConfiguration.DataTimeout); |
||
- | 2658 | |
||
- | 2659 | if (string.IsNullOrEmpty(result)) |
||
- | 2660 | throw new Exception("Error communicating with Corrade."); |
||
- | 2661 | |
||
- | 2662 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
||
- | 2663 | throw new Exception("No success status could be retrieved."); |
||
- | 2664 | |
||
- | 2665 | if (!success) |
||
- | 2666 | throw new Exception("Could not schedule a region restart."); |
||
- | 2667 | |
||
- | 2668 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 2669 | { |
||
- | 2670 | vassalForm.StatusText.Text = @"Region scheduled for restart."; |
||
- | 2671 | currentDataGridViewRow.Selected = false; |
||
- | 2672 | currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightGreen; |
||
- | 2673 | foreach ( |
||
- | 2674 | DataGridViewCell cell in |
||
- | 2675 | currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
||
- | 2676 | { |
||
- | 2677 | cell.ToolTipText = @"Region scheduled for restart."; |
||
- | 2678 | } |
||
- | 2679 | })); |
||
- | 2680 | break; |
||
- | 2681 | default: |
||
- | 2682 | throw new Exception("No estate manager rights for region restart."); |
||
- | 2683 | } |
||
- | 2684 | } |
||
- | 2685 | catch (Exception ex) |
||
- | 2686 | { |
||
- | 2687 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 2688 | { |
||
- | 2689 | vassalForm.StatusText.Text = ex.Message; |
||
- | 2690 | currentDataGridViewRow.Selected = false; |
||
- | 2691 | currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightPink; |
||
- | 2692 | foreach ( |
||
- | 2693 | DataGridViewCell cell in |
||
- | 2694 | currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
||
- | 2695 | { |
||
- | 2696 | cell.ToolTipText = ex.Message; |
||
- | 2697 | } |
||
- | 2698 | })); |
||
- | 2699 | } |
||
- | 2700 | } while (!restartRegionQueue.Count.Equals(0)); |
||
- | 2701 | } |
||
- | 2702 | catch (Exception) |
||
- | 2703 | { |
||
- | 2704 | |
||
- | 2705 | } |
||
- | 2706 | finally |
||
- | 2707 | { |
||
- | 2708 | Monitor.Exit(ClientInstanceTeleportLock); |
||
- | 2709 | // Allow teleports and enable button. |
||
- | 2710 | vassalForm.BeginInvoke((MethodInvoker) (() => |
||
- | 2711 | { |
||
- | 2712 | vassalForm.BatchRestartButton.Enabled = true; |
||
- | 2713 | RegionTeleportGroup.Enabled = true; |
||
- | 2714 | })); |
||
- | 2715 | } |
||
- | 2716 | }) |
||
- | 2717 | {IsBackground = true}.Start(); |
||
- | 2718 | |
||
- | 2719 | } |
||
- | 2720 | |
||
- | 2721 | private void RequestFilterResidentList(object sender, EventArgs e) |
||
- | 2722 | { |
||
- | 2723 | vassalForm.BeginInvoke((MethodInvoker) (() => |
||
- | 2724 | { |
||
- | 2725 | Regex residentListRowRegex; |
||
- | 2726 | switch (!string.IsNullOrEmpty(ResidentListFilter.Text)) |
||
- | 2727 | { |
||
- | 2728 | case true: |
||
- | 2729 | residentListRowRegex = new Regex(ResidentListFilter.Text, RegexOptions.Compiled); |
||
- | 2730 | break; |
||
- | 2731 | default: |
||
- | 2732 | residentListRowRegex = new Regex(@".+?", RegexOptions.Compiled); |
||
- | 2733 | break; |
||
- | 2734 | } |
||
- | 2735 | foreach ( |
||
- | 2736 | DataGridViewRow residentListRow in ResidentListGridView.Rows.AsParallel().Cast<DataGridViewRow>()) |
||
- | 2737 | { |
||
- | 2738 | residentListRow.Visible = |
||
- | 2739 | residentListRowRegex.IsMatch(residentListRow.Cells["ResidentListName"].Value.ToString()) || |
||
- | 2740 | residentListRowRegex.IsMatch( |
||
- | 2741 | residentListRow.Cells["ResidentListUUID"].Value.ToString()) || |
||
- | 2742 | residentListRowRegex.IsMatch(residentListRow.Cells["ResidentListPosition"].Value.ToString()); |
||
- | 2743 | } |
||
- | 2744 | })); |
||
- | 2745 | } |
||
- | 2746 | |
||
- | 2747 | private void RequestBanAgents(object sender, EventArgs e) |
||
- | 2748 | { |
||
- | 2749 | // Block teleports and disable button. |
||
- | 2750 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 2751 | { |
||
- | 2752 | ResidentListBanGroup.Enabled = false; |
||
- | 2753 | RegionTeleportGroup.Enabled = false; |
||
- | 2754 | })); |
||
- | 2755 | |
||
- | 2756 | // Enqueue all the regions to restart. |
||
- | 2757 | Queue<UUID> agentsQueue = new Queue<UUID>(); |
||
- | 2758 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 2759 | { |
||
- | 2760 | foreach ( |
||
- | 2761 | DataGridViewRow residentListRow in |
||
- | 2762 | ResidentListGridView.Rows.AsParallel() |
||
- | 2763 | .Cast<DataGridViewRow>() |
||
- | 2764 | .Where(o => o.Selected || o.Cells.Cast<DataGridViewCell>().Any(p => p.Selected))) |
||
- | 2765 | { |
||
- | 2766 | UUID agentUUID; |
||
- | 2767 | if (!UUID.TryParse(residentListRow.Cells["ResidentListUUID"].Value.ToString(), out agentUUID)) |
||
- | 2768 | continue; |
||
- | 2769 | agentsQueue.Enqueue(agentUUID); |
||
- | 2770 | } |
||
- | 2771 | })); |
||
- | 2772 | |
||
- | 2773 | // If no rows were selected, enable teleports, the return button and return. |
||
- | 2774 | if (agentsQueue.Count.Equals(0)) |
||
- | 2775 | { |
||
- | 2776 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 2777 | { |
||
- | 2778 | ResidentListBanGroup.Enabled = true; |
||
- | 2779 | RegionTeleportGroup.Enabled = true; |
||
- | 2780 | })); |
||
- | 2781 | return; |
||
- | 2782 | } |
||
- | 2783 | |
||
- | 2784 | new Thread(() => |
||
- | 2785 | { |
||
- | 2786 | Monitor.Enter(ClientInstanceTeleportLock); |
||
- | 2787 | try |
||
- | 2788 | { |
||
- | 2789 | do |
||
- | 2790 | { |
||
- | 2791 | // Dequeue the first object. |
||
- | 2792 | UUID agentUUID = agentsQueue.Dequeue(); |
||
- | 2793 | DataGridViewRow currentDataGridViewRow = null; |
||
- | 2794 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 2795 | { |
||
- | 2796 | currentDataGridViewRow = vassalForm.ResidentListGridView.Rows.AsParallel() |
||
- | 2797 | .Cast<DataGridViewRow>() |
||
- | 2798 | .FirstOrDefault( |
||
- | 2799 | o => |
||
- | 2800 | o.Cells["ResidentListUUID"].Value.ToString() |
||
- | 2801 | .Equals(agentUUID.ToString(), StringComparison.OrdinalIgnoreCase)); |
||
- | 2802 | })); |
||
- | 2803 | |
||
- | 2804 | if (currentDataGridViewRow == null) continue; |
||
- | 2805 | |
||
- | 2806 | try |
||
- | 2807 | { |
||
- | 2808 | bool alsoBan = false; |
||
- | 2809 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 2810 | { |
||
- | 2811 | alsoBan = vassalForm.ResidentBanAllEstatesBox.Checked; |
||
- | 2812 | })); |
||
- | 2813 | |
||
- | 2814 | // Teleport to the region. |
||
- | 2815 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
||
- | 2816 | wasKeyValueEscape(new Dictionary<string, string> |
||
- | 2817 | { |
||
- | 2818 | {"command", "setestatelist"}, |
||
- | 2819 | {"group", vassalConfiguration.Group}, |
||
- | 2820 | {"password", vassalConfiguration.Password}, |
||
- | 2821 | {"type", "ban"}, |
||
- | 2822 | {"action", "add"}, |
||
- | 2823 | {"agent", agentUUID.ToString()}, |
||
- | 2824 | {"all", alsoBan.ToString()} |
||
- | 2825 | }), vassalConfiguration.DataTimeout); |
||
- | 2826 | |
||
- | 2827 | if (string.IsNullOrEmpty(result)) |
||
- | 2828 | throw new Exception("Error communicating with Corrade."); |
||
- | 2829 | |
||
- | 2830 | bool success; |
||
- | 2831 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
||
- | 2832 | throw new Exception("No success status could be retrieved."); |
||
- | 2833 | |
||
- | 2834 | switch (success) |
||
- | 2835 | { |
||
- | 2836 | case true: |
||
- | 2837 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 2838 | { |
||
- | 2839 | vassalForm.StatusText.Text = @"Resident banned."; |
||
- | 2840 | currentDataGridViewRow.Selected = false; |
||
- | 2841 | currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightGreen; |
||
- | 2842 | foreach ( |
||
- | 2843 | DataGridViewCell cell in |
||
- | 2844 | currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
||
- | 2845 | { |
||
- | 2846 | cell.ToolTipText = @"Resident banned."; |
||
- | 2847 | } |
||
- | 2848 | })); |
||
- | 2849 | break; |
||
- | 2850 | default: |
||
- | 2851 | throw new Exception("Unable to ban resident."); |
||
- | 2852 | } |
||
- | 2853 | } |
||
- | 2854 | catch (Exception ex) |
||
- | 2855 | { |
||
- | 2856 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 2857 | { |
||
- | 2858 | vassalForm.StatusText.Text = ex.Message; |
||
- | 2859 | currentDataGridViewRow.Selected = false; |
||
- | 2860 | currentDataGridViewRow.DefaultCellStyle.BackColor = Color.LightPink; |
||
- | 2861 | foreach ( |
||
- | 2862 | DataGridViewCell cell in |
||
- | 2863 | currentDataGridViewRow.Cells.AsParallel().Cast<DataGridViewCell>()) |
||
- | 2864 | { |
||
- | 2865 | cell.ToolTipText = ex.Message; |
||
- | 2866 | } |
||
- | 2867 | })); |
||
- | 2868 | } |
||
- | 2869 | |
||
- | 2870 | } while (agentsQueue.Count.Equals(0)); |
||
- | 2871 | } |
||
- | 2872 | catch (Exception) |
||
- | 2873 | { |
||
- | 2874 | |
||
- | 2875 | } |
||
- | 2876 | finally |
||
- | 2877 | { |
||
- | 2878 | Monitor.Exit(ClientInstanceTeleportLock); |
||
- | 2879 | // Allow teleports and enable button. |
||
- | 2880 | vassalForm.BeginInvoke((MethodInvoker) (() => |
||
- | 2881 | { |
||
- | 2882 | ResidentListBanGroup.Enabled = true; |
||
- | 2883 | RegionTeleportGroup.Enabled = true; |
||
- | 2884 | })); |
||
- | 2885 | } |
||
- | 2886 | }) |
||
- | 2887 | {IsBackground = true}.Start(); |
||
- | 2888 | } |
||
- | 2889 | |
||
- | 2890 | private void RequestRipTerrain(object sender, EventArgs e) |
||
- | 2891 | { |
||
- | 2892 | // Block teleports and disable button. |
||
- | 2893 | vassalForm.Invoke((MethodInvoker) (() => |
||
- | 2894 | { |
||
- | 2895 | RegionTeleportGroup.Enabled = false; |
||
- | 2896 | RipTerrainButton.Enabled = false; |
||
- | 2897 | })); |
||
- | 2898 | |
||
- | 2899 | new Thread(() => |
||
- | 2900 | { |
||
- | 2901 | Monitor.Enter(ClientInstanceTeleportLock); |
||
- | 2902 | |
||
- | 2903 | try |
||
- | 2904 | { |
||
- | 2905 | // Get the statistics. |
||
- | 2906 | string result = wasPOST(vassalConfiguration.HTTPServerURL, |
||
- | 2907 | wasKeyValueEscape(new Dictionary<string, string> |
||
- | 2908 | { |
||
- | 2909 | {"command", "getterrainheight"}, |
||
- | 2910 | {"group", vassalConfiguration.Group}, |
||
- | 2911 | {"password", vassalConfiguration.Password}, |
||
- | 2912 | {"entity", "region"} |
||
- | 2913 | }), vassalConfiguration.DataTimeout); |
||
- | 2914 | |
||
- | 2915 | if (string.IsNullOrEmpty(result)) |
||
- | 2916 | throw new Exception("Error communicating with Corrade."); |
||
- | 2917 | |
||
- | 2918 | bool success; |
||
- | 2919 | if (!bool.TryParse(wasInput(wasKeyValueGet("success", result)), out success)) |
||
- | 2920 | throw new Exception("No success status could be retrieved."); |
||
- | 2921 | |
||
- | 2922 | if (!success) |
||
- | 2923 | throw new Exception("Could not get terrain heights."); |
||
- | 2924 | |
||
- | 2925 | List<double> heights = new List<double>(); |
||
- | 2926 | foreach (string map in wasCSVToEnumerable(wasInput(wasKeyValueGet("data", result)))) |
||
- | 2927 | { |
||
- | 2928 | double height; |
||
- | 2929 | if (!double.TryParse(map, out height)) |
||
- | 2930 | continue; |
||
- | 2931 | heights.Add(height); |
||
- | 2932 | } |
||
- | 2933 | if (heights.Count.Equals(0)) |
||
- | 2934 | throw new Exception("Could not get terrain heights."); |
||
- | 2935 | |
||
- | 2936 | double maxHeight = heights.Max(); |
||
- | 2937 | using (Bitmap bitmap = new Bitmap(256, 256)) |
||
- | 2938 | { |
||
- | 2939 | foreach (int x in Enumerable.Range(1, 255)) |
||
- | 2940 | { |
||
- | 2941 | foreach (int y in Enumerable.Range(1, 255)) |
||
- | 2942 | { |
||
- | 2943 | bitmap.SetPixel(x, 256 - y, |
||
- | 2944 | Color.FromArgb((int) wasMapValueToRange(heights[256*x + y], 0, maxHeight, 0, 255), 0, 0)); |
||
- | 2945 | } |
||
- | 2946 | } |
||
- | 2947 | Bitmap closureBitmap = (Bitmap)bitmap.Clone(); |
||
- | 2948 | vassalForm.BeginInvoke((MethodInvoker) (() => |
||
- | 2949 | { |
||
- | 2950 | switch (vassalForm.SaveTerrainFileDialog.ShowDialog()) |
||
- | 2951 | { |
||
- | 2952 | case DialogResult.OK: |
||
- | 2953 | string file = vassalForm.SaveTerrainFileDialog.FileName; |
||
- | 2954 | new Thread(() => |
||
- | 2955 | { |
||
- | 2956 | vassalForm.BeginInvoke((MethodInvoker) (() => |
||
- | 2957 | { |
||
- | 2958 | try |
||
- | 2959 | { |
||
- | 2960 | vassalForm.StatusText.Text = @"saving terrain..."; |
||
- | 2961 | vassalForm.StatusProgress.Value = 0; |
||
- | 2962 | |
||
- | 2963 | closureBitmap.Save(file, ImageFormat.Png); |
||
- | 2964 | |
||
- | 2965 | vassalForm.StatusText.Text = @"terrain saved"; |
||
- | 2966 | vassalForm.StatusProgress.Value = 100; |
||
- | 2967 | } |
||
- | 2968 | catch (Exception ex) |
||
- | 2969 | { |
||
- | 2970 | vassalForm.StatusText.Text = ex.Message; |
||
- | 2971 | } |
||
- | 2972 | finally |
||
- | 2973 | { |
||
- | 2974 | closureBitmap.Dispose(); |
||
- | 2975 | } |
||
- | 2976 | })); |
||
- | 2977 | }) |
||
- | 2978 | {IsBackground = true, Priority = ThreadPriority.Normal}.Start(); |
||
- | 2979 | break; |
||
- | 2980 | } |
||
- | 2981 | })); |
||
- | 2982 | } |
||
- | 2983 | |
||
- | 2984 | } |
||
- | 2985 | catch (Exception ex) |
||
- | 2986 | { |
||
- | 2987 | vassalForm.BeginInvoke((MethodInvoker)(() => |
||
- | 2988 | { |
||
- | 2989 | StatusText.Text = ex.Message; |
||
- | 2990 | })); |
||
- | 2991 | } |
||
- | 2992 | finally |
||
- | 2993 | { |
||
- | 2994 | Monitor.Exit(ClientInstanceTeleportLock); |
||
- | 2995 | vassalForm.BeginInvoke((MethodInvoker)(() => |
||
Line -... | Line 2996... | |||
- | 2996 | { |
||
2067 | { IsBackground = true }.Start(); |
2997 | RegionTeleportGroup.Enabled = true; |
|
2068 | } |
2998 | RipTerrainButton.Enabled = true; |
|
2069 | |
2999 | })); |