|
@@ -196,10 +196,12 @@ JsonEncoder* describe_game(Game* g, int playerIndex){
|
|
|
JsonEncoder* player;
|
|
|
JsonEncoder* desc = malloc(sizeof(JsonEncoder));
|
|
|
JsonEncoder* map = malloc(sizeof(JsonEncoder));
|
|
|
+ JsonArray* players = malloc(sizeof(JsonArray));
|
|
|
char* content;
|
|
|
//Initialisation
|
|
|
ini_encoder(desc);
|
|
|
ini_encoder(map);
|
|
|
+ ini_array_encoder(players);
|
|
|
//Info map
|
|
|
content = remove_char(g->mapContent, '\n'); //La map sans \n car interdit en JSON
|
|
|
add_integer(map, "width", g->width);
|
|
@@ -209,6 +211,18 @@ JsonEncoder* describe_game(Game* g, int playerIndex){
|
|
|
//Ajout info
|
|
|
add_integer(desc, "nbPlayers", g->nbPlayer);
|
|
|
add_object(desc, "map", map);
|
|
|
+ //Ajout info courte joueur
|
|
|
+ //printf("Add players\n");
|
|
|
+ for(int i = 0; i < MAXPLAYER; i++){
|
|
|
+ if(g->player[i]->ini){
|
|
|
+ player = describe_short_player(g->player[i]);
|
|
|
+ add_array_object(players, player);
|
|
|
+ clean_json_encoder(player);
|
|
|
+ free(player);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //printf("Fin Add players\n");
|
|
|
+ add_array(desc, "players", players);
|
|
|
//Si besoins ajout un joueur
|
|
|
if(playerIndex >= 0 && playerIndex < MAXPLAYER && g->player[playerIndex]->ini){
|
|
|
player = describe_player(g->player[playerIndex]);
|
|
@@ -222,7 +236,7 @@ JsonEncoder* describe_game(Game* g, int playerIndex){
|
|
|
return desc;
|
|
|
}
|
|
|
|
|
|
-boolean notify_player(Game* g, char* method, char* ressource, JsonEncoder* param){
|
|
|
+boolean notify_player(Game* g, char* method, char* ressource, JsonEncoder* param, int excludePlayerId){
|
|
|
boolean res = true;
|
|
|
//Regarde si la game est active
|
|
|
if(!g->active){
|
|
@@ -231,7 +245,7 @@ boolean notify_player(Game* g, char* method, char* ressource, JsonEncoder* param
|
|
|
//Parcours les joeurs de la game
|
|
|
for(int i = 0; i < MAXPLAYER; i++){
|
|
|
//Si joueur actif
|
|
|
- if(g->player[i]->ini){
|
|
|
+ if(g->player[i]->ini && g->player[i]->id != excludePlayerId){
|
|
|
res = res && notify_client(g->player[i]->cli, method, ressource, param);
|
|
|
}
|
|
|
}
|