/* set username */
strncpy(ivac.username,argv[1],CHAR_USERNAME);
+ /* clear challenger struct */
+ for(i=0;i<MAX_CONNECTIONS;i++)
+ memset(&(ivac.challenger[i]),0,sizeof(t_challenger));
+ /* zero console buffer */
for(i=0;i<IVAC_CONSOLE_LEN;i++)
memset(ivac.console[i],0,IVAC_CONSOLE_STRING_LEN);
event_math(0,&(ivac.event),READ,ADD);
/* display init */
- display_init(&(ivac.display));
+ // display_init(&(ivac.display));
/* display */
ivac_display(&(ivac.display));
network_shutdown(&(ivac->net));
input_shutdown(&(ivac->input));
event_stop(&(ivac->event));
-#ifdef USE_NCURSES
- display_shutdown(&(ivac->display));
-#endif
+ // display_shutdown(&(ivac->display));
return SUCCESS;
}
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 */
input_get_event(&(ivac->input),ivac_parse_command,ivac);
/* display ivac gui */
-#ifdef USE_NCURSES
- ivac_display_content(ivac);
-#endif
+ // ivac_display_content(ivac);
return SUCCESS;
}
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 */
for(j=0;j<IVAC_ARG_COUNT;j++) memset(arg[j],0,IVAC_ARG_LEN);
/* get args */
-
len=0;
while(data[len]!='\n') len++;
i=0; j=0;
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;
}
}
}
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);
int ivac_display_box_content(t_ivac *ivac) {
+ int channel;
+
+ /* prepare challenger names */
+ for(channel=0;channel<MAX_CONNECTIONS;channel++)
+ if(ivac->challenger[channel].name[0]==0)
+ strcpy(ivac->challenger[channel].name,"<empty>");
+
+#ifdef USE_NCURSES
+#else
+ for(channel=0;channel<MAX_CONNECTIONS;channel++) {
+ if(ivac->net.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;x<display->max_x;x++) addch('#');
+ for(x=0;x<display->max_x;x++) addch('#');
+#endif
return SUCCESS;
}
int ivac_display_console_content(t_ivac *ivac) {
+#ifdef USE_NCURSES
int x,y;
int len;
for(x=len;x<IVAC_CONSOLE_STRING_LEN-4;x++) addch(' ');
}
refresh();
+#else
+ int i;
+
+ for(i=0;i<IVAC_CONSOLE_LEN;i++)
+ printf("[ivac] console line %d: %s\n",i,ivac->console[i]);
+#endif
return SUCCESS;
}
int ivac_display_prompt(t_display *display) {
+#ifdef USE_NCURSES
int x,y;
move(display->max_y-3,0);
move(display->max_y-1,0);
for(x=0;x<display->max_x;x++) addch('#');
refresh();
+#endif
return SUCCESS;
}
int ivac_display_prompt_content(t_ivac *ivac) {
+#ifdef USE_NCURSES
int x,y;
/* delete old command */
for(x=0;x<ivac->input.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;
}
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;i<IVAC_CONSOLE_LEN;i++)
- printf("[ivac] console line %d: %s\n",i,ivac->console[i]);
-#ifdef USE_NCURSES
- ivac_display_console_content(ivac);
-#endif
-
return SUCCESS;
}