Update Server Architecture and SQLHelper Transaction (#18)

This commit is contained in:
milimoe 2023-06-17 00:54:19 +08:00 committed by GitHub
parent 955fff82d5
commit ac2cf9ee67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 10 deletions

View File

@ -57,4 +57,8 @@
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Controllers\" />
</ItemGroup>
</Project>

View File

@ -316,14 +316,20 @@ namespace Milimoe.FunGame.Server.Model
if (RegVerify.Equals(SQLHelper.DataSet.Tables[0].Rows[0][RegVerifyCodes.Column_RegVerifyCode]))
{
ServerHelper.WriteLine("[" + ServerSocket.GetTypeString(type) + "] UserName: " + username + " Email: " + email);
SQLHelper.NewTransaction();
SQLHelper.Execute(UserQuery.Insert_Register(username, password, email, socket.ClientIP));
if (SQLHelper.Result == SQLResult.Success)
{
msg = "注册成功!请牢记您的账号与密码!";
SQLHelper.Execute(RegVerifyCodes.Delete_RegVerifyCode(username, email));
SQLHelper.Commit();
return Send(socket, type, true, msg);
}
else msg = "服务器无法处理您的注册,注册失败!";
else
{
msg = "服务器无法处理您的注册,注册失败!";
SQLHelper.Rollback();
}
}
else msg = "验证码不正确,请重新输入!";
}

View File

@ -15,10 +15,7 @@ namespace Milimoe.FunGame.Server.Utility
public override string Script { get; set; } = "";
public override CommandType CommandType { get; set; } = CommandType.Text;
public override SQLResult Result => _Result;
public override bool Success
{
get => Result == SQLResult.Success;
}
public override bool Success => Result == SQLResult.Success;
public override SQLServerInfo ServerInfo => _ServerInfo ?? SQLServerInfo.Create();
public override int UpdateRows => _UpdateRows;
public override DataSet DataSet => _DataSet;

View File

@ -28,14 +28,12 @@ namespace Milimoe.FunGame.Server.Utility
Result = SQLResult.Success;
}
else Result = SQLResult.NotFound;
Helper.Commit();
}
catch (Exception e)
{
ServerHelper.Error(e);
updaterow = -1;
Result = SQLResult.Fail;
Helper.Rollback();
}
return updaterow;
@ -85,7 +83,7 @@ namespace Milimoe.FunGame.Server.Utility
/// <param name="Helper">MySQLHelper</param>
/// <param name="Result">执行结果</param>
/// <returns>插入值ID</returns>
public static object ExecuteAndGetLastInsertedID(MySQLHelper Helper, out SQLResult Result)
public static long ExecuteAndGetLastInsertedID(MySQLHelper Helper, out SQLResult Result)
{
MySqlCommand cmd = new();
int updaterow;
@ -101,13 +99,11 @@ namespace Milimoe.FunGame.Server.Utility
Result = SQLResult.Success;
}
else Result = SQLResult.NotFound;
Helper.Commit();
}
catch (Exception e)
{
ServerHelper.Error(e);
Result = SQLResult.Fail;
Helper.Rollback();
}
return cmd.LastInsertedId;