You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.2 KiB
45 lines
1.2 KiB
using System; |
|
using System.Collections.Generic; |
|
using System.Linq; |
|
using System.Text; |
|
using System.Threading.Tasks; |
|
|
|
namespace ET |
|
{ |
|
[FriendClass(typeof(TokenComponent))] |
|
public static class TokenComponentSystem |
|
{ |
|
public static void Add(this TokenComponent self, long key, string token) |
|
{ |
|
self.TokenDictionary.Add(key, token); |
|
self.TimeOutRemoveKey(key, token).Coroutine(); |
|
} |
|
|
|
public static string Get(this TokenComponent self, long key) |
|
{ |
|
string value = null; |
|
self.TokenDictionary.TryGetValue(key, out value); |
|
|
|
return value; |
|
} |
|
|
|
public static void Remove(this TokenComponent self, long key) |
|
{ |
|
if(self.TokenDictionary.ContainsKey(key)) |
|
{ |
|
self.TokenDictionary.Remove(key); |
|
} |
|
} |
|
|
|
private static async ETTask TimeOutRemoveKey(this TokenComponent self, long key, string tokenKey) |
|
{ |
|
await TimerComponent.Instance.WaitAsync(600000); |
|
string onlineToken = self.Get(key); |
|
|
|
if (!string.IsNullOrEmpty(onlineToken) && onlineToken == tokenKey) |
|
{ |
|
self.Remove(key); |
|
} |
|
} |
|
} |
|
}
|
|
|