This commit is contained in:
2025-08-07 09:16:23 +08:00
parent c97bd0ab55
commit 70bfe43a80
34 changed files with 532 additions and 135 deletions

View File

@@ -0,0 +1,55 @@
using Fantasy;
using Fantasy.Async;
using Fantasy.Entitas;
using Fantasy.Network;
using Fantasy.Platform.Net;
using NB.Game;
namespace NB.Gate;
public static class GateUnitManageComponentSystem
{
public static GateUnit Add(this GateUnitManageComponent self, Session session, long accountId)
{
if (self.Units.TryGetValue(accountId, out var unit))
{
unit.Session = session;
return unit;
}
unit = Entity.Create<GateUnit>(self.Scene, accountId, true, true);
unit.AccountID = accountId;
unit.Session = session;
self.Units.Add(accountId, unit);
return unit;
}
public static GateUnit? Get(this GateUnitManageComponent self, long accountId)
{
return self.Units.GetValueOrDefault(accountId);
}
public static bool TryGet(this GateUnitManageComponent self, long accountId, out GateUnit? unit)
{
return self.Units.TryGetValue(accountId, out unit);
}
public static async FTask Remove(this GateUnitManageComponent self, long accountId, bool isDispose = true)
{
if (!self.Units.TryGetValue(accountId, out var unit)) return;
//通知其他服务器下线
var result = await GateLoginHelper.Offline(unit);
if (result != 0)
{
Log.Error($"通知其他服务器下线失败,错误码:{result}");
return;
}
Log.Info($"accountId:{accountId} 下线成功");
self.Units.Remove(accountId);
if (isDispose)
{
unit.Dispose();
}
}
}

View File

@@ -0,0 +1,17 @@
using Fantasy.Entitas.Interface;
namespace NB.Gate;
public class GateUnitSessionComponentSystem : DestroySystem<GateUnitSessionComponent>
{
protected override void Destroy(GateUnitSessionComponent self)
{
var gateUnitManageComponent = self.Scene.GetComponent<GateUnitManageComponent>();
if (gateUnitManageComponent != null)
{
_ = gateUnitManageComponent.Remove(self.AccountID);
}
self.AccountID = 0;
}
}

View File

@@ -0,0 +1,16 @@
using Fantasy.Entitas.Interface;
namespace NB.Gate;
public class GateUnitDestroySystem : DestroySystem<GateUnit>
{
protected override void Destroy(GateUnit self)
{
self.AccountID = 0;
self.Kick = false;
}
}
public class GateUnitSystem
{
}

View File

@@ -1,19 +1,19 @@
using Fantasy.Entitas.Interface;
namespace NB.Gate;
public sealed class SessionPlayerComponentDestroySystem : DestroySystem<SessionPlayerComponent>
{
protected override void Destroy(SessionPlayerComponent self)
{
if (self.AccountID != 0)
{
// 执行下线过程、并且要求在5分钟后完成缓存清理。也就是5分钟后会保存数据到数据库。
// 由于5分钟太长了、咱们测试的时候不方便测试也可以把这个时间改短一些比如10秒。
// PlayerHelper.Disconnect(self.Scene, self.AccountID, 1000 * 60 * 5).Coroutine();
// self.AccountID = 0;
}
// self.Player = null;
}
}
// using Fantasy.Entitas.Interface;
//
// namespace NB.Gate;
//
// public sealed class SessionPlayerComponentDestroySystem : DestroySystem<GateUnitSessionComponent>
// {
// protected override void Destroy(GateUnitSessionComponent self)
// {
// if (self.AccountID != 0)
// {
// // 执行下线过程、并且要求在5分钟后完成缓存清理。也就是5分钟后会保存数据到数据库。
// // 由于5分钟太长了、咱们测试的时候不方便测试也可以把这个时间改短一些比如10秒。
// // PlayerHelper.Disconnect(self.Scene, self.AccountID, 1000 * 60 * 5).Coroutine();
// // self.AccountID = 0;
// }
//
// // self.Player = null;
// }
// }