From 4c9b72946389599ffeab418063220d5d04863cee Mon Sep 17 00:00:00 2001 From: Mili Date: Wed, 15 Mar 2023 23:52:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9User=E6=9E=84=E9=80=A0?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FunGame.Server/FunGame.Server.csproj | 4 ++++ FunGame.Server/Model/ServerModel.cs | 24 ++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/FunGame.Server/FunGame.Server.csproj b/FunGame.Server/FunGame.Server.csproj index 408dba1..c7a81e3 100644 --- a/FunGame.Server/FunGame.Server.csproj +++ b/FunGame.Server/FunGame.Server.csproj @@ -39,6 +39,10 @@ ..\..\FunGame\bin\Server\Debug\net6.0\MySql.Data.dll False + + ..\..\FunGame\bin\Debug\net7.0-windows\Newtonsoft.Json.dll + True + ..\..\FunGame\bin\Server\Debug\net6.0\System.Configuration.ConfigurationManager.dll False diff --git a/FunGame.Server/Model/ServerModel.cs b/FunGame.Server/Model/ServerModel.cs index 109f135..e381b4b 100644 --- a/FunGame.Server/Model/ServerModel.cs +++ b/FunGame.Server/Model/ServerModel.cs @@ -36,7 +36,7 @@ namespace Milimoe.FunGame.Server.Model private string RegVerify = ""; private int FailedTimes = 0; // 超过一定次数断开连接 private string UserName = ""; - private string Password = ""; + private DataSet UserDataSet = new(); private string RoomID = ""; private readonly Guid Token; private readonly ServerSocket Server; @@ -106,11 +106,23 @@ namespace Milimoe.FunGame.Server.Model SQLHelper.ExecuteDataSet(UserQuery.Select_Users_LoginQuery(username, password), out SQLResult result); if (result == SQLResult.Success) { - DataRow UserRow = SQLHelper.DataSet.Tables[0].Rows[0]; + UserDataSet = SQLHelper.DataSet; + DataRow UserRow = UserDataSet.Tables[0].Rows[0]; if (autokey != null && autokey.Trim() != "") - ServerHelper.WriteLine("[" + ServerSocket.GetTypeString(type) + "] AutoKey: 已确认"); + { + SQLHelper.ExecuteDataSet(UserQuery.Select_CheckAutoKey(username, autokey), out result); + if (result == SQLResult.Success) + { + ServerHelper.WriteLine("[" + ServerSocket.GetTypeString(type) + "] AutoKey: 已确认"); + } + else + { + msg = "AutoKey不正确,拒绝自动登录!"; + ServerHelper.WriteLine("[" + ServerSocket.GetTypeString(type) + "] " + msg); + return Send(socket, type, CheckLoginKey, msg); + } + } UserName = username; - Password = password; CheckLoginKey = Guid.NewGuid(); return Send(socket, type, CheckLoginKey); } @@ -127,7 +139,7 @@ namespace Milimoe.FunGame.Server.Model if (CheckLoginKey.Equals(checkloginkey)) { // 创建User对象 - _User = Factory.New(UserName, Password); + _User = Factory.GetInstance(UserDataSet); // 检查有没有重复登录的情况 KickUser(); // 添加至玩家列表 @@ -136,7 +148,7 @@ namespace Milimoe.FunGame.Server.Model // CheckLogin LoginTime = DateTime.Now.Ticks; SQLHelper.Execute(UserQuery.Update_CheckLogin(UserName, socket.ClientIP.Split(':')[0]), out _); - return Send(socket, type, UserName, Password); + return Send(socket, type, UserDataSet); } ServerHelper.WriteLine("客户端发送了错误的秘钥,不允许本次登录。"); }