feat : 토큰 인증 RestApi 구현 / Token기반 haskKey구현 / Dummy, User Token체크 분기
This commit is contained in:
12
MMOTestServer/MMOserver/Utils/Singleton.cs
Normal file
12
MMOTestServer/MMOserver/Utils/Singleton.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace MMOserver.Utils;
|
||||
|
||||
public abstract class Singleton<T> where T : Singleton<T>, new()
|
||||
{
|
||||
private static readonly Lazy<T> instance = new Lazy<T>(static () => new T(), LazyThreadSafetyMode.ExecutionAndPublication);
|
||||
|
||||
public static T Instance => instance.Value;
|
||||
|
||||
protected Singleton()
|
||||
{
|
||||
}
|
||||
}
|
||||
21
MMOTestServer/MMOserver/Utils/UuidGeneratorManager.cs
Normal file
21
MMOTestServer/MMOserver/Utils/UuidGeneratorManager.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace MMOserver.Utils;
|
||||
|
||||
public class UuidGeneratorManager : Singleton<UuidGeneratorManager>
|
||||
{
|
||||
private long counter = 0;
|
||||
private readonly ConcurrentDictionary<string, long> tokenMap = new();
|
||||
|
||||
// string token → 고유 long ID 변환 (멀티스레드 안전)
|
||||
// 동일 token은 항상 같은 ID 반환
|
||||
public long GetOrCreate(string token)
|
||||
{
|
||||
return tokenMap.GetOrAdd(token, _ => Interlocked.Increment(ref counter));
|
||||
}
|
||||
|
||||
public bool TryGet(string token, out long id)
|
||||
{
|
||||
return tokenMap.TryGetValue(token, out id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user