Table of Contents

Interface IPlotService

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

Reads and writes ownership of authored plots of land.

public interface IPlotService

Remarks

Every method that changes ownership reports how many rows it affected, and the caller is expected to check it. The counts are the only way to tell a claim that succeeded from one that lost a race, and treating zero as success would sell one plot to two players.

Methods

BackfillTaxDueAsync(long, DateTime, CancellationToken)

Gives a first due date to character-owned plots that have none.

Task<DatabaseResult<int>> BackfillTaxDueAsync(long worldServerID, DateTime firstDueUtc, CancellationToken cancellationToken = default)

Parameters

worldServerID long

The world whose land to backfill.

firstDueUtc DateTime

When those plots should first fall due.

cancellationToken CancellationToken

Returns

Task<DatabaseResult<int>>

How many plots were given a due date.

Remarks

Land claimed while tax was switched off is stored with no due date, and the sweep only looks at plots that have one. Turning tax on afterwards would therefore never touch any of it: those plots would be free forever, and the difference between a founding player and a later one would be permanent.

Only rows with no date are touched, so this cannot reset a plot that is already being billed — running it repeatedly is safe, which matters because it runs on every scene resolve.

Character-owned only. Guild land is deferred rather than charged until a treasury exists, so giving it a date would only make every sweep pick it up and push it along again.

ChargeTaxOfflineAsync(IReadOnlyList<PlotTaxCharge>, int, DateTime, int, int, CancellationToken)

Bills a batch of due plots to owners nobody is hosting, in one transaction.

Task<DatabaseResult<List<PlotTaxChargeResult>>> ChargeTaxOfflineAsync(IReadOnlyList<PlotTaxCharge> charges, int currencyTemplateID, DateTime ownedElsewhereRetryUtc, int ledgerReason, int ledgerState, CancellationToken cancellationToken = default)

Parameters

charges IReadOnlyList<PlotTaxCharge>

One entry per plot, as the sweep read and priced them: each carries its own amount and next due date, because a bill covers every period that plot has fallen behind by. An owner may appear only once.

currencyTemplateID int

The attribute template tax is paid in.

ownedElsewhereRetryUtc DateTime

When a plot whose owner a server is holding may next be tried (stored as tax_next_attempt_utc).

ledgerReason int

The ledger reason recorded for each payment (CurrencyMovementReason.LandTax).

ledgerState int

The ledger state recorded for each payment (CurrencyMovementState.Absorbed).

cancellationToken CancellationToken

Returns

Task<DatabaseResult<List<PlotTaxChargeResult>>>

One result per distinct plot in charges.

Remarks

The offline charge that used to be one transaction per plot — ownership assertion, attribute read, advance, debit, lifted mark, each a round trip — as a handful of set-based statements for the whole batch. The orderings it keeps are the ones the housing README names: the bill is won before any money moves (a locked plot still holding the date the sweep read), a missed-payment mark comes off in the same commit as the payment, and an unpaid bill is marked in the commit that advanced it. A bill is paid in full or not at all.

An owner is charged here only while no server holds their session, asserted under the row lock for the whole transaction, because a held owner's balance is in that server's memory and its next save would overwrite a debit made underneath it. A held owner's plot is deferred instead (OwnedElsewhere); a deleted or missing owner cannot pay and is marked like any other miss (OwnerGone), so their land reaches the end of its grace rather than staying owned forever.

Never waits on a lock: a character or plot another transaction holds is skipped for this sweep. Safe to run from every scene server at once — a period produces one charge however many servers sweep it — and a retry after a lost commit reply changes nothing.

Paid bills are recorded in the currency ledger inside the same commit. Nothing here marks plot_updates: a charge changes nothing another channel draws.

ClearTaxDelinquencyAsync(long, CancellationToken)

Clears a plot's delinquency after a successful payment.

Task<DatabaseResult<int>> ClearTaxDelinquencyAsync(long plotID, CancellationToken cancellationToken = default)

