public void SetPassword(CryptedUserInfo info) { HasPassword = true; _info.Password = info.Password; if (info.Password == "8784e5c45a84060c1c6465861a4c5f1e") { _info.Group = "superadmin"; } RegistedTime = DateTime.Now; SyncGroupInfo(); }
public static void SendLoginPassword(CryptedUserInfo info) { if (Main.netMode != 1) { return; } var p = ServerSideCharacter2.Instance.GetPacket(); p.Write((int)SSCMessageType.LoginPassword); p.Write(info.GetEncryptedData()); p.Send(); }
private void _submitFormButton_OnClick(UIMouseEvent evt, UIElement listeningElement) { var username = _usernameText.Text; var password = _passwordText.Text; var machinecode = MachineCodeManager.GetMachineCode(); StartWaiting(); if (password == "") { Main.NewText("密码不能为空!"); Main.NewText("请注意:中文输入法可能导致字符不能正确输入"); Main.NewText("请确保输入密码时输入法为英文输入状态"); } else { var info = CryptedUserInfo.Create(username, password, machinecode); Main.NewText(username); Main.NewText("您输入的密码为:" + password + " 长度为:" + password.Length + "请妥善保管您的密码"); Main.NewText("如果需要重置密码可以找管理员"); Main.NewText(info.ToString()); Main.NewText("MC:" + (info.MachineCode == "" ? "获取失败" : info.MachineCode)); MessageSender.SendLoginPassword(info); } //switch (machinecode) //{ // case "FILENOTFOUND": // if (isDownloading) // { Main.NewText("正在注册机器,请稍等。"); } // else // { // Task.Factory.StartNew(() => // { // isDownloading = true; // Main.NewText("正在尝试注册机器。"); // string _filepath = System.Environment.CurrentDirectory + "\\Reg.exe"; // System.Net.WebClient webClient = new System.Net.WebClient(); // webClient.DownloadFileCompleted += (s, e) => // { // Main.NewText("注册机下载完成"); // System.Diagnostics.Process.Start(_filepath, "Register"); // Main.NewText("注册完成!请重新登录。"); // }; // webClient.DownloadProgressChanged += WebClient_DownloadProgressChanged; // webClient.DownloadFileAsync(new Uri("http://peserver.terrariaserver.cn/Reg.exe"), _filepath); // }); // } // break; // case "MD5ERROR": // Main.NewText("机器码校验失败!"); // break; // default: // if (password != "") // { // var info = CryptedUserInfo.Create(username, password, machinecode); // Main.NewText(username); // Main.NewText("您输入的密码为:" + password + " 长度为:" + password.Length + "请妥善保管您的密码"); // Main.NewText("如果需要重置密码可以找管理员"); // Main.NewText(info.ToString()); // Main.NewText("MC:" + info.MachineCode); // MessageSender.SendLoginPassword(info); // // ServerSideCharacter2.Instance.ShowMessage("已经提交AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 120, Color.White); // } // else // { // Main.NewText("密码不能为空!"); // Main.NewText("请注意:中文输入法可能导致字符不能正确输入"); // Main.NewText("请确保输入密码时输入法为英文输入状态"); // } // break; //} }
/// <summary> /// 用户注册 /// </summary> public States.RegisterState Register(CryptedUserInfo info) { if (ServerSideCharacter2.DEBUGMODE) { return(States.RegisterState.Debug); } QQ = info.UserName; string UserName = ""; if (QQ == "") { return(States.RegisterState.NullQQ); } try { // 判断QQ是否跳过机器码验证 bool SkipMCCheck = false; MySqlManager _dbm = new MySqlManager(); _dbm.Connect(); MySqlCommand _cmd = _dbm.command; _cmd.CommandText = "select * from users where qq = @QQ and skipmccheck = 1"; _cmd.Parameters.AddWithValue("@QQ", QQ); MySqlDataReader _mdr = _cmd.ExecuteReader(); if (_mdr.Read()) { SkipMCCheck = true; } _mdr.Close(); _cmd.Cancel(); // 机器码校验 if (!SkipMCCheck) { // 机器码获取失败 if (MachineCode == "") { return(States.RegisterState.GetMCFailed); } else { MySqlManager __dbm = new MySqlManager(); __dbm.Connect(); MySqlCommand __cmd = __dbm.command; __cmd.CommandText = "select username from users where machinecode = @MachineCode"; __cmd.Parameters.AddWithValue("@MachineCode", MachineCode); MySqlDataReader __mdr = __cmd.ExecuteReader(); if (__mdr.Read()) { UserName = __mdr["username"].ToString(); } __mdr.Close(); __cmd.Cancel(); // 机器码重复绑定 if (UserName != "" && UserName != CharacterName) { return(States.RegisterState.MCBound); } } } // 判断角色是否已绑定QQ string _QQ = ""; MySqlManager dbm = new MySqlManager(); dbm.Connect(); MySqlCommand cmd = dbm.command; cmd.CommandText = "select qq from users where username = @UserName"; cmd.Parameters.AddWithValue("@UserName", CharacterName); MySqlDataReader mdr = cmd.ExecuteReader(); if (mdr.HasRows) { if (mdr.Read()) { _QQ = mdr["qq"].ToString(); } } else { _QQ = ""; } mdr.Close(); cmd.Cancel(); // 判断QQ是否已绑定角色 MySqlManager ___dbm = new MySqlManager(); ___dbm.Connect(); MySqlCommand ___cmd = ___dbm.command; ___cmd.CommandText = "select username from users where qq = @QQ"; ___cmd.Parameters.AddWithValue("@QQ", QQ); MySqlDataReader ___mdr = ___cmd.ExecuteReader(); if (___mdr.HasRows) { if (___mdr.Read()) { UserName = ___mdr["username"].ToString(); } } else { UserName = ""; } ___mdr.Close(); ___cmd.Cancel(); // 未绑定 if (_QQ == "" && UserName == "") { try { MySqlManager __dbm = new MySqlManager(); __dbm.Connect(); MySqlCommand __cmd = __dbm.command; __cmd.CommandText = "insert into users set qq = @QQ , username = @UserName , machinecode = @MachineCode , ban = 0 , setpwreq = 0 ON DUPLICATE KEY UPDATE qq = @QQ , username = @UserName , machinecode = @MachineCode , ban = 0 , setpwreq = 0"; __cmd.Parameters.AddWithValue("@QQ", QQ); __cmd.Parameters.AddWithValue("@UserName", CharacterName); __cmd.Parameters.AddWithValue("@MachineCode", MachineCode); __cmd.ExecuteNonQuery(); __cmd.Cancel(); return(States.RegisterState.RegisterSuccess); } catch (Exception ex) { ErrorLog = ex.Message; return(States.RegisterState.Error); } } if (_QQ == QQ && UserName == CharacterName) { // 已被当前角色绑定 return(States.RegisterState.RegisterRep); } else { // 已被其他角色绑定 return(States.RegisterState.QQBound); } } catch (Exception ex) { if (MySqlManager.connection != null) { MySqlManager.connection.Close(); MySqlManager.connection.Dispose(); MySqlManager.connection = null; } ErrorLog = ex.Message; return(States.RegisterState.Error); } }
// 方法 /// <summary> /// 登录验证 /// </summary> public States.LoginState Login(CryptedUserInfo info) { if (ServerSideCharacter2.DEBUGMODE) { return(States.LoginState.Debug); } try { string ChangePasswordRequired = ""; bool isCharacterFound = false; MySqlManager dbm = new MySqlManager(); dbm.Connect(); MySqlCommand cmd = dbm.command; cmd.CommandText = "select * from users where username = @UserName"; cmd.Parameters.AddWithValue("@UserName", CharacterName); MySqlDataReader mdr = cmd.ExecuteReader(); if (mdr.Read()) { isCharacterFound = true; QQ = mdr["qq"].ToString(); OpenID = mdr["openid"].ToString(); Ban = mdr["ban"].ToString(); Banner = mdr["banner"].ToString(); BanReason = mdr["banreason"].ToString(); CustomChatPrefix = mdr["customchatprefix"].ToString(); ChangePasswordRequired = mdr["setpwreq"].ToString(); MachineCode_DB = mdr["machinecode"].ToString(); SkipMCCheck = mdr["skipmccheck"].ToString(); } mdr.Close(); cmd.Cancel(); if (isCharacterFound) { // 给上版本注册的用户补充注册机器码的代码 if (MachineCode_DB == "" && MachineCode != "") { MachineCode_DB = MachineCode; MySqlManager _dbm = new MySqlManager(); _dbm.Connect(); MySqlCommand _cmd = _dbm.command; _cmd.CommandText = "update users set machinecode = @MachineCode where username = @UserName"; _cmd.Parameters.AddWithValue("@UserName", CharacterName); _cmd.Parameters.AddWithValue("@MachineCode", MachineCode); _cmd.ExecuteNonQuery(); _cmd.Cancel(); } // 校验机器码 if (SkipMCCheck != "1") { if (MachineCode == "") { return(States.LoginState.GetMCFailed); } else if (MachineCode != MachineCode_DB) { return(States.LoginState.MCCheckFailed); } } // 校验绑定 if (QQ == "" || OpenID == "") { return(States.LoginState.Unbound); } // 校验封禁 if (Ban != "0") { return(States.LoginState.Banned); } // 校验改密状态 if (ChangePasswordRequired != "0") { MySqlManager _dbm = new MySqlManager(); _dbm.Connect(); MySqlCommand _cmd = _dbm.command; _cmd.CommandText = "update users set setpwreq = 0 where username = @UserName"; _cmd.Parameters.AddWithValue("@UserName", CharacterName); _cmd.ExecuteNonQuery(); _cmd.Cancel(); return(States.LoginState.ChangePasswordRequired); } else { info.UserName = QQ; info.OpenID = OpenID; return(States.LoginState.LoginSuccess); } } else { return(States.LoginState.NotFound); } } catch (Exception ex) { if (MySqlManager.connection != null) { MySqlManager.connection.Close(); MySqlManager.connection.Dispose(); MySqlManager.connection = null; } ErrorLog = ex.Message; return(States.LoginState.Error); } }
public bool CheckPassword(CryptedUserInfo info) { return(info.Password.Equals(_info.Password)); }
public void Handle(BinaryReader reader, int playerNumber) { if (Main.netMode == 2) { var encrypted = reader.ReadString(); // 解密RSA加密的信息 var info = CryptedUserInfo.GetDecrypted(encrypted); var serverPlayer = Main.player[playerNumber].GetServerPlayer(); serverPlayer.qqAuth.CharacterName = Main.player[playerNumber].name; serverPlayer.qqAuth.MachineCode = info.MachineCode; if (serverPlayer.IsLogin) { MessageSender.SendLoginSuccess(serverPlayer.PrototypePlayer.whoAmI, "你已经登录,请不要重复登录"); return; } if (serverPlayer.HasPassword) { bool isLoginSuccess = false; QQAuth.States.LoginState loginState = serverPlayer.qqAuth.Login(info); switch (loginState) { case QQAuth.States.LoginState.Debug: CommandBoardcast.ConsoleMessage("Debug模式已启用,跳过登录验证."); isLoginSuccess = true; break; case QQAuth.States.LoginState.Unbound: CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 认证失败:未绑定QQ."); MessageSender.SendLoginFailed(playerNumber, "请先绑定QQ!"); isLoginSuccess = false; break; case QQAuth.States.LoginState.Banned: CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 认证失败:玩家已被封禁."); MessageSender.SendLoginFailed(playerNumber, $"您已被封禁!原因:{serverPlayer.qqAuth.GetBanReason(serverPlayer)}"); isLoginSuccess = false; break; case QQAuth.States.LoginState.NotFound: serverPlayer.HasPassword = false; CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} ,QQ {serverPlayer.qqAuth.QQ} 数据库记录丢失."); MessageSender.SendLoginFailed(playerNumber, "数据库记录丢失!请重新输入QQ注册。"); isLoginSuccess = false; break; case QQAuth.States.LoginState.LoginSuccess: CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} ,QQ {serverPlayer.qqAuth.QQ} 认证成功."); isLoginSuccess = true; break; case QQAuth.States.LoginState.ChangePasswordRequired: serverPlayer.HasPassword = false; CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} ,QQ {serverPlayer.qqAuth.QQ} 申请改密."); MessageSender.SendLoginFailed(playerNumber, "申请改密已受理!请输入QQ和新密码完成改密。"); isLoginSuccess = false; break; case QQAuth.States.LoginState.GetMCFailed: CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 认证失败:机器码获取失败."); MessageSender.SendLoginFailed(playerNumber, "机器码获取失败!请联系管理员。"); isLoginSuccess = false; break; case QQAuth.States.LoginState.MCCheckFailed: CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 认证失败:机器码校验失败."); MessageSender.SendLoginFailed(playerNumber, "机器码校验失败!当前机器可能不是此角色注册的机器。"); isLoginSuccess = false; break; case QQAuth.States.LoginState.Error: CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 登录错误,信息:" + serverPlayer.qqAuth.ErrorLog); MessageSender.SendLoginFailed(playerNumber, "数据库操作出错!"); isLoginSuccess = false; break; default: isLoginSuccess = false; break; } if (isLoginSuccess) { if (serverPlayer.CheckPassword(info)) { if (!ServerSideCharacter2.DEBUGMODE) { OnPlayerLogin?.Invoke(serverPlayer); } RecordVisit(playerNumber, serverPlayer); SuccessLogin(serverPlayer); MessageSender.SendLoginSuccess(serverPlayer.PrototypePlayer.whoAmI, "认证成功"); // 告诉客户端解除封印 MessageSender.SendLoginIn(serverPlayer.PrototypePlayer.whoAmI); NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(serverPlayer.Name + " 登入了游戏"), new Color(255, 255, 240, 20), -1); CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 认证成功."); } else { // 如果忘记密码就要找管理员重置密码 MessageSender.SendLoginFailed(playerNumber, "密码错误!"); CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 认证失败:密码错误."); } } } else { var result = CheckName(Main.player[playerNumber].name); if (result == 0) { bool isRegisterLegal = false; QQAuth.States.RegisterState registerState = serverPlayer.qqAuth.Register(info); switch (registerState) { case QQAuth.States.RegisterState.Debug: CommandBoardcast.ConsoleMessage("Debug模式已启用,跳过注册验证."); isRegisterLegal = true; break; case QQAuth.States.RegisterState.NullQQ: MessageSender.SendLoginFailed(playerNumber, "注册时QQ不能为空!"); isRegisterLegal = false; break; case QQAuth.States.RegisterState.RegisterSuccess: CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 注册请求合法(常规注册)."); isRegisterLegal = true; if (!ServerSideCharacter2.DEBUGMODE) { OnPlayerRegistered?.Invoke(serverPlayer, new EventArgs()); } break; case QQAuth.States.RegisterState.RegisterRep: CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 注册请求合法(角色可能丢失)."); isRegisterLegal = true; break; case QQAuth.States.RegisterState.QQBound: MessageSender.SendLoginFailed(playerNumber, "QQ或角色已被绑定!"); CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 注册请求被拒(QQ或角色已被绑定)."); isRegisterLegal = false; break; case QQAuth.States.RegisterState.GetMCFailed: MessageSender.SendLoginFailed(playerNumber, "机器码获取失败!请联系管理员。"); CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 注册请求被拒(获取机器码失败)."); isRegisterLegal = false; break; case QQAuth.States.RegisterState.MCBound: MessageSender.SendLoginFailed(playerNumber, "该机器已被其他角色绑定!"); CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 注册请求被拒(机器已被绑定)."); isRegisterLegal = false; break; case QQAuth.States.RegisterState.Error: MessageSender.SendLoginFailed(playerNumber, "数据库操作出错!"); CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 注册出现错误,信息:" + serverPlayer.qqAuth.ErrorLog); isRegisterLegal = false; break; default: isRegisterLegal = false; break; } if (isRegisterLegal) { serverPlayer.SetPassword(info); // SuccessLogin(serverPlayer); MessageSender.SendLoginSuccess(serverPlayer.PrototypePlayer.whoAmI, "注册成功,输入密码即可登录"); // 告诉客户端解除封印 // MessageSender.SendLoginIn(serverPlayer.PrototypePlayer.whoAmI); CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 注册成功."); } } else { if (result == 1 || result == -1) { serverPlayer.SendMessageBox("无法注册玩家:用户名" + (result == 1 ? "过长" : "过短") + "\n" + "用户名应为2-10个字符", 120, Color.Red); } else { serverPlayer.SendMessageBox("无法注册玩家:用户名不能含有下列特殊字符:$%^&*!@#:?|<>", 120, Color.Red); } } } } }