1
mirror of https://github.com/thepeacockproject/Peacock synced 2025-04-02 23:15:29 +02:00
Peacock/components/2016/legacyContractHandler.ts
Reece Dunham 4575924e80
Rewrite the escalation service to use group contracts ()
* Rewrite the escalation service to use group contracts ()

* Fix build and type errors

Signed-off-by: Reece Dunham <me@rdil.rocks>

* Improve Escalation Functionality with Contract Groups ()

* Fix Sinbad escalation and add group definition

* Add group contracts and fix InGroup IDs where needed

* Run prettier

* Add missing group definitions

* Fixed id issues with sinbad

* Fix missionsInLocation.ts

* Added groupdefinitions ()

Added localization and missing groupdefinitions for Peacock custom escalations

* Fix incorrect escalation contract ids

* Remove missing escalations

* Add Ataro group definition

* Add 7DS entrances

* Restore no2016 functionality, add xmas to no2016 list

* Add missing deluxe escalation entrance

* Fix linting

* Added h3 escalations ()

* Added h3 escalations

Added all remaining escalations from h3 maps

* Prettier

yeehaw

---------

Co-authored-by: Anthony Fuller <24512050+AnthonyFuller@users.noreply.github.com>

* Fix escalation completion

* Fix smilax level 1

* Fix escalation challenges not completing

* Get groups when resolving contracts

* track escalation challenge completion

* fix mission end page for escalation challenges

* Update GameChangerProperties

* Update EvergreenGameChangerProperties

* Add new GameChangerProperties

* Fix aborting on invalid escalation group

* remove dupe yellow rabbit suit

* Fixed DGS having no challenges on career page

* run prettier

* Update Proloff Level 2

* Update escalation hub tile to work with group contracts

* Move escalations and elusives to subfolders

* Add 7DS campaign

* Fix escalation level picker

* Fix escalations being incorrectly marked as completed

* Remove completed status when editing escalation level progress

* Add new H3 escalations to level picker

* Add Season tag to elusives for future use

* Add Season tag to typedefs

* Respect Season tag when sending elusives

* Add Legacy Escalations

* Remove milfoil for now, add escalations to missions

* Move xmas escalation

* Fix Snowdrop not showing in 2016

* Add missing entitlements to escalations

* Fix play next level in 2016, remove use of deprecated function

* Move remaining Peacock escalations

* Swap out featured Peacock escalation

---------

Signed-off-by: Reece Dunham <me@rdil.rocks>
Co-authored-by: moonysolari <118079569+moonysolari@users.noreply.github.com>
Co-authored-by: Kaki <66200818+Kakiking@users.noreply.github.com>
Co-authored-by: moonysolari <changyiding@126.com>
Co-authored-by: riisikumi <54016129+riisikumi@users.noreply.github.com>
Co-authored-by: AnthonyFuller <24512050+AnthonyFuller@users.noreply.github.com>
2023-04-14 03:13:16 +01:00

188 lines
6.0 KiB
TypeScript

/*
* The Peacock Project - a HITMAN server replacement.
* Copyright (C) 2021-2023 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 { Router } from "express"
import { gameDifficulty, nilUuid, ServerVer, uuidRegex } from "../utils"
import { json as jsonMiddleware } from "body-parser"
import { enqueueEvent, newSession } from "../eventHandler"
import { _legacyBull, _theLastYardbirdScpc, controller } from "../controller"
import { log, LogLevel } from "../loggingInterop"
import { getConfig } from "../configSwizzleManager"
import type { GameChanger, RequestWithJwt } from "../types/types"
import { randomUUID } from "crypto"
import { getFlag } from "../flags"
import { getPlayEscalationInfo } from "../contracts/escalations/escalationService"
const legacyContractRouter = Router()
legacyContractRouter.post(
"/GetForPlay",
jsonMiddleware(),
(req: RequestWithJwt, res) => {
if (!uuidRegex.test(req.body.id)) {
res.status(400).end()
return
}
const contractData =
req.gameVersion === "h1" &&
req.body.id === "42bac555-bbb9-429d-a8ce-f1ffdf94211c"
? _legacyBull
: req.body.id === "ff9f46cf-00bd-4c12-b887-eac491c3a96d"
? _theLastYardbirdScpc
: controller.resolveContract(req.body.id)
if (!contractData) {
log(
LogLevel.ERROR,
`Requested unknown contract in LGFP: ${req.body.id}`,
)
res.status(400).send("no such contract")
return
}
if (
contractData.Metadata.Type === "elusive" &&
getFlag("legacyElusivesEnableSaving")
) {
log(LogLevel.DEBUG, "Changing elusive mission...")
contractData.Metadata.Type = "mission"
}
if (!contractData.Data.GameChangers) {
contractData.Data.GameChangers = []
}
for (const gamechangerId of req.body.extraGameChangerIds) {
contractData.Data.GameChangers.push(gamechangerId)
}
if (contractData.Data.GameChangers.length > 0) {
type GCPConfig = Record<string, GameChanger>
const gameChangerData: GCPConfig = {
...getConfig<GCPConfig>("GameChangerProperties", true),
...getConfig<GCPConfig>("PeacockGameChangerProperties", true),
}
contractData.Data.GameChangerReferences = []
for (const gameChangerId of contractData.Data.GameChangers) {
const gameChanger = gameChangerData[gameChangerId]
if (!gameChanger) {
log(
LogLevel.ERROR,
`Encountered unknown GameChanger id: ${gameChangerId}`,
)
res.status(500)
continue
}
gameChanger.Id = gameChangerId
delete gameChanger.ObjectivesCategory
contractData.Data.GameChangerReferences.push(gameChanger)
if (gameChanger.Resource) {
contractData.Data.Bricks.push(...gameChanger.Resource)
}
if (gameChanger.Objectives) {
contractData.Data.Objectives?.push(
...gameChanger.Objectives,
)
}
}
}
// Add escalation data to Contract data HERE
contractData.Metadata = {
...contractData.Metadata,
...(contractData.Metadata.Type === "escalation"
? getPlayEscalationInfo(
req.jwt.unique_name,
contractData.Metadata.InGroup,
req.gameVersion,
)
: {}),
}
res.json(contractData)
},
)
legacyContractRouter.post(
"/Start",
jsonMiddleware(),
(req: RequestWithJwt, res) => {
if (req.body.profileId !== req.jwt.unique_name) {
res.status(400).end() // requested for different user id
return
}
if (!uuidRegex.test(req.body.contractId)) {
res.status(400).end()
return
}
const c = controller.resolveContract(req.body.contractId)
if (!c) {
res.status(404).end()
return
}
const contractSessionId = `${process.hrtime
.bigint()
.toString()}-${randomUUID()}`
// all event stuff is handled in h3 event handler
enqueueEvent(req.jwt.unique_name, {
Version: ServerVer,
IsReplicated: false,
CreatedContract: null,
Id: randomUUID(),
Name: "ContractSessionMarker",
UserId: nilUuid,
ContractId: nilUuid,
SessionId: null,
ContractSessionId: contractSessionId,
Timestamp: 0.0,
Value: {
Currency: {
ContractPaymentAllowed: true,
ContractPayment: null,
},
},
Origin: null,
})
res.json(contractSessionId)
newSession(
contractSessionId,
req.body.contractId,
req.jwt.unique_name,
gameDifficulty.normal,
req.gameVersion,
)
},
)
export { legacyContractRouter }