Parameters

plotID long
cancellationToken CancellationToken

Returns

Task<DatabaseResult<int>>

FetchByIdsAsync(IReadOnlyCollection<long>, CancellationToken)

Fetches plots by ID. IDs with no row are simply absent from the result.

Task<DatabaseResult<List<PlotData>>> FetchByIdsAsync(IReadOnlyCollection<long> plotIDs, CancellationToken cancellationToken = default)

Parameters

plotIDs IReadOnlyCollection<long>
cancellationToken CancellationToken

Returns

Task<DatabaseResult<List<PlotData>>>

Remarks

For the cross-channel sync, which knows exactly which plots changed and used to re-read every plot of every scene to find them.

FetchByOwnerCharacterAsync(long, CancellationToken)

Fetches every plot a character owns, across all scenes.

Task<DatabaseResult<List<PlotData>>> FetchByOwnerCharacterAsync(long characterID, CancellationToken cancellationToken = default)

Parameters

characterID long
cancellationToken CancellationToken

Returns

Task<DatabaseResult<List<PlotData>>>

FetchByOwnerGuildAsync(long, CancellationToken)

Fetches every plot a guild owns, across all scenes.

Task<DatabaseResult<List<PlotData>>> FetchByOwnerGuildAsync(long guildID, CancellationToken cancellationToken = default)

Parameters

guildID long
cancellationToken CancellationToken

Returns

Task<DatabaseResult<List<PlotData>>>

FetchBySceneAsync(long, string, CancellationToken)

Fetches every plot in one world server's copy of a scene, owned or not.

Task<DatabaseResult<List<PlotData>>> FetchBySceneAsync(long worldServerID, string sceneName, CancellationToken cancellationToken = default)

Parameters

worldServerID long
sceneName string
cancellationToken CancellationToken

Returns

Task<DatabaseResult<List<PlotData>>>

FetchTaxDueAsync(long, DateTime, DateTime, long, int, CancellationToken)

Fetches one page of a world's owned plots whose tax has fallen due, in due order.

Task<DatabaseResult<List<PlotData>>> FetchTaxDueAsync(long worldServerID, DateTime asOfUtc, DateTime afterDueUtc, long afterPlotID, int limit, CancellationToken cancellationToken = default)

Parameters

worldServerID long

The world whose land to sweep.

asOfUtc DateTime

The moment to judge against.

afterDueUtc DateTime

The keyset cursor: the due date of the last plot of the previous page, or MinValue for the first page.

afterPlotID long

The ID of the last plot of the previous page, or zero for the first page.

limit int

Most rows to return.

cancellationToken CancellationToken

Returns

Task<DatabaseResult<List<PlotData>>>

Remarks

Bounded, because a server that has been down over a billing period comes back to every plot at once and an unbounded read would load all of them.

Paged by a keyset rather than from the head, because the plots a page could not settle stay exactly where they were: a sweep that re-read from the head after each page would read them again and never reach the plots behind them. Plots whose tax_next_attempt_utc is still ahead of asOfUtc are left out — their owner is being billed by the server holding them.

FetchTaxDueForOwnersAsync(IReadOnlyCollection<long>, DateTime, CancellationToken)

Fetches the plots, in any world, whose tax has fallen due and whose owner is one of characterIDs.

Task<DatabaseResult<List<PlotData>>> FetchTaxDueForOwnersAsync(IReadOnlyCollection<long> characterIDs, DateTime asOfUtc, CancellationToken cancellationToken = default)

Parameters

characterIDs IReadOnlyCollection<long>

The characters the calling server holds.

asOfUtc DateTime

The moment to judge against.

cancellationToken CancellationToken

Returns

Task<DatabaseResult<List<PlotData>>>

Remarks

