mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 09:30:45 +00:00
UsernameSchema, FlagSchema (#1185)
## Description: Fix zod validation failure for flag codes that do not conform to the SafeString pattern. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com>
This commit is contained in:
+9
-6
@@ -179,10 +179,13 @@ export const AttackIntentSchema = BaseIntentSchema.extend({
|
||||
troops: z.number().nullable(),
|
||||
});
|
||||
|
||||
export const UsernameSchema = SafeString;
|
||||
export const FlagSchema = z.string().max(128).optional();
|
||||
|
||||
export const SpawnIntentSchema = BaseIntentSchema.extend({
|
||||
flag: z.string().nullable(),
|
||||
type: z.literal("spawn"),
|
||||
name: SafeString,
|
||||
name: UsernameSchema,
|
||||
flag: FlagSchema,
|
||||
playerType: PlayerTypeSchema,
|
||||
x: z.number(),
|
||||
y: z.number(),
|
||||
@@ -346,8 +349,8 @@ export const ServerPrestartMessageSchema = ServerBaseMessageSchema.extend({
|
||||
|
||||
export const PlayerSchema = z.object({
|
||||
clientID: ID,
|
||||
username: SafeString,
|
||||
flag: SafeString.optional(),
|
||||
username: UsernameSchema,
|
||||
flag: FlagSchema,
|
||||
});
|
||||
|
||||
export const GameStartInfoSchema = z.object({
|
||||
@@ -424,8 +427,8 @@ export const ClientJoinMessageSchema = z.object({
|
||||
token: TokenSchema, // WARNING: PII
|
||||
gameID: ID,
|
||||
lastTurn: z.number(), // The last turn the client saw.
|
||||
username: SafeString,
|
||||
flag: SafeString.optional(),
|
||||
username: UsernameSchema,
|
||||
flag: FlagSchema,
|
||||
});
|
||||
|
||||
export const ClientMessageSchema = z.discriminatedUnion("type", [
|
||||
|
||||
Reference in New Issue
Block a user