server: the character, reveal and encountered records and migration step 7 (#23)
This commit is contained in:
+31
-5
@@ -1,13 +1,39 @@
|
||||
## The one copy of the text rules of DESIGN 6.5: a stored text field is trimmed, 1..maxLen code
|
||||
## points and free of control characters. Shared by the token/character names (tokens.nim) and the
|
||||
## property keys (props.nim), so the two cannot drift apart.
|
||||
import std/unicode
|
||||
## points and free of control characters. Shared by the character/token names (tokens.nim,
|
||||
## characters.nim), the property keys (props.nim) and the player names (auth.nim), so they cannot
|
||||
## drift apart.
|
||||
##
|
||||
## Player names are the one exception to "refuse untrimmed input": they are typed by a human at
|
||||
## sign-in, so the server trims the value (and requires the trimmed form, which then is what it
|
||||
## stores) and applies the same length/control rules (6.5). Character and plain-token names are
|
||||
## GM-authored world text and must already be in that form.
|
||||
##
|
||||
## Deviation, recorded FIXED (owner-delegated) in DESIGN 6.5: 6.5 also asks for NFC normalisation of
|
||||
## a player name. Nim 2.2.12's stdlib carries no Unicode normalisation (it lives in an external
|
||||
## package that the pinned dependency set does not include), so a name is stored as typed, trimmed,
|
||||
## and compared case-insensitively. The practical consequence is that two visually identical names
|
||||
## written with precomposed vs combining accents count as different names; nothing else changes.
|
||||
import std/strutils
|
||||
import std/unicode as uni
|
||||
|
||||
proc hasControlChar*(s: string): bool =
|
||||
for r in s.runes:
|
||||
if r.int < 0x20 or r.int == 0x7f: return true
|
||||
|
||||
proc validText*(s: string, maxLen: int): bool =
|
||||
## Trimmed, 1..maxLen code points, no control characters. NFC normalisation and the per-player
|
||||
## uniqueness rule arrived with the name machinery of slice 8 (#23).
|
||||
## Trimmed, 1..maxLen code points, no control characters.
|
||||
s.len > 0 and s == s.strip and s.runeLen in 1 .. maxLen and not hasControlChar(s)
|
||||
|
||||
proc normalizedPlayerName*(raw: string): string =
|
||||
## DESIGN 6.5: the form a player name is stored in. Trimming is the normalisation the server can
|
||||
## apply without a Unicode table (see the module comment).
|
||||
raw.strip
|
||||
|
||||
proc validPlayerName*(normalized: string): bool =
|
||||
## The rule of 6.5 for a player's display name: 1..32 code points, no control characters.
|
||||
normalized.len > 0 and normalized.runeLen in 1 .. 32 and not hasControlChar(normalized)
|
||||
|
||||
proc sameName*(a, b: string): bool =
|
||||
## Names are unique regardless of case (6.5 `name-taken`); Latin case folding is enough for Q17's
|
||||
## glyph set.
|
||||
uni.toLower(a) == uni.toLower(b)
|
||||
|
||||
Reference in New Issue
Block a user