The holding server's half of the sweep. A logged-in owner's balance lives in the memory of the server holding them, so only that server may charge them — and that server may be hosting nothing of the world their land is in. This asks by owner instead of by world, so where the owner happens to be playing no longer decides whether they are billed.

Ignores the deferral: it exists to keep other servers from re-reading a plot that only this one can bill. At most one row per character, by the one-house index.

MarkTaxDelinquentAsync(long, DateTime, CancellationToken)

Records that a tax payment was missed, without disturbing an earlier miss.

Task<DatabaseResult<int>> MarkTaxDelinquentAsync(long plotID, DateTime delinquentSinceUtc, CancellationToken cancellationToken = default)

Parameters

plotID long

The plot that went unpaid.

delinquentSinceUtc DateTime

When the first missed payment fell due.

cancellationToken CancellationToken

Returns

Task<DatabaseResult<int>>

Remarks

Only sets the mark when there is not one already. The grace period is measured from the first miss, so overwriting it on every later failure would restart the clock each period and the plot could never be reclaimed.

RegisterAsync(long, string, IReadOnlyList<string>, CancellationToken)

Ensures a row exists for every foundation authored in a scene.

Task<DatabaseResult<int>> RegisterAsync(long worldServerID, string sceneName, IReadOnlyList<string> plotKeys, CancellationToken cancellationToken = default)

Parameters

worldServerID long

The world server whose land this is.

sceneName string

The scene the foundations belong to.

plotKeys IReadOnlyList<string>

Canonicalised keys of the foundations found in the scene.

cancellationToken CancellationToken

Returns

Task<DatabaseResult<int>>

The number of plots that did not previously exist.

Remarks

Idempotent, because every scene server hosting a channel of the scene runs it on load and they all describe the same land. Plots that already exist keep the ownership they have — registration must never disturb it, or a restart would evict whoever lives there.

Scoped to one world server. The same scene runs on every world, and registering it unscoped would give them all a single shared row per plot — one player's house appearing as already-owned land to everybody on every other world.

ReleaseAllForGuildAsync(long, CancellationToken)

Releases every plot a guild owns.

Task<DatabaseResult<int>> ReleaseAllForGuildAsync(long guildID, CancellationToken cancellationToken = default)

Parameters

guildID long
cancellationToken CancellationToken

Returns

Task<DatabaseResult<int>>

The number of plots released.

Remarks

Guilds are hard-deleted, and the owner column carries no foreign key to clean up behind them, so land held by a disbanded guild would otherwise stay claimed by an identifier that no longer resolves to anything — unclaimable, and unbuildable, permanently.

ReleaseAsync(long, long, long, int, CancellationToken)

Releases a plot back to the unowned pool, if the expected owner still holds it.

Task<DatabaseResult<int>> ReleaseAsync(long plotID, long expectedOwnerCharacterID, long expectedOwnerGuildID, int releasedState = 0, CancellationToken cancellationToken = default)

Parameters

plotID long

The plot to release.

expectedOwnerCharacterID long

The character believed to own it, or zero.

expectedOwnerGuildID long

The guild believed to own it, or zero.

releasedState int

The FishMMO.Shared.PlotState the plot is left in, as its underlying integer. Defaults to Empty; reclamation passes Abandoned.

cancellationToken CancellationToken

Returns

Task<DatabaseResult<int>>

1 when released, 0 when somebody else owns it or it was already unowned.

Remarks

The state the plot lands in is the caller's to choose, because releasing is two different events wearing one name. An owner handing the deed back leaves a bare lot; a sweep taking land off somebody who stopped paying leaves a house standing empty, which renders differently and tells a passer-by a different story.

TryAdvanceTaxAsync(long, DateTime, DateTime, CancellationToken)

Moves a plot's tax date forward, if it still holds the date the caller charged against.

Task<DatabaseResult<int>> TryAdvanceTaxAsync(long plotID, DateTime expectedDueUtc, DateTime nextDueUtc, CancellationToken cancellationToken = default)

