|
@@ -121,6 +121,7 @@ void ini_handler() {
|
|
|
add_handler("POST", "player/move", handler_player_move);
|
|
|
add_handler("POST", "object/new", handler_object_new);
|
|
|
add_handler("POST", "attack/bomb", handler_attack_bomb);
|
|
|
+ add_handler("POST", "attack/remote/go", handler_attack_remote_go);
|
|
|
}
|
|
|
|
|
|
int handler_client_end(int cliId, JsonParser* json) {
|
|
@@ -635,12 +636,10 @@ int handler_attack_bomb(int cliId, JsonParser* json) {
|
|
|
p->classicBomb--;
|
|
|
game[index].map[x][y] = '1';
|
|
|
//Lance timer
|
|
|
- printf("Ici\n");
|
|
|
int* tab = malloc(sizeof(int) * 2);
|
|
|
tab[0] = x;
|
|
|
tab[1] = y;
|
|
|
//Timer
|
|
|
- printf("Delay\n");
|
|
|
delay_data(TIMEBOMB, index, playerIndex, (void*) tab, callback_bomb_explode);
|
|
|
}
|
|
|
} else if (strncmp(class, "mine", length) == 0) {
|
|
@@ -657,6 +656,7 @@ int handler_attack_bomb(int cliId, JsonParser* json) {
|
|
|
p->remoteBomb--;
|
|
|
game[index].map[x][y] = '3';
|
|
|
//Ajoute la bombe dans la liste du joueur
|
|
|
+ object_add(p->bomb, OBJ_BREMOTE, x, y);
|
|
|
}
|
|
|
} else {
|
|
|
pthread_mutex_unlock(&playerMutex[(index * MAXPLAYER) + playerIndex]);
|
|
@@ -712,4 +712,59 @@ int handler_attack_bomb(int cliId, JsonParser* json) {
|
|
|
free(pos);
|
|
|
free(class);
|
|
|
return SUCCESS;
|
|
|
+}
|
|
|
+
|
|
|
+int handler_attack_remote_go(int cliId, JsonParser* json){
|
|
|
+ int index, playerIndex;
|
|
|
+ JsonEncoder notif;
|
|
|
+ Player* p = NULL;
|
|
|
+ obj_node* objn, *tmp;
|
|
|
+ //Charche la game
|
|
|
+ index = search_client_game(cliId);
|
|
|
+ //Ini json
|
|
|
+ ini_encoder(¬if);
|
|
|
+ //Recup le joueur
|
|
|
+ pthread_mutex_lock(&gameMutex[index]);
|
|
|
+ for (int i = 0; i < MAXPLAYER; i++) {
|
|
|
+ pthread_mutex_lock(&playerMutex[(index * MAXPLAYER) + i]);
|
|
|
+ if (game[index].player[i]->ini && game[index].player[i]->id == cliId) {
|
|
|
+ playerIndex = i;
|
|
|
+ p = game[index].player[i];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ pthread_mutex_unlock(&playerMutex[(index * MAXPLAYER) + i]);
|
|
|
+ }
|
|
|
+ if (p == NULL) {
|
|
|
+ pthread_mutex_unlock(&gameMutex[index]);
|
|
|
+ send_err_client(cliId, EREQUEST);
|
|
|
+ adderror("Aucun joueur associé au client");
|
|
|
+ return FAIL;
|
|
|
+ }
|
|
|
+ //Explose toutes les remotes du joueur
|
|
|
+ objn = p->bomb->first;
|
|
|
+ while(objn != NULL){
|
|
|
+ tmp = objn->next;
|
|
|
+ if(objn->type == OBJ_BREMOTE){
|
|
|
+ //Retire mutex gérés dans fonctions
|
|
|
+ pthread_mutex_unlock(&playerMutex[(index * MAXPLAYER) + playerIndex]);
|
|
|
+ pthread_mutex_unlock(&gameMutex[index]);
|
|
|
+ if(bomb_explode(&game[index], playerIndex, objn->x, objn->y, ¬if)){
|
|
|
+ //Notification joueurs
|
|
|
+ if(!notify_player(&game[index], "POST", "attack/explose", ¬if, -1)){
|
|
|
+ adderror("Impossible de notifier le joueur de l'explosion");
|
|
|
+ }
|
|
|
+ clean_json_encoder(¬if);
|
|
|
+ }
|
|
|
+ //Remet mutex
|
|
|
+ pthread_mutex_lock(&gameMutex[index]);
|
|
|
+ pthread_mutex_lock(&playerMutex[(index * MAXPLAYER) + playerIndex]);
|
|
|
+ //Supprime la bombe de la liste
|
|
|
+ object_delete(p->bomb, objn);
|
|
|
+ objn = tmp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //Nettoyage
|
|
|
+ pthread_mutex_unlock(&playerMutex[(index * MAXPLAYER) + playerIndex]);
|
|
|
+ pthread_mutex_unlock(&gameMutex[index]);
|
|
|
+ return SUCCESS;
|
|
|
}
|