- Add real-time multiplayer game server with Colyseus - Implement unique player naming system with auto-increment - Create lobby system with automatic matchmaking - Build 10-minute competitive clicking game rooms (max 2 players) - Add admin dashboard for game management (pause/resume/restart/kick) - Implement Vue 3 client with professional UI - Add WebSocket communication with state synchronization - Include TypeScript throughout with proper typing - Create REST API for admin operations - Add reconnection support and error handling
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { Server } from "colyseus";
|
|
import { createServer } from "http";
|
|
import express from "express";
|
|
import cors from "cors";
|
|
import { monitor } from "@colyseus/monitor";
|
|
|
|
import { GameRoom } from "./rooms/GameRoom";
|
|
import { LobbyRoom } from "./rooms/LobbyRoom";
|
|
import { adminRouter } from "./adminApi";
|
|
|
|
const port = Number(process.env.PORT) || 3000;
|
|
const app = express();
|
|
|
|
app.use(cors());
|
|
app.use(express.json());
|
|
|
|
const server = createServer(app);
|
|
const gameServer = new Server({
|
|
server,
|
|
});
|
|
|
|
gameServer.define("lobby", LobbyRoom)
|
|
.filterBy(["maxClients"]);
|
|
|
|
gameServer.define("game", GameRoom)
|
|
.filterBy(["maxClients"])
|
|
.enableRealtimeListing();
|
|
|
|
app.use("/api", adminRouter);
|
|
|
|
app.use("/colyseus", monitor());
|
|
|
|
app.get("/health", (req, res) => {
|
|
res.json({ status: "healthy", uptime: process.uptime() });
|
|
});
|
|
|
|
gameServer.listen(port);
|
|
|
|
console.log(`🎮 Snatch Game Server is running on port ${port}`);
|
|
console.log(`📊 Monitor: http://localhost:${port}/colyseus`);
|
|
console.log(`🌐 WebSocket: ws://localhost:${port}`);
|
|
console.log(`🔧 Admin API: http://localhost:${port}/api`); |