Class PlotAccess
Who may do what on a plot, resolved from its state, its owner, and the grants on it.
public static class PlotAccess
- Inheritance
-
PlotAccess
- Inherited Members
Remarks
One place, and a pure function, because this answer is needed in several that must agree. The server decides whether a placement is written and whether a body is pushed back out of a doorway; the client greys out the buttons it knows will be refused. If those disagreed the player would be shown a door they cannot walk through, which reads as the game being broken rather than as the house being locked.
Locked by default is the rule this encodes. A plot admits its owner, and admits everybody the owner has explicitly named; it admits nobody else, and neither an unclaimed grant row nor an unrecognised permission bit can widen that.
Methods
AllowsEntry(PlotState, PlotOwner, long, long, PlotPermission)
True when a character may cross into the plot.
public static bool AllowsEntry(PlotState state, PlotOwner owner, long characterID, long characterGuildID, PlotPermission granted)
Parameters
statePlotStateownerPlotOwnercharacterIDlongcharacterGuildIDlonggrantedPlotPermission
Returns
ClampGrant(PlotPermission, PlotPermission)
What a character with InviteFriends is actually able to hand out.
public static PlotPermission ClampGrant(PlotPermission granterHolds, PlotPermission requested)
Parameters
granterHoldsPlotPermissionWhat the character doing the granting holds themselves.
requestedPlotPermissionWhat they are trying to give.
Returns
Remarks
Nobody may grant a permission they do not hold. Without this the whole model collapses to its weakest link: a friend given only Enter and InviteFriends could grant themselves — or a stranger — the right to strip the house, and the owner's careful choice of what to trust them with would have meant nothing.
An owner passes All and is therefore unclamped, which is the intended asymmetry: the owner is the source of the authority, not a holder of it.
IsOwner(PlotOwner, long, long)
True when a character is the plot's owner, personally or through their guild.
public static bool IsOwner(PlotOwner owner, long characterID, long characterGuildID)
Parameters
ownerPlotOwnerWho holds the plot.
characterIDlongThe character asking.
characterGuildIDlongTheir guild, or zero when they are in none.
Returns
Remarks
Guild membership is passed in rather than looked up, so this stays a function of its arguments and can be reasoned about — and tested — without a guild system to hand. A character with no guild can never match a guild-owned plot, which is why the zero case is rejected explicitly rather than left to compare equal to an unset owner column.
Resolve(PlotState, PlotOwner, long, long, PlotPermission)
Everything a character may do on a plot right now.
public static PlotPermission Resolve(PlotState state, PlotOwner owner, long characterID, long characterGuildID, PlotPermission granted)
Parameters
statePlotStateThe plot's lifecycle state.
ownerPlotOwnerWho holds it.
characterIDlongThe character asking.
characterGuildIDlongTheir guild, or zero.
grantedPlotPermissionWhat the plot's access list gives them, if anything.
Returns
Remarks
State is consulted before ownership, because two of the four states answer the same way for everybody. An abandoned plot admits nobody at all — there is no owner left to admit them and nothing standing on it to enter — and an empty lot is a piece of the public world that happens to be for sale, so people may walk across it and nothing more.
A grant is only honoured on an Occupied plot. Rows outlive the ownership that created them: a plot reclaimed for unpaid tax and bought by somebody else must not come with the previous owner's friends still holding keys, and clearing those rows is a write that can fail or be interrupted. Ignoring them outside the one state where they apply makes that cleanup a tidiness matter rather than a security one.
Sanitize(PlotPermission)
Cleans a stored or received permission mask down to bits that mean something.
public static PlotPermission Sanitize(PlotPermission permissions)
Parameters
permissionsPlotPermission
Returns
Remarks
Applied to everything crossing a boundary — a row read back, a request from a client — so an unknown bit is dropped at the edge rather than stored and later reinterpreted. A permission retired in a later version then stops meaning anything, instead of quietly becoming whichever permission is given its bit next.
Sanitize(int)
Cleans a stored or received permission mask down to bits that mean something.
public static PlotPermission Sanitize(int mask)
Parameters
maskint
Returns
Remarks
Applied to everything crossing a boundary — a row read back, a request from a client — so an unknown bit is dropped at the edge rather than stored and later reinterpreted. A permission retired in a later version then stops meaning anything, instead of quietly becoming whichever permission is given its bit next.