AccountInfoForm.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. using Server.MirDatabase;
  2. using Server.MirEnvir;
  3. using Server.MirObjects;
  4. using System.Globalization;
  5. using System.Security.Principal;
  6. namespace Server
  7. {
  8. public partial class AccountInfoForm : Form
  9. {
  10. private List<AccountInfo> _selectedAccountInfos;
  11. public Envir AccountEnvir => SMain.Envir;
  12. public AccountInfoForm()
  13. {
  14. InitializeComponent();
  15. Setup();
  16. }
  17. public AccountInfoForm(string accountId, bool match = false)
  18. {
  19. InitializeComponent();
  20. FilterTextBox.Text = accountId;
  21. MatchFilterCheckBox.Checked = match;
  22. Setup();
  23. }
  24. private void Setup()
  25. {
  26. RefreshInterface();
  27. AutoResize();
  28. AccountIDTextBox.MaxLength = Globals.MaxAccountIDLength;
  29. UserNameTextBox.MaxLength = 20;
  30. BirthDateTextBox.MaxLength = 10;
  31. QuestionTextBox.MaxLength = 30;
  32. AnswerTextBox.MaxLength = 30;
  33. EMailTextBox.MaxLength = 50;
  34. }
  35. private void AutoResize()
  36. {
  37. indexHeader.Width = -2;
  38. accountIDHeader.Width = -2;
  39. userNameHeader.Width = -2;
  40. bannedHeader.Width = -2;
  41. banReasonHeader.Width = -2;
  42. expiryDateHeader.Width = -2;
  43. Gold.Width = -2;
  44. GameGold.Width = -2;
  45. }
  46. private void Update(ListViewItem ListItem, AccountInfo account)
  47. {
  48. ListItem.SubItems[0].Text = account.Index.ToString();
  49. ListItem.SubItems[1].Text = account.AccountID;
  50. ListItem.SubItems[2].Text = account.UserName;
  51. ListItem.SubItems[3].Text = account.AdminAccount.ToString();
  52. ListItem.SubItems[4].Text = account.Banned.ToString();
  53. ListItem.SubItems[5].Text = account.BanReason;
  54. ListItem.SubItems[6].Text = account.ExpiryDate.ToString();
  55. ListItem.SubItems[7].Text = account.Gold.ToString();
  56. ListItem.SubItems[8].Text = account.Credit.ToString();
  57. }
  58. private ListViewItem CreateListView(AccountInfo account)
  59. {
  60. ListViewItem ListItem = new ListViewItem(account.Index.ToString()) { Tag = account };
  61. ListItem.SubItems.Add(account.AccountID);
  62. ListItem.SubItems.Add(account.UserName);
  63. ListItem.SubItems.Add(account.AdminAccount.ToString());
  64. ListItem.SubItems.Add(account.Banned.ToString());
  65. ListItem.SubItems.Add(account.BanReason);
  66. ListItem.SubItems.Add(account.ExpiryDate.ToString());
  67. ListItem.SubItems.Add(account.Gold.ToString());
  68. ListItem.SubItems.Add(account.Credit.ToString());
  69. return ListItem;
  70. }
  71. public void RefreshInterface()
  72. {
  73. if (InvokeRequired)
  74. {
  75. Invoke(new MethodInvoker(RefreshInterface));
  76. return;
  77. }
  78. List<AccountInfo> accounts = SMain.Envir.AccountList;
  79. long totalGold = accounts
  80. .Where(account => !account.AdminAccount && !account.Banned)
  81. .Sum(account => account.Gold);
  82. ServerGoldTextBox.Text = totalGold.ToString("N0", CultureInfo.GetCultureInfo("en-GB"));
  83. long totalCredit = accounts
  84. .Where(account => !account.AdminAccount && !account.Banned)
  85. .Sum(account => account.Credit);
  86. ServerCreditTextBox.Text = totalCredit.ToString("N0", CultureInfo.GetCultureInfo("en-GB"));
  87. if (FilterTextBox.Text.Length > 0)
  88. accounts = SMain.Envir.MatchAccounts(FilterTextBox.Text, MatchFilterCheckBox.Checked);
  89. else if (FilterPlayerTextBox.Text.Length > 0)
  90. accounts = SMain.Envir.MatchAccountsByPlayer(FilterPlayerTextBox.Text, MatchFilterCheckBox.Checked);
  91. else if (FilterIPTextBox.Text.Length > 0)
  92. accounts = SMain.Envir.MatchAccountsByIP(FilterIPTextBox.Text, MatchFilterCheckBox.Checked);
  93. if (AccountInfoListView.Items.Count != accounts.Count)
  94. {
  95. AccountInfoListView.SelectedIndexChanged -= AccountInfoListView_SelectedIndexChanged;
  96. AccountInfoListView.Items.Clear();
  97. for (int i = AccountInfoListView.Items.Count; i < accounts.Count; i++)
  98. {
  99. AccountInfo account = accounts[i];
  100. ListViewItem tempItem = CreateListView(account);
  101. AccountInfoListView.Items.Add(tempItem);
  102. }
  103. AccountInfoListView.SelectedIndexChanged += AccountInfoListView_SelectedIndexChanged;
  104. }
  105. _selectedAccountInfos = new List<AccountInfo>();
  106. CharactersListView.Items.Clear();
  107. for (int i = 0; i < AccountInfoListView.SelectedItems.Count; i++)
  108. _selectedAccountInfos.Add(AccountInfoListView.SelectedItems[i].Tag as AccountInfo);
  109. if (_selectedAccountInfos.Count == 0)
  110. {
  111. AccountInfoPanel.Enabled = false;
  112. AccountIDTextBox.Text = string.Empty;
  113. UserNameTextBox.Text = string.Empty;
  114. BirthDateTextBox.Text = string.Empty;
  115. QuestionTextBox.Text = string.Empty;
  116. AnswerTextBox.Text = string.Empty;
  117. EMailTextBox.Text = string.Empty;
  118. return;
  119. }
  120. AccountInfo info = _selectedAccountInfos[0];
  121. AccountInfoPanel.Enabled = true;
  122. AccountIDTextBox.Enabled = _selectedAccountInfos.Count == 1;
  123. AccountIDTextBox.Text = info.AccountID;
  124. UserNameTextBox.Text = info.UserName;
  125. BirthDateTextBox.Text = info.BirthDate.ToShortDateString();
  126. QuestionTextBox.Text = info.SecretQuestion;
  127. AnswerTextBox.Text = info.SecretAnswer;
  128. EMailTextBox.Text = info.EMailAddress;
  129. CreationIPTextBox.Text = info.CreationIP;
  130. CreationDateTextBox.Text = info.CreationDate.ToString();
  131. LastIPTextBox.Text = info.LastIP;
  132. LastDateTextBox.Text = info.LastDate.ToString();
  133. BanReasonTextBox.Text = info.BanReason;
  134. BannedCheckBox.CheckState = info.Banned ? CheckState.Checked : CheckState.Unchecked;
  135. ExpiryDateTextBox.Text = info.ExpiryDate.ToString();
  136. AdminCheckBox.CheckState = info.AdminAccount ? CheckState.Checked : CheckState.Unchecked;
  137. PasswordChangeCheckBox.CheckState = info.RequirePasswordChange ? CheckState.Checked : CheckState.Unchecked;
  138. for (int i = 0; i < _selectedAccountInfos.Count; i++)
  139. {
  140. info = _selectedAccountInfos[i];
  141. if (AccountIDTextBox.Text != info.AccountID) AccountIDTextBox.Text = string.Empty;
  142. if (UserNameTextBox.Text != info.UserName) UserNameTextBox.Text = string.Empty;
  143. if (BirthDateTextBox.Text != info.BirthDate.ToShortDateString()) BirthDateTextBox.Text = string.Empty;
  144. if (QuestionTextBox.Text != info.SecretQuestion) QuestionTextBox.Text = string.Empty;
  145. if (AnswerTextBox.Text != info.SecretAnswer) AnswerTextBox.Text = string.Empty;
  146. if (EMailTextBox.Text != info.EMailAddress) EMailTextBox.Text = string.Empty;
  147. if (CreationIPTextBox.Text != info.CreationIP) CreationIPTextBox.Text = string.Empty;
  148. if (CreationDateTextBox.Text != info.CreationDate.ToString()) CreationDateTextBox.Text = string.Empty;
  149. if (LastIPTextBox.Text != info.LastIP) LastIPTextBox.Text = string.Empty;
  150. if (LastDateTextBox.Text != info.LastDate.ToString()) LastDateTextBox.Text = string.Empty;
  151. if (BanReasonTextBox.Text != info.BanReason) BanReasonTextBox.Text = string.Empty;
  152. if (BannedCheckBox.Checked != info.Banned) BannedCheckBox.CheckState = CheckState.Indeterminate;
  153. if (ExpiryDateTextBox.Text != info.ExpiryDate.ToString()) ExpiryDateTextBox.Text = string.Empty;
  154. if (AdminCheckBox.Checked != info.AdminAccount) AdminCheckBox.CheckState = CheckState.Indeterminate;
  155. if (PasswordChangeCheckBox.Checked != info.RequirePasswordChange) PasswordChangeCheckBox.CheckState = CheckState.Indeterminate;
  156. foreach (var character in info.Characters)
  157. {
  158. var listItem = new ListViewItem(character.Name) { Tag = character };
  159. listItem.SubItems.Add(character.Class.ToString());
  160. listItem.SubItems.Add(character.Level.ToString());
  161. listItem.SubItems.Add(character.PKPoints.ToString());
  162. GuildObject guild = null;
  163. if (character.GuildIndex != -1)
  164. {
  165. guild = AccountEnvir.GetGuild(character.GuildIndex);
  166. if (guild != null)
  167. {
  168. listItem.SubItems.Add(guild.Name.ToString());
  169. }
  170. }
  171. else
  172. {
  173. listItem.SubItems.Add("No Guild");
  174. }
  175. string status = $"";
  176. if (character.LastLoginDate > character.LastLogoutDate)
  177. {
  178. status = $"Online: {(SMain.Envir.Now - character.LastLoginDate).TotalMinutes.ToString("##")} minutes";
  179. listItem.ForeColor = Color.Green;
  180. }
  181. else
  182. {
  183. status = $"Offline: {character.LastLogoutDate}";
  184. }
  185. if (character.Deleted)
  186. {
  187. status = $"Deleted: {character.DeleteDate}";
  188. listItem.ForeColor = Color.Red;
  189. }
  190. listItem.SubItems.Add(status.ToString());
  191. CharactersListView.Items.Add(listItem);
  192. }
  193. }
  194. }
  195. private void AccountInfoListView_SelectedIndexChanged(object sender, EventArgs e)
  196. {
  197. RefreshInterface();
  198. }
  199. private void CreateButton_Click(object sender, EventArgs e)
  200. {
  201. lock (Envir.AccountLock)
  202. {
  203. SMain.Envir.CreateAccountInfo();
  204. RefreshInterface();
  205. }
  206. }
  207. private void AccountIDTextBox_TextChanged(object sender, EventArgs e)
  208. {
  209. if (ActiveControl != sender) return;
  210. if (_selectedAccountInfos.Count != 1) return;
  211. lock (Envir.AccountLock)
  212. {
  213. if (SMain.Envir.AccountExists(ActiveControl.Text))
  214. {
  215. ActiveControl.BackColor = Color.Red;
  216. return;
  217. }
  218. AccountInfoListView.BeginUpdate();
  219. ActiveControl.BackColor = SystemColors.Window;
  220. _selectedAccountInfos[0].AccountID = ActiveControl.Text;
  221. Update(AccountInfoListView.SelectedItems[0], _selectedAccountInfos[0]);
  222. AutoResize();
  223. AccountInfoListView.EndUpdate();
  224. }
  225. }
  226. private void UserNameTextBox_TextChanged(object sender, EventArgs e)
  227. {
  228. if (ActiveControl != sender) return;
  229. AccountInfoListView.BeginUpdate();
  230. for (int i = 0; i < _selectedAccountInfos.Count; i++)
  231. {
  232. _selectedAccountInfos[i].UserName = ActiveControl.Text;
  233. Update(AccountInfoListView.SelectedItems[i], _selectedAccountInfos[i]);
  234. }
  235. AutoResize();
  236. AccountInfoListView.EndUpdate();
  237. }
  238. private void BirthDateTextBox_TextChanged(object sender, EventArgs e)
  239. {
  240. if (ActiveControl != sender) return;
  241. DateTime temp;
  242. if (!DateTime.TryParse(ActiveControl.Text, out temp))
  243. {
  244. ActiveControl.BackColor = Color.Red;
  245. return;
  246. }
  247. ActiveControl.BackColor = SystemColors.Window;
  248. for (int i = 0; i < _selectedAccountInfos.Count; i++)
  249. _selectedAccountInfos[i].BirthDate = temp;
  250. }
  251. private void QuestionTextBox_TextChanged(object sender, EventArgs e)
  252. {
  253. if (ActiveControl != sender) return;
  254. for (int i = 0; i < _selectedAccountInfos.Count; i++)
  255. _selectedAccountInfos[i].SecretQuestion = ActiveControl.Text;
  256. }
  257. private void AnswerTextBox_TextChanged(object sender, EventArgs e)
  258. {
  259. if (ActiveControl != sender) return;
  260. for (int i = 0; i < _selectedAccountInfos.Count; i++)
  261. _selectedAccountInfos[i].SecretAnswer = ActiveControl.Text;
  262. }
  263. private void EMailTextBox_TextChanged(object sender, EventArgs e)
  264. {
  265. if (ActiveControl != sender) return;
  266. for (int i = 0; i < _selectedAccountInfos.Count; i++)
  267. _selectedAccountInfos[i].EMailAddress = ActiveControl.Text;
  268. }
  269. private void DayBanButton_Click(object sender, EventArgs e)
  270. {
  271. if (MessageBox.Show("Are you sure you want to ban the selected Accounts?", "Ban Selected.", MessageBoxButtons.YesNoCancel) != DialogResult.Yes) return;
  272. DateTime expiry = SMain.Envir.Now.AddDays(1);
  273. AccountInfoListView.BeginUpdate();
  274. for (int i = 0; i < _selectedAccountInfos.Count; i++)
  275. {
  276. _selectedAccountInfos[i].Banned = true;
  277. _selectedAccountInfos[i].ExpiryDate = expiry;
  278. Update(AccountInfoListView.SelectedItems[i], _selectedAccountInfos[i]);
  279. }
  280. RefreshInterface();
  281. AutoResize();
  282. AccountInfoListView.EndUpdate();
  283. }
  284. private void WeekBanButton_Click(object sender, EventArgs e)
  285. {
  286. if (MessageBox.Show("Are you sure you want to ban the selected Accounts?", "Ban Selected.", MessageBoxButtons.YesNoCancel) != DialogResult.Yes) return;
  287. DateTime expiry = SMain.Envir.Now.AddDays(7);
  288. AccountInfoListView.BeginUpdate();
  289. for (int i = 0; i < _selectedAccountInfos.Count; i++)
  290. {
  291. _selectedAccountInfos[i].Banned = true;
  292. _selectedAccountInfos[i].ExpiryDate = expiry;
  293. Update(AccountInfoListView.SelectedItems[i], _selectedAccountInfos[i]);
  294. }
  295. RefreshInterface();
  296. AutoResize();
  297. AccountInfoListView.EndUpdate();
  298. }
  299. private void PermBanButton_Click(object sender, EventArgs e)
  300. {
  301. if (MessageBox.Show("Are you sure you want to ban the selected Accounts?", "Ban Selected.", MessageBoxButtons.YesNoCancel) != DialogResult.Yes) return;
  302. AccountInfoListView.BeginUpdate();
  303. for (int i = 0; i < _selectedAccountInfos.Count; i++)
  304. {
  305. _selectedAccountInfos[i].Banned = true;
  306. _selectedAccountInfos[i].ExpiryDate = DateTime.MaxValue;
  307. Update(AccountInfoListView.SelectedItems[i], _selectedAccountInfos[i]);
  308. }
  309. RefreshInterface();
  310. AutoResize();
  311. AccountInfoListView.EndUpdate();
  312. }
  313. private void BannedCheckBox_CheckedChanged(object sender, EventArgs e)
  314. {
  315. if (ActiveControl != sender) return;
  316. AccountInfoListView.BeginUpdate();
  317. for (int i = 0; i < _selectedAccountInfos.Count; i++)
  318. {
  319. _selectedAccountInfos[i].Banned = false;
  320. Update(AccountInfoListView.SelectedItems[i], _selectedAccountInfos[i]);
  321. }
  322. AutoResize();
  323. AccountInfoListView.EndUpdate();
  324. }
  325. private void BanReasonTextBox_TextChanged(object sender, EventArgs e)
  326. {
  327. if (ActiveControl != sender) return;
  328. AccountInfoListView.BeginUpdate();
  329. for (int i = 0; i < _selectedAccountInfos.Count; i++)
  330. {
  331. _selectedAccountInfos[i].BanReason = ActiveControl.Text;
  332. Update(AccountInfoListView.SelectedItems[i], _selectedAccountInfos[i]);
  333. }
  334. AutoResize();
  335. AccountInfoListView.EndUpdate();
  336. }
  337. private void ExpiryDateTextBox_TextChanged(object sender, EventArgs e)
  338. {
  339. if (ActiveControl != sender) return;
  340. DateTime temp;
  341. if (!DateTime.TryParse(ActiveControl.Text, out temp))
  342. {
  343. ActiveControl.BackColor = Color.Red;
  344. return;
  345. }
  346. ActiveControl.BackColor = SystemColors.Window;
  347. AccountInfoListView.BeginUpdate();
  348. for (int i = 0; i < _selectedAccountInfos.Count; i++)
  349. {
  350. _selectedAccountInfos[i].ExpiryDate = temp;
  351. Update(AccountInfoListView.SelectedItems[i], _selectedAccountInfos[i]);
  352. }
  353. AutoResize();
  354. AccountInfoListView.EndUpdate();
  355. }
  356. private void RefreshButton_Click(object sender, EventArgs e)
  357. {
  358. RefreshInterface();
  359. }
  360. private void AccountInfoForm_FormClosed(object sender, FormClosedEventArgs e)
  361. {
  362. if (SMain.Envir.Running) return;
  363. SMain.Envir.SaveAccounts();
  364. }
  365. private void AdminCheckBox_CheckedChanged(object sender, EventArgs e)
  366. {
  367. if (ActiveControl != sender) return;
  368. AccountInfoListView.BeginUpdate();
  369. for (int i = 0; i < _selectedAccountInfos.Count; i++)
  370. {
  371. _selectedAccountInfos[i].AdminAccount = AdminCheckBox.CheckState == CheckState.Checked ? true : false;
  372. Update(AccountInfoListView.SelectedItems[i], _selectedAccountInfos[i]);
  373. }
  374. AutoResize();
  375. AccountInfoListView.EndUpdate();
  376. }
  377. private void WipeCharButton_Click(object sender, EventArgs e)
  378. {
  379. if (SMain.Envir.Running)
  380. {
  381. MessageBox.Show("Cannot wipe characters whilst the server is running", "Notice",
  382. MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  383. return;
  384. }
  385. if (MessageBox.Show("Are you sure you want to wipe all characters from the database?", "Notice",
  386. MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
  387. {
  388. for (int i = 0; i < SMain.Envir.AccountList.Count; i++)
  389. {
  390. AccountInfo account = SMain.Envir.AccountList[i];
  391. account.Characters.Clear();
  392. }
  393. SMain.Envir.Auctions.Clear();
  394. SMain.Envir.GuildList.Clear();
  395. MessageBox.Show("All characters and associated data has been cleared", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  396. }
  397. }
  398. private void button1_Click(object sender, EventArgs e)
  399. {
  400. ChangePasswordDialog PasswordDialog = new ChangePasswordDialog();
  401. if (PasswordDialog.ShowDialog(this) == DialogResult.OK && PasswordDialog.PasswordTextBox.Text.Length > 0)
  402. {
  403. AccountInfoListView.BeginUpdate();
  404. for (int i = 0; i < _selectedAccountInfos.Count; i++)
  405. {
  406. _selectedAccountInfos[i].Password = PasswordDialog.PasswordTextBox.Text;
  407. _selectedAccountInfos[i].RequirePasswordChange = true;
  408. PasswordChangeCheckBox.CheckState = CheckState.Checked;
  409. Update(AccountInfoListView.SelectedItems[i], _selectedAccountInfos[i]);
  410. MessageBox.Show("Password Changed");
  411. }
  412. AutoResize();
  413. AccountInfoListView.EndUpdate();
  414. }
  415. }
  416. private void ClearStoragePasswordButton_Click(object sender, EventArgs e)
  417. {
  418. if (_selectedAccountInfos == null || _selectedAccountInfos.Count == 0) return;
  419. if (MessageBox.Show("Clear storage password for selected account(s)?", "Notice",
  420. MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) != DialogResult.Yes)
  421. return;
  422. for (int i = 0; i < _selectedAccountInfos.Count; i++)
  423. {
  424. AccountInfo account = _selectedAccountInfos[i];
  425. account.ClearStoragePassword();
  426. foreach (var character in account.Characters)
  427. {
  428. if (character?.Player == null) continue;
  429. character.Player.SetStorageUnlocked(false);
  430. character.Player.ResetStorageUnlock();
  431. character.Player.Enqueue(new ServerPackets.StoragePasswordResult
  432. {
  433. Result = 4,
  434. Removing = true,
  435. HasPassword = false,
  436. LastSetTime = DateTime.MinValue
  437. });
  438. }
  439. }
  440. MessageBox.Show("Storage password cleared.", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  441. }
  442. private void PasswordChangeCheckBox_CheckedChanged(object sender, EventArgs e)
  443. {
  444. if (ActiveControl != sender) return;
  445. AccountInfoListView.BeginUpdate();
  446. for (int i = 0; i < _selectedAccountInfos.Count; i++)
  447. {
  448. _selectedAccountInfos[i].RequirePasswordChange = PasswordChangeCheckBox.CheckState == CheckState.Checked;
  449. Update(AccountInfoListView.SelectedItems[i], _selectedAccountInfos[i]);
  450. }
  451. AutoResize();
  452. AccountInfoListView.EndUpdate();
  453. }
  454. #region IPSearch
  455. private void CreationIPSearch_Click(object sender, EventArgs e)
  456. {
  457. string ipAddress = CreationIPTextBox.Text;
  458. string url = $"https://whatismyipaddress.com/ip/{ipAddress}";
  459. try
  460. {
  461. System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(url)
  462. {
  463. UseShellExecute = true
  464. });
  465. }
  466. catch (Exception ex)
  467. {
  468. MessageBox.Show($"Error opening URL: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  469. }
  470. }
  471. private void LastIPSearch_Click(object sender, EventArgs e)
  472. {
  473. string ipAddress = LastIPTextBox.Text;
  474. string url = $"https://whatismyipaddress.com/ip/{ipAddress}";
  475. try
  476. {
  477. System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(url)
  478. {
  479. UseShellExecute = true
  480. });
  481. }
  482. catch (Exception ex)
  483. {
  484. MessageBox.Show($"Error opening URL: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  485. }
  486. }
  487. #endregion
  488. private void Delaccbtn_Click(object sender, EventArgs e)
  489. {
  490. if (AccountInfoListView.SelectedItems.Count > 0)
  491. {
  492. // Ask for confirmation
  493. DialogResult result = MessageBox.Show("Are you sure you want to delete this account?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  494. if (result == DialogResult.Yes)
  495. {
  496. // Get the selected account from the ListViewItem's Tag property
  497. AccountInfo accInfo = (AccountInfo)AccountInfoListView.SelectedItems[0].Tag;
  498. // Remove the selected account from AccountList
  499. if (SMain.Envir.AccountList.Contains(accInfo))
  500. {
  501. SMain.Envir.AccountList.Remove(accInfo);
  502. }
  503. // Remove the selected item from AccountInfoListView
  504. AccountInfoListView.SelectedItems[0].Remove();
  505. }
  506. }
  507. else
  508. {
  509. MessageBox.Show("Please select an account to remove.");
  510. }
  511. }
  512. }
  513. }