From c9435d6d669a0d0587f8d72db40ae94004f9dfcc Mon Sep 17 00:00:00 2001 From: svoboda200786 Date: Fri, 15 Aug 2025 16:08:06 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20ship.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ship.js | 95 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/ship.js b/ship.js index 0873dfb..be3b94d 100644 --- a/ship.js +++ b/ship.js @@ -1,47 +1,48 @@ -// const {sequelize, DataTypes} = require('./db/sql_connection'); -require('dotenv').config({ path: require('node:path').resolve(process.cwd(), '.env') }); -const APP_BASE_PATH = process.env.APP_BASE_PATH || ""; -const express = require("express"); -const app = express(); // -// const fs = require("fs"); -const http = require("http").createServer(app); -const io = require("socket.io")(http); -// const path = require("path"); - -var id = []; -var obj_collection = {}; - -http.listen(process.env.PORT, process.env.HOST, function () { - console.log("game server is started"); -}) - -io.on("connection", function (socket) { - console.log("user " + socket.id + " is connected"); - socket.on("mouseclick", (coords) => { - console.log("coords"); - console.log(coords); - socket.broadcast.emit("coords", coords); - id[socket.id] = coords.id; - obj_collection[coords.id] = coords; - }) - socket.on("disconnect", () => { - console.log("user " + socket.id + " is disconnected"); - socket.broadcast.emit("remove", id[socket.id]); - - delete obj_collection[id[socket.id]]; - delete id[socket.id]; - }) - socket.on("loaded", () => { - console.log("loaded"); - io.emit("send_objects", obj_collection); - }) -}) - -app.set("view engine", "ejs"); -app.use(express.static("public")); -app.use(express.json({extended: false})); -app.get("/", (req, res) => { - res.render("game", { - base_path: APP_BASE_PATH, - }); -}); +// project +// const {sequelize, DataTypes} = require('./db/sql_connection'); +require('dotenv').config({ path: require('node:path').resolve(process.cwd(), '.env') }); +const APP_BASE_PATH = process.env.APP_BASE_PATH || ""; +const express = require("express"); +const app = express(); // +// const fs = require("fs"); +const http = require("http").createServer(app); +const io = require("socket.io")(http); +// const path = require("path"); + +var id = []; +var obj_collection = {}; + +http.listen(process.env.PORT, process.env.HOST, function () { + console.log("game server is started"); +}) + +io.on("connection", function (socket) { + console.log("user " + socket.id + " is connected"); + socket.on("mouseclick", (coords) => { + console.log("coords"); + console.log(coords); + socket.broadcast.emit("coords", coords); + id[socket.id] = coords.id; + obj_collection[coords.id] = coords; + }) + socket.on("disconnect", () => { + console.log("user " + socket.id + " is disconnected"); + socket.broadcast.emit("remove", id[socket.id]); + + delete obj_collection[id[socket.id]]; + delete id[socket.id]; + }) + socket.on("loaded", () => { + console.log("loaded"); + io.emit("send_objects", obj_collection); + }) +}) + +app.set("view engine", "ejs"); +app.use(express.static("public")); +app.use(express.json({extended: false})); +app.get("/", (req, res) => { + res.render("game", { + base_path: APP_BASE_PATH, + }); +});