1
mirror of https://github.com/thepeacockproject/Peacock synced 2024-11-29 09:15:11 +01:00
Peacock/components/entitlementStrategies.ts
Reece Dunham 6245e91624 Initial commit
Co-authored-by: Tino Roivanen <tino.roivanen98@gmail.com>
Co-authored-by: Govert de Gans <grappigegovert@hotmail.com>
Co-authored-by: Gray Olson <gray@grayolson.com>
Co-authored-by: Alexandre Sanchez <alex73630@gmail.com>
Co-authored-by: Anthony Fuller <24512050+anthonyfuller@users.noreply.github.com>
Co-authored-by: atampy25 <24306974+atampy25@users.noreply.github.com>
Co-authored-by: David <davidstulemeijer@gmail.com>
Co-authored-by: c0derMo <c0dermo@users.noreply.github.com>
Co-authored-by: Jeevat Singh <jeevatt.singh@gmail.com>
Signed-off-by: Reece Dunham <me@rdil.rocks>
2022-10-19 21:33:45 -04:00

156 lines
4.1 KiB
TypeScript

/*
* The Peacock Project - a HITMAN server replacement.
* Copyright (C) 2021-2022 The Peacock Project Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { log, LogLevel } from "./loggingInterop"
import { userAuths } from "./officialServerAuth"
import {
EPIC_NAMESPACE_2021,
FRANKENSTEIN_SNIPER_ENTITLEMENTS,
getEpicEntitlements,
H2_STEAM_ENTITLEMENTS,
STEAM_NAMESPACE_2016,
} from "./platformEntitlements"
import { GameVersion } from "./types/types"
/**
* The base class for an entitlement strategy.
*
* @internal
*/
abstract class EntitlementStrategy {
abstract get(
accessToken: string,
userId: string,
): string[] | Promise<string[]>
}
/**
* Provider for HITMAN 3 on Epic Games Store.
*
* @internal
*/
export class EpicH3Strategy extends EntitlementStrategy {
override async get(accessToken: string, userId: string) {
return await getEpicEntitlements(
EPIC_NAMESPACE_2021,
userId,
accessToken,
)
}
}
/**
* Provider for any game using the official servers.
*
* @internal
*/
export class IOIStrategy extends EntitlementStrategy {
private readonly _remoteService: string
constructor(gameVersion: GameVersion, private readonly issuerId: string) {
super()
this.issuerId = issuerId
this._remoteService =
gameVersion === "h3"
? "hm3-service"
: gameVersion === "h2"
? "pc2-service"
: "pc-service"
}
override async get(userId: string) {
if (!userAuths.has(userId)) {
log(LogLevel.ERROR, `No data found for ${userId}.`)
return []
}
const user = userAuths.get(userId)
const resp = await user?._useService<string[]>(
`https://${this._remoteService}.hitman.io/authentication/api/userchannel/ProfileService/GetPlatformEntitlements`,
false,
{
issuerId: this.issuerId,
},
)
return resp?.data || []
}
}
/**
* Provider for HITMAN 2016 on Epic Games.
* TODO: This does not work due to old Epic API version. We should probably not hard-code this!
*
* @internal
*/
export class EpicH1Strategy extends EntitlementStrategy {
override get() {
return [
"0a73eaedcac84bd28b567dbec764c5cb", // Hitman 1 standard edition
"81aecb49a60b47478e61e1cbd68d63c5", // Hitman 1 GOTY upgrade
]
}
}
/**
* Provider for HITMAN: Sniper Challenge (Hawk) on Steam.
*
* @internal
*/
export class SteamScpcStrategy extends EntitlementStrategy {
override get() {
return FRANKENSTEIN_SNIPER_ENTITLEMENTS
}
}
/**
* Provider for HITMAN 2016 on Steam.
* TODO: This does not work because of the Steam API. We should probably not hard-code this!
*
* @internal
*/
export class SteamH1Strategy extends EntitlementStrategy {
override get() {
return [
STEAM_NAMESPACE_2016,
"439870",
"439890",
"440930",
"440940",
"440960",
"440961",
"440962",
"505180",
"588780",
]
}
}
/**
* Provider for HITMAN 2 on Steam.
* TODO: This does not work because of the Steam API. We should probably not hard-code this!
*
* @internal
*/
export class SteamH2Strategy extends EntitlementStrategy {
override get() {
return H2_STEAM_ENTITLEMENTS
}
}