修复插槽清理后的bug
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
using Fantasy.Entitas;
|
||||
|
||||
namespace NB;
|
||||
|
||||
public class EntityTimeOutComponent : Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 主要是用于检测每次请求的间隔,这里存放是下一次能正常通信时间
|
||||
/// </summary>
|
||||
public long NextTime;
|
||||
|
||||
/// <summary>
|
||||
/// 用来设置检查的间隔时间
|
||||
/// </summary>
|
||||
public int Interval;
|
||||
|
||||
/// <summary>
|
||||
/// 用于记录时间计划任务的ID,后面可以通过这个ID随时取消这个任务
|
||||
/// </summary>
|
||||
public long TimerId;
|
||||
}
|
||||
// using Fantasy.Entitas;
|
||||
//
|
||||
// namespace NB;
|
||||
//
|
||||
// public class EntityTimeOutComponent : Entity
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// 主要是用于检测每次请求的间隔,这里存放是下一次能正常通信时间
|
||||
// /// </summary>
|
||||
// public long NextTime;
|
||||
//
|
||||
// /// <summary>
|
||||
// /// 用来设置检查的间隔时间
|
||||
// /// </summary>
|
||||
// public int Interval;
|
||||
//
|
||||
// /// <summary>
|
||||
// /// 用于记录时间计划任务的ID,后面可以通过这个ID随时取消这个任务
|
||||
// /// </summary>
|
||||
// public long TimerId;
|
||||
// }
|
||||
@@ -13,14 +13,14 @@ public class C2A_LoginRequestHandler : MessageRPC<C2A_LoginRequest, A2C_LoginRes
|
||||
protected override async FTask Run(Session session, C2A_LoginRequest request, A2C_LoginResponse response,
|
||||
Action reply)
|
||||
{
|
||||
if (!session.CheckInterval(20000))
|
||||
{
|
||||
// 返回这个3代表操作过于频繁。
|
||||
response.ErrorCode = ErrorCode.ErrFrequent;
|
||||
return;
|
||||
}
|
||||
// if (!session.CheckInterval(20000))
|
||||
// {
|
||||
// // 返回这个3代表操作过于频繁。
|
||||
// response.ErrorCode = ErrorCode.ErrFrequent;
|
||||
// return;
|
||||
// }
|
||||
|
||||
session.SetTimeout(3000);
|
||||
// session.SetTimeout(3000);
|
||||
var scene = session.Scene;
|
||||
Log.Info($"登录服场景 {scene.Id} {scene.RuntimeId} {scene.SceneConfigId}");
|
||||
var result = await AuthenticationHelper.Login(scene, request.Username, request.Password);
|
||||
|
||||
@@ -1,48 +1,48 @@
|
||||
using System;
|
||||
using NB.Authentication;
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Network;
|
||||
// ReSharper disable ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
|
||||
|
||||
namespace NB;
|
||||
|
||||
public static class EntityHelper
|
||||
{
|
||||
public static bool CheckInterval(this Entity entity, int interval)
|
||||
{
|
||||
var sessionTimeOutComponent = entity.GetComponent<EntityTimeOutComponent>();
|
||||
|
||||
if (sessionTimeOutComponent == null)
|
||||
{
|
||||
sessionTimeOutComponent = entity.AddComponent<EntityTimeOutComponent>();
|
||||
sessionTimeOutComponent.SetInterval(interval);
|
||||
return true;
|
||||
}
|
||||
|
||||
return sessionTimeOutComponent.CheckInterval();
|
||||
}
|
||||
|
||||
public static void SetTimeout(this Entity entity, int timeout = 3000, Func<FTask>? task = null)
|
||||
{
|
||||
var sessionTimeOutComponent = entity.GetComponent<EntityTimeOutComponent>();
|
||||
|
||||
if (sessionTimeOutComponent == null)
|
||||
{
|
||||
sessionTimeOutComponent = entity.AddComponent<EntityTimeOutComponent>();
|
||||
}
|
||||
|
||||
sessionTimeOutComponent.TimeOut(timeout, task);
|
||||
}
|
||||
|
||||
public static bool IsTimeOutComponent(this Entity entity)
|
||||
{
|
||||
return entity.GetComponent<EntityTimeOutComponent>() != null;
|
||||
}
|
||||
|
||||
public static void CancelTimeout(this Entity entity)
|
||||
{
|
||||
entity.RemoveComponent<EntityTimeOutComponent>();
|
||||
}
|
||||
}
|
||||
// using System;
|
||||
// using NB.Authentication;
|
||||
// using Fantasy;
|
||||
// using Fantasy.Async;
|
||||
// using Fantasy.Entitas;
|
||||
// using Fantasy.Network;
|
||||
// // ReSharper disable ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
|
||||
//
|
||||
// namespace NB;
|
||||
//
|
||||
// public static class EntityHelper
|
||||
// {
|
||||
// public static bool CheckInterval(this Entity entity, int interval)
|
||||
// {
|
||||
// var sessionTimeOutComponent = entity.GetComponent<EntityTimeOutComponent>();
|
||||
//
|
||||
// if (sessionTimeOutComponent == null)
|
||||
// {
|
||||
// sessionTimeOutComponent = entity.AddComponent<EntityTimeOutComponent>();
|
||||
// sessionTimeOutComponent.SetInterval(interval);
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// return sessionTimeOutComponent.CheckInterval();
|
||||
// }
|
||||
//
|
||||
// public static void SetTimeout(this Entity entity, int timeout = 3000, Func<FTask>? task = null)
|
||||
// {
|
||||
// var sessionTimeOutComponent = entity.GetComponent<EntityTimeOutComponent>();
|
||||
//
|
||||
// if (sessionTimeOutComponent == null)
|
||||
// {
|
||||
// sessionTimeOutComponent = entity.AddComponent<EntityTimeOutComponent>();
|
||||
// }
|
||||
//
|
||||
// sessionTimeOutComponent.TimeOut(timeout, task);
|
||||
// }
|
||||
//
|
||||
// public static bool IsTimeOutComponent(this Entity entity)
|
||||
// {
|
||||
// return entity.GetComponent<EntityTimeOutComponent>() != null;
|
||||
// }
|
||||
//
|
||||
// public static void CancelTimeout(this Entity entity)
|
||||
// {
|
||||
// entity.RemoveComponent<EntityTimeOutComponent>();
|
||||
// }
|
||||
// }
|
||||
@@ -1,79 +1,79 @@
|
||||
using System;
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Entitas.Interface;
|
||||
using Fantasy.Helper;
|
||||
|
||||
namespace NB.Authentication;
|
||||
|
||||
public sealed class EntityTimeOutComponentDestroySystem : DestroySystem<EntityTimeOutComponent>
|
||||
{
|
||||
protected override void Destroy(EntityTimeOutComponent self)
|
||||
{
|
||||
if (self.TimerId != 0)
|
||||
{
|
||||
self.Scene.TimerComponent.Net.Remove(ref self.TimerId);
|
||||
}
|
||||
|
||||
self.NextTime = 0;
|
||||
self.Interval = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EntityTimeOutComponentSystem
|
||||
{
|
||||
public static void SetInterval(this EntityTimeOutComponent self, int interval)
|
||||
{
|
||||
if (interval <= 0)
|
||||
{
|
||||
throw new ArgumentException("interval must be greater than 0", nameof(interval));
|
||||
}
|
||||
|
||||
self.Interval = interval;
|
||||
self.NextTime = TimeHelper.Now + interval;
|
||||
}
|
||||
|
||||
public static bool CheckInterval(this EntityTimeOutComponent self)
|
||||
{
|
||||
if (self.NextTime > TimeHelper.Now)
|
||||
{
|
||||
Log.Warning("当前连接请求的间隔过小");
|
||||
return false;
|
||||
}
|
||||
|
||||
self.NextTime = TimeHelper.Now + self.Interval;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void TimeOut(this EntityTimeOutComponent self, int timeout, Func<FTask>? task = null)
|
||||
{
|
||||
var scene = self.Scene;
|
||||
var parentRunTimeId = self.Parent.RuntimeId;
|
||||
|
||||
if (self.TimerId != 0)
|
||||
{
|
||||
self.Scene.TimerComponent.Net.Remove(ref self.TimerId);
|
||||
}
|
||||
|
||||
self.TimerId =
|
||||
scene.TimerComponent.Net.OnceTimer(timeout, () => { self.Handler(parentRunTimeId, task).Coroutine(); });
|
||||
}
|
||||
|
||||
private static async FTask Handler(this EntityTimeOutComponent self, long parentRunTimeId, Func<FTask>? task = null)
|
||||
{
|
||||
var selfParent = self.Parent;
|
||||
|
||||
if (selfParent == null || parentRunTimeId != selfParent.RuntimeId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (task != null)
|
||||
{
|
||||
await task();
|
||||
}
|
||||
|
||||
self.TimerId = 0;
|
||||
selfParent.Dispose();
|
||||
}
|
||||
}
|
||||
// using System;
|
||||
// using Fantasy;
|
||||
// using Fantasy.Async;
|
||||
// using Fantasy.Entitas.Interface;
|
||||
// using Fantasy.Helper;
|
||||
//
|
||||
// namespace NB.Authentication;
|
||||
//
|
||||
// public sealed class EntityTimeOutComponentDestroySystem : DestroySystem<EntityTimeOutComponent>
|
||||
// {
|
||||
// protected override void Destroy(EntityTimeOutComponent self)
|
||||
// {
|
||||
// if (self.TimerId != 0)
|
||||
// {
|
||||
// self.Scene.TimerComponent.Net.Remove(ref self.TimerId);
|
||||
// }
|
||||
//
|
||||
// self.NextTime = 0;
|
||||
// self.Interval = 0;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static class EntityTimeOutComponentSystem
|
||||
// {
|
||||
// public static void SetInterval(this EntityTimeOutComponent self, int interval)
|
||||
// {
|
||||
// if (interval <= 0)
|
||||
// {
|
||||
// throw new ArgumentException("interval must be greater than 0", nameof(interval));
|
||||
// }
|
||||
//
|
||||
// self.Interval = interval;
|
||||
// self.NextTime = TimeHelper.Now + interval;
|
||||
// }
|
||||
//
|
||||
// public static bool CheckInterval(this EntityTimeOutComponent self)
|
||||
// {
|
||||
// if (self.NextTime > TimeHelper.Now)
|
||||
// {
|
||||
// Log.Warning("当前连接请求的间隔过小");
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// self.NextTime = TimeHelper.Now + self.Interval;
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// public static void TimeOut(this EntityTimeOutComponent self, int timeout, Func<FTask>? task = null)
|
||||
// {
|
||||
// var scene = self.Scene;
|
||||
// var parentRunTimeId = self.Parent.RuntimeId;
|
||||
//
|
||||
// if (self.TimerId != 0)
|
||||
// {
|
||||
// self.Scene.TimerComponent.Net.Remove(ref self.TimerId);
|
||||
// }
|
||||
//
|
||||
// self.TimerId =
|
||||
// scene.TimerComponent.Net.OnceTimer(timeout, () => { self.Handler(parentRunTimeId, task).Coroutine(); });
|
||||
// }
|
||||
//
|
||||
// private static async FTask Handler(this EntityTimeOutComponent self, long parentRunTimeId, Func<FTask>? task = null)
|
||||
// {
|
||||
// var selfParent = self.Parent;
|
||||
//
|
||||
// if (selfParent == null || parentRunTimeId != selfParent.RuntimeId)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (task != null)
|
||||
// {
|
||||
// await task();
|
||||
// }
|
||||
//
|
||||
// self.TimerId = 0;
|
||||
// selfParent.Dispose();
|
||||
// }
|
||||
// }
|
||||
@@ -13,7 +13,7 @@ public class C2Game_GetItemsRequestHandler : AddressRPC<Player, C2Game_GetItemsR
|
||||
var itemContainer = entity.GetComponent<PlayerItemContainerComponent>();
|
||||
response.Items = itemContainer.GetItemInfos();
|
||||
response.Rigs = itemContainer.GetRigInfos();
|
||||
response.Slots = itemContainer.Slots;
|
||||
response.Slots = itemContainer.GetSlots();
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Entitas.Interface;
|
||||
@@ -161,5 +162,10 @@ public static class PlayerItemContainerComponentSystem
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static List<long> GetSlots(this PlayerItemContainerComponent self)
|
||||
{
|
||||
return self.Slots.ToList();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public static class PlayerManageComponentSystem
|
||||
{
|
||||
Log.Debug("检测到当前账号已经在缓存中了");
|
||||
// 如果有延迟下线的计划任务,那就先取消一下。
|
||||
account.CancelTimeout();
|
||||
// account.CancelTimeout();
|
||||
// 如果在Gate的缓存中已经存在了该账号那只能以下几种可能:
|
||||
// 1、同一客户端发送了重复登录的请求数据。
|
||||
// 2、客户端经历的断线然后又重新连接到这个服务器上了(断线重连)。
|
||||
|
||||
@@ -92,12 +92,12 @@ public static class PlayerHelper
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果不存在定时任务的组件,那就添加并设置定时任务
|
||||
if (account.IsTimeOutComponent())
|
||||
{
|
||||
// 如果已经存在了,那就表示当然已经有一个延时断开的任务了,那就不需要重复添加了
|
||||
return;
|
||||
}
|
||||
// // 如果不存在定时任务的组件,那就添加并设置定时任务
|
||||
// if (account.IsTimeOutComponent())
|
||||
// {
|
||||
// // 如果已经存在了,那就表示当然已经有一个延时断开的任务了,那就不需要重复添加了
|
||||
// return;
|
||||
// }
|
||||
|
||||
// 立即下线处理
|
||||
if (timeOut <= 0)
|
||||
@@ -108,7 +108,7 @@ public static class PlayerHelper
|
||||
}
|
||||
|
||||
// 设置延迟下线
|
||||
account.SetTimeout(timeOut, account.Disconnect);
|
||||
// account.SetTimeout(timeOut, account.Disconnect);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user