Skip to content

Commit

Permalink
Add/fix some plugin hooks (#543)
Browse files Browse the repository at this point in the history
This PR adds some small things useful for plugins that I was missing:
- Adds an extra hook `onUserLogin` that gets called when a user logs in
(requests `/configuration/Init`);
- Adds back functionality to the `onMissionEnd` hook that already
existed but was never called;
- Passes a plugin's filename to the plugin, which can especially be
useful for SMF-added plugins. (Basically just
https://nodejs.org/api/modules.html#__filename)
 
Relevant issue: #21
  • Loading branch information
RDIL authored Dec 22, 2024
2 parents 04e2825 + c4a6426 commit e38d1c9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions components/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ export class Controller {
>
onMissionEnd: SyncHook<[session: ContractSession]>
onEscalationReset: SyncHook<[groupId: string]>
onUserLogin: SyncHook<[gameVersion: GameVersion, userId: string]>
}
public configManager: typeof configManagerType = {
getConfig,
Expand Down Expand Up @@ -396,6 +397,7 @@ export class Controller {
getNextCampaignMission: new SyncBailHook(),
onMissionEnd: new SyncHook(),
onEscalationReset: new SyncHook(),
onUserLogin: new SyncHook(),
}
}

Expand Down Expand Up @@ -1120,6 +1122,7 @@ export class Controller {
process,
fetch,
require: createPeacockRequire(pluginName),
__filename: pluginPath,
})

let theExports
Expand Down
2 changes: 2 additions & 0 deletions components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ app.get(
servertimeutc: new Date().toISOString(),
ias: 2,
})

controller.hooks.onUserLogin.call(req.gameVersion, req.jwt.unique_name)
},
)

Expand Down
3 changes: 3 additions & 0 deletions components/scoreHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,9 @@ export async function getMissionEndData(
"requested score for other user's session",
)

// call hook
controller.hooks.onMissionEnd.call(sessionDetails)

const realData = getUserData(jwt.unique_name, gameVersion)
// Resolve userdata
const userData = isDryRun ? structuredClone(realData) : realData
Expand Down

0 comments on commit e38d1c9

Please sign in to comment.