Skip to content
Snippets Groups Projects
Commit b2b014fc authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

When chat() fails (e.g. to open a file), display an error dialog

rather than just falling over and twitching like an injured slug
parent 6f74f947
Branches
Tags
No related merge requests found
......@@ -129,7 +129,7 @@ int chat(scfg_t *cfg, int nodenum, node_t *node, box_t *boxch, void(*timecallbac
int in,out;
char inpath[MAX_PATH];
char outpath[MAX_PATH];
char usrname[128];
char usrname[128] = "Unknown user";
char *p;
char ch;
time_t now;
......@@ -139,34 +139,35 @@ int chat(scfg_t *cfg, int nodenum, node_t *node, box_t *boxch, void(*timecallbac
gettextinfo(&ti);
if((buf=(char *)alloca(ti.screenwidth*ti.screenheight*2))==NULL) {
return(-1);
return __LINE__;
}
if(getnodedat(cfg,nodenum,node,FALSE,NULL))
return(-1);
return __LINE__;
username(cfg,node->useron,usrname);
gettext(1,1,ti.screenwidth,ti.screenheight,buf);
drawchatwin(boxch,usrname,cfg->sys_op);
sprintf(outpath,"%slchat.dab",cfg->node_path[nodenum-1]);
if((out=sopen(outpath,O_RDWR|O_CREAT|O_BINARY,O_DENYNONE
,DEFFILEMODE))==-1)
return(-1);
return __LINE__;
sprintf(inpath,"%schat.dab",cfg->node_path[nodenum-1]);
if((in=sopen(inpath,O_RDWR|O_CREAT|O_BINARY,O_DENYNONE
,DEFFILEMODE))==-1) {
close(out);
return(-1);
return __LINE__;
}
if((p=(char *)alloca(PCHAT_LEN))==NULL) {
close(in);
close(out);
return(-1);
return __LINE__;
}
gettext(1,1,ti.screenwidth,ti.screenheight,buf);
drawchatwin(boxch,usrname,cfg->sys_op);
memset(p,0,PCHAT_LEN);
write(in,p,PCHAT_LEN);
write(out,p,PCHAT_LEN);
......@@ -176,7 +177,7 @@ int chat(scfg_t *cfg, int nodenum, node_t *node, box_t *boxch, void(*timecallbac
togglechat(cfg,nodenum,node,TRUE);
while(in != -1) {
now=time(NULL);
if(now!=last_nodechk) {
......
......@@ -1192,8 +1192,11 @@ USAGE:
uifc.msg("Error reading node data!");
continue;
}
if((node.status==NODE_INUSE) && node.useron)
chat(&cfg,main_dflt,&node,&boxch,NULL);
if((node.status==NODE_INUSE) && node.useron) {
int result = chat(&cfg,main_dflt,&node,&boxch,NULL);
if(result != 0)
uifc.msgf("Chat error: %d (%s)", result, strerror(errno));
}
continue;
}
......@@ -1305,9 +1308,12 @@ USAGE:
break;
case 3: /* Chat with User */
chat(&cfg,main_dflt,&node,&boxch,NULL);
{
int result = chat(&cfg,main_dflt,&node,&boxch,NULL);
if(result != 0)
uifc.msgf("Chat error %d (%s)", result, strerror(errno));
break;
}
case 4: /* Node Toggles */
node_toggles(&cfg, j);
break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment