CTT/Server/Model/Demo/GateSessionKeyComponent.cs

34 lines
817 B
C#
Executable File

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)
{
this.sessionKey.TryGetValue(key, out long account);
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);
}
}
}