|
|
@ -37,59 +37,70 @@ io.on('connection', (socket) => {
|
|
|
|
io.to(playerId).emit("join during game", networkPerson, person, indices, start, map.get(room).tab, nodes)
|
|
|
|
io.to(playerId).emit("join during game", networkPerson, person, indices, start, map.get(room).tab, nodes)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
socket.on("lobby joined", (room, player) =>{
|
|
|
|
socket.on("join back game", (player) => {
|
|
|
|
if (lastSocketJoined != player.id){
|
|
|
|
for (const k of map.keys()){
|
|
|
|
lastSocketJoined=player.id
|
|
|
|
const tab = map.get(k)
|
|
|
|
const game = map.get(room)
|
|
|
|
for (let i = 0; i<tab.tab.length; i++){
|
|
|
|
if (game !== undefined){
|
|
|
|
if (tab.tab[i].pseudo === player.pseudo && tab.tab[i].type !== "User"){
|
|
|
|
if (game.tab.length == 6 && !game.started){
|
|
|
|
if (tab.started){
|
|
|
|
io.to(socket.id).emit("room full")
|
|
|
|
io.to(socket.id).emit("join back game", k)
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (game.started){
|
|
|
|
|
|
|
|
for(const u of game.tab){
|
|
|
|
|
|
|
|
if(u.type !== "User" && u.pseudo===player.pseudo){
|
|
|
|
|
|
|
|
u.type = "User"
|
|
|
|
|
|
|
|
u.id=socket.id
|
|
|
|
|
|
|
|
io.to(game.tab[game.actualPlayer].id).emit("give network", socket.id)
|
|
|
|
|
|
|
|
io.to(room).emit("player joined ingame", game.tab)
|
|
|
|
|
|
|
|
socket.join(room)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
io.to(socket.id).emit("game already started")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
socket.on("lobby joined", (room, player) =>{
|
|
|
|
|
|
|
|
|
|
|
|
if (game == undefined){
|
|
|
|
const game = map.get(room)
|
|
|
|
map.set(room, {tab: [{type: player.type, id: socket.id, pseudo: player.pseudo, profilePicture: player.profilePicture}], started: false, actualPlayer: 0, lastWorks: false})
|
|
|
|
if (game !== undefined){
|
|
|
|
socket.join(room)
|
|
|
|
if (game.tab.length == 6 && !game.started){
|
|
|
|
|
|
|
|
io.to(socket.id).emit("room full")
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if (game.started){
|
|
|
|
const tab = game.tab
|
|
|
|
for(const u of game.tab){
|
|
|
|
for(let i = 0; i<tab.length; i++){
|
|
|
|
if(u.type !== "User" && u.pseudo===player.pseudo){
|
|
|
|
if (tab[i].id === socket.id && player.type==="User"){
|
|
|
|
u.type = "User"
|
|
|
|
tab.splice(i, 1)
|
|
|
|
u.id=socket.id
|
|
|
|
|
|
|
|
io.to(game.tab[game.actualPlayer].id).emit("give network", socket.id)
|
|
|
|
|
|
|
|
io.to(room).emit("player joined ingame", game.tab)
|
|
|
|
|
|
|
|
socket.join(room)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
io.to(socket.id).emit("game already started")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (player.type!=="User"){
|
|
|
|
|
|
|
|
tab.push({type: player.type, id: player.id, pseudo: player.pseudo, profilePicture: player.profilePicture})
|
|
|
|
if (game == undefined){
|
|
|
|
}
|
|
|
|
map.set(room, {tab: [{type: player.type, id: socket.id, pseudo: player.pseudo, profilePicture: player.profilePicture}], started: false, actualPlayer: 0, lastWorks: false})
|
|
|
|
else{
|
|
|
|
socket.join(room)
|
|
|
|
tab.push({type: player.type, id: socket.id, pseudo: player.pseudo, profilePicture: player.profilePicture})
|
|
|
|
}
|
|
|
|
socket.join(room)
|
|
|
|
else{
|
|
|
|
|
|
|
|
const tab = game.tab
|
|
|
|
|
|
|
|
for(let i = 0; i<tab.length; i++){
|
|
|
|
|
|
|
|
if (tab[i].id === socket.id && player.type==="User"){
|
|
|
|
|
|
|
|
tab.splice(i, 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
io.to(room).emit("new player", map.get(room))
|
|
|
|
if (player.type!=="User"){
|
|
|
|
const playerArray = Array.from(map.entries()).map(([key, value]) => ({ key, value }))
|
|
|
|
tab.push({type: player.type, id: player.id, pseudo: player.pseudo, profilePicture: player.profilePicture})
|
|
|
|
const playerJson = JSON.stringify(playerArray);
|
|
|
|
}
|
|
|
|
io.emit("request lobbies", playerJson)
|
|
|
|
else{
|
|
|
|
|
|
|
|
tab.push({type: player.type, id: socket.id, pseudo: player.pseudo, profilePicture: player.profilePicture})
|
|
|
|
|
|
|
|
socket.join(room)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
io.to(room).emit("new player", map.get(room))
|
|
|
|
|
|
|
|
const playerArray = Array.from(map.entries()).map(([key, value]) => ({ key, value }))
|
|
|
|
|
|
|
|
const playerJson = JSON.stringify(playerArray);
|
|
|
|
|
|
|
|
io.emit("request lobbies", playerJson)
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
socket.on("request lobbies", () => {
|
|
|
|
socket.on("request lobbies", () => {
|
|
|
|