Skip to content

Commit

Permalink
[修改]1. 修改登录流程为Web 的方式
Browse files Browse the repository at this point in the history
  • Loading branch information
AlianBlank committed Dec 26, 2024
1 parent e8230f5 commit 25f627c
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 10 deletions.
4 changes: 2 additions & 2 deletions GameFrameX.Apps/Account/Login/Component/LoginComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Threading.Tasks;
/*using System.Threading.Tasks;
using GameFrameX.Apps.Account.Login.Entity;
using GameFrameX.Apps.Player.Player.Entity;
using GameFrameX.Core.Abstractions.Attribute;
Expand Down Expand Up @@ -48,4 +48,4 @@ public async Task<PlayerState> OnPlayerCreate(ReqPlayerCreate reqPlayerCreate)
await GameDb.SaveOneAsync(playerState);
return playerState;
}
}
}*/
4 changes: 2 additions & 2 deletions GameFrameX.Hotfix/Logic/Account/Login/LoginComponentAgent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GameFrameX.Apps.Account.Login.Component;
/*using GameFrameX.Apps.Account.Login.Component;
using GameFrameX.Apps.Account.Login.Entity;
using GameFrameX.Hotfix.Common;
using GameFrameX.NetWork.Abstractions;
Expand Down Expand Up @@ -95,4 +95,4 @@ public async Task OnGetPlayerList(INetWorkChannel workChannel, ReqPlayerList req
await workChannel.WriteAsync(respPlayerList);
}
}
}*/
4 changes: 2 additions & 2 deletions GameFrameX.Hotfix/Logic/Account/Login/ReqLoginHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GameFrameX.Core.BaseHandler;
/*using GameFrameX.Core.BaseHandler;
using GameFrameX.NetWork.Abstractions;
namespace GameFrameX.Hotfix.Logic.Account.Login;
Expand All @@ -10,4 +10,4 @@ protected override async Task ActionAsync()
{
await ComponentAgent.OnLogin(NetWorkChannel, Message as ReqLogin);
}
}
}*/
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GameFrameX.Core.BaseHandler;
/*using GameFrameX.Core.BaseHandler;
using GameFrameX.NetWork.Abstractions;
namespace GameFrameX.Hotfix.Logic.Account.Login;
Expand All @@ -10,4 +10,4 @@ protected override async Task ActionAsync()
{
await ComponentAgent.OnPlayerCreate(NetWorkChannel, Message as ReqPlayerCreate);
}
}
}*/
4 changes: 2 additions & 2 deletions GameFrameX.Hotfix/Logic/Account/Login/ReqPlayerListHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GameFrameX.Core.BaseHandler;
/*using GameFrameX.Core.BaseHandler;
using GameFrameX.NetWork.Abstractions;
namespace GameFrameX.Hotfix.Logic.Account.Login;
Expand All @@ -10,4 +10,4 @@ protected override async Task ActionAsync()
{
await ComponentAgent.OnGetPlayerList(NetWorkChannel, Message as ReqPlayerList);
}
}
}*/
58 changes: 58 additions & 0 deletions GameFrameX.Hotfix/Logic/Http/ReqLoginHttpHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using GameFrameX.Apps.Account.Login.Entity;
using GameFrameX.DataBase;
using GameFrameX.Hotfix.Common;
using GameFrameX.Monitor.Account;
using GameFrameX.NetWork.HTTP;

namespace GameFrameX.Hotfix.Logic.Http;

/// <summary>
/// 账号登录
/// </summary>
[HttpMessageMapping(typeof(ReqLoginHttpHandler))]
public sealed class ReqLoginHttpHandler : BaseHttpHandler
{
public override async Task<string> Action(string ip, string url, Dictionary<string, object> paramMap)
{
ReqLogin reqLogin = JsonHelper.Deserialize<ReqLogin>(JsonHelper.Serialize(paramMap));

if (reqLogin.UserName.IsNullOrEmpty() || reqLogin.Password.IsNullOrEmpty())
{
return HttpResult.Create((int)ResultCode.Failed);
}

MetricsAccountRegister.LoginCounterOptions.Inc();
var loginState = await OnLogin(reqLogin);

if (loginState == null)
{
var accountId = ActorIdGenerator.GetUniqueId();
loginState = await Register(accountId, reqLogin);
}

// 构建账号登录返回信息
var respLogin = new RespLogin
{
Code = loginState.State,
CreateTime = loginState.CreateTime,
Level = loginState.Level,
Id = loginState.Id,
RoleName = loginState.NickName,
};
return HttpResult.Create(JsonHelper.Serialize(respLogin));
}

public async Task<LoginState> OnLogin(ReqLogin reqLogin)
{
MetricsAccountRegister.LoginCounterOptions.Inc();
return await GameDb.FindAsync<LoginState>(m => m.UserName == reqLogin.UserName && m.Password == reqLogin.Password);
}

public async Task<LoginState> Register(long accountId, ReqLogin reqLogin)
{
MetricsAccountRegister.RegisterCounterOptions.Inc();
var loginState = new LoginState { Id = accountId, UserName = reqLogin.UserName, Password = reqLogin.Password, };
await GameDb.SaveOneAsync(loginState);
return loginState;
}
}
52 changes: 52 additions & 0 deletions GameFrameX.Hotfix/Logic/Http/ReqPlayerCreateHttpHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using GameFrameX.Apps.Account.Login.Entity;
using GameFrameX.Apps.Player.Player.Entity;
using GameFrameX.DataBase;
using GameFrameX.Hotfix.Common;
using GameFrameX.Monitor.Account;
using GameFrameX.Monitor.Player;
using GameFrameX.NetWork.HTTP;

