ivac.event.timeout.tv_sec=IVAC_S_SEC;
ivac.event.timeout.tv_usec=IVAC_S_USEC;
/* event init */
- event_init(&(ivac.event));
+ if(event_init(&(ivac.event))==E_ERROR) {
+ ivac_shutdown(&ivac);
+ return ERROR;
+ }
/* input init */
ivac.input.mode=CONTENT_BUFFER;
- input_init(&(ivac.input));
+ ivac.input.c_count=0;
+ if(input_init(&(ivac.input))==I_ERROR) {
+ ivac_shutdown(&ivac);
+ return ERROR;
+ }
/* network init */
if(network_init(&(ivac.net))==N_ERROR) {
ivac_shutdown(&ivac);
return ERROR;
}
+
+ /* network udp init */
network_udp_listen_init(&(ivac.net));
/* add listening port(s) + stdin to (read) event system */
event_math(ivac.net.l_udp_fd,&(ivac.event),READ,ADD);
event_math(0,&(ivac.event),READ,ADD);
- /* display init */
- display_init(&(ivac.display));
-
/* use hardcoded audio settings by now */
ivac.audio.fmt=BIT_8;
ivac.audio.channels=MONO;
ivac.audio.speed=8000;
/* audio init */
audio_init(&(ivac.audio));
+ /* audio setup */
audio_setup(&(ivac.audio));
+ /* display init */
+ display_init(&(ivac.display));
+
/* display */
ivac_display(&ivac);
+ ivac_display_content(&ivac);
ivac_display_draw(&ivac);
/* start event system - callbacks used: ivac_event_cb + ivac_regular_cb */
int ivac_shutdown(t_ivac *ivac) {
+ display_shutdown(&(ivac->display));
network_shutdown(&(ivac->net));
network_udp_shutdown(&(ivac->net));
input_shutdown(&(ivac->input));
event_stop(&(ivac->event));
audio_shutdown(&(ivac->audio));
- display_shutdown(&(ivac->display));
return SUCCESS;
}
switch(data[count]) {
case IVAC_SEND_NAME:
strncpy(ivac->challenger[channel].name,data+count+2,data[count+1]);
- ivac->challenger[channel].name[data[count+1]]='\0';
+ ivac->challenger[channel].name[(int)data[count+1]]='\0';
count+=(data[count+1]+2);
break;
case IVAC_SEND_G_CAP:
char *data,valid;
char c_str[IVAC_CONSOLE_STRING_LEN];
char arg[IVAC_ARG_COUNT][IVAC_ARG_LEN];
+ char debug_string[128];
ivac=(t_ivac *)ptr;
data=input->content;
/* refresh prompt content only */
ivac_display_prompt_content(ivac);
+ ivac_display_draw(ivac);
+
+#ifdef DEBUG
+ ivac_add_to_monitor(ivac,"nach display refresh");
+#endif
+
+#ifdef DEBUG
+ ivac_add_to_monitor(ivac,"nach display refresh");
+#endif
+
+#ifdef DEBUG
+
+ strcpy(debug_string,"hahahaha!");
+ ivac_add_to_monitor(ivac,debug_string);
+#endif
/* parse command routines */
- if(data[input->c_count-1]=='\n') {
+ if(data[input->c_count-1]=='\n' || data[input->c_count-1]=='\r') {
+
+#ifdef DEBUG
+ ivac_add_to_monitor(ivac,"got newline or carriage return!");
+#endif
/* delete console string + args */
memset(c_str,0,IVAC_CONSOLE_STRING_LEN);
i+=k;
}
+
/* parse command aka arg[0] */
if(!(strncmp(arg[0],"quit",4))) {
valid=1;
network_select(&(ivac->net),channel);
sprintf(c_str,"selected channel %d",channel);
}
- else if(arg[1][0]='*') {
+ else if(arg[1][0]=='*') {
network_select(&(ivac->net),MAX_CONNECTIONS);
strcpy(c_str,"selected all channels");
}
network_deselect(&(ivac->net),channel);
sprintf(c_str,"deselected channel %d",channel);
}
- else if(arg[1][0]='*') {
+ else if(arg[1][0]=='*') {
network_deselect(&(ivac->net),MAX_CONNECTIONS);
strcpy(c_str,"deselected all channels");
}
ivac_display_content(ivac);
ivac_display_draw(ivac);
- /* delete content buffer + reset counter */
+ /* delete input content buffer + reset counter */
memset(input->content,0,input->c_count-1);
input->c_count=0;
}
+ ivac_add_to_monitor(ivac,"debug: end of parse function");
+
return SUCCESS;
}
int ivac_display_box(t_ivac *ivac) {
display_line(&(ivac->display),0,3,ivac->display.max_x,3,'-');
- printf("username: %s, capabilities: %02x|%04x\n",ivac->username,ivac->g_cap,
- ivac->av_cap);
display_line(&(ivac->display),0,5,ivac->display.max_x,5,'-');
display_string(&(ivac->display),0,6,"connections:",12);
display_line(&(ivac->display),
if(ivac->challenger[channel].name[0]==0)
strcpy(ivac->challenger[channel].name,"<empty>");
+ sprintf(string,"username: %s, capabilities: %02x|%04x",
+ ivac->username,ivac->g_cap,ivac->av_cap);
+ display_string(&(ivac->display),0,4,string,strlen(string));
+
for(channel=0;channel<MAX_CONNECTIONS;channel++) {
if(ivac->net.connection[channel].status&C_INFO_A) {
snprintf(string,MAX_BOX_CHARS,
int ivac_display_prompt(t_ivac *ivac) {
- /* simply a printf - dirty! */
- printf("prompt: ");
- fflush(NULL);
+ display_string(&(ivac->display),0,ivac->display.max_y-1,"prompt: ",8);
return SUCCESS;
}
int ivac_display_prompt_content(t_ivac *ivac) {
- /* simply a printf - dirty! */
- printf("%c",ivac->input.content[ivac->input.c_count-1]);
- fflush(NULL);
+ char string[IVAC_CONSOLE_STRING_LEN];
+ int count;
+ for(count=0;count<ivac->input.c_count;count++)
+ string[count]=ivac->input.content[count];
+ for(;count<ivac->display.max_x-8;count++) string[count]=' ';
+ display_string(&(ivac->display),8,ivac->display.max_y-1,
+ string,ivac->display.max_x);
+
return SUCCESS;
}
/* display console content */
ivac_display_console_content(ivac);
+ /* display prompt content */
+ ivac_display_prompt_content(ivac);
+
return SUCCESS;
}
int ivac_display(t_ivac *ivac) {
- int x,y;
-
/* display static head */
ivac_display_head(ivac);
int ivac_display_draw(t_ivac *ivac) {
- display_draw_until_line(&(ivac->display),ivac->display.max_y-1);
- ivac_display_prompt(ivac);
+ display_draw(&(ivac->display));
+ display_set_cursor(&(ivac->display),ivac->input.c_count+8,
+ ivac->display.max_y-1);
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);
+ ivac_display_console_content(ivac);
+ ivac_display_draw(ivac);
+
return SUCCESS;
}