This commit is contained in:
2025-08-07 09:16:23 +08:00
parent c97bd0ab55
commit 70bfe43a80
34 changed files with 532 additions and 135 deletions

View File

@@ -40,13 +40,13 @@ internal static class AuthenticationComponentSystem
Log.Info($"鉴权服务器启动成功Position:{self.Position} AuthenticationCount:{self.AuthenticationCount}");
}
internal static async FTask<(uint ErrorCode, long AccountId)> Login(this AuthenticationComponent self,
internal static async FTask<(uint ErrorCode, long AccountId, int region)> Login(this AuthenticationComponent self,
string userName, string password)
{
// 1、检查传递的参数是否完整
if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
{
return (ErrorCode.ErrArgs, 0);
return (ErrorCode.ErrArgs, 0, 0);
}
// 检查账号是否应该在当前鉴权服务器中处理
@@ -55,7 +55,7 @@ internal static class AuthenticationComponentSystem
{
// 这个3代表的是当前账号不应该在这个鉴权服务器处理。
// return (3, 0);
return (ErrorCode.ErrServer, 0);
return (ErrorCode.ErrServer, 0, 0);
}
var scene = self.Scene;
@@ -90,10 +90,10 @@ internal static class AuthenticationComponentSystem
if (account == null)
{
return (ErrorCode.ErrAccountOrPass, 0);
return (ErrorCode.ErrAccountOrPass, 0, 0);
}
return (ErrorCode.Successful, account.Id);
return (ErrorCode.Successful, account.Id, account.Region);
}
uint result = 0;
@@ -103,7 +103,7 @@ internal static class AuthenticationComponentSystem
if (account == null)
{
// 没有注册
return (ErrorCode.ErrAccountOrPass, -1); //返回-1用于判断是否需要自动注册
return (ErrorCode.ErrAccountOrPass, -1, 0); //返回-1用于判断是否需要自动注册
}
if (account.Password != password)
@@ -126,10 +126,10 @@ internal static class AuthenticationComponentSystem
if (result != 0)
{
return (result, 0);
return (result, 0, 0);
}
return (ErrorCode.Successful, account.Id);
return (ErrorCode.Successful, account.Id, account.Region);
}
}
@@ -138,14 +138,14 @@ internal static class AuthenticationComponentSystem
/// </summary>
/// <param name="self"></param>
/// <param name="username"></param>
/// <param name="password"></param>
/// <param name="region"></param>
/// <param name="source"></param>
internal static async FTask<uint> Register(this AuthenticationComponent self, string username, string password,
internal static async FTask<uint> Register(this AuthenticationComponent self, string username, int region,
string source)
{
// 1、检查传递的参数是否完整
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
if (string.IsNullOrEmpty(username))
{
// 这个1代表的是参数不完整。
return ErrorCode.ErrArgs;
@@ -187,7 +187,8 @@ internal static class AuthenticationComponentSystem
//3、执行到这里的话表示数据库或缓存没有该账号的注册信息需要咱们创建一个。
account = Entity.Create<Account>(scene, true, true);
account.Username = username;
account.Password = password;
account.Password = username;
account.Region = region;
account.CreateTime = TimeHelper.Now;
// 写入这个实体到数据中
await worldDateBase.Save(account);