namespace GameFrameX.Hotfix.Logic.Http;

/// <summary>
/// 角色创建
/// </summary>
[HttpMessageMapping(typeof(ReqPlayerCreateHttpHandler))]
public sealed class ReqPlayerCreateHttpHandler : BaseHttpHandler
{
public override async Task<string> Action(string ip, string url, Dictionary<string, object> paramMap)
{
var reqPlayerCreate = JsonHelper.Deserialize<ReqPlayerCreate>(JsonHelper.Serialize(paramMap));

var playerState = await OnPlayerCreate(reqPlayerCreate);
var respPlayerCreate = new RespPlayerCreate
{
UniqueId = reqPlayerCreate.UniqueId,
PlayerInfo = new PlayerInfo
{
Id = playerState.Id,
Name = playerState.Name,
Level = playerState.Level,
State = playerState.State,
Avatar = playerState.Avatar,
},
};
return HttpResult.Create(JsonHelper.Serialize(respPlayerCreate));
}

private async Task<PlayerState> OnPlayerCreate(ReqPlayerCreate reqPlayerCreate)
{
var playerState = new PlayerState
{
Id = ActorIdGenerator.GetActorId(GlobalConst.ActorTypePlayer),
AccountId = reqPlayerCreate.Id,
Name = reqPlayerCreate.Name,
Level = (uint)Utility.Random.Next(1, 50),
State = 0,
Avatar = (uint)Utility.Random.Next(1, 50),
};
MetricsPlayerRegister.CreateCounterOptions.Inc();
await GameDb.SaveOneAsync(playerState);
return playerState;
}
}
54 changes: 54 additions & 0 deletions GameFrameX.Hotfix/Logic/Http/ReqPlayerListHttpHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using GameFrameX.Apps.Player.Player.Entity;
using GameFrameX.DataBase;
using GameFrameX.Monitor.Player;
using GameFrameX.NetWork.HTTP;

namespace GameFrameX.Hotfix.Logic.Http;

/// <summary>
/// 获取角色列表
/// </summary>
[HttpMessageMapping(typeof(ReqPlayerListHttpHandler))]
public sealed class ReqPlayerListHttpHandler : BaseHttpHandler
{
public override async Task<string> Action(string ip, string url, Dictionary<string, object> paramMap)
{
ReqPlayerList reqPlayerList = JsonHelper.Deserialize<ReqPlayerList>(JsonHelper.Serialize(paramMap));

if (reqPlayerList.Id == default)
{
return HttpResult.Create(HttpStatusCode.NotFound, "账号不存在");
}

var playerList = await GetPlayerList(reqPlayerList);

var respPlayerList = new RespPlayerList
{
UniqueId = reqPlayerList.UniqueId,
PlayerList = new List<PlayerInfo>(),
};
if (playerList != null)
{
foreach (var playerState in playerList)
{
var playerInfo = new PlayerInfo
{
Id = playerState.Id,
Name = playerState.Name,
};
playerInfo.Level = playerState.Level;
playerInfo.State = playerState.State;
playerInfo.Avatar = playerState.Avatar;
respPlayerList.PlayerList.Add(playerInfo);
}
}

return HttpResult.Create(JsonHelper.Serialize(respPlayerList));
}

private async Task<List<PlayerState>> GetPlayerList(ReqPlayerList reqPlayerList)
{
MetricsPlayerRegister.GetPlayerListCounterOptions.Inc();
return await GameDb.FindListAsync<PlayerState>(m => m.AccountId == reqPlayerList.Id);
}
}

0 comments on commit 25f627c

Please sign in to comment.