|
@@ -8,7 +8,6 @@
|
|
|
#include <stdio.h>
|
|
|
#include <stdlib.h>
|
|
|
#include <unistd.h>
|
|
|
-#include <pthread.h>
|
|
|
#include "error.h"
|
|
|
#include "bomberstudent_server.h"
|
|
|
#include "client.h"
|
|
@@ -20,49 +19,6 @@ extern Game game[MAXGAME];
|
|
|
extern int nbGame;
|
|
|
|
|
|
/* --- Fonctions privées --- */
|
|
|
-/**
|
|
|
- * Thread d'attente de la fonction timer
|
|
|
- * @param void* La structure timer_data cast en void*
|
|
|
- * @return NULL
|
|
|
- */
|
|
|
-void* timer_thread(void* data){
|
|
|
- timer_data* t;
|
|
|
- //Recup données
|
|
|
- t = (timer_data*) data;
|
|
|
- //Detache le thread
|
|
|
- if (pthread_detach(pthread_self()) != 0) {
|
|
|
- adderror("Impossible de détacher le thread Timer");
|
|
|
- return NULL;
|
|
|
- }
|
|
|
- //Attend le temps indiqué
|
|
|
- sleep(t->second);
|
|
|
- //Appel callback
|
|
|
- if(t->callback(&game[t->game], t->player) != SUCCESS){
|
|
|
- adderror("Erreur callback Timer");
|
|
|
- }
|
|
|
- return NULL;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Attend X second (sans bloquer l'execution) avant d'executer le callback
|
|
|
- * @param int Nombre de second en attente
|
|
|
- * @param int Index de la game
|
|
|
- * @param int Index du joueur dans la game
|
|
|
- * @param int(*)(Game*, int) Le callback
|
|
|
- */
|
|
|
-void timer(int second, int game, int player, int(*callback)(Game*, int)){
|
|
|
- pthread_t thread;
|
|
|
- timer_data* t = malloc(sizeof(timer_t));
|
|
|
- t->second = second;
|
|
|
- t->game = game;
|
|
|
- t->player = player;
|
|
|
- t->callback = callback;
|
|
|
- //Creation thread
|
|
|
- if (pthread_create(&thread, NULL, timer_thread, t) != 0) {
|
|
|
- adderror("Impossible de créer le thread Timer");
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
/**
|
|
|
* Cherche dans quel partie est un client
|
|
|
* @param int L'id du client
|