GamePlay
This commit is contained in:
@@ -10,4 +10,7 @@ public interface ISessionRegistry
|
||||
bool IsAuthenticated(Guid connectionId);
|
||||
bool TryGetAccountId(Guid connectionId, out ulong accountId);
|
||||
bool TryGet(Guid connectionId, out ulong accountId, out string token);
|
||||
void BindCharacter(Guid connectionId, ulong characterId);
|
||||
void UnbindCharacter(Guid connectionId);
|
||||
bool TryGetCharacter(Guid connectionId, out ulong characterId);
|
||||
}
|
||||
|
||||
@@ -6,12 +6,16 @@ namespace Server.Services.Auth;
|
||||
public sealed class SessionRegistry : ISessionRegistry
|
||||
{
|
||||
private readonly ConcurrentDictionary<Guid, (ulong accountId, string token)> _byConn = new();
|
||||
private readonly ConcurrentDictionary<Guid, ulong> _charByConn = new();
|
||||
|
||||
public void Bind(Guid connectionId, ulong accountId, string token)
|
||||
=> _byConn[connectionId] = (accountId, token);
|
||||
|
||||
public void Unbind(Guid connectionId)
|
||||
=> _byConn.TryRemove(connectionId, out _);
|
||||
{
|
||||
_byConn.TryRemove(connectionId, out _);
|
||||
_charByConn.TryRemove(connectionId, out _);
|
||||
}
|
||||
|
||||
public bool IsAuthenticated(Guid connectionId)
|
||||
=> _byConn.ContainsKey(connectionId);
|
||||
@@ -28,4 +32,12 @@ public sealed class SessionRegistry : ISessionRegistry
|
||||
{ accountId = v.accountId; token = v.token; return true; }
|
||||
accountId = 0; token = string.Empty; return false;
|
||||
}
|
||||
public void BindCharacter(Guid connectionId, ulong characterId)
|
||||
=> _charByConn[connectionId] = characterId;
|
||||
|
||||
public void UnbindCharacter(Guid connectionId)
|
||||
=> _charByConn.TryRemove(connectionId, out _);
|
||||
|
||||
public bool TryGetCharacter(Guid connectionId, out ulong characterId)
|
||||
=> _charByConn.TryGetValue(connectionId, out characterId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user