fix games
This commit is contained in:
parent
56952afa5b
commit
d95d2ec4b3
|
|
@ -5,6 +5,7 @@ import { $$ } from "./dom"
|
|||
import { randomId } from "../shared/utils"
|
||||
import { setStatus, addOutput, insert } from "./scrollback"
|
||||
import { browserCommands } from "./commands"
|
||||
import { sessionId } from "./session"
|
||||
|
||||
const FPS = 30
|
||||
const HEIGHT = 540
|
||||
|
|
@ -34,7 +35,7 @@ export async function handleGameStart(msg: Message) {
|
|||
|
||||
let game
|
||||
try {
|
||||
game = await import(`/source/${name}`)
|
||||
game = await import(`/source/${name}?session=${sessionId}`)
|
||||
} catch (err: any) {
|
||||
setStatus(msgId, "error")
|
||||
addOutput(msgId, `Error: ${err.message ? err.message : err}`)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import { initSneakers, disconnectSneakers } from "./sneaker"
|
|||
import { dispatchMessage } from "./dispatch"
|
||||
import { fatal } from "./fatal"
|
||||
import { getState } from "./state"
|
||||
import { sessionRun } from "./session"
|
||||
|
||||
import { Layout } from "./html/layout"
|
||||
import { Terminal } from "./html/terminal"
|
||||
|
|
@ -96,7 +97,8 @@ app.use("*", async (c, next) => {
|
|||
|
||||
app.get("/source/:name", async c => {
|
||||
const name = c.req.param("name")
|
||||
const path = commandPath(name)
|
||||
const sessionId = c.req.query("session") || "0"
|
||||
const path = await sessionRun(sessionId, () => commandPath(name))
|
||||
if (!path) return c.text("Command not found", 404)
|
||||
return new Response(await transpile(path), {
|
||||
headers: {
|
||||
|
|
@ -111,7 +113,7 @@ app.on(["GET", "POST"], ["/cmd/:name"], async c => {
|
|||
const method = c.req.method
|
||||
|
||||
try {
|
||||
const mod = await loadCommandModule(cmd)
|
||||
const mod = await sessionRun(sessionId, () => loadCommandModule(cmd))
|
||||
if (!mod || !mod[method])
|
||||
return c.json({ status: "error", output: `No ${method} export in ${cmd}` }, 500)
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export const ALS = g.__thread ??= new AsyncLocalStorage<Session>()
|
|||
|
||||
const sessions: Map<string, Session> = new Map()
|
||||
|
||||
export async function sessionRun(sessionId: string, fn: () => void | Promise<void>) {
|
||||
export async function sessionRun(sessionId: string, fn: () => any) {
|
||||
const state = sessionStore(sessionId)
|
||||
return await ALS.run(state, async () => fn())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user