feat : 토큰 -> 해시키 생성 로직 구조 변경 / 토큰 관리 로직 추가
This commit is contained in:
@@ -36,6 +36,9 @@ public abstract class ServerBase : INetEventListener
|
||||
// peer → hashKey 역방향은 peer.Tag as Session 으로 대체
|
||||
protected readonly Dictionary<long, NetPeer> sessions = new();
|
||||
|
||||
// Token / HashKey 관리
|
||||
protected readonly Dictionary<string, long> tokenHash = new();
|
||||
|
||||
// 재사용 NetDataWriter (단일 스레드 폴링이므로 안전)
|
||||
private readonly NetDataWriter cachedWriter = new();
|
||||
|
||||
@@ -123,6 +126,12 @@ public abstract class ServerBase : INetEventListener
|
||||
// (재연결로 이미 교체된 경우엔 건드리지 않음)
|
||||
if (sessions.TryGetValue(session.HashKey, out NetPeer? current) && current.Id == peer.Id)
|
||||
{
|
||||
// 더미 클라 아니면 token관리
|
||||
if (!string.IsNullOrEmpty(session.Token))
|
||||
{
|
||||
tokenHash.Remove(session.Token);
|
||||
}
|
||||
|
||||
sessions.Remove(session.HashKey);
|
||||
Log.Information("[Server] 세션 해제 HashKey={Key} Reason={Reason}", session.HashKey, disconnectInfo.Reason);
|
||||
OnSessionDisconnected(peer, session.HashKey, disconnectInfo);
|
||||
|
||||
@@ -4,12 +4,28 @@ namespace ServerLib.Service;
|
||||
|
||||
public class Session
|
||||
{
|
||||
public long HashKey { get; init; }
|
||||
public NetPeer Peer { get; set; }
|
||||
public string? Token
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public long HashKey
|
||||
{
|
||||
get;
|
||||
init;
|
||||
}
|
||||
|
||||
public NetPeer Peer
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public Session(long hashKey, NetPeer peer)
|
||||
{
|
||||
HashKey = hashKey;
|
||||
Peer = peer;
|
||||
Peer = peer;
|
||||
Token = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user