-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8230f5
commit 25f627c
Showing
8 changed files
with
174 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
52
GameFrameX.Hotfix/Logic/Http/ReqPlayerCreateHttpHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |