LoginScene.cs 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368
  1. using System.Security.Cryptography;
  2. using System.Text.RegularExpressions;
  3. using Client.MirControls;
  4. using Client.MirGraphics;
  5. using Client.MirNetwork;
  6. using Client.MirSounds;
  7. using S = ServerPackets;
  8. using C = ClientPackets;
  9. namespace Client.MirScenes
  10. {
  11. public sealed class LoginScene : MirScene
  12. {
  13. private MirAnimatedControl _background;
  14. public MirLabel Version;
  15. private LoginDialog _login;
  16. private NewAccountDialog _account;
  17. private ChangePasswordDialog _password;
  18. private MirMessageBox _connectBox;
  19. private InputKeyDialog _ViewKey;
  20. public MirImageControl TestLabel, ViolenceLabel, MinorLabel, YouthLabel;
  21. public LoginScene()
  22. {
  23. SoundManager.PlayMusic(SoundList.IntroMusic, true);
  24. Disposing += (o, e) => SoundManager.StopMusic();
  25. _background = new MirAnimatedControl
  26. {
  27. Animated = false,
  28. AnimationCount = 19,
  29. AnimationDelay = 100,
  30. Index = 0,
  31. Library = Libraries.ChrSel,
  32. Loop = false,
  33. Parent = this,
  34. };
  35. _login = new LoginDialog {Parent = _background, Visible = false};
  36. _login.AccountButton.Click += (o, e) =>
  37. {
  38. _login.Hide();
  39. if(_ViewKey != null && !_ViewKey.IsDisposed) _ViewKey.Dispose();
  40. _account = new NewAccountDialog { Parent = _background };
  41. _account.Disposing += (o1, e1) => _login.Show();
  42. };
  43. _login.PassButton.Click += (o, e) =>
  44. {
  45. OpenPasswordChangeDialog(string.Empty, string.Empty);
  46. };
  47. _login.ViewKeyButton.Click += (o, e) => //ADD
  48. {
  49. if (_ViewKey != null && !_ViewKey.IsDisposed) return;
  50. _ViewKey = new InputKeyDialog(_login) { Parent = _background };
  51. };
  52. Version = new MirLabel
  53. {
  54. AutoSize = true,
  55. BackColour = Color.FromArgb(200, 50, 50, 50),
  56. Border = true,
  57. BorderColour = Color.Black,
  58. Location = new Point(5, Settings.ScreenHeight - 20),
  59. Parent = _background,
  60. Text = string.Format("Build: {0}.{1}.{2}", Globals.ProductCodename, Settings.UseTestConfig ? "Debug" : "Release", Application.ProductVersion),
  61. };
  62. TestLabel = new MirImageControl
  63. {
  64. Index = 79,
  65. Library = Libraries.Prguse,
  66. Parent = this,
  67. Location = new Point(Settings.ScreenWidth - 116, 10),
  68. Visible = Settings.UseTestConfig
  69. };
  70. _connectBox = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AttemptingConnectServer), MirMessageBoxButtons.Cancel);
  71. _connectBox.CancelButton.Click += (o, e) => Program.Form.Close();
  72. Shown += (sender, args) =>
  73. {
  74. Network.Connect();
  75. _connectBox.Show();
  76. };
  77. }
  78. public override void Process()
  79. {
  80. if (!Network.Connected && _connectBox.Label != null)
  81. _connectBox.Label.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.AttemptingConnect),"\n\n", Network.ConnectAttempt);
  82. }
  83. public override void ProcessPacket(Packet p)
  84. {
  85. switch (p.Index)
  86. {
  87. case (short)ServerPacketIds.Connected:
  88. Network.Connected = true;
  89. SendVersion();
  90. break;
  91. case (short)ServerPacketIds.ClientVersion:
  92. ClientVersion((S.ClientVersion) p);
  93. break;
  94. case (short)ServerPacketIds.NewAccount:
  95. NewAccount((S.NewAccount) p);
  96. break;
  97. case (short)ServerPacketIds.ChangePassword:
  98. ChangePassword((S.ChangePassword) p);
  99. break;
  100. case (short)ServerPacketIds.ChangePasswordBanned:
  101. ChangePassword((S.ChangePasswordBanned) p);
  102. break;
  103. case (short)ServerPacketIds.Login:
  104. Login((S.Login) p);
  105. break;
  106. case (short)ServerPacketIds.LoginBanned:
  107. Login((S.LoginBanned) p);
  108. break;
  109. case (short)ServerPacketIds.LoginSuccess:
  110. Login((S.LoginSuccess) p);
  111. break;
  112. default:
  113. base.ProcessPacket(p);
  114. break;
  115. }
  116. }
  117. private void SendVersion()
  118. {
  119. _connectBox.Label.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SendingClientVersion);
  120. C.ClientVersion p = new C.ClientVersion();
  121. try
  122. {
  123. byte[] sum;
  124. using (MD5 md5 = MD5.Create())
  125. using (FileStream stream = File.OpenRead(Application.ExecutablePath))
  126. sum = md5.ComputeHash(stream);
  127. p.VersionHash = sum;
  128. Network.Enqueue(p);
  129. }
  130. catch (Exception ex)
  131. {
  132. if (Settings.LogErrors) CMain.SaveError(ex.ToString());
  133. }
  134. }
  135. private void ClientVersion(S.ClientVersion p)
  136. {
  137. switch (p.Result)
  138. {
  139. case 0:
  140. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.WrongVersionPleaseUpdateGame), true);
  141. Network.Disconnect();
  142. break;
  143. case 1:
  144. _connectBox.Dispose();
  145. _login.Show();
  146. break;
  147. }
  148. }
  149. private void OpenPasswordChangeDialog(string autoFillID, string autoFillPassword)
  150. {
  151. _login.Hide();
  152. if (_ViewKey != null && !_ViewKey.IsDisposed) _ViewKey.Dispose();
  153. _password = new ChangePasswordDialog { Parent = _background };
  154. _password.AccountIDTextBox.Text = autoFillID;
  155. _password.CurrentPasswordTextBox.Text = autoFillPassword;
  156. _password.Disposing += (o1, e1) => _login.Show();
  157. }
  158. private void NewAccount(S.NewAccount p)
  159. {
  160. _account.OKButton.Enabled = true;
  161. switch (p.Result)
  162. {
  163. case 0:
  164. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AccountCreationDisabled));
  165. _account.Dispose();
  166. break;
  167. case 1:
  168. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AccountIdNotAcceptable));
  169. _account.AccountIDTextBox.SetFocus();
  170. break;
  171. case 2:
  172. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.PasswordNotAcceptable));
  173. _account.Password1TextBox.SetFocus();
  174. break;
  175. case 3:
  176. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.EmailAddressNotAcceptable));
  177. _account.EMailTextBox.SetFocus();
  178. break;
  179. case 4:
  180. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.UserNameNotAcceptable));
  181. _account.UserNameTextBox.SetFocus();
  182. break;
  183. case 5:
  184. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SecretQuestionNotAcceptable));
  185. _account.QuestionTextBox.SetFocus();
  186. break;
  187. case 6:
  188. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SecretAnswerNotAcceptable));
  189. _account.AnswerTextBox.SetFocus();
  190. break;
  191. case 7:
  192. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AccountIdAlreadyExists));
  193. _account.AccountIDTextBox.Text = string.Empty;
  194. _account.AccountIDTextBox.SetFocus();
  195. break;
  196. case 8:
  197. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AccountCreatedSuccessfully));
  198. _account.Dispose();
  199. break;
  200. }
  201. }
  202. private void ChangePassword(S.ChangePassword p)
  203. {
  204. _password.OKButton.Enabled = true;
  205. switch (p.Result)
  206. {
  207. case 0:
  208. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.PasswordChangingDisabled));
  209. _password.Dispose();
  210. break;
  211. case 1:
  212. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AccountIdNotAcceptable));
  213. _password.AccountIDTextBox.SetFocus();
  214. break;
  215. case 2:
  216. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.CurrentPasswordNotAcceptable));
  217. _password.CurrentPasswordTextBox.SetFocus();
  218. break;
  219. case 3:
  220. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NewPasswordNotAcceptable));
  221. _password.NewPassword1TextBox.SetFocus();
  222. break;
  223. case 4:
  224. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NoAccountID));
  225. _password.AccountIDTextBox.SetFocus();
  226. break;
  227. case 5:
  228. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.IncorrectPasswordAccountID));
  229. _password.CurrentPasswordTextBox.SetFocus();
  230. _password.CurrentPasswordTextBox.Text = string.Empty;
  231. break;
  232. case 6:
  233. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.PasswordChangedSuccessfully));
  234. _password.Dispose();
  235. break;
  236. }
  237. }
  238. private void ChangePassword(S.ChangePasswordBanned p)
  239. {
  240. _password.Dispose();
  241. TimeSpan d = p.ExpiryDate - CMain.Now;
  242. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.AccountBannedReasonDuration), p.Reason,
  243. p.ExpiryDate, Math.Floor(d.TotalHours), d.Minutes, d.Seconds ));
  244. }
  245. private void Login(S.Login p)
  246. {
  247. _login.OKButton.Enabled = true;
  248. switch (p.Result)
  249. {
  250. case 0:
  251. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.LoginDisabled));
  252. _login.Clear();
  253. break;
  254. case 1:
  255. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AccountIdNotAcceptable));
  256. _login.AccountIDTextBox.SetFocus();
  257. break;
  258. case 2:
  259. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.PasswordNotAcceptable));
  260. _login.PasswordTextBox.SetFocus();
  261. break;
  262. case 3:
  263. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NoAccountID));
  264. _login.PasswordTextBox.SetFocus();
  265. break;
  266. case 4:
  267. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.IncorrectPasswordAccountID));
  268. _login.PasswordTextBox.Text = string.Empty;
  269. _login.PasswordTextBox.SetFocus();
  270. break;
  271. case 5:
  272. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AccountPasswordMustChangeBeforeLogin));
  273. OpenPasswordChangeDialog(_login.AccountIDTextBox.Text, _login.PasswordTextBox.Text);
  274. _login.PasswordTextBox.Text = string.Empty;
  275. break;
  276. }
  277. }
  278. private void Login(S.LoginBanned p)
  279. {
  280. _login.OKButton.Enabled = true;
  281. TimeSpan d = p.ExpiryDate - CMain.Now;
  282. MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.AccountBannedReasonDuration), p.Reason,
  283. p.ExpiryDate, Math.Floor(d.TotalHours), d.Minutes, d.Seconds));
  284. }
  285. private void Login(S.LoginSuccess p)
  286. {
  287. Enabled = false;
  288. _login.Dispose();
  289. if(_ViewKey != null && !_ViewKey.IsDisposed) _ViewKey.Dispose();
  290. SoundManager.PlaySound(SoundList.LoginEffect);
  291. _background.Animated = true;
  292. _background.AfterAnimation += (o, e) =>
  293. {
  294. Dispose();
  295. ActiveScene = new SelectScene(p.Characters);
  296. };
  297. }
  298. public sealed class LoginDialog : MirImageControl
  299. {
  300. public MirImageControl TitleLabel, AccountIDLabel, PassLabel;
  301. public MirButton AccountButton, CloseButton, OKButton, PassButton, ViewKeyButton;
  302. public MirTextBox AccountIDTextBox, PasswordTextBox;
  303. private bool _accountIDValid, _passwordValid;
  304. public LoginDialog()
  305. {
  306. Index = 1084;
  307. Library = Libraries.Prguse;
  308. Location = new Point((Settings.ScreenWidth - Size.Width)/2, (Settings.ScreenHeight - Size.Height)/2);
  309. PixelDetect = false;
  310. Size = new Size(328, 220);
  311. TitleLabel = new MirImageControl
  312. {
  313. Index = 30,
  314. Library = Libraries.Title,
  315. Parent = this,
  316. };
  317. TitleLabel.Location = new Point((Size.Width - TitleLabel.Size.Width)/2, 12);
  318. AccountIDLabel = new MirImageControl
  319. {
  320. Index = 31,
  321. Library = Libraries.Title,
  322. Parent = this,
  323. Location = new Point(52, 83),
  324. };
  325. PassLabel = new MirImageControl
  326. {
  327. Index = 32,
  328. Library = Libraries.Title,
  329. Parent = this,
  330. Location = new Point(43, 105)
  331. };
  332. OKButton = new MirButton
  333. {
  334. Enabled = false,
  335. Size = new Size(42,42),
  336. HoverIndex = 321,
  337. Index = 320,
  338. Library = Libraries.Title,
  339. Location = new Point(227, 81),
  340. Parent = this,
  341. PressedIndex = 322
  342. };
  343. OKButton.Click += (o, e) => Login();
  344. AccountButton = new MirButton
  345. {
  346. HoverIndex = 324,
  347. Index = 323,
  348. Library = Libraries.Title,
  349. Location = new Point(60, 163),
  350. Parent = this,
  351. PressedIndex = 325,
  352. };
  353. PassButton = new MirButton
  354. {
  355. HoverIndex = 327,
  356. Index = 326,
  357. Library = Libraries.Title,
  358. Location = new Point(166, 163),
  359. Parent = this,
  360. PressedIndex = 328,
  361. };
  362. ViewKeyButton = new MirButton
  363. {
  364. HoverIndex = 333,
  365. Index = 332,
  366. Library = Libraries.Title,
  367. Location = new Point(60, 189),
  368. Parent = this,
  369. PressedIndex = 334,
  370. };
  371. CloseButton = new MirButton
  372. {
  373. HoverIndex = 330,
  374. Index = 329,
  375. Library = Libraries.Title,
  376. Location = new Point(166, 189),
  377. Parent = this,
  378. PressedIndex = 331,
  379. };
  380. CloseButton.Click += (o, e) => Program.Form.Close();
  381. PasswordTextBox = new MirTextBox
  382. {
  383. Location = new Point(85, 108),
  384. Parent = this,
  385. Password = true,
  386. Size = new Size(136, 15),
  387. MaxLength = Globals.MaxPasswordLength
  388. };
  389. PasswordTextBox.TextBox.TextChanged += PasswordTextBox_TextChanged;
  390. PasswordTextBox.TextBox.KeyPress += TextBox_KeyPress;
  391. PasswordTextBox.Text = Settings.Password;
  392. AccountIDTextBox = new MirTextBox
  393. {
  394. Location = new Point(85, 85),
  395. Parent = this,
  396. Size = new Size(136, 15),
  397. MaxLength = Globals.MaxAccountIDLength
  398. };
  399. AccountIDTextBox.TextBox.TextChanged += AccountIDTextBox_TextChanged;
  400. AccountIDTextBox.TextBox.KeyPress += TextBox_KeyPress;
  401. AccountIDTextBox.Text = Settings.AccountID;
  402. }
  403. private void AccountIDTextBox_TextChanged(object sender, EventArgs e)
  404. {
  405. Regex reg =
  406. new Regex(@"^[A-Za-z0-9]{" + Globals.MinAccountIDLength + "," + Globals.MaxAccountIDLength + "}$");
  407. if (string.IsNullOrEmpty(AccountIDTextBox.Text) || !reg.IsMatch(AccountIDTextBox.TextBox.Text))
  408. {
  409. _accountIDValid = false;
  410. AccountIDTextBox.Border = !string.IsNullOrEmpty(AccountIDTextBox.Text);
  411. AccountIDTextBox.BorderColour = Color.Red;
  412. }
  413. else
  414. {
  415. _accountIDValid = true;
  416. AccountIDTextBox.Border = true;
  417. AccountIDTextBox.BorderColour = Color.Green;
  418. }
  419. }
  420. private void PasswordTextBox_TextChanged(object sender, EventArgs e)
  421. {
  422. Regex reg =
  423. new Regex(@"^[A-Za-z0-9]{" + Globals.MinPasswordLength + "," + Globals.MaxPasswordLength + "}$");
  424. if (string.IsNullOrEmpty(PasswordTextBox.TextBox.Text) || !reg.IsMatch(PasswordTextBox.TextBox.Text))
  425. {
  426. _passwordValid = false;
  427. PasswordTextBox.Border = !string.IsNullOrEmpty(PasswordTextBox.TextBox.Text);
  428. PasswordTextBox.BorderColour = Color.Red;
  429. }
  430. else
  431. {
  432. _passwordValid = true;
  433. PasswordTextBox.Border = true;
  434. PasswordTextBox.BorderColour = Color.Green;
  435. }
  436. RefreshLoginButton();
  437. }
  438. public void TextBox_KeyPress(object sender, KeyPressEventArgs e)
  439. {
  440. if (sender == null || e.KeyChar != (char) Keys.Enter) return;
  441. e.Handled = true;
  442. if (!_accountIDValid)
  443. {
  444. AccountIDTextBox.SetFocus();
  445. return;
  446. }
  447. if (!_passwordValid)
  448. {
  449. PasswordTextBox.SetFocus();
  450. return;
  451. }
  452. if (OKButton.Enabled)
  453. OKButton.InvokeMouseClick(null);
  454. }
  455. private void RefreshLoginButton()
  456. {
  457. OKButton.Enabled = _accountIDValid && _passwordValid;
  458. }
  459. private void Login()
  460. {
  461. OKButton.Enabled = false;
  462. Network.Enqueue(new C.Login {AccountID = AccountIDTextBox.Text, Password = PasswordTextBox.Text});
  463. }
  464. public override void Show()
  465. {
  466. if (Visible) return;
  467. Visible = true;
  468. AccountIDTextBox.SetFocus();
  469. if (Settings.Password != string.Empty && Settings.AccountID != string.Empty)
  470. {
  471. Login();
  472. }
  473. }
  474. public void Clear()
  475. {
  476. AccountIDTextBox.Text = string.Empty;
  477. PasswordTextBox.Text = string.Empty;
  478. }
  479. #region Disposable
  480. protected override void Dispose(bool disposing)
  481. {
  482. if (disposing)
  483. {
  484. TitleLabel = null;
  485. AccountIDLabel = null;
  486. PassLabel = null;
  487. AccountButton = null;
  488. CloseButton = null;
  489. OKButton = null;
  490. PassButton = null;
  491. AccountIDTextBox = null;
  492. PasswordTextBox = null;
  493. }
  494. base.Dispose(disposing);
  495. }
  496. #endregion
  497. }
  498. public sealed class InputKeyDialog : MirImageControl
  499. {
  500. public readonly MirButton KeyEscButton, KeyDelButton, KeyRandButton, KeyEnterButton;
  501. private LoginDialog _loginDialog;
  502. private List<MirButton> _buttons = new List<MirButton>();
  503. private char[] _letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
  504. private char[] _numbers = "0123456789".ToCharArray();
  505. public InputKeyDialog(LoginDialog loginDialog)
  506. {
  507. _loginDialog = loginDialog;
  508. Index = 1080;
  509. Library = Libraries.Prguse;
  510. Location = new Point((Client.Settings.ScreenWidth - Size.Width) / 2 + 285, (Client.Settings.ScreenHeight - Size.Height) / 2 + 150);
  511. Visible = true;
  512. KeyEscButton = new MirButton
  513. {
  514. Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.BtnEsc),
  515. HoverIndex = 301,
  516. Index = 300,
  517. Library = Libraries.Title,
  518. Location = new Point(12, 12),
  519. Parent = this,
  520. PressedIndex = 302,
  521. CenterText = true
  522. };
  523. KeyEscButton.Click += (o, e) => Dispose();
  524. KeyDelButton = new MirButton
  525. {
  526. Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.BtnDelete),
  527. HoverIndex = 304,
  528. Index = 303,
  529. Library = Libraries.Title,
  530. Location = new Point(140, 76),
  531. Parent = this,
  532. PressedIndex = 305,
  533. CenterText = true
  534. };
  535. KeyDelButton.Click += (o, e) => SecureKeyDelete();
  536. KeyEnterButton = new MirButton
  537. {
  538. Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.BtnEnter),
  539. HoverIndex = 307,
  540. Index = 306,
  541. Library = Libraries.Title,
  542. Location = new Point(140, 236),
  543. Parent = this,
  544. PressedIndex = 308,
  545. CenterText = true
  546. };
  547. KeyEnterButton.Click += (o, e) =>
  548. {
  549. KeyPressEventArgs arg = new KeyPressEventArgs((char)Keys.Enter);
  550. _loginDialog.TextBox_KeyPress(o, arg);
  551. };
  552. KeyRandButton = new MirButton
  553. {
  554. Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.BtnRandom),
  555. HoverIndex = 310,
  556. Index = 309,
  557. Library = Libraries.Title,
  558. Location = new Point(76, 236),
  559. Parent = this,
  560. PressedIndex = 311,
  561. CenterText = true
  562. };
  563. KeyRandButton.Click += (o, e) =>
  564. {
  565. _letters = new string(_letters.OrderBy(s => Guid.NewGuid()).ToArray()).ToCharArray();
  566. _numbers = new string(_numbers.OrderBy(s => Guid.NewGuid()).ToArray()).ToCharArray();
  567. UpdateKeys();
  568. };
  569. UpdateKeys();
  570. }
  571. private void DisposeKeys()
  572. {
  573. foreach(MirButton button in _buttons)
  574. {
  575. if (button != null && !button.IsDisposed) button.Dispose();
  576. }
  577. }
  578. private void UpdateKeys()
  579. {
  580. DisposeKeys();
  581. for (int i = 0; i < _numbers.Length; i++)
  582. {
  583. char key = _numbers[i];
  584. MirButton numButton = new MirButton
  585. {
  586. HoverIndex = 1082,
  587. Index = 1081,
  588. Size = new Size(32, 30),
  589. Library = Libraries.Prguse,
  590. Location = new Point(12 + (i % 6 * 32), 44 + (i / 6 * 32)),
  591. Parent = this,
  592. PressedIndex = 1083,
  593. Text = _numbers[i].ToString(),
  594. CenterText = true
  595. };
  596. numButton.Click += (o, e) => SecureKeyPress(key);
  597. _buttons.Add(numButton);
  598. }
  599. for (int i = 0; i < _letters.Length; i++)
  600. {
  601. char key = _letters[i];
  602. MirButton alphButton = new MirButton
  603. {
  604. HoverIndex = 1082,
  605. Index = 1081,
  606. Size = new Size(32, 30),
  607. Library = Libraries.Prguse,
  608. Location = new Point(12 + (i % 6 * 32), 108 + (i / 6 * 32)),
  609. Parent = this,
  610. PressedIndex = 1083,
  611. Text = _letters[i].ToString(),
  612. CenterText = true
  613. };
  614. alphButton.Click += (o, e) => SecureKeyPress(key);
  615. _buttons.Add(alphButton);
  616. }
  617. }
  618. private void SecureKeyPress(char chr)
  619. {
  620. MirTextBox currentTextBox = GetFocussedTextBox();
  621. string keyToAdd = chr.ToString();
  622. if (CMain.IsKeyLocked(Keys.CapsLock))
  623. keyToAdd = keyToAdd.ToUpper();
  624. else
  625. keyToAdd = keyToAdd.ToLower();
  626. currentTextBox.Text += keyToAdd;
  627. currentTextBox.TextBox.SelectionLength = 0;
  628. currentTextBox.TextBox.SelectionStart = currentTextBox.Text.Length;
  629. }
  630. private void SecureKeyDelete()
  631. {
  632. MirTextBox currentTextBox = GetFocussedTextBox();
  633. if (currentTextBox.TextBox.SelectionLength > 0)
  634. {
  635. currentTextBox.Text = currentTextBox.Text.Remove(currentTextBox.TextBox.SelectionStart, currentTextBox.TextBox.SelectionLength);
  636. }
  637. else if (currentTextBox.Text.Length > 0)
  638. {
  639. currentTextBox.Text = currentTextBox.Text.Remove(currentTextBox.Text.Length - 1);
  640. }
  641. currentTextBox.TextBox.SelectionStart = currentTextBox.Text.Length;
  642. }
  643. private MirTextBox GetFocussedTextBox()
  644. {
  645. if (_loginDialog.AccountIDTextBox.TextBox.Focused)
  646. return _loginDialog.AccountIDTextBox;
  647. else
  648. return _loginDialog.PasswordTextBox;
  649. }
  650. #region Disposable
  651. protected override void Dispose(bool disposing)
  652. {
  653. base.Dispose(disposing);
  654. DisposeKeys();
  655. }
  656. #endregion
  657. }
  658. public sealed class NewAccountDialog : MirImageControl
  659. {
  660. public MirButton OKButton, CancelButton;
  661. public MirTextBox AccountIDTextBox,
  662. Password1TextBox,
  663. Password2TextBox,
  664. EMailTextBox,
  665. UserNameTextBox,
  666. BirthDateTextBox,
  667. QuestionTextBox,
  668. AnswerTextBox;
  669. public MirLabel Description;
  670. private bool _accountIDValid,
  671. _password1Valid,
  672. _password2Valid,
  673. _eMailValid = true,
  674. _userNameValid = true,
  675. _birthDateValid = true,
  676. _questionValid = true,
  677. _answerValid = true;
  678. public NewAccountDialog()
  679. {
  680. Index = 63;
  681. Library = Libraries.Prguse;
  682. Size = new Size();
  683. Location = new Point((Settings.ScreenWidth - Size.Width) / 2, (Settings.ScreenHeight - Size.Height) / 2);
  684. CancelButton = new MirButton
  685. {
  686. HoverIndex = 204,
  687. Index = 203,
  688. Library = Libraries.Title,
  689. Location = new Point(409, 425),
  690. Parent = this,
  691. PressedIndex = 205
  692. };
  693. CancelButton.Click += (o, e) => Dispose();
  694. OKButton = new MirButton
  695. {
  696. Enabled = false,
  697. HoverIndex = 201,
  698. Index = 200,
  699. Library = Libraries.Title,
  700. Location = new Point(135, 425),
  701. Parent = this,
  702. PressedIndex = 202,
  703. };
  704. OKButton.Click += (o, e) => CreateAccount();
  705. Password1TextBox = new MirTextBox
  706. {
  707. Border = true,
  708. BorderColour = Color.Gray,
  709. Location = new Point(226, 129),
  710. MaxLength = Globals.MaxPasswordLength,
  711. Parent = this,
  712. Password = true,
  713. Size = new Size(136, 18),
  714. TextBox = { MaxLength = Globals.MaxPasswordLength },
  715. };
  716. Password1TextBox.TextBox.TextChanged += Password1TextBox_TextChanged;
  717. Password1TextBox.TextBox.GotFocus += PasswordTextBox_GotFocus;
  718. Password2TextBox = new MirTextBox
  719. {
  720. Border = true,
  721. BorderColour = Color.Gray,
  722. Location = new Point(226, 155),
  723. MaxLength = Globals.MaxPasswordLength,
  724. Parent = this,
  725. Password = true,
  726. Size = new Size(136, 18),
  727. TextBox = { MaxLength = Globals.MaxPasswordLength },
  728. };
  729. Password2TextBox.TextBox.TextChanged += Password2TextBox_TextChanged;
  730. Password2TextBox.TextBox.GotFocus += PasswordTextBox_GotFocus;
  731. UserNameTextBox = new MirTextBox
  732. {
  733. Border = true,
  734. BorderColour = Color.Gray,
  735. Location = new Point(226, 189),
  736. MaxLength = 20,
  737. Parent = this,
  738. Size = new Size(136, 18),
  739. TextBox = { MaxLength = 20 },
  740. };
  741. UserNameTextBox.TextBox.TextChanged += UserNameTextBox_TextChanged;
  742. UserNameTextBox.TextBox.GotFocus += UserNameTextBox_GotFocus;
  743. BirthDateTextBox = new MirTextBox
  744. {
  745. Border = true,
  746. BorderColour = Color.Gray,
  747. Location = new Point(226, 215),
  748. MaxLength = 10,
  749. Parent = this,
  750. Size = new Size(136, 18),
  751. TextBox = { MaxLength = 10 },
  752. };
  753. BirthDateTextBox.TextBox.TextChanged += BirthDateTextBox_TextChanged;
  754. BirthDateTextBox.TextBox.GotFocus += BirthDateTextBox_GotFocus;
  755. QuestionTextBox = new MirTextBox
  756. {
  757. Border = true,
  758. BorderColour = Color.Gray,
  759. Location = new Point(226, 250),
  760. MaxLength = 30,
  761. Parent = this,
  762. Size = new Size(190, 18),
  763. TextBox = { MaxLength = 30 },
  764. };
  765. QuestionTextBox.TextBox.TextChanged += QuestionTextBox_TextChanged;
  766. QuestionTextBox.TextBox.GotFocus += QuestionTextBox_GotFocus;
  767. AnswerTextBox = new MirTextBox
  768. {
  769. Border = true,
  770. BorderColour = Color.Gray,
  771. Location = new Point(226, 276),
  772. MaxLength = 30,
  773. Parent = this,
  774. Size = new Size(190, 18),
  775. TextBox = { MaxLength = 30 },
  776. };
  777. AnswerTextBox.TextBox.TextChanged += AnswerTextBox_TextChanged;
  778. AnswerTextBox.TextBox.GotFocus += AnswerTextBox_GotFocus;
  779. EMailTextBox = new MirTextBox
  780. {
  781. Border = true,
  782. BorderColour = Color.Gray,
  783. Location = new Point(226, 311),
  784. MaxLength = 50,
  785. Parent = this,
  786. Size = new Size(136, 18),
  787. TextBox = { MaxLength = 50 },
  788. };
  789. EMailTextBox.TextBox.TextChanged += EMailTextBox_TextChanged;
  790. EMailTextBox.TextBox.GotFocus += EMailTextBox_GotFocus;
  791. Description = new MirLabel
  792. {
  793. Border = true,
  794. BorderColour = Color.Gray,
  795. Location = new Point(15, 340),
  796. Parent = this,
  797. Size = new Size(300, 70),
  798. Visible = false
  799. };
  800. AccountIDTextBox = new MirTextBox
  801. {
  802. Border = true,
  803. BorderColour = Color.Gray,
  804. Location = new Point(226, 103),
  805. MaxLength = Globals.MaxAccountIDLength,
  806. Parent = this,
  807. Size = new Size(136, 18),
  808. };
  809. AccountIDTextBox.TextBox.MaxLength = Globals.MaxAccountIDLength;
  810. AccountIDTextBox.TextBox.TextChanged += AccountIDTextBox_TextChanged;
  811. AccountIDTextBox.TextBox.GotFocus += AccountIDTextBox_GotFocus;
  812. }
  813. private void AccountIDTextBox_TextChanged(object sender, EventArgs e)
  814. {
  815. Regex reg = new Regex(@"^[A-Za-z0-9]{" + Globals.MinAccountIDLength + "," + Globals.MaxAccountIDLength + "}$");
  816. if (string.IsNullOrEmpty(AccountIDTextBox.Text) || !reg.IsMatch(AccountIDTextBox.Text))
  817. {
  818. _accountIDValid = false;
  819. AccountIDTextBox.BorderColour = Color.Red;
  820. }
  821. else
  822. {
  823. _accountIDValid = true;
  824. AccountIDTextBox.BorderColour = Color.Green;
  825. }
  826. RefreshConfirmButton();
  827. }
  828. private void Password1TextBox_TextChanged(object sender, EventArgs e)
  829. {
  830. Regex reg = new Regex(@"^[A-Za-z0-9]{" + Globals.MinPasswordLength + "," + Globals.MaxPasswordLength + "}$");
  831. if (string.IsNullOrEmpty(Password1TextBox.Text) || !reg.IsMatch(Password1TextBox.Text))
  832. {
  833. _password1Valid = false;
  834. Password1TextBox.BorderColour = Color.Red;
  835. }
  836. else
  837. {
  838. _password1Valid = true;
  839. Password1TextBox.BorderColour = Color.Green;
  840. }
  841. Password2TextBox_TextChanged(sender, e);
  842. }
  843. private void Password2TextBox_TextChanged(object sender, EventArgs e)
  844. {
  845. Regex reg = new Regex(@"^[A-Za-z0-9]{" + Globals.MinPasswordLength + "," + Globals.MaxPasswordLength + "}$");
  846. if (string.IsNullOrEmpty(Password2TextBox.Text) || !reg.IsMatch(Password2TextBox.Text) ||
  847. Password1TextBox.Text != Password2TextBox.Text)
  848. {
  849. _password2Valid = false;
  850. Password2TextBox.BorderColour = Color.Red;
  851. }
  852. else
  853. {
  854. _password2Valid = true;
  855. Password2TextBox.BorderColour = Color.Green;
  856. }
  857. RefreshConfirmButton();
  858. }
  859. private void EMailTextBox_TextChanged(object sender, EventArgs e)
  860. {
  861. Regex reg = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
  862. if (string.IsNullOrEmpty(EMailTextBox.Text))
  863. {
  864. _eMailValid = true;
  865. EMailTextBox.BorderColour = Color.Gray;
  866. }
  867. else if (!reg.IsMatch(EMailTextBox.Text) || EMailTextBox.Text.Length > 50)
  868. {
  869. _eMailValid = false;
  870. EMailTextBox.BorderColour = Color.Red;
  871. }
  872. else
  873. {
  874. _eMailValid = true;
  875. EMailTextBox.BorderColour = Color.Green;
  876. }
  877. RefreshConfirmButton();
  878. }
  879. private void UserNameTextBox_TextChanged(object sender, EventArgs e)
  880. {
  881. if (string.IsNullOrEmpty(UserNameTextBox.Text))
  882. {
  883. _userNameValid = true;
  884. UserNameTextBox.BorderColour = Color.Gray;
  885. }
  886. else if (UserNameTextBox.Text.Length > 20)
  887. {
  888. _userNameValid = false;
  889. UserNameTextBox.BorderColour = Color.Red;
  890. }
  891. else
  892. {
  893. _userNameValid = true;
  894. UserNameTextBox.BorderColour = Color.Green;
  895. }
  896. RefreshConfirmButton();
  897. }
  898. private void BirthDateTextBox_TextChanged(object sender, EventArgs e)
  899. {
  900. DateTime dateTime;
  901. if (string.IsNullOrEmpty(BirthDateTextBox.Text))
  902. {
  903. _birthDateValid = true;
  904. BirthDateTextBox.BorderColour = Color.Gray;
  905. }
  906. else if (!DateTime.TryParse(BirthDateTextBox.Text, out dateTime) || BirthDateTextBox.Text.Length > 10)
  907. {
  908. _birthDateValid = false;
  909. BirthDateTextBox.BorderColour = Color.Red;
  910. }
  911. else
  912. {
  913. _birthDateValid = true;
  914. BirthDateTextBox.BorderColour = Color.Green;
  915. }
  916. RefreshConfirmButton();
  917. }
  918. private void QuestionTextBox_TextChanged(object sender, EventArgs e)
  919. {
  920. if (string.IsNullOrEmpty(QuestionTextBox.Text))
  921. {
  922. _questionValid = true;
  923. QuestionTextBox.BorderColour = Color.Gray;
  924. }
  925. else if (QuestionTextBox.Text.Length > 30)
  926. {
  927. _questionValid = false;
  928. QuestionTextBox.BorderColour = Color.Red;
  929. }
  930. else
  931. {
  932. _questionValid = true;
  933. QuestionTextBox.BorderColour = Color.Green;
  934. }
  935. RefreshConfirmButton();
  936. }
  937. private void AnswerTextBox_TextChanged(object sender, EventArgs e)
  938. {
  939. if (string.IsNullOrEmpty(AnswerTextBox.Text))
  940. {
  941. _answerValid = true;
  942. AnswerTextBox.BorderColour = Color.Gray;
  943. }
  944. else if (AnswerTextBox.Text.Length > 30)
  945. {
  946. _answerValid = false;
  947. AnswerTextBox.BorderColour = Color.Red;
  948. }
  949. else
  950. {
  951. _answerValid = true;
  952. AnswerTextBox.BorderColour = Color.Green;
  953. }
  954. RefreshConfirmButton();
  955. }
  956. private void AccountIDTextBox_GotFocus(object sender, EventArgs e)
  957. {
  958. Description.Visible = true;
  959. Description.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.AccountIdDescription), Globals.MinAccountIDLength, Globals.MaxAccountIDLength);
  960. }
  961. private void PasswordTextBox_GotFocus(object sender, EventArgs e)
  962. {
  963. Description.Visible = true;
  964. Description.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.PasswordDescription), Globals.MinPasswordLength, Globals.MaxPasswordLength);
  965. }
  966. private void EMailTextBox_GotFocus(object sender, EventArgs e)
  967. {
  968. Description.Visible = true;
  969. Description.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.EmailAddressDescription);
  970. }
  971. private void UserNameTextBox_GotFocus(object sender, EventArgs e)
  972. {
  973. Description.Visible = true;
  974. Description.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.UserNameDescription);
  975. }
  976. private void BirthDateTextBox_GotFocus(object sender, EventArgs e)
  977. {
  978. Description.Visible = true;
  979. Description.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.BirthDateDescription),
  980. Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern.ToUpper());
  981. }
  982. private void QuestionTextBox_GotFocus(object sender, EventArgs e)
  983. {
  984. Description.Visible = true;
  985. Description.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SecretQuestionDescription);
  986. }
  987. private void AnswerTextBox_GotFocus(object sender, EventArgs e)
  988. {
  989. Description.Visible = true;
  990. Description.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SecretAnswerDescription);
  991. }
  992. private void RefreshConfirmButton()
  993. {
  994. OKButton.Enabled = _accountIDValid && _password1Valid && _password2Valid && _eMailValid &&
  995. _userNameValid && _birthDateValid && _questionValid && _answerValid;
  996. }
  997. private void CreateAccount()
  998. {
  999. OKButton.Enabled = false;
  1000. Network.Enqueue(new C.NewAccount
  1001. {
  1002. AccountID = AccountIDTextBox.Text,
  1003. Password = Password1TextBox.Text,
  1004. EMailAddress = EMailTextBox.Text,
  1005. BirthDate = !string.IsNullOrEmpty(BirthDateTextBox.Text)
  1006. ? DateTime.Parse(BirthDateTextBox.Text)
  1007. : DateTime.MinValue,
  1008. UserName = UserNameTextBox.Text,
  1009. SecretQuestion = QuestionTextBox.Text,
  1010. SecretAnswer = AnswerTextBox.Text,
  1011. });
  1012. }
  1013. public override void Show()
  1014. {
  1015. if (Visible) return;
  1016. Visible = true;
  1017. AccountIDTextBox.SetFocus();
  1018. }
  1019. #region Disposable
  1020. protected override void Dispose(bool disposing)
  1021. {
  1022. if (disposing)
  1023. {
  1024. OKButton = null;
  1025. CancelButton = null;
  1026. AccountIDTextBox = null;
  1027. Password1TextBox = null;
  1028. Password2TextBox = null;
  1029. EMailTextBox = null;
  1030. UserNameTextBox = null;
  1031. BirthDateTextBox = null;
  1032. QuestionTextBox = null;
  1033. AnswerTextBox = null;
  1034. Description = null;
  1035. }
  1036. base.Dispose(disposing);
  1037. }
  1038. #endregion
  1039. }
  1040. public sealed class ChangePasswordDialog : MirImageControl
  1041. {
  1042. public readonly MirButton OKButton,
  1043. CancelButton;
  1044. public readonly MirTextBox AccountIDTextBox,
  1045. CurrentPasswordTextBox,
  1046. NewPassword1TextBox,
  1047. NewPassword2TextBox;
  1048. private bool _accountIDValid,
  1049. _currentPasswordValid,
  1050. _newPassword1Valid,
  1051. _newPassword2Valid;
  1052. public ChangePasswordDialog()
  1053. {
  1054. Index = 50;
  1055. Library = Libraries.Prguse;
  1056. Location = new Point((Settings.ScreenWidth - Size.Width) / 2, (Settings.ScreenHeight - Size.Height) / 2);
  1057. CancelButton = new MirButton
  1058. {
  1059. HoverIndex = 111,
  1060. Index = 110,
  1061. Library = Libraries.Title,
  1062. Location = new Point(222, 236),
  1063. Parent = this,
  1064. PressedIndex = 112
  1065. };
  1066. CancelButton.Click += (o, e) => Dispose();
  1067. OKButton = new MirButton
  1068. {
  1069. Enabled = false,
  1070. HoverIndex = 108,
  1071. Index = 107,
  1072. Library = Libraries.Title,
  1073. Location = new Point(80, 236),
  1074. Parent = this,
  1075. PressedIndex = 109,
  1076. };
  1077. OKButton.Click += (o, e) => ChangePassword();
  1078. AccountIDTextBox = new MirTextBox
  1079. {
  1080. Border = true,
  1081. BorderColour = Color.Gray,
  1082. Location = new Point(178, 75),
  1083. MaxLength = Globals.MaxAccountIDLength,
  1084. Parent = this,
  1085. Size = new Size(136, 18),
  1086. };
  1087. AccountIDTextBox.SetFocus();
  1088. AccountIDTextBox.TextBox.MaxLength = Globals.MaxAccountIDLength;
  1089. AccountIDTextBox.TextBox.TextChanged += AccountIDTextBox_TextChanged;
  1090. CurrentPasswordTextBox = new MirTextBox
  1091. {
  1092. Border = true,
  1093. BorderColour = Color.Gray,
  1094. Location = new Point(178, 113),
  1095. MaxLength = Globals.MaxPasswordLength,
  1096. Parent = this,
  1097. Password = true,
  1098. Size = new Size(136, 18),
  1099. TextBox = { MaxLength = Globals.MaxPasswordLength },
  1100. };
  1101. CurrentPasswordTextBox.TextBox.TextChanged += CurrentPasswordTextBox_TextChanged;
  1102. NewPassword1TextBox = new MirTextBox
  1103. {
  1104. Border = true,
  1105. BorderColour = Color.Gray,
  1106. Location = new Point(178, 151),
  1107. MaxLength = Globals.MaxPasswordLength,
  1108. Parent = this,
  1109. Password = true,
  1110. Size = new Size(136, 18),
  1111. TextBox = { MaxLength = Globals.MaxPasswordLength },
  1112. };
  1113. NewPassword1TextBox.TextBox.TextChanged += NewPassword1TextBox_TextChanged;
  1114. NewPassword2TextBox = new MirTextBox
  1115. {
  1116. Border = true,
  1117. BorderColour = Color.Gray,
  1118. Location = new Point(178, 188),
  1119. MaxLength = Globals.MaxPasswordLength,
  1120. Parent = this,
  1121. Password = true,
  1122. Size = new Size(136, 18),
  1123. TextBox = { MaxLength = Globals.MaxPasswordLength },
  1124. };
  1125. NewPassword2TextBox.TextBox.TextChanged += NewPassword2TextBox_TextChanged;
  1126. }
  1127. void RefreshConfirmButton()
  1128. {
  1129. OKButton.Enabled = _accountIDValid && _currentPasswordValid && _newPassword1Valid && _newPassword2Valid;
  1130. }
  1131. private void AccountIDTextBox_TextChanged(object sender, EventArgs e)
  1132. {
  1133. Regex reg = new Regex(@"^[A-Za-z0-9]{" + Globals.MinAccountIDLength + "," + Globals.MaxAccountIDLength + "}$");
  1134. if (string.IsNullOrEmpty(AccountIDTextBox.Text) || !reg.IsMatch(AccountIDTextBox.Text))
  1135. {
  1136. _accountIDValid = false;
  1137. AccountIDTextBox.BorderColour = Color.Red;
  1138. }
  1139. else
  1140. {
  1141. _accountIDValid = true;
  1142. AccountIDTextBox.BorderColour = Color.Green;
  1143. }
  1144. RefreshConfirmButton();
  1145. }
  1146. private void CurrentPasswordTextBox_TextChanged(object sender, EventArgs e)
  1147. {
  1148. Regex reg = new Regex(@"^[A-Za-z0-9]{" + Globals.MinPasswordLength + "," + Globals.MaxPasswordLength + "}$");
  1149. if (string.IsNullOrEmpty(CurrentPasswordTextBox.Text) || !reg.IsMatch(CurrentPasswordTextBox.Text))
  1150. {
  1151. _currentPasswordValid = false;
  1152. CurrentPasswordTextBox.BorderColour = Color.Red;
  1153. }
  1154. else
  1155. {
  1156. _currentPasswordValid = true;
  1157. CurrentPasswordTextBox.BorderColour = Color.Green;
  1158. }
  1159. RefreshConfirmButton();
  1160. }
  1161. private void NewPassword1TextBox_TextChanged(object sender, EventArgs e)
  1162. {
  1163. Regex reg = new Regex(@"^[A-Za-z0-9]{" + Globals.MinPasswordLength + "," + Globals.MaxPasswordLength + "}$");
  1164. if (string.IsNullOrEmpty(NewPassword1TextBox.Text) || !reg.IsMatch(NewPassword1TextBox.Text))
  1165. {
  1166. _newPassword1Valid = false;
  1167. NewPassword1TextBox.BorderColour = Color.Red;
  1168. }
  1169. else
  1170. {
  1171. _newPassword1Valid = true;
  1172. NewPassword1TextBox.BorderColour = Color.Green;
  1173. }
  1174. NewPassword2TextBox_TextChanged(sender, e);
  1175. }
  1176. private void NewPassword2TextBox_TextChanged(object sender, EventArgs e)
  1177. {
  1178. if (NewPassword1TextBox.Text == NewPassword2TextBox.Text)
  1179. {
  1180. _newPassword2Valid = _newPassword1Valid;
  1181. NewPassword2TextBox.BorderColour = NewPassword1TextBox.BorderColour;
  1182. }
  1183. else
  1184. {
  1185. _newPassword2Valid = false;
  1186. NewPassword2TextBox.BorderColour = Color.Red;
  1187. }
  1188. RefreshConfirmButton();
  1189. }
  1190. private void ChangePassword()
  1191. {
  1192. OKButton.Enabled = false;
  1193. Network.Enqueue(new C.ChangePassword
  1194. {
  1195. AccountID = AccountIDTextBox.Text,
  1196. CurrentPassword = CurrentPasswordTextBox.Text,
  1197. NewPassword = NewPassword1TextBox.Text
  1198. });
  1199. }
  1200. public override void Show()
  1201. {
  1202. if (Visible) return;
  1203. Visible = true;
  1204. AccountIDTextBox.SetFocus();
  1205. }
  1206. }
  1207. #region Disposable
  1208. protected override void Dispose(bool disposing)
  1209. {
  1210. if (disposing)
  1211. {
  1212. _background = null;
  1213. Version = null;
  1214. _login = null;
  1215. _account = null;
  1216. _password = null;
  1217. _connectBox = null;
  1218. }
  1219. base.Dispose(disposing);
  1220. }
  1221. #endregion
  1222. }
  1223. }