feat : UuidGenerator 여러곳에서 사용하도록 싱글톤 제거

This commit is contained in:
qornwh1
2026-03-08 17:47:49 +09:00
parent aed5d7d0b6
commit 76c6f46bbe
2 changed files with 6 additions and 4 deletions

View File

@@ -14,6 +14,7 @@ namespace MMOserver.Game;
public class GameServer : ServerBase public class GameServer : ServerBase
{ {
private readonly Dictionary<ushort, Action<NetPeer, long, byte[]>> packetHandlers; private readonly Dictionary<ushort, Action<NetPeer, long, byte[]>> packetHandlers;
private UuidGenerator userUuidGenerator;
public GameServer(int port, string connectionString) : base(port, connectionString) public GameServer(int port, string connectionString) : base(port, connectionString)
{ {
@@ -25,6 +26,7 @@ public class GameServer : ServerBase
[(ushort)PacketCode.ACTION_PLAYER] = OnActionPlayer, [(ushort)PacketCode.ACTION_PLAYER] = OnActionPlayer,
[(ushort)PacketCode.STATE_PLAYER] = OnStatePlayer, [(ushort)PacketCode.STATE_PLAYER] = OnStatePlayer,
}; };
userUuidGenerator = new UuidGenerator();
} }
protected override void HandleEcho(NetPeer peer, byte[] payload) protected override void HandleEcho(NetPeer peer, byte[] payload)
@@ -95,7 +97,7 @@ public class GameServer : ServerBase
tokenHash.TryGetValue(token, out long hashKey); tokenHash.TryGetValue(token, out long hashKey);
if (hashKey <= 1000) if (hashKey <= 1000)
{ {
hashKey = UuidGeneratorManager.Instance.Create(); hashKey = userUuidGenerator.Create();
} }
if (sessions.TryGetValue(hashKey, out NetPeer? existing)) if (sessions.TryGetValue(hashKey, out NetPeer? existing))
@@ -113,7 +115,7 @@ public class GameServer : ServerBase
if (username == null) if (username == null)
{ {
Log.Warning("[Server] 토큰 검증 실패 - 연결 거부 PeerId={Id}", peer.Id); Log.Warning("[Server] 토큰 검증 실패 - 연결 거부 PeerId={Id}", peer.Id);
UuidGeneratorManager.Instance.Release(hashKey); userUuidGenerator.Release(hashKey);
peer.Disconnect(); peer.Disconnect();
return; return;
} }
@@ -171,7 +173,7 @@ public class GameServer : ServerBase
} }
} }
UuidGeneratorManager.Instance.Release(hashKey); userUuidGenerator.Release(hashKey);
} }
protected override void HandlePacket(NetPeer peer, long hashKey, ushort type, byte[] payload) protected override void HandlePacket(NetPeer peer, long hashKey, ushort type, byte[] payload)

View File

@@ -1,6 +1,6 @@
namespace MMOserver.Utils; namespace MMOserver.Utils;
public class UuidGeneratorManager : Singleton<UuidGeneratorManager> public class UuidGenerator
{ {
// 0 ~ 1000 은 더미 클라이언트 예약 범위 // 0 ~ 1000 은 더미 클라이언트 예약 범위
private const long DUMMY_RANGE_MAX = 1000; private const long DUMMY_RANGE_MAX = 1000;