feat : 토큰 -> 해시키 생성 로직 구조 변경 / 토큰 관리 로직 추가
This commit is contained in:
@@ -85,7 +85,11 @@ public class GameServer : ServerBase
|
||||
{
|
||||
AccTokenPacket accTokenPacket = Serializer.Deserialize<AccTokenPacket>(new ReadOnlyMemory<byte>(payload));
|
||||
string token = accTokenPacket.Token;
|
||||
long hashKey = UuidGeneratorManager.Instance.GetOrCreate(token);
|
||||
tokenHash.TryGetValue(token, out long hashKey);
|
||||
if (hashKey <= 1000)
|
||||
{
|
||||
hashKey = UuidGeneratorManager.Instance.Create();
|
||||
}
|
||||
|
||||
if (sessions.TryGetValue(hashKey, out NetPeer? existing))
|
||||
{
|
||||
@@ -102,6 +106,7 @@ public class GameServer : ServerBase
|
||||
if (username == null)
|
||||
{
|
||||
Log.Warning("[Server] 토큰 검증 실패 - 연결 거부 PeerId={Id}", peer.Id);
|
||||
UuidGeneratorManager.Instance.Release(hashKey);
|
||||
peer.Disconnect();
|
||||
return;
|
||||
}
|
||||
@@ -110,17 +115,11 @@ public class GameServer : ServerBase
|
||||
}
|
||||
|
||||
peer.Tag = new Session(hashKey, peer);
|
||||
((Session)peer.Tag).Token = token;
|
||||
sessions[hashKey] = peer;
|
||||
tokenHash[token] = hashKey;
|
||||
pendingPeers.Remove(peer.Id);
|
||||
|
||||
if (hashKey <= 1000)
|
||||
{
|
||||
// 더미 클라이언트면 에러
|
||||
Log.Error("[Server] Dummy 클라이언트가 입니다. 연결을 종료합니다. HashKey={Key} PeerId={Id}", hashKey, peer.Id);
|
||||
peer.Disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Information("[Server] 인증 완료 HashKey={Key} PeerId={Id}", hashKey, peer.Id);
|
||||
OnSessionConnected(peer, hashKey);
|
||||
}
|
||||
@@ -152,6 +151,7 @@ public class GameServer : ServerBase
|
||||
{
|
||||
Log.Information("[GameServer] 세션 해제 HashKey={Key} Reason={Reason}", hashKey, info.Reason);
|
||||
}
|
||||
UuidGeneratorManager.Instance.Release(hashKey);
|
||||
}
|
||||
|
||||
protected override void HandlePacket(NetPeer peer, long hashKey, ushort type, byte[] payload)
|
||||
|
||||
Reference in New Issue
Block a user