Обновить ship.js
This commit is contained in:
parent
1e74491310
commit
c9435d6d66
95
ship.js
95
ship.js
@ -1,47 +1,48 @@
|
|||||||
// const {sequelize, DataTypes} = require('./db/sql_connection');
|
// project
|
||||||
require('dotenv').config({ path: require('node:path').resolve(process.cwd(), '.env') });
|
// const {sequelize, DataTypes} = require('./db/sql_connection');
|
||||||
const APP_BASE_PATH = process.env.APP_BASE_PATH || "";
|
require('dotenv').config({ path: require('node:path').resolve(process.cwd(), '.env') });
|
||||||
const express = require("express");
|
const APP_BASE_PATH = process.env.APP_BASE_PATH || "";
|
||||||
const app = express(); //
|
const express = require("express");
|
||||||
// const fs = require("fs");
|
const app = express(); //
|
||||||
const http = require("http").createServer(app);
|
// const fs = require("fs");
|
||||||
const io = require("socket.io")(http);
|
const http = require("http").createServer(app);
|
||||||
// const path = require("path");
|
const io = require("socket.io")(http);
|
||||||
|
// const path = require("path");
|
||||||
var id = [];
|
|
||||||
var obj_collection = {};
|
var id = [];
|
||||||
|
var obj_collection = {};
|
||||||
http.listen(process.env.PORT, process.env.HOST, function () {
|
|
||||||
console.log("game server is started");
|
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");
|
io.on("connection", function (socket) {
|
||||||
socket.on("mouseclick", (coords) => {
|
console.log("user " + socket.id + " is connected");
|
||||||
console.log("coords");
|
socket.on("mouseclick", (coords) => {
|
||||||
console.log(coords);
|
console.log("coords");
|
||||||
socket.broadcast.emit("coords", coords);
|
console.log(coords);
|
||||||
id[socket.id] = coords.id;
|
socket.broadcast.emit("coords", coords);
|
||||||
obj_collection[coords.id] = coords;
|
id[socket.id] = coords.id;
|
||||||
})
|
obj_collection[coords.id] = coords;
|
||||||
socket.on("disconnect", () => {
|
})
|
||||||
console.log("user " + socket.id + " is disconnected");
|
socket.on("disconnect", () => {
|
||||||
socket.broadcast.emit("remove", id[socket.id]);
|
console.log("user " + socket.id + " is disconnected");
|
||||||
|
socket.broadcast.emit("remove", id[socket.id]);
|
||||||
delete obj_collection[id[socket.id]];
|
|
||||||
delete id[socket.id];
|
delete obj_collection[id[socket.id]];
|
||||||
})
|
delete id[socket.id];
|
||||||
socket.on("loaded", () => {
|
})
|
||||||
console.log("loaded");
|
socket.on("loaded", () => {
|
||||||
io.emit("send_objects", obj_collection);
|
console.log("loaded");
|
||||||
})
|
io.emit("send_objects", obj_collection);
|
||||||
})
|
})
|
||||||
|
})
|
||||||
app.set("view engine", "ejs");
|
|
||||||
app.use(express.static("public"));
|
app.set("view engine", "ejs");
|
||||||
app.use(express.json({extended: false}));
|
app.use(express.static("public"));
|
||||||
app.get("/", (req, res) => {
|
app.use(express.json({extended: false}));
|
||||||
res.render("game", {
|
app.get("/", (req, res) => {
|
||||||
base_path: APP_BASE_PATH,
|
res.render("game", {
|
||||||
});
|
base_path: APP_BASE_PATH,
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user