[done] Managing ONLINE/OFFLINE status for planes deconnected
This commit is contained in:
parent
b96e89bddb
commit
e2fe1a7155
|
@ -26,6 +26,7 @@
|
|||
int z;
|
||||
int cap;
|
||||
int spd;
|
||||
char online;
|
||||
};
|
||||
|
||||
struct term_req{
|
||||
|
|
|
@ -24,8 +24,9 @@
|
|||
* (2) Attente de requête
|
||||
* (3) Gestion de la requête
|
||||
* (4) Envoi de la réponse
|
||||
* [5] On libère la mémoire
|
||||
* [6] Fermeture de la connection (SOCKET)
|
||||
* [5] On notifie que l'avion est déconnecté (crash)
|
||||
* [6] On libère la mémoire
|
||||
* [7] Fermeture de la connection (SOCKET)
|
||||
* [n] Arrêt du THREAD
|
||||
* 1. On met à jour "activeManagers"
|
||||
* 2. On arrête le THREAD
|
||||
|
@ -95,6 +96,7 @@ void* managePlane(void* THREADABLE_ARGS){
|
|||
data.z = ntohl(data.z);
|
||||
data.cap = ntohl(data.cap);
|
||||
data.spd = ntohl(data.spd);
|
||||
data.online = 1;
|
||||
|
||||
|
||||
|
||||
|
@ -164,12 +166,21 @@ void* managePlane(void* THREADABLE_ARGS){
|
|||
}
|
||||
|
||||
|
||||
/* [5] On libère la mémoire
|
||||
/* [5] On notifie que l'avoin est déconnecté (crash)
|
||||
=========================================================*/
|
||||
/* 1. On notifie le crash */
|
||||
arg->sgca->data[pindex].online = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* [6] On libère la mémoire
|
||||
=========================================================*/
|
||||
|
||||
|
||||
|
||||
/* [6] Fermeture de la connection (SOCKET)
|
||||
/* [7] Fermeture de la connection (SOCKET)
|
||||
=========================================================*/
|
||||
printf("{tcp_com}(%d) Fermeture de la socket de communication!\n", index);
|
||||
close(SOCKET);
|
||||
|
@ -219,7 +230,7 @@ void* manageViewTerm(void* THREADABLE_ARGS){
|
|||
struct sockaddr_in clientInfo;
|
||||
socklen_t len;
|
||||
char loop = 1;
|
||||
int count, last, sent; // compteurs d'envoi
|
||||
int count, last, sent, nb; // compteurs d'envoi
|
||||
int i, index = -1; // Compteurs globaux
|
||||
char buffer[MAX_BUF_LEN]; // Buffer d'envoi
|
||||
struct term_res request; // Requête
|
||||
|
@ -248,13 +259,14 @@ void* manageViewTerm(void* THREADABLE_ARGS){
|
|||
=========================================================*/
|
||||
/* 1. On initialise les variables utiles */
|
||||
request.flags = TERMREQ_FBK;
|
||||
request.n = arg->sgca->n;
|
||||
nb = arg->sgca->n;
|
||||
request.n = 0; // nombre d'avions online
|
||||
|
||||
free(request.data);
|
||||
request.data = malloc( request.n * sizeof(struct plane) + 1 );
|
||||
request.data = malloc( nb * sizeof(struct plane) + 1 );
|
||||
|
||||
/* 2. On récupère la liste des avions (network byte order) */
|
||||
for( i = 0 ; i < request.n ; i++ ){
|
||||
for( i = 0 ; i < nb ; i++ ){
|
||||
|
||||
memcpy(&request.data[i].code, &arg->sgca->data[i].code, sizeof(char)*6);
|
||||
request.data[i].x = htonl( arg->sgca->data[i].x );
|
||||
|
@ -262,6 +274,10 @@ void* manageViewTerm(void* THREADABLE_ARGS){
|
|||
request.data[i].z = htonl( arg->sgca->data[i].z );
|
||||
request.data[i].cap = htonl( arg->sgca->data[i].cap );
|
||||
request.data[i].spd = htonl( arg->sgca->data[i].spd );
|
||||
request.data[i].online = arg->sgca->data[i].online;
|
||||
|
||||
// Incrément du compte si online
|
||||
request.n += request.data[i].online;
|
||||
|
||||
}
|
||||
|
||||
|
@ -277,6 +293,11 @@ void* manageViewTerm(void* THREADABLE_ARGS){
|
|||
|
||||
/* 3. Copie des données des avions */
|
||||
for( i = 0 ; i < request.n ; i++ ){
|
||||
|
||||
// Ignore les avions offline
|
||||
if( !request.data[i].online )
|
||||
continue;
|
||||
|
||||
count += last; last = sizeof(char)*6; memcpy(buffer+count, &request.data[i].code, last);
|
||||
count += last; last = sizeof(int); memcpy(buffer+count, &request.data[i].x, last);
|
||||
count += last; last = sizeof(int); memcpy(buffer+count, &request.data[i].y, last);
|
||||
|
|
Loading…
Reference in New Issue