mirror of
https://github.com/djdevin/recflare.git
synced 2026-09-08 14:41:28 -07:00
[match] just a little cleanup
This commit is contained in:
+13
-16
@@ -136,22 +136,18 @@ function unauthorized(c: Context<App>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The "avoid juniors" preference, normalized. The player's settings are a free-form
|
* The "avoid juniors" preference, spelled the way the client posts it — the key a NEW
|
||||||
* `{ key: value }` bag written by the client through the `playersettings` worker, and the
|
* setting is written under, and the one every stored spelling is matched against.
|
||||||
* exact spelling it writes this key under is reverse-engineered — so the lookup is
|
*
|
||||||
* case- and separator-insensitive (`AvoidJuniors`, `avoidjuniors`, `AVOID_JUNIORS` all
|
* The player's settings are a free-form `{ key: value }` bag written by the client through
|
||||||
* resolve to this one preference) rather than betting on one casing and silently reading
|
* the `playersettings` worker, and the exact spelling it writes this key under is
|
||||||
* false forever if it's wrong.
|
* reverse-engineered, so the lookup is case- and separator-insensitive (`avoidJuniors`,
|
||||||
|
* `AvoidJuniors`, `AVOID_JUNIORS` all resolve to this one preference) rather than betting on
|
||||||
|
* one casing and silently reading false forever if it's wrong. The write then overwrites
|
||||||
|
* whichever spelling is already there, so a player never ends up with two keys for the one
|
||||||
|
* preference — which would make the read depend on their order in the map.
|
||||||
*/
|
*/
|
||||||
const AVOID_JUNIORS_SETTING = 'avoidjuniors'
|
const AVOID_JUNIORS_KEY = 'avoidJuniors'
|
||||||
|
|
||||||
/**
|
|
||||||
* The spelling a NEW setting is written under. Only used when the player's map doesn't
|
|
||||||
* already carry the key under some other spelling — the write overwrites whichever one is
|
|
||||||
* there, so a player never ends up with two keys for the one preference (which would make
|
|
||||||
* the read depend on their order in the map).
|
|
||||||
*/
|
|
||||||
const AVOID_JUNIORS_KEY = 'AvoidJuniors'
|
|
||||||
|
|
||||||
/** Lowercase and drop separators, so keys compare on their letters alone. */
|
/** Lowercase and drop separators, so keys compare on their letters alone. */
|
||||||
function normalizeSettingKey(key: string): string {
|
function normalizeSettingKey(key: string): string {
|
||||||
@@ -160,7 +156,8 @@ function normalizeSettingKey(key: string): string {
|
|||||||
|
|
||||||
/** The player's existing spelling of the setting key, if their map has one. */
|
/** The player's existing spelling of the setting key, if their map has one. */
|
||||||
function findAvoidJuniorsKey(stored: Record<string, unknown>): string | undefined {
|
function findAvoidJuniorsKey(stored: Record<string, unknown>): string | undefined {
|
||||||
return Object.keys(stored).find((key) => normalizeSettingKey(key) === AVOID_JUNIORS_SETTING)
|
const wanted = normalizeSettingKey(AVOID_JUNIORS_KEY)
|
||||||
|
return Object.keys(stored).find((key) => normalizeSettingKey(key) === wanted)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -294,10 +294,10 @@ describe('public endpoints', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test('reads the stored setting', async () => {
|
test('reads the stored setting', async () => {
|
||||||
await settings(3100, { AvoidJuniors: 'True', 'Recroom.OOBE': '77' })
|
await settings(3100, { avoidJuniors: 'True', 'Recroom.OOBE': '77' })
|
||||||
expect(await read(3100)).toBe(true)
|
expect(await read(3100)).toBe(true)
|
||||||
|
|
||||||
await settings(3101, { AvoidJuniors: 'False' })
|
await settings(3101, { avoidJuniors: 'False' })
|
||||||
expect(await read(3101)).toBe(false)
|
expect(await read(3101)).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -317,7 +317,7 @@ describe('public endpoints', () => {
|
|||||||
await settings(3105, { 'Recroom.OOBE': '77' })
|
await settings(3105, { 'Recroom.OOBE': '77' })
|
||||||
expect(await read(3105)).toBe(false)
|
expect(await read(3105)).toBe(false)
|
||||||
|
|
||||||
await settings(3106, { AvoidJuniors: 'maybe' })
|
await settings(3106, { avoidJuniors: 'maybe' })
|
||||||
expect(await read(3106)).toBe(false)
|
expect(await read(3106)).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -370,7 +370,7 @@ describe('public endpoints', () => {
|
|||||||
expect(await stored(3201)).toEqual({
|
expect(await stored(3201)).toEqual({
|
||||||
'Recroom.OOBE': '77',
|
'Recroom.OOBE': '77',
|
||||||
TUTORIAL_COMPLETE_MASK: '11',
|
TUTORIAL_COMPLETE_MASK: '11',
|
||||||
AvoidJuniors: 'True',
|
avoidJuniors: 'True',
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -405,7 +405,7 @@ describe('public endpoints', () => {
|
|||||||
await write(3204, 'avoidJuniors=True')
|
await write(3204, 'avoidJuniors=True')
|
||||||
expect(await write(3204, 'avoidJuniors=maybe')).toBe(true)
|
expect(await write(3204, 'avoidJuniors=maybe')).toBe(true)
|
||||||
expect(await write(3204, '')).toBe(true)
|
expect(await write(3204, '')).toBe(true)
|
||||||
expect(await stored(3204)).toEqual({ AvoidJuniors: 'True' })
|
expect(await stored(3204)).toEqual({ avoidJuniors: 'True' })
|
||||||
})
|
})
|
||||||
|
|
||||||
test('is auth-gated', async () => {
|
test('is auth-gated', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user