@air-jam/server 0.1.3 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/chunk-5ZVGSYXC.js +252 -0
- package/dist/chunk-5ZVGSYXC.js.map +1 -0
- package/dist/chunk-RM7AMBDY.js +831 -0
- package/dist/chunk-RM7AMBDY.js.map +1 -0
- package/dist/cli.js +512 -5
- package/dist/cli.js.map +1 -1
- package/dist/game-dev-D3TEAHOD.js +422 -0
- package/dist/game-dev-D3TEAHOD.js.map +1 -0
- package/dist/index.js +5978 -1
- package/dist/index.js.map +1 -1
- package/dist/local-dev-state-QT7H5GUA.js +270 -0
- package/dist/local-dev-state-QT7H5GUA.js.map +1 -0
- package/dist/secure-dev-HMOGLYVC.js +39 -0
- package/dist/secure-dev-HMOGLYVC.js.map +1 -0
- package/dist/topology-PM3PI753.js +140 -0
- package/dist/topology-PM3PI753.js.map +1 -0
- package/package.json +36 -14
- package/src/project-cli/vite-config.d.mts +17 -0
- package/src/project-cli/vite-config.mjs +121 -0
- package/src/project-cli/vite-https.d.mts +14 -0
- package/src/project-cli/vite-https.mjs +39 -0
- package/dist/chunk-T6BT7WE5.js +0 -976
- package/dist/chunk-T6BT7WE5.js.map +0 -1
package/dist/chunk-T6BT7WE5.js
DELETED
|
@@ -1,976 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import {
|
|
3
|
-
controllerInputSchema,
|
|
4
|
-
controllerJoinSchema,
|
|
5
|
-
controllerLeaveSchema,
|
|
6
|
-
controllerStateSchema,
|
|
7
|
-
controllerSystemSchema,
|
|
8
|
-
ErrorCode,
|
|
9
|
-
hostCreateRoomSchema,
|
|
10
|
-
hostJoinAsChildSchema,
|
|
11
|
-
hostReconnectSchema,
|
|
12
|
-
hostRegisterSystemSchema,
|
|
13
|
-
hostRegistrationSchema,
|
|
14
|
-
systemLaunchGameSchema
|
|
15
|
-
} from "@air-jam/sdk/protocol";
|
|
16
|
-
import Color from "color";
|
|
17
|
-
import cors from "cors";
|
|
18
|
-
import express from "express";
|
|
19
|
-
import { createServer } from "http";
|
|
20
|
-
import { Server } from "socket.io";
|
|
21
|
-
import { v4 as uuidv4 } from "uuid";
|
|
22
|
-
|
|
23
|
-
// src/services/auth-service.ts
|
|
24
|
-
import { and, eq } from "drizzle-orm";
|
|
25
|
-
|
|
26
|
-
// src/db.ts
|
|
27
|
-
import * as dotenv from "dotenv";
|
|
28
|
-
import { boolean, pgTable, text, timestamp } from "drizzle-orm/pg-core";
|
|
29
|
-
import { drizzle } from "drizzle-orm/postgres-js";
|
|
30
|
-
import postgres from "postgres";
|
|
31
|
-
dotenv.config();
|
|
32
|
-
var apiKeys = pgTable("api_keys", {
|
|
33
|
-
id: text("id").primaryKey(),
|
|
34
|
-
gameId: text("game_id").notNull().unique(),
|
|
35
|
-
// One API key per game
|
|
36
|
-
key: text("key").notNull().unique(),
|
|
37
|
-
isActive: boolean("is_active").default(true).notNull(),
|
|
38
|
-
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
39
|
-
lastUsedAt: timestamp("last_used_at")
|
|
40
|
-
});
|
|
41
|
-
var connectionString = process.env.DATABASE_URL;
|
|
42
|
-
var client = connectionString ? postgres(connectionString) : null;
|
|
43
|
-
var db = client ? drizzle(client) : null;
|
|
44
|
-
|
|
45
|
-
// src/services/auth-service.ts
|
|
46
|
-
var AuthService = class {
|
|
47
|
-
masterKey;
|
|
48
|
-
databaseUrl;
|
|
49
|
-
isDevMode;
|
|
50
|
-
constructor() {
|
|
51
|
-
this.masterKey = process.env.AIR_JAM_MASTER_KEY;
|
|
52
|
-
this.databaseUrl = process.env.DATABASE_URL;
|
|
53
|
-
this.isDevMode = !this.masterKey && !this.databaseUrl;
|
|
54
|
-
if (this.isDevMode) {
|
|
55
|
-
console.log(
|
|
56
|
-
"[server] Running in development mode - authentication disabled"
|
|
57
|
-
);
|
|
58
|
-
} else if (this.masterKey && !this.databaseUrl) {
|
|
59
|
-
console.log(
|
|
60
|
-
"[server] Running with master key authentication (no database required)"
|
|
61
|
-
);
|
|
62
|
-
} else if (this.databaseUrl) {
|
|
63
|
-
console.log("[server] Running with database authentication");
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Verify an API key
|
|
68
|
-
* Returns verification result with optional error message
|
|
69
|
-
* In dev mode, always returns success
|
|
70
|
-
*/
|
|
71
|
-
async verifyApiKey(apiKey) {
|
|
72
|
-
if (this.isDevMode) {
|
|
73
|
-
return { isVerified: true };
|
|
74
|
-
}
|
|
75
|
-
if (!apiKey) {
|
|
76
|
-
return {
|
|
77
|
-
isVerified: false,
|
|
78
|
-
error: "Unauthorized: Invalid or Missing API Key"
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
if (this.masterKey && apiKey === this.masterKey) {
|
|
82
|
-
return { isVerified: true };
|
|
83
|
-
}
|
|
84
|
-
if (!this.databaseUrl || !db) {
|
|
85
|
-
return {
|
|
86
|
-
isVerified: false,
|
|
87
|
-
error: "Unauthorized: Invalid or Missing API Key"
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
try {
|
|
91
|
-
const [keyRecord] = await db.select().from(apiKeys).where(and(eq(apiKeys.key, apiKey), eq(apiKeys.isActive, true))).limit(1);
|
|
92
|
-
if (keyRecord) {
|
|
93
|
-
db.update(apiKeys).set({ lastUsedAt: /* @__PURE__ */ new Date() }).where(eq(apiKeys.id, keyRecord.id)).catch(
|
|
94
|
-
(err) => console.error("[server] Failed to update lastUsedAt", err)
|
|
95
|
-
);
|
|
96
|
-
return { isVerified: true };
|
|
97
|
-
}
|
|
98
|
-
return {
|
|
99
|
-
isVerified: false,
|
|
100
|
-
error: "Unauthorized: Invalid or Missing API Key"
|
|
101
|
-
};
|
|
102
|
-
} catch (error) {
|
|
103
|
-
console.error("[server] Database error during key verification", error);
|
|
104
|
-
return {
|
|
105
|
-
isVerified: false,
|
|
106
|
-
error: "Internal Server Error"
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
var authService = new AuthService();
|
|
112
|
-
|
|
113
|
-
// src/services/room-manager.ts
|
|
114
|
-
var RoomManager = class {
|
|
115
|
-
rooms = /* @__PURE__ */ new Map();
|
|
116
|
-
hostIndex = /* @__PURE__ */ new Map();
|
|
117
|
-
controllerIndex = /* @__PURE__ */ new Map();
|
|
118
|
-
/**
|
|
119
|
-
* Get a room by ID
|
|
120
|
-
*/
|
|
121
|
-
getRoom(roomId) {
|
|
122
|
-
return this.rooms.get(roomId);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Create or update a room
|
|
126
|
-
*/
|
|
127
|
-
setRoom(roomId, session) {
|
|
128
|
-
this.rooms.set(roomId, session);
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Delete a room
|
|
132
|
-
*/
|
|
133
|
-
deleteRoom(roomId) {
|
|
134
|
-
this.rooms.delete(roomId);
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Get room ID by host socket ID
|
|
138
|
-
*/
|
|
139
|
-
getRoomByHostId(socketId) {
|
|
140
|
-
return this.hostIndex.get(socketId);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Associate a host socket with a room
|
|
144
|
-
*/
|
|
145
|
-
setHostRoom(socketId, roomId) {
|
|
146
|
-
this.hostIndex.set(socketId, roomId);
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Remove host association
|
|
150
|
-
*/
|
|
151
|
-
deleteHost(socketId) {
|
|
152
|
-
this.hostIndex.delete(socketId);
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Get controller info by socket ID
|
|
156
|
-
*/
|
|
157
|
-
getControllerInfo(socketId) {
|
|
158
|
-
return this.controllerIndex.get(socketId);
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Associate a controller socket with room and controller ID
|
|
162
|
-
*/
|
|
163
|
-
setController(socketId, entry) {
|
|
164
|
-
this.controllerIndex.set(socketId, entry);
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Remove controller association
|
|
168
|
-
*/
|
|
169
|
-
deleteController(socketId) {
|
|
170
|
-
this.controllerIndex.delete(socketId);
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Get the active host socket ID based on focus
|
|
174
|
-
*/
|
|
175
|
-
getActiveHostId(session) {
|
|
176
|
-
return session.focus === "GAME" && session.childHostSocketId ? session.childHostSocketId : session.masterHostSocketId;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Remove a room and clean up all associations
|
|
180
|
-
*/
|
|
181
|
-
removeRoom(roomId, io2, reason) {
|
|
182
|
-
const session = this.rooms.get(roomId);
|
|
183
|
-
if (!session) return;
|
|
184
|
-
io2.to(roomId).emit("server:hostLeft", { roomId, reason });
|
|
185
|
-
session.controllers.forEach((controller) => {
|
|
186
|
-
this.controllerIndex.delete(controller.socketId);
|
|
187
|
-
});
|
|
188
|
-
this.hostIndex.delete(session.masterHostSocketId);
|
|
189
|
-
if (session.childHostSocketId) {
|
|
190
|
-
this.hostIndex.delete(session.childHostSocketId);
|
|
191
|
-
}
|
|
192
|
-
this.rooms.delete(roomId);
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Get all rooms (for debugging/monitoring)
|
|
196
|
-
*/
|
|
197
|
-
getAllRooms() {
|
|
198
|
-
return this.rooms;
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
var roomManager = new RoomManager();
|
|
202
|
-
|
|
203
|
-
// src/utils/ids.ts
|
|
204
|
-
import { roomCodeSchema } from "@air-jam/sdk/protocol";
|
|
205
|
-
import { randomInt } from "crypto";
|
|
206
|
-
var alphabet = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
207
|
-
var generateRoomCode = () => {
|
|
208
|
-
const code = Array.from(
|
|
209
|
-
{ length: 4 },
|
|
210
|
-
() => alphabet[randomInt(0, alphabet.length)]
|
|
211
|
-
).join("");
|
|
212
|
-
return roomCodeSchema.parse(code);
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
// src/index.ts
|
|
216
|
-
var lastServerInputLogTime = 0;
|
|
217
|
-
var lastServerInputFailLogTime = 0;
|
|
218
|
-
var PORT = Number(process.env.PORT ?? 4e3);
|
|
219
|
-
var app = express();
|
|
220
|
-
app.use(cors());
|
|
221
|
-
app.use(express.json());
|
|
222
|
-
app.get("/health", (_, res) => {
|
|
223
|
-
res.json({ ok: true });
|
|
224
|
-
});
|
|
225
|
-
var httpServer = createServer(app);
|
|
226
|
-
var io = new Server(httpServer, {
|
|
227
|
-
cors: {
|
|
228
|
-
origin: "*"
|
|
229
|
-
},
|
|
230
|
-
pingInterval: 2e3,
|
|
231
|
-
pingTimeout: 5e3
|
|
232
|
-
});
|
|
233
|
-
var emitError = (socketId, payload) => {
|
|
234
|
-
io.to(socketId).emit("server:error", payload);
|
|
235
|
-
};
|
|
236
|
-
io.on(
|
|
237
|
-
"connection",
|
|
238
|
-
(socket) => {
|
|
239
|
-
socket.on(
|
|
240
|
-
"host:registerSystem",
|
|
241
|
-
async (payload, callback) => {
|
|
242
|
-
const parsed = hostRegisterSystemSchema.safeParse(payload);
|
|
243
|
-
if (!parsed.success) {
|
|
244
|
-
callback({
|
|
245
|
-
ok: false,
|
|
246
|
-
message: parsed.error.message,
|
|
247
|
-
code: ErrorCode.INVALID_PAYLOAD
|
|
248
|
-
});
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
const { roomId, apiKey } = parsed.data;
|
|
252
|
-
const verification = await authService.verifyApiKey(apiKey);
|
|
253
|
-
if (!verification.isVerified) {
|
|
254
|
-
console.warn(
|
|
255
|
-
`[server] Unauthorized host registration attempt for room ${roomId}`
|
|
256
|
-
);
|
|
257
|
-
callback({
|
|
258
|
-
ok: false,
|
|
259
|
-
message: verification.error,
|
|
260
|
-
code: ErrorCode.INVALID_API_KEY
|
|
261
|
-
});
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
let session = roomManager.getRoom(roomId);
|
|
265
|
-
if (session) {
|
|
266
|
-
session.masterHostSocketId = socket.id;
|
|
267
|
-
roomManager.setRoom(roomId, session);
|
|
268
|
-
} else {
|
|
269
|
-
console.log(`[server] Creating room ${roomId}`);
|
|
270
|
-
session = {
|
|
271
|
-
roomId,
|
|
272
|
-
masterHostSocketId: socket.id,
|
|
273
|
-
focus: "SYSTEM",
|
|
274
|
-
controllers: /* @__PURE__ */ new Map(),
|
|
275
|
-
maxPlayers: 32,
|
|
276
|
-
// Default increased to 32 to allow for observers/queue
|
|
277
|
-
gameState: "paused"
|
|
278
|
-
};
|
|
279
|
-
roomManager.setRoom(roomId, session);
|
|
280
|
-
}
|
|
281
|
-
roomManager.setHostRoom(socket.id, roomId);
|
|
282
|
-
socket.join(roomId);
|
|
283
|
-
callback({ ok: true, roomId });
|
|
284
|
-
io.to(roomId).emit("server:roomReady", { roomId });
|
|
285
|
-
}
|
|
286
|
-
);
|
|
287
|
-
socket.on(
|
|
288
|
-
"host:createRoom",
|
|
289
|
-
async (payload, callback) => {
|
|
290
|
-
const parsed = hostCreateRoomSchema.safeParse(payload);
|
|
291
|
-
if (!parsed.success) {
|
|
292
|
-
callback({
|
|
293
|
-
ok: false,
|
|
294
|
-
message: parsed.error.message,
|
|
295
|
-
code: ErrorCode.INVALID_PAYLOAD
|
|
296
|
-
});
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
const { maxPlayers, apiKey } = parsed.data;
|
|
300
|
-
if (apiKey) {
|
|
301
|
-
const verification = await authService.verifyApiKey(apiKey);
|
|
302
|
-
if (!verification.isVerified) {
|
|
303
|
-
callback({
|
|
304
|
-
ok: false,
|
|
305
|
-
message: verification.error,
|
|
306
|
-
code: ErrorCode.INVALID_API_KEY
|
|
307
|
-
});
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
const existingRoomId = roomManager.getRoomByHostId(socket.id);
|
|
312
|
-
if (existingRoomId) {
|
|
313
|
-
const existingSession = roomManager.getRoom(existingRoomId);
|
|
314
|
-
if (existingSession && existingSession.masterHostSocketId === socket.id) {
|
|
315
|
-
console.log(
|
|
316
|
-
`[server] Host ${socket.id} already has room ${existingRoomId}, returning existing.`
|
|
317
|
-
);
|
|
318
|
-
callback({ ok: true, roomId: existingRoomId });
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
let roomId;
|
|
323
|
-
let attempts = 0;
|
|
324
|
-
do {
|
|
325
|
-
roomId = generateRoomCode();
|
|
326
|
-
attempts++;
|
|
327
|
-
if (attempts > 10) {
|
|
328
|
-
callback({
|
|
329
|
-
ok: false,
|
|
330
|
-
message: "Failed to generate unique room ID",
|
|
331
|
-
code: ErrorCode.CONNECTION_FAILED
|
|
332
|
-
});
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
} while (roomManager.getRoom(roomId));
|
|
336
|
-
const session = {
|
|
337
|
-
roomId,
|
|
338
|
-
masterHostSocketId: socket.id,
|
|
339
|
-
focus: "SYSTEM",
|
|
340
|
-
controllers: /* @__PURE__ */ new Map(),
|
|
341
|
-
maxPlayers: maxPlayers ?? 8,
|
|
342
|
-
gameState: "paused"
|
|
343
|
-
};
|
|
344
|
-
roomManager.setRoom(roomId, session);
|
|
345
|
-
roomManager.setHostRoom(socket.id, roomId);
|
|
346
|
-
socket.join(roomId);
|
|
347
|
-
console.log(`[server] Created room ${roomId} for host ${socket.id}`);
|
|
348
|
-
callback({ ok: true, roomId });
|
|
349
|
-
io.to(roomId).emit("server:roomReady", { roomId });
|
|
350
|
-
}
|
|
351
|
-
);
|
|
352
|
-
socket.on(
|
|
353
|
-
"host:reconnect",
|
|
354
|
-
async (payload, callback) => {
|
|
355
|
-
const parsed = hostReconnectSchema.safeParse(payload);
|
|
356
|
-
if (!parsed.success) {
|
|
357
|
-
callback({
|
|
358
|
-
ok: false,
|
|
359
|
-
message: parsed.error.message,
|
|
360
|
-
code: ErrorCode.INVALID_PAYLOAD
|
|
361
|
-
});
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
const { roomId, apiKey } = parsed.data;
|
|
365
|
-
if (apiKey) {
|
|
366
|
-
const verification = await authService.verifyApiKey(apiKey);
|
|
367
|
-
if (!verification.isVerified) {
|
|
368
|
-
callback({
|
|
369
|
-
ok: false,
|
|
370
|
-
message: verification.error,
|
|
371
|
-
code: ErrorCode.INVALID_API_KEY
|
|
372
|
-
});
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
const session = roomManager.getRoom(roomId);
|
|
377
|
-
if (!session) {
|
|
378
|
-
callback({
|
|
379
|
-
ok: false,
|
|
380
|
-
message: "Room not found",
|
|
381
|
-
code: ErrorCode.ROOM_NOT_FOUND
|
|
382
|
-
});
|
|
383
|
-
return;
|
|
384
|
-
}
|
|
385
|
-
const previousMasterSocket = io.sockets.sockets.get(
|
|
386
|
-
session.masterHostSocketId
|
|
387
|
-
);
|
|
388
|
-
const isPreviousHostConnected = previousMasterSocket?.connected ?? false;
|
|
389
|
-
if (!isPreviousHostConnected || session.masterHostSocketId === socket.id) {
|
|
390
|
-
session.masterHostSocketId = socket.id;
|
|
391
|
-
roomManager.setRoom(roomId, session);
|
|
392
|
-
roomManager.setHostRoom(socket.id, roomId);
|
|
393
|
-
socket.join(roomId);
|
|
394
|
-
console.log(
|
|
395
|
-
`[server] Host ${socket.id} reconnected to room ${roomId}`
|
|
396
|
-
);
|
|
397
|
-
callback({ ok: true, roomId });
|
|
398
|
-
io.to(roomId).emit("server:roomReady", { roomId });
|
|
399
|
-
} else {
|
|
400
|
-
callback({
|
|
401
|
-
ok: false,
|
|
402
|
-
message: "Room already has an active host",
|
|
403
|
-
code: ErrorCode.ALREADY_CONNECTED
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
);
|
|
408
|
-
socket.on(
|
|
409
|
-
"system:launchGame",
|
|
410
|
-
(payload, callback) => {
|
|
411
|
-
const parsed = systemLaunchGameSchema.safeParse(payload);
|
|
412
|
-
if (!parsed.success) {
|
|
413
|
-
callback({
|
|
414
|
-
ok: false,
|
|
415
|
-
message: parsed.error.message,
|
|
416
|
-
code: ErrorCode.INVALID_PAYLOAD
|
|
417
|
-
});
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
420
|
-
const { roomId, gameUrl } = parsed.data;
|
|
421
|
-
const session = roomManager.getRoom(roomId);
|
|
422
|
-
if (!session) {
|
|
423
|
-
callback({
|
|
424
|
-
ok: false,
|
|
425
|
-
message: "Room not found",
|
|
426
|
-
code: ErrorCode.ROOM_NOT_FOUND
|
|
427
|
-
});
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
|
-
if (session.masterHostSocketId !== socket.id) {
|
|
431
|
-
callback({
|
|
432
|
-
ok: false,
|
|
433
|
-
message: "Unauthorized: Not System Host",
|
|
434
|
-
code: ErrorCode.UNAUTHORIZED
|
|
435
|
-
});
|
|
436
|
-
return;
|
|
437
|
-
}
|
|
438
|
-
if (session.childHostSocketId) {
|
|
439
|
-
callback({
|
|
440
|
-
ok: false,
|
|
441
|
-
message: "Game already active",
|
|
442
|
-
code: ErrorCode.ALREADY_CONNECTED
|
|
443
|
-
});
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
if (session.joinToken && !session.childHostSocketId) {
|
|
447
|
-
callback({ ok: true, joinToken: session.joinToken });
|
|
448
|
-
return;
|
|
449
|
-
}
|
|
450
|
-
const joinToken = uuidv4();
|
|
451
|
-
session.joinToken = joinToken;
|
|
452
|
-
session.activeControllerUrl = gameUrl;
|
|
453
|
-
console.log(`[server] Launching game in room ${roomId}`);
|
|
454
|
-
io.to(roomId).emit("client:loadUi", { url: gameUrl });
|
|
455
|
-
callback({ ok: true, joinToken });
|
|
456
|
-
}
|
|
457
|
-
);
|
|
458
|
-
socket.on(
|
|
459
|
-
"host:joinAsChild",
|
|
460
|
-
(payload, callback) => {
|
|
461
|
-
const parsed = hostJoinAsChildSchema.safeParse(payload);
|
|
462
|
-
if (!parsed.success) {
|
|
463
|
-
callback({
|
|
464
|
-
ok: false,
|
|
465
|
-
message: parsed.error.message,
|
|
466
|
-
code: ErrorCode.INVALID_PAYLOAD
|
|
467
|
-
});
|
|
468
|
-
return;
|
|
469
|
-
}
|
|
470
|
-
const { roomId, joinToken } = parsed.data;
|
|
471
|
-
const session = roomManager.getRoom(roomId);
|
|
472
|
-
if (!session) {
|
|
473
|
-
callback({
|
|
474
|
-
ok: false,
|
|
475
|
-
message: "Room not found",
|
|
476
|
-
code: ErrorCode.ROOM_NOT_FOUND
|
|
477
|
-
});
|
|
478
|
-
return;
|
|
479
|
-
}
|
|
480
|
-
if (session.joinToken !== joinToken) {
|
|
481
|
-
console.warn(
|
|
482
|
-
`[server] Invalid join token for room ${roomId}. Expected ${session.joinToken}, got ${joinToken}`
|
|
483
|
-
);
|
|
484
|
-
callback({
|
|
485
|
-
ok: false,
|
|
486
|
-
message: "Invalid Join Token",
|
|
487
|
-
code: ErrorCode.INVALID_TOKEN
|
|
488
|
-
});
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
console.log(`[server] Game host joined room ${roomId}`);
|
|
492
|
-
session.childHostSocketId = socket.id;
|
|
493
|
-
session.focus = "GAME";
|
|
494
|
-
roomManager.setHostRoom(socket.id, roomId);
|
|
495
|
-
socket.join(roomId);
|
|
496
|
-
setTimeout(() => {
|
|
497
|
-
session.controllers.forEach((c) => {
|
|
498
|
-
const notice = {
|
|
499
|
-
controllerId: c.controllerId,
|
|
500
|
-
nickname: c.nickname,
|
|
501
|
-
player: c.playerProfile
|
|
502
|
-
};
|
|
503
|
-
socket.emit("server:controllerJoined", notice);
|
|
504
|
-
});
|
|
505
|
-
const statePayload = {
|
|
506
|
-
roomId,
|
|
507
|
-
state: {
|
|
508
|
-
gameState: session.gameState
|
|
509
|
-
}
|
|
510
|
-
};
|
|
511
|
-
socket.emit("server:state", statePayload);
|
|
512
|
-
}, 100);
|
|
513
|
-
callback({ ok: true, roomId });
|
|
514
|
-
}
|
|
515
|
-
);
|
|
516
|
-
socket.on("system:closeGame", (payload) => {
|
|
517
|
-
const { roomId } = payload;
|
|
518
|
-
const session = roomManager.getRoom(roomId);
|
|
519
|
-
if (!session) {
|
|
520
|
-
return;
|
|
521
|
-
}
|
|
522
|
-
if (session.masterHostSocketId !== socket.id) {
|
|
523
|
-
return;
|
|
524
|
-
}
|
|
525
|
-
console.log(`[server] Closing game in room ${roomId}`);
|
|
526
|
-
if (session.childHostSocketId) {
|
|
527
|
-
const childSocket = io.sockets.sockets.get(session.childHostSocketId);
|
|
528
|
-
if (childSocket) {
|
|
529
|
-
childSocket.disconnect(true);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
session.focus = "SYSTEM";
|
|
533
|
-
session.childHostSocketId = void 0;
|
|
534
|
-
session.joinToken = void 0;
|
|
535
|
-
session.activeControllerUrl = void 0;
|
|
536
|
-
io.to(roomId).emit("client:unloadUi");
|
|
537
|
-
if (session.masterHostSocketId) {
|
|
538
|
-
const masterSocket = io.sockets.sockets.get(session.masterHostSocketId);
|
|
539
|
-
if (masterSocket) {
|
|
540
|
-
setTimeout(() => {
|
|
541
|
-
session.controllers.forEach((c) => {
|
|
542
|
-
const notice = {
|
|
543
|
-
controllerId: c.controllerId,
|
|
544
|
-
nickname: c.nickname,
|
|
545
|
-
player: c.playerProfile
|
|
546
|
-
};
|
|
547
|
-
masterSocket.emit("server:controllerJoined", notice);
|
|
548
|
-
});
|
|
549
|
-
}, 100);
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
});
|
|
553
|
-
socket.on(
|
|
554
|
-
"host:register",
|
|
555
|
-
async (payload, callback) => {
|
|
556
|
-
const parsed = hostRegistrationSchema.safeParse(payload);
|
|
557
|
-
if (!parsed.success) {
|
|
558
|
-
callback({
|
|
559
|
-
ok: false,
|
|
560
|
-
message: parsed.error.message,
|
|
561
|
-
code: ErrorCode.INVALID_PAYLOAD
|
|
562
|
-
});
|
|
563
|
-
return;
|
|
564
|
-
}
|
|
565
|
-
const { roomId, maxPlayers } = parsed.data;
|
|
566
|
-
let session = roomManager.getRoom(roomId);
|
|
567
|
-
if (session) {
|
|
568
|
-
session.masterHostSocketId = socket.id;
|
|
569
|
-
session.focus = "SYSTEM";
|
|
570
|
-
} else {
|
|
571
|
-
console.log(`[server] Creating standalone room ${roomId}`);
|
|
572
|
-
session = {
|
|
573
|
-
roomId,
|
|
574
|
-
masterHostSocketId: socket.id,
|
|
575
|
-
focus: "SYSTEM",
|
|
576
|
-
controllers: /* @__PURE__ */ new Map(),
|
|
577
|
-
maxPlayers,
|
|
578
|
-
gameState: "paused"
|
|
579
|
-
};
|
|
580
|
-
roomManager.setRoom(roomId, session);
|
|
581
|
-
}
|
|
582
|
-
roomManager.setHostRoom(socket.id, roomId);
|
|
583
|
-
socket.join(roomId);
|
|
584
|
-
callback({ ok: true, roomId });
|
|
585
|
-
io.to(roomId).emit("server:roomReady", { roomId });
|
|
586
|
-
}
|
|
587
|
-
);
|
|
588
|
-
socket.on("controller:join", (payload, callback) => {
|
|
589
|
-
const parsed = controllerJoinSchema.safeParse(payload);
|
|
590
|
-
if (!parsed.success) {
|
|
591
|
-
callback({
|
|
592
|
-
ok: false,
|
|
593
|
-
message: parsed.error.message,
|
|
594
|
-
code: ErrorCode.INVALID_PAYLOAD
|
|
595
|
-
});
|
|
596
|
-
return;
|
|
597
|
-
}
|
|
598
|
-
const { roomId, controllerId, nickname } = parsed.data;
|
|
599
|
-
const session = roomManager.getRoom(roomId);
|
|
600
|
-
if (!session) {
|
|
601
|
-
callback({
|
|
602
|
-
ok: false,
|
|
603
|
-
message: "Room not found",
|
|
604
|
-
code: ErrorCode.ROOM_NOT_FOUND
|
|
605
|
-
});
|
|
606
|
-
emitError(socket.id, {
|
|
607
|
-
code: ErrorCode.ROOM_NOT_FOUND,
|
|
608
|
-
message: "Room not found"
|
|
609
|
-
});
|
|
610
|
-
return;
|
|
611
|
-
}
|
|
612
|
-
if (session.controllers.size >= session.maxPlayers) {
|
|
613
|
-
callback({
|
|
614
|
-
ok: false,
|
|
615
|
-
message: "Room full",
|
|
616
|
-
code: ErrorCode.ROOM_FULL
|
|
617
|
-
});
|
|
618
|
-
emitError(socket.id, {
|
|
619
|
-
code: ErrorCode.ROOM_FULL,
|
|
620
|
-
message: "Room is full"
|
|
621
|
-
});
|
|
622
|
-
return;
|
|
623
|
-
}
|
|
624
|
-
const existing = session.controllers.get(controllerId);
|
|
625
|
-
if (existing) {
|
|
626
|
-
roomManager.deleteController(existing.socketId);
|
|
627
|
-
}
|
|
628
|
-
const PLAYER_COLORS = [
|
|
629
|
-
"#38bdf8",
|
|
630
|
-
"#a78bfa",
|
|
631
|
-
"#f472b6",
|
|
632
|
-
"#34d399",
|
|
633
|
-
"#fbbf24",
|
|
634
|
-
"#60a5fa",
|
|
635
|
-
"#c084fc",
|
|
636
|
-
"#fb7185",
|
|
637
|
-
"#4ade80",
|
|
638
|
-
"#f87171",
|
|
639
|
-
"#22d3ee",
|
|
640
|
-
"#a855f7",
|
|
641
|
-
"#ec4899",
|
|
642
|
-
"#10b981",
|
|
643
|
-
"#f59e0b",
|
|
644
|
-
"#3b82f6",
|
|
645
|
-
"#8b5cf6",
|
|
646
|
-
"#ef4444",
|
|
647
|
-
"#14b8a6",
|
|
648
|
-
"#f97316"
|
|
649
|
-
];
|
|
650
|
-
const colorHex = PLAYER_COLORS[session.controllers.size % PLAYER_COLORS.length];
|
|
651
|
-
let color;
|
|
652
|
-
try {
|
|
653
|
-
color = Color(colorHex).hex();
|
|
654
|
-
} catch {
|
|
655
|
-
color = Color("#38bdf8").hex();
|
|
656
|
-
}
|
|
657
|
-
const playerProfile = {
|
|
658
|
-
id: controllerId,
|
|
659
|
-
label: nickname ?? `Player ${session.controllers.size}`,
|
|
660
|
-
color
|
|
661
|
-
};
|
|
662
|
-
const controllerSession = {
|
|
663
|
-
controllerId,
|
|
664
|
-
nickname,
|
|
665
|
-
socketId: socket.id,
|
|
666
|
-
playerProfile
|
|
667
|
-
};
|
|
668
|
-
session.controllers.set(controllerId, controllerSession);
|
|
669
|
-
roomManager.setController(socket.id, { roomId, controllerId });
|
|
670
|
-
socket.join(roomId);
|
|
671
|
-
const notice = {
|
|
672
|
-
controllerId,
|
|
673
|
-
nickname,
|
|
674
|
-
player: playerProfile
|
|
675
|
-
};
|
|
676
|
-
io.to(roomManager.getActiveHostId(session)).emit(
|
|
677
|
-
"server:controllerJoined",
|
|
678
|
-
notice
|
|
679
|
-
);
|
|
680
|
-
callback({ ok: true, controllerId, roomId });
|
|
681
|
-
const welcomePayload = {
|
|
682
|
-
controllerId,
|
|
683
|
-
roomId,
|
|
684
|
-
player: playerProfile
|
|
685
|
-
};
|
|
686
|
-
socket.emit("server:welcome", welcomePayload);
|
|
687
|
-
const statePayload = {
|
|
688
|
-
roomId,
|
|
689
|
-
state: {
|
|
690
|
-
gameState: session.gameState
|
|
691
|
-
}
|
|
692
|
-
};
|
|
693
|
-
socket.emit("server:state", statePayload);
|
|
694
|
-
if (session.activeControllerUrl) {
|
|
695
|
-
socket.emit("client:loadUi", { url: session.activeControllerUrl });
|
|
696
|
-
}
|
|
697
|
-
console.log(
|
|
698
|
-
`[server] Controller joined room ${roomId} (${session.controllers.size}/${session.maxPlayers} players)`
|
|
699
|
-
);
|
|
700
|
-
});
|
|
701
|
-
socket.on("controller:leave", (payload) => {
|
|
702
|
-
const parsed = controllerLeaveSchema.safeParse(payload);
|
|
703
|
-
if (!parsed.success) {
|
|
704
|
-
return;
|
|
705
|
-
}
|
|
706
|
-
const { roomId, controllerId } = parsed.data;
|
|
707
|
-
const session = roomManager.getRoom(roomId);
|
|
708
|
-
if (!session) {
|
|
709
|
-
return;
|
|
710
|
-
}
|
|
711
|
-
session.controllers.delete(controllerId);
|
|
712
|
-
roomManager.deleteController(socket.id);
|
|
713
|
-
const notice = { controllerId };
|
|
714
|
-
io.to(roomManager.getActiveHostId(session)).emit(
|
|
715
|
-
"server:controllerLeft",
|
|
716
|
-
notice
|
|
717
|
-
);
|
|
718
|
-
socket.leave(roomId);
|
|
719
|
-
});
|
|
720
|
-
socket.on("controller:input", (payload) => {
|
|
721
|
-
const now = Date.now();
|
|
722
|
-
const input = payload?.input;
|
|
723
|
-
const hasActiveInput = input && (input.action === true || typeof input.vector === "object" && input.vector !== null && (Math.abs(input.vector.x ?? 0) > 0.01 || Math.abs(input.vector.y ?? 0) > 0.01));
|
|
724
|
-
if (hasActiveInput && (!lastServerInputLogTime || now - lastServerInputLogTime > 1e3)) {
|
|
725
|
-
lastServerInputLogTime = now;
|
|
726
|
-
}
|
|
727
|
-
const result = controllerInputSchema.safeParse(payload);
|
|
728
|
-
if (!result.success) {
|
|
729
|
-
if (!lastServerInputFailLogTime || now - lastServerInputFailLogTime > 1e3) {
|
|
730
|
-
lastServerInputFailLogTime = now;
|
|
731
|
-
}
|
|
732
|
-
return;
|
|
733
|
-
}
|
|
734
|
-
const { roomId } = result.data;
|
|
735
|
-
const session = roomManager.getRoom(roomId);
|
|
736
|
-
if (!session) {
|
|
737
|
-
if (!lastServerInputFailLogTime || now - lastServerInputFailLogTime > 1e3) {
|
|
738
|
-
lastServerInputFailLogTime = now;
|
|
739
|
-
}
|
|
740
|
-
return;
|
|
741
|
-
}
|
|
742
|
-
const targetHostId = roomManager.getActiveHostId(session);
|
|
743
|
-
if (targetHostId) {
|
|
744
|
-
if (!lastServerInputLogTime || now - lastServerInputLogTime > 1e3) {
|
|
745
|
-
lastServerInputLogTime = now;
|
|
746
|
-
}
|
|
747
|
-
io.to(targetHostId).emit("server:input", result.data);
|
|
748
|
-
} else {
|
|
749
|
-
if (!lastServerInputFailLogTime || now - lastServerInputFailLogTime > 1e3) {
|
|
750
|
-
lastServerInputFailLogTime = now;
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
});
|
|
754
|
-
socket.on("controller:system", (payload) => {
|
|
755
|
-
const parsed = controllerSystemSchema.safeParse(payload);
|
|
756
|
-
if (!parsed.success) {
|
|
757
|
-
return;
|
|
758
|
-
}
|
|
759
|
-
const { roomId, command } = parsed.data;
|
|
760
|
-
const session = roomManager.getRoom(roomId);
|
|
761
|
-
if (!session) {
|
|
762
|
-
return;
|
|
763
|
-
}
|
|
764
|
-
if (command === "exit") {
|
|
765
|
-
console.log(`[server] Controller exit request in room ${roomId}`);
|
|
766
|
-
if (session.childHostSocketId) {
|
|
767
|
-
const childSocket = io.sockets.sockets.get(session.childHostSocketId);
|
|
768
|
-
if (childSocket) {
|
|
769
|
-
childSocket.disconnect(true);
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
session.focus = "SYSTEM";
|
|
773
|
-
session.childHostSocketId = void 0;
|
|
774
|
-
session.joinToken = void 0;
|
|
775
|
-
session.activeControllerUrl = void 0;
|
|
776
|
-
session.gameState = "paused";
|
|
777
|
-
io.to(roomId).emit("client:unloadUi");
|
|
778
|
-
if (session.masterHostSocketId) {
|
|
779
|
-
io.to(session.masterHostSocketId).emit("server:closeChild");
|
|
780
|
-
}
|
|
781
|
-
} else if (command === "toggle_pause") {
|
|
782
|
-
session.gameState = session.gameState === "playing" ? "paused" : "playing";
|
|
783
|
-
const statePayload = {
|
|
784
|
-
roomId,
|
|
785
|
-
state: {
|
|
786
|
-
gameState: session.gameState
|
|
787
|
-
}
|
|
788
|
-
};
|
|
789
|
-
io.to(roomId).emit("server:state", statePayload);
|
|
790
|
-
}
|
|
791
|
-
});
|
|
792
|
-
socket.on("host:system", (payload) => {
|
|
793
|
-
const parsed = controllerSystemSchema.safeParse(payload);
|
|
794
|
-
if (!parsed.success) {
|
|
795
|
-
return;
|
|
796
|
-
}
|
|
797
|
-
const { roomId, command } = parsed.data;
|
|
798
|
-
const session = roomManager.getRoom(roomId);
|
|
799
|
-
if (!session) {
|
|
800
|
-
return;
|
|
801
|
-
}
|
|
802
|
-
if (command === "toggle_pause") {
|
|
803
|
-
session.gameState = session.gameState === "playing" ? "paused" : "playing";
|
|
804
|
-
const statePayload = {
|
|
805
|
-
roomId,
|
|
806
|
-
state: {
|
|
807
|
-
gameState: session.gameState
|
|
808
|
-
}
|
|
809
|
-
};
|
|
810
|
-
io.to(roomId).emit("server:state", statePayload);
|
|
811
|
-
}
|
|
812
|
-
});
|
|
813
|
-
socket.on("host:state", (payload) => {
|
|
814
|
-
const result = controllerStateSchema.safeParse(payload);
|
|
815
|
-
if (!result.success) return;
|
|
816
|
-
const { roomId, state } = result.data;
|
|
817
|
-
const session = roomManager.getRoom(roomId);
|
|
818
|
-
if (session) {
|
|
819
|
-
if (state.gameState) {
|
|
820
|
-
session.gameState = state.gameState;
|
|
821
|
-
}
|
|
822
|
-
session.controllers.forEach((c) => {
|
|
823
|
-
io.to(c.socketId).emit("server:state", result.data);
|
|
824
|
-
});
|
|
825
|
-
if (session.masterHostSocketId) {
|
|
826
|
-
io.to(session.masterHostSocketId).emit("server:state", result.data);
|
|
827
|
-
}
|
|
828
|
-
if (session.childHostSocketId) {
|
|
829
|
-
io.to(session.childHostSocketId).emit("server:state", result.data);
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
});
|
|
833
|
-
socket.on("host:signal", (payload) => {
|
|
834
|
-
const roomId = roomManager.getRoomByHostId(socket.id);
|
|
835
|
-
if (!roomId) return;
|
|
836
|
-
const session = roomManager.getRoom(roomId);
|
|
837
|
-
if (!session) return;
|
|
838
|
-
if (payload.targetId) {
|
|
839
|
-
const controller = session.controllers.get(payload.targetId);
|
|
840
|
-
if (controller) {
|
|
841
|
-
io.to(controller.socketId).emit("server:signal", payload);
|
|
842
|
-
}
|
|
843
|
-
} else {
|
|
844
|
-
socket.to(roomId).emit("server:signal", payload);
|
|
845
|
-
}
|
|
846
|
-
});
|
|
847
|
-
socket.on("host:play_sound", (payload) => {
|
|
848
|
-
const { roomId, targetControllerId, soundId, volume, loop } = payload;
|
|
849
|
-
const session = roomManager.getRoom(roomId);
|
|
850
|
-
if (!session) return;
|
|
851
|
-
const message = { id: soundId, volume, loop };
|
|
852
|
-
if (targetControllerId) {
|
|
853
|
-
const controller = session.controllers.get(targetControllerId);
|
|
854
|
-
if (controller) {
|
|
855
|
-
io.to(controller.socketId).emit("server:playSound", message);
|
|
856
|
-
}
|
|
857
|
-
} else {
|
|
858
|
-
socket.to(roomId).emit("server:playSound", message);
|
|
859
|
-
}
|
|
860
|
-
});
|
|
861
|
-
socket.on("controller:play_sound", (payload) => {
|
|
862
|
-
const { roomId, soundId, volume, loop } = payload;
|
|
863
|
-
const session = roomManager.getRoom(roomId);
|
|
864
|
-
if (!session) return;
|
|
865
|
-
io.to(roomManager.getActiveHostId(session)).emit("server:playSound", {
|
|
866
|
-
id: soundId,
|
|
867
|
-
volume,
|
|
868
|
-
loop
|
|
869
|
-
});
|
|
870
|
-
});
|
|
871
|
-
socket.on("host:state_sync", (payload) => {
|
|
872
|
-
const { roomId, data } = payload;
|
|
873
|
-
const session = roomManager.getRoom(roomId);
|
|
874
|
-
if (!session) {
|
|
875
|
-
return;
|
|
876
|
-
}
|
|
877
|
-
if (session.masterHostSocketId !== socket.id && session.childHostSocketId !== socket.id) {
|
|
878
|
-
return;
|
|
879
|
-
}
|
|
880
|
-
const syncPayload = {
|
|
881
|
-
roomId,
|
|
882
|
-
data
|
|
883
|
-
};
|
|
884
|
-
io.to(roomId).emit("airjam:state_sync", syncPayload);
|
|
885
|
-
});
|
|
886
|
-
socket.on(
|
|
887
|
-
"controller:action_rpc",
|
|
888
|
-
(payload) => {
|
|
889
|
-
const { roomId, actionName, args, controllerId } = payload;
|
|
890
|
-
const session = roomManager.getRoom(roomId);
|
|
891
|
-
if (!session) return;
|
|
892
|
-
const controllerSession = session.controllers.get(controllerId);
|
|
893
|
-
if (!controllerSession) {
|
|
894
|
-
return;
|
|
895
|
-
}
|
|
896
|
-
if (controllerSession.socketId !== socket.id) {
|
|
897
|
-
socket.join(roomId);
|
|
898
|
-
}
|
|
899
|
-
const hostId = roomManager.getActiveHostId(session);
|
|
900
|
-
if (hostId) {
|
|
901
|
-
const rpcPayload = {
|
|
902
|
-
actionName,
|
|
903
|
-
args,
|
|
904
|
-
controllerId
|
|
905
|
-
};
|
|
906
|
-
io.to(hostId).emit("airjam:action_rpc", rpcPayload);
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
);
|
|
910
|
-
socket.on("disconnect", () => {
|
|
911
|
-
const roomId = roomManager.getRoomByHostId(socket.id);
|
|
912
|
-
if (roomId) {
|
|
913
|
-
const session = roomManager.getRoom(roomId);
|
|
914
|
-
if (!session) {
|
|
915
|
-
roomManager.deleteHost(socket.id);
|
|
916
|
-
return;
|
|
917
|
-
}
|
|
918
|
-
if (socket.id === session.childHostSocketId) {
|
|
919
|
-
console.log(`[server] Game host disconnected from room ${roomId}`);
|
|
920
|
-
session.childHostSocketId = void 0;
|
|
921
|
-
session.focus = "SYSTEM";
|
|
922
|
-
session.joinToken = void 0;
|
|
923
|
-
session.activeControllerUrl = void 0;
|
|
924
|
-
io.to(roomId).emit("client:unloadUi");
|
|
925
|
-
if (session.masterHostSocketId) {
|
|
926
|
-
const masterSocket = io.sockets.sockets.get(
|
|
927
|
-
session.masterHostSocketId
|
|
928
|
-
);
|
|
929
|
-
if (masterSocket) {
|
|
930
|
-
setTimeout(() => {
|
|
931
|
-
session.controllers.forEach((c) => {
|
|
932
|
-
const notice = {
|
|
933
|
-
controllerId: c.controllerId,
|
|
934
|
-
nickname: c.nickname,
|
|
935
|
-
player: c.playerProfile
|
|
936
|
-
};
|
|
937
|
-
masterSocket.emit("server:controllerJoined", notice);
|
|
938
|
-
});
|
|
939
|
-
}, 100);
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
} else if (socket.id === session.masterHostSocketId) {
|
|
943
|
-
console.log(`[server] Host disconnected from room ${roomId}`);
|
|
944
|
-
setTimeout(() => {
|
|
945
|
-
const currentSession = roomManager.getRoom(roomId);
|
|
946
|
-
if (currentSession && currentSession.masterHostSocketId === socket.id) {
|
|
947
|
-
console.log(`[server] Removing room ${roomId}`);
|
|
948
|
-
roomManager.removeRoom(roomId, io, "Host disconnected");
|
|
949
|
-
}
|
|
950
|
-
}, 3e3);
|
|
951
|
-
}
|
|
952
|
-
roomManager.deleteHost(socket.id);
|
|
953
|
-
return;
|
|
954
|
-
}
|
|
955
|
-
const controller = roomManager.getControllerInfo(socket.id);
|
|
956
|
-
if (controller) {
|
|
957
|
-
const session = roomManager.getRoom(controller.roomId);
|
|
958
|
-
if (session) {
|
|
959
|
-
session.controllers.delete(controller.controllerId);
|
|
960
|
-
const notice = {
|
|
961
|
-
controllerId: controller.controllerId
|
|
962
|
-
};
|
|
963
|
-
io.to(roomManager.getActiveHostId(session)).emit(
|
|
964
|
-
"server:controllerLeft",
|
|
965
|
-
notice
|
|
966
|
-
);
|
|
967
|
-
}
|
|
968
|
-
roomManager.deleteController(socket.id);
|
|
969
|
-
}
|
|
970
|
-
});
|
|
971
|
-
}
|
|
972
|
-
);
|
|
973
|
-
httpServer.listen(PORT, () => {
|
|
974
|
-
console.log(`[air-jam] server listening on http://localhost:${PORT}`);
|
|
975
|
-
});
|
|
976
|
-
//# sourceMappingURL=chunk-T6BT7WE5.js.map
|