Skip to content
Snippets Groups Projects
Commit 1405593c 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 c7955a8a
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #160 passed
...@@ -129,7 +129,7 @@ int chat(scfg_t *cfg, int nodenum, node_t *node, box_t *boxch, void(*timecallbac ...@@ -129,7 +129,7 @@ int chat(scfg_t *cfg, int nodenum, node_t *node, box_t *boxch, void(*timecallbac
int in,out; int in,out;
char inpath[MAX_PATH]; char inpath[MAX_PATH];
char outpath[MAX_PATH]; char outpath[MAX_PATH];
char usrname[128]; char usrname[128] = "Unknown user";
char *p; char *p;
char ch; char ch;
time_t now; time_t now;
...@@ -139,34 +139,35 @@ int chat(scfg_t *cfg, int nodenum, node_t *node, box_t *boxch, void(*timecallbac ...@@ -139,34 +139,35 @@ int chat(scfg_t *cfg, int nodenum, node_t *node, box_t *boxch, void(*timecallbac
gettextinfo(&ti); gettextinfo(&ti);
if((buf=(char *)alloca(ti.screenwidth*ti.screenheight*2))==NULL) { if((buf=(char *)alloca(ti.screenwidth*ti.screenheight*2))==NULL) {
return(-1); return __LINE__;
} }
if(getnodedat(cfg,nodenum,node,FALSE,NULL)) if(getnodedat(cfg,nodenum,node,FALSE,NULL))
return(-1); return __LINE__;
username(cfg,node->useron,usrname); 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]); sprintf(outpath,"%slchat.dab",cfg->node_path[nodenum-1]);
if((out=sopen(outpath,O_RDWR|O_CREAT|O_BINARY,O_DENYNONE if((out=sopen(outpath,O_RDWR|O_CREAT|O_BINARY,O_DENYNONE
,DEFFILEMODE))==-1) ,DEFFILEMODE))==-1)
return(-1); return __LINE__;
sprintf(inpath,"%schat.dab",cfg->node_path[nodenum-1]); sprintf(inpath,"%schat.dab",cfg->node_path[nodenum-1]);
if((in=sopen(inpath,O_RDWR|O_CREAT|O_BINARY,O_DENYNONE if((in=sopen(inpath,O_RDWR|O_CREAT|O_BINARY,O_DENYNONE
,DEFFILEMODE))==-1) { ,DEFFILEMODE))==-1) {
close(out); close(out);
return(-1); return __LINE__;
} }
if((p=(char *)alloca(PCHAT_LEN))==NULL) { if((p=(char *)alloca(PCHAT_LEN))==NULL) {
close(in); close(in);
close(out); 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); memset(p,0,PCHAT_LEN);
write(in,p,PCHAT_LEN); write(in,p,PCHAT_LEN);
write(out,p,PCHAT_LEN); write(out,p,PCHAT_LEN);
......
...@@ -1192,8 +1192,11 @@ USAGE: ...@@ -1192,8 +1192,11 @@ USAGE:
uifc.msg("Error reading node data!"); uifc.msg("Error reading node data!");
continue; continue;
} }
if((node.status==NODE_INUSE) && node.useron) if((node.status==NODE_INUSE) && node.useron) {
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));
}
continue; continue;
} }
...@@ -1305,9 +1308,12 @@ USAGE: ...@@ -1305,9 +1308,12 @@ USAGE:
break; break;
case 3: /* Chat with User */ 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; break;
}
case 4: /* Node Toggles */ case 4: /* Node Toggles */
node_toggles(&cfg, j); node_toggles(&cfg, j);
break; break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment