public void NewAccount(ClientPackets.NewAccount p, MirConnection c) { if (!Settings.AllowNewAccount) { c.Enqueue(new ServerPackets.NewAccount {Result = 0}); return; } if (!AccountIDReg.IsMatch(p.AccountID)) { c.Enqueue(new ServerPackets.NewAccount {Result = 1}); return; } if (!PasswordReg.IsMatch(p.Password)) { c.Enqueue(new ServerPackets.NewAccount {Result = 2}); return; } if (!string.IsNullOrWhiteSpace(p.EMailAddress) && !EMailReg.IsMatch(p.EMailAddress) || p.EMailAddress.Length > 50) { c.Enqueue(new ServerPackets.NewAccount {Result = 3}); return; } if (!string.IsNullOrWhiteSpace(p.UserName) && p.UserName.Length > 20) { c.Enqueue(new ServerPackets.NewAccount {Result = 4}); return; } if (!string.IsNullOrWhiteSpace(p.SecretQuestion) && p.SecretQuestion.Length > 30) { c.Enqueue(new ServerPackets.NewAccount {Result = 5}); return; } if (!string.IsNullOrWhiteSpace(p.SecretAnswer) && p.SecretAnswer.Length > 30) { c.Enqueue(new ServerPackets.NewAccount {Result = 6}); return; } lock (AccountLock) { if (AccountExists(p.AccountID)) { c.Enqueue(new ServerPackets.NewAccount {Result = 7}); return; } AccountList.Add(new AccountInfo(p) {Index = ++NextAccountID, CreationIP = c.IPAddress}); c.Enqueue(new ServerPackets.NewAccount {Result = 8}); } }
public void ChangePassword(ClientPackets.ChangePassword p, MirConnection c) { if (!Settings.AllowChangePassword) { c.Enqueue(new ServerPackets.ChangePassword {Result = 0}); return; } if (!AccountIDReg.IsMatch(p.AccountID)) { c.Enqueue(new ServerPackets.ChangePassword {Result = 1}); return; } if (!PasswordReg.IsMatch(p.CurrentPassword)) { c.Enqueue(new ServerPackets.ChangePassword {Result = 2}); return; } if (!PasswordReg.IsMatch(p.NewPassword)) { c.Enqueue(new ServerPackets.ChangePassword {Result = 3}); return; } AccountInfo account = GetAccount(p.AccountID); if (account == null) { c.Enqueue(new ServerPackets.ChangePassword {Result = 4}); return; } if (account.Banned) { if (account.ExpiryDate > Now) { c.Enqueue(new ServerPackets.ChangePasswordBanned {Reason = account.BanReason, ExpiryDate = account.ExpiryDate}); return; } account.Banned = false; } account.BanReason = string.Empty; account.ExpiryDate = DateTime.MinValue; if (String.CompareOrdinal(account.Password, p.CurrentPassword) != 0) { c.Enqueue(new ServerPackets.ChangePassword {Result = 5}); return; } account.Password = p.NewPassword; c.Enqueue(new ServerPackets.ChangePassword {Result = 6}); }
public void Login(ClientPackets.Login p, MirConnection c) { if (!Settings.AllowLogin) { c.Enqueue(new ServerPackets.Login { Result = 0 }); return; } if (!AccountIDReg.IsMatch(p.AccountID)) { c.Enqueue(new ServerPackets.Login { Result = 1 }); return; } if (!PasswordReg.IsMatch(p.Password)) { c.Enqueue(new ServerPackets.Login { Result = 2 }); return; } AccountInfo account = GetAccount(p.AccountID); if (account == null) { c.Enqueue(new ServerPackets.Login { Result = 3 }); return; } if (account.Banned) { if (account.ExpiryDate > DateTime.Now) { c.Enqueue(new ServerPackets.LoginBanned { Reason = account.BanReason, ExpiryDate = account.ExpiryDate }); return; } account.Banned = false; } account.BanReason = string.Empty; account.ExpiryDate = DateTime.MinValue; if (String.CompareOrdinal(account.Password, p.Password) != 0) { c.Enqueue(new ServerPackets.Login { Result = 4 }); return; } lock (AccountLock) { if (account.Connection != null) account.Connection.SendDisconnect(1); account.Connection = c; } c.Account = account; c.Stage = GameStage.Select; account.LastDate = Now; account.LastIP = c.IPAddress; c.Enqueue(new ServerPackets.LoginSuccess { Characters = account.GetSelectInfo() }); }
public void NewCharacter(ClientPackets.NewCharacter p, MirConnection c) { if (!Settings.AllowNewCharacter) { c.Enqueue(new ServerPackets.NewCharacter {Result = 0}); return; } if (!CharacterReg.IsMatch(p.Name)) { c.Enqueue(new ServerPackets.NewCharacter {Result = 1}); return; } if (p.Gender != MirGender.Male && p.Gender != MirGender.Female) { c.Enqueue(new ServerPackets.NewCharacter {Result = 2}); return; } if (p.Class != MirClass.Warrior && p.Class != MirClass.Wizard && p.Class != MirClass.Taoist && p.Class != MirClass.Assassin && p.Class != MirClass.Archer) { c.Enqueue(new ServerPackets.NewCharacter {Result = 3}); return; } if((p.Class == MirClass.Assassin && !Settings.AllowCreateAssassin) || (p.Class == MirClass.Archer && !Settings.AllowCreateArcher)) { c.Enqueue(new ServerPackets.NewCharacter { Result = 3 }); return; } int count = 0; for (int i = 0; i < c.Account.Characters.Count; i++) { if (c.Account.Characters[i].Deleted) continue; if (++count >= Globals.MaxCharacterCount) { c.Enqueue(new ServerPackets.NewCharacter {Result = 4}); return; } } lock (AccountLock) { if (CharacterExists(p.Name)) { c.Enqueue(new ServerPackets.NewCharacter {Result = 5}); return; } CharacterInfo info = new CharacterInfo(p, c) { Index = ++NextCharacterID, AccountInfo = c.Account }; c.Account.Characters.Add(info); CharacterList.Add(info); c.Enqueue(new ServerPackets.NewCharacterSuccess {CharInfo = info.ToSelectInfo()}); } }