1
mirror of https://github.com/thepeacockproject/Peacock synced 2025-01-26 13:02:45 +01:00

Fix the legacy contract downloader and improve options related to it (#96)

* Fix legacy downloader for h3
This commit is contained in:
moonysolari 2023-01-28 17:28:05 -05:00 committed by GitHub
parent 7b4e417cb0
commit c617a23a04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 55 deletions

View File

@ -982,7 +982,11 @@ export class Controller {
userId: string,
): Promise<MissionManifest | undefined> {
const remoteService =
gameVersion === "h2" ? "pc2-service" : "pc-service"
gameVersion === "h3"
? "hm3-service"
: gameVersion === "h2"
? "pc2-service"
: "pc-service"
const user = userAuths.get(userId)
@ -1201,20 +1205,12 @@ export function contractIdToHitObject(
}
const subLocation = getSubLocationFromContract(contract, gameVersion)
let parentLocId = subLocation?.Properties?.ParentLocation
if (parentLocId === "LOCATION_PARENT_ICA_SHIP_FACILITY") {
parentLocId = "LOCATION_PARENT_ICA_FACILITY"
}
if (parentLocId === "LOCATION_PARENT_COASTALTOWN_EBOLA") {
parentLocId = "LOCATION_PARENT_COASTALTOWN"
}
const parentLocation = getVersionedConfig<PeacockLocationsData>(
"LocationsData",
gameVersion,
false,
).parents[parentLocId]
).parents[subLocation?.Properties?.ParentLocation]
// failed to find the location, must be from a newer game
if (!subLocation && (gameVersion === "h1" || gameVersion === "h2")) {

View File

@ -74,6 +74,7 @@ export class IOIStrategy extends EntitlementStrategy {
}
override async get(userId: string) {
// Note: Relies on the "legacyContractDownloader" flag.
if (!userAuths.has(userId)) {
log(LogLevel.ERROR, `No data found for ${userId}.`)
return []

View File

@ -33,10 +33,6 @@ const defaultFlags: Flags = {
desc: "For Discord Rich Presence, if set to false, the time playing the current level will be shown, and if set to true, the total time using Peacock will be shown.",
default: false,
},
officialAuthentication: {
desc: "Use official servers for contract downloading",
default: true,
},
liveSplit: {
desc: "Toggle LiveSplit support on or off",
default: false,
@ -94,7 +90,7 @@ const defaultFlags: Flags = {
default: false,
},
legacyContractDownloader: {
desc: "Use the legacy contract downloader in H3 - only works for the platform you are playing on.",
desc: "When set to true, the official servers will be used for contract downloading in H3, which only works for the platform you are playing on. When false, the HITMAPS servers will be used instead. Note that this option only pertains to H3. Official servers will be used for H1 and H2 regardless of the value of this option.",
default: false,
},
}

View File

@ -60,44 +60,6 @@ export async function handleOauthToken(
noTimestamp: true,
}
//#region Refresh tokens
if (req.body.grant_type === "refresh_token") {
// send back the token from the request (re-signed so the timestamps update)
extractToken(req) // init req.jwt
// remove signOptions from existing jwt
// ts-expect-error Non-optional, we're reassigning.
delete req.jwt.nbf // notBefore
// ts-expect-error Non-optional, we're reassigning.
delete req.jwt.exp // expiresIn
// ts-expect-error Non-optional, we're reassigning.
delete req.jwt.iss // issuer
// ts-expect-error Non-optional, we're reassigning.
delete req.jwt.aud // audience
if (getFlag("officialAuthentication") === true && !isFrankenstein) {
if (userAuths.has(req.jwt.unique_name)) {
userAuths
.get(req.jwt.unique_name)!
._doRefresh()
.then(() => undefined)
.catch(() => {
log(LogLevel.WARN, "Failed authentication refresh.")
userAuths.get(req.jwt.unique_name)!.initialized = false
})
}
}
res.json({
access_token: sign(req.jwt, "secret", signOptions),
token_type: "bearer",
expires_in: 5000,
refresh_token: randomUUID(),
})
return
}
//#endregion
let external_platform: "steam" | "epic",
external_userid: string,
external_users_folder: "steamids" | "epicids",
@ -149,6 +111,49 @@ export async function handleOauthToken(
external_appid === "fghi4567xQOCheZIin0pazB47qGUvZw4" ||
external_appid === STEAM_NAMESPACE_2021
//#region Refresh tokens
if (req.body.grant_type === "refresh_token") {
// send back the token from the request (re-signed so the timestamps update)
extractToken(req) // init req.jwt
// remove signOptions from existing jwt
// ts-expect-error Non-optional, we're reassigning.
delete req.jwt.nbf // notBefore
// ts-expect-error Non-optional, we're reassigning.
delete req.jwt.exp // expiresIn
// ts-expect-error Non-optional, we're reassigning.
delete req.jwt.iss // issuer
// ts-expect-error Non-optional, we're reassigning.
delete req.jwt.aud // audience
if (
((external_platform === "steam" ||
getFlag("legacyContractDownloader") === true) &&
isHitman3) ||
!isFrankenstein
) {
if (userAuths.has(req.jwt.unique_name)) {
userAuths
.get(req.jwt.unique_name)!
._doRefresh()
.then(() => undefined)
.catch(() => {
log(LogLevel.WARN, "Failed authentication refresh.")
userAuths.get(req.jwt.unique_name)!.initialized = false
})
}
}
res.json({
access_token: sign(req.jwt, "secret", signOptions),
token_type: "bearer",
expires_in: 5000,
refresh_token: randomUUID(),
})
return
}
//#endregion
const gameVersion: GameVersion = isFrankenstein
? "scpc"
: isHitman3
@ -196,8 +201,17 @@ export async function handleOauthToken(
} catch (e) {
log(LogLevel.DEBUG, "Unable to load profile information.")
}
if (getFlag("officialAuthentication") === true && !isFrankenstein) {
/*
Never store user auth for scpc
Always store user auth for H1 & H2
If on steam or using legacy contract downloader, then store user auth for H3
*/
if (
((external_platform === "steam" ||
getFlag("legacyContractDownloader") === true) &&
isHitman3) ||
!isFrankenstein
) {
const authContainer = new OfficialServerAuth(
gameVersion,
req.body.access_token,