Files
a301_mmo_game_server/MMOTestServer/MMOserver/Utils/UuidGeneratorManager.cs

22 lines
612 B
C#

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);
}
}