Script pour le serveur + fichier de config pour les adresses + timer

pull/83/head
Thomas Chazot 1 year ago
parent f55db09007
commit c679066d9e

@ -41,13 +41,14 @@ let firstLap = true
let cptHistory = 0 let cptHistory = 0
let lastNodes: NodePerson[] = [] let lastNodes: NodePerson[] = []
let firstEnigme = true let firstEnigme = true
let endgame= false
const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, isDaily, addToHistory, showLast, setNetwork}) => { const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, isDaily, addToHistory, showLast, setNetwork}) => {
let cptTour: number = 0 let cptTour: number = 0
//* Gestion du temps : //* Gestion du temps :
const initMtn = new Date().getSeconds() let initMtn = 0
const {user} = useAuth() const {user} = useAuth()
const { indices, indice, person, personNetwork, setNodeIdData, players, askedPersons, setActualPlayerIndexData, room, actualPlayerIndex, turnPlayerIndex, setTurnPlayerIndexData, setWinnerData, dailyEnigme, setNbCoupData, settempsData} = useGame(); const { indices, indice, person, personNetwork, setNodeIdData, players, askedPersons, setActualPlayerIndexData, room, actualPlayerIndex, turnPlayerIndex, setTurnPlayerIndexData, setWinnerData, dailyEnigme, setNbCoupData, settempsData} = useGame();
@ -56,6 +57,24 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
const navigate = useNavigate(); const navigate = useNavigate();
const [lastIndex, setLastIndex] = useState(-1) const [lastIndex, setLastIndex] = useState(-1)
const [elapsedTime, setElapsedTime] = useState(0);
useEffect(() => {
// Démarrez le timer au montage du composant
const intervalId = setInterval(() => {
setElapsedTime((prevElapsedTime) => prevElapsedTime + 0.5);
settempsData(elapsedTime)
// Vérifiez si la durée est écoulée, puis arrêtez le timer
if (endgame) {
clearInterval(intervalId);
}
}, 500);
// Nettoyez l'intervalle lorsque le composant est démonté
return () => clearInterval(intervalId);
}, [elapsedTime, endgame]);
useEffect(() =>{ useEffect(() =>{
touchedPlayer=playerTouched touchedPlayer=playerTouched
@ -201,7 +220,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
if (first){ if (first){
first = false first = false
endgame= false
if (!solo){ if (!solo){
for(let i = 0; i<indices.length; i++){ for(let i = 0; i<indices.length; i++){
mapIndexPersons.set(i, []) mapIndexPersons.set(i, [])
@ -267,24 +286,15 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
dailyEnigme.forEach((pairs, index) => { dailyEnigme.forEach((pairs, index) => {
pairs.forEach((pair) => { pairs.forEach((pair) => {
const i = indices.findIndex((indice) => pair.first.getId() === indice.getId()) const i = indices.findIndex((indice) => pair.first.getId() === indice.getId())
console.log(index)
const node = networkData.nodes.get().find((n) => index == n.id) const node = networkData.nodes.get().find((n) => index == n.id)
if (node != undefined){ if (node != undefined){
networkData.nodes.update({id: node.id, label: node.label + positionToEmoji(i, pair.second)}) networkData.nodes.update({id: node.id, label: node.label + positionToEmoji(i, pair.second)})
const test = networkData.nodes.get().find((n) => index == n.id) const test = networkData.nodes.get().find((n) => index == n.id)
if (test!=undefined){
console.log(test.label)
}
} }
}) })
}); });
} }
indices.forEach((i, index) => {
console.log(i.ToString("fr") + " => " + positionToEmoji(index, true))
})
if (!solo){ if (!solo){
socket.on("asked all", (id) =>{ socket.on("asked all", (id) =>{
const pers = personNetwork.getPersons().find((p) => p.getId() == id) const pers = personNetwork.getPersons().find((p) => p.getId() == id)
@ -313,7 +323,6 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
}) })
socket.on("node checked",(id, works, askedIndex, newPlayerIndex, socketId) => { socket.on("node checked",(id, works, askedIndex, newPlayerIndex, socketId) => {
console.log(newPlayerIndex)
const node = nodes.get().find((n) => id == n.id) const node = nodes.get().find((n) => id == n.id)
if (node!=undefined){ if (node!=undefined){
onNodeClick(false) onNodeClick(false)
@ -480,10 +489,12 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
setLastIndex(-1) setLastIndex(-1)
setPlayerTouched(-1) setPlayerTouched(-1)
setWinnerData(players[winnerIndex]) setWinnerData(players[winnerIndex])
setElapsedTime(0)
first = true first = true
cptHistory = 0 cptHistory = 0
askedWrong=false askedWrong=false
askedWrongBot=false askedWrongBot=false
endgame = true
socket.off("end game") socket.off("end game")
socket.off("asked all") socket.off("asked all")
socket.off("opacity activated") socket.off("opacity activated")
@ -512,7 +523,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
} }
if (a==indices.length){ if (a==indices.length){
//networkData.nodes.update({id: p.getId(), label: p.getName() + "\n🔵"}) //networkData.nodes.update({id: p.getId(), label: p.getName() + "\n🔵"})
console.log(p) //console.log(p)
} }
}); });
@ -651,12 +662,14 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
works = false works = false
} }
if (index == indices.length - 1 && works){ if (index == indices.length - 1 && works){
const Mtn = new Date().getSeconds()
settempsData(Mtn - initMtn)
if (user!=null){
setWinnerData(user)
}
cptTour ++; cptTour ++;
setNbCoupData(cptTour) setNbCoupData(cptTour)
setElapsedTime(0)
endgame = true
navigate("/endgame?solo=true&daily=" + isDaily) navigate("/endgame?solo=true&daily=" + isDaily)
} }

@ -53,7 +53,6 @@ function EndGame() {
const {winner, person, players, indices, nbCoup, temps} =useGame() const {winner, person, players, indices, nbCoup, temps} =useGame()
console.log(winner)
let indice = indices[0] let indice = indices[0]
let losingPlayers : Player[]; let losingPlayers : Player[];
@ -120,7 +119,7 @@ function EndGame() {
</div> </div>
<div className='winner'> <div className='winner'>
<img src={Person} width='250' height='250'/> <img src={Person} width='250' height='250'/>
<h1>[ {winner?.pseudo} ]</h1> <h1>{winner?.pseudo}</h1>
</div> </div>
<div className='bottom'> <div className='bottom'>

@ -216,7 +216,7 @@ function Lobby() {
</ul> </ul>
<center > <center >
<button className='buttonNabImg' onClick={StartGame}> <button className='buttonNabImg' onClick={StartGame}>
<img src={cible} alt="Button Image" height="50" width="50"/> <img src={cible} alt="Button Image" height="50" width="50" />
<p>{"la chasse !"}</p> <p>{"la chasse !"}</p>
</button> </button>
</center> </center>

@ -159,7 +159,7 @@ function Play() {
</div> </div>
<div className='buttonGroupVertical'> <div className='buttonGroupVertical'>
<button onClick={launchMastermind} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Jouer seul </button> <button onClick={launchMastermind} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Jouer seul </button>
<button onClick={launchEngimeJour} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Jouer seul mais aujourd'hui</button> <button onClick={launchEngimeJour} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Résoudre une énigme</button>
<button onClick={createLobby} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Créer une partie </button> <button onClick={createLobby} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Créer une partie </button>
<button className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Rejoindre </button> <button className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Rejoindre </button>

@ -1,6 +1,7 @@
import { io } from "socket.io-client"; import { io } from "socket.io-client";
import { ADRESSE_WEBSERVER } from "./adressConfig";
const socket = io("http://172.20.10.4:3002"); const socket = io(ADRESSE_WEBSERVER);
export {socket} export {socket}

@ -0,0 +1,7 @@
const ADRESSE_WEBSERVER = "http://localhost:3002"
const ADRESSE_DBSERVER = "http://localhost:3003"
const ADRESSE_WEBSITE = "http://localhost:3000"
export {ADRESSE_DBSERVER, ADRESSE_WEBSERVER, ADRESSE_WEBSITE}

@ -16,7 +16,7 @@ class NbSportIndice extends Indice {
// Implémentation de la méthode abstraite // Implémentation de la méthode abstraite
ToString(lang: string): string { ToString(lang: string): string {
let json = GetJsonFile(lang) let json = GetJsonFile(lang)
let string = `${json.nb_sports_indice_start}`; let string = `${json.nb_sports_indice_start} `;
this.nbSport.forEach((i, index) =>{ this.nbSport.forEach((i, index) =>{
if (index == this.nbSport.length - 1){ if (index == this.nbSport.length - 1){
string += i string += i

@ -16,10 +16,10 @@ class SportIndice extends Indice {
let string = json.sport_start; let string = json.sport_start;
for (let i = 0; i<this.sports.length; i++){ for (let i = 0; i<this.sports.length; i++){
if (i==this.sports.length - 1 || this.sports.length == 1){ if (i==this.sports.length - 1 || this.sports.length == 1){
string = `${string} ${SportToString(this.sports[i], lang)}` string = `${string} ${SportToString(this.sports[i], lang)} `
} }
else{ else{
string = `${string} ${SportToString(this.sports[i], lang)} ${json.or_sport}` string = `${string} ${SportToString(this.sports[i], lang)} ${json.or_sport} `
} }
} }
return `${string} ${json.sport_end}` return `${string} ${json.sport_end}`

@ -6,13 +6,14 @@ const crypto = require('crypto');
const authRoutes = require('./routes/authRoutes'); const authRoutes = require('./routes/authRoutes');
const DatabaseService = require('./services/DatabaseService'); const DatabaseService = require('./services/DatabaseService');
const app = express(); const app = express();
const port = 3003; const port = 3003;
// Middleware // Middleware
app.use(cors( app.use(cors(
{ {
origin: ['http://localhost:3000', "http://172.20.10.4:3000"], origin: ["http://localhost:3000", "http://172.20.10.4:3000"],
credentials: true credentials: true
} }
)); // Autoriser les requêtes cross-origin )); // Autoriser les requêtes cross-origin

@ -1,3 +1,4 @@
import { ADRESSE_DBSERVER } from '../adressConfig';
import VerificationService from './VerificationService'; import VerificationService from './VerificationService';
class AuthService{ class AuthService{
@ -12,7 +13,7 @@ class AuthService{
static async signUp(data: any) { static async signUp(data: any) {
try { try {
const response = await fetch('http://172.20.10.4:3003/auth/signup', { const response = await fetch(ADRESSE_DBSERVER + '/auth/signup', {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -36,7 +37,7 @@ class AuthService{
static async signIn(data: any) { static async signIn(data: any) {
try { try {
const response = await fetch('http://172.20.10.4:3003/auth/signin', { const response = await fetch(ADRESSE_DBSERVER + '/auth/signin', {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -61,7 +62,7 @@ class AuthService{
static async logout() { static async logout() {
try { try {
const response = await fetch('http://172.20.10.4:3003/auth/logout', { const response = await fetch(ADRESSE_DBSERVER + '/auth/logout', {
method: 'DELETE', method: 'DELETE',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',

@ -1,7 +1,9 @@
import { ADRESSE_DBSERVER } from "../adressConfig";
class SessionService { class SessionService {
static async getSession() { static async getSession() {
try { try {
const response = await fetch('http://172.20.10.4:3003/session', { const response = await fetch(ADRESSE_DBSERVER + '/session', {
method: 'GET', method: 'GET',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',

@ -0,0 +1,17 @@
#!/bin/sh
node server/server.js &
node src/server/server.js
if lsof -Pi :3002 -sTCP:LISTEN -t >/dev/null; then
# Tuer le processus associé au port
pid=$(lsof -Pi :3002 -sTCP:LISTEN -t)
kill -9 $pid
fi
if lsof -Pi :3003 -sTCP:LISTEN -t >/dev/null; then
# Tuer le processus associé au port
pid=$(lsof -Pi :3003 -sTCP:LISTEN -t)
kill -9 $pid
fi
Loading…
Cancel
Save