Class OperatorCommandParsing
- Namespace
- FishMMO.Server.Implementation.World.SceneServer
- Assembly
- FishMMO.Server.dll
The text handling behind the in-game /gm and /admin commands.
public static class OperatorCommandParsing
- Inheritance
-
OperatorCommandParsing
- Inherited Members
Remarks
Nothing here touches server state, so every rule an operator can trip over — what counts as a duration, when a leading word names a character, how a usage line is spelled — can be tested without standing up a scene server.
Fields
GameMasterMaximumDuration
Longest mute or temporary ban a game master may apply.
public static readonly TimeSpan GameMasterMaximumDuration
Field Value
Remarks
Administrators are not held to it. A game master who needs longer than a month is asking for a decision that belongs to an administrator, who can apply it themselves.
MaximumDuration
Longest duration accepted from anybody. Bounds a typo, not a policy.
public static readonly TimeSpan MaximumDuration
Field Value
Methods
DescribeDuration(TimeSpan)
Describes a duration in the same short units it is typed in.
public static string DescribeDuration(TimeSpan duration)
Parameters
durationTimeSpan
Returns
FormatUsage(string, string, string)
Formats a usage line, /gm mute <character> <duration> [reason], from a spec.
public static string FormatUsage(string command, string name, string spec)
Parameters
Returns
Remarks
Derived rather than written beside the spec, so the help an operator reads in chat and the form the console builds cannot describe the same command two different ways.
IsInteger(string)
True when the word is a whole number, optionally signed.
public static bool IsInteger(string word)
Parameters
wordstring
Returns
IsPermanent(string)
True when the word asks for something with no end: perm or permanent.
public static bool IsPermanent(string text)
Parameters
textstring
Returns
PackLines(IEnumerable<string>, string, string, int)
Packs items into lines no longer than maxLength, joined by separator.
public static IEnumerable<string> PackLines(IEnumerable<string> items, string prefix, string separator, int maxLength)
Parameters
itemsIEnumerable<string>prefixstringseparatorstringmaxLengthint
Returns
Remarks
An item longer than a whole line is truncated onto a line of its own rather than dropped: an operator who asked for a list must see that the entry exists.
SplitFirstWord(string, out string)
Splits the first space-separated word off text.
public static string SplitFirstWord(string text, out string rest)
Parameters
textstringText to split. Null is treated as empty.
reststringEverything after the first word, trimmed.
Returns
- string
The first word, or empty when there is none.
Truncate(string, int)
Cuts text to a length, marking it when anything was removed.
public static string Truncate(string text, int maxLength)
Parameters
Returns
TryParseDuration(string, out TimeSpan)
Parses a duration such as 90, 30m, 2h, 7d or 1w.
public static bool TryParseDuration(string text, out TimeSpan duration)
Parameters
Returns
- bool
True when a positive duration no longer than MaximumDuration was parsed.
Remarks
A bare number is minutes, because minutes are what a moderator reaches for first and "mute 10" meaning ten seconds would be a mute that has lapsed before the player reads it. Zero and negative values are refused rather than meaning "none": a mute of nothing is a typo, and treating it as permanent would be a far worse one.
TryParseSpec(string, out List<ArgumentSpec>, out string)
Parses an argument spec in the grammar documented on StaffCommandEntry.
public static bool TryParseSpec(string spec, out List<OperatorCommandParsing.ArgumentSpec> arguments, out string error)
Parameters
specstringThe spec. Null or empty means no arguments.
argumentsList<OperatorCommandParsing.ArgumentSpec>The parsed arguments.
errorstringWhy the spec is malformed, when it is.
Returns
- bool
True when the spec is well formed.
TryParseTicketID(string, out long)
Parses a ticket number, with or without a leading #.
public static bool TryParseTicketID(string text, out long ticketID)
Parameters
Returns
TrySplitLeadingCharacter(string, out string, out string)
Decides whether a command's leading word names a character or is already its first real argument.
public static bool TrySplitLeadingCharacter(string arguments, out string name, out string rest)
Parameters
argumentsstringThe command's argument text.
namestringThe named character, or null when the caller is the target.
reststringThe arguments after the name, or all of them when there is no name.
Returns
- bool
True when a character was named.
Remarks
For the administrator commands whose target is optional — /admin setgold [character]
<amount>, /admin heal [character]. The rule is deliberately about the
word's shape and not about whether a character by that name exists: nothing, or a number,
means the caller; anything else is a character name, and if that character is not on
this scene server the command says so rather than quietly acting on the caller.
The alternative — "a name if one is online, else yourself" — turns a mistyped name into a grant to the administrator's own character, which is exactly the silent wrong-target failure an economy command must not have.