| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- using System.Collections.Generic;
- using Base;
- namespace Model
- {
- [DisposerEvent]
- public class GateSessionKeyComponentEvent : DisposerEvent<GateSessionKeyComponent>, IAwake
- {
- public void Awake()
- {
- this.GetValue().Awake();
- }
- }
- public class GateSessionKeyComponent : Component
- {
- private TimerComponent timerComponent;
- private readonly HashSet<long> sessionKey = new HashSet<long>();
- public void Awake()
- {
- this.timerComponent = Game.Scene.GetComponent<TimerComponent>();
- }
- public long Get()
- {
- long key = RandomHelper.RandInt64();
- this.sessionKey.Add(key);
- this.TimeoutRemoveKey(key);
- return key;
- }
- public bool Check(long key)
- {
- bool ret = this.sessionKey.Contains(key);
- if (ret)
- {
- this.sessionKey.Remove(key);
- }
- return ret;
- }
- public void Remove(long key)
- {
- this.sessionKey.Remove(key);
- }
- private async void TimeoutRemoveKey(long key)
- {
- await this.timerComponent.WaitAsync(20000);
- this.sessionKey.Remove(key);
- }
- }
- }
|