feat : UuidGenerator 여러곳에서 사용하도록 싱글톤 제거
This commit is contained in:
35
MMOTestServer/MMOserver/Utils/UuidGenerator.cs
Normal file
35
MMOTestServer/MMOserver/Utils/UuidGenerator.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
namespace MMOserver.Utils;
|
||||
|
||||
public class UuidGenerator
|
||||
{
|
||||
// 0 ~ 1000 은 더미 클라이언트 예약 범위
|
||||
private const long DUMMY_RANGE_MAX = 1000;
|
||||
|
||||
private readonly object idLock = new();
|
||||
private readonly HashSet<long> usedIds = new();
|
||||
|
||||
// 고유 랜덤 long ID 발급 (1001번 이상, 충돌 시 재생성)
|
||||
public long Create()
|
||||
{
|
||||
lock (idLock)
|
||||
{
|
||||
long id;
|
||||
do
|
||||
{
|
||||
id = Random.Shared.NextInt64(DUMMY_RANGE_MAX + 1, long.MaxValue);
|
||||
} while (usedIds.Contains(id));
|
||||
|
||||
usedIds.Add(id);
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
// 로그아웃 / 세션 만료 시 ID 반납
|
||||
public bool Release(long id)
|
||||
{
|
||||
lock (idLock)
|
||||
{
|
||||
return usedIds.Remove(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user