| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368 |
- using System.Security.Cryptography;
- using System.Text.RegularExpressions;
- using Client.MirControls;
- using Client.MirGraphics;
- using Client.MirNetwork;
- using Client.MirSounds;
- using S = ServerPackets;
- using C = ClientPackets;
- namespace Client.MirScenes
- {
- public sealed class LoginScene : MirScene
- {
- private MirAnimatedControl _background;
- public MirLabel Version;
- private LoginDialog _login;
- private NewAccountDialog _account;
- private ChangePasswordDialog _password;
- private MirMessageBox _connectBox;
- private InputKeyDialog _ViewKey;
- public MirImageControl TestLabel, ViolenceLabel, MinorLabel, YouthLabel;
- public LoginScene()
- {
- SoundManager.PlayMusic(SoundList.IntroMusic, true);
- Disposing += (o, e) => SoundManager.StopMusic();
- _background = new MirAnimatedControl
- {
- Animated = false,
- AnimationCount = 19,
- AnimationDelay = 100,
- Index = 0,
- Library = Libraries.ChrSel,
- Loop = false,
- Parent = this,
- };
- _login = new LoginDialog {Parent = _background, Visible = false};
- _login.AccountButton.Click += (o, e) =>
- {
- _login.Hide();
- if(_ViewKey != null && !_ViewKey.IsDisposed) _ViewKey.Dispose();
- _account = new NewAccountDialog { Parent = _background };
- _account.Disposing += (o1, e1) => _login.Show();
- };
- _login.PassButton.Click += (o, e) =>
- {
- OpenPasswordChangeDialog(string.Empty, string.Empty);
- };
- _login.ViewKeyButton.Click += (o, e) => //ADD
- {
- if (_ViewKey != null && !_ViewKey.IsDisposed) return;
- _ViewKey = new InputKeyDialog(_login) { Parent = _background };
- };
- Version = new MirLabel
- {
- AutoSize = true,
- BackColour = Color.FromArgb(200, 50, 50, 50),
- Border = true,
- BorderColour = Color.Black,
- Location = new Point(5, Settings.ScreenHeight - 20),
- Parent = _background,
- Text = string.Format("Build: {0}.{1}.{2}", Globals.ProductCodename, Settings.UseTestConfig ? "Debug" : "Release", Application.ProductVersion),
- };
- TestLabel = new MirImageControl
- {
- Index = 79,
- Library = Libraries.Prguse,
- Parent = this,
- Location = new Point(Settings.ScreenWidth - 116, 10),
- Visible = Settings.UseTestConfig
- };
- _connectBox = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AttemptingConnectServer), MirMessageBoxButtons.Cancel);
- _connectBox.CancelButton.Click += (o, e) => Program.Form.Close();
- Shown += (sender, args) =>
- {
- Network.Connect();
- _connectBox.Show();
- };
- }
- public override void Process()
- {
- if (!Network.Connected && _connectBox.Label != null)
- _connectBox.Label.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.AttemptingConnect),"\n\n", Network.ConnectAttempt);
- }
- public override void ProcessPacket(Packet p)
- {
- switch (p.Index)
- {
- case (short)ServerPacketIds.Connected:
- Network.Connected = true;
- SendVersion();
- break;
- case (short)ServerPacketIds.ClientVersion:
- ClientVersion((S.ClientVersion) p);
- break;
- case (short)ServerPacketIds.NewAccount:
- NewAccount((S.NewAccount) p);
- break;
- case (short)ServerPacketIds.ChangePassword:
- ChangePassword((S.ChangePassword) p);
- break;
- case (short)ServerPacketIds.ChangePasswordBanned:
- ChangePassword((S.ChangePasswordBanned) p);
- break;
- case (short)ServerPacketIds.Login:
- Login((S.Login) p);
- break;
- case (short)ServerPacketIds.LoginBanned:
- Login((S.LoginBanned) p);
- break;
- case (short)ServerPacketIds.LoginSuccess:
- Login((S.LoginSuccess) p);
- break;
- default:
- base.ProcessPacket(p);
- break;
- }
- }
- private void SendVersion()
- {
- _connectBox.Label.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SendingClientVersion);
- C.ClientVersion p = new C.ClientVersion();
- try
- {
- byte[] sum;
- using (MD5 md5 = MD5.Create())
- using (FileStream stream = File.OpenRead(Application.ExecutablePath))
- sum = md5.ComputeHash(stream);
- p.VersionHash = sum;
- Network.Enqueue(p);
- }
- catch (Exception ex)
- {
- if (Settings.LogErrors) CMain.SaveError(ex.ToString());
- }
- }
- private void ClientVersion(S.ClientVersion p)
- {
- switch (p.Result)
- {
- case 0:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.WrongVersionPleaseUpdateGame), true);
- Network.Disconnect();
- break;
- case 1:
- _connectBox.Dispose();
- _login.Show();
- break;
- }
- }
- private void OpenPasswordChangeDialog(string autoFillID, string autoFillPassword)
- {
- _login.Hide();
- if (_ViewKey != null && !_ViewKey.IsDisposed) _ViewKey.Dispose();
- _password = new ChangePasswordDialog { Parent = _background };
- _password.AccountIDTextBox.Text = autoFillID;
- _password.CurrentPasswordTextBox.Text = autoFillPassword;
- _password.Disposing += (o1, e1) => _login.Show();
- }
- private void NewAccount(S.NewAccount p)
- {
- _account.OKButton.Enabled = true;
- switch (p.Result)
- {
- case 0:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AccountCreationDisabled));
- _account.Dispose();
- break;
- case 1:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AccountIdNotAcceptable));
- _account.AccountIDTextBox.SetFocus();
- break;
- case 2:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.PasswordNotAcceptable));
- _account.Password1TextBox.SetFocus();
- break;
- case 3:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.EmailAddressNotAcceptable));
- _account.EMailTextBox.SetFocus();
- break;
- case 4:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.UserNameNotAcceptable));
- _account.UserNameTextBox.SetFocus();
- break;
- case 5:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SecretQuestionNotAcceptable));
- _account.QuestionTextBox.SetFocus();
- break;
- case 6:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SecretAnswerNotAcceptable));
- _account.AnswerTextBox.SetFocus();
- break;
- case 7:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AccountIdAlreadyExists));
- _account.AccountIDTextBox.Text = string.Empty;
- _account.AccountIDTextBox.SetFocus();
- break;
- case 8:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AccountCreatedSuccessfully));
- _account.Dispose();
- break;
- }
- }
- private void ChangePassword(S.ChangePassword p)
- {
- _password.OKButton.Enabled = true;
- switch (p.Result)
- {
- case 0:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.PasswordChangingDisabled));
- _password.Dispose();
- break;
- case 1:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AccountIdNotAcceptable));
- _password.AccountIDTextBox.SetFocus();
- break;
- case 2:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.CurrentPasswordNotAcceptable));
- _password.CurrentPasswordTextBox.SetFocus();
- break;
- case 3:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NewPasswordNotAcceptable));
- _password.NewPassword1TextBox.SetFocus();
- break;
- case 4:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NoAccountID));
- _password.AccountIDTextBox.SetFocus();
- break;
- case 5:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.IncorrectPasswordAccountID));
- _password.CurrentPasswordTextBox.SetFocus();
- _password.CurrentPasswordTextBox.Text = string.Empty;
- break;
- case 6:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.PasswordChangedSuccessfully));
- _password.Dispose();
- break;
- }
- }
- private void ChangePassword(S.ChangePasswordBanned p)
- {
- _password.Dispose();
- TimeSpan d = p.ExpiryDate - CMain.Now;
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.AccountBannedReasonDuration), p.Reason,
- p.ExpiryDate, Math.Floor(d.TotalHours), d.Minutes, d.Seconds ));
- }
- private void Login(S.Login p)
- {
- _login.OKButton.Enabled = true;
- switch (p.Result)
- {
- case 0:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.LoginDisabled));
- _login.Clear();
- break;
- case 1:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AccountIdNotAcceptable));
- _login.AccountIDTextBox.SetFocus();
- break;
- case 2:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.PasswordNotAcceptable));
- _login.PasswordTextBox.SetFocus();
- break;
- case 3:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NoAccountID));
- _login.PasswordTextBox.SetFocus();
- break;
- case 4:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.IncorrectPasswordAccountID));
- _login.PasswordTextBox.Text = string.Empty;
- _login.PasswordTextBox.SetFocus();
- break;
- case 5:
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.AccountPasswordMustChangeBeforeLogin));
- OpenPasswordChangeDialog(_login.AccountIDTextBox.Text, _login.PasswordTextBox.Text);
- _login.PasswordTextBox.Text = string.Empty;
- break;
- }
- }
- private void Login(S.LoginBanned p)
- {
- _login.OKButton.Enabled = true;
- TimeSpan d = p.ExpiryDate - CMain.Now;
- MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.AccountBannedReasonDuration), p.Reason,
- p.ExpiryDate, Math.Floor(d.TotalHours), d.Minutes, d.Seconds));
- }
- private void Login(S.LoginSuccess p)
- {
- Enabled = false;
- _login.Dispose();
- if(_ViewKey != null && !_ViewKey.IsDisposed) _ViewKey.Dispose();
- SoundManager.PlaySound(SoundList.LoginEffect);
- _background.Animated = true;
- _background.AfterAnimation += (o, e) =>
- {
- Dispose();
- ActiveScene = new SelectScene(p.Characters);
- };
- }
- public sealed class LoginDialog : MirImageControl
- {
- public MirImageControl TitleLabel, AccountIDLabel, PassLabel;
- public MirButton AccountButton, CloseButton, OKButton, PassButton, ViewKeyButton;
- public MirTextBox AccountIDTextBox, PasswordTextBox;
- private bool _accountIDValid, _passwordValid;
- public LoginDialog()
- {
- Index = 1084;
- Library = Libraries.Prguse;
- Location = new Point((Settings.ScreenWidth - Size.Width)/2, (Settings.ScreenHeight - Size.Height)/2);
- PixelDetect = false;
- Size = new Size(328, 220);
- TitleLabel = new MirImageControl
- {
- Index = 30,
- Library = Libraries.Title,
- Parent = this,
- };
- TitleLabel.Location = new Point((Size.Width - TitleLabel.Size.Width)/2, 12);
- AccountIDLabel = new MirImageControl
- {
- Index = 31,
- Library = Libraries.Title,
- Parent = this,
- Location = new Point(52, 83),
- };
- PassLabel = new MirImageControl
- {
- Index = 32,
- Library = Libraries.Title,
- Parent = this,
- Location = new Point(43, 105)
- };
- OKButton = new MirButton
- {
- Enabled = false,
- Size = new Size(42,42),
- HoverIndex = 321,
- Index = 320,
- Library = Libraries.Title,
- Location = new Point(227, 81),
- Parent = this,
- PressedIndex = 322
- };
- OKButton.Click += (o, e) => Login();
- AccountButton = new MirButton
- {
- HoverIndex = 324,
- Index = 323,
- Library = Libraries.Title,
- Location = new Point(60, 163),
- Parent = this,
- PressedIndex = 325,
- };
- PassButton = new MirButton
- {
- HoverIndex = 327,
- Index = 326,
- Library = Libraries.Title,
- Location = new Point(166, 163),
- Parent = this,
- PressedIndex = 328,
- };
- ViewKeyButton = new MirButton
- {
- HoverIndex = 333,
- Index = 332,
- Library = Libraries.Title,
- Location = new Point(60, 189),
- Parent = this,
- PressedIndex = 334,
- };
- CloseButton = new MirButton
- {
- HoverIndex = 330,
- Index = 329,
- Library = Libraries.Title,
- Location = new Point(166, 189),
- Parent = this,
- PressedIndex = 331,
- };
- CloseButton.Click += (o, e) => Program.Form.Close();
- PasswordTextBox = new MirTextBox
- {
- Location = new Point(85, 108),
- Parent = this,
- Password = true,
- Size = new Size(136, 15),
- MaxLength = Globals.MaxPasswordLength
- };
- PasswordTextBox.TextBox.TextChanged += PasswordTextBox_TextChanged;
- PasswordTextBox.TextBox.KeyPress += TextBox_KeyPress;
- PasswordTextBox.Text = Settings.Password;
- AccountIDTextBox = new MirTextBox
- {
- Location = new Point(85, 85),
- Parent = this,
- Size = new Size(136, 15),
- MaxLength = Globals.MaxAccountIDLength
- };
- AccountIDTextBox.TextBox.TextChanged += AccountIDTextBox_TextChanged;
- AccountIDTextBox.TextBox.KeyPress += TextBox_KeyPress;
- AccountIDTextBox.Text = Settings.AccountID;
- }
- private void AccountIDTextBox_TextChanged(object sender, EventArgs e)
- {
- Regex reg =
- new Regex(@"^[A-Za-z0-9]{" + Globals.MinAccountIDLength + "," + Globals.MaxAccountIDLength + "}$");
- if (string.IsNullOrEmpty(AccountIDTextBox.Text) || !reg.IsMatch(AccountIDTextBox.TextBox.Text))
- {
- _accountIDValid = false;
- AccountIDTextBox.Border = !string.IsNullOrEmpty(AccountIDTextBox.Text);
- AccountIDTextBox.BorderColour = Color.Red;
- }
- else
- {
- _accountIDValid = true;
- AccountIDTextBox.Border = true;
- AccountIDTextBox.BorderColour = Color.Green;
- }
- }
- private void PasswordTextBox_TextChanged(object sender, EventArgs e)
- {
- Regex reg =
- new Regex(@"^[A-Za-z0-9]{" + Globals.MinPasswordLength + "," + Globals.MaxPasswordLength + "}$");
- if (string.IsNullOrEmpty(PasswordTextBox.TextBox.Text) || !reg.IsMatch(PasswordTextBox.TextBox.Text))
- {
- _passwordValid = false;
- PasswordTextBox.Border = !string.IsNullOrEmpty(PasswordTextBox.TextBox.Text);
- PasswordTextBox.BorderColour = Color.Red;
- }
- else
- {
- _passwordValid = true;
- PasswordTextBox.Border = true;
- PasswordTextBox.BorderColour = Color.Green;
- }
- RefreshLoginButton();
- }
- public void TextBox_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (sender == null || e.KeyChar != (char) Keys.Enter) return;
- e.Handled = true;
- if (!_accountIDValid)
- {
- AccountIDTextBox.SetFocus();
- return;
- }
- if (!_passwordValid)
- {
- PasswordTextBox.SetFocus();
- return;
- }
- if (OKButton.Enabled)
- OKButton.InvokeMouseClick(null);
- }
- private void RefreshLoginButton()
- {
- OKButton.Enabled = _accountIDValid && _passwordValid;
- }
-
- private void Login()
- {
- OKButton.Enabled = false;
- Network.Enqueue(new C.Login {AccountID = AccountIDTextBox.Text, Password = PasswordTextBox.Text});
- }
- public override void Show()
- {
- if (Visible) return;
- Visible = true;
- AccountIDTextBox.SetFocus();
- if (Settings.Password != string.Empty && Settings.AccountID != string.Empty)
- {
- Login();
- }
- }
- public void Clear()
- {
- AccountIDTextBox.Text = string.Empty;
- PasswordTextBox.Text = string.Empty;
- }
- #region Disposable
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- TitleLabel = null;
- AccountIDLabel = null;
- PassLabel = null;
- AccountButton = null;
- CloseButton = null;
- OKButton = null;
- PassButton = null;
- AccountIDTextBox = null;
- PasswordTextBox = null;
- }
- base.Dispose(disposing);
- }
- #endregion
- }
- public sealed class InputKeyDialog : MirImageControl
- {
- public readonly MirButton KeyEscButton, KeyDelButton, KeyRandButton, KeyEnterButton;
- private LoginDialog _loginDialog;
- private List<MirButton> _buttons = new List<MirButton>();
- private char[] _letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
- private char[] _numbers = "0123456789".ToCharArray();
- public InputKeyDialog(LoginDialog loginDialog)
- {
- _loginDialog = loginDialog;
- Index = 1080;
- Library = Libraries.Prguse;
- Location = new Point((Client.Settings.ScreenWidth - Size.Width) / 2 + 285, (Client.Settings.ScreenHeight - Size.Height) / 2 + 150);
- Visible = true;
- KeyEscButton = new MirButton
- {
- Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.BtnEsc),
- HoverIndex = 301,
- Index = 300,
- Library = Libraries.Title,
- Location = new Point(12, 12),
- Parent = this,
- PressedIndex = 302,
- CenterText = true
- };
- KeyEscButton.Click += (o, e) => Dispose();
- KeyDelButton = new MirButton
- {
- Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.BtnDelete),
- HoverIndex = 304,
- Index = 303,
- Library = Libraries.Title,
- Location = new Point(140, 76),
- Parent = this,
- PressedIndex = 305,
- CenterText = true
- };
- KeyDelButton.Click += (o, e) => SecureKeyDelete();
- KeyEnterButton = new MirButton
- {
- Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.BtnEnter),
- HoverIndex = 307,
- Index = 306,
- Library = Libraries.Title,
- Location = new Point(140, 236),
- Parent = this,
- PressedIndex = 308,
- CenterText = true
- };
- KeyEnterButton.Click += (o, e) =>
- {
- KeyPressEventArgs arg = new KeyPressEventArgs((char)Keys.Enter);
- _loginDialog.TextBox_KeyPress(o, arg);
- };
- KeyRandButton = new MirButton
- {
- Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.BtnRandom),
- HoverIndex = 310,
- Index = 309,
- Library = Libraries.Title,
- Location = new Point(76, 236),
- Parent = this,
- PressedIndex = 311,
- CenterText = true
- };
- KeyRandButton.Click += (o, e) =>
- {
- _letters = new string(_letters.OrderBy(s => Guid.NewGuid()).ToArray()).ToCharArray();
- _numbers = new string(_numbers.OrderBy(s => Guid.NewGuid()).ToArray()).ToCharArray();
- UpdateKeys();
- };
- UpdateKeys();
- }
- private void DisposeKeys()
- {
- foreach(MirButton button in _buttons)
- {
- if (button != null && !button.IsDisposed) button.Dispose();
- }
- }
- private void UpdateKeys()
- {
- DisposeKeys();
- for (int i = 0; i < _numbers.Length; i++)
- {
- char key = _numbers[i];
- MirButton numButton = new MirButton
- {
- HoverIndex = 1082,
- Index = 1081,
- Size = new Size(32, 30),
- Library = Libraries.Prguse,
- Location = new Point(12 + (i % 6 * 32), 44 + (i / 6 * 32)),
- Parent = this,
- PressedIndex = 1083,
- Text = _numbers[i].ToString(),
- CenterText = true
- };
- numButton.Click += (o, e) => SecureKeyPress(key);
- _buttons.Add(numButton);
- }
- for (int i = 0; i < _letters.Length; i++)
- {
- char key = _letters[i];
- MirButton alphButton = new MirButton
- {
- HoverIndex = 1082,
- Index = 1081,
- Size = new Size(32, 30),
- Library = Libraries.Prguse,
- Location = new Point(12 + (i % 6 * 32), 108 + (i / 6 * 32)),
- Parent = this,
- PressedIndex = 1083,
- Text = _letters[i].ToString(),
- CenterText = true
- };
- alphButton.Click += (o, e) => SecureKeyPress(key);
- _buttons.Add(alphButton);
- }
- }
- private void SecureKeyPress(char chr)
- {
- MirTextBox currentTextBox = GetFocussedTextBox();
- string keyToAdd = chr.ToString();
- if (CMain.IsKeyLocked(Keys.CapsLock))
- keyToAdd = keyToAdd.ToUpper();
- else
- keyToAdd = keyToAdd.ToLower();
- currentTextBox.Text += keyToAdd;
- currentTextBox.TextBox.SelectionLength = 0;
- currentTextBox.TextBox.SelectionStart = currentTextBox.Text.Length;
- }
- private void SecureKeyDelete()
- {
- MirTextBox currentTextBox = GetFocussedTextBox();
- if (currentTextBox.TextBox.SelectionLength > 0)
- {
- currentTextBox.Text = currentTextBox.Text.Remove(currentTextBox.TextBox.SelectionStart, currentTextBox.TextBox.SelectionLength);
- }
- else if (currentTextBox.Text.Length > 0)
- {
- currentTextBox.Text = currentTextBox.Text.Remove(currentTextBox.Text.Length - 1);
- }
- currentTextBox.TextBox.SelectionStart = currentTextBox.Text.Length;
- }
- private MirTextBox GetFocussedTextBox()
- {
- if (_loginDialog.AccountIDTextBox.TextBox.Focused)
- return _loginDialog.AccountIDTextBox;
- else
- return _loginDialog.PasswordTextBox;
- }
- #region Disposable
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- DisposeKeys();
- }
- #endregion
- }
- public sealed class NewAccountDialog : MirImageControl
- {
- public MirButton OKButton, CancelButton;
- public MirTextBox AccountIDTextBox,
- Password1TextBox,
- Password2TextBox,
- EMailTextBox,
- UserNameTextBox,
- BirthDateTextBox,
- QuestionTextBox,
- AnswerTextBox;
- public MirLabel Description;
- private bool _accountIDValid,
- _password1Valid,
- _password2Valid,
- _eMailValid = true,
- _userNameValid = true,
- _birthDateValid = true,
- _questionValid = true,
- _answerValid = true;
- public NewAccountDialog()
- {
- Index = 63;
- Library = Libraries.Prguse;
- Size = new Size();
- Location = new Point((Settings.ScreenWidth - Size.Width) / 2, (Settings.ScreenHeight - Size.Height) / 2);
- CancelButton = new MirButton
- {
- HoverIndex = 204,
- Index = 203,
- Library = Libraries.Title,
- Location = new Point(409, 425),
- Parent = this,
- PressedIndex = 205
- };
- CancelButton.Click += (o, e) => Dispose();
- OKButton = new MirButton
- {
- Enabled = false,
- HoverIndex = 201,
- Index = 200,
- Library = Libraries.Title,
- Location = new Point(135, 425),
- Parent = this,
- PressedIndex = 202,
- };
- OKButton.Click += (o, e) => CreateAccount();
- Password1TextBox = new MirTextBox
- {
- Border = true,
- BorderColour = Color.Gray,
- Location = new Point(226, 129),
- MaxLength = Globals.MaxPasswordLength,
- Parent = this,
- Password = true,
- Size = new Size(136, 18),
- TextBox = { MaxLength = Globals.MaxPasswordLength },
- };
- Password1TextBox.TextBox.TextChanged += Password1TextBox_TextChanged;
- Password1TextBox.TextBox.GotFocus += PasswordTextBox_GotFocus;
- Password2TextBox = new MirTextBox
- {
- Border = true,
- BorderColour = Color.Gray,
- Location = new Point(226, 155),
- MaxLength = Globals.MaxPasswordLength,
- Parent = this,
- Password = true,
- Size = new Size(136, 18),
- TextBox = { MaxLength = Globals.MaxPasswordLength },
- };
- Password2TextBox.TextBox.TextChanged += Password2TextBox_TextChanged;
- Password2TextBox.TextBox.GotFocus += PasswordTextBox_GotFocus;
- UserNameTextBox = new MirTextBox
- {
- Border = true,
- BorderColour = Color.Gray,
- Location = new Point(226, 189),
- MaxLength = 20,
- Parent = this,
- Size = new Size(136, 18),
- TextBox = { MaxLength = 20 },
- };
- UserNameTextBox.TextBox.TextChanged += UserNameTextBox_TextChanged;
- UserNameTextBox.TextBox.GotFocus += UserNameTextBox_GotFocus;
- BirthDateTextBox = new MirTextBox
- {
- Border = true,
- BorderColour = Color.Gray,
- Location = new Point(226, 215),
- MaxLength = 10,
- Parent = this,
- Size = new Size(136, 18),
- TextBox = { MaxLength = 10 },
- };
- BirthDateTextBox.TextBox.TextChanged += BirthDateTextBox_TextChanged;
- BirthDateTextBox.TextBox.GotFocus += BirthDateTextBox_GotFocus;
- QuestionTextBox = new MirTextBox
- {
- Border = true,
- BorderColour = Color.Gray,
- Location = new Point(226, 250),
- MaxLength = 30,
- Parent = this,
- Size = new Size(190, 18),
- TextBox = { MaxLength = 30 },
- };
- QuestionTextBox.TextBox.TextChanged += QuestionTextBox_TextChanged;
- QuestionTextBox.TextBox.GotFocus += QuestionTextBox_GotFocus;
- AnswerTextBox = new MirTextBox
- {
- Border = true,
- BorderColour = Color.Gray,
- Location = new Point(226, 276),
- MaxLength = 30,
- Parent = this,
- Size = new Size(190, 18),
- TextBox = { MaxLength = 30 },
- };
- AnswerTextBox.TextBox.TextChanged += AnswerTextBox_TextChanged;
- AnswerTextBox.TextBox.GotFocus += AnswerTextBox_GotFocus;
- EMailTextBox = new MirTextBox
- {
- Border = true,
- BorderColour = Color.Gray,
- Location = new Point(226, 311),
- MaxLength = 50,
- Parent = this,
- Size = new Size(136, 18),
- TextBox = { MaxLength = 50 },
- };
- EMailTextBox.TextBox.TextChanged += EMailTextBox_TextChanged;
- EMailTextBox.TextBox.GotFocus += EMailTextBox_GotFocus;
- Description = new MirLabel
- {
- Border = true,
- BorderColour = Color.Gray,
- Location = new Point(15, 340),
- Parent = this,
- Size = new Size(300, 70),
- Visible = false
- };
- AccountIDTextBox = new MirTextBox
- {
- Border = true,
- BorderColour = Color.Gray,
- Location = new Point(226, 103),
- MaxLength = Globals.MaxAccountIDLength,
- Parent = this,
- Size = new Size(136, 18),
- };
- AccountIDTextBox.TextBox.MaxLength = Globals.MaxAccountIDLength;
- AccountIDTextBox.TextBox.TextChanged += AccountIDTextBox_TextChanged;
- AccountIDTextBox.TextBox.GotFocus += AccountIDTextBox_GotFocus;
- }
- private void AccountIDTextBox_TextChanged(object sender, EventArgs e)
- {
- Regex reg = new Regex(@"^[A-Za-z0-9]{" + Globals.MinAccountIDLength + "," + Globals.MaxAccountIDLength + "}$");
- if (string.IsNullOrEmpty(AccountIDTextBox.Text) || !reg.IsMatch(AccountIDTextBox.Text))
- {
- _accountIDValid = false;
- AccountIDTextBox.BorderColour = Color.Red;
- }
- else
- {
- _accountIDValid = true;
- AccountIDTextBox.BorderColour = Color.Green;
- }
- RefreshConfirmButton();
- }
- private void Password1TextBox_TextChanged(object sender, EventArgs e)
- {
- Regex reg = new Regex(@"^[A-Za-z0-9]{" + Globals.MinPasswordLength + "," + Globals.MaxPasswordLength + "}$");
- if (string.IsNullOrEmpty(Password1TextBox.Text) || !reg.IsMatch(Password1TextBox.Text))
- {
- _password1Valid = false;
- Password1TextBox.BorderColour = Color.Red;
- }
- else
- {
- _password1Valid = true;
- Password1TextBox.BorderColour = Color.Green;
- }
- Password2TextBox_TextChanged(sender, e);
- }
- private void Password2TextBox_TextChanged(object sender, EventArgs e)
- {
- Regex reg = new Regex(@"^[A-Za-z0-9]{" + Globals.MinPasswordLength + "," + Globals.MaxPasswordLength + "}$");
- if (string.IsNullOrEmpty(Password2TextBox.Text) || !reg.IsMatch(Password2TextBox.Text) ||
- Password1TextBox.Text != Password2TextBox.Text)
- {
- _password2Valid = false;
- Password2TextBox.BorderColour = Color.Red;
- }
- else
- {
- _password2Valid = true;
- Password2TextBox.BorderColour = Color.Green;
- }
- RefreshConfirmButton();
- }
- private void EMailTextBox_TextChanged(object sender, EventArgs e)
- {
- Regex reg = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
- if (string.IsNullOrEmpty(EMailTextBox.Text))
- {
- _eMailValid = true;
- EMailTextBox.BorderColour = Color.Gray;
- }
- else if (!reg.IsMatch(EMailTextBox.Text) || EMailTextBox.Text.Length > 50)
- {
- _eMailValid = false;
- EMailTextBox.BorderColour = Color.Red;
- }
- else
- {
- _eMailValid = true;
- EMailTextBox.BorderColour = Color.Green;
- }
- RefreshConfirmButton();
- }
- private void UserNameTextBox_TextChanged(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(UserNameTextBox.Text))
- {
- _userNameValid = true;
- UserNameTextBox.BorderColour = Color.Gray;
- }
- else if (UserNameTextBox.Text.Length > 20)
- {
- _userNameValid = false;
- UserNameTextBox.BorderColour = Color.Red;
- }
- else
- {
- _userNameValid = true;
- UserNameTextBox.BorderColour = Color.Green;
- }
- RefreshConfirmButton();
- }
- private void BirthDateTextBox_TextChanged(object sender, EventArgs e)
- {
- DateTime dateTime;
- if (string.IsNullOrEmpty(BirthDateTextBox.Text))
- {
- _birthDateValid = true;
- BirthDateTextBox.BorderColour = Color.Gray;
- }
- else if (!DateTime.TryParse(BirthDateTextBox.Text, out dateTime) || BirthDateTextBox.Text.Length > 10)
- {
- _birthDateValid = false;
- BirthDateTextBox.BorderColour = Color.Red;
- }
- else
- {
- _birthDateValid = true;
- BirthDateTextBox.BorderColour = Color.Green;
- }
- RefreshConfirmButton();
- }
- private void QuestionTextBox_TextChanged(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(QuestionTextBox.Text))
- {
- _questionValid = true;
- QuestionTextBox.BorderColour = Color.Gray;
- }
- else if (QuestionTextBox.Text.Length > 30)
- {
- _questionValid = false;
- QuestionTextBox.BorderColour = Color.Red;
- }
- else
- {
- _questionValid = true;
- QuestionTextBox.BorderColour = Color.Green;
- }
- RefreshConfirmButton();
- }
- private void AnswerTextBox_TextChanged(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(AnswerTextBox.Text))
- {
- _answerValid = true;
- AnswerTextBox.BorderColour = Color.Gray;
- }
- else if (AnswerTextBox.Text.Length > 30)
- {
- _answerValid = false;
- AnswerTextBox.BorderColour = Color.Red;
- }
- else
- {
- _answerValid = true;
- AnswerTextBox.BorderColour = Color.Green;
- }
- RefreshConfirmButton();
- }
- private void AccountIDTextBox_GotFocus(object sender, EventArgs e)
- {
- Description.Visible = true;
- Description.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.AccountIdDescription), Globals.MinAccountIDLength, Globals.MaxAccountIDLength);
- }
- private void PasswordTextBox_GotFocus(object sender, EventArgs e)
- {
- Description.Visible = true;
- Description.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.PasswordDescription), Globals.MinPasswordLength, Globals.MaxPasswordLength);
- }
- private void EMailTextBox_GotFocus(object sender, EventArgs e)
- {
- Description.Visible = true;
- Description.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.EmailAddressDescription);
- }
- private void UserNameTextBox_GotFocus(object sender, EventArgs e)
- {
- Description.Visible = true;
- Description.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.UserNameDescription);
- }
- private void BirthDateTextBox_GotFocus(object sender, EventArgs e)
- {
- Description.Visible = true;
- Description.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.BirthDateDescription),
- Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern.ToUpper());
- }
- private void QuestionTextBox_GotFocus(object sender, EventArgs e)
- {
- Description.Visible = true;
- Description.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SecretQuestionDescription);
- }
- private void AnswerTextBox_GotFocus(object sender, EventArgs e)
- {
- Description.Visible = true;
- Description.Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SecretAnswerDescription);
- }
- private void RefreshConfirmButton()
- {
- OKButton.Enabled = _accountIDValid && _password1Valid && _password2Valid && _eMailValid &&
- _userNameValid && _birthDateValid && _questionValid && _answerValid;
- }
- private void CreateAccount()
- {
- OKButton.Enabled = false;
- Network.Enqueue(new C.NewAccount
- {
- AccountID = AccountIDTextBox.Text,
- Password = Password1TextBox.Text,
- EMailAddress = EMailTextBox.Text,
- BirthDate = !string.IsNullOrEmpty(BirthDateTextBox.Text)
- ? DateTime.Parse(BirthDateTextBox.Text)
- : DateTime.MinValue,
- UserName = UserNameTextBox.Text,
- SecretQuestion = QuestionTextBox.Text,
- SecretAnswer = AnswerTextBox.Text,
- });
- }
-
- public override void Show()
- {
- if (Visible) return;
- Visible = true;
- AccountIDTextBox.SetFocus();
- }
- #region Disposable
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- OKButton = null;
- CancelButton = null;
- AccountIDTextBox = null;
- Password1TextBox = null;
- Password2TextBox = null;
- EMailTextBox = null;
- UserNameTextBox = null;
- BirthDateTextBox = null;
- QuestionTextBox = null;
- AnswerTextBox = null;
- Description = null;
- }
- base.Dispose(disposing);
- }
- #endregion
- }
- public sealed class ChangePasswordDialog : MirImageControl
- {
- public readonly MirButton OKButton,
- CancelButton;
- public readonly MirTextBox AccountIDTextBox,
- CurrentPasswordTextBox,
- NewPassword1TextBox,
- NewPassword2TextBox;
- private bool _accountIDValid,
- _currentPasswordValid,
- _newPassword1Valid,
- _newPassword2Valid;
-
- public ChangePasswordDialog()
- {
- Index = 50;
- Library = Libraries.Prguse;
- Location = new Point((Settings.ScreenWidth - Size.Width) / 2, (Settings.ScreenHeight - Size.Height) / 2);
- CancelButton = new MirButton
- {
- HoverIndex = 111,
- Index = 110,
- Library = Libraries.Title,
- Location = new Point(222, 236),
- Parent = this,
- PressedIndex = 112
- };
- CancelButton.Click += (o, e) => Dispose();
- OKButton = new MirButton
- {
- Enabled = false,
- HoverIndex = 108,
- Index = 107,
- Library = Libraries.Title,
- Location = new Point(80, 236),
- Parent = this,
- PressedIndex = 109,
- };
- OKButton.Click += (o, e) => ChangePassword();
- AccountIDTextBox = new MirTextBox
- {
- Border = true,
- BorderColour = Color.Gray,
- Location = new Point(178, 75),
- MaxLength = Globals.MaxAccountIDLength,
- Parent = this,
- Size = new Size(136, 18),
- };
- AccountIDTextBox.SetFocus();
- AccountIDTextBox.TextBox.MaxLength = Globals.MaxAccountIDLength;
- AccountIDTextBox.TextBox.TextChanged += AccountIDTextBox_TextChanged;
- CurrentPasswordTextBox = new MirTextBox
- {
- Border = true,
- BorderColour = Color.Gray,
- Location = new Point(178, 113),
- MaxLength = Globals.MaxPasswordLength,
- Parent = this,
- Password = true,
- Size = new Size(136, 18),
- TextBox = { MaxLength = Globals.MaxPasswordLength },
- };
- CurrentPasswordTextBox.TextBox.TextChanged += CurrentPasswordTextBox_TextChanged;
- NewPassword1TextBox = new MirTextBox
- {
- Border = true,
- BorderColour = Color.Gray,
- Location = new Point(178, 151),
- MaxLength = Globals.MaxPasswordLength,
- Parent = this,
- Password = true,
- Size = new Size(136, 18),
- TextBox = { MaxLength = Globals.MaxPasswordLength },
- };
- NewPassword1TextBox.TextBox.TextChanged += NewPassword1TextBox_TextChanged;
- NewPassword2TextBox = new MirTextBox
- {
- Border = true,
- BorderColour = Color.Gray,
- Location = new Point(178, 188),
- MaxLength = Globals.MaxPasswordLength,
- Parent = this,
- Password = true,
- Size = new Size(136, 18),
- TextBox = { MaxLength = Globals.MaxPasswordLength },
- };
- NewPassword2TextBox.TextBox.TextChanged += NewPassword2TextBox_TextChanged;
- }
- void RefreshConfirmButton()
- {
- OKButton.Enabled = _accountIDValid && _currentPasswordValid && _newPassword1Valid && _newPassword2Valid;
- }
- private void AccountIDTextBox_TextChanged(object sender, EventArgs e)
- {
- Regex reg = new Regex(@"^[A-Za-z0-9]{" + Globals.MinAccountIDLength + "," + Globals.MaxAccountIDLength + "}$");
- if (string.IsNullOrEmpty(AccountIDTextBox.Text) || !reg.IsMatch(AccountIDTextBox.Text))
- {
- _accountIDValid = false;
- AccountIDTextBox.BorderColour = Color.Red;
- }
- else
- {
- _accountIDValid = true;
- AccountIDTextBox.BorderColour = Color.Green;
- }
- RefreshConfirmButton();
- }
- private void CurrentPasswordTextBox_TextChanged(object sender, EventArgs e)
- {
- Regex reg = new Regex(@"^[A-Za-z0-9]{" + Globals.MinPasswordLength + "," + Globals.MaxPasswordLength + "}$");
- if (string.IsNullOrEmpty(CurrentPasswordTextBox.Text) || !reg.IsMatch(CurrentPasswordTextBox.Text))
- {
- _currentPasswordValid = false;
- CurrentPasswordTextBox.BorderColour = Color.Red;
- }
- else
- {
- _currentPasswordValid = true;
- CurrentPasswordTextBox.BorderColour = Color.Green;
- }
- RefreshConfirmButton();
- }
- private void NewPassword1TextBox_TextChanged(object sender, EventArgs e)
- {
- Regex reg = new Regex(@"^[A-Za-z0-9]{" + Globals.MinPasswordLength + "," + Globals.MaxPasswordLength + "}$");
- if (string.IsNullOrEmpty(NewPassword1TextBox.Text) || !reg.IsMatch(NewPassword1TextBox.Text))
- {
- _newPassword1Valid = false;
- NewPassword1TextBox.BorderColour = Color.Red;
- }
- else
- {
- _newPassword1Valid = true;
- NewPassword1TextBox.BorderColour = Color.Green;
- }
- NewPassword2TextBox_TextChanged(sender, e);
- }
- private void NewPassword2TextBox_TextChanged(object sender, EventArgs e)
- {
- if (NewPassword1TextBox.Text == NewPassword2TextBox.Text)
- {
- _newPassword2Valid = _newPassword1Valid;
- NewPassword2TextBox.BorderColour = NewPassword1TextBox.BorderColour;
- }
- else
- {
- _newPassword2Valid = false;
- NewPassword2TextBox.BorderColour = Color.Red;
- }
- RefreshConfirmButton();
- }
- private void ChangePassword()
- {
- OKButton.Enabled = false;
- Network.Enqueue(new C.ChangePassword
- {
- AccountID = AccountIDTextBox.Text,
- CurrentPassword = CurrentPasswordTextBox.Text,
- NewPassword = NewPassword1TextBox.Text
- });
- }
- public override void Show()
- {
- if (Visible) return;
- Visible = true;
- AccountIDTextBox.SetFocus();
- }
- }
- #region Disposable
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- _background = null;
- Version = null;
- _login = null;
- _account = null;
- _password = null;
- _connectBox = null;
- }
- base.Dispose(disposing);
- }
- #endregion
- }
- }
|