mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-08 14:02:09 +00:00
Merge branch 'v30'
This commit is contained in:
+30
-8
@@ -9,10 +9,11 @@ import {
|
||||
skipNonAlphabeticTransformer,
|
||||
toAsciiLowerCaseTransformer,
|
||||
} from "obscenity";
|
||||
import countries from "resources/countries.json";
|
||||
|
||||
import { Cosmetics } from "../core/CosmeticSchemas";
|
||||
import { decodePatternData } from "../core/PatternDecoder";
|
||||
import {
|
||||
FlagSchema,
|
||||
PlayerColor,
|
||||
PlayerCosmeticRefs,
|
||||
PlayerCosmetics,
|
||||
@@ -20,6 +21,8 @@ import {
|
||||
} from "../core/Schemas";
|
||||
import { simpleHash } from "../core/Util";
|
||||
|
||||
const countryCodes = countries.filter((c) => !c.restricted).map((c) => c.code);
|
||||
|
||||
export const shadowNames = [
|
||||
"UnhuggedToday",
|
||||
"DaddysLilChamp",
|
||||
@@ -148,14 +151,11 @@ export class PrivilegeCheckerImpl implements PrivilegeChecker {
|
||||
}
|
||||
}
|
||||
if (refs.flag) {
|
||||
const result = FlagSchema.safeParse(refs.flag);
|
||||
if (!result.success) {
|
||||
return {
|
||||
type: "forbidden",
|
||||
reason: "invalid flag: " + result.error.message,
|
||||
};
|
||||
try {
|
||||
cosmetics.flag = this.isFlagAllowed(flares, refs.flag);
|
||||
} catch (e) {
|
||||
return { type: "forbidden", reason: "invalid flag: " + e.message };
|
||||
}
|
||||
cosmetics.flag = result.data;
|
||||
}
|
||||
|
||||
return { type: "allowed", cosmetics };
|
||||
@@ -202,6 +202,28 @@ export class PrivilegeCheckerImpl implements PrivilegeChecker {
|
||||
}
|
||||
}
|
||||
|
||||
isFlagAllowed(flares: string[], flagRef: string): string {
|
||||
if (flagRef.startsWith("flag:")) {
|
||||
const key = flagRef.slice("flag:".length);
|
||||
const found = this.cosmetics.flags[key];
|
||||
if (!found) throw new Error(`Flag ${key} not found`);
|
||||
|
||||
if (flares.includes("flag:*") || flares.includes(`flag:${found.name}`)) {
|
||||
return found.url;
|
||||
}
|
||||
|
||||
throw new Error(`No flares for flag ${key}`);
|
||||
} else if (flagRef.startsWith("country:")) {
|
||||
const code = flagRef.slice("country:".length);
|
||||
if (!countryCodes.includes(code)) {
|
||||
throw new Error(`invalid country code`);
|
||||
}
|
||||
return `/flags/${code}.svg`;
|
||||
} else {
|
||||
throw new Error(`invalid flag prefix`);
|
||||
}
|
||||
}
|
||||
|
||||
isColorAllowed(flares: string[], color: string): PlayerColor {
|
||||
const allowedColors = flares
|
||||
.filter((flare) => flare.startsWith("color:"))
|
||||
|
||||
Reference in New Issue
Block a user