From 20091f41f2bc8802b6dd2e6b8c70430ab53ad3fc Mon Sep 17 00:00:00 2001 From: "www.udayempire" <147295044+udayempire@users.noreply.github.com> Date: Thu, 25 Sep 2025 14:41:46 +0530 Subject: [PATCH 1/2] added changes --- monad-frontend | 1 + websocket-server/package-lock.json | 412 ++++++++++++++++++ ...kage-lock.json\357\200\272Zone.Identifier" | 3 + websocket-server/package.json | 16 + .../package.json\357\200\272Zone.Identifier" | 3 + websocket-server/server.js | 226 ++++++++++ .../server.js\357\200\272Zone.Identifier" | 3 + 7 files changed, 664 insertions(+) create mode 160000 monad-frontend create mode 100644 websocket-server/package-lock.json create mode 100644 "websocket-server/package-lock.json\357\200\272Zone.Identifier" create mode 100644 websocket-server/package.json create mode 100644 "websocket-server/package.json\357\200\272Zone.Identifier" create mode 100644 websocket-server/server.js create mode 100644 "websocket-server/server.js\357\200\272Zone.Identifier" diff --git a/monad-frontend b/monad-frontend new file mode 160000 index 000000000..d8a1c875b --- /dev/null +++ b/monad-frontend @@ -0,0 +1 @@ +Subproject commit d8a1c875b0a581addd9ff5583b29ae55e2789482 diff --git a/websocket-server/package-lock.json b/websocket-server/package-lock.json new file mode 100644 index 000000000..1294565af --- /dev/null +++ b/websocket-server/package-lock.json @@ -0,0 +1,412 @@ +{ + "name": "glassfill-websocket-server", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "glassfill-websocket-server", + "version": "1.0.0", + "dependencies": { + "ws": "^8.14.2" + }, + "devDependencies": { + "nodemon": "^3.0.1" + } + }, + "node_modules/anymatch": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", + "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "dev": true, + "license": "ISC", + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true, + "license": "MIT" + }, + "node_modules/binary-extensions": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", + "integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/brace-expansion": { + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz", + "integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/braces": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "dev": true, + "license": "MIT", + "dependencies": { + "fill-range": "^7.1.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/chokidar": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", + "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", + "dev": true, + "license": "MIT", + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", + "dev": true, + "license": "MIT" + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/fill-range": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", + "dev": true, + "license": "MIT", + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "license": "ISC", + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/ignore-by-default": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz", + "integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==", + "dev": true, + "license": "ISC" + }, + "node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "license": "MIT", + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.12.0" + } + }, + "node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true, + "license": "MIT" + }, + "node_modules/nodemon": { + "version": "3.1.10", + "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.10.tgz", + "integrity": "sha512-WDjw3pJ0/0jMFmyNDp3gvY2YizjLmmOUQo6DEBY+JgdvW/yQ9mEeSw6H5ythl5Ny2ytb7f9C2nIbjSxMNzbJXw==", + "dev": true, + "license": "MIT", + "dependencies": { + "chokidar": "^3.5.2", + "debug": "^4", + "ignore-by-default": "^1.0.1", + "minimatch": "^3.1.2", + "pstree.remy": "^1.1.8", + "semver": "^7.5.3", + "simple-update-notifier": "^2.0.0", + "supports-color": "^5.5.0", + "touch": "^3.1.0", + "undefsafe": "^2.0.5" + }, + "bin": { + "nodemon": "bin/nodemon.js" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nodemon" + } + }, + "node_modules/normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/pstree.remy": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", + "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==", + "dev": true, + "license": "MIT" + }, + "node_modules/readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dev": true, + "license": "MIT", + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, + "node_modules/semver": { + "version": "7.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", + "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/simple-update-notifier": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz", + "integrity": "sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==", + "dev": true, + "license": "MIT", + "dependencies": { + "semver": "^7.5.3" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "license": "MIT", + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, + "node_modules/touch": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/touch/-/touch-3.1.1.tgz", + "integrity": "sha512-r0eojU4bI8MnHr8c5bNo7lJDdI2qXlWWJk6a9EAFG7vbhTjElYhBVS3/miuE0uOuoLdb8Mc/rVfsmm6eo5o9GA==", + "dev": true, + "license": "ISC", + "bin": { + "nodetouch": "bin/nodetouch.js" + } + }, + "node_modules/undefsafe": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", + "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==", + "dev": true, + "license": "MIT" + }, + "node_modules/ws": { + "version": "8.18.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.3.tgz", + "integrity": "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==", + "license": "MIT", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + } + } +} diff --git "a/websocket-server/package-lock.json\357\200\272Zone.Identifier" "b/websocket-server/package-lock.json\357\200\272Zone.Identifier" new file mode 100644 index 000000000..de430db8b --- /dev/null +++ "b/websocket-server/package-lock.json\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\Users\kuday\Downloads\websocket-server.zip diff --git a/websocket-server/package.json b/websocket-server/package.json new file mode 100644 index 000000000..fc534bc19 --- /dev/null +++ b/websocket-server/package.json @@ -0,0 +1,16 @@ +{ + "name": "glassfill-websocket-server", + "version": "1.0.0", + "description": "WebSocket server for GlassFill multiplayer game", + "main": "server.js", + "scripts": { + "start": "node server.js", + "dev": "nodemon server.js" + }, + "dependencies": { + "ws": "^8.14.2" + }, + "devDependencies": { + "nodemon": "^3.0.1" + } +} diff --git "a/websocket-server/package.json\357\200\272Zone.Identifier" "b/websocket-server/package.json\357\200\272Zone.Identifier" new file mode 100644 index 000000000..de430db8b --- /dev/null +++ "b/websocket-server/package.json\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\Users\kuday\Downloads\websocket-server.zip diff --git a/websocket-server/server.js b/websocket-server/server.js new file mode 100644 index 000000000..3a5aa1603 --- /dev/null +++ b/websocket-server/server.js @@ -0,0 +1,226 @@ +const WebSocket = require('ws'); +const http = require('http'); + +class GameServer { + constructor() { + this.server = http.createServer(); + this.wss = new WebSocket.Server({ server: this.server }); + this.games = new Map(); // gameId -> GameState + this.connections = new Map(); // ws -> { gameId, role } + + this.setupWebSocket(); + } + + setupWebSocket() { + this.wss.on('connection', (ws) => { + console.log('New client connected'); + + ws.on('message', (data) => { + try { + const message = JSON.parse(data.toString()); + this.handleMessage(ws, message); + } catch (error) { + console.error('Failed to parse message:', error); + this.sendError(ws, 'Invalid message format'); + } + }); + + ws.on('close', () => { + this.handleDisconnect(ws); + }); + + ws.on('error', (error) => { + console.error('WebSocket error:', error); + }); + }); + } + + handleMessage(ws, message) { + switch (message.type) { + case 'join': + this.handleJoin(ws, message); + break; + case 'leave': + this.handleLeave(ws, message); + break; + case 'pour': + this.handlePour(ws, message); + break; + default: + this.sendError(ws, 'Unknown message type'); + } + } + + handleJoin(ws, message) { + const { gameId, role } = message; + + if (!gameId || !role || !['eth', 'mon'].includes(role)) { + this.sendError(ws, 'Invalid join parameters'); + return; + } + + // Initialize game if it doesn't exist + if (!this.games.has(gameId)) { + this.games.set(gameId, { + gameId, + currentAmount: BigInt(0), + ethAmount: BigInt(0), + monAmount: BigInt(0), + isEthTurn: true, + isGameOver: false, + winner: null, + players: { eth: null, mon: null } + }); + } + + const game = this.games.get(gameId); + + // Check if role is already taken + if (game.players[role]) { + this.sendError(ws, `Role ${role} is already taken`); + return; + } + + // Assign player to role + game.players[role] = ws; + this.connections.set(ws, { gameId, role }); + + console.log(`Player joined game ${gameId} as ${role}`); + + // Send current game state to all players + this.broadcastGameState(gameId); + } + + handleLeave(ws, message) { + const connection = this.connections.get(ws); + if (connection) { + const { gameId, role } = connection; + const game = this.games.get(gameId); + + if (game) { + game.players[role] = null; + console.log(`Player left game ${gameId} (${role})`); + + // If both players left, remove the game + if (!game.players.eth && !game.players.mon) { + this.games.delete(gameId); + } else { + this.broadcastGameState(gameId); + } + } + + this.connections.delete(ws); + } + } + + handlePour(ws, message) { + const connection = this.connections.get(ws); + if (!connection) { + this.sendError(ws, 'Not in a game'); + return; + } + + const { gameId, role } = connection; + const game = this.games.get(gameId); + + if (!game || game.isGameOver) { + this.sendError(ws, 'Game not found or already over'); + return; + } + + // Check if it's the player's turn + const isPlayerTurn = (role === 'eth' && game.isEthTurn) || (role === 'mon' && !game.isEthTurn); + if (!isPlayerTurn) { + this.sendError(ws, 'Not your turn'); + return; + } + + const amount = parseFloat(message.amount); + if (isNaN(amount) || amount <= 0) { + this.sendError(ws, 'Invalid amount'); + return; + } + + const pourAmount = BigInt(Math.floor(amount * 1e18)); + const newTotal = game.currentAmount + pourAmount; + const limit = BigInt(1e18); // 1.0 in wei + + // Check for overflow + if (newTotal > limit) { + // Game over - overflow! + game.isGameOver = true; + game.winner = role === 'eth' ? 'mon' : 'eth'; // Opposite player wins + game.currentAmount = limit; + } else { + // Normal pour + game.currentAmount = newTotal; + + // Add to appropriate pot + if (role === 'eth') { + game.ethAmount += pourAmount; + } else { + game.monAmount += pourAmount; + } + + // Check if glass is exactly full + if (newTotal === limit) { + game.isGameOver = true; + game.winner = role; // Current player wins + } else { + // Switch turns + game.isEthTurn = !game.isEthTurn; + } + } + + console.log(`Player ${role} poured ${amount} in game ${gameId}`); + this.broadcastGameState(gameId); + } + + handleDisconnect(ws) { + const connection = this.connections.get(ws); + if (connection) { + this.handleLeave(ws, { type: 'leave' }); + } + } + + broadcastGameState(gameId) { + const game = this.games.get(gameId); + if (!game) return; + + const message = { + type: 'gameState', + gameId, + gameState: { + ...game, + currentAmount: game.currentAmount.toString(), + ethAmount: game.ethAmount.toString(), + monAmount: game.monAmount.toString(), + } + }; + + // Send to both players + Object.values(game.players).forEach(player => { + if (player && player.readyState === WebSocket.OPEN) { + player.send(JSON.stringify(message)); + } + }); + } + + sendError(ws, error) { + if (ws.readyState === WebSocket.OPEN) { + ws.send(JSON.stringify({ type: 'error', error })); + } + } + + start(port = 8080) { + this.server.listen(port, () => { + console.log(`Game server running on port ${port}`); + }); + } +} + +// Start the server +const gameServer = new GameServer(); +gameServer.start(); + +module.exports = GameServer; diff --git "a/websocket-server/server.js\357\200\272Zone.Identifier" "b/websocket-server/server.js\357\200\272Zone.Identifier" new file mode 100644 index 000000000..de430db8b --- /dev/null +++ "b/websocket-server/server.js\357\200\272Zone.Identifier" @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +ReferrerUrl=C:\Users\kuday\Downloads\websocket-server.zip From 1b9be10dde04b9081d2393a6ac0dc4795acef5d5 Mon Sep 17 00:00:00 2001 From: Harpal Jadeja Date: Wed, 24 Sep 2025 19:21:56 +0530 Subject: [PATCH 2/2] Initial commit --- README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 000000000..578ade6a9 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# athena-hacker-house \ No newline at end of file