added LoginPage

This commit is contained in:
Wenszel
2023-11-23 21:20:44 +01:00
parent c999bfca39
commit ffaaf0b6f3
10 changed files with 228 additions and 29 deletions
+20
View File
@@ -15,5 +15,25 @@ module.exports = (io, socket) => {
io.to(socket.id).emit('room:data', JSON.stringify(room));
}
};
const getRooms = async () => {
let rooms = await RoomModel.find({});
const response = [];
rooms.forEach(room => {
if (!room.isStarted && !room.isFull()) {
response.push({
_id: room._id,
name: room.name,
players: room.players,
isStarted: room.isStarted,
});
}
});
io.to(socket.id).emit('room:rooms', JSON.stringify(response));
};
socket.on('room:data', getData);
socket.on('room:rooms', getRooms);
};
+2
View File
@@ -6,6 +6,7 @@ const PawnSchema = require('./pawn');
const PlayerSchema = require('./player');
const RoomSchema = new Schema({
name: String,
createDate: { type: Date, default: Date.now },
started: { type: Boolean, default: false },
full: { type: Boolean, default: false },
@@ -66,6 +67,7 @@ RoomSchema.methods.startGame = function () {
this.nextMoveTime = Date.now() + 15000;
this.players.forEach(player => (player.ready = true));
this.players[0].nowMoving = true;
this.timeoutID = setTimeout(makeRandomMove, 15000, this);
};
RoomSchema.methods.isFull = function () {
+1 -1
View File
@@ -91,4 +91,4 @@ if (process.env.NODE_ENV === 'production') {
});
}
module.exports = { server };
module.exports = { server };