X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;f=src%2Fivac.c;h=23d59b19cd498ec8ecd603cfe716c261b15e84f6;hb=9c1916712be5882b728b5e54e6716272ce0678a5;hp=8b8acbc50923ad9b58fd6340546a838479455c72;hpb=2fb65b9beceb0945b593e28332507aa1b7c3fd90;p=my-code%2Fivac.git diff --git a/src/ivac.c b/src/ivac.c index 8b8acbc..23d59b1 100644 --- a/src/ivac.c +++ b/src/ivac.c @@ -21,7 +21,7 @@ * */ -// #define DISPLAY +// #define USE_NCURSES #include "ivac.h" @@ -32,8 +32,17 @@ int main(int argc,char **argv) { t_ivac ivac; int i; - /* set username (futur: read from config or entered later) */ - strcpy(ivac.username,"hackbard"); + if(argc!=2) { + printf("\nusage: %s \n\n",argv[0]); + return ERROR; + } + + /* set username */ + strncpy(ivac.username,argv[1],CHAR_USERNAME); + /* clear challenger struct */ + for(i=0;inet)); input_shutdown(&(ivac->input)); event_stop(&(ivac->event)); -#ifdef DISPLAY - display_shutdown(&(ivac->display)); -#endif + // display_shutdown(&(ivac->display)); return SUCCESS; } @@ -174,25 +177,29 @@ int ivac_event_cb(t_event *event,void *ptr) { if(FD_ISSET(ivac->net.l_fd,&(event->rfds))) { /* manage incoming + send info */ - channel=network_manage_incoming(&(ivac->net)); - event_math(ivac->net.connection[channel].fd,event,READ,ADD); - ivac_send_info(channel,ivac); + if((channel=network_manage_incoming(&(ivac->net)))!=N_ERROR) { + event_math(ivac->net.connection[channel].fd,event,READ,ADD); + ivac_send_info(channel,ivac); + } } - /* receive info */ - for(channel=0;channelnet.connection[channel].status&C_ESTABL) + for(channel=0;channelnet.connection[channel].status&C_ESTABL) { + /* receive info */ if(FD_ISSET(ivac->net.connection[channel].fd,&(event->rfds))) ivac_receive_info(channel,ivac); + /* sync network/event api */ + if(!(FD_ISSET(ivac->net.connection[channel].fd,&(event->rfds_o)))) + event_math(ivac->net.connection[channel].fd,event,READ,ADD); + } + } /* user interaction */ if(FD_ISSET(0,&(event->rfds))) input_get_event(&(ivac->input),ivac_parse_command,ivac); /* display ivac gui */ -#ifdef DISPLAY - ivac_display_content(ivac); -#endif + // ivac_display_content(ivac); return SUCCESS; } @@ -218,11 +225,10 @@ int ivac_parse_command(t_input *input,void *ptr) { data=input->content; valid=0; - printf("%c",data[input->c_count-1]); - fflush(NULL); + /* refresh prompt content only! */ + ivac_display_prompt_content(ivac); /* parse command routines */ - if(data[input->c_count-1]=='\n') { /* delete console string + args */ @@ -230,7 +236,6 @@ int ivac_parse_command(t_input *input,void *ptr) { for(j=0;j='0')&&(arg[1][0]<='9')) channel=atoi(arg[1]); else channel=-1; if((channel>=0)&&(channelnet.connection[channel].status&C_INFO_A) + if(!(ivac->net.connection[channel].status&C_INFO_A)) sprintf(c_str,"channel %02d: channel not configured",channel); else { if(ivac->net.connection[channel].status&C_IN_USE) @@ -288,6 +293,7 @@ int ivac_parse_command(t_input *input,void *ptr) { sprintf(c_str,"channel %02d: trying to connect to %s:%d",channel, ivac->net.connection[channel].ip, ivac->net.connection[channel].port); + ivac->net.connection[channel].status|=C_IN_USE; } } } @@ -298,7 +304,7 @@ 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.connection[channel].status&C_ESTABL) + if(!(ivac->net.connection[channel].status&C_ESTABL)) sprintf(c_str,"channel %02d: no active connection",channel); else { ivac->net.connection[channel].status|=C_HANGUP; @@ -339,8 +345,14 @@ int ivac_parse_command(t_input *input,void *ptr) { if(!valid) snprintf(c_str,IVAC_CONSOLE_STRING_LEN,"unknown command: '%s'",arg[0]); + /* call network functions */ + network_manage_connection(&(ivac->net)); + + /* add console string to console buffer */ ivac_add_to_monitor(ivac,c_str); - + + /* refresh whole display content */ + ivac_display_content(ivac); /* delete content buffer + reset counter */ memset(input->content,0,input->c_count-1); @@ -353,6 +365,7 @@ int ivac_parse_command(t_input *input,void *ptr) { int ivac_display_head(t_display *display) { +#ifdef USE_NCURSES int x,y; move(0,0); @@ -363,40 +376,68 @@ int ivac_display_head(t_display *display) { move(2,0); for(x=0;xmax_x;x++) addch('#'); refresh(); +#else + puts("#########################################################"); + puts("##### ivac - - Copyright (C) 2004 Frank Zirkelbach #####"); + puts("#########################################################"); +#endif return SUCCESS; } int ivac_display_box(t_display *display) { - + +#ifdef USE_NCURSES int x,y; for(y=IVAC_PROMPT_LEN;ymax_y-IVAC_PROMPT_LEN;y++) { mvaddch(y,0,'#'); mvaddch(y,display->max_x-1,'#'); } +#endif return SUCCESS; } int ivac_display_box_content(t_ivac *ivac) { + int channel; + + /* prepare challenger names */ + for(channel=0;channelchallenger[channel].name[0]==0) + strcpy(ivac->challenger[channel].name,""); + +#ifdef USE_NCURSES +#else + for(channel=0;channelnet.connection[channel].status&C_INFO_A) + printf("channel %02d: ip:%s port:%d status: %02x - name: %s\n",channel, + ivac->net.connection[channel].ip, + ivac->net.connection[channel].port, + ivac->net.connection[channel].status, + ivac->challenger[channel].name); + } +#endif return SUCCESS; } int ivac_display_console(t_display *display) { - + +#ifdef USE_NCURSES int x,y; move(display->max_y-IVAC_CONSOLE_LEN-IVAC_PROMPT_LEN-1,0); - for(x=0;xmax_x;x++) addch('#'); + for(x=0;xmax_x;x++) addch('#'); +#endif return SUCCESS; } int ivac_display_console_content(t_ivac *ivac) { +#ifdef USE_NCURSES int x,y; int len; @@ -409,12 +450,19 @@ int ivac_display_console_content(t_ivac *ivac) { for(x=len;xconsole[i]); +#endif return SUCCESS; } int ivac_display_prompt(t_display *display) { +#ifdef USE_NCURSES int x,y; move(display->max_y-3,0); @@ -424,12 +472,14 @@ int ivac_display_prompt(t_display *display) { move(display->max_y-1,0); for(x=0;xmax_x;x++) addch('#'); refresh(); +#endif return SUCCESS; } int ivac_display_prompt_content(t_ivac *ivac) { +#ifdef USE_NCURSES int x,y; /* delete old command */ @@ -441,6 +491,10 @@ int ivac_display_prompt_content(t_ivac *ivac) { for(x=0;xinput.c_count;x++) mvaddch(ivac->display.max_y-2,x+12,ivac->input.content[x]); refresh(); +#else + printf("%c",ivac->input.content[ivac->input.c_count-1]); + fflush(NULL); +#endif return SUCCESS; } @@ -486,11 +540,5 @@ int ivac_add_to_monitor(t_ivac *ivac,char *msg) { memcpy(ivac->console[i],ivac->console[i+1],IVAC_CONSOLE_STRING_LEN); memcpy(ivac->console[IVAC_CONSOLE_LEN-1],msg,IVAC_CONSOLE_STRING_LEN); - for(i=0;iconsole[i]); -#ifdef DISPLAY - ivac_display_console_content(ivac); -#endif - return SUCCESS; }