Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/actionHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import type {
ActionModdedRequest,
ActionHandyMPExtensionEnable,
ActionHandyMPExtensionDisable,
ActionDataSyncRequest,
} from "./actions.js";
import { generateSeed } from "./utils.js";
import {
Expand Down Expand Up @@ -931,6 +932,19 @@ const streamLogLinesAction = (
});
};

const dataSyncAction = (
{ timer }: ActionHandlerArgs<ActionDataSyncRequest>,
client: Client,
) => {
const [lobby, enemy] = getEnemy(client);
if (!lobby || !enemy) return

enemy.sendAction({
action: "dataSync",
timer: Number.isNaN(timer) ? undefined : Number(timer)
})
}

export const actionHandlers = {
username: usernameAction,
createLobby: createLobbyAction,
Expand Down Expand Up @@ -985,6 +999,7 @@ export const actionHandlers = {
handyMPExtensionEnable: handyMPExtensionEnable,
handyMPExtensionDisable: handyMPExtensionDisable,
failPvPTimer: failPvPTimerAction,
dataSync: dataSyncAction,
} satisfies Partial<ActionHandlers>;

/** Server-internal handler for connection drops (not a client action) */
Expand Down
4 changes: 4 additions & 0 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export type ActionGetNemesisStatsRequest = { action: 'endGameStatsRequested' }
export type ActionReceiveNemesisStatsRequest = { action: 'nemesisEndGameStats', reroll_count: string, reroll_cost_total:string, vouchers:string }
export type ActionStartAnteTimer = { action: 'startAnteTimer', time: number, isPvP?: boolean }
export type ActionPauseAnteTimer = { action: 'pauseAnteTimer', time: number }
export type ActionDataSyncResponse = { action: "dataSync", timer?: number }
// Handy Actions (Server to Client)
export type ActionHandyMPExtensionLobbyEnabled = { action: 'handyMPExtensionLobbyEnabled', enabled: boolean }
// TCG Actions (Server to Client)
Expand Down Expand Up @@ -115,6 +116,7 @@ export type ActionServerToClient =
| ActionTcgPlayerStatus
| ActionTcgStartTurn
| ActionModded
| ActionDataSyncResponse
| ActionHandyMPExtensionLobbyEnabled
// Client to Server
export type ActionUsername = { action: 'username'; username: string; modHash: string }
Expand Down Expand Up @@ -175,6 +177,7 @@ export type ActionTcgEndTurn = { action: 'tcgEndTurn', [key: string]: unknown }
export type ActionModdedRequest = { action: 'moddedAction', modId: string, modAction: string, target?: 'nemesis' | 'all', [key: string]: unknown }
// Handy Actions (Client to Server)
export type ActionRejoinLobby = { action: 'rejoinLobby'; code: string; reconnectToken: string }
export type ActionDataSyncRequest = { action: "dataSync", timer?: number }
export type ActionHandyMPExtensionEnable = { action: 'handyMPExtensionEnable', [key: string]: unknown }
export type ActionHandyMPExtensionDisable = { action: 'handyMPExtensionDisable', [key: string]: unknown }
export type ActionClientToServer =
Expand Down Expand Up @@ -230,6 +233,7 @@ export type ActionClientToServer =
| ActionTcgEndTurn
| ActionModdedRequest
| ActionRejoinLobby
| ActionDataSyncRequest
| ActionHandyMPExtensionEnable
| ActionHandyMPExtensionDisable
// Utility actions
Expand Down
7 changes: 7 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import type {
ActionRejoinLobby,
ActionHandyMPExtensionEnable,
ActionHandyMPExtensionDisable,
ActionDataSyncRequest,
} from './actions.js'
import { InsaneInt } from './InsaneInt.js'
import { ABUSE_CONFIG, ConnectionMeter } from './abuse.js'
Expand Down Expand Up @@ -507,6 +508,12 @@ const server = createServer((socket) => {
client,
)
break
case 'dataSync':
actionHandlers.dataSync(
actionArgs as ActionHandlerArgs<ActionDataSyncRequest>,
client,
)
break
case 'handyMPExtensionEnable':
actionHandlers.handyMPExtensionEnable(
actionArgs as ActionHandlerArgs<ActionHandyMPExtensionEnable>,
Expand Down