+ /* parse command aka arg[0] */
+ if(!(strncmp(arg[0],"quit",4))) {
+ valid=1;
+ sprintf(c_str,"ivac shutdown ...");
+ for(i=0;i<MAX_CONNECTIONS;i++) {
+ if(ivac->net.connection[i].status&C_ESTABL) {
+ ivac_send_quit(i,ivac);
+ network_close(&(ivac->net),i);
+ }
+ }
+ ivac_shutdown(ivac);
+ }
+ if(!(strncmp(arg[0],"set",3))) {
+ valid=1;
+ if((arg[1][0]>='0')&&(arg[1][0]<='9')) channel=atoi(arg[1]);
+ else channel=-1;
+ if(!(strncmp(arg[1],"name",4))) {
+ strncpy(ivac->username,arg[2],CHAR_USERNAME);
+ sprintf(c_str,"changed username to %s",ivac->username);
+ }
+ else if((channel>=0)&&(channel<MAX_CONNECTIONS)) {
+ 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)
+ sprintf(c_str,"channel %02d: set connection info",channel);
+ } else snprintf(c_str,IVAC_CONSOLE_STRING_LEN,"unknown argument: '%s'",
+ arg[1]);
+ }
+ if(!(strncmp(arg[0],"connect",7))) {
+ valid=1;
+ if((arg[1][0]>='0')&&(arg[1][0]<='9')) channel=atoi(arg[1]);
+ else channel=-1;
+ if((channel>=0)&&(channel<MAX_CONNECTIONS)) {
+ i=network_connect(&(ivac->net),channel);
+ if(i==N_E_IN_USE)
+ sprintf(c_str,"channel %02d: connection in use",channel);
+ else if(i==N_E_NO_INFO)
+ sprintf(c_str,"channel %02d: channel not configured",channel);
+ else {
+ sprintf(c_str,"channel %02d: connected to %s:%d",channel,
+ ivac->net.connection[channel].ip,
+ ivac->net.connection[channel].port);
+ event_math(ivac->net.connection[channel].fd,&(ivac->event),READ,ADD);
+ ivac_send_info(channel,ivac);
+ }
+ }
+ else sprintf(c_str,"invalid argument: '%s'",arg[1]);
+ }
+ if(!(strncmp(arg[0],"close",5))) {
+ valid=1;
+ if((arg[1][0]>='0')&&(arg[1][0]<='9')) channel=atoi(arg[1]);
+ else channel=-1;
+ if((channel>=0)&&(channel<MAX_CONNECTIONS)) {
+ 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]);
+ }
+ if(!(strncmp(arg[0],"select",6))) {
+ valid=1;
+ if((arg[1][0]>='0')&&(arg[1][0]<='9')) channel=atoi(arg[1]);
+ else channel=-1;
+ if((channel>=0)&&(channel<MAX_CONNECTIONS)) {
+ network_select(&(ivac->net),channel);
+ sprintf(c_str,"selected channel %d",channel);
+ }
+ else if(arg[1][0]='*') {
+ network_select(&(ivac->net),MAX_CONNECTIONS);
+ strcpy(c_str,"selected all channels");
+ }
+ else sprintf(c_str,"invalid argument: '%s'",arg[1]);
+ }
+ if(!(strncmp(arg[0],"deselect",8))) {
+ valid=1;
+ if((arg[1][0]>='0')&&(arg[1][0]<='9')) channel=atoi(arg[1]);
+ else channel=-1;
+ if((channel>=0)&&(channel<MAX_CONNECTIONS)) {
+ network_deselect(&(ivac->net),channel);
+ sprintf(c_str,"deselected channel %d",channel);
+ }
+ else if(arg[1][0]='*') {
+ network_deselect(&(ivac->net),MAX_CONNECTIONS);
+ strcpy(c_str,"deselected all channels");
+ }
+ else sprintf(c_str,"invalid argument: '%s'",arg[1]);
+ }
+
+ 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);
+ input->c_count=0;
+
+ }
+
+ return SUCCESS;
+}
+
+int ivac_display_head(t_display *display) {
+
+ puts("#########################################################");
+ puts("##### ivac - - Copyright (C) 2004 Frank Zirkelbach #####");
+ puts("#########################################################");
+
+ return SUCCESS;
+}
+
+int ivac_display_box(t_display *display) {
+
+ return SUCCESS;
+}
+
+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>");
+
+ return SUCCESS;
+}
+
+int ivac_display_console(t_display *display) {
+
+ return SUCCESS;
+}
+
+int ivac_display_console_content(t_ivac *ivac) {
+
+ int i;
+
+ for(i=0;i<IVAC_CONSOLE_LEN;i++)
+ printf("[ivac] console line %d: %s\n",i,ivac->console[i]);
+
+ return SUCCESS;
+}
+
+int ivac_display_prompt(t_display *display) {
+
+ return SUCCESS;
+}
+
+int ivac_display_prompt_content(t_ivac *ivac) {
+
+ printf("%c",ivac->input.content[ivac->input.c_count-1]);
+ fflush(NULL);
+
+ return SUCCESS;
+}
+
+int ivac_display(t_display *display) {
+
+ int x,y;
+
+ /* display head */
+ ivac_display_head(display);
+
+ /* display box */
+ ivac_display_box(display);
+
+ /* display console */
+ ivac_display_console(display);
+
+ /* display command prompt */
+ ivac_display_prompt(display);
+
+ return SUCCESS;
+}
+
+int ivac_display_content(t_ivac *ivac) {
+
+ /* display box content */
+ ivac_display_box_content(ivac);
+
+ /* display console content */
+ ivac_display_console_content(ivac);
+
+ /* display prompt content */
+ ivac_display_prompt_content(ivac);
+
+ return SUCCESS;
+}
+
+int ivac_add_to_monitor(t_ivac *ivac,char *msg) {
+
+ int i;
+
+ for(i=0;i<IVAC_CONSOLE_LEN-1;i++)
+ memcpy(ivac->console[i],ivac->console[i+1],IVAC_CONSOLE_STRING_LEN);
+ memcpy(ivac->console[IVAC_CONSOLE_LEN-1],msg,IVAC_CONSOLE_STRING_LEN);
+
+ return SUCCESS;