-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
68 lines (61 loc) · 1.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var http = require("http");
var engines = require("consolidate");
var BP = require("body-parser");
var express = require("express");
var app = express();
var room,
count = 0;
var roomz = [];
var idRoom = [];
app.use(BP.urlencoded({ extended: true }));
app.engine("html", engines.mustache);
app.use(express.static("public"));
var server = http.createServer(app);
server.listen(process.env.PORT || 8080, function () {
console.log("Server Is Up");
});
app.get("/play", function (req, res) {
res.render("game.html");
});
app.get("/", function (req, res) {
res.render("roolz.html");
});
var io = require("socket.io").listen(server);
io.on("connection", (socket) => {
console.log("Cunectid");
socket.on("createRoom", (rom) => {
room = rom;
if (!roomz.hasOwnProperty(room)) {
roomz[room] = 1;
socket.join(room);
idRoom[socket.id] = room;
socket.emit("goUhed", "g");
} else if (roomz[room] < 2) {
socket.join(room);
idRoom[socket.id] = room;
socket.emit("goUhed", "g");
roomz[room] = roomz[room] + 1;
} else socket.emit("eruu", "e");
console.log(roomz);
});
socket.on("newPlayer", (naym) => {
// console.log(naym + " joind " + room);
});
socket.on("ges", (data) => {
// io.in(room).emit('ges', ges)
socket.broadcast.to(data.rom).emit("ges", data.guess);
});
socket.on("sub", (data) => {
socket.broadcast.to(data.rom).emit("sub", data.gesser);
});
socket.on("curect", (q) => {
socket.broadcast.to(q).emit("curect", "j");
});
socket.on("code", (s) => {
socket.broadcast.to(s).emit("code", "g");
});
socket.on("disconnect", (p) => {
roomz[idRoom[socket.id]] = roomz[idRoom[socket.id]] - 1;
console.log(roomz);
});
});