diff --git a/app/src/store/session.js b/app/src/store/session.js index f3ec7e9..9ab8295 100644 --- a/app/src/store/session.js +++ b/app/src/store/session.js @@ -95,10 +95,6 @@ function newResponse(response) { store.session.status = response.status } -function updateStatus(status) { - store.session.status = status -} - export function useTerminal() { return term } @@ -137,18 +133,9 @@ function setup() { socket.on('graph', (event) => { updateGraph(event) }) - // socket.on('hints', (event) => { - // updateHints(event) - // }) - // socket.on('tasks', (tasks) => { - // setTasks(tasks) - // }) socket.on('response', (response) => { newResponse(response) }) - socket.on('status', (event) => { - updateStatus(event) - }) } setup() diff --git a/packages/models/src/session.ts b/packages/models/src/session.ts index 8f2ff85..49185fd 100644 --- a/packages/models/src/session.ts +++ b/packages/models/src/session.ts @@ -48,7 +48,7 @@ export interface ISession { user: Types.ObjectId quest: string containerId: string | null - status: string + status: 'active' | 'finished' | 'inactive' createdAt: Date updatedAt: Date finishedAt?: Date diff --git a/server/src/api/controllers/commandController.ts b/server/src/api/controllers/commandController.ts index 085d2c5..4306601 100644 --- a/server/src/api/controllers/commandController.ts +++ b/server/src/api/controllers/commandController.ts @@ -6,8 +6,6 @@ import { pushToSession } from '../socket.js' import { finishSession } from '../../models/sessionManager.js' import { asyncHandler } from '../../middleware/error.js' -const commandCompleteCallbacks = new Map() - export const newCommand = asyncHandler(async (req: Request, res: Response) => { const { command, pwd, output, error, params } = matchedData(req) @@ -53,40 +51,12 @@ export const newCommand = asyncHandler(async (req: Request, res: Response) => { session.responses.push(response.responses) - if (response.stage === 'END') { + if ((session.status as string) === 'finished') { await finishSession(session) } - // commandCompleteCallbacks.set(session.id, response.callback) pushToSession(session.id, 'response', response) } res.status(200).end() await session.save() }) - -export const completedCommand = asyncHandler( - async (req: Request, res: Response) => { - const { sessionId } = req.user as any - - const session = await Session.findById(sessionId) - - if (!session) { - res.status(404).json({ message: 'session not found' }) - return - } - - if (session.status === 'inactive') { - res.status(400).json({ message: 'session is not active' }) - return - } - - const callback = commandCompleteCallbacks.get(session.id) - if (!callback) { - res.status(200).json({ message: 'no callback found' }) - return - } - callback() - commandCompleteCallbacks.delete(session.id) - res.json({ message: 'ok' }) - } -) diff --git a/server/src/api/routes/commandRouter.ts b/server/src/api/routes/commandRouter.ts index ef22842..b255d21 100644 --- a/server/src/api/routes/commandRouter.ts +++ b/server/src/api/routes/commandRouter.ts @@ -5,6 +5,5 @@ import { newCommandValidator } from '../validators/commandValidator.js' const router = Router() router.post('/', newCommandValidator, commandController.newCommand) -router.post('/completed', commandController.completedCommand) export default router diff --git a/server/src/game/sessionHandler.ts b/server/src/game/sessionHandler.ts index a4a126f..c061d57 100644 --- a/server/src/game/sessionHandler.ts +++ b/server/src/game/sessionHandler.ts @@ -79,6 +79,12 @@ export default class SessionHandler { this.addNewTasks() + this.session.responses.push(stage.responses) + + if (stage.id === 'END') { + this.session.status = 'finished' + } + return { responses: stage.responses, hints: stage.hints,