Эх сурвалжийг харах

Ajout fonction pour notifier tous les clients actifs

Arthur Brandao 6 жил өмнө
parent
commit
f7b0ca6bf6

+ 17 - 0
Serveur/bomberstudent_server.c

@@ -282,4 +282,21 @@ boolean notify_client(Client* cli, char* method, char* ressource, JsonEncoder* p
     free(answer);
     free(msg);
     return true;
+}
+
+boolean notify_all(char* method, char* ressource, JsonEncoder* param){
+    Client* cli;
+    boolean res = true;
+    //Parcours tous les clients
+    int nbClient = get_number_client();
+    for(int i = 0; i < nbClient; i++){
+        cli = get_client(i);
+        //Si le client existe toujours
+        if(cli == NULL){
+            continue;
+        }
+        //Lui envoi le message
+        res = res && notify_client(cli, method, ressource, param);
+    }
+    return res;
 }

+ 1 - 0
Serveur/bomberstudent_server.h

@@ -26,6 +26,7 @@ boolean launch_tcp_server(int);
 boolean receive_client(Client*);
 boolean send_client(int, JsonEncoder*);
 boolean notify_client(Client*, char*, char*, JsonEncoder*);
+boolean notify_all(char*, char*, JsonEncoder*);
 
 #endif /* BOMBERSTUDENT_SERVER_H */