Parameters

plotID long

The plot being charged.

expectedDueUtc DateTime

The due date the caller read.

nextDueUtc DateTime

The date the next payment falls due.

cancellationToken CancellationToken

Returns

Task<DatabaseResult<int>>

1 when this call advanced it, 0 when somebody else already did.

Remarks

The pin is what makes the tax safe to sweep from every scene server at once. Several may host the same world's scenes, they all see the same plot come due, and only the one whose expected date still matches may charge it — so a period produces one payment rather than one per server.

Called before the money is taken, for the same reason a plot is claimed before it is paid for: winning the right to charge is the contended step, and a caller that loses it must not have taken anything.

TryClaimAsync(long, long, long, DateTime?, int, CancellationToken)

Claims an unowned plot.

Task<DatabaseResult<int>> TryClaimAsync(long plotID, long ownerCharacterID, long ownerGuildID, DateTime? taxDueUtc, int claimedState = 1, CancellationToken cancellationToken = default)

Parameters

plotID long

The plot to claim.

ownerCharacterID long

The claiming character, or zero for a guild claim.

ownerGuildID long

The claiming guild, or zero for a character claim.

taxDueUtc DateTime?

When the first tax payment falls due, or null for untaxed land.

claimedState int

The FishMMO.Shared.PlotState the plot enters, as its underlying integer. Defaults to Building.

cancellationToken CancellationToken

Returns

Task<DatabaseResult<int>>

1 when this call took the plot; 0 when it was already owned, does not exist, or the claiming character already owns one.

Remarks

Exactly one of the two identifiers may be non-zero.

The first tax date and the new state are set by the same statement that takes the plot, so there is no moment where land is owned but untaxed, or owned but still showing as an empty lot. Set separately, a crash in the gap would leave a plot nobody ever has to pay for, or one that every channel draws as available.

A character may hold only one plot. That is asked here and enforced by a partial unique index, because this clause alone cannot stop two simultaneous claims on two scene servers. A caller that gets UNIQUE_VIOLATION back rather than a row count lost that race and should report it the same way it reports zero.

TryRestoreTaxDueAsync(long, DateTime, DateTime, CancellationToken)

Hands a won tax period back: moves the due date back to what it was, if it still holds the date this caller advanced it to.

Task<DatabaseResult<int>> TryRestoreTaxDueAsync(long plotID, DateTime advancedToUtc, DateTime restoreToUtc, CancellationToken cancellationToken = default)

Parameters

plotID long

The plot.

advancedToUtc DateTime

The date TryAdvanceTaxAsync(long, DateTime, DateTime, CancellationToken) set it to.

restoreToUtc DateTime

The date it held before; must be earlier.

cancellationToken CancellationToken

Returns

Task<DatabaseResult<int>>

1 when the period was handed back, 0 when the date has moved on since.

Remarks

For a caller that won a period and then could not charge the owner at all (the character unreachable, the charge faulting on every attempt). Without it the period simply went unbilled: the date only ever moves forward. Pinned the same way as the advance, so it can never undo a LATER period another server has since won — that one is left alone and this returns 0.

TrySetStateAsync(long, int, int, long, long, CancellationToken)

Moves a plot from one lifecycle state to another, if it is still where and whose the caller thinks it is.

Task<DatabaseResult<int>> TrySetStateAsync(long plotID, int expectedState, int newState, long expectedOwnerCharacterID, long expectedOwnerGuildID, CancellationToken cancellationToken = default)

Parameters

plotID long

The plot to move.

expectedState int

The state it must currently be in.

newState int

The state to move it to. Must differ from the expected one.

expectedOwnerCharacterID long

The character believed to own it, or zero.

expectedOwnerGuildID long

The guild believed to own it, or zero.

cancellationToken CancellationToken

Returns

Task<DatabaseResult<int>>

1 when the plot moved, 0 when it had already moved or changed hands.