Table of Contents

Class WebSessionService

Namespace
FishMMO.Database.Npgsql.Services
Assembly
FishMMO-DB.dll

Control Panel browser sessions, stored by hash.

public sealed class WebSessionService : BaseService<WebSessionEntity>, IWebSessionService
Inheritance
WebSessionService
Implements
Inherited Members

Remarks

Every statement goes through EF rather than raw SQL, deliberately: the model carries the configured schema via HasDefaultSchema, but a raw UPDATE web_sessions ... is resolved against the connection's search_path instead. On any deployment whose Npgsql:Schema is not the search path, those statements silently matched nothing and the failure was swallowed by callers that ignored the result — a session could be issued and then never promoted, revoked or expired.

Constructors

WebSessionService(INpgsqlDbContextFactory)

public WebSessionService(INpgsqlDbContextFactory dbContextFactory)

Parameters

dbContextFactory INpgsqlDbContextFactory

Methods

CleanupExpiredAsync(DateTime, CancellationToken)

Deletes sessions that expired before the cutoff. Returns how many rows went.

public Task<DatabaseResult<int>> CleanupExpiredAsync(DateTime cutoffUtc, CancellationToken cancellationToken = default)

Parameters

cutoffUtc DateTime
cancellationToken CancellationToken

Returns

Task<DatabaseResult<int>>

FetchActiveForAccountAsync(string, CancellationToken)

Lists the live sessions for an account, newest first.

public Task<DatabaseResult<List<WebSessionData>>> FetchActiveForAccountAsync(string accountName, CancellationToken cancellationToken = default)

Parameters

accountName string
cancellationToken CancellationToken

Returns

Task<DatabaseResult<List<WebSessionData>>>

FetchByHashAsync(string, CancellationToken)

Fetches a session by hash. Returns failure when it does not exist; the caller still has to apply the revoked, expiry and idle checks.

public Task<DatabaseResult<WebSessionData>> FetchByHashAsync(string sessionHash, CancellationToken cancellationToken = default)

Parameters

sessionHash string
cancellationToken CancellationToken

Returns

Task<DatabaseResult<WebSessionData>>

IssueAsync(string, string, byte, bool, DateTime, string, string, CancellationToken)

Records a newly issued session.

public Task<DatabaseResult<WebSessionData>> IssueAsync(string sessionHash, string accountName, byte accessLevel, bool twoFactorSatisfied, DateTime expiresUtc, string ipAddress, string userAgent, CancellationToken cancellationToken = default)

Parameters

sessionHash string

SHA-256 hex of the session identifier.

accountName string

Account the session authenticates.

accessLevel byte

The account's access level at issue.

twoFactorSatisfied bool

Whether two-factor is already satisfied.

expiresUtc DateTime

Absolute expiry.

ipAddress string

Client address, or null.

userAgent string

Client user agent, or null.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<WebSessionData>>

PersistStepUpAsync(string, CancellationToken)

Stamps a fresh step-up, restarting the window for destructive actions.

public Task<DatabaseResult> PersistStepUpAsync(string sessionHash, CancellationToken cancellationToken = default)

Parameters

sessionHash string
cancellationToken CancellationToken

Returns

Task<DatabaseResult>

PersistTwoFactorSatisfiedAsync(string, DateTime, CancellationToken)

Marks two-factor satisfied and stamps the step-up time, promoting a pending session.

public Task<DatabaseResult> PersistTwoFactorSatisfiedAsync(string sessionHash, DateTime expiresUtc, CancellationToken cancellationToken = default)

Parameters

sessionHash string
expiresUtc DateTime
cancellationToken CancellationToken

Returns

Task<DatabaseResult>

RevokeAllForAccountAsync(string, CancellationToken)

Revokes every session for an account. Called when the account is banned, its access level changes, its password changes, or its tokens are revoked.

public Task<DatabaseResult<int>> RevokeAllForAccountAsync(string accountName, CancellationToken cancellationToken = default)

Parameters

accountName string
cancellationToken CancellationToken

Returns

Task<DatabaseResult<int>>

RevokeByHashAsync(string, CancellationToken)

Revokes one session.

public Task<DatabaseResult> RevokeByHashAsync(string sessionHash, CancellationToken cancellationToken = default)

Parameters

sessionHash string
cancellationToken CancellationToken

Returns

Task<DatabaseResult>

RevokeByIdAsync(string, long, CancellationToken)

Revokes one session by its surrogate id, for the operator's session list.

public Task<DatabaseResult> RevokeByIdAsync(string accountName, long id, CancellationToken cancellationToken = default)

Parameters

accountName string
id long
cancellationToken CancellationToken

Returns

Task<DatabaseResult>

TouchAsync(string, CancellationToken)

Stamps last-seen on a live session, extending its idle window.

public Task<DatabaseResult> TouchAsync(string sessionHash, CancellationToken cancellationToken = default)

Parameters

sessionHash string
cancellationToken CancellationToken

Returns

Task<DatabaseResult>