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 lastNodes: NodePerson[] = []
let firstEnigme = true
let endgame= false
const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, isDaily, addToHistory, showLast, setNetwork}) => {
let cptTour: number = 0
//* Gestion du temps :
const initMtn = new Date().getSeconds()
let initMtn = 0
const {user} = useAuth()
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 [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(() =>{
touchedPlayer=playerTouched
@ -201,7 +220,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
if (first){
first = false
endgame= false
if (!solo){
for(let i = 0; i<indices.length; i++){
mapIndexPersons.set(i, [])
@ -267,24 +286,15 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
dailyEnigme.forEach((pairs, index) => {
pairs.forEach((pair) => {
const i = indices.findIndex((indice) => pair.first.getId() === indice.getId())
console.log(index)
const node = networkData.nodes.get().find((n) => index == n.id)
if (node != undefined){
networkData.nodes.update({id: node.id, label: node.label + positionToEmoji(i, pair.second)})
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){
socket.on("asked all", (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) => {
console.log(newPlayerIndex)
const node = nodes.get().find((n) => id == n.id)
if (node!=undefined){
onNodeClick(false)
@ -480,10 +489,12 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
setLastIndex(-1)
setPlayerTouched(-1)
setWinnerData(players[winnerIndex])
setElapsedTime(0)
first = true
cptHistory = 0
askedWrong=false
askedWrongBot=false
endgame = true
socket.off("end game")
socket.off("asked all")
socket.off("opacity activated")
@ -512,7 +523,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
}
if (a==indices.length){
//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
}
if (index == indices.length - 1 && works){
const Mtn = new Date().getSeconds()
settempsData(Mtn - initMtn)
if (user!=null){
setWinnerData(user)
}
cptTour ++;
setNbCoupData(cptTour)
setElapsedTime(0)
endgame = true
navigate("/endgame?solo=true&daily=" + isDaily)
}

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

@ -216,7 +216,7 @@ function Lobby() {
</ul>
<center >
<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>
</button>
</center>

@ -159,7 +159,7 @@ function Play() {
</div>
<div className='buttonGroupVertical'>
<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 className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Rejoindre </button>

@ -1,6 +1,7 @@
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}

@ -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
ToString(lang: string): string {
let json = GetJsonFile(lang)
let string = `${json.nb_sports_indice_start}`;
let string = `${json.nb_sports_indice_start} `;
this.nbSport.forEach((i, index) =>{
if (index == this.nbSport.length - 1){
string += i

@ -16,10 +16,10 @@ class SportIndice extends Indice {
let string = json.sport_start;
for (let i = 0; i<this.sports.length; i++){
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{
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}`

@ -6,13 +6,14 @@ const crypto = require('crypto');
const authRoutes = require('./routes/authRoutes');
const DatabaseService = require('./services/DatabaseService');
const app = express();
const port = 3003;
// Middleware
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
}
)); // Autoriser les requêtes cross-origin

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

@ -1,7 +1,9 @@
import { ADRESSE_DBSERVER } from "../adressConfig";
class SessionService {
static async getSession() {
try {
const response = await fetch('http://172.20.10.4:3003/session', {
const response = await fetch(ADRESSE_DBSERVER + '/session', {
method: 'GET',
headers: {
'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