Table of Contents

Class RegistrationProfile

Namespace
FishMMO.Auth.Core
Assembly
FishMMO-AuthShared.dll

The optional details a player gives at in-game registration, carried to the login server as ONE additional AES-GCM field of the create-account message.

public sealed class RegistrationProfile
Inheritance
RegistrationProfile
Inherited Members

Remarks

Why one field and not seven. Every field of the create-account message is encrypted under its own sequence number, and the server decrypts them by counting back from the message's last sequence. Seven new fields would have been seven new offsets to keep in step on both sides; one field holding a compact serialisation adds one, and the next detail to be added changes FormatVersion rather than the wire arithmetic.

Format. One version byte, one channels byte, from version 3 one RegistrationOptions byte, then strings in a fixed order — phone, beta code, country, real name, address, referral account, and from version 2 the Discord username — each as a two-byte big-endian length followed by that many bytes of UTF-8. An empty string means "not given". Versions 1 and 2 are still read, so a client one release behind can register. Decoding refuses an unknown version, an unknown option bit, trailing bytes, invalid UTF-8 and any field over its length, so the size of what reaches the server's validator is bounded before it is parsed.

Two-factor is opt-in. EnableTwoFactor asks the server to set up an authenticator on the new account. A version 1 or 2 profile has no options byte and reads as opted in: those clients were written when every account was enrolled, and wait for the setup.

Validation. The database's AccountProfileRules is the authority and the server applies it before the account row is created. TryValidate(out string?) is a client-side mirror of the parts a form needs for immediate feedback; the client does not reference the database assembly. A unit test pins the shared limits to the database's.

Fields

FormatVersion

The serialisation version written by Serialize().

public const byte FormatVersion = 3

Field Value

byte

MaxAddressLength

Longest address. Mirrors AccountProfileRules.MaxAddressLength.

public const int MaxAddressLength = 512

Field Value

int

MaxBetaCodeLength

Longest beta code accepted as typed (the canonical form is 14 characters).

public const int MaxBetaCodeLength = 32

Field Value

int

MaxCountryLength

Longest country or region. Mirrors AccountProfileRules.MaxCountryLength.

public const int MaxCountryLength = 64

Field Value

int

MaxDiscordNameLength

Longest Discord username, not counting a discriminator. Mirrors AccountProfileRules.MaxDiscordUsernameLength.

public const int MaxDiscordNameLength = 32

Field Value

int

MaxDiscordUsernameLength

Longest Discord username accepted as typed: a 32-character name, # and a four-digit discriminator, with room for a leading @ and stray spaces before normalisation.

public const int MaxDiscordUsernameLength = 40

Field Value

int

MaxEncryptedBytes

Largest encrypted profile field a server should accept (serialisation plus the GCM tag, with headroom).

public const int MaxEncryptedBytes = 3441

Field Value

int

MaxPhoneLength

Longest phone number accepted as typed, before normalisation.

public const int MaxPhoneLength = 32

Field Value

int

MaxRealNameLength

Longest real name. Mirrors AccountProfileRules.MaxRealNameLength.

public const int MaxRealNameLength = 128

Field Value

int

MaxReferralLength

Longest referral account name (an account name is at most 32 characters).

public const int MaxReferralLength = 32

Field Value

int

MaxSerializedBytes

Largest serialisation any valid profile can produce: every field full of 4-byte UTF-8.

public const int MaxSerializedBytes = 3377

Field Value

int

MinDiscordNameLength

Shortest Discord username. Mirrors AccountProfileRules.MinDiscordUsernameLength.

public const int MinDiscordNameLength = 2

Field Value

int

OldestFormatVersion

The oldest serialisation version TryDeserialize(byte[]?, out RegistrationProfile) still reads.

public const byte OldestFormatVersion = 1

Field Value

byte

OptionsFormatVersion

The first serialisation version that carries the RegistrationOptions byte.

public const byte OptionsFormatVersion = 3

Field Value

byte

Properties

Address

Postal address, or null.

public string? Address { get; set; }

Property Value

string

BetaCode

Beta code as typed, or null.

public string? BetaCode { get; set; }

Property Value

string

Country

Country or region, or null.

public string? Country { get; set; }

Property Value

string

DiscordUsername

The Discord username the verification DM goes to, as typed, or null.

public string? DiscordUsername { get; set; }

Property Value

string

EnableTwoFactor

Whether the player asked for an authenticator on the new account. Off by default.

public bool EnableTwoFactor { get; set; }

Property Value

bool

Phone

Phone number as typed, or null.

public string? Phone { get; set; }

Property Value

string

RealName

Real name, or null.

public string? RealName { get; set; }

Property Value

string

ReferralAccount

The account that referred this player, or null.

public string? ReferralAccount { get; set; }

Property Value

string

VerificationChannels

The channels the player chose to verify with.

public RegistrationVerificationChannels VerificationChannels { get; set; }

Property Value

RegistrationVerificationChannels

Methods

NormalizeDiscordUsername(string?)

Mirror of AccountProfileRules.NormalizeDiscordUsername: a unique username (fishfan) or a name with its four-digit discriminator (FishFan#1234), trimmed, without a leading @, lowercased.

public static string? NormalizeDiscordUsername(string? input)

Parameters

input string

Returns

string

The normalised username, or null when it is not one.

NormalizePhone(string?)

Mirror of AccountProfileRules.NormalizePhone: E.164, a leading + (or 00) and 8 to 15 digits, with spaces, hyphens, dots and parentheses dropped.

public static string? NormalizePhone(string? input)

Parameters

input string

Returns

string

The normalised number, or null when it is not one.

Serialize()

Serialises the profile (format version FormatVersion).

public byte[] Serialize()

Returns

byte[]

Exceptions

ArgumentException

A field is over its length limit.

TryDeserialize(byte[]?, out RegistrationProfile)

Decodes a serialised profile, refusing anything Serialize() could not have produced.

public static bool TryDeserialize(byte[]? data, out RegistrationProfile profile)

Parameters

data byte[]

The decrypted bytes.

profile RegistrationProfile

The profile; blank fields are null.

Returns

bool

False for an unknown version, a truncated or over-long buffer, invalid UTF-8, or a field over its limit.

TryValidate(out string?)

Client-side mirror of the database's profile rules, for immediate feedback on a form.

public bool TryValidate(out string? error)

Parameters

error string

Why the profile was refused, written for the player.

Returns

bool

Remarks

Not the authority — the login server re-validates with AccountProfileRules — so it errs towards the same answers rather than towards being complete. The messages match the database's word for word where the rule is the same.