X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Fivac.git;a=blobdiff_plain;f=src%2Fivac.c;h=47d1892ae77d0ca3baededd9f40310d4a5a7a9fc;hp=56a687fb6603443236966a3d32763c68a1d07abf;hb=3bffc32233a1608ba3338f39bc5193665f3095cc;hpb=c0de1cff899325f9a4a058d7544ddbef3a5c50b1 diff --git a/src/ivac.c b/src/ivac.c index 56a687f..47d1892 100644 --- a/src/ivac.c +++ b/src/ivac.c @@ -21,10 +21,6 @@ * */ -// #define USE_NCURSES -/* dont care about ncurses .. go for gtk(2)! */ -#define USE_GTK - #include "ivac.h" int usage(void) { @@ -36,6 +32,8 @@ int usage(void) { puts("-h \t\t show this help"); puts("-n \t specify your name"); puts("-p \t specify port to listen for incoming connections"); + puts("-u \t specify udp data port"); + puts("-d \t specify audio device"); puts(""); return SUCCESS; @@ -51,6 +49,8 @@ int main(int argc,char **argv) { /* default values */ strcpy(ivac.username,"ivac"); ivac.net.l_port=IVAC_LISTEN_PORT; + ivac.net.l_udp_port=IVAC_UDP_PORT; + strcpy(ivac.audio.dsp_dev,SOUND_DEVICE); /* parse argv and change default values */ for(i=1;inet)); + network_udp_shutdown(&(ivac->net)); input_shutdown(&(ivac->input)); event_stop(&(ivac->event)); -#ifdef USE_NCURSES + audio_shutdown(&(ivac->audio)); display_shutdown(&(ivac->display)); -#endif return SUCCESS; } @@ -229,7 +243,7 @@ int ivac_receive_info(int channel,t_ivac *ivac) { } } - return SUCCESS; + return length; } int ivac_event_cb(t_event *event,void *ptr) { @@ -263,7 +277,12 @@ int ivac_event_cb(t_event *event,void *ptr) { if(ivac->net.connection[channel].status&C_ESTABL) { /* remote is sending info */ if(FD_ISSET(ivac->net.connection[channel].fd,&(event->rfds))) { - ivac_receive_info(channel,ivac); + if(ivac_receive_info(channel,ivac)==0) { + event_math(ivac->net.connection[channel].fd,event,READ,REMOVE); + network_close(&(ivac->net),channel); + sprintf(c_str,"channel %02d: broken pipe - disconnected",channel); + ivac_add_to_monitor(ivac,c_str); + } ivac_display_content(ivac); } } @@ -443,37 +462,15 @@ 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); - for(x=0;xmax_x;x++) addch('#'); - mvaddstr(1,0,"##"); - mvaddstr(1,(display->max_x-4)/2-4,"- ivac -"); - mvaddstr(1,(display->max_x-2),"##"); - 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; } @@ -486,93 +483,33 @@ int ivac_display_box_content(t_ivac *ivac) { if(ivac->challenger[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('#'); -#endif - return SUCCESS; } int ivac_display_console_content(t_ivac *ivac) { -#ifdef USE_NCURSES - int x,y; - int len; - - for(y=0;yconsole[y]); - move(ivac->display.max_y-IVAC_CONSOLE_LEN-IVAC_PROMPT_LEN+y,2); - for(x=0;xconsole[y][x]>' ')||(ivac->console[y][x]<='~')) - ?ivac->console[y][x]:' '); - 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); - for(x=0;xmax_x;x++) addch('#'); - mvaddstr(display->max_y-2,0,"## command: "); - mvaddstr(display->max_y-2,display->max_x-2,"##"); - 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 */ - if(ivac->input.c_count==0) { - move(ivac->display.max_y-2,12); - for(x=12;xdisplay.max_x-1;x++) addch(' '); - } - - 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; }