修改User构造方法

This commit is contained in:
Mili 2023-03-15 23:52:58 +08:00
parent f7382b7d04
commit 4c9b729463
2 changed files with 22 additions and 6 deletions

View File

@ -39,6 +39,10 @@
<HintPath>..\..\FunGame\bin\Server\Debug\net6.0\MySql.Data.dll</HintPath>
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\FunGame\bin\Debug\net7.0-windows\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Configuration.ConfigurationManager">
<HintPath>..\..\FunGame\bin\Server\Debug\net6.0\System.Configuration.ConfigurationManager.dll</HintPath>
<EmbedInteropTypes>False</EmbedInteropTypes>

View File

@ -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() != "")
{
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<User>(UserName, Password);
_User = Factory.GetInstance<User>(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("客户端发送了错误的秘钥,不允许本次登录。");
}