/* set username (futur: read from config or entered later) */
strcpy(ivac.username,"hackbard");
+ memset(&ivac.console[0][0],0,IVAC_CONSOLE_LEN*IVAC_CONSOLE_STRING_LEN);
/* set capabilities (futur: set by check routines) */
ivac.g_cap=NETWORK;
event_math(ivac.net.l_fd,&(ivac.event),READ,ADD);
event_math(0,&(ivac.event),READ,ADD);
+ /* display init */
+ display_init(&(ivac.display));
+
/* display */
- ivac_display(&(ivac));
+ ivac_display(&(ivac.display));
/* start event system - callbacks used: ivac_event_cb + ivac_regular_cb */
event_start(&(ivac.event),(void *)&ivac,ivac_event_cb,ivac_regular_cb);
network_shutdown(&(ivac->net));
input_shutdown(&(ivac->input));
event_stop(&(ivac->event));
+ display_shutdown(&(ivac->display));
return SUCCESS;
}
input_get_event(&(ivac->input),ivac_parse_command,ivac);
/* display ivac gui */
- ivac_display(ivac);
+ ivac_display_content(ivac);
return SUCCESS;
}
int ivac_parse_command(t_input *input,void *ptr) {
t_ivac *ivac;
- int channel;
+ int channel,i;
+ int len;
+ char *data,valid=0;
+ char c_str[IVAC_CONSOLE_STRING_LEN];
ivac=(t_ivac *)ptr;
+ data=input->content;
+ i=input->c_count-1;
+ memset(c_str,0,IVAC_CONSOLE_STRING_LEN);
/* parse command routines */
- if(input->content[input->c_count-1]=='\n') {
+ if((data[i]=='\r') || (data[i]=='\n')) {
+
+ /* parse commands */
+ switch(data[0]) {
+ case '/':
+ len=strlen(data+1);
+ if(len==4) {
+ /* len 4 commands */
+ if(!strncmp(data+1,"quit",4)) {
+ valid=1;
+ sprintf(c_str,"ivac shutdown\n");
+ ivac_add_to_monitor(ivac,c_str);
+ ivac_shutdown(ivac);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+
+ if(!valid) {
+ snprintf(c_str,IVAC_CONSOLE_STRING_LEN-1,"unknown command: '%s...'\n",
+ data);
+ ivac_add_to_monitor(ivac,c_str);
+ }
+
/* delete content buffer + reset counter */
memset(input->content,0,input->c_count);
input->c_count=0;
+
}
return SUCCESS;
}
-int ivac_display_head(void) {
+int ivac_display_head(t_display *display) {
+
+ int x,y;
+
+ move(0,0);
+ for(x=0;x<display->max_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;x<display->max_x;x++) addch('#');
+ refresh();
+
+ return SUCCESS;
+}
+
+int ivac_display_box(t_display *display) {
+
+ int x,y;
- /* 23 x 80 */
- int column,line;
+ for(y=IVAC_PROMPT_LEN;y<display->max_y-IVAC_PROMPT_LEN;y++) {
+ mvaddch(y,0,'#');
+ mvaddch(y,display->max_x-1,'#');
+ }
- for(column=0;column<COLUMN;column++) printf("#");
- printf("\n");
+ return SUCCESS;
+}
- printf("##");
- for(column=2;column<(COLUMN-8)/2;column++) printf(" ");
- printf("- ivac -");
- for(column=2;column<(COLUMN-8)/2;column++) printf(" ");
- printf("##\n");
+int ivac_display_box_content(t_ivac *ivac) {
- for(column=0;column<COLUMN;column++) printf("#");
- printf("\n");
return SUCCESS;
}
-int ivac_display_prompt(t_ivac *ivac) {
+int ivac_display_console(t_display *display) {
+
+ int x,y;
+
+ move(display->max_y-IVAC_CONSOLE_LEN-IVAC_PROMPT_LEN-1,0);
+ for(x=0;x<display->max_x;x++) addch('#');
+
+ return SUCCESS;
+}
- int column,line;
+int ivac_display_console_content(t_ivac *ivac) {
- for(column=0;column<COLUMN;column++) printf("#");
- printf("\n");
- printf("## command: ");
- for(column=12;column<12+ivac->input.c_count;column++)
- printf("%c",ivac->input.content[column-12]);
- for(column=12+ivac->input.c_count;column<COLUMN-2;column++) printf(" ");
- printf("##");
- printf("\n");
- for(column=0;column<COLUMN;column++) printf("#");
+ int x,y,len;
+ for(y=0;y<IVAC_CONSOLE_LEN;y++) {
+ len=strlen(ivac->console[y]);
+ move(ivac->display.max_y-IVAC_CONSOLE_LEN-IVAC_PROMPT_LEN+y,2);
+ for(x=0;x<IVAC_CONSOLE_STRING_LEN;x++) addch(ivac->console[y][x]);
+ }
+ refresh();
return SUCCESS;
}
-int ivac_display(t_ivac *ivac) {
+int ivac_display_prompt(t_display *display) {
- int line,column;
+ int x,y;
- /* display head */
- ivac_display_head();
+ move(display->max_y-3,0);
+ for(x=0;x<display->max_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;x<display->max_x;x++) addch('#');
+ refresh();
+
+ return SUCCESS;
+}
- /* build content of middle part + display */
- for(line=3;line<LINE-3;line++) {
- printf("#");
- for(column=1;column<COLUMN-1;column++) printf(" ");
- printf("#\n");
+int ivac_display_prompt_content(t_ivac *ivac) {
+
+ int x,y;
+
+ /* delete old command */
+ if(ivac->input.c_count==0) {
+ move(ivac->display.max_y-2,12);
+ for(x=12;x<ivac->display.max_x-1;x++) addch(' ');
}
+ for(x=0;x<ivac->input.c_count;x++)
+ mvaddch(ivac->display.max_y-2,x+12,ivac->input.content[x]);
+ refresh();
+
+ 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(ivac);
+ 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);
+ ivac_display_console_content(ivac);
return SUCCESS;
}
#include "network.h"
#include "event.h"
#include "input.h"
+#include "display.h"
/* defines */
#define CHAR_USERNAME 32
#define VIDEO (1<<1)
#define DUPLEX (1<<2)
-#define COLUMN 80
-#define LINE 24
+#define IVAC_CONSOLE_STRING_LEN 64
+
+#define IVAC_HEAD_LEN 3
+#define IVAC_PROMPT_LEN 3
+#define IVAC_CONSOLE_LEN 8
/* variables */
typedef struct s_challenger {
t_net net;
t_event event;
t_input input;
+ t_display display;
t_challenger challenger[MAX_CONNECTIONS];
+ char console[IVAC_CONSOLE_LEN][IVAC_CONSOLE_STRING_LEN];
} t_ivac;
/* function prototypes */
int ivac_event_cb(t_event *event,void *ptr);
int ivac_regular_cb(t_event *event,void *ptr);
int ivac_parse_command(t_input *input,void *ptr);
-int ivac_display_head(void);
-int ivac_display_prompt(t_ivac *ivac);
-int ivac_display(t_ivac *ivac);
+int ivac_display_head(t_display *display);
+int ivac_display_box(t_display *display);
+int ivac_display_box_content(t_ivac *ivac);
+int ivac_display_console(t_display *display);
+int ivac_display_console_content(t_ivac *ivac);
+int ivac_display_prompt(t_display *display);
+int ivac_display_prompt_content(t_ivac *ivac);
+int ivac_display(t_display *display);
+int ivac_display_content(t_ivac *ivac);
+int ivac_add_to_monitor(t_ivac *ivac,char *msg);
#endif