mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
注册登录Demo
注册登录Demo
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
// 生成器自动生成,请不要手动编辑。
|
||||
|
@@ -152,6 +152,33 @@ namespace TEngine
|
||||
[ProtoMember(91, IsRequired = true)]
|
||||
public int ErrorCode { get; set; }
|
||||
[ProtoMember(1)]
|
||||
public uint UID { get; set; }
|
||||
[ProtoMember(2)]
|
||||
public string Text { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 客户端发送消息请求注册账户
|
||||
/// </summary>
|
||||
[ProtoContract]
|
||||
public partial class H_C2G_RegisterRequest : AProto, IRequest
|
||||
{
|
||||
[ProtoIgnore]
|
||||
public H_G2C_RegisterResponse ResponseType { get; set; }
|
||||
public uint OpCode() { return OuterOpcode.H_C2G_RegisterRequest; }
|
||||
[ProtoMember(1)]
|
||||
public string UserName { get; set; }
|
||||
[ProtoMember(2)]
|
||||
public string Password { get; set; }
|
||||
[ProtoMember(3)]
|
||||
public uint SDKUID { get; set; }
|
||||
}
|
||||
[ProtoContract]
|
||||
public partial class H_G2C_RegisterResponse : AProto, IResponse
|
||||
{
|
||||
public uint OpCode() { return OuterOpcode.H_G2C_RegisterResponse; }
|
||||
[ProtoMember(91, IsRequired = true)]
|
||||
public int ErrorCode { get; set; }
|
||||
[ProtoMember(1)]
|
||||
public uint UID { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -16,5 +16,7 @@ namespace TEngine
|
||||
public const int H_M2C_ReceiveAddressMessageToServer = 190000003;
|
||||
public const int H_C2G_LoginRequest = 110000003;
|
||||
public const int H_G2C_LoginResponse = 160000003;
|
||||
public const int H_C2G_RegisterRequest = 110000004;
|
||||
public const int H_G2C_RegisterResponse = 160000004;
|
||||
}
|
||||
}
|
||||
|
@@ -1,18 +0,0 @@
|
||||
#if TENGINE_NET
|
||||
using System;
|
||||
using TEngine.Core.Network;
|
||||
using TEngine.Core;
|
||||
|
||||
namespace TEngine.Logic
|
||||
{
|
||||
public class H_C2G_LoginRequestHandler : MessageRPC<H_C2G_LoginRequest,H_G2C_LoginResponse>
|
||||
{
|
||||
protected override async FTask Run(Session session, H_C2G_LoginRequest request, H_G2C_LoginResponse response, Action reply)
|
||||
{
|
||||
Log.Debug($"收到请求登录的消息 request:{request.ToJson()}");
|
||||
response.Text = "登录成功";
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,39 @@
|
||||
#if TENGINE_NET
|
||||
using System;
|
||||
using TEngine.Core.Network;
|
||||
using TEngine.Core;
|
||||
using TEngine.Core.DataBase;
|
||||
|
||||
namespace TEngine.Logic
|
||||
{
|
||||
public class H_C2G_LoginRequestHandler: MessageRPC<H_C2G_LoginRequest, H_G2C_LoginResponse>
|
||||
{
|
||||
protected override async FTask Run(Session session, H_C2G_LoginRequest request, H_G2C_LoginResponse response, Action reply)
|
||||
{
|
||||
IDateBase db = session.Scene.World.DateBase;
|
||||
List<AccountInfo> result = await db.Query<AccountInfo>(
|
||||
t=>t.UserName == request.UserName &&
|
||||
t.Password == request.Password);
|
||||
|
||||
if (result.Count < 1)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ERR_AccountOrPasswordError;
|
||||
reply();
|
||||
return;
|
||||
}
|
||||
|
||||
if (result[0].Forbid)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ERR_AccountIsForbid;
|
||||
reply();
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Debug($"收到请求登录的消息 request:{request.ToJson()}");
|
||||
response.Text = "登录成功";
|
||||
response.UID = result[0].UID;
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,50 @@
|
||||
using TEngine.Core.Network;
|
||||
using TEngine.Core;
|
||||
using TEngine.Core.DataBase;
|
||||
|
||||
namespace TEngine.Logic
|
||||
{
|
||||
public class H_C2G_RegisterRequestHandler: MessageRPC<H_C2G_RegisterRequest, H_G2C_RegisterResponse>
|
||||
{
|
||||
protected override async FTask Run(Session session, H_C2G_RegisterRequest request, H_G2C_RegisterResponse response, Action reply)
|
||||
{
|
||||
IDateBase db = session.Scene.World.DateBase;
|
||||
bool isSDKRegister = request.SDKUID != 0;
|
||||
|
||||
List<AccountInfo> result = !isSDKRegister ?
|
||||
await db.Query<AccountInfo>(t=>t.UserName == request.UserName) :
|
||||
await db.Query<AccountInfo>(t=>t.SDKUID == request.SDKUID) ;
|
||||
|
||||
if (result.Count > 0)
|
||||
{
|
||||
response.ErrorCode = ErrorCode.ERR_AccountAlreadyRegisted;
|
||||
reply();
|
||||
return;
|
||||
}
|
||||
|
||||
uint uid = await GeneratorUID(db);
|
||||
|
||||
AccountInfo accountInfo = Entity.Create<AccountInfo>(session.Scene);
|
||||
accountInfo.UserName = request.UserName;
|
||||
accountInfo.Password = request.Password;
|
||||
accountInfo.SDKUID = request.SDKUID;
|
||||
accountInfo.UID = uid;
|
||||
|
||||
db.Save(accountInfo);
|
||||
|
||||
Log.Debug($"收到注册的消息 request:{request.ToJson()}");
|
||||
response.UID = uid;
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
|
||||
public async FTask<uint> GeneratorUID(IDateBase db)
|
||||
{
|
||||
var ret = await db.First<AccountInfo>(t=>t.UID != 0);
|
||||
if (ret == null)
|
||||
{
|
||||
return 100000;
|
||||
}
|
||||
return ret.UID + 1;
|
||||
}
|
||||
}
|
||||
}
|
32
DotNet/Logic/src/Model/AccountInfo.cs
Normal file
32
DotNet/Logic/src/Model/AccountInfo.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
namespace TEngine.Logic;
|
||||
|
||||
/// <summary>
|
||||
/// 账号信息
|
||||
/// </summary>
|
||||
public class AccountInfo : Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户唯一ID。
|
||||
/// </summary>
|
||||
public uint UID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户名。
|
||||
/// </summary>
|
||||
public string UserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 密码。
|
||||
/// </summary>
|
||||
public string Password { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 渠道唯一ID。
|
||||
/// </summary>
|
||||
public uint SDKUID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否禁用账号。
|
||||
/// </summary>
|
||||
public bool Forbid { get; set; }
|
||||
}
|
38
DotNet/Logic/src/Model/UserInfo.cs
Normal file
38
DotNet/Logic/src/Model/UserInfo.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
namespace TEngine.Logic;
|
||||
|
||||
public class UserInfoAwakeSystem : AwakeSystem<UserInfo>
|
||||
{
|
||||
protected override void Awake(UserInfo self)
|
||||
{
|
||||
self.Awake();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 角色信息。
|
||||
/// </summary>
|
||||
public class UserInfo : Entity
|
||||
{
|
||||
//昵称
|
||||
public string UserName { get; set; }
|
||||
|
||||
//等级
|
||||
public int Level { get; set; }
|
||||
|
||||
//余额
|
||||
public long Money { get; set; }
|
||||
|
||||
|
||||
//上次游戏角色序列 1/2/3
|
||||
public int LastPlay { get; set; }
|
||||
|
||||
//public List<Ca>
|
||||
public void Awake()
|
||||
{
|
||||
UserName = string.Empty;
|
||||
Level = 1;
|
||||
Money = 10000;
|
||||
LastPlay = 0;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user