diff --git a/src/sbbs3/answer.cpp b/src/sbbs3/answer.cpp index 52a60853880877f3de21e7b88b826621f66d0c63..feb5d7292ae663964e93586db663cf5db93bb4d1 100644 --- a/src/sbbs3/answer.cpp +++ b/src/sbbs3/answer.cpp @@ -440,14 +440,16 @@ bool sbbs_t::answer() client.usernum = useron.number; client_on(client_socket, &client,/* update: */TRUE); SAFECOPY(connection, client.protocol); - if((useron.exempt&FLAG('Q') && useron.misc&QUIET)) - thisnode.status = NODE_QUIET; - else - thisnode.status = NODE_INUSE; - thisnode.action = NODE_XFER; - thisnode.connection = NODE_CONNECTION_SFTP; - thisnode.useron = useron.number; - putnodedat(cfg.node_num, &thisnode); + if(getnodedat(cfg.node_num, &thisnode, true)) { + if((useron.exempt&FLAG('Q') && useron.misc&QUIET)) + thisnode.status = NODE_QUIET; + else + thisnode.status = NODE_INUSE; + thisnode.action = NODE_XFER; + thisnode.connection = NODE_CONNECTION_SFTP; + thisnode.useron = useron.number; + putnodedat(cfg.node_num, &thisnode); + } SAFECOPY(useron.modem, connection); SAFECOPY(useron.ipaddr, client_ipaddr); SAFECOPY(useron.comp, client_name); diff --git a/src/sbbs3/atcodes.cpp b/src/sbbs3/atcodes.cpp index e2cce3a4d1e68017fd268f6ff970b4da266d4766..ad156cea973990948a7640efc206627622851e05 100644 --- a/src/sbbs3/atcodes.cpp +++ b/src/sbbs3/atcodes.cpp @@ -1013,7 +1013,7 @@ const char* sbbs_t::atcode(const char* sp, char* str, size_t maxlen, int* pmode, if(!strncmp(sp,"NODE",4) && IS_DIGIT(sp[4])) { i=atoi(sp+4); if(i && i<=cfg.sys_nodes) { - getnodedat(i,&node,0); + getnodedat(i, &node); printnodedat(i,&node); } return(nulstr); diff --git a/src/sbbs3/bat_xfer.cpp b/src/sbbs3/bat_xfer.cpp index a65cef4ebb16eb39f74df632167ae663b569874f..4ba9116f17c28558a8d512e8c6fc8eccbd5f3adc 100644 --- a/src/sbbs3/bat_xfer.cpp +++ b/src/sbbs3/bat_xfer.cpp @@ -365,7 +365,7 @@ bool sbbs_t::start_batch_download() ,cfg.dir[batdn_dir[i]]->path ,fname); mv(str,path,1); /* copy the file to temp dir */ - if(getnodedat(cfg.node_num,&thisnode,true)==0) { + if(getnodedat(cfg.node_num,&thisnode, true)) { thisnode.aux=40; /* clear the seq dev # */ putnodedat(cfg.node_num,&thisnode); } diff --git a/src/sbbs3/bulkmail.cpp b/src/sbbs3/bulkmail.cpp index 22d4741d32658d4a48d80707e434fb8c24778aab..a5ed6aa794eab4b6b918b6a5328bccb0fa29714b 100644 --- a/src/sbbs3/bulkmail.cpp +++ b/src/sbbs3/bulkmail.cpp @@ -203,7 +203,7 @@ int sbbs_t::bulkmailhdr(smb_t* smb, smbmsg_t* msg, uint usernum) logon_emails++; useron.etoday++; for(i=1;i<=cfg.sys_nodes;i++) { /* Tell user, if online */ - getnodedat(i,&node,0); + getnodedat(i, &node); if(node.useron==usernum && !(node.misc&NODE_POFF) && (node.status==NODE_INUSE || node.status==NODE_QUIET)) { SAFEPRINTF2(str,text[EmailNodeMsg],cfg.node_num,useron.alias); diff --git a/src/sbbs3/chat.cpp b/src/sbbs3/chat.cpp index 8ad968215fd37996d56bc5b3a51133a2a359e6bc..da82a26d3ce51676c828b1d82247f538d1682347 100644 --- a/src/sbbs3/chat.cpp +++ b/src/sbbs3/chat.cpp @@ -55,7 +55,7 @@ void sbbs_t::multinodechat(int channel) if(useron.misc&(RIP) ||!(useron.misc&EXPERT)) menu("multchat"); bputs(text[WelcomeToMultiChat]); - if(getnodedat(cfg.node_num,&thisnode,true)==0) { + if(getnodedat(cfg.node_num,&thisnode, true)) { thisnode.aux=channel; putnodedat(cfg.node_num,&thisnode); } @@ -82,7 +82,7 @@ void sbbs_t::multinodechat(int channel) for(i=1;i<=cfg.sys_nodes && i<=cfg.sys_lastnode;i++) { if(i==cfg.node_num) continue; - getnodedat(i,&node,0); + getnodedat(i, &node); if(node.action!=NODE_MCHT || node.status!=NODE_INUSE) continue; if(node.aux && (node.aux&0xff)!=channel) @@ -105,7 +105,7 @@ void sbbs_t::multinodechat(int channel) for(i=1;i<=cfg.sys_nodes;i++) { if(i==cfg.node_num) continue; - getnodedat(i,&node,0); + getnodedat(i,&node); if(node.action!=NODE_MCHT || (node.aux && channel && (node.aux&0xff)!=channel)) continue; @@ -126,7 +126,7 @@ void sbbs_t::multinodechat(int channel) if(preusr[i]==usr[j]) break; if(j==usrs) { - getnodedat(preusr[i],&node,0); + getnodedat(preusr[i], &node); if(node.misc&NODE_ANON) sprintf(str,"%.80s",text[UNKNOWN_USER]); else @@ -148,7 +148,7 @@ void sbbs_t::multinodechat(int channel) if(usr[i]==preusr[j]) break; if(j==preusrs) { - getnodedat(usr[i],&node,0); + getnodedat(usr[i], &node); if(node.misc&NODE_ANON) sprintf(str,"%.80s",text[UNKNOWN_USER]); else @@ -184,7 +184,7 @@ void sbbs_t::multinodechat(int channel) for(i=1;i<=cfg.sys_nodes;i++) { if(i==cfg.node_num) continue; - getnodedat(i,&node,0); + getnodedat(i, &node); if(node.action!=NODE_MCHT || node.status!=NODE_INUSE) continue; @@ -273,7 +273,7 @@ void sbbs_t::multinodechat(int channel) for(i=1;i<=cfg.sys_nodes;i++) { if(i==cfg.node_num) continue; - getnodedat(i,&node,0); + getnodedat(i, &node); if(node.action!=NODE_MCHT || node.status!=NODE_INUSE) continue; @@ -282,7 +282,7 @@ void sbbs_t::multinodechat(int channel) usr[usrs++]=(char)i; } preusrs=usrs; - if(getnodedat(cfg.node_num,&thisnode,true)==0) { + if(getnodedat(cfg.node_num,&thisnode, true)) { thisnode.aux=channel=0; putnodedat(cfg.node_num,&thisnode); } @@ -320,7 +320,7 @@ void sbbs_t::multinodechat(int channel) case 'L': /* list nodes */ CRLF; for(i=1;i<=cfg.sys_nodes && i<=cfg.sys_lastnode;i++) { - getnodedat(i,&node,0); + getnodedat(i, &node); printnodedat(i,&node); } CRLF; @@ -439,7 +439,7 @@ void sbbs_t::multinodechat(int channel) p=pgraph+strlen(str); n=atoi(p); for(j=0;j<usrs;j++) { - getnodedat(usr[j],&node,0); + getnodedat(usr[j], &node); if(usrs==1) /* no need to search */ break; if(n) { @@ -493,11 +493,11 @@ void sbbs_t::multinodechat(int channel) for(i=0;i<usrs;i++) { if(i==j) continue; - getnodedat(usr[i],&node,0); + getnodedat(usr[i], &node); putnmsg(usr[i],buf); } for(i=0;i<qusrs;i++) { - getnodedat(qusr[i],&node,0); + getnodedat(qusr[i], &node); putnmsg(qusr[i],buf); } continue; @@ -512,11 +512,11 @@ void sbbs_t::multinodechat(int channel) if(useron.chat&CHAT_ECHO) bputs(buf); for(i=0;i<usrs;i++) { - getnodedat(usr[i],&node,0); + getnodedat(usr[i], &node); putnmsg(usr[i],buf); } for(i=0;i<qusrs;i++) { - getnodedat(qusr[i],&node,0); + getnodedat(qusr[i], &node); putnmsg(qusr[i],buf); } if(!usrs && channel && gurubuf @@ -711,12 +711,12 @@ void sbbs_t::privchat(bool forced, int node_num) bputs(text[NoNeedToPageSelf]); return; } - getnodedat(n,&node,0); + getnodedat(n, &node); if(node.action==NODE_PCHT && node.aux!=cfg.node_num) { bprintf(text[NodeNAlreadyInPChat],n); return; } - if(SYSOP && getnodedat(n, &node, true) == 0) { + if(SYSOP && getnodedat(n, &node, true)) { node.misc |= NODE_FCHAT; putnodedat(n, &node); } else { @@ -740,7 +740,7 @@ void sbbs_t::privchat(bool forced, int node_num) } } - if(getnodedat(cfg.node_num,&thisnode,true)==0) { + if(getnodedat(cfg.node_num,&thisnode, true)) { thisnode.action=action=NODE_PAGE; thisnode.aux=n; putnodedat(cfg.node_num,&thisnode); @@ -749,7 +749,7 @@ void sbbs_t::privchat(bool forced, int node_num) if(node.action!=NODE_PAGE || node.aux!=cfg.node_num) { bprintf(text[WaitingForNodeInPChat],n); while(online && !(sys_status&SS_ABORT)) { - getnodedat(n,&node,0); + getnodedat(n, &node); if((node.action==NODE_PAGE || node.action==NODE_PCHT) && node.aux==cfg.node_num) { bprintf(text[NodeJoinedPrivateChat] @@ -768,7 +768,7 @@ void sbbs_t::privchat(bool forced, int node_num) gettimeleft(); - if(getnodedat(cfg.node_num,&thisnode,true)==0) { + if(getnodedat(cfg.node_num,&thisnode, true)) { thisnode.action=action=NODE_PCHT; thisnode.aux=n; thisnode.misc&=~ (NODE_LCHAT|NODE_FCHAT); @@ -834,13 +834,13 @@ void sbbs_t::privchat(bool forced, int node_num) lseek(in,0L,SEEK_SET); lseek(out,0L,SEEK_SET); - if(getnodedat(cfg.node_num,&thisnode,true)==0) { + if(getnodedat(cfg.node_num,&thisnode, true)) { thisnode.misc&=~NODE_RPCHT; /* Clear "reset pchat flag" */ putnodedat(cfg.node_num,&thisnode); } if(n) { // not local - if(getnodedat(n,&node,true)==0) { + if(getnodedat(n, &node, true)) { node.misc|=NODE_RPCHT; /* Set "reset pchat flag" */ putnodedat(n,&node); /* on other node */ } @@ -848,10 +848,10 @@ void sbbs_t::privchat(bool forced, int node_num) /* Wait for other node */ /* to acknowledge and reset */ while(online && !(sys_status&SS_ABORT)) { - getnodedat(n,&node,0); + getnodedat(n, &node); if(!(node.misc&NODE_RPCHT)) break; - getnodedat(cfg.node_num,&thisnode,0); + getnodedat(cfg.node_num, &thisnode); if(thisnode.misc&NODE_RPCHT) break; checkline(); @@ -1114,12 +1114,12 @@ void sbbs_t::privchat(bool forced, int node_num) if(!localchar) { if(sys_status&SS_SPLITP) { - getnodedat(cfg.node_num,&thisnode,0); + getnodedat(cfg.node_num, &thisnode); if(thisnode.misc&NODE_INTR) break; if(thisnode.misc&NODE_UDAT && !(useron.rest&FLAG('G'))) { getuserdat(&cfg,&useron); - if(getnodedat(cfg.node_num,&thisnode,true)==0) { + if(getnodedat(cfg.node_num,&thisnode, true)) { thisnode.misc&=~NODE_UDAT; putnodedat(cfg.node_num,&thisnode); } @@ -1130,7 +1130,7 @@ void sbbs_t::privchat(bool forced, int node_num) } if(n != 0) { - getnodedat(n,&node,0); + getnodedat(n, &node); if((node.action!=NODE_PCHT && node.action!=NODE_PAGE) || node.aux!=cfg.node_num) { bprintf(text[NodeLeftPrivateChat] @@ -1139,7 +1139,7 @@ void sbbs_t::privchat(bool forced, int node_num) break; } } - getnodedat(cfg.node_num,&thisnode,0); + getnodedat(cfg.node_num, &thisnode); if(thisnode.action!=NODE_PCHT) { action=thisnode.action; bputs(text[EndOfChat]); @@ -1148,7 +1148,7 @@ void sbbs_t::privchat(bool forced, int node_num) if(thisnode.misc&NODE_RPCHT) { /* pchat has been reset */ lseek(in,0L,SEEK_SET); /* so seek to beginning */ lseek(out,0L,SEEK_SET); - if(getnodedat(cfg.node_num,&thisnode,true)==0) { + if(getnodedat(cfg.node_num,&thisnode, true)) { thisnode.misc&=~NODE_RPCHT; putnodedat(cfg.node_num,&thisnode); } @@ -1175,12 +1175,12 @@ int sbbs_t::getnodetopage(int all, int telegram) if(!lastnodemsg) lastnodemsguser[0]=0; if(lastnodemsg) { - getnodedat(lastnodemsg,&node,0); + getnodedat(lastnodemsg, &node); if(node.status!=NODE_INUSE && !SYSOP) lastnodemsg=1; } for(j=0,i=1;i<=cfg.sys_nodes && i<=cfg.sys_lastnode;i++) { - getnodedat(i,&node,0); + getnodedat(i, &node); if(i==cfg.node_num) continue; if(node.status==NODE_INUSE || (SYSOP && node.status >= NODE_LOGON && node.status <= NODE_QUIET)) { @@ -1215,7 +1215,7 @@ int sbbs_t::getnodetopage(int all, int telegram) j=atoi(str); if(j && j<=cfg.sys_lastnode && j<=cfg.sys_nodes) { - getnodedat(j,&node,0); + getnodedat(j, &node); if(node.useron == 0 || (node.status!=NODE_INUSE && !SYSOP)) { bprintf(text[NodeNIsNotInUse],j); return(0); @@ -1254,7 +1254,7 @@ int sbbs_t::getnodetopage(int all, int telegram) } for(i=1;i<=cfg.sys_nodes && i<=cfg.sys_lastnode;i++) { - getnodedat(i,&node,0); + getnodedat(i, &node); if((node.status==NODE_INUSE || (SYSOP && node.status==NODE_QUIET)) && node.useron==j) { if(telegram && node.misc&NODE_POFF && !SYSOP) { @@ -1296,7 +1296,7 @@ void sbbs_t::nodemsg() return; } sys_status|=SS_IN_CTRLP; - getnodedat(cfg.node_num,&savenode,0); + getnodedat(cfg.node_num, &savenode); wordwrap[0]=0; while(online && !done) { if(useron.rest&FLAG('C')) { @@ -1312,7 +1312,7 @@ void sbbs_t::nodemsg() break; if(sys_status&SS_ABORT) break; - if(getnodedat(cfg.node_num,&thisnode,false)==0) { + if(getnodedat(cfg.node_num,&thisnode, false)) { if(thisnode.misc&(NODE_MSGW|NODE_NMSG)) { lncntr=0; /* prevent pause prompt */ saveline(); @@ -1392,7 +1392,7 @@ void sbbs_t::nodemsg() if(!i) break; if(i!=-1) { - getnodedat(i,&node,0); + getnodedat(i, &node); usernumber=node.useron; if(node.misc&NODE_POFF && !SYSOP) bprintf(text[CantPageNode],node.misc&NODE_ANON @@ -1428,7 +1428,7 @@ void sbbs_t::nodemsg() for(i=1;i<=cfg.sys_nodes;i++) { if(i==cfg.node_num) continue; - getnodedat(i,&node,0); + getnodedat(i, &node); if((node.status==NODE_INUSE || (SYSOP && node.status==NODE_QUIET)) && (SYSOP || !(node.misc&NODE_POFF))) @@ -1457,7 +1457,7 @@ void sbbs_t::nodemsg() nodemsg_inside--; if(!nodemsg_inside) sys_status&=~SS_IN_CTRLP; - if(getnodedat(cfg.node_num,&thisnode,true)==0) { + if(getnodedat(cfg.node_num, &thisnode, true)) { thisnode.action=action=savenode.action; thisnode.aux=savenode.aux; thisnode.extaux=savenode.extaux; @@ -1931,7 +1931,7 @@ void sbbs_t::localguru(char *gurubuf, int gurunum) } } bprintf(text[SysopIsHere],cfg.guru[gurunum]->name); - if(getnodedat(cfg.node_num,&thisnode,true)==0) { + if(getnodedat(cfg.node_num,&thisnode, true)) { thisnode.aux=gurunum; putnodedat(cfg.node_num,&thisnode); } diff --git a/src/sbbs3/download.cpp b/src/sbbs3/download.cpp index 9d0c3d9a4d4dfc3f7314e4a259ded06f409743cc..dfa77f8de96c3fab2c4b37d61fdc4aa889ec1295 100644 --- a/src/sbbs3/download.cpp +++ b/src/sbbs3/download.cpp @@ -367,7 +367,7 @@ void sbbs_t::seqwait(uint devnum) getnodedat(cfg.node_num,&thisnode,true); /* open and lock this record */ for(i=1;i<=cfg.sys_nodes;i++) { if(i==cfg.node_num) continue; - if(getnodedat(i,&node,true)==0) { + if(getnodedat(i,&node, true)) { if((node.status==NODE_INUSE || node.status==NODE_QUIET) && node.action==NODE_RFSD && node.aux==devnum) { putnodedat(i,&node); diff --git a/src/sbbs3/email.cpp b/src/sbbs3/email.cpp index 7280472fc0d8eeb9f15d0098d3199c6699ba8ba2..77e345d418f286b5f86088c07af3bbb786143a31 100644 --- a/src/sbbs3/email.cpp +++ b/src/sbbs3/email.cpp @@ -315,7 +315,7 @@ bool sbbs_t::email(int usernumber, const char *top, const char *subj, int mode, if(msgattr&MSG_ANONYMOUS) /* Don't tell user if anonymous */ return(true); for(i=1;i<=cfg.sys_nodes;i++) { /* Tell user, if online */ - getnodedat(i,&node,0); + getnodedat(i, &node); if(node.useron==usernumber && !(node.misc&NODE_POFF) && (node.status==NODE_INUSE || node.status==NODE_QUIET)) { safe_snprintf(str,sizeof(str),text[EmailNodeMsg],cfg.node_num,useron.alias); diff --git a/src/sbbs3/exec.cpp b/src/sbbs3/exec.cpp index 0e82751b785ce28ada096ae081bacc2de9d941b8..f3b9c33ce34c8330aa64e5da4e8d57fb1037443e 100644 --- a/src/sbbs3/exec.cpp +++ b/src/sbbs3/exec.cpp @@ -1430,14 +1430,14 @@ int sbbs_t::exec(csi_t *csi) csi->ip+=2; return(0); case CS_TOGGLE_NODE_MISC: - if(getnodedat(cfg.node_num,&thisnode,true)==0) { + if(getnodedat(cfg.node_num,&thisnode, true)) { thisnode.misc^=*(ushort *)csi->ip; putnodedat(cfg.node_num,&thisnode); } csi->ip+=2; return(0); case CS_COMPARE_NODE_MISC: - getnodedat(cfg.node_num,&thisnode,0); + getnodedat(cfg.node_num, &thisnode); if((thisnode.misc&*(ushort *)csi->ip)==*(ushort *)csi->ip) csi->logic=LOGIC_TRUE; else @@ -1568,7 +1568,7 @@ int sbbs_t::exec(csi_t *csi) action=*csi->ip++; return(0); case CS_NODE_STATUS: - if(getnodedat(cfg.node_num,&thisnode,true)==0) { + if(getnodedat(cfg.node_num,&thisnode, true)) { thisnode.status=*csi->ip++; putnodedat(cfg.node_num,&thisnode); } else @@ -1854,7 +1854,7 @@ int sbbs_t::exec(csi_t *csi) csi->logic=!chksyspass(); return(0); case CS_PUT_NODE: - if(getnodedat(cfg.node_num,&thisnode,true)==0) + if(getnodedat(cfg.node_num,&thisnode, true)) putnodedat(cfg.node_num,&thisnode); return(0); case CS_SYNC: diff --git a/src/sbbs3/execfunc.cpp b/src/sbbs3/execfunc.cpp index cfea699fb2741970b99232a20e8388ddd3337885..a3eaf7ffc8ca3e0ce69434e984c4d8db9230f1ec 100644 --- a/src/sbbs3/execfunc.cpp +++ b/src/sbbs3/execfunc.cpp @@ -256,14 +256,14 @@ int sbbs_t::exec_function(csi_t *csi) else bprintf(text[FileDoesNotExist],str); for(i=1;i<=cfg.sys_nodes;i++) { - getnodedat(i,&node,0); + getnodedat(i, &node); if(node.errors) break; } if(i<=cfg.sys_nodes || criterrs) { if(text[ClearErrCounter][0]==0 || !noyes(text[ClearErrCounter])) { for(i=1;i<=cfg.sys_nodes;i++) { - if(getnodedat(i,&node,true)==0) { + if(getnodedat(i,&node, true)) { node.errors=0; putnodedat(i,&node); } diff --git a/src/sbbs3/getkey.cpp b/src/sbbs3/getkey.cpp index c0ce86b62febe9230ac3f1f81421def9d61d193c..04c97f66d76aa17332f2c1def34c11ea0fd911f9 100644 --- a/src/sbbs3/getkey.cpp +++ b/src/sbbs3/getkey.cpp @@ -456,7 +456,7 @@ bool sbbs_t::pause(bool set_abort) lncntr=rows-2; if(text[Pause][0]!='@') backspace(len); - getnodedat(cfg.node_num,&thisnode,0); + getnodedat(cfg.node_num, &thisnode); nodesync(); attr(tempattrs); pause_inside = false; diff --git a/src/sbbs3/getnode.cpp b/src/sbbs3/getnode.cpp index cb789b81019eabde9c291818957ea9d4435d66c8..f3bbf7e5822d7901da620550720ae571596734b9 100644 --- a/src/sbbs3/getnode.cpp +++ b/src/sbbs3/getnode.cpp @@ -27,18 +27,18 @@ /* from NODE.DAB */ /* if lockit is non-zero, locks this node's record. putnodedat() unlocks it */ /****************************************************************************/ -int sbbs_t::getnodedat(uint number, node_t *node, bool lockit) +bool sbbs_t::getnodedat(uint number, node_t *node, bool lockit) { char str[MAX_PATH+1]; int rd=sizeof(node_t); int count; if(node==NULL || number<1) - return(-1); + return false; if(number>cfg.sys_nodes) { errormsg(WHERE,ERR_CHK,"node number",number); - return(-1); + return false; } if(node!=&thisnode) @@ -49,7 +49,7 @@ int sbbs_t::getnodedat(uint number, node_t *node, bool lockit) if((nodefile=nopen(str,O_RDWR|O_DENYNONE))==-1) { pthread_mutex_unlock(&nodefile_mutex); errormsg(WHERE,ERR_OPEN,str,O_RDWR|O_DENYNONE); - return(errno); + return false; } } #if 0 // This leads to high disk (or Samba/file server) utilization as we call getnodedat() a lot @@ -82,7 +82,7 @@ int sbbs_t::getnodedat(uint number, node_t *node, bool lockit) nodefile=-1; pthread_mutex_unlock(&nodefile_mutex); errormsg(WHERE,rd==sizeof(node_t) ? ERR_LOCK : ERR_READ,"node.dab",number+1); - return(-2); + return false; } pthread_mutex_unlock(&nodefile_mutex); if(count>(LOOP_NODEDAB/2)) { @@ -91,7 +91,7 @@ int sbbs_t::getnodedat(uint number, node_t *node, bool lockit) logline(LOG_WARNING,"!!",str); } - return(0); + return true; } static int getpagingnode(scfg_t* cfg) @@ -122,7 +122,7 @@ void sbbs_t::nodesync(bool clearline) nodesync_inside=1; if(thisnode.action!=action) { - if(getnodedat(cfg.node_num,&thisnode,true)==0) { + if(getnodedat(cfg.node_num,&thisnode, true)) { thisnode.action=action; putnodedat(cfg.node_num,&thisnode); } @@ -134,7 +134,7 @@ void sbbs_t::nodesync(bool clearline) if(thisnode.status==NODE_WFC) { lprintf(LOG_ERR, "Node %d NODE STATUS FIXUP", cfg.node_num); - if(getnodedat(cfg.node_num,&thisnode,true)==0) { + if(getnodedat(cfg.node_num,&thisnode, true)) { thisnode.status=NODE_INUSE; thisnode.useron=useron.number; putnodedat(cfg.node_num,&thisnode); @@ -152,7 +152,7 @@ void sbbs_t::nodesync(bool clearline) } if(thisnode.misc&NODE_UDAT && !(useron.rest&FLAG('G'))) { /* not guest */ getuserdat(&cfg, &useron); - if(getnodedat(cfg.node_num,&thisnode,true)==0) { + if(getnodedat(cfg.node_num,&thisnode, true)) { thisnode.misc&=~NODE_UDAT; putnodedat(cfg.node_num,&thisnode); } @@ -191,7 +191,7 @@ void sbbs_t::nodesync(bool clearline) action = save_action; restoreline(); } - if(getnodedat(cfg.node_num, &thisnode, true)==0) { + if(getnodedat(cfg.node_num, &thisnode, true)) { thisnode.action = action; thisnode.misc &= ~NODE_FCHAT; putnodedat(cfg.node_num, &thisnode); @@ -221,41 +221,41 @@ void sbbs_t::nodesync(bool clearline) /****************************************************************************/ /* Prints short messages waiting for this node, if any... */ /****************************************************************************/ -int sbbs_t::getnmsg(bool clearline) +bool sbbs_t::getnmsg(bool clearline) { char str[MAX_PATH+1], *buf; int file; long length; - if(getnodedat(cfg.node_num,&thisnode,true)==0) { + if(getnodedat(cfg.node_num,&thisnode, true)) { thisnode.misc&=~NODE_NMSG; /* clear the NMSG flag */ putnodedat(cfg.node_num,&thisnode); } SAFEPRINTF2(str,"%smsgs/n%3.3u.msg",cfg.data_dir,cfg.node_num); if(flength(str)<1L) - return(0); + return true; if((file=nopen(str,O_RDWR))==-1) { /** errormsg(WHERE,ERR_OPEN,str,O_RDWR); **/ - return(errno); + return false; } length=(long)filelength(file); if(length <= 0) { close(file); - return(0); + return true; } if((buf=(char *)malloc(length+1))==NULL) { close(file); errormsg(WHERE,ERR_ALLOC,str,length+1); - return(-1); + return false; } if(read(file,buf,length)!=length) { close(file); free(buf); errormsg(WHERE,ERR_READ,str,length); - return(errno); + return false; } int retval = chsize(file,0L); close(file); @@ -268,27 +268,27 @@ int sbbs_t::getnmsg(bool clearline) putmsg(buf,P_NOATCODES); free(buf); - return retval; + return retval == 0; } /****************************************************************************/ /* 'ext' must be at least 128 bytes! */ /****************************************************************************/ -int sbbs_t::getnodeext(uint number, char *ext) +bool sbbs_t::getnodeext(uint number, char *ext) { char str[MAX_PATH+1]; int rd,count; - if(!number || number>cfg.sys_nodes) { + if(number < 1 || number>cfg.sys_nodes) { errormsg(WHERE,ERR_CHK,"node number",number); - return(-1); + return false; } SAFEPRINTF(str,"%snode.exb",cfg.ctrl_dir); if((node_ext=nopen(str,O_RDONLY|O_DENYNONE))==-1) { memset(ext,0,128); errormsg(WHERE,ERR_OPEN,str,O_RDONLY|O_DENYNONE); - return(errno); + return false; } number--; /* make zero based */ @@ -309,7 +309,7 @@ int sbbs_t::getnodeext(uint number, char *ext) if(count==LOOP_NODEDAB) { errormsg(WHERE,ERR_READ,"node.exb",number+1); - return(-2); + return false; } if(count>(LOOP_NODEDAB/2)) { SAFEPRINTF2(str,"NODE.EXB (node %d) COLLISION - Count: %d" @@ -317,24 +317,23 @@ int sbbs_t::getnodeext(uint number, char *ext) logline("!!",str); } - return(0); + return true; } - /****************************************************************************/ /* Prints short messages waiting for 'usernumber', if any... */ /* then truncates the file. */ /****************************************************************************/ -int sbbs_t::getsmsg(int usernumber, bool clearline) +bool sbbs_t::getsmsg(int usernumber, bool clearline) { char *buf; node_t node; int i; for(i=1;i<=cfg.sys_nodes;i++) { /* clear msg waiting flag */ - if(getnodedat(i,&node,false) != 0 || node.useron != usernumber) + if(!getnodedat(i,&node,false) || node.useron != usernumber) continue; - if(getnodedat(i,&node,true)==0) { + if(getnodedat(i,&node, true)) { if(node.useron==usernumber && (node.status==NODE_INUSE || node.status==NODE_QUIET) && node.misc&NODE_MSGW) @@ -344,8 +343,8 @@ int sbbs_t::getsmsg(int usernumber, bool clearline) } if((buf = readsmsg(&cfg, usernumber)) == NULL) - return -1; - getnodedat(cfg.node_num,&thisnode,0); + return false; + getnodedat(cfg.node_num,&thisnode); if(clearline) this->clearline(); else @@ -354,7 +353,7 @@ int sbbs_t::getsmsg(int usernumber, bool clearline) putmsg(buf,P_NOATCODES); free(buf); - return(0); + return true; } /****************************************************************************/ @@ -374,7 +373,7 @@ int sbbs_t::whos_online(bool listself) CRLF; bputs(text[NodeLstHdr]); for(j=0,i=1;i<=cfg.sys_nodes && i<=cfg.sys_lastnode;i++) { - getnodedat(i,&node,false); + getnodedat(i,&node); if(i==cfg.node_num) { if(listself) printnodedat(i,&node); @@ -404,7 +403,7 @@ void sbbs_t::nodelist(void) CRLF; bputs(text[NodeLstHdr]); for(int i=1;i<=cfg.sys_nodes && i<=cfg.sys_lastnode;i++) { - getnodedat(i,&node,false); + getnodedat(i,&node); printnodedat(i,&node); } } @@ -675,7 +674,7 @@ uint sbbs_t::count_nodes(bool self) for(int i=1; i<=cfg.sys_nodes && i<=cfg.sys_lastnode; i++) { node_t node; - if(getnodedat(i, &node, false) != 0) + if(!getnodedat(i, &node)) continue; if(!self && i==cfg.node_num) continue; diff --git a/src/sbbs3/js_bbs.cpp b/src/sbbs3/js_bbs.cpp index 0f6064515b7fdae0e415b9b3be430e0eaf792e8f..03e78623b38c83867a86f2834ddb2e36baf3431b 100644 --- a/src/sbbs3/js_bbs.cpp +++ b/src/sbbs3/js_bbs.cpp @@ -1292,7 +1292,7 @@ js_nodesync(JSContext *cx, uintN argc, jsval *arglist) clearline = JSVAL_TO_BOOLEAN(argv[0]); rc=JS_SUSPENDREQUEST(cx); - sbbs->getnodedat(sbbs->cfg.node_num,&sbbs->thisnode,0); + sbbs->getnodedat(sbbs->cfg.node_num,&sbbs->thisnode); sbbs->nodesync(clearline ? true : false); JS_RESUMEREQUEST(cx, rc); @@ -3434,7 +3434,7 @@ js_put_node_message(JSContext *cx, uintN argc, jsval *arglist) int usernumber = 0; node_t node{}; if(nodenum >= 1) { /* !all */ - sbbs->getnodedat(nodenum, &node, false); + sbbs->getnodedat(nodenum, &node); usernumber = node.useron; if((node.misc&NODE_POFF) && !is_user_sysop(&sbbs->useron)) { sbbs->bprintf(sbbs->text[CantPageNode] @@ -3480,7 +3480,7 @@ js_put_node_message(JSContext *cx, uintN argc, jsval *arglist) for(int i=1; i<=sbbs->cfg.sys_nodes && success; i++) { if(i==sbbs->cfg.node_num) continue; - sbbs->getnodedat(i, &node, false); + sbbs->getnodedat(i, &node); if((node.status==NODE_INUSE || (is_user_sysop(&sbbs->useron) && node.status==NODE_QUIET)) && (is_user_sysop(&sbbs->useron) || !(node.misc&NODE_POFF))) diff --git a/src/sbbs3/listfile.cpp b/src/sbbs3/listfile.cpp index c37f7856c916a712bfc02cb15a8ea2c9510bd665..2fb2280f936e305fc75477936cda74ac1e5c7f80 100644 --- a/src/sbbs3/listfile.cpp +++ b/src/sbbs3/listfile.cpp @@ -92,9 +92,9 @@ int sbbs_t::listfiles(const int dirnum, const char *filespec, FILE* tofile, cons } if(!tofile) { - getnodedat(cfg.node_num,&thisnode,0); + getnodedat(cfg.node_num, &thisnode); if(thisnode.action!=NODE_LFIL) { /* was a sync */ - if(getnodedat(cfg.node_num,&thisnode,true)==0) { + if(getnodedat(cfg.node_num,&thisnode, true)) { thisnode.action=NODE_LFIL; putnodedat(cfg.node_num,&thisnode); } @@ -133,7 +133,7 @@ int sbbs_t::listfiles(const int dirnum, const char *filespec, FILE* tofile, cons } else break; - getnodedat(cfg.node_num,&thisnode,0); + getnodedat(cfg.node_num,&thisnode); nodesync(); } else @@ -318,7 +318,7 @@ int sbbs_t::listfiles(const int dirnum, const char *filespec, FILE* tofile, cons found-=letter-'A'+1; } } - getnodedat(cfg.node_num,&thisnode,0); + getnodedat(cfg.node_num,&thisnode); nodesync(); letter='A'; } @@ -1050,7 +1050,7 @@ int sbbs_t::listfileinfo(const int dirnum, const char *filespec, const int mode) getfilepath(&cfg, f, str); SAFEPRINTF2(path,"%s%s",cfg.temp_dir,f->name); mv(str,path,1); /* copy the file to temp dir */ - if(getnodedat(cfg.node_num,&thisnode,true)==0) { + if(getnodedat(cfg.node_num,&thisnode, true)) { thisnode.aux=0xf0; putnodedat(cfg.node_num,&thisnode); } diff --git a/src/sbbs3/logfile.cpp b/src/sbbs3/logfile.cpp index 42d441452f18365f579590e069e1cefdada80ec4..29d986902a8cd46584532bba8e8c2f3ba7b520ca 100644 --- a/src/sbbs3/logfile.cpp +++ b/src/sbbs3/logfile.cpp @@ -310,11 +310,12 @@ void sbbs_t::errormsg(int line, const char* function, const char *src, const cha } safe_snprintf(str,sizeof(str),"ERROR %s %s", action, object); if(cfg.node_num>0) { - getnodedat(cfg.node_num,&thisnode,1); - if(thisnode.errors<UCHAR_MAX) - thisnode.errors++; - criterrs=thisnode.errors; - putnodedat(cfg.node_num,&thisnode); + if(getnodedat(cfg.node_num,&thisnode, true)) { + if(thisnode.errors<UCHAR_MAX) + thisnode.errors++; + criterrs=thisnode.errors; + putnodedat(cfg.node_num,&thisnode); + } } now=time(NULL); diff --git a/src/sbbs3/logon.cpp b/src/sbbs3/logon.cpp index ecf2681b5ff786ed22268b3aaae7d114ee0e3009..1a18dd60eb43919dd77363b1f9a89a1eb0e14edd 100644 --- a/src/sbbs3/logon.cpp +++ b/src/sbbs3/logon.cpp @@ -109,9 +109,9 @@ bool sbbs_t::logon() return(false); } - getnodedat(cfg.node_num,&thisnode,1); + getnodedat(cfg.node_num,&thisnode, true); if(thisnode.misc&NODE_LOCK) { - putnodedat(cfg.node_num,&thisnode); /* must unlock! */ + unlocknodedat(cfg.node_num); /* must unlock! */ if(!SYSOP && !(useron.exempt&FLAG('N'))) { bputs(text[NodeLocked]); safe_snprintf(str, sizeof(str), "(%04u) %-25s Locked node logon attempt" @@ -121,12 +121,12 @@ bool sbbs_t::logon() return(false); } if(yesno(text[RemoveNodeLockQ])) { - getnodedat(cfg.node_num,&thisnode,1); + getnodedat(cfg.node_num,&thisnode, true); logline("S-","Removed Node Lock"); thisnode.misc&=~NODE_LOCK; } else - getnodedat(cfg.node_num,&thisnode,1); + getnodedat(cfg.node_num,&thisnode, true); } if(useron.exempt&FLAG('H')) @@ -515,20 +515,21 @@ bool sbbs_t::logon() if(sys_status&SS_EVENT) bprintf(text[ReducedTime],timestr(event_time)); - getnodedat(cfg.node_num,&thisnode,1); - thisnode.misc&=~(NODE_AOFF|NODE_POFF); - if(useron.chat&CHAT_NOACT) - thisnode.misc|=NODE_AOFF; - if(useron.chat&CHAT_NOPAGE) - thisnode.misc|=NODE_POFF; - putnodedat(cfg.node_num,&thisnode); + if(getnodedat(cfg.node_num,&thisnode, true)) { + thisnode.misc&=~(NODE_AOFF|NODE_POFF); + if(useron.chat&CHAT_NOACT) + thisnode.misc|=NODE_AOFF; + if(useron.chat&CHAT_NOPAGE) + thisnode.misc|=NODE_POFF; + putnodedat(cfg.node_num,&thisnode); + } getsmsg(useron.number); /* Moved from further down */ sync(); c=0; for(i=1;i<=cfg.sys_nodes;i++) { if(i!=cfg.node_num) { - getnodedat(i,&node,0); + getnodedat(i, &node); if(!(cfg.sys_misc&SM_NONODELIST) && (node.status==NODE_INUSE || ((node.status==NODE_QUIET || node.errors) && SYSOP))) { @@ -550,7 +551,7 @@ bool sbbs_t::logon() } for(i=1;i<=cfg.sys_nodes;i++) { if(i!=cfg.node_num) { - getnodedat(i,&node,0); + getnodedat(i, &node); if(thisnode.status!=NODE_QUIET && (node.status==NODE_INUSE || node.status==NODE_QUIET) && !(node.misc&NODE_AOFF) && node.useron!=useron.number) { @@ -642,9 +643,10 @@ uint sbbs_t::logonstats() close(file); for(i=0;i<=cfg.sys_nodes;i++) { if(i) { /* updating a node */ - getnodedat(i,&node,1); - node.misc|=NODE_EVENT; - putnodedat(i,&node); + if(getnodedat(i,&node, true)) { + node.misc|=NODE_EVENT; + putnodedat(i,&node); + } } dstats_fname(&cfg, i, path, sizeof path); backup(path, 90, /* rename: */false); diff --git a/src/sbbs3/logout.cpp b/src/sbbs3/logout.cpp index 27234c1e8cf275aa21be6a01a02c7dc040840f0b..fbab736b61467061183d50d88902558b90f80044 100644 --- a/src/sbbs3/logout.cpp +++ b/src/sbbs3/logout.cpp @@ -47,7 +47,7 @@ void sbbs_t::logout(bool logged_in) } lprintf(LOG_INFO, "logout initiated"); SAFECOPY(lastuseron,useron.alias); // TODO: race condition here - if(!online && getnodedat(cfg.node_num, &node, /* lock: */true) == 0) { + if(!online && getnodedat(cfg.node_num, &node, /* lock: */true)) { node.status = NODE_LOGOUT; putnodedat(cfg.node_num, &node); } @@ -60,7 +60,7 @@ void sbbs_t::logout(bool logged_in) if(sys_status&SS_USERON && thisnode.status!=NODE_QUIET && !(useron.rest&FLAG('Q')) && logged_in) for(i=1;i<=cfg.sys_nodes;i++) if(i!=cfg.node_num) { - getnodedat(i,&node,0); + getnodedat(i, &node); if((node.status==NODE_INUSE || node.status==NODE_QUIET) && !(node.misc&NODE_AOFF) && node.useron!=useron.number) { putnmsg(i, format_text(NodeLoggedOff diff --git a/src/sbbs3/mail.cpp b/src/sbbs3/mail.cpp index c3ceb9797703d92679718abca57c0485136759d7..b384e26d72ad5e54ececdd30d8289aea5f527d7a 100644 --- a/src/sbbs3/mail.cpp +++ b/src/sbbs3/mail.cpp @@ -136,7 +136,7 @@ void sbbs_t::telluser(smbmsg_t* msg) return; } for(n=1;n<=cfg.sys_nodes;n++) { /* Tell user */ - getnodedat(n,&node,0); + getnodedat(n, &node); if(node.useron==usernumber && (node.status==NODE_INUSE || node.status==NODE_QUIET)) { diff --git a/src/sbbs3/main.cpp b/src/sbbs3/main.cpp index bb97704068a9cdd2d918497341ba20e4dc3ad445..f27426359a14a6454caea93c6978d746a09fa229 100644 --- a/src/sbbs3/main.cpp +++ b/src/sbbs3/main.cpp @@ -3047,12 +3047,13 @@ void event_thread(void* arg) for(i=first_node;i<=last_node;i++) { // Node Daily Event node.status=NODE_INVALID_STATUS; - if(sbbs->getnodedat(i,&node,0)!=0) + if(!sbbs->getnodedat(i,&node)) continue; if(node.misc&NODE_EVENT && node.status==NODE_WFC) { - sbbs->getnodedat(i,&node,1); - node.status=NODE_EVENT_RUNNING; - sbbs->putnodedat(i,&node); + if(sbbs->getnodedat(i,&node, true)) { + node.status=NODE_EVENT_RUNNING; + sbbs->putnodedat(i,&node); + } if(sbbs->cfg.node_daily.cmd[0] && !(sbbs->cfg.node_daily.misc & EVENT_DISABLED)) { sbbs->cfg.node_num=i; SAFECOPY(sbbs->cfg.node_dir, sbbs->cfg.node_path[i-1]); @@ -3067,11 +3068,12 @@ void event_thread(void* arg) sbbs->console&=~CON_L_ECHO; sbbs->online=false; } - sbbs->getnodedat(i,&node,1); - node.misc&=~NODE_EVENT; - node.status=NODE_WFC; - node.useron=0; - sbbs->putnodedat(i,&node); + if(sbbs->getnodedat(i,&node, true)) { + node.misc&=~NODE_EVENT; + node.status=NODE_WFC; + node.useron=0; + sbbs->putnodedat(i,&node); + } } } sbbs->event_code = nulstr; @@ -3271,7 +3273,7 @@ void event_thread(void* arg) if(now-start>10 && now-lastnodechk<10) continue; for(j=first_node;j<=last_node;j++) { - if(sbbs->getnodedat(j,&node,1)!=0) + if(!sbbs->getnodedat(j,&node, true)) continue; if(node.status==NODE_WFC) node.status=NODE_EVENT_LIMBO; @@ -3311,7 +3313,7 @@ void event_thread(void* arg) lastnodechk=now; // Check/change the status of the nodes that we're in control of for(j=first_node;j<=last_node;j++) { - if(sbbs->getnodedat(j,&node,1)!=0) + if(!sbbs->getnodedat(j,&node, true)) continue; if(node.status==NODE_WFC) { if(j==sbbs->cfg.event[i]->node) @@ -3324,7 +3326,7 @@ void event_thread(void* arg) } for(j=1;j<=sbbs->cfg.sys_nodes;j++) { - if(sbbs->getnodedat(j,&node,0)!=0) + if(!sbbs->getnodedat(j,&node)) continue; if(j==sbbs->cfg.event[i]->node) { if(node.status!=NODE_EVENT_WAITING) @@ -3367,7 +3369,7 @@ void event_thread(void* arg) sbbs->cfg.event[i]->last=(time32_t)now; for(j=first_node;j<=last_node;j++) { node.status=NODE_INVALID_STATUS; - if(sbbs->getnodedat(j,&node,1)!=0) + if(!sbbs->getnodedat(j,&node, true)) continue; node.status=NODE_WFC; sbbs->putnodedat(j,&node); @@ -3386,9 +3388,10 @@ void event_thread(void* arg) if(fexistcase(str)) sbbs->fremove(WHERE, str); if(sbbs->cfg.event[i]->node != NODE_ANY && (sbbs->cfg.event[i]->misc&EVENT_EXCL)) { - sbbs->getnodedat(sbbs->cfg.event[i]->node,&node,1); - node.status=NODE_EVENT_RUNNING; - sbbs->putnodedat(sbbs->cfg.event[i]->node,&node); + if(sbbs->getnodedat(sbbs->cfg.event[i]->node,&node, true)) { + node.status=NODE_EVENT_RUNNING; + sbbs->putnodedat(sbbs->cfg.event[i]->node,&node); + } } const char* cmd = sbbs->cfg.event[i]->cmd; int ex_mode = EX_OFFLINE; @@ -3433,7 +3436,7 @@ void event_thread(void* arg) // Check/change the status of the nodes that we're in control of for(j=first_node;j<=last_node;j++) { node.status=NODE_INVALID_STATUS; - if(sbbs->getnodedat(j,&node,1)!=0) + if(!sbbs->getnodedat(j,&node, true)) continue; node.status=NODE_WFC; sbbs->putnodedat(j,&node); @@ -3640,14 +3643,15 @@ bool sbbs_t::init() catsyslog(true); } - getnodedat(cfg.node_num,&thisnode,1); - /* thisnode.status=0; */ - thisnode.action=0; - thisnode.useron=0; - thisnode.aux=0; - thisnode.misc&=(NODE_EVENT|NODE_LOCK|NODE_RRUN); - criterrs=thisnode.errors; - putnodedat(cfg.node_num,&thisnode); + if(getnodedat(cfg.node_num,&thisnode, true)) { + /* thisnode.status=0; */ + thisnode.action=0; + thisnode.useron=0; + thisnode.aux=0; + thisnode.misc&=(NODE_EVENT|NODE_LOCK|NODE_RRUN); + criterrs=thisnode.errors; + putnodedat(cfg.node_num,&thisnode); + } // remove any pending node messages safe_snprintf(str, sizeof(str), "%smsgs/n%3.3u.msg",cfg.data_dir,cfg.node_num); @@ -4383,7 +4387,7 @@ void node_thread(void* arg) sbbs->getnodedat(sbbs->cfg.node_num, &sbbs->thisnode, /* lock: */false); if(sbbs->thisnode.misc & NODE_UDAT && !(sbbs->useron.rest & FLAG('G'))) { /* not guest */ getuserdat(&sbbs->cfg, &sbbs->useron); - if(sbbs->getnodedat(sbbs->cfg.node_num, &sbbs->thisnode, /* lock: */true) == 0) { + if(sbbs->getnodedat(sbbs->cfg.node_num, &sbbs->thisnode, /* lock: */true)) { sbbs->thisnode.misc &= ~NODE_UDAT; sbbs->putnodedat(sbbs->cfg.node_num, &sbbs->thisnode); } @@ -4552,15 +4556,16 @@ void node_thread(void* arg) sbbs->errormsg(WHERE, "truncating", "logfile", 0); } - sbbs->getnodedat(sbbs->cfg.node_num,&node,1); - if(node.misc&NODE_DOWN) - node.status=NODE_OFFLINE; - else - node.status=NODE_WFC; - node.misc&=~(NODE_DOWN|NODE_INTR|NODE_MSGW|NODE_NMSG - |NODE_UDAT|NODE_POFF|NODE_AOFF|NODE_EXT); -/* node.useron=0; needed for hang-ups while in multinode chat */ - sbbs->putnodedat(sbbs->cfg.node_num,&node); + if(sbbs->getnodedat(sbbs->cfg.node_num,&node, true)) { + if(node.misc&NODE_DOWN) + node.status=NODE_OFFLINE; + else + node.status=NODE_WFC; + node.misc&=~(NODE_DOWN|NODE_INTR|NODE_MSGW|NODE_NMSG + |NODE_UDAT|NODE_POFF|NODE_AOFF|NODE_EXT); + /* node.useron=0; needed for hang-ups while in multinode chat */ + sbbs->putnodedat(sbbs->cfg.node_num,&node); + } { /* crash here on Aug-4-2015: @@ -4623,9 +4628,7 @@ void sbbs_t::daily_maint(void) now=time(NULL); if(cfg.node_num) { - if((i=getnodedat(cfg.node_num,&thisnode,true)) != 0) - errormsg(WHERE,ERR_LOCK,"node file",i); - else { + if(getnodedat(cfg.node_num,&thisnode, true)) { thisnode.status=NODE_EVENT_RUNNING; putnodedat(cfg.node_num,&thisnode); } @@ -5296,11 +5299,12 @@ NO_SSH: last_node=startup->last_node; for(int i=first_node;i<=last_node;i++) { - sbbs->getnodedat(i,&node,1); - node.status=NODE_WFC; - node.misc&=NODE_EVENT; /* Note: Turns-off NODE_RRUN flag (and others) */ - node.action=0; - sbbs->putnodedat(i,&node); + if(sbbs->getnodedat(i,&node, true)) { + node.status=NODE_WFC; + node.misc&=NODE_EVENT; /* Note: Turns-off NODE_RRUN flag (and others) */ + node.action=0; + sbbs->putnodedat(i,&node); + } } /* Setup recycle/shutdown semaphore file lists */ @@ -5665,13 +5669,13 @@ NO_SSH: for(node_num=first_node; node_num <= last_node; node_num++) { /* paranoia: make sure node.status!=NODE_WFC by default */ node.status=NODE_INVALID_STATUS; - if(sbbs->getnodedat(node_num,&node,1)!=0) + if(!sbbs->getnodedat(node_num,&node, true)) continue; if(node.status==NODE_WFC) { if(node_socket[node_num - 1] != INVALID_SOCKET) { lprintf(LOG_CRIT, "%04d !Node %d status is WFC, but the node socket (%d) and thread are still in use!" ,client_socket, node_num, node_socket[node_num - 1]); - sbbs->putnodedat(node_num, &node); + sbbs->unlocknodedat(node_num); continue; } node.status=NODE_LOGON; @@ -5688,7 +5692,7 @@ NO_SSH: sbbs->putnodedat(node_num, &node); break; } - sbbs->putnodedat(node_num, &node); + sbbs->unlocknodedat(node_num); } if(node_num>last_node) { @@ -5728,17 +5732,19 @@ NO_SSH: client_off(client_socket); SSH_END(client_socket); close_socket(client_socket); - sbbs->getnodedat(cfg->node_num,&node,true); - node.status = NODE_WFC; - sbbs->putnodedat(cfg->node_num,&node); + if(sbbs->getnodedat(cfg->node_num,&node, true)) { + node.status = NODE_WFC; + sbbs->putnodedat(cfg->node_num,&node); + } continue; } } cfg->node_num = node_num; // correct the node number if(node.misc & NODE_RRUN) { - sbbs->getnodedat(cfg->node_num,&node,true); - node.misc &= ~NODE_RRUN; - sbbs->putnodedat(cfg->node_num,&node); + if(sbbs->getnodedat(cfg->node_num,&node,true)) { + node.misc &= ~NODE_RRUN; + sbbs->putnodedat(cfg->node_num,&node); + } } sbbs->bputs(crlf); } @@ -5774,9 +5780,10 @@ NO_SSH: else sbbs->putcom("\r\nSorry, initialization failed. Try again later.\r\n"); sbbs->flush_output(3000); - sbbs->getnodedat(new_node->cfg.node_num,&node,1); - node.status=NODE_WFC; - sbbs->putnodedat(new_node->cfg.node_num,&node); + if(sbbs->getnodedat(new_node->cfg.node_num,&node, true)) { + node.status=NODE_WFC; + sbbs->putnodedat(new_node->cfg.node_num,&node); + } delete new_node; node_socket[node_num-1]=INVALID_SOCKET; client_off(client_socket); @@ -6012,9 +6019,10 @@ NO_SSH: // Set all nodes' status to OFFLINE for(int i=first_node;i<=last_node;i++) { - sbbs->getnodedat(i,&node,1); - node.status=NODE_OFFLINE; - sbbs->putnodedat(i,&node); + if(sbbs->getnodedat(i,&node, true)) { + node.status=NODE_OFFLINE; + sbbs->putnodedat(i,&node); + } } if(events!=NULL) { diff --git a/src/sbbs3/newuser.cpp b/src/sbbs3/newuser.cpp index b79e76a960cf3cf627900ac56bf4f9aea06123b9..5227554e7a374e36308e38c7134e8288ca597bba 100644 --- a/src/sbbs3/newuser.cpp +++ b/src/sbbs3/newuser.cpp @@ -39,7 +39,7 @@ bool sbbs_t::newuser() max_socket_inactivity = startup->max_newuser_inactivity; bputs(text[StartingNewUserRegistration]); - getnodedat(cfg.node_num,&thisnode,0); + getnodedat(cfg.node_num,&thisnode); if(thisnode.misc&NODE_LOCK) { bputs(text[NodeLocked]); logline(LOG_WARNING,"N!","New user locked node logon attempt"); @@ -52,10 +52,11 @@ bool sbbs_t::newuser() hangup(); return(false); } - getnodedat(cfg.node_num,&thisnode,1); - thisnode.status=NODE_NEWUSER; - thisnode.connection=node_connection; - putnodedat(cfg.node_num,&thisnode); + if(getnodedat(cfg.node_num,&thisnode, true)) { + thisnode.status=NODE_NEWUSER; + thisnode.connection=node_connection; + putnodedat(cfg.node_num,&thisnode); + } memset(&useron,0,sizeof(user_t)); /* Initialize user info to null */ newuserdefaults(&cfg, &useron); if(cfg.new_pass[0] && online==ON_REMOTE) { diff --git a/src/sbbs3/putnode.cpp b/src/sbbs3/putnode.cpp index 333dcea0a1eb6cb3e4be6059c76f8a1d7f372504..528237ceaad382f43458320c4464be329c576770 100644 --- a/src/sbbs3/putnode.cpp +++ b/src/sbbs3/putnode.cpp @@ -26,7 +26,7 @@ /* getnodedat(num,&node,1); must have been called before calling this func */ /* NOTE: ------^ the indicates the node record has been locked */ /****************************************************************************/ -int sbbs_t::putnodedat(uint number, node_t* node) +bool sbbs_t::putnodedat(uint number, node_t* node) { char str[256]; char path[MAX_PATH+1]; @@ -34,12 +34,9 @@ int sbbs_t::putnodedat(uint number, node_t* node) int wrerr=0; int attempts; - if(!number) - return(-1); - - if(number>cfg.sys_nodes) { + if(number < 1 || number>cfg.sys_nodes) { errormsg(WHERE,ERR_CHK,"node number",number); - return(-1); + return false; } if(number==cfg.node_num) { if((node->status==NODE_INUSE || node->status==NODE_QUIET) @@ -70,58 +67,65 @@ int sbbs_t::putnodedat(uint number, node_t* node) if((nodefile=nopen(path,O_CREAT|O_RDWR|O_DENYNONE))==-1) { errormsg(WHERE,ERR_OPEN,path,O_CREAT|O_RDWR|O_DENYNONE); pthread_mutex_unlock(&nodefile_mutex); - return(errno); + return false; } } - number--; /* make zero based */ for(attempts=0;attempts<10;attempts++) { - lseek(nodefile,(long)number*sizeof(node_t),SEEK_SET); + lseek(nodefile, (number - 1) * sizeof(node_t), SEEK_SET); wr=write(nodefile,node,sizeof(node_t)); if(wr==sizeof(node_t)) break; wrerr=errno; /* save write error */ mswait(100); } - unlock(nodefile,(long)number*sizeof(node_t),sizeof(node_t)); - if(cfg.node_misc&NM_CLOSENODEDAB) { - close(nodefile); - nodefile=-1; - } - pthread_mutex_unlock(&nodefile_mutex); + unlocknodedat(number); if(mqtt->connected) { - int result = mqtt_putnodedat(mqtt, number + 1, node); + int result = mqtt_putnodedat(mqtt, number, node); if(result != MQTT_SUCCESS) lprintf(LOG_WARNING, "ERROR %d (%d) publishing node status", result, errno); } if(wr!=sizeof(node_t)) { errno=wrerr; - errormsg(WHERE,ERR_WRITE,"nodefile",number+1); - return(errno); + errormsg(WHERE,ERR_WRITE,"nodefile",number); + return false; } - utime(path,NULL); /* Update mod time for NFS/smbfs compatibility */ + return utime(path,NULL) == 0; /* Update mod time for NFS/smbfs compatibility */ +} - return(0); +bool sbbs_t::unlocknodedat(uint number) +{ + if(number < 1 || number > cfg.sys_nodes) { + errormsg(WHERE, ERR_CHK, "node number", number); + return false; + } + int result = unlock(nodefile, (number - 1) * sizeof(node_t), sizeof(node_t)); + if(cfg.node_misc & NM_CLOSENODEDAB) { + close(nodefile); + nodefile = -1; + } + pthread_mutex_unlock(&nodefile_mutex); + return result == 0; } -int sbbs_t::putnodeext(uint number, char *ext) +bool sbbs_t::putnodeext(uint number, char *ext) { char str[MAX_PATH+1]; int count; int wr; - if(!number || number>cfg.sys_nodes) { + if(number < 1 || number>cfg.sys_nodes) { errormsg(WHERE,ERR_CHK,"node number",number); - return(-1); + return false; } number--; /* make zero based */ sprintf(str,"%snode.exb",cfg.ctrl_dir); if((node_ext=nopen(str,O_CREAT|O_RDWR|O_DENYNONE))==-1) { errormsg(WHERE,ERR_OPEN,str,O_CREAT|O_RDWR|O_DENYNONE); - return(errno); + return false; } for(count=0;count<LOOP_NODEDAB;count++) { if(count) @@ -144,10 +148,10 @@ int sbbs_t::putnodeext(uint number, char *ext) } if(count==LOOP_NODEDAB) { errormsg(WHERE,ERR_WRITE,"NODE.EXB",number+1); - return(-2); + return false; } - return(0); + return true; } bool sbbs_t::putnode_downloading(off_t size) @@ -163,8 +167,8 @@ bool sbbs_t::putnode_downloading(off_t size) struct tm tm; if(localtime_r(&t, &tm) != NULL) thisnode.aux = (tm.tm_hour * 60) + tm.tm_min; - if(getnodedat(cfg.node_num, &thisnode, /* lock-it: */true) != 0) + if(!getnodedat(cfg.node_num, &thisnode, /* lock-it: */true)) return false; thisnode.action = action; - return putnodedat(cfg.node_num, &thisnode) == 0; + return putnodedat(cfg.node_num, &thisnode); } diff --git a/src/sbbs3/readmsgs.cpp b/src/sbbs3/readmsgs.cpp index 4a03eb1d04357105291069bd9500969ec9b231fa..2ce9a5224404fbe7622cf967b7b275197c0485d2 100644 --- a/src/sbbs3/readmsgs.cpp +++ b/src/sbbs3/readmsgs.cpp @@ -553,9 +553,10 @@ int sbbs_t::scanposts(int subnum, int mode, const char *find) last=smb.status.last_msg; if(mode&SCAN_CONT) { /* update action */ - getnodedat(cfg.node_num,&thisnode,1); - thisnode.action=NODE_RMSG; - putnodedat(cfg.node_num,&thisnode); + if(getnodedat(cfg.node_num,&thisnode, true)) { + thisnode.action=NODE_RMSG; + putnodedat(cfg.node_num,&thisnode); + } } current_msg=&msg; /* For MSG_* @-codes and bbs.msg_* property values */ while(online && !done) { diff --git a/src/sbbs3/sbbs.h b/src/sbbs3/sbbs.h index 10c7d7ef9aa6cc0f1dd957757862bee306ab2a19..a3e28926624244e3c66e21119e51ce85c2730c6a 100644 --- a/src/sbbs3/sbbs.h +++ b/src/sbbs3/sbbs.h @@ -1073,22 +1073,23 @@ public: char* expand_atcodes(const char* src, char* buf, size_t size, const smbmsg_t* msg = NULL); /* getnode.cpp */ - int getsmsg(int usernumber, bool clearline = false); - int getnmsg(bool clearline = false); + bool getsmsg(int usernumber, bool clearline = false); + bool getnmsg(bool clearline = false); int whos_online(bool listself);/* Lists active nodes, returns active nodes */ void nodelist(void); - int getnodeext(uint number, char * str); - int getnodedat(uint number, node_t * node, bool lock); + bool getnodeext(uint number, char * str); + bool getnodedat(uint number, node_t * node, bool lock = false); void nodesync(bool clearline = false); user_t nodesync_user{}; bool nodesync_inside = false; uint count_nodes(bool self = true); - void sync(bool clearline = false) { getnodedat(cfg.node_num, &thisnode, 0); nodesync(clearline); } + void sync(bool clearline = false) { getnodedat(cfg.node_num, &thisnode); nodesync(clearline); } /* putnode.cpp */ - int putnodedat(uint number, node_t * node); - int putnodeext(uint number, char * str); + bool putnodedat(uint number, node_t * node); + bool putnodeext(uint number, char * str); bool putnode_downloading(off_t size); + bool unlocknodedat(uint number); /* login.ccp */ int login(const char *user_name, const char *pw_prompt, const char* user_pw = NULL, const char* sys_pw = NULL); diff --git a/src/sbbs3/str.cpp b/src/sbbs3/str.cpp index 6d08e7ee54b0d8e189eef106069016ceeb965b01..466cb58a6e2a81b3d808233b07eaabd59fb18e64 100644 --- a/src/sbbs3/str.cpp +++ b/src/sbbs3/str.cpp @@ -1386,9 +1386,10 @@ void sbbs_t::change_user(void) ,cfg.dir[usrdir[curlib][curdir[curlib]]]->code); useron.number=i; getuserdat(&cfg,&useron); - getnodedat(cfg.node_num,&thisnode,1); - thisnode.useron=useron.number; - putnodedat(cfg.node_num,&thisnode); + if(getnodedat(cfg.node_num,&thisnode, true)) { + thisnode.useron=useron.number; + putnodedat(cfg.node_num,&thisnode); + } getmsgptrs(); if(REALSYSOP) sys_status&=~SS_TMPSYSOP; else sys_status|=SS_TMPSYSOP; diff --git a/src/sbbs3/telgate.cpp b/src/sbbs3/telgate.cpp index 672c24e604c6ff1614c283810f9896de7aa4bbb2..f777c302b4eabc79f1d7e2ff719f810c8ec7dc6d 100644 --- a/src/sbbs3/telgate.cpp +++ b/src/sbbs3/telgate.cpp @@ -440,7 +440,7 @@ bool sbbs_t::telnet_gate(char* destaddr, uint mode, unsigned timeout, str_list_t sync(); } else { // Check if the node has been interrupted - getnodedat(cfg.node_num,&thisnode,0); + getnodedat(cfg.node_num,&thisnode); if(thisnode.misc&NODE_INTR) break; } diff --git a/src/sbbs3/un_rep.cpp b/src/sbbs3/un_rep.cpp index 7fbcee422bb4bf034dd94147573de8f082e47500..b2c61b32e3e74bccd75911f367ab8562311ab991 100644 --- a/src/sbbs3/un_rep.cpp +++ b/src/sbbs3/un_rep.cpp @@ -335,7 +335,7 @@ bool sbbs_t::unpack_rep(char* repfile) logline("E+",str); if(cfg.node_num) { for(k=1;k<=cfg.sys_nodes;k++) { /* Tell user, if online */ - getnodedat(k,&node,0); + getnodedat(k, &node); if(node.useron==usernum && !(node.misc&NODE_POFF) && (node.status==NODE_INUSE || node.status==NODE_QUIET)) { diff --git a/src/sbbs3/writemsg.cpp b/src/sbbs3/writemsg.cpp index 58f4146e59e6fa63caf4cf6a6bacc9cfe3133573..d244dd6c5c61621e4f3d58741b253e59fe9d582f 100644 --- a/src/sbbs3/writemsg.cpp +++ b/src/sbbs3/writemsg.cpp @@ -1637,7 +1637,7 @@ bool sbbs_t::forwardmsg(smb_t* smb, smbmsg_t* orgmsg, const char* to, const char if(usernumber > 0) { int i; for(i=1;i<=cfg.sys_nodes;i++) { /* Tell user, if online */ - getnodedat(i,&node,0); + getnodedat(i, &node); if(node.useron==usernumber && !(node.misc&NODE_POFF) && (node.status==NODE_INUSE || node.status==NODE_QUIET)) { SAFEPRINTF2(str,text[EmailNodeMsg],cfg.node_num,useron.alias); diff --git a/src/sbbs3/xtrn.cpp b/src/sbbs3/xtrn.cpp index 67db8944c655862a0fd8845a17a63477d26a7025..eac61bc186714472bdf15a61d25384af07f173bb 100644 --- a/src/sbbs3/xtrn.cpp +++ b/src/sbbs3/xtrn.cpp @@ -841,7 +841,7 @@ int sbbs_t::external(const char* cmdline, int mode, const char* startup_dir) /* only check node for interrupt flag every 3 seconds of no I/O */ if((loop_since_io%30)==0) { // Check if the node has been interrupted - getnodedat(cfg.node_num,&thisnode,0); + getnodedat(cfg.node_num, &thisnode); if(thisnode.misc&NODE_INTR) break; } diff --git a/src/sbbs3/xtrn_sec.cpp b/src/sbbs3/xtrn_sec.cpp index 598c127d651e7b05e2adcdb3325bd7ad45e9cdc2..2b22af5bca5c8aeba5e1ff9eb222d3f96ed9f9ef 100644 --- a/src/sbbs3/xtrn_sec.cpp +++ b/src/sbbs3/xtrn_sec.cpp @@ -1286,7 +1286,7 @@ bool sbbs_t::exec_xtrn(uint xtrnnum, bool user_event) if(!(cfg.xtrn[xtrnnum]->misc&MULTIUSER)) { for(i=1;i<=cfg.sys_nodes;i++) { - getnodedat(i,&node,0); + getnodedat(i, &node); c=i; if((node.status==NODE_INUSE || node.status==NODE_QUIET) && node.action==NODE_XTRN && node.aux==(xtrnnum+1)) { @@ -1349,10 +1349,11 @@ bool sbbs_t::exec_xtrn(uint xtrnnum, bool user_event) strlwr(name); SAFECAT(path,name); if(action!=NODE_PCHT) { - getnodedat(cfg.node_num,&thisnode,1); - thisnode.action=NODE_XTRN; - thisnode.aux=xtrnnum+1; - putnodedat(cfg.node_num,&thisnode); + if(getnodedat(cfg.node_num,&thisnode, true)) { + thisnode.action=NODE_XTRN; + thisnode.aux=xtrnnum+1; + putnodedat(cfg.node_num,&thisnode); + } } putuserstr(useron.number, USER_CURXTRN, cfg.xtrn[xtrnnum]->code); @@ -1464,9 +1465,10 @@ bool sbbs_t::exec_xtrn(uint xtrnnum, bool user_event) if(cfg.xtrn[xtrnnum]->misc&MODUSERDAT) /* Modify user data */ moduserdat(xtrnnum); - getnodedat(cfg.node_num,&thisnode,1); - thisnode.aux=0; - putnodedat(cfg.node_num,&thisnode); + if(getnodedat(cfg.node_num,&thisnode, true)) { + thisnode.aux=0; + putnodedat(cfg.node_num,&thisnode); + } if(cfg.xtrn[xtrnnum]->misc & XTRN_PAUSE) pause();