GateSessionKeyComponent.cs 689 B

123456789101112131415161718192021222324252627282930313233
  1. using System.Collections.Generic;
  2. namespace ET
  3. {
  4. public class GateSessionKeyComponent : Entity, IAwake
  5. {
  6. private readonly Dictionary<long, string> sessionKey = new Dictionary<long, string>();
  7. public void Add(long key, string account)
  8. {
  9. this.sessionKey.Add(key, account);
  10. this.TimeoutRemoveKey(key).Coroutine();
  11. }
  12. public string Get(long key)
  13. {
  14. string account = null;
  15. this.sessionKey.TryGetValue(key, out account);
  16. return account;
  17. }
  18. public void Remove(long key)
  19. {
  20. this.sessionKey.Remove(key);
  21. }
  22. private async ETTask TimeoutRemoveKey(long key)
  23. {
  24. await TimerComponent.Instance.WaitAsync(20000);
  25. this.sessionKey.Remove(key);
  26. }
  27. }
  28. }