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, + }); +});