X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;f=src%2Fivac.c;h=0108131e4a9e9e2ad3b5ab5e646fddbfeb2510bb;hb=b5512e7ee393a12bffc0b3fecabe515a2964c26b;hp=ca12131325b82352b04bb7a3e36409d17e4dc79f;hpb=d03742fa15c23fa40b8e213cf948e5465508e07b;p=my-code%2Fivac.git diff --git a/src/ivac.c b/src/ivac.c index ca12131..0108131 100644 --- a/src/ivac.c +++ b/src/ivac.c @@ -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; @@ -184,7 +205,7 @@ int ivac_event_cb(t_event *event,void *ptr) { else if(channel==N_E_MAXC) sprintf(c_str,"maximum connections reached"); else { - sprintf(c_str,"established connection from %s port %d on channel %d\n", + sprintf(c_str,"connection from %s port %d on channel %d", ivac->net.connection[channel].ip, ivac->net.connection[channel].port,channel); ivac_add_to_monitor(ivac,c_str); @@ -200,6 +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); } } @@ -273,9 +295,7 @@ int ivac_parse_command(t_input *input,void *ptr) { sprintf(c_str,"changed username to %s",ivac->username); } else if((channel>=0)&&(channelnet),channel, - ivac->net.connection[channel].ip, - ivac->net.connection[channel].port); + i=network_set_connection_info(&(ivac->net),channel,arg[2],atoi(arg[3])); if(i==N_E_IN_USE) sprintf(c_str,"channel %02d: connection in use",channel); if(i==N_SUCCESS) @@ -308,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)&&(channelnet),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]); }