Skip to content

Commit

Permalink
Support ChallengesService/GetProgression in non-Legacy games
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyFuller committed Apr 4, 2024
1 parent 042af36 commit 28b6673
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
4 changes: 2 additions & 2 deletions components/2016/legacyProfileRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { controller } from "../controller"
import { json as jsonMiddleware } from "body-parser"
import { uuidRegex } from "../utils"
import { compileRuntimeChallenge } from "../candle/challengeHelpers"
import { LegacyGetProgressionBody } from "../types/gameSchemas"
import { GetChallengeProgressionBody } from "../types/gameSchemas"

const legacyProfileRouter = Router()

Expand Down Expand Up @@ -95,7 +95,7 @@ legacyProfileRouter.post(
"/ChallengesService/GetProgression",
jsonMiddleware(),
// @ts-expect-error Has jwt props.
(req: RequestWithJwt<never, LegacyGetProgressionBody>, res) => {
(req: RequestWithJwt<never, GetChallengeProgressionBody>, res) => {
if (!Array.isArray(req.body.challengeids)) {
res.status(400).send("invalid body")
return
Expand Down
54 changes: 53 additions & 1 deletion components/profileHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ import {
compileRuntimeChallenge,
inclusionDataCheck,
} from "./candle/challengeHelpers"
import { LoadSaveBody, ResolveGamerTagsBody } from "./types/gameSchemas"
import {
GetChallengeProgressionBody,
LoadSaveBody,
ResolveGamerTagsBody,
} from "./types/gameSchemas"
import assert from "assert"

const profileRouter = Router()
Expand Down Expand Up @@ -577,6 +581,54 @@ profileRouter.post(
},
)

profileRouter.post(
"/ChallengesService/GetProgression",
jsonMiddleware(),
// @ts-expect-error Has jwt props.
(req: RequestWithJwt<never, GetChallengeProgressionBody>, res) => {
if (!Array.isArray(req.body.challengeids)) {
res.status(400).send("invalid body")
return
}

if (req.jwt.unique_name !== req.body.profileid) {
res.status(403).send("unauthorised")
return
}

const challenges: ChallengeProgressionData[] = []

for (const challengeId of req.body.challengeids) {
const challenge = controller.challengeService.getChallengeById(
challengeId,
req.gameVersion,
)

if (!challenge) {
log(LogLevel.ERROR, `Unknown challenge in CSGP: ${challengeId}`)
continue
}

const progression =
controller.challengeService.getPersistentChallengeProgression(
req.jwt.unique_name,
challengeId,
req.gameVersion,
)

challenges.push({
ChallengeId: challengeId,
ProfileId: req.jwt.unique_name,
State: progression.State,
CompletedAt: progression.CompletedAt,
Completed: progression.Completed,
})
}

res.json(challenges)
},
)

profileRouter.post(
"/HubPagesService/GetChallengeTreeFor",
jsonMiddleware(),
Expand Down
2 changes: 1 addition & 1 deletion components/types/gameSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export type MultiplayerMatchStatsQuery = Partial<{
contractSessionId: string
}>

export type LegacyGetProgressionBody = Partial<{
export type GetChallengeProgressionBody = Partial<{
profileid: string
challengeids: string[]
}>
Expand Down
4 changes: 2 additions & 2 deletions components/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1278,11 +1278,11 @@ export interface ChallengeProgressionData {
ChallengeId: string
ProfileId: string
Completed: boolean
Ticked: boolean
Ticked?: boolean
ETag?: string
State: Record<string, unknown>
CompletedAt: Date | string | null
MustBeSaved: boolean
MustBeSaved?: boolean
}

export interface CompiledChallengeRuntimeData {
Expand Down

0 comments on commit 28b6673

Please sign in to comment.