Update server.js
Browse files
server.js
CHANGED
|
@@ -2,16 +2,30 @@ const express = require('express');
|
|
| 2 |
const http = require('http');
|
| 3 |
const { Server } = require('socket.io');
|
| 4 |
const path = require('path');
|
|
|
|
| 5 |
|
| 6 |
const app = express();
|
| 7 |
const server = http.createServer(app);
|
|
|
|
|
|
|
| 8 |
const io = new Server(server, {
|
| 9 |
cors: {
|
| 10 |
origin: "*",
|
| 11 |
methods: ["GET", "POST"]
|
| 12 |
},
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
});
|
| 16 |
|
| 17 |
app.use(express.static(path.join(__dirname, 'public')));
|
|
@@ -19,17 +33,21 @@ app.use(express.static(path.join(__dirname, 'public')));
|
|
| 19 |
// Game constants
|
| 20 |
const TILE_SIZE = 10;
|
| 21 |
const GRID_WIDTH = 13;
|
| 22 |
-
const
|
| 23 |
-
const
|
| 24 |
|
| 25 |
// Game state
|
| 26 |
const players = new Map();
|
| 27 |
const gameState = {
|
| 28 |
lanes: new Map(),
|
| 29 |
-
furthestLaneIndex: 14
|
|
|
|
| 30 |
};
|
| 31 |
|
| 32 |
-
//
|
|
|
|
|
|
|
|
|
|
| 33 |
function generateLaneData(index, prevLane) {
|
| 34 |
let type = 'grass';
|
| 35 |
let runLength = 1;
|
|
@@ -66,21 +84,23 @@ function generateLaneData(index, prevLane) {
|
|
| 66 |
for (let i = 0; i < treeCount; i++) {
|
| 67 |
let gx = Math.floor(Math.random() * GRID_WIDTH) - Math.floor(GRID_WIDTH / 2);
|
| 68 |
if (index < 5 && gx === 0) continue;
|
| 69 |
-
staticObstacles.
|
|
|
|
|
|
|
| 70 |
}
|
| 71 |
}
|
| 72 |
|
| 73 |
const lane = {
|
| 74 |
-
index,
|
| 75 |
-
type,
|
| 76 |
-
runLength,
|
| 77 |
-
staticObstacles,
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
obstacles: [],
|
| 82 |
timer: 0,
|
| 83 |
-
interval: Math.random() * 100 + 150
|
|
|
|
| 84 |
};
|
| 85 |
|
| 86 |
// Pre-populate obstacles
|
|
@@ -91,15 +111,14 @@ function generateLaneData(index, prevLane) {
|
|
| 91 |
if (Math.abs(randX) < 15) randX += (randX > 0 ? 20 : -20);
|
| 92 |
|
| 93 |
const obsWidth = type === 'water'
|
| 94 |
-
? (Math.random() > 0.5 ?
|
| 95 |
: 12;
|
| 96 |
|
| 97 |
-
lane.
|
| 98 |
-
id:
|
| 99 |
-
x: randX,
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
speed: lane.speed * lane.direction
|
| 103 |
});
|
| 104 |
}
|
| 105 |
}
|
|
@@ -107,7 +126,6 @@ function generateLaneData(index, prevLane) {
|
|
| 107 |
return lane;
|
| 108 |
}
|
| 109 |
|
| 110 |
-
// Initialize lanes
|
| 111 |
function initializeLanes() {
|
| 112 |
gameState.lanes.clear();
|
| 113 |
for (let i = -4; i < 15; i++) {
|
|
@@ -119,447 +137,470 @@ function initializeLanes() {
|
|
| 119 |
|
| 120 |
initializeLanes();
|
| 121 |
|
| 122 |
-
//
|
| 123 |
-
function updateObstacles() {
|
| 124 |
-
gameState.lanes.forEach((lane) => {
|
| 125 |
-
if (lane.type === 'road' || lane.type === 'water') {
|
| 126 |
-
lane.timer++;
|
| 127 |
-
|
| 128 |
-
if (lane.timer > lane.interval) {
|
| 129 |
-
const startX = -lane.direction * (GRID_WIDTH * TILE_SIZE / 2 + 60);
|
| 130 |
-
const obsWidth = lane.type === 'water'
|
| 131 |
-
? (Math.random() > 0.5 ? 4 : 6) * TILE_SIZE
|
| 132 |
-
: 12;
|
| 133 |
-
|
| 134 |
-
lane.obstacles.push({
|
| 135 |
-
id: `${lane.index}-${Date.now()}`,
|
| 136 |
-
x: startX,
|
| 137 |
-
isLog: lane.type === 'water',
|
| 138 |
-
width: obsWidth,
|
| 139 |
-
speed: lane.speed * lane.direction
|
| 140 |
-
});
|
| 141 |
-
|
| 142 |
-
lane.timer = 0;
|
| 143 |
-
lane.interval = Math.random() * 100 + 200;
|
| 144 |
-
}
|
| 145 |
-
|
| 146 |
-
// Move obstacles
|
| 147 |
-
for (let i = lane.obstacles.length - 1; i >= 0; i--) {
|
| 148 |
-
const obs = lane.obstacles[i];
|
| 149 |
-
obs.x += obs.speed;
|
| 150 |
-
if (Math.abs(obs.x) > 400) {
|
| 151 |
-
lane.obstacles.splice(i, 1);
|
| 152 |
-
}
|
| 153 |
-
}
|
| 154 |
-
}
|
| 155 |
-
});
|
| 156 |
-
}
|
| 157 |
-
|
| 158 |
-
// Check collision at position
|
| 159 |
function checkCollisionAtPosition(gridX, gridZ, worldX = null) {
|
| 160 |
const lane = gameState.lanes.get(gridZ);
|
| 161 |
-
if (!lane) return {
|
| 162 |
|
| 163 |
-
const
|
| 164 |
|
| 165 |
-
/
|
| 166 |
-
|
| 167 |
-
return { collision: true, type: 'bounds' };
|
| 168 |
}
|
| 169 |
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
return { collision: true, type: 'tree', blocked: true };
|
| 174 |
}
|
| 175 |
-
return {
|
| 176 |
}
|
| 177 |
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
const
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
const playerRight = playerX + 3;
|
| 185 |
-
|
| 186 |
-
if (playerRight > obsLeft && playerLeft < obsRight) {
|
| 187 |
-
return { collision: true, type: 'car' };
|
| 188 |
}
|
| 189 |
}
|
| 190 |
-
return {
|
| 191 |
}
|
| 192 |
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
const safeDist = (obs.width / 2) + 4;
|
| 198 |
-
|
| 199 |
-
if (distX < safeDist) {
|
| 200 |
-
return { collision: false, onLog: true, log: obs };
|
| 201 |
}
|
| 202 |
}
|
| 203 |
-
return {
|
| 204 |
}
|
| 205 |
|
| 206 |
-
return {
|
| 207 |
}
|
| 208 |
|
| 209 |
-
// Validate move
|
| 210 |
function validateMove(player, dx, dz) {
|
| 211 |
-
if (!player.alive) return { valid: false };
|
| 212 |
-
if (dz < 0) return { valid: false
|
| 213 |
|
| 214 |
-
const targetX = player.
|
| 215 |
-
const targetZ = player.
|
| 216 |
|
| 217 |
if (Math.abs(targetX) > Math.floor(GRID_WIDTH / 2)) {
|
| 218 |
-
return { valid: false };
|
| 219 |
}
|
| 220 |
|
| 221 |
-
// Check for tree blocking
|
| 222 |
const lane = gameState.lanes.get(targetZ);
|
| 223 |
-
if (lane && lane.
|
| 224 |
-
|
| 225 |
-
return { valid: false };
|
| 226 |
-
}
|
| 227 |
}
|
| 228 |
|
| 229 |
-
return { valid: true, targetX, targetZ };
|
| 230 |
}
|
| 231 |
|
| 232 |
-
//
|
| 233 |
function getLeaderboard() {
|
| 234 |
-
|
| 235 |
.filter(p => p.alive || p.score > 0)
|
| 236 |
.sort((a, b) => b.score - a.score)
|
| 237 |
-
.slice(0, 3)
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
}));
|
| 244 |
}
|
| 245 |
|
| 246 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
io.on('connection', (socket) => {
|
| 248 |
-
console.log(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
gridX: 0,
|
| 257 |
-
gridZ: 0,
|
| 258 |
-
worldX: 0,
|
| 259 |
-
worldZ: 0,
|
| 260 |
-
score: 0,
|
| 261 |
-
alive: true,
|
| 262 |
-
isHopping: false,
|
| 263 |
-
hopStartTime: 0,
|
| 264 |
-
hopDuration: 120,
|
| 265 |
-
hopStartPos: { x: 0, z: 0 },
|
| 266 |
-
hopTargetPos: { x: 0, z: 0 },
|
| 267 |
-
rotation: 0,
|
| 268 |
-
attachedLog: null,
|
| 269 |
-
lastMoveTime: 0
|
| 270 |
-
};
|
| 271 |
-
|
| 272 |
-
players.set(socket.id, player);
|
| 273 |
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
|
| 288 |
-
|
| 289 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
});
|
| 291 |
|
| 292 |
-
socket.on('
|
| 293 |
const player = players.get(socket.id);
|
| 294 |
if (!player) return;
|
| 295 |
|
| 296 |
const now = Date.now();
|
| 297 |
|
| 298 |
-
// Rate
|
| 299 |
-
if (now - player.
|
| 300 |
-
socket.emit('
|
| 301 |
return;
|
| 302 |
}
|
| 303 |
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
socket.emit('moveRejected', { reason: 'hopping' });
|
| 307 |
return;
|
| 308 |
}
|
| 309 |
|
| 310 |
if (!player.alive) {
|
| 311 |
-
socket.emit('
|
| 312 |
-
return;
|
| 313 |
-
}
|
| 314 |
-
|
| 315 |
-
const { dx, dz, seq } = data;
|
| 316 |
-
const validation = validateMove(player, dx, dz);
|
| 317 |
-
|
| 318 |
-
if (!validation.valid) {
|
| 319 |
-
socket.emit('moveRejected', { seq, reason: 'invalid' });
|
| 320 |
return;
|
| 321 |
}
|
| 322 |
|
| 323 |
-
|
| 324 |
-
const
|
| 325 |
-
const collisionCheck = checkCollisionAtPosition(
|
| 326 |
-
validation.targetX,
|
| 327 |
-
validation.targetZ,
|
| 328 |
-
targetWorldX
|
| 329 |
-
);
|
| 330 |
|
| 331 |
-
if (
|
| 332 |
-
socket.emit('
|
| 333 |
return;
|
| 334 |
}
|
| 335 |
|
| 336 |
-
//
|
| 337 |
-
player.
|
| 338 |
-
player.
|
| 339 |
-
player.
|
| 340 |
-
player.
|
| 341 |
-
player.
|
| 342 |
-
player.
|
| 343 |
-
player.
|
| 344 |
-
player.
|
| 345 |
-
player.
|
| 346 |
-
player.
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
else if (
|
| 352 |
-
else if (dz ===
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
|
|
|
| 358 |
}
|
| 359 |
|
| 360 |
-
// Generate new lanes
|
| 361 |
const spawnZ = player.score + 12;
|
| 362 |
while (spawnZ > gameState.furthestLaneIndex) {
|
| 363 |
gameState.furthestLaneIndex++;
|
| 364 |
const prevLane = gameState.lanes.get(gameState.furthestLaneIndex - 1);
|
| 365 |
const newLane = generateLaneData(gameState.furthestLaneIndex, prevLane);
|
| 366 |
gameState.lanes.set(gameState.furthestLaneIndex, newLane);
|
| 367 |
-
io.emit('
|
| 368 |
}
|
| 369 |
|
| 370 |
-
// Confirm
|
| 371 |
-
socket.emit('
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
score: player.score,
|
| 378 |
-
serverTime: now
|
| 379 |
});
|
| 380 |
|
| 381 |
-
// Broadcast
|
| 382 |
-
socket.broadcast.emit('
|
| 383 |
id: player.id,
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
|
|
|
| 391 |
});
|
| 392 |
});
|
| 393 |
|
| 394 |
-
socket.on('
|
| 395 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 396 |
});
|
| 397 |
|
| 398 |
-
socket.on('
|
| 399 |
const player = players.get(socket.id);
|
| 400 |
if (!player) return;
|
| 401 |
|
| 402 |
-
player.
|
| 403 |
-
player.
|
| 404 |
-
player.
|
| 405 |
-
player.
|
| 406 |
player.score = 0;
|
| 407 |
player.alive = true;
|
| 408 |
-
player.
|
| 409 |
-
player.
|
| 410 |
-
player.
|
| 411 |
|
| 412 |
-
socket.emit('
|
| 413 |
-
socket.broadcast.emit('
|
| 414 |
-
io.emit('
|
| 415 |
});
|
| 416 |
|
| 417 |
-
socket.on('
|
| 418 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 419 |
players.delete(socket.id);
|
| 420 |
-
|
| 421 |
-
io.emit('
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 422 |
});
|
| 423 |
});
|
| 424 |
|
| 425 |
-
//
|
| 426 |
-
|
| 427 |
-
updateObstacles();
|
| 428 |
|
| 429 |
-
|
| 430 |
const now = Date.now();
|
| 431 |
-
|
| 432 |
-
|
| 433 |
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 438 |
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
);
|
| 445 |
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
|
|
|
| 455 |
}
|
| 456 |
}
|
| 457 |
}
|
|
|
|
| 458 |
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 483 |
player.alive = false;
|
| 484 |
-
|
| 485 |
-
io.emit('
|
|
|
|
|
|
|
| 486 |
}
|
| 487 |
}
|
| 488 |
}
|
| 489 |
}
|
| 490 |
|
| 491 |
-
//
|
| 492 |
-
if (player.
|
| 493 |
-
const
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
if (lane && lane.type === 'road') {
|
| 500 |
-
for (const obs of lane.obstacles) {
|
| 501 |
-
const obsLeft = obs.x - obs.width / 2 - 2;
|
| 502 |
-
const obsRight = obs.x + obs.width / 2 + 2;
|
| 503 |
|
| 504 |
-
if (
|
| 505 |
player.alive = false;
|
| 506 |
-
player.
|
| 507 |
-
io.emit('
|
| 508 |
-
|
| 509 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 510 |
}
|
| 511 |
}
|
| 512 |
}
|
| 513 |
}
|
| 514 |
});
|
| 515 |
|
| 516 |
-
// Broadcast
|
| 517 |
-
const playersData =
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
gridZ: p.gridZ,
|
| 522 |
-
worldX: p.worldX,
|
| 523 |
-
worldZ: p.worldZ,
|
| 524 |
-
rotation: p.rotation,
|
| 525 |
-
score: p.score,
|
| 526 |
-
alive: p.alive,
|
| 527 |
-
isHopping: p.isHopping,
|
| 528 |
-
hopStartTime: p.hopStartTime,
|
| 529 |
-
hopStartPos: p.hopStartPos,
|
| 530 |
-
hopTargetPos: p.hopTargetPos
|
| 531 |
-
}));
|
| 532 |
-
|
| 533 |
-
const obstaclesData = {};
|
| 534 |
gameState.lanes.forEach((lane, key) => {
|
| 535 |
-
if (lane.
|
| 536 |
-
|
|
|
|
|
|
|
|
|
|
| 537 |
}
|
| 538 |
});
|
| 539 |
|
| 540 |
-
io.emit('
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
});
|
|
|
|
| 545 |
|
| 546 |
-
|
| 547 |
|
| 548 |
-
// Cleanup old lanes
|
| 549 |
setInterval(() => {
|
| 550 |
let minZ = Infinity;
|
| 551 |
players.forEach(p => {
|
| 552 |
-
if (p.
|
| 553 |
});
|
| 554 |
-
|
| 555 |
if (minZ === Infinity) minZ = 0;
|
| 556 |
|
| 557 |
gameState.lanes.forEach((lane, key) => {
|
| 558 |
-
if (key < minZ -
|
| 559 |
gameState.lanes.delete(key);
|
| 560 |
}
|
| 561 |
});
|
| 562 |
-
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 563 |
|
| 564 |
const PORT = process.env.PORT || 7860;
|
| 565 |
server.listen(PORT, '0.0.0.0', () => {
|
|
|
|
| 2 |
const http = require('http');
|
| 3 |
const { Server } = require('socket.io');
|
| 4 |
const path = require('path');
|
| 5 |
+
const zlib = require('zlib');
|
| 6 |
|
| 7 |
const app = express();
|
| 8 |
const server = http.createServer(app);
|
| 9 |
+
|
| 10 |
+
// Professional Socket.IO configuration
|
| 11 |
const io = new Server(server, {
|
| 12 |
cors: {
|
| 13 |
origin: "*",
|
| 14 |
methods: ["GET", "POST"]
|
| 15 |
},
|
| 16 |
+
// Optimized for slow connections
|
| 17 |
+
pingTimeout: 120000,
|
| 18 |
+
pingInterval: 10000,
|
| 19 |
+
upgradeTimeout: 30000,
|
| 20 |
+
transports: ['websocket', 'polling'],
|
| 21 |
+
allowUpgrades: true,
|
| 22 |
+
perMessageDeflate: {
|
| 23 |
+
threshold: 256,
|
| 24 |
+
zlibDeflateOptions: { level: 6 },
|
| 25 |
+
zlibInflateOptions: { chunkSize: 10 * 1024 }
|
| 26 |
+
},
|
| 27 |
+
httpCompression: true,
|
| 28 |
+
maxHttpBufferSize: 1e6
|
| 29 |
});
|
| 30 |
|
| 31 |
app.use(express.static(path.join(__dirname, 'public')));
|
|
|
|
| 33 |
// Game constants
|
| 34 |
const TILE_SIZE = 10;
|
| 35 |
const GRID_WIDTH = 13;
|
| 36 |
+
const BASE_TICK_RATE = 15; // Lower for bandwidth
|
| 37 |
+
const HOP_DURATION = 120;
|
| 38 |
|
| 39 |
// Game state
|
| 40 |
const players = new Map();
|
| 41 |
const gameState = {
|
| 42 |
lanes: new Map(),
|
| 43 |
+
furthestLaneIndex: 14,
|
| 44 |
+
version: 0 // State version for delta sync
|
| 45 |
};
|
| 46 |
|
| 47 |
+
// Connection stats
|
| 48 |
+
const connectionStats = new Map();
|
| 49 |
+
|
| 50 |
+
// ============= LANE GENERATION =============
|
| 51 |
function generateLaneData(index, prevLane) {
|
| 52 |
let type = 'grass';
|
| 53 |
let runLength = 1;
|
|
|
|
| 84 |
for (let i = 0; i < treeCount; i++) {
|
| 85 |
let gx = Math.floor(Math.random() * GRID_WIDTH) - Math.floor(GRID_WIDTH / 2);
|
| 86 |
if (index < 5 && gx === 0) continue;
|
| 87 |
+
if (!staticObstacles.includes(gx)) {
|
| 88 |
+
staticObstacles.push(gx);
|
| 89 |
+
}
|
| 90 |
}
|
| 91 |
}
|
| 92 |
|
| 93 |
const lane = {
|
| 94 |
+
i: index, // Short keys for bandwidth
|
| 95 |
+
t: type.charAt(0), // 'g', 'r', 'w'
|
| 96 |
+
rl: runLength,
|
| 97 |
+
so: staticObstacles,
|
| 98 |
+
sp: Math.round((Math.random() * 0.04 + 0.02) * TILE_SIZE * 100) / 100,
|
| 99 |
+
d: Math.random() > 0.5 ? 1 : -1,
|
| 100 |
+
obs: [],
|
|
|
|
| 101 |
timer: 0,
|
| 102 |
+
interval: Math.random() * 100 + 150,
|
| 103 |
+
obsId: 0
|
| 104 |
};
|
| 105 |
|
| 106 |
// Pre-populate obstacles
|
|
|
|
| 111 |
if (Math.abs(randX) < 15) randX += (randX > 0 ? 20 : -20);
|
| 112 |
|
| 113 |
const obsWidth = type === 'water'
|
| 114 |
+
? (Math.random() > 0.5 ? 40 : 60)
|
| 115 |
: 12;
|
| 116 |
|
| 117 |
+
lane.obs.push({
|
| 118 |
+
id: lane.obsId++,
|
| 119 |
+
x: Math.round(randX * 10) / 10,
|
| 120 |
+
l: type === 'water' ? 1 : 0, // isLog
|
| 121 |
+
w: obsWidth
|
|
|
|
| 122 |
});
|
| 123 |
}
|
| 124 |
}
|
|
|
|
| 126 |
return lane;
|
| 127 |
}
|
| 128 |
|
|
|
|
| 129 |
function initializeLanes() {
|
| 130 |
gameState.lanes.clear();
|
| 131 |
for (let i = -4; i < 15; i++) {
|
|
|
|
| 137 |
|
| 138 |
initializeLanes();
|
| 139 |
|
| 140 |
+
// ============= COLLISION DETECTION =============
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
function checkCollisionAtPosition(gridX, gridZ, worldX = null) {
|
| 142 |
const lane = gameState.lanes.get(gridZ);
|
| 143 |
+
if (!lane) return { hit: false };
|
| 144 |
|
| 145 |
+
const px = worldX !== null ? worldX : gridX * TILE_SIZE;
|
| 146 |
|
| 147 |
+
if (Math.abs(px) > (GRID_WIDTH * TILE_SIZE / 2 + 10)) {
|
| 148 |
+
return { hit: true, type: 'bounds' };
|
|
|
|
| 149 |
}
|
| 150 |
|
| 151 |
+
if (lane.t === 'g') {
|
| 152 |
+
if (lane.so.includes(gridX)) {
|
| 153 |
+
return { hit: true, type: 'tree', blocked: true };
|
|
|
|
| 154 |
}
|
| 155 |
+
return { hit: false };
|
| 156 |
}
|
| 157 |
|
| 158 |
+
if (lane.t === 'r') {
|
| 159 |
+
for (const obs of lane.obs) {
|
| 160 |
+
const left = obs.x - obs.w / 2;
|
| 161 |
+
const right = obs.x + obs.w / 2;
|
| 162 |
+
if (px + 3 > left && px - 3 < right) {
|
| 163 |
+
return { hit: true, type: 'car' };
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
}
|
| 165 |
}
|
| 166 |
+
return { hit: false };
|
| 167 |
}
|
| 168 |
|
| 169 |
+
if (lane.t === 'w') {
|
| 170 |
+
for (const obs of lane.obs) {
|
| 171 |
+
if (Math.abs(px - obs.x) < (obs.w / 2) + 4) {
|
| 172 |
+
return { hit: false, onLog: true, logId: obs.id };
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
}
|
| 174 |
}
|
| 175 |
+
return { hit: true, type: 'water' };
|
| 176 |
}
|
| 177 |
|
| 178 |
+
return { hit: false };
|
| 179 |
}
|
| 180 |
|
|
|
|
| 181 |
function validateMove(player, dx, dz) {
|
| 182 |
+
if (!player.alive) return { valid: false, reason: 'dead' };
|
| 183 |
+
if (dz < 0) return { valid: false, reason: 'backward' };
|
| 184 |
|
| 185 |
+
const targetX = player.gx + dx;
|
| 186 |
+
const targetZ = player.gz + dz;
|
| 187 |
|
| 188 |
if (Math.abs(targetX) > Math.floor(GRID_WIDTH / 2)) {
|
| 189 |
+
return { valid: false, reason: 'bounds' };
|
| 190 |
}
|
| 191 |
|
|
|
|
| 192 |
const lane = gameState.lanes.get(targetZ);
|
| 193 |
+
if (lane && lane.t === 'g' && lane.so.includes(targetX)) {
|
| 194 |
+
return { valid: false, reason: 'tree' };
|
|
|
|
|
|
|
| 195 |
}
|
| 196 |
|
| 197 |
+
return { valid: true, tx: targetX, tz: targetZ };
|
| 198 |
}
|
| 199 |
|
| 200 |
+
// ============= LEADERBOARD =============
|
| 201 |
function getLeaderboard() {
|
| 202 |
+
return Array.from(players.values())
|
| 203 |
.filter(p => p.alive || p.score > 0)
|
| 204 |
.sort((a, b) => b.score - a.score)
|
| 205 |
+
.slice(0, 3)
|
| 206 |
+
.map((p, i) => ({
|
| 207 |
+
r: i + 1,
|
| 208 |
+
n: p.name,
|
| 209 |
+
s: p.score
|
| 210 |
+
}));
|
|
|
|
| 211 |
}
|
| 212 |
|
| 213 |
+
// Compact player data for network
|
| 214 |
+
function compactPlayer(p) {
|
| 215 |
+
return {
|
| 216 |
+
id: p.id,
|
| 217 |
+
n: p.name,
|
| 218 |
+
gx: p.gx,
|
| 219 |
+
gz: p.gz,
|
| 220 |
+
wx: Math.round(p.wx * 10) / 10,
|
| 221 |
+
wz: Math.round(p.wz * 10) / 10,
|
| 222 |
+
r: Math.round(p.rot * 100) / 100,
|
| 223 |
+
s: p.score,
|
| 224 |
+
a: p.alive ? 1 : 0,
|
| 225 |
+
h: p.hopping ? 1 : 0,
|
| 226 |
+
ht: p.hopTime
|
| 227 |
+
};
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
// Compact lane data
|
| 231 |
+
function compactLane(lane) {
|
| 232 |
+
return {
|
| 233 |
+
i: lane.i,
|
| 234 |
+
t: lane.t,
|
| 235 |
+
rl: lane.rl,
|
| 236 |
+
so: lane.so,
|
| 237 |
+
sp: lane.sp,
|
| 238 |
+
d: lane.d,
|
| 239 |
+
obs: lane.obs.map(o => ({
|
| 240 |
+
id: o.id,
|
| 241 |
+
x: Math.round(o.x * 10) / 10,
|
| 242 |
+
l: o.l,
|
| 243 |
+
w: o.w
|
| 244 |
+
}))
|
| 245 |
+
};
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
// ============= SOCKET HANDLING =============
|
| 249 |
io.on('connection', (socket) => {
|
| 250 |
+
console.log(`[${new Date().toISOString()}] Connection: ${socket.id}`);
|
| 251 |
+
|
| 252 |
+
// Initialize connection stats
|
| 253 |
+
connectionStats.set(socket.id, {
|
| 254 |
+
connected: Date.now(),
|
| 255 |
+
lastPing: Date.now(),
|
| 256 |
+
ping: 0,
|
| 257 |
+
quality: 'good'
|
| 258 |
+
});
|
| 259 |
|
| 260 |
+
// Send immediate acknowledgment
|
| 261 |
+
socket.emit('ack', {
|
| 262 |
+
id: socket.id,
|
| 263 |
+
t: Date.now(),
|
| 264 |
+
v: gameState.version
|
| 265 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
|
| 267 |
+
socket.on('join', (data) => {
|
| 268 |
+
try {
|
| 269 |
+
const name = (data.name || 'Anon').substring(0, 12).replace(/[<>\"\'&]/g, '');
|
| 270 |
+
|
| 271 |
+
const player = {
|
| 272 |
+
id: socket.id,
|
| 273 |
+
name: name,
|
| 274 |
+
gx: 0, gz: 0,
|
| 275 |
+
wx: 0, wz: 0,
|
| 276 |
+
score: 0,
|
| 277 |
+
alive: true,
|
| 278 |
+
hopping: false,
|
| 279 |
+
hopTime: 0,
|
| 280 |
+
hopStart: { x: 0, z: 0 },
|
| 281 |
+
hopTarget: { x: 0, z: 0 },
|
| 282 |
+
rot: 0,
|
| 283 |
+
logId: null,
|
| 284 |
+
lastMove: 0,
|
| 285 |
+
moveSeq: 0
|
| 286 |
+
};
|
| 287 |
+
|
| 288 |
+
players.set(socket.id, player);
|
| 289 |
|
| 290 |
+
// Send minimal initial state
|
| 291 |
+
const lanesArr = [];
|
| 292 |
+
gameState.lanes.forEach((lane) => {
|
| 293 |
+
lanesArr.push(compactLane(lane));
|
| 294 |
+
});
|
| 295 |
+
|
| 296 |
+
const otherPlayers = [];
|
| 297 |
+
players.forEach((p, id) => {
|
| 298 |
+
if (id !== socket.id) {
|
| 299 |
+
otherPlayers.push(compactPlayer(p));
|
| 300 |
+
}
|
| 301 |
+
});
|
| 302 |
|
| 303 |
+
socket.emit('init', {
|
| 304 |
+
p: compactPlayer(player),
|
| 305 |
+
ps: otherPlayers,
|
| 306 |
+
ls: lanesArr,
|
| 307 |
+
t: Date.now(),
|
| 308 |
+
lb: getLeaderboard()
|
| 309 |
+
});
|
| 310 |
+
|
| 311 |
+
// Notify others
|
| 312 |
+
socket.broadcast.emit('pj', compactPlayer(player));
|
| 313 |
+
|
| 314 |
+
console.log(`[${new Date().toISOString()}] Joined: ${name} (${socket.id})`);
|
| 315 |
+
} catch (err) {
|
| 316 |
+
console.error('Join error:', err);
|
| 317 |
+
socket.emit('err', { m: 'Join failed' });
|
| 318 |
+
}
|
| 319 |
});
|
| 320 |
|
| 321 |
+
socket.on('m', (data) => { // Move
|
| 322 |
const player = players.get(socket.id);
|
| 323 |
if (!player) return;
|
| 324 |
|
| 325 |
const now = Date.now();
|
| 326 |
|
| 327 |
+
// Rate limit: 70ms minimum
|
| 328 |
+
if (now - player.lastMove < 70) {
|
| 329 |
+
socket.emit('mr', { s: data.s, r: 'fast' });
|
| 330 |
return;
|
| 331 |
}
|
| 332 |
|
| 333 |
+
if (player.hopping) {
|
| 334 |
+
socket.emit('mr', { s: data.s, r: 'hop' });
|
|
|
|
| 335 |
return;
|
| 336 |
}
|
| 337 |
|
| 338 |
if (!player.alive) {
|
| 339 |
+
socket.emit('mr', { s: data.s, r: 'dead' });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 340 |
return;
|
| 341 |
}
|
| 342 |
|
| 343 |
+
const { dx, dz, s } = data;
|
| 344 |
+
const v = validateMove(player, dx, dz);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
|
| 346 |
+
if (!v.valid) {
|
| 347 |
+
socket.emit('mr', { s, r: v.reason });
|
| 348 |
return;
|
| 349 |
}
|
| 350 |
|
| 351 |
+
// Execute move
|
| 352 |
+
player.lastMove = now;
|
| 353 |
+
player.hopping = true;
|
| 354 |
+
player.hopTime = now;
|
| 355 |
+
player.hopStart = { x: player.wx, z: player.wz };
|
| 356 |
+
player.hopTarget = { x: v.tx * TILE_SIZE, z: v.tz * TILE_SIZE };
|
| 357 |
+
player.gx = v.tx;
|
| 358 |
+
player.gz = v.tz;
|
| 359 |
+
player.wx = v.tx * TILE_SIZE;
|
| 360 |
+
player.wz = v.tz * TILE_SIZE;
|
| 361 |
+
player.logId = null;
|
| 362 |
+
player.moveSeq = s;
|
| 363 |
+
|
| 364 |
+
// Rotation
|
| 365 |
+
if (dx === 1) player.rot = -Math.PI / 2;
|
| 366 |
+
else if (dx === -1) player.rot = Math.PI / 2;
|
| 367 |
+
else if (dz === 1) player.rot = 0;
|
| 368 |
+
else if (dz === -1) player.rot = Math.PI;
|
| 369 |
+
|
| 370 |
+
// Score
|
| 371 |
+
if (v.tz > player.score) {
|
| 372 |
+
player.score = v.tz;
|
| 373 |
+
io.emit('lb', getLeaderboard());
|
| 374 |
}
|
| 375 |
|
| 376 |
+
// Generate new lanes
|
| 377 |
const spawnZ = player.score + 12;
|
| 378 |
while (spawnZ > gameState.furthestLaneIndex) {
|
| 379 |
gameState.furthestLaneIndex++;
|
| 380 |
const prevLane = gameState.lanes.get(gameState.furthestLaneIndex - 1);
|
| 381 |
const newLane = generateLaneData(gameState.furthestLaneIndex, prevLane);
|
| 382 |
gameState.lanes.set(gameState.furthestLaneIndex, newLane);
|
| 383 |
+
io.emit('nl', compactLane(newLane));
|
| 384 |
}
|
| 385 |
|
| 386 |
+
// Confirm
|
| 387 |
+
socket.emit('mc', {
|
| 388 |
+
s,
|
| 389 |
+
gx: player.gx,
|
| 390 |
+
gz: player.gz,
|
| 391 |
+
sc: player.score,
|
| 392 |
+
t: now
|
|
|
|
|
|
|
| 393 |
});
|
| 394 |
|
| 395 |
+
// Broadcast
|
| 396 |
+
socket.broadcast.emit('pm', {
|
| 397 |
id: player.id,
|
| 398 |
+
gx: player.gx,
|
| 399 |
+
gz: player.gz,
|
| 400 |
+
wx: player.wx,
|
| 401 |
+
wz: player.wz,
|
| 402 |
+
r: player.rot,
|
| 403 |
+
t: now,
|
| 404 |
+
hs: player.hopStart,
|
| 405 |
+
ht: player.hopTarget
|
| 406 |
});
|
| 407 |
});
|
| 408 |
|
| 409 |
+
socket.on('p', (ct) => { // Ping
|
| 410 |
+
const stats = connectionStats.get(socket.id);
|
| 411 |
+
if (stats) {
|
| 412 |
+
stats.lastPing = Date.now();
|
| 413 |
+
}
|
| 414 |
+
socket.emit('po', { c: ct, s: Date.now() });
|
| 415 |
});
|
| 416 |
|
| 417 |
+
socket.on('rs', () => { // Respawn
|
| 418 |
const player = players.get(socket.id);
|
| 419 |
if (!player) return;
|
| 420 |
|
| 421 |
+
player.gx = 0;
|
| 422 |
+
player.gz = 0;
|
| 423 |
+
player.wx = 0;
|
| 424 |
+
player.wz = 0;
|
| 425 |
player.score = 0;
|
| 426 |
player.alive = true;
|
| 427 |
+
player.hopping = false;
|
| 428 |
+
player.logId = null;
|
| 429 |
+
player.rot = 0;
|
| 430 |
|
| 431 |
+
socket.emit('rsd', compactPlayer(player));
|
| 432 |
+
socket.broadcast.emit('prs', { id: player.id });
|
| 433 |
+
io.emit('lb', getLeaderboard());
|
| 434 |
});
|
| 435 |
|
| 436 |
+
socket.on('hb', () => { // Heartbeat
|
| 437 |
+
socket.emit('hba');
|
| 438 |
+
});
|
| 439 |
+
|
| 440 |
+
socket.on('disconnect', (reason) => {
|
| 441 |
+
console.log(`[${new Date().toISOString()}] Disconnect: ${socket.id} (${reason})`);
|
| 442 |
players.delete(socket.id);
|
| 443 |
+
connectionStats.delete(socket.id);
|
| 444 |
+
io.emit('pl', socket.id);
|
| 445 |
+
io.emit('lb', getLeaderboard());
|
| 446 |
+
});
|
| 447 |
+
|
| 448 |
+
socket.on('error', (err) => {
|
| 449 |
+
console.error(`Socket error ${socket.id}:`, err);
|
| 450 |
});
|
| 451 |
});
|
| 452 |
|
| 453 |
+
// ============= GAME LOOP =============
|
| 454 |
+
let lastTick = Date.now();
|
|
|
|
| 455 |
|
| 456 |
+
function gameTick() {
|
| 457 |
const now = Date.now();
|
| 458 |
+
const dt = now - lastTick;
|
| 459 |
+
lastTick = now;
|
| 460 |
|
| 461 |
+
// Update obstacles
|
| 462 |
+
gameState.lanes.forEach((lane) => {
|
| 463 |
+
if (lane.t === 'r' || lane.t === 'w') {
|
| 464 |
+
lane.timer += dt;
|
| 465 |
+
|
| 466 |
+
if (lane.timer > lane.interval) {
|
| 467 |
+
const startX = -lane.d * (GRID_WIDTH * TILE_SIZE / 2 + 60);
|
| 468 |
+
const obsWidth = lane.t === 'w' ? (Math.random() > 0.5 ? 40 : 60) : 12;
|
| 469 |
|
| 470 |
+
lane.obs.push({
|
| 471 |
+
id: lane.obsId++,
|
| 472 |
+
x: startX,
|
| 473 |
+
l: lane.t === 'w' ? 1 : 0,
|
| 474 |
+
w: obsWidth
|
| 475 |
+
});
|
| 476 |
|
| 477 |
+
lane.timer = 0;
|
| 478 |
+
lane.interval = Math.random() * 100 + 200;
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
// Move obstacles
|
| 482 |
+
for (let i = lane.obs.length - 1; i >= 0; i--) {
|
| 483 |
+
const obs = lane.obs[i];
|
| 484 |
+
obs.x += lane.sp * lane.d * (dt / 16.67);
|
| 485 |
+
if (Math.abs(obs.x) > 400) {
|
| 486 |
+
lane.obs.splice(i, 1);
|
| 487 |
}
|
| 488 |
}
|
| 489 |
}
|
| 490 |
+
});
|
| 491 |
|
| 492 |
+
// Update players
|
| 493 |
+
players.forEach((player) => {
|
| 494 |
+
if (!player.alive) return;
|
| 495 |
+
|
| 496 |
+
// Complete hop
|
| 497 |
+
if (player.hopping && now - player.hopTime >= HOP_DURATION) {
|
| 498 |
+
player.hopping = false;
|
| 499 |
+
|
| 500 |
+
const col = checkCollisionAtPosition(player.gx, player.gz, player.wx);
|
| 501 |
+
|
| 502 |
+
if (col.hit) {
|
| 503 |
+
player.alive = false;
|
| 504 |
+
io.emit('pd', { id: player.id, type: col.type });
|
| 505 |
+
io.emit('lb', getLeaderboard());
|
| 506 |
+
} else if (col.onLog) {
|
| 507 |
+
player.logId = col.logId;
|
| 508 |
+
}
|
| 509 |
+
}
|
| 510 |
+
|
| 511 |
+
// Check collision during hop
|
| 512 |
+
if (player.hopping) {
|
| 513 |
+
const progress = (now - player.hopTime) / HOP_DURATION;
|
| 514 |
+
const cx = player.hopStart.x + (player.hopTarget.x - player.hopStart.x) * progress;
|
| 515 |
+
const cz = player.hopStart.z + (player.hopTarget.z - player.hopStart.z) * progress;
|
| 516 |
+
const cgz = Math.round(cz / TILE_SIZE);
|
| 517 |
+
|
| 518 |
+
const lane = gameState.lanes.get(cgz);
|
| 519 |
+
if (lane && lane.t === 'r') {
|
| 520 |
+
for (const obs of lane.obs) {
|
| 521 |
+
if (Math.abs(cx - obs.x) < (obs.w / 2 + 3)) {
|
| 522 |
player.alive = false;
|
| 523 |
+
player.hopping = false;
|
| 524 |
+
io.emit('pd', { id: player.id, type: 'car' });
|
| 525 |
+
io.emit('lb', getLeaderboard());
|
| 526 |
+
break;
|
| 527 |
}
|
| 528 |
}
|
| 529 |
}
|
| 530 |
}
|
| 531 |
|
| 532 |
+
// Log riding
|
| 533 |
+
if (!player.hopping && player.logId !== null) {
|
| 534 |
+
const lane = gameState.lanes.get(player.gz);
|
| 535 |
+
if (lane) {
|
| 536 |
+
const log = lane.obs.find(o => o.id === player.logId);
|
| 537 |
+
if (log) {
|
| 538 |
+
player.wx = log.x;
|
| 539 |
+
player.gx = Math.round(player.wx / TILE_SIZE);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 540 |
|
| 541 |
+
if (Math.abs(player.wx) > (GRID_WIDTH * TILE_SIZE / 2 + 10)) {
|
| 542 |
player.alive = false;
|
| 543 |
+
io.emit('pd', { id: player.id, type: 'bounds' });
|
| 544 |
+
io.emit('lb', getLeaderboard());
|
| 545 |
+
}
|
| 546 |
+
} else {
|
| 547 |
+
player.logId = null;
|
| 548 |
+
if (lane.t === 'w') {
|
| 549 |
+
player.alive = false;
|
| 550 |
+
io.emit('pd', { id: player.id, type: 'water' });
|
| 551 |
+
io.emit('lb', getLeaderboard());
|
| 552 |
}
|
| 553 |
}
|
| 554 |
}
|
| 555 |
}
|
| 556 |
});
|
| 557 |
|
| 558 |
+
// Broadcast state (minimal)
|
| 559 |
+
const playersData = [];
|
| 560 |
+
players.forEach(p => playersData.push(compactPlayer(p)));
|
| 561 |
+
|
| 562 |
+
const obsData = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 563 |
gameState.lanes.forEach((lane, key) => {
|
| 564 |
+
if (lane.t !== 'g' && lane.obs.length > 0) {
|
| 565 |
+
obsData[key] = lane.obs.map(o => ({
|
| 566 |
+
id: o.id,
|
| 567 |
+
x: Math.round(o.x * 10) / 10
|
| 568 |
+
}));
|
| 569 |
}
|
| 570 |
});
|
| 571 |
|
| 572 |
+
io.emit('gs', {
|
| 573 |
+
ps: playersData,
|
| 574 |
+
obs: obsData,
|
| 575 |
+
t: now
|
| 576 |
});
|
| 577 |
+
}
|
| 578 |
|
| 579 |
+
setInterval(gameTick, 1000 / BASE_TICK_RATE);
|
| 580 |
|
| 581 |
+
// Cleanup old lanes
|
| 582 |
setInterval(() => {
|
| 583 |
let minZ = Infinity;
|
| 584 |
players.forEach(p => {
|
| 585 |
+
if (p.gz < minZ) minZ = p.gz;
|
| 586 |
});
|
|
|
|
| 587 |
if (minZ === Infinity) minZ = 0;
|
| 588 |
|
| 589 |
gameState.lanes.forEach((lane, key) => {
|
| 590 |
+
if (key < minZ - 15) {
|
| 591 |
gameState.lanes.delete(key);
|
| 592 |
}
|
| 593 |
});
|
| 594 |
+
}, 10000);
|
| 595 |
+
|
| 596 |
+
// Health check endpoint
|
| 597 |
+
app.get('/health', (req, res) => {
|
| 598 |
+
res.json({
|
| 599 |
+
status: 'ok',
|
| 600 |
+
players: players.size,
|
| 601 |
+
uptime: process.uptime()
|
| 602 |
+
});
|
| 603 |
+
});
|
| 604 |
|
| 605 |
const PORT = process.env.PORT || 7860;
|
| 606 |
server.listen(PORT, '0.0.0.0', () => {
|