From 14033ec87057f5745c7ed0891ff6f0d0918bef44 Mon Sep 17 00:00:00 2001 From: Jeffrey Alan Scudder Date: Mon, 10 Nov 2025 20:13:08 -0800 Subject: [PATCH 1/6] Add IP geolocation with geoip-lite (city, region, country, timezone) --- session-server/package-lock.json | 192 ++++++++++++++++++++++++++++++- session-server/package.json | 1 + session-server/session.mjs | 41 ++++++- 3 files changed, 230 insertions(+), 4 deletions(-) diff --git a/session-server/package-lock.json b/session-server/package-lock.json index 5a82b300c7..6cfcb0e400 100644 --- a/session-server/package-lock.json +++ b/session-server/package-lock.json @@ -13,6 +13,7 @@ "dotenv": "^16.5.0", "fastify": "^5.3.0", "firebase-admin": "^13.2.0", + "geoip-lite": "^1.4.10", "ip": "^2.0.1", "jamsocket": "^0.10.8", "obscenity": "^0.4.5", @@ -1181,6 +1182,15 @@ "ieee754": "^1.1.13" } }, + "node_modules/buffer-crc32": { + "version": "0.2.13", + "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", + "integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==", + "license": "MIT", + "engines": { + "node": "*" + } + }, "node_modules/buffer-equal-constant-time": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", @@ -1413,7 +1423,6 @@ "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/content-type": { @@ -1941,6 +1950,15 @@ "node": ">=0.8.0" } }, + "node_modules/fd-slicer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", + "integrity": "sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g==", + "license": "MIT", + "dependencies": { + "pend": "~1.2.0" + } + }, "node_modules/figures": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", @@ -2065,6 +2083,12 @@ "node": ">=10" } }, + "node_modules/fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", + "license": "ISC" + }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", @@ -2148,6 +2172,45 @@ "node": ">= 4" } }, + "node_modules/geoip-lite": { + "version": "1.4.10", + "resolved": "https://registry.npmjs.org/geoip-lite/-/geoip-lite-1.4.10.tgz", + "integrity": "sha512-4N69uhpS3KFd97m00wiFEefwa+L+HT5xZbzPhwu+sDawStg6UN/dPwWtUfkQuZkGIY1Cj7wDVp80IsqNtGMi2w==", + "license": "Apache-2.0", + "dependencies": { + "async": "2.1 - 2.6.4", + "chalk": "4.1 - 4.1.2", + "iconv-lite": "0.4.13 - 0.6.3", + "ip-address": "5.8.9 - 5.9.4", + "lazy": "1.0.11", + "rimraf": "2.5.2 - 2.7.1", + "yauzl": "2.9.2 - 2.10.0" + }, + "engines": { + "node": ">=10.3.0" + } + }, + "node_modules/geoip-lite/node_modules/async": { + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz", + "integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==", + "license": "MIT", + "dependencies": { + "lodash": "^4.17.14" + } + }, + "node_modules/geoip-lite/node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -2219,6 +2282,27 @@ "integrity": "sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==", "license": "MIT" }, + "node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "deprecated": "Glob versions prior to v9 are no longer supported", + "license": "ISC", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/glob-parent": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", @@ -2231,6 +2315,28 @@ "node": ">= 6" } }, + "node_modules/glob/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==", + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/glob/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "license": "ISC", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, "node_modules/globby": { "version": "11.1.0", "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", @@ -2549,6 +2655,17 @@ "node": ">=8" } }, + "node_modules/inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.", + "license": "ISC", + "dependencies": { + "once": "^1.3.0", + "wrappy": "1" + } + }, "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", @@ -2614,6 +2731,26 @@ "integrity": "sha512-lJUL9imLTNi1ZfXT+DU6rBBdbiKGBuay9B6xGSPVjUeQwaH1RIGqef8RZkUtHioLmSNpPR5M4HVKJGm1j8FWVQ==", "license": "MIT" }, + "node_modules/ip-address": { + "version": "5.9.4", + "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-5.9.4.tgz", + "integrity": "sha512-dHkI3/YNJq4b/qQaz+c8LuarD3pY24JqZWfjB8aZx1gtpc2MDILu9L9jpZe1sHpzo/yWFweQVn+U//FhazUxmw==", + "license": "MIT", + "dependencies": { + "jsbn": "1.1.0", + "lodash": "^4.17.15", + "sprintf-js": "1.1.2" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/ip-address/node_modules/sprintf-js": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.2.tgz", + "integrity": "sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug==", + "license": "BSD-3-Clause" + }, "node_modules/ipaddr.js": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-2.2.0.tgz", @@ -2868,6 +3005,12 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/jsbn": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz", + "integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==", + "license": "MIT" + }, "node_modules/json-bigint": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/json-bigint/-/json-bigint-1.0.0.tgz", @@ -3015,6 +3158,15 @@ "kill-port": "cli.js" } }, + "node_modules/lazy": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/lazy/-/lazy-1.0.11.tgz", + "integrity": "sha512-Y+CjUfLmIpoUCCRl0ub4smrYtGGr5AOa2AKOaWelGHOGz33X/Y/KizefGqbkwfz44+cnq/+9habclf8vOmu2LA==", + "license": "MIT", + "engines": { + "node": ">=0.2.0" + } + }, "node_modules/lazyness": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/lazyness/-/lazyness-1.2.0.tgz", @@ -3664,6 +3816,15 @@ "cross-spawn": "^7.0.3" } }, + "node_modules/path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/path-key": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", @@ -3682,6 +3843,12 @@ "node": ">=8" } }, + "node_modules/pend": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", + "integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==", + "license": "MIT" + }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", @@ -4029,6 +4196,19 @@ "integrity": "sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==", "license": "MIT" }, + "node_modules/rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "deprecated": "Rimraf versions prior to v4 are no longer supported", + "license": "ISC", + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + } + }, "node_modules/run-async": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz", @@ -4857,6 +5037,16 @@ "node": ">=12" } }, + "node_modules/yauzl": { + "version": "2.10.0", + "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz", + "integrity": "sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==", + "license": "MIT", + "dependencies": { + "buffer-crc32": "~0.2.3", + "fd-slicer": "~1.1.0" + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/session-server/package.json b/session-server/package.json index 73acce9c0b..06c15324a3 100644 --- a/session-server/package.json +++ b/session-server/package.json @@ -24,6 +24,7 @@ "dotenv": "^16.5.0", "fastify": "^5.3.0", "firebase-admin": "^13.2.0", + "geoip-lite": "^1.4.10", "ip": "^2.0.1", "jamsocket": "^0.10.8", "obscenity": "^0.4.5", diff --git a/session-server/session.mjs b/session-server/session.mjs index 3d685c464a..30192815a9 100644 --- a/session-server/session.mjs +++ b/session-server/session.mjs @@ -28,6 +28,7 @@ // Add redis pub/sub here... import Fastify from "fastify"; +import geoip from "geoip-lite"; import { WebSocket, WebSocketServer } from "ws"; import ip from "ip"; import chokidar from "chokidar"; @@ -274,6 +275,7 @@ function getClientStatus() { handle: client.handle || null, location: client.location || null, ip: client.ip || null, + geo: client.geo || null, connectionIds: { websocket: [], udp: [] }, protocols: { websocket: false, udp: false }, connections: { websocket: [], udp: [] } @@ -286,6 +288,7 @@ function getClientStatus() { if (client.handle && !identity.handle) identity.handle = client.handle; if (client.location) identity.location = client.location; if (client.ip && !identity.ip) identity.ip = client.ip; + if (client.geo && !identity.geo) identity.geo = client.geo; identity.connectionIds.websocket.push(parseInt(id)); identity.protocols.websocket = true; @@ -312,6 +315,7 @@ function getClientStatus() { handle: client.handle || null, location: client.location || null, ip: client.ip || null, + geo: client.geo || null, connectionIds: { websocket: [], udp: [] }, protocols: { websocket: false, udp: false }, connections: { websocket: [], udp: [] } @@ -324,6 +328,7 @@ function getClientStatus() { if (client.handle && !identity.handle) identity.handle = client.handle; if (client.location) identity.location = client.location; if (client.ip && !identity.ip) identity.ip = client.ip; + if (client.geo && !identity.geo) identity.geo = client.geo; identity.connectionIds.udp.push(id); identity.protocols.udp = true; @@ -344,6 +349,7 @@ function getClientStatus() { handle: identity.handle, location: identity.location, ip: identity.ip, + geo: identity.geo, protocols: identity.protocols, connectionCount: { websocket: wsCount, @@ -516,7 +522,19 @@ fastify.get("/", async (request, reply) => { if (c.websocket?.ping) out += \` (\${c.websocket.ping}ms)\`; out += ''; if (c.location && c.location !== '*keep-alive*') out += \`
📍 \${c.location}
\`; - if (c.ip) out += \`
🌐 \${c.ip.replace('::ffff:', '')}
\`; + + // Show geolocation if available + if (c.geo) { + let geo = '🗺️ '; + if (c.geo.city) geo += c.geo.city + ', '; + if (c.geo.region) geo += c.geo.region + ', '; + geo += c.geo.country; + if (c.geo.timezone) geo += \` (\${c.geo.timezone})\`; + out += \`
\${geo}
\`; + } else if (c.ip) { + out += \`
🌐 \${c.ip}
\`; + } + if (c.websocket?.worlds?.length > 0) { const w = c.websocket.worlds[0]; out += \`
🌍 \${w.piece}\`; @@ -621,10 +639,27 @@ wss.on("connection", (ws, req) => { const id = connectionId; let codeChannel; // Used to subscribe to incoming piece code. - // Initialize client record with IP + // Initialize client record with IP and geolocation if (!clients[id]) clients[id] = {}; clients[id].websocket = true; - clients[id].ip = ip; + + // Clean IP and get geolocation + const cleanIp = ip.replace('::ffff:', ''); + clients[id].ip = cleanIp; + + const geo = geoip.lookup(cleanIp); + if (geo) { + clients[id].geo = { + country: geo.country, + region: geo.region, + city: geo.city, + timezone: geo.timezone, + ll: geo.ll // [latitude, longitude] + }; + log(`🌍 Geolocation for ${cleanIp}:`, geo.country, geo.region, geo.city); + } else { + log(`🌍 No geolocation data for ${cleanIp}`); + } log("🧏 Someone joined:", `${id}:${ip}`, "Online:", wss.clients.size, "🫂"); log("🎮 Added to connections. Total game clients:", Object.keys(connections).length); -- knotmirror 0.0.1 From d13f8a0a724ea1758e93c0124ff26a3352973a6c Mon Sep 17 00:00:00 2001 From: Jeffrey Alan Scudder Date: Mon, 10 Nov 2025 20:19:55 -0800 Subject: [PATCH 2/6] Add ac-deploy-session command and improve identity/handle logging --- .devcontainer/config.fish | 10 ++ plans/session-dashboard-progress.md | 205 ++++++++++++++++++++++++++++ session-server/deploy.fish | 17 ++- session-server/session.mjs | 46 +++++-- 4 files changed, 257 insertions(+), 21 deletions(-) create mode 100644 plans/session-dashboard-progress.md diff --git a/.devcontainer/config.fish b/.devcontainer/config.fish index d354da5c84..1af25c5026 100644 --- a/.devcontainer/config.fish +++ b/.devcontainer/config.fish @@ -1413,6 +1413,16 @@ alias nvm forget bind \t complete-select-first +function ac-deploy-session + set script_path ~/aesthetic-computer/session-server/deploy.fish + if test -f $script_path + fish $script_path $argv + else + echo "❌ Deploy script not found at $script_path" + return 1 + end +end + function clipboard set content $argv set -l hosts host.docker.internal $HOST_IP 172.17.0.1 diff --git a/plans/session-dashboard-progress.md b/plans/session-dashboard-progress.md new file mode 100644 index 0000000000..217be540be --- /dev/null +++ b/plans/session-dashboard-progress.md @@ -0,0 +1,205 @@ +# Session Dashboard Progress Log + +**Date**: November 11, 2025 + +## Overview +Implemented a real-time status dashboard for the session server at `session-server.aesthetic.computer` that displays all connected WebSocket and UDP clients with identity tracking. + +## Completed Features + +### ✅ Status Dashboard (WORKING) +- **URL**: https://session-server.aesthetic.computer/ +- **Features**: + - Real-time updates every 2 seconds via WebSocket streaming + - Displays WebSocket connections with user IDs and handles + - Displays UDP connections with user IDs and handles + - Auto-refreshing interface with connection counts + - Clean HTML interface with embedded JavaScript + +### ✅ Status API Endpoints (WORKING) +- **GET `/status`**: JSON endpoint returning connection data + - WebSocket total count and connection details + - UDP total count and channel details + - Includes user IDs (auth0 subs) and handles + +- **WebSocket `/status-stream`**: Real-time streaming updates + - Broadcasts status updates every 2 seconds + - Used by dashboard for live updates + +### ✅ Identity Tracking Implementation (SERVER-SIDE COMPLETE) +- **WebSocket tracking**: + - `users{}` map: Tracks auth0 user.sub from login messages + - `handles{}` map: Tracks user handles from location:broadcast messages + - Enhanced `getWebSocketStatus()` to include user and handle fields + +- **UDP tracking**: + - Enhanced UDP channel storage to include user and handle + - Added `udp:identity` message handler + - Enhanced `getUDPStatus()` to include user and handle fields + +### ✅ Client-Side Identity Code (IMPLEMENTED, NEEDS DEPLOYMENT) +- **disk.mjs changes**: + - Uncommented login message sending on WebSocket connect (line 6381) + - Exposed `window.acHANDLE` in 3 locations for UDP access (lines 3451, 12379, 12393) + - Existing location:broadcast already sends handle + +- **udp.mjs changes**: + - Added `udp:identity` message emission on connection (lines 56-61) + - Sends both user and handle to server + +### ✅ WebSocket Connection Routing (WORKING) +- Dashboard connections (`/status-stream`) handled separately +- Game client connections tracked in `connections{}` object +- Debug logging added for connection monitoring + +### ✅ Code Deployment +- All server-side code committed and deployed to production +- Session server running with latest code +- Debug logging active for troubleshooting + +## Current Issues + +### 🔴 CRITICAL: WebSocket Connections Not Establishing +**Problem**: aesthetic.computer clients establish UDP connections but NOT WebSocket connections + +**Evidence**: +- Status shows: `{"total": 2, "connections": []}` + - `total: 2` = dashboard WebSocket connections (correct) + - `connections: []` = zero game client connections (BROKEN) +- UDP shows 5 active connections with auth0 user IDs (WORKING) +- Dashboard WebSocket connections work perfectly (proves server works) + +**Root Cause FOUND**: +```javascript +// Line 6340 in disk.mjs (BEFORE FIX) +const monolith = undefined; // This was the problem! +``` + +When `monolith` is `undefined`, the session endpoint tries to use JamSocket horizontal scaling instead of connecting to session-server.aesthetic.computer. + +**Fix Applied** (commit 9f4ac380): +```javascript +// Line 6340 in disk.mjs (AFTER FIX) +const monolith = "monolith"; // Now correctly uses session-server +``` + +**Status**: Code fixed and pushed to main, but aesthetic.computer site needs rebuild to deploy + +### ⚠️ Handles Showing as Null +**Problem**: UDP connections show auth0 user IDs but handles are null + +**Root Cause**: Client-side code changes not deployed to live aesthetic.computer yet + +**Status**: Will be fixed once aesthetic.computer is rebuilt with updated disk.mjs and udp.mjs + +## Technical Architecture + +### Session Server Stack +- **Framework**: Fastify v4 (HTTP/HTTPS) +- **WebSocket**: ws library with custom routing +- **UDP**: geckos.io for game networking +- **Tracking**: In-memory maps (users{}, handles{}, connections{}, udpChannels{}) + +### Identity Flow +1. **WebSocket**: + - Client connects → server adds to connections{} + - Client sends login message → server stores user.sub in users{} + - Client sends location:broadcast → server stores handle in handles{} + - Dashboard queries → server enriches data with user/handle from maps + +2. **UDP**: + - Client connects → server creates channel + - Client sends udp:identity → server stores user and handle in channel object + - Dashboard queries → server returns enriched channel data + +### Deployment Architecture +- **Production Server**: session-server.aesthetic.computer (157.245.134.225) +- **Deployment Method**: SSH + git pull + process restart +- **Process Management**: Direct node process (not pm2) +- **Log Location**: /var/log/session-server.log + +## Next Steps + +### 🎯 IMMEDIATE: Rebuild aesthetic.computer +**Required**: Deploy client-side changes to enable WebSocket connections + +**Changes that need to go live**: +1. `monolith = "monolith"` (enables WebSocket to session-server) ← **CRITICAL** +2. Login message sending (enables user ID tracking) +3. `window.acHANDLE` exposure (enables handle tracking) +4. UDP identity message (enables UDP handle tracking) + +**Once deployed, all features should work**: +- ✅ WebSocket connections will appear in dashboard +- ✅ Handles will populate for both WebSocket and UDP +- ✅ User IDs will populate for both WebSocket and UDP +- ✅ Full identity tracking operational + +### 📊 Validation Steps After Rebuild +1. Open aesthetic.computer in browser +2. Check dashboard shows WebSocket connection (not just UDP) +3. Verify handle appears for WebSocket connection +4. Verify handle appears for UDP connection (currently null) +5. Verify user ID appears for both connection types + +## Files Modified + +### Server-Side (DEPLOYED) +- `session-server/session.mjs` + - Added `handles{}` map (line 139) + - Enhanced getWebSocketStatus() with handle field (line 267) + - Enhanced getUDPStatus() with user/handle fields (line 282) + - Added login message handler (line 693) + - Added handle tracking in location:broadcast (line 725) + - Added udp:identity handler (line 1072) + - Added WebSocket routing logic (line 548) + - Added debug logging (lines 545, 569) + - Added dashboard HTML (lines 350-515) + +### Client-Side (COMMITTED, NOT DEPLOYED) +- `system/public/aesthetic.computer/lib/disk.mjs` + - Changed monolith from undefined to "monolith" (line 6340) ← **CRITICAL FIX** + - Uncommented login message sending (line 6381) + - Exposed window.acHANDLE (lines 3451, 12379, 12393) + +- `system/public/aesthetic.computer/lib/udp.mjs` + - Added udp:identity message emission (lines 56-61) + +### Deployment Scripts +- `session-server/deploy.fish` + - Updated paths from /root to /home/aesthetic-computer + - Changed from pm2 to direct node process management + +## Commits +- 9f4ac380: Enable monolith session server for WebSocket connections (LATEST) +- [previous]: Add more detailed WebSocket connection logging +- [previous]: Add comprehensive identity tracking to session server +- [previous]: Initial status dashboard implementation + +## Testing Results + +### Dashboard (✅ WORKING) +- Loads at session-server.aesthetic.computer +- Creates 2 WebSocket connections +- Updates every 2 seconds +- Displays connection data correctly +- JSON endpoint returns valid data + +### UDP Connections (⚠️ PARTIAL) +- 5 connections visible +- Auth0 user IDs showing correctly +- Handles showing as null (needs client rebuild) + +### WebSocket Connections (🔴 BROKEN, FIX READY) +- Dashboard connections work (2 visible) +- Game client connections not appearing (0 visible) +- Root cause identified: monolith = undefined +- Fix committed, needs deployment + +## Lessons Learned + +1. **Separation of concerns**: Dashboard WebSocket connections vs game client connections needed separate tracking +2. **Deployment dependency**: Client-side changes require aesthetic.computer rebuild, not just server restart +3. **Configuration matters**: Single variable (`monolith`) determines entire connection architecture +4. **Independent protocols**: UDP and WebSocket are separate - one can work while other fails +5. **Debug early**: Added logging revealed the WebSocket routing was working, connections just weren't being made diff --git a/session-server/deploy.fish b/session-server/deploy.fish index 9361e391ff..09ae858ec3 100755 --- a/session-server/deploy.fish +++ b/session-server/deploy.fish @@ -5,6 +5,7 @@ set SERVER "root@157.245.134.225" set SSH_KEY "$HOME/.ssh/session_server" set REPO_PATH "/home/aesthetic-computer" +set NODE_PATH "/root/.local/share/fnm/node-versions/v20.14.0/installation/bin" echo "🚀 Deploying session server to production..." echo "" @@ -19,10 +20,10 @@ if test $status -ne 0 exit 1 end -# Step 2: Install dependencies (skip if node_modules exists) +# Step 2: Install dependencies echo "" -echo "📦 Step 2/4: Checking dependencies..." -ssh -i $SSH_KEY $SERVER "cd $REPO_PATH/session-server && if [ ! -d node_modules ]; then echo 'Installing...'; npm install; else echo 'Dependencies already installed'; fi" +echo "📦 Step 2/4: Installing dependencies..." +ssh -i $SSH_KEY $SERVER "export PATH=$NODE_PATH:\$PATH && cd $REPO_PATH/session-server && npm install" if test $status -ne 0 echo "" @@ -33,7 +34,7 @@ end # Step 3: Restart service echo "" echo "🔄 Step 3/4: Restarting session server..." -ssh -i $SSH_KEY $SERVER "pkill -f 'node.*session.mjs' && sleep 2 && cd $REPO_PATH/session-server && nohup node session.mjs > /tmp/session-server.log 2>&1 &" +ssh -i $SSH_KEY $SERVER "export PATH=$NODE_PATH:\$PATH && pkill -f 'node.*session.mjs' && sleep 2 && cd $REPO_PATH/session-server && nohup node session.mjs > /var/log/session-server.log 2>&1 &" if test $status -ne 0 echo "" @@ -45,12 +46,10 @@ end echo "" echo "📊 Step 4/4: Checking server status..." sleep 3 -ssh -i $SSH_KEY $SERVER "ps aux | grep 'session.mjs' | grep -v grep && echo '' && tail -20 /tmp/session-server.log" +ssh -i $SSH_KEY $SERVER "ps aux | grep 'session.mjs' | grep -v grep && echo '' && tail -20 /var/log/session-server.log" echo "" echo "✅ Deployment complete!" echo "" -echo "📡 Test the endpoints:" -echo " curl -k https://session-server.aesthetic.computer/build-stream \\" -echo " --header 'Content-Type: application/json' \\" -echo " --data '{\"line\": \"Test message\"}'" +echo "🌐 Visit: https://session-server.aesthetic.computer" +echo "📊 Status: https://session-server.aesthetic.computer/status" diff --git a/session-server/session.mjs b/session-server/session.mjs index 30192815a9..f8ade14d87 100644 --- a/session-server/session.mjs +++ b/session-server/session.mjs @@ -596,9 +596,12 @@ wss.on("connection", (ws, req) => { // Route status dashboard WebSocket connections separately if (req.url === '/status-stream') { - log('📊 Status dashboard connected, returning early (not adding to game clients)'); + log('📊 Status dashboard viewer connected from:', req.socket.remoteAddress); statusClients.add(ws); + // Mark as dashboard viewer (don't add to game clients) + ws.isDashboardViewer = true; + // Send initial state ws.send(JSON.stringify({ type: 'status', @@ -606,7 +609,7 @@ wss.on("connection", (ws, req) => { })); ws.on('close', () => { - log('📊 Status dashboard disconnected'); + log('📊 Status dashboard viewer disconnected'); statusClients.delete(ws); }); @@ -782,18 +785,24 @@ wss.on("connection", (ws, req) => { // Fetch the user's handle from the API const userSub = msg.content.user.sub; + log("🔑 Login attempt for user:", userSub.substring(0, 20) + "...", "connection:", id); + fetch(`https://aesthetic.computer/handle/${encodeURIComponent(userSub)}`) - .then(response => response.json()) + .then(response => { + log("📡 Handle API response status:", response.status, "for", userSub.substring(0, 20) + "..."); + return response.json(); + }) .then(data => { + log("📦 Handle API data:", JSON.stringify(data), "for connection:", id); if (data.handle) { clients[id].handle = data.handle; - log("🔑 User logged in:", data.handle, `(${userSub.substring(0, 12)}...)`, "connection:", id); + log("✅ User logged in:", data.handle, `(${userSub.substring(0, 12)}...)`, "connection:", id); } else { - log("🔑 User logged in (no handle):", userSub.substring(0, 12), "..., connection:", id); + log("⚠️ User logged in (no handle in response):", userSub.substring(0, 12), "..., connection:", id); } }) .catch(err => { - log("⚠️ Failed to fetch handle for:", userSub, err.message); + log("❌ Failed to fetch handle for:", userSub.substring(0, 20) + "...", "Error:", err.message); }); } } else if (msg.type === "location:broadcast") { /* @@ -1206,38 +1215,51 @@ io.onConnection((channel) => { handle: null }; - log(`🩰 ${channel.id} connected`); + log(`🩰 UDP ${channel.id} connected from:`, channel.userData?.address || 'unknown'); + + // Set a timeout to warn about missing identity + setTimeout(() => { + if (!clients[channel.id]?.user && !clients[channel.id]?.handle) { + log(`⚠️ UDP ${channel.id} has been connected for 10s but hasn't sent identity message`); + } + }, 10000); // Handle identity message channel.on("udp:identity", (data) => { try { const identity = JSON.parse(data); + log(`🩰 UDP ${channel.id} sent identity:`, JSON.stringify(identity).substring(0, 100)); // Initialize client record if needed if (!clients[channel.id]) clients[channel.id] = { udp: true }; if (identity.user?.sub) { clients[channel.id].user = identity.user.sub; + log(`🩰 UDP ${channel.id} user:`, identity.user.sub.substring(0, 20) + "..."); // Fetch the actual handle from the API const userSub = identity.user.sub; fetch(`https://aesthetic.computer/handle/${encodeURIComponent(userSub)}`) - .then(response => response.json()) + .then(response => { + log(`📡 Handle API for UDP ${channel.id}, status:`, response.status); + return response.json(); + }) .then(data => { + log(`📦 Handle API data for UDP ${channel.id}:`, JSON.stringify(data)); if (data.handle) { clients[channel.id].handle = data.handle; - log(`🩰 ${channel.id} handle verified from API: "${data.handle}"`); + log(`✅ UDP ${channel.id} handle verified from API: "${data.handle}"`); } else { - log(`🩰 ${channel.id} user has no handle in API`); + log(`⚠️ UDP ${channel.id} user has no handle in API`); } }) .catch(err => { - log(`⚠️ Failed to fetch handle for UDP ${channel.id}:`, err.message); + log(`❌ Failed to fetch handle for UDP ${channel.id}:`, err.message); }); } else if (identity.handle) { // If they send a handle but no user.sub, store it but don't verify clients[channel.id].handle = identity.handle; - log(`🩰 ${channel.id} handle set (unverified): "${identity.handle}"`); + log(`🩰 UDP ${channel.id} handle set (unverified): "${identity.handle}"`); } } catch (e) { error(`🩰 Failed to parse identity for ${channel.id}:`, e); -- knotmirror 0.0.1 From eca4db054317b5ed99deea49cff532669c63ff61 Mon Sep 17 00:00:00 2001 From: Jeffrey Alan Scudder Date: Mon, 10 Nov 2025 20:24:10 -0800 Subject: [PATCH 3/6] Fix deploy script to use full node path for logging --- session-server/deploy.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/session-server/deploy.fish b/session-server/deploy.fish index 09ae858ec3..5f4c9410af 100755 --- a/session-server/deploy.fish +++ b/session-server/deploy.fish @@ -34,7 +34,7 @@ end # Step 3: Restart service echo "" echo "🔄 Step 3/4: Restarting session server..." -ssh -i $SSH_KEY $SERVER "export PATH=$NODE_PATH:\$PATH && pkill -f 'node.*session.mjs' && sleep 2 && cd $REPO_PATH/session-server && nohup node session.mjs > /var/log/session-server.log 2>&1 &" +ssh -i $SSH_KEY $SERVER "pkill -f 'node.*session.mjs' && sleep 2 && cd $REPO_PATH/session-server && nohup $NODE_PATH/node session.mjs > /var/log/session-server.log 2>&1 &" if test $status -ne 0 echo "" -- knotmirror 0.0.1 From ccac1774828410f4f810d08fe3574ec16e923b1d Mon Sep 17 00:00:00 2001 From: Jeffrey Alan Scudder Date: Mon, 10 Nov 2025 20:30:14 -0800 Subject: [PATCH 4/6] Extract user identity from ALL messages, not just login --- session-server/session.mjs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/session-server/session.mjs b/session-server/session.mjs index f8ade14d87..90b12b7dad 100644 --- a/session-server/session.mjs +++ b/session-server/session.mjs @@ -711,6 +711,37 @@ wss.on("connection", (ws, req) => { msg.id = id; // TODO: When sending a server generated message, use a special id. + // Extract user identity from ANY message that contains it + if (msg.content?.user?.sub) { + if (!clients[id]) clients[id] = { websocket: true }; + + // Only fetch handle if we don't have it yet + if (!clients[id].user || clients[id].user !== msg.content.user.sub) { + clients[id].user = msg.content.user.sub; + const userSub = msg.content.user.sub; + + log("🔑 User identity from message type:", msg.type, "user:", userSub.substring(0, 20) + "...", "conn:", id); + + fetch(`https://aesthetic.computer/handle/${encodeURIComponent(userSub)}`) + .then(response => { + log("📡 Handle API status:", response.status, "for", userSub.substring(0, 20) + "..."); + return response.json(); + }) + .then(data => { + log("📦 Handle API data:", JSON.stringify(data)); + if (data.handle) { + clients[id].handle = data.handle; + log("✅ Handle resolved:", data.handle, `(${userSub.substring(0, 12)}...)`, "conn:", id); + } else { + log("⚠️ No handle in API response for:", userSub.substring(0, 12) + "..."); + } + }) + .catch(err => { + log("❌ Handle fetch failed:", userSub.substring(0, 20) + "...", err.message); + }); + } + } + if (msg.type === "scream") { // Alert all connected users via redis pub/sub to the scream. log("😱 About to scream..."); -- knotmirror 0.0.1 From f060cf507d8b55e237c857cea231792e138711a1 Mon Sep 17 00:00:00 2001 From: Jeffrey Alan Scudder Date: Mon, 10 Nov 2025 20:31:32 -0800 Subject: [PATCH 5/6] Include user in location:broadcast messages for identity resolution --- system/public/aesthetic.computer/lib/disk.mjs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/system/public/aesthetic.computer/lib/disk.mjs b/system/public/aesthetic.computer/lib/disk.mjs index 0aaf658801..92815821b8 100644 --- a/system/public/aesthetic.computer/lib/disk.mjs +++ b/system/public/aesthetic.computer/lib/disk.mjs @@ -6385,11 +6385,13 @@ async function load( socket?.send("location:broadcast", { handle: HANDLE, slug: currentText, + user: USER, // Include user for identity resolution }); slugBroadcastInterval = setInterval(() => { socket?.send("location:broadcast", { handle: HANDLE, slug: "*keep-alive*", + user: USER, // Include user for identity resolution }); }, 2500); } -- knotmirror 0.0.1 From 1b66a3c97a201072304f7164350c1a96beb01e3d Mon Sep 17 00:00:00 2001 From: Jeffrey Alan Scudder Date: Mon, 10 Nov 2025 20:37:19 -0800 Subject: [PATCH 6/6] Use handle directly from messages instead of non-existent API --- session-server/session.mjs | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/session-server/session.mjs b/session-server/session.mjs index 90b12b7dad..9e1aff6726 100644 --- a/session-server/session.mjs +++ b/session-server/session.mjs @@ -711,34 +711,22 @@ wss.on("connection", (ws, req) => { msg.id = id; // TODO: When sending a server generated message, use a special id. - // Extract user identity from ANY message that contains it + // Extract user identity and handle from ANY message that contains it if (msg.content?.user?.sub) { if (!clients[id]) clients[id] = { websocket: true }; - // Only fetch handle if we don't have it yet - if (!clients[id].user || clients[id].user !== msg.content.user.sub) { - clients[id].user = msg.content.user.sub; - const userSub = msg.content.user.sub; - - log("🔑 User identity from message type:", msg.type, "user:", userSub.substring(0, 20) + "...", "conn:", id); - - fetch(`https://aesthetic.computer/handle/${encodeURIComponent(userSub)}`) - .then(response => { - log("📡 Handle API status:", response.status, "for", userSub.substring(0, 20) + "..."); - return response.json(); - }) - .then(data => { - log("📦 Handle API data:", JSON.stringify(data)); - if (data.handle) { - clients[id].handle = data.handle; - log("✅ Handle resolved:", data.handle, `(${userSub.substring(0, 12)}...)`, "conn:", id); - } else { - log("⚠️ No handle in API response for:", userSub.substring(0, 12) + "..."); - } - }) - .catch(err => { - log("❌ Handle fetch failed:", userSub.substring(0, 20) + "...", err.message); - }); + const userSub = msg.content.user.sub; + const userChanged = !clients[id].user || clients[id].user !== userSub; + + if (userChanged) { + clients[id].user = userSub; + log("🔑 User identity from", msg.type + ":", userSub.substring(0, 20) + "...", "conn:", id); + } + + // Extract handle from message if present (e.g., location:broadcast includes it) + if (msg.content.handle && (!clients[id].handle || clients[id].handle !== msg.content.handle)) { + clients[id].handle = msg.content.handle; + log("✅ Handle from message:", msg.content.handle, "conn:", id); } } -- knotmirror 0.0.1