CTT/Server/Model/Demo/GateSessionKeyComponent.cs

34 lines
817 B
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using System.Collections.Generic;
namespace ET
{
public class GateSessionKeyComponent : Entity
{
private readonly Dictionary<long, long> sessionKey = new Dictionary<long, long>();
public void Add(long key, long userId)
{
this.sessionKey.Add(key, userId);
this.TimeoutRemoveKey(key).Coroutine();
}
public long Get(long key)
{
2021-04-11 19:50:39 +08:00
this.sessionKey.TryGetValue(key, out long account);
2021-04-08 20:09:59 +08:00
return account;
}
public void Remove(long key)
{
this.sessionKey.Remove(key);
}
private async ETVoid TimeoutRemoveKey(long key)
{
await Game.Scene.GetComponent<TimerComponent>().WaitAsync(20000);
this.sessionKey.Remove(key);
}
}
}