diff --git a/DotNet/Logic/src/Handler/UserHandler/H_C2G_LoginRequestHandler.cs b/DotNet/Logic/src/Handler/UserHandler/H_C2G_LoginRequestHandler.cs index 77a94f9d..9959c3c1 100644 --- a/DotNet/Logic/src/Handler/UserHandler/H_C2G_LoginRequestHandler.cs +++ b/DotNet/Logic/src/Handler/UserHandler/H_C2G_LoginRequestHandler.cs @@ -22,18 +22,35 @@ namespace TEngine.Logic return; } - if (result[0].Forbid) + AccountInfo account = result[0]; + + if (account.Forbid) { response.ErrorCode = ErrorCode.ERR_AccountIsForbid; reply(); return; } + AccountComponent accountComponent = session.Scene.GetComponent(); + if (accountComponent.Get(account.UID) != null) + { + response.ErrorCode = ErrorCode.ERR_LoginError; + reply(); + return; + } + else + { + var accountInfo = session.AddComponent(); + accountInfo.UID = account.UID; + accountInfo.SDKUID = account.SDKUID; + accountComponent.Add(account); + } + Log.Debug($"收到请求登录的消息 request:{request.ToJson()}"); response.Text = "登录成功"; - response.UID = result[0].UID; + response.UID = account.UID; await FTask.CompletedTask; - } + } } } #endif \ No newline at end of file diff --git a/DotNet/Logic/src/Handler/UserHandler/H_C2G_RegisterRequestHandler.cs b/DotNet/Logic/src/Handler/UserHandler/H_C2G_RegisterRequestHandler.cs index e572c285..cfd9ed39 100644 --- a/DotNet/Logic/src/Handler/UserHandler/H_C2G_RegisterRequestHandler.cs +++ b/DotNet/Logic/src/Handler/UserHandler/H_C2G_RegisterRequestHandler.cs @@ -15,12 +15,19 @@ namespace TEngine.Logic await db.Query(t=>t.UserName == request.UserName) : await db.Query(t=>t.SDKUID == request.SDKUID) ; - if (result.Count > 0) + if (result.Count == 1) { response.ErrorCode = ErrorCode.ERR_AccountAlreadyRegisted; reply(); return; } + else if (result.Count >= 1) + { + response.ErrorCode = ErrorCode.ERR_AccountAlreadyRegisted; + Log.Error("出现重复账号:" + request.UserName); + reply(); + return; + } uint uid = await GeneratorUID(db); diff --git a/DotNet/Logic/src/Model/AccountComponent.cs b/DotNet/Logic/src/Model/AccountComponent.cs new file mode 100644 index 00000000..94df269c --- /dev/null +++ b/DotNet/Logic/src/Model/AccountComponent.cs @@ -0,0 +1,68 @@ +namespace TEngine.Logic; + +/// +/// 场景账号管理组件。 +/// [Scene] +/// +public class AccountComponent:Entity, INotSupportedPool +{ + /// + /// 当前登陆的账号。 + /// + public readonly Dictionary accountInfoMap = new Dictionary(); + + /// + /// 获取账号信息。 + /// + /// + /// + public AccountInfo? Get(uint uid) + { + this.accountInfoMap.TryGetValue(uid, out AccountInfo? ret); + return ret; + } + + /// + /// 添加当前登录的账号。 + /// + /// 账号信息。 + /// + public bool Add(AccountInfo? accountInfo) + { + if (accountInfo == null) + { + return false; + } + + if (this.accountInfoMap.ContainsKey(accountInfo.UID)) + { + return false; + } + + this.accountInfoMap[accountInfo.UID] = accountInfo; + + return true; + } + + /// + /// 移除当前登录的账号。 + /// + /// 账号信息。 + /// + public bool Remove(AccountInfo? accountInfo) + { + if (accountInfo == null) + { + return false; + } + + if (!this.accountInfoMap.ContainsKey(accountInfo.UID)) + { + return false; + } + + this.accountInfoMap.Remove(accountInfo.UID); + + return true; + } +} \ No newline at end of file diff --git a/DotNet/Logic/src/Model/AccountInfo.cs b/DotNet/Logic/src/Model/AccountInfo.cs index 6141ce73..9379c9b0 100644 --- a/DotNet/Logic/src/Model/AccountInfo.cs +++ b/DotNet/Logic/src/Model/AccountInfo.cs @@ -29,4 +29,11 @@ public class AccountInfo : Entity /// 是否禁用账号。 /// public bool Forbid { get; set; } + + public override void Dispose() + { + Log.Debug($"UID:{this.UID}"); + this.Parent?.Scene?.GetComponent()?.Remove(this); + base.Dispose(); + } } \ No newline at end of file diff --git a/DotNet/Logic/src/Model/UserInfo.cs b/DotNet/Logic/src/Model/CharacterInfo.cs similarity index 76% rename from DotNet/Logic/src/Model/UserInfo.cs rename to DotNet/Logic/src/Model/CharacterInfo.cs index be29ebea..796b234e 100644 --- a/DotNet/Logic/src/Model/UserInfo.cs +++ b/DotNet/Logic/src/Model/CharacterInfo.cs @@ -1,8 +1,8 @@ namespace TEngine.Logic; -public class UserInfoAwakeSystem : AwakeSystem +public class CharacterInfoAwakeSystem : AwakeSystem { - protected override void Awake(UserInfo self) + protected override void Awake(CharacterInfo self) { self.Awake(); } @@ -11,7 +11,7 @@ public class UserInfoAwakeSystem : AwakeSystem /// /// 角色信息。 /// -public class UserInfo : Entity +public class CharacterInfo : Entity { //昵称 public string UserName { get; set; } diff --git a/DotNet/Logic/src/OnCreateScene.cs b/DotNet/Logic/src/OnCreateScene.cs index 1e774d9c..6f57f916 100644 --- a/DotNet/Logic/src/OnCreateScene.cs +++ b/DotNet/Logic/src/OnCreateScene.cs @@ -4,7 +4,8 @@ using TEngine.Core.Network; namespace TEngine.Logic; /// -/// 当Scene创建时需要干什么 +/// 场景创建回调。 +/// 常用于定义场景需要添加的组件。 /// public class OnCreateScene : AsyncEventSystem { @@ -23,6 +24,11 @@ public class OnCreateScene : AsyncEventSystem sceneConfigInfo.Scene.AddComponent(); break; } + case "Gate": + { + sceneConfigInfo.Scene.AddComponent(); + break; + } } Log.Info($"scene create: {self.SceneInfo.SceneType} {self.SceneInfo.Name} SceneId:{self.SceneInfo.Id} ServerId:{self.SceneInfo.RouteId} WorldId:{self.SceneInfo.WorldId}");