diff options
author | Lizzy Hunt <lizzy.hunt@usu.edu> | 2023-08-16 15:41:35 -0600 |
---|---|---|
committer | Lizzy Hunt <lizzy.hunt@usu.edu> | 2023-08-16 15:41:35 -0600 |
commit | 1c28e10b860056d85cc07e5a834c4a54eac14563 (patch) | |
tree | 8057cbda0336474c3e27cc1de5ac35502e5daff7 /server | |
parent | 732fe6f4811cc082bf938fed2d28c1f9c8bbd1f6 (diff) | |
download | jumpstorm-1c28e10b860056d85cc07e5a834c4a54eac14563.tar.gz jumpstorm-1c28e10b860056d85cc07e5a834c4a54eac14563.zip |
refactor collision methods, rescaffold server
Diffstat (limited to 'server')
-rw-r--r-- | server/src/server.ts | 78 | ||||
-rw-r--r-- | server/tsconfig.json | 2 |
2 files changed, 33 insertions, 47 deletions
diff --git a/server/src/server.ts b/server/src/server.ts index 9a73f11..d169f7d 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -11,50 +11,38 @@ import { Miscellaneous } from "../../engine/config"; const TICK_RATE = 60 / 1000; -class Server { - private server: any; - private game: Game; - - constructor() { - this.game = new Game(); - - [ - new Physics(), - new Collision({ - width: Miscellaneous.WIDTH, - height: Miscellaneous.HEIGHT, - }), - new WallBounds(Miscellaneous.WIDTH), - ].forEach((system) => this.game.addSystem(system)); - - [new Floor(160), new Player()].forEach((entity) => - this.game.addEntity(entity), - ); - - this.game.start(); - setInterval(() => { - this.game.doGameLoop(performance.now()); - }, TICK_RATE); - - this.server = Bun.serve<any>({ - websocket: { - open(ws) { - ws.subscribe("the-group-chat"); - ws.publish("the-group-chat", msg); - }, - message(ws, message) { - // this is a group chat - // so the server re-broadcasts incoming message to everyone - ws.publish("the-group-chat", `${ws.data.username}: ${message}`); - }, - close(ws) { - const msg = `${ws.data.username} has left the chat`; - ws.unsubscribe("the-group-chat"); - ws.publish("the-group-chat", msg); - }, +const game = new Game(); + +[new Physics(), new Collision(), new WallBounds(Miscellaneous.WIDTH)].forEach( + (system) => game.addSystem(system), +); + +[new Floor(160), new Player()].forEach((entity) => game.addEntity(entity)); + +game.start(); + +setInterval(() => { + game.doGameLoop(performance.now()); +}, TICK_RATE); + +const server = Bun.serve({ + port: 8080, + fetch(req, server) { + const sessionId = Math.floor(Math.random() * 1e10).toString(); + + server.upgrade(req, { + headers: { + "Set-Cookie": `SessionId=${sessionId}`, }, }); - } -} - -new Server(); + }, + websocket: { + open(ws) {}, + message(ws, message) { + console.log(message); + }, + close(ws) {}, + }, +}); + +console.log(`Listening on ${server.hostname}:${server.port}`); diff --git a/server/tsconfig.json b/server/tsconfig.json index 2567512..e39b364 100644 --- a/server/tsconfig.json +++ b/server/tsconfig.json @@ -13,8 +13,6 @@ "noEmit": true, "allowImportingTsExtensions": true, "moduleDetection": "force", - // if TS 4.x or earlier - "moduleResolution": "nodenext", "jsx": "react-jsx", // support JSX "allowJs": true, // allow importing `.js` from `.ts` |