|
@@ -7,10 +7,11 @@
|
|
|
|
|
|
#include <stdio.h>
|
|
|
#include <stdlib.h>
|
|
|
+#include <unistd.h>
|
|
|
+#include <pthread.h>
|
|
|
#include "error.h"
|
|
|
#include "bomberstudent_server.h"
|
|
|
#include "client.h"
|
|
|
-#include "game.h"
|
|
|
#include "player.h"
|
|
|
#include "handler.h"
|
|
|
|
|
@@ -19,6 +20,38 @@ extern Game game[MAXGAME];
|
|
|
extern int nbGame;
|
|
|
|
|
|
/* --- Fonctions privées --- */
|
|
|
+
|
|
|
+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;
|
|
|
+}
|
|
|
+
|
|
|
+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
|
|
@@ -67,8 +100,6 @@ int search_game(char* name){
|
|
|
return index;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/* --- Fonctions publiques --- */
|
|
|
void ini_handler(){
|
|
|
//Get
|