40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const express_1 = __importDefault(require("express"));
|
|
const Game_1 = require("./Game");
|
|
const ws_1 = require("ws");
|
|
const app = express_1.default();
|
|
const WebSocketServer = ws_1.Server;
|
|
const port = process.env.PORT || 3000;
|
|
app.use(express_1.default.static('../distClient'));
|
|
const server = app.listen(port, () => {
|
|
console.log(`Tron.io running on port ${port}`);
|
|
});
|
|
const wss = new WebSocketServer({ server });
|
|
const game = new Game_1.Game();
|
|
wss.on('connection', function (connection) {
|
|
connection.on('close', () => game.logout(connection));
|
|
connection.on('message', (message) => {
|
|
try {
|
|
const data = JSON.parse(message);
|
|
switch (data.type) {
|
|
case 'login':
|
|
game.login(connection, data.name);
|
|
break;
|
|
case 'respawn':
|
|
game.respawn(connection);
|
|
break;
|
|
case 'update':
|
|
game.update(connection, data.player);
|
|
break;
|
|
}
|
|
}
|
|
catch (e) {
|
|
return;
|
|
}
|
|
});
|
|
});
|
|
//# sourceMappingURL=app.js.map
|