Prechádzať zdrojové kódy

:bug: Debug handler object new

Arthur Brandao 6 rokov pred
rodič
commit
f43ae10082
1 zmenil súbory, kde vykonal 5 pridanie a 4 odobranie
  1. 5 4
      Serveur/handler.c

+ 5 - 4
Serveur/handler.c

@@ -530,12 +530,11 @@ int handler_object_new(int cliId, JsonParser* json) {
         adderror("Aucun joueur associé au client");
         return FAIL;
     }
-    //Initialisation json
-    ini_encoder(&reponse);
-    add_string(&reponse, "action", "object/new");
     //Regarde si un objet correspond
     objn = object_search(game[index].object, type, p->x, p->y);
     if (objn == NULL) {
+        ini_encoder(&reponse);
+        add_string(&reponse, "action", "object/new");
         add_integer(&reponse, "status", 501);
         add_string(&reponse, "message", "No object");
         //Envoi
@@ -550,8 +549,10 @@ int handler_object_new(int cliId, JsonParser* json) {
         pthread_mutex_lock(&playerMutex[(index * MAXPLAYER) + playerIndex]);
         add_player_object(p, type);
         //Creation reponse
-        add_integer(&reponse, "status", 201);
+        ini_encoder(&reponse);
         describe_player(p, &reponse);
+        add_integer(&reponse, "status", 201);
+        add_string(&reponse, "action", "object/new");
         pthread_mutex_unlock(&playerMutex[(index * MAXPLAYER) + playerIndex]);
         //Envoi
         if (!send_client(cliId, &reponse)) {