| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using System.Collections.Generic;
- namespace Model
- {
- [ObjectEvent]
- public class GateSessionKeyComponentEvent : ObjectEvent<GateSessionKeyComponent>, IAwake
- {
- public void Awake()
- {
- this.Get().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);
- }
- }
- }
|