1
mirror of https://github.com/thepeacockproject/Peacock synced 2024-11-16 11:03:30 +01:00

Prevent disconnections caused by contract report requests (#99)

This commit is contained in:
moonysolari 2023-03-20 12:24:21 -04:00 committed by GitHub
parent 168aee05fe
commit e6f72eb53d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 181 additions and 0 deletions

View File

@ -92,6 +92,7 @@ import FrankensteinScoreOverviewTemplate from "../static/FrankensteinScoreOvervi
import FrankensteinPlanningTemplate from "../static/FrankensteinPlanningTemplate.json"
import Videos from "../static/Videos.json"
import ChallengeLocationTemplate from "../static/ChallengeLocationTemplate.json"
import ReportTemplate from "../static/ReportTemplate.json"
import ContractSearchPageTemplate from "../static/ContractSearchPageTemplate.json"
import ContractSearchPaginateTemplate from "../static/ContractSearchPaginateTemplate.json"
import ContractSearchResponseTemplate from "../static/ContractSearchResponseTemplate.json"
@ -189,6 +190,7 @@ const configs: Record<string, unknown> = {
FrankensteinScoreOverviewTemplate,
Videos,
ChallengeLocationTemplate,
ReportTemplate,
ContractSearchPageTemplate,
ContractSearchPaginateTemplate,
ContractSearchResponseTemplate,

View File

@ -0,0 +1,34 @@
/*
* 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 { json as jsonMiddleware } from "body-parser"
import type { RequestWithJwt } from "../types/types"
const reportRouter = Router()
reportRouter.post(
"/ReportContract",
jsonMiddleware(),
(
req: RequestWithJwt<never, { contractId: string; reason: number }>,
res,
) => {
res.json({})
},
)
export { reportRouter }

View File

@ -81,6 +81,7 @@ import { multiplayerMenuDataRouter } from "./multiplayer/multiplayerMenuData"
import { pack, unpack } from "msgpackr"
import { liveSplitManager } from "./livesplit/liveSplitManager"
import { cheapLoadUserData } from "./databaseHandler"
import { reportRouter } from "./contracts/reportRouting"
// welcome to the bleeding edge
setFlagsFromString("--harmony")
@ -435,6 +436,10 @@ primaryRouter.use(
"/authentication/api/userchannel/ContractsService/",
contractRoutingRouter,
)
primaryRouter.use(
"/authentication/api/userchannel/ReportingService/",
reportRouter,
)
primaryRouter.use("/authentication/api/userchannel/", profileRouter)
primaryRouter.use("/profiles/page/", preMenuDataRouter)
primaryRouter.use("/profiles/page", multiplayerMenuDataRouter)

View File

@ -451,6 +451,18 @@ menuDataRouter.get("/SafehouseCategory", (req: RequestWithJwt, res) => {
res.json(safehouseData)
})
menuDataRouter.get("/report", (req: RequestWithJwt, res) => {
res.json({
template: getVersionedConfig("ReportTemplate", req.gameVersion, false),
data: {
Reasons: [
{ Id: 0, Title: "UI_MENU_REPORT_REASON_OFFENSIVE" },
{ Id: 1, Title: "UI_MENU_REPORT_REASON_BUGGY" },
],
},
})
})
menuDataRouter.get(
"/stashpoint",
(req: RequestWithJwt<StashpointQuery>, res) => {

128
static/ReportTemplate.json Normal file
View File

@ -0,0 +1,128 @@
{
"buttons": [
{
"actiontype": "accept",
"actionlabel": "$loc UI_BUTTON_PROMPTS_ACTION_SELECT"
},
{
"actiontype": "cancel",
"actionlabel": "$loc UI_BUTTON_PROMPTS_ACTION_BACK"
}
],
"onpageopened": {
"show-background-layers": {
"show-background": {
"$if $arg _isingame": { "$then": false, "$else": true }
},
"show-world-map": false,
"show-overlay": false
}
},
"body": {
"controller": "list",
"children": [
{
"controller": "list",
"id": "category_container",
"_comment": "the container that will be dynamically updated with the contents of the selected category"
},
{
"view": "menu3.containers.ScrollingTabsContainer",
"direction": "horizontal",
"data": {
"direction": "horizontal",
"topnavigation": {
"title": "$arg contracttitle",
"icon": "usercreated"
}
},
"ncols": 10,
"_comment": "note the below two fields, the container tells the category controller which container is to be used",
"controller": "category",
"container": "category_container",
"children": [
{
"view": "menu3.basic.CategoryElement",
"id": "category_background",
"data": {
"title": "$loc UI_MENU_PAGE_TITLE_REPORTING",
"icon": "background"
},
"children": [
{
"view": "menu3.TextboxElement",
"selectable": false,
"_col": 1.25,
"row": 1,
"ncols": 4,
"data": {
"text": "$loc UI_MENU_REPORT_HEADLINE_REASON",
"size": 40,
"color": "FFFFFF"
}
},
{
"controller": "list",
"view": "menu3.containers.ScrollingListContainer",
"row": 1.5,
"nrows": 2.5,
"ncols": 10,
"direction": "vertical",
"data": { "direction": "vertical" },
"children": {
"$each $.Reasons": {
"view": "menu3.basic.OptionsListElement",
"data": {
"showningame": {
"$if $arg _isingame": {
"$then": true,
"$else": false
}
},
"title": "$loc $.Title",
"icon": "arrowright"
},
"actions": {
"accept": {
"show-modal": {
"config": {
"view": "menu3.modal.ModalDialogGeneric",
"buttons": [
"$loc UI_DIALOG_CONFIRM",
{
"label": "$loc UI_DIALOG_CANCEL",
"type": "cancel"
}
],
"data": {
"title": "$loc UI_DIALOG_REPORT_CONTRACT_TITLE",
"description": "$loc UI_DIALOG_CONFIRM_REPORT_TEXT"
}
},
"onbutton": [
{
"report-pressed": {
"contractid": "$arg contractid",
"reason": "$.Id"
}
},
{
"set-selected": {}
}
]
}
},
"on-report-saved": {
"request-back": {}
}
}
}
}
}
]
}
]
}
]
}
}