diff --git a/public b/public index 0f21e39..6d894d1 160000 --- a/public +++ b/public @@ -1 +1 @@ -Subproject commit 0f21e390667589f7acfef4d82a8f270a830822ee +Subproject commit 6d894d19cd7dbe09f9fdf65cd954b916326c4437 diff --git a/src/ws/Socket.ts b/src/ws/Socket.ts index f093a8d..ff6c535 100644 --- a/src/ws/Socket.ts +++ b/src/ws/Socket.ts @@ -56,11 +56,11 @@ export class Socket extends EventEmitter { private cursorPos: Vector2 = { x: 200, y: 100 }; constructor( - private ws: ServerWebSocket, + private ws: ServerWebSocket<{ ip: string }>, public socketID: string ) { super(); - this.ip = ws.remoteAddress; // Participant ID + this.ip = ws.data.ip; // User ID this._id = createUserID(this.getIP()); diff --git a/src/ws/server.ts b/src/ws/server.ts index ce98922..570cb8b 100644 --- a/src/ws/server.ts +++ b/src/ws/server.ts @@ -31,11 +31,20 @@ async function getIndex() { return response; } -export const app = Bun.serve({ +export const app = Bun.serve<{ ip: string }>({ port: env.PORT, hostname: "0.0.0.0", fetch: (req, server) => { - if (server.upgrade(req)) { + const reqip = server.requestIP(req); + if (!reqip) return; + + if ( + server.upgrade(req, { + data: { + ip: req.headers.get("X-Forwarded-For") || reqip.address + } + }) + ) { return; } else { const url = new URL(req.url).pathname;