]> hackdaworld.org Git - my-code/ivac.git/commitdiff
added quit msg to send before network close
authorhackbard <hackbard>
Tue, 11 May 2004 07:53:24 +0000 (07:53 +0000)
committerhackbard <hackbard>
Tue, 11 May 2004 07:53:24 +0000 (07:53 +0000)
src/ivac.c
src/ivac.h

index 8b9c312f5e42cd7240404a2f48cf684a956492e4..0108131e4a9e9e2ad3b5ab5e646fddbfeb2510bb 100644 (file)
@@ -129,6 +129,22 @@ int ivac_send_info(int channel,t_ivac *ivac) {
   return SUCCESS;
 }
 
+int ivac_send_quit(int channel,t_ivac *ivac) {
+
+  char data[6];
+
+  data[0]=IVAC_SEND_QUIT;
+  data[1]=4;
+  strcpy(data+2,"quit");
+
+  if(network_send(ivac->net.connection[channel].fd,data,6)==N_ERROR) {
+    puts("[ivac] ivac_send_quit failed");
+    return ERROR;
+  }
+
+  return SUCCESS;
+}
+
 int ivac_receive_info(int channel,t_ivac *ivac) {
 
   char data[SEND_N_MAX];
@@ -158,6 +174,11 @@ int ivac_receive_info(int channel,t_ivac *ivac) {
         ivac->challenger[channel].av_cap|=data[count+3];
         count+=4;
         break;
+      case IVAC_SEND_QUIT:
+        if(!(strncmp(data+count+2,"quit",data[1])))
+          event_math(ivac->net.connection[channel].fd,&(ivac->event),
+                     READ,REMOVE);
+          network_close(&(ivac->net),channel);
       default:
         puts("[ivac] ivac_receive_info, unknown character");
         return ERROR;
@@ -200,7 +221,7 @@ int ivac_event_cb(t_event *event,void *ptr) {
       /* remote is sending info */
       if(FD_ISSET(ivac->net.connection[channel].fd,&(event->rfds)))
         ivac_receive_info(channel,ivac);
-        ivac_display_content(ivac);
+        // ivac_display_content(ivac);
     }
   } 
 
@@ -307,11 +328,16 @@ int ivac_parse_command(t_input *input,void *ptr) {
       if((arg[1][0]>='0')&&(arg[1][0]<='9')) channel=atoi(arg[1]);
       else channel=-1;
       if((channel>=0)&&(channel<MAX_CONNECTIONS)) {
-        i=network_close(&(ivac->net),channel);
-        if(i==N_E_NC)
-          sprintf(c_str,"channel %02d: no active connection",channel);
-        else
+        if(ivac->net.connection[channel].status&C_ESTABL) {
+          ivac_send_quit(channel,ivac);
+          event_math(ivac->net.connection[channel].fd,&(ivac->event),
+                     READ,REMOVE);
+          network_close(&(ivac->net),channel);
           sprintf(c_str,"channel %02d: connection closed",channel);
+          memset(&(ivac->challenger[channel]),0,sizeof(t_challenger));
+        }
+        else
+          sprintf(c_str,"channel %02d: no active connection",channel);
       }
       else sprintf(c_str,"invalid argument: '%s'",arg[1]);
     }
index a946580db13e4b75388894b79a044d4e39026092..b635160f12115b37f233c7fcc6aca2ac8b3bb4ed 100644 (file)
@@ -28,6 +28,7 @@
 #define IVAC_SEND_NAME 'n'
 #define IVAC_SEND_G_CAP 'g'
 #define IVAC_SEND_AV_CAP 'c'
+#define IVAC_SEND_QUIT 'q'
 
 #define NETWORK (1<<0)