GateSessionKeyComponentSystem.cs 960 B

123456789101112131415161718192021222324252627282930
  1. namespace ET.Server
  2. {
  3. [FriendOf(typeof(GateSessionKeyComponent))]
  4. public static partial class GateSessionKeyComponentSystem
  5. {
  6. public static void Add(this GateSessionKeyComponent self, long key, string account)
  7. {
  8. self.sessionKey.Add(key, account);
  9. self.TimeoutRemoveKey(key).NoContext();
  10. }
  11. public static string Get(this GateSessionKeyComponent self, long key)
  12. {
  13. string account = null;
  14. self.sessionKey.TryGetValue(key, out account);
  15. return account;
  16. }
  17. public static void Remove(this GateSessionKeyComponent self, long key)
  18. {
  19. self.sessionKey.Remove(key);
  20. }
  21. private static async ETTask TimeoutRemoveKey(this GateSessionKeyComponent self, long key)
  22. {
  23. await self.Root().GetComponent<TimerComponent>().WaitAsync(20000);
  24. self.sessionKey.Remove(key);
  25. }
  26. }
  27. }