pull/74/head
Thomas Chazot 2 years ago
parent 703a07db97
commit 5087f20c5c

@ -7,7 +7,7 @@ const app = express();
const server = http.createServer(app);
const io = socketIO(server, {
cors: {
origin: ["http://localhost:3000", "http://localhost:3001"], // Remplacez par l'URL de votre application React
origin: ["http://172.20.10.4:3000", "http://localhost:3000"], // Remplacez par l'URL de votre application React
methods: ["GET", "POST"],
credentials: true
}
@ -80,7 +80,7 @@ io.on('connection', (socket) => {
for (let i = 0; i<tab.length; i++){
if (tab[i].id === socket.id){
tab.splice(i, 1)
io.to(k).emit("new player", tab)
io.to(k).emit("player left", tab, socket.id)
}
}
}

@ -482,8 +482,11 @@ let cptTour: number = 0
}
}
else{
socket.emit("ask player", params.nodes[0], players[touchedPlayer].id, players.find((p) => p.id === socket.id, actualPlayerIndex))
socket.emit("put correct background", socket.id)
if (touchedPlayer > 0){
console.log(touchedPlayer)
socket.emit("ask player", params.nodes[0], players[touchedPlayer].id, players.find((p) => p.id === socket.id, actualPlayerIndex))
socket.emit("put correct background", socket.id)
}
touchedPlayer=-1
}
}

@ -27,6 +27,7 @@ import EasyBot from '../model/EasyBot';
import Bot from '../model/Bot';
let gameStarted = false
function Lobby() {
const theme=useTheme();
@ -79,6 +80,7 @@ function Lobby() {
setPersonNetworkData(network)
setIndicesData(choosenIndices)
first = true
gameStarted = true
navigate('/game?solo=false');
});
@ -90,6 +92,27 @@ function Lobby() {
setPlayersData(tmpTab)
})
socket.on("player left", (tab, socketId) => {
if (gameStarted){
const i = players.findIndex((p) => p.id == socketId)
if (i != undefined){
let player = players[i]
player = new EasyBot("125", "BOT125")
if (player instanceof Bot){
player.indice = indices[i]
}
}
}
else{
const tmpTab: Player[] = []
for (const p of tab){
tmpTab.push(JSONParser.JSONToPlayer(p))
}
setPlayersData(tmpTab)
}
const index = players
})
const [codeShowed, setCodeShowed] = useState(true);

@ -1,6 +1,6 @@
import { io } from "socket.io-client";
const socket = io("http://localhost:3002");
const socket = io("http://172.20.10.4:3002");
export {socket}
Loading…
Cancel
Save