房间创建和进入相关逻辑和协议
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
// using Fantasy;
|
||||
// using Fantasy.Async;
|
||||
// using Fantasy.Entitas;
|
||||
// using Fantasy.Helper;
|
||||
// using Fantasy.Network;
|
||||
// using Fantasy.Network.Interface;
|
||||
// using NB;
|
||||
// using NB.Gate;
|
||||
//
|
||||
// namespace NB.Game;
|
||||
//
|
||||
// public class G2Game_EnterRequestHandler : RouteRPC<Scene, G2Game_EnterRequest, Game2G_EnterResponse>
|
||||
// {
|
||||
// protected override async FTask Run(Scene scene, G2Game_EnterRequest request, Game2G_EnterResponse response,
|
||||
// Action reply)
|
||||
// {
|
||||
// Log.Debug("收到 G2Game_EnterRequestHandler");
|
||||
//
|
||||
//
|
||||
// // 在缓存中检查该账号是否存在
|
||||
// var gameAccountManageComponent = scene.GetComponent<PlayerManageComponent>();
|
||||
//
|
||||
// var account = await gameAccountManageComponent.Online(scene, request.AccountId, request.GateRouteId);
|
||||
//
|
||||
// response.RoleRouteId = account.RuntimeId;
|
||||
// response.RoleInfo = account.GetRoleSimpleInfo();
|
||||
// await FTask.CompletedTask;
|
||||
// }
|
||||
// }
|
||||
@@ -40,24 +40,22 @@ public static class PlayerManageComponentSystem
|
||||
/// 玩家上线
|
||||
/// </summary>
|
||||
/// <param name="self"></param>
|
||||
/// <param name="scene"></param>
|
||||
/// <param name="accountId"></param>
|
||||
/// <param name="gateRouteId"></param>
|
||||
public static async FTask<Player?> Online(this PlayerManageComponent self, Scene scene, long accountId,
|
||||
long gateRouteId)
|
||||
public static async FTask<Player?> Online(this PlayerManageComponent self, long accountId, long gateRouteId)
|
||||
{
|
||||
Log.Debug("检查账号是否在缓存中");
|
||||
if (!self.TryGet(accountId, out var account))
|
||||
{
|
||||
// 首先要先到数据库中查询是否有这个账号
|
||||
account = await PlayerHelper.LoadDataBase(scene, accountId);
|
||||
account = await PlayerHelper.LoadDataBase(self.Scene, accountId);
|
||||
// 如果有的话,就直接加入在缓存中就可以了
|
||||
if (account == null)
|
||||
{
|
||||
Log.Debug("检查到账号没有在数据库中,需要创建一个新的账号并且保存到数据库中");
|
||||
// 如果没有,就要创建一个新的并且保存到数据库。
|
||||
// 如果不存在,表示这是一个新的账号,需要创建一下这个账号。
|
||||
account = PlayerFactory.Create(scene, accountId);
|
||||
account = PlayerFactory.Create(self.Scene, accountId);
|
||||
|
||||
|
||||
account.Level = 99;
|
||||
@@ -111,6 +109,19 @@ public static class PlayerManageComponentSystem
|
||||
return account;
|
||||
}
|
||||
|
||||
public static async FTask Offline(this PlayerManageComponent self, long accountId, long sessionId)
|
||||
{
|
||||
if (self.TryGet(accountId, out var account))
|
||||
{
|
||||
if (account.SessionRunTimeId == sessionId)
|
||||
{
|
||||
//退出的是当前的
|
||||
await account.Save();
|
||||
self.Remove(accountId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取&移除
|
||||
|
||||
Reference in New Issue
Block a user