--- sbbs/src/sbbs3/chat.cpp 2018/04/24 16:41:23 1.1.1.1 +++ sbbs/src/sbbs3/chat.cpp 2018/04/24 16:42:45 1.1.1.2 @@ -2,13 +2,13 @@ /* Synchronet real-time chat functions */ -/* $Id: chat.cpp,v 1.1.1.1 2018/04/24 16:41:23 root Exp $ */ +/* $Id: chat.cpp,v 1.1.1.2 2018/04/24 16:42:45 root Exp $ */ /**************************************************************************** * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * @@ -78,20 +78,24 @@ void sbbs_t::multinodechat(int channel) bprintf(text[WelcomeToChannelN],channel,cfg.chan[channel-1]->name); if(gurubuf) { free(gurubuf); - gurubuf=NULL; } + gurubuf=NULL; + } if(cfg.chan[channel-1]->misc&CHAN_GURU && cfg.chan[channel-1]->guruguru]->ar,&useron)) { + && chk_ar(cfg.guru[cfg.chan[channel-1]->guru]->ar,&useron,&client)) { sprintf(str,"%s%s.dat",cfg.ctrl_dir,cfg.guru[cfg.chan[channel-1]->guru]->code); if((file=nopen(str,O_RDONLY))==-1) { errormsg(WHERE,ERR_OPEN,str,O_RDONLY); - return; } - if((gurubuf=(char *)malloc(filelength(file)+1))==NULL) { + return; + } + if((gurubuf=(char *)malloc((size_t)filelength(file)+1))==NULL) { close(file); - errormsg(WHERE,ERR_ALLOC,str,filelength(file)+1); - return; } - read(file,gurubuf,filelength(file)); + errormsg(WHERE,ERR_ALLOC,str,(size_t)filelength(file)+1); + return; + } + read(file,gurubuf,(size_t)filelength(file)); gurubuf[filelength(file)]=0; - close(file); } + close(file); + } usrs=0; for(i=1;i<=cfg.sys_nodes && i<=cfg.sys_lastnode;i++) { if(i==cfg.node_num) @@ -102,7 +106,8 @@ void sbbs_t::multinodechat(int channel) if(node.aux && (node.aux&0xff)!=channel) continue; printnodedat(i,&node); - preusr[usrs]=usr[usrs++]=(char)i; } + preusr[usrs]=usr[usrs++]=(char)i; + } preusrs=usrs; if(gurubuf) bprintf(text[NodeInMultiChatLocally] @@ -124,7 +129,8 @@ void sbbs_t::multinodechat(int channel) if(node.status==NODE_QUIET) qusr[qusrs++]=(char)i; else if(node.status==NODE_INUSE) - usr[usrs++]=(char)i; } + usr[usrs++]=(char)i; + } if(preusrs>usrs) { if(!usrs && channel && cfg.chan[channel-1]->misc&CHAN_GURU && cfg.chan[channel-1]->gurumisc&CHAN_GURU && cfg.chan[channel-1]->gurumisc&CHAN_GURU && cfg.chan[savch-1]->guruguru]->ar,&useron + && chk_ar(cfg.guru[cfg.chan[savch-1]->guru]->ar,&useron,&client )) { sprintf(str,"%s%s.dat",cfg.ctrl_dir ,cfg.guru[cfg.chan[savch-1]->guru]->code); if((file=nopen(str,O_RDONLY))==-1) { errormsg(WHERE,ERR_OPEN,str,O_RDONLY); - break; } - if((gurubuf=(char *)malloc(filelength(file)+1))==NULL) { + break; + } + if((gurubuf=(char *)malloc((size_t)filelength(file)+1))==NULL) { close(file); errormsg(WHERE,ERR_ALLOC,str - ,filelength(file)+1); - break; } - read(file,gurubuf,filelength(file)); + ,(size_t)filelength(file)+1); + break; + } + read(file,gurubuf,(size_t)filelength(file)); gurubuf[filelength(file)]=0; - close(file); } + close(file); + } preusrs=usrs; if(gurubuf) bprintf(text[NodeInMultiChatLocally] @@ -243,18 +261,23 @@ void sbbs_t::multinodechat(int channel) if(getstr(str,8,K_UPPER|K_ALPHA|K_LINE)) { getnodedat(cfg.node_num,&thisnode,true); thisnode.aux=channel; - packchatpass(str,&thisnode); } + packchatpass(str,&thisnode); + } else { getnodedat(cfg.node_num,&thisnode,true); - thisnode.aux=channel; } } + thisnode.aux=channel; + } + } else { getnodedat(cfg.node_num,&thisnode,true); - thisnode.aux=channel; } + thisnode.aux=channel; + } putnodedat(cfg.node_num,&thisnode); bputs(text[YoureOnTheAir]); if(cfg.chan[channel-1]->cost && !(useron.exempt&FLAG('J'))) - subtract_cdt(&cfg,&useron,cfg.chan[channel-1]->cost); } + subtract_cdt(&cfg,&useron,cfg.chan[channel-1]->cost); + } else switch(i) { /* other command */ case '0': /* Global channel */ if(!SYSOP) @@ -268,7 +291,8 @@ void sbbs_t::multinodechat(int channel) || node.status!=NODE_INUSE) continue; printnodedat(i,&node); - preusr[usrs]=usr[usrs++]=(char)i; } + preusr[usrs]=usr[usrs++]=(char)i; + } preusrs=usrs; if(getnodedat(cfg.node_num,&thisnode,true)==0) { thisnode.aux=channel=0; @@ -292,9 +316,11 @@ void sbbs_t::multinodechat(int channel) bprintf("%-*.*s",LEN_CHATACTCMD ,LEN_CHATACTCMD,cfg.chatact[i]->cmd); if(!((i+1)%8)) { - CRLF; } + CRLF; + } else - bputs(" "); } + bputs(" "); + } CRLF; break; case 'E': /* Toggle echo */ @@ -309,7 +335,8 @@ void sbbs_t::multinodechat(int channel) CRLF; for(i=1;i<=cfg.sys_nodes && i<=cfg.sys_lastnode;i++) { getnodedat(i,&node,0); - printnodedat(i,&node); } + printnodedat(i,&node); + } CRLF; break; case 'W': /* page node(s) */ @@ -321,7 +348,8 @@ void sbbs_t::multinodechat(int channel) break; if(i>=usrs) { bputs(text[UserNotFound]); - break; } + break; + } bputs(text[NodeMsgPrompt]); if(!getstr(line,66,K_LINE|K_MSG)) @@ -349,12 +377,14 @@ void sbbs_t::multinodechat(int channel) bputs(text[ChatChanLstTitles]); if(cfg.total_chans>=10) { bputs(" "); - bputs(text[ChatChanLstTitles]); } + bputs(text[ChatChanLstTitles]); + } CRLF; bputs(text[ChatChanLstUnderline]); if(cfg.total_chans>=10) { bputs(" "); - bputs(text[ChatChanLstUnderline]); } + bputs(text[ChatChanLstUnderline]); + } CRLF; if(cfg.total_chans>=10) j=(cfg.total_chans/2)+(cfg.total_chans&1); @@ -372,9 +402,13 @@ void sbbs_t::multinodechat(int channel) bprintf(text[ChatChanLstFmt] ,k+1 ,cfg.chan[k]->name - ,cfg.chan[k]->cost); } } - CRLF; } - CRLF; } + ,cfg.chan[k]->cost); + } + } + CRLF; + } + CRLF; + } break; case '?': /* menu */ menu("multchat"); @@ -394,12 +428,14 @@ void sbbs_t::multinodechat(int channel) : useron.handle ,cfg.node_num,':',nulstr); sprintf(tmp,"%*s",bstrlen(str),nulstr); - strcat(pgraph,tmp); } + strcat(pgraph,tmp); + } strcat(pgraph,line); strcat(pgraph,crlf); if(!wordwrap[0]) break; - j++; } + j++; + } if(pgraph[0]) { if(channel && useron.chat&CHAT_ACTION) { for(i=0;icmd,str)) - break; } + break; + } if(iguruar,&useron)) + if(cfg.total_gurus==1 && chk_ar(cfg.guru[0]->ar,&useron,&client)) i=0; else { for(i=0;iar,&useron)) { - sprintf(str,text[ChatWithGuruInsteadQ],cfg.guru[0]->name); + if(cfg.total_gurus && chk_ar(cfg.guru[0]->ar,&useron,&client) && text[ChatWithGuruInsteadQ][0]) { + SAFEPRINTF(str,text[ChatWithGuruInsteadQ],cfg.guru[0]->name); if(!yesno(str)) - break; } + break; + } else break; /* FALL-THROUGH */ @@ -633,14 +678,16 @@ void sbbs_t::chatsection() lncntr=0; // if(gurubuf) // free(gurubuf); - return; } + return; + } action=NODE_CHAT; if(!(useron.misc&EXPERT) || useron.misc&(WIP|HTML) || (useron.misc&RIP && !no_rip_menu)) { menu("chat"); } ASYNC; - bputs(text[ChatPrompt]); } + bputs(text[ChatPrompt]); + } // if(gurubuf) // free(gurubuf); } @@ -658,27 +705,29 @@ bool sbbs_t::sysop_page(void) } if(startup->options&BBS_OPT_SYSOP_AVAILABLE - || (cfg.sys_chat_ar[0] && chk_ar(cfg.sys_chat_ar,&useron)) + || (cfg.sys_chat_ar[0] && chk_ar(cfg.sys_chat_ar,&useron,&client)) || useron.exempt&FLAG('C')) { sprintf(str,"%s paged sysop for chat",useron.alias); logline("C",str); for(i=0;iar,&useron)) + if(chk_ar(cfg.page[i]->ar,&useron,&client)) break; if(icmd,nulstr,nulstr,NULL) - ,cfg.page[i]->misc&IO_INTS ? EX_OUTL|EX_OUTR|EX_INR - : EX_OUTL); } + ,cfg.page[i]->misc&XTRN_STDIO ? EX_STDIO : 0); + } else if(cfg.sys_misc&SM_SHRTPAGE) { bprintf(text[PagingGuru],cfg.sys_op); for(i=0;i<10 && !lkbrd(1);i++) { sbbs_beep(1000,200); mswait(200); - outchar('.'); } - CRLF; } + outchar('.'); + } + CRLF; + } else { sys_status^=SS_SYSPAGE; bprintf(text[SysopPageIsNow] @@ -700,12 +749,14 @@ bool sbbs_t::sysop_page(void) bool sbbs_t::chan_access(uint cnum) { - if(!cfg.total_chans || cnum>=cfg.total_chans || !chk_ar(cfg.chan[cnum]->ar,&useron)) { + if(!cfg.total_chans || cnum>=cfg.total_chans || !chk_ar(cfg.chan[cnum]->ar,&useron,&client)) { bputs(text[CantAccessThatChannel]); - return(false); } + return(false); + } if(!(useron.exempt&FLAG('J')) && cfg.chan[cnum]->cost>useron.cdt+useron.freecdt) { bputs(text[NotEnoughCredits]); - return(false); } + return(false); + } return(true); } @@ -728,29 +779,33 @@ void sbbs_t::privchat(bool local) node_t node; time_t last_nodechk=0; - if(useron.rest&FLAG('C')) { - bputs(text[R_Chat]); - return; - } - if(local) n=0; else { + + if(useron.rest&FLAG('C')) { + bputs(text[R_Chat]); + return; + } + n=getnodetopage(0,0); if(!n) return; if(n==cfg.node_num) { bputs(text[NoNeedToPageSelf]); - return; } + return; + } getnodedat(n,&node,0); if(node.action==NODE_PCHT && node.aux!=cfg.node_num) { bprintf(text[NodeNAlreadyInPChat],n); - return; } + return; + } if((node.action!=NODE_PAGE || node.aux!=cfg.node_num) && node.misc&NODE_POFF && !SYSOP) { bprintf(text[CantPageNode],node.misc&NODE_ANON ? text[UNKNOWN_USER] : username(&cfg,node.useron,tmp)); - return; } + return; + } if(node.action!=NODE_PAGE) { bprintf(text[PagingUser] ,node.misc&NODE_ANON ? text[UNKNOWN_USER] : username(&cfg,node.useron,tmp) @@ -761,7 +816,8 @@ void sbbs_t::privchat(bool local) putnmsg(&cfg,n,str); sprintf(str,"%s paged %s on node %d to private chat" ,useron.alias,username(&cfg,node.useron,tmp),n); - logline("C",str); } + logline("C",str); + } if(getnodedat(cfg.node_num,&thisnode,true)==0) { thisnode.action=action=NODE_PAGE; @@ -802,7 +858,7 @@ void sbbs_t::privchat(bool local) return; if(((sys_status&SS_USERON && useron.chat&CHAT_SPLITP) || !(sys_status&SS_USERON)) - && term_supports(ANSI) && rows>=24) + && term_supports(ANSI) && rows>=24 && cols>=80) sys_status|=SS_SPLITP; else sys_status&=~SS_SPLITP; @@ -819,7 +875,7 @@ void sbbs_t::privchat(bool local) } sprintf(outpath,"%schat.dab",cfg.node_dir); - if((out=sopen(outpath,O_RDWR|O_CREAT|O_BINARY,SH_DENYNO,S_IREAD|S_IWRITE))==-1) { + if((out=sopen(outpath,O_RDWR|O_CREAT|O_BINARY,SH_DENYNO,DEFFILEMODE))==-1) { errormsg(WHERE,ERR_OPEN,outpath,O_RDWR|O_DENYNONE|O_CREAT); return; } @@ -830,16 +886,18 @@ void sbbs_t::privchat(bool local) sprintf(inpath,"%schat.dab",cfg.node_path[n-1]); if(!fexist(inpath)) /* Wait while it's created for the first time */ mswait(2000); - if((in=sopen(inpath,O_RDWR|O_CREAT|O_BINARY,SH_DENYNO,S_IREAD|S_IWRITE))==-1) { + if((in=sopen(inpath,O_RDWR|O_CREAT|O_BINARY,SH_DENYNO,DEFFILEMODE))==-1) { close(out); errormsg(WHERE,ERR_OPEN,str,O_RDWR|O_DENYNONE|O_CREAT); - return; } + return; + } if((p=(char *)malloc(PCHAT_LEN))==NULL) { close(in); close(out); errormsg(WHERE,ERR_ALLOC,str,PCHAT_LEN); - return; } + return; + } memset(p,0,PCHAT_LEN); write(in,p,PCHAT_LEN); write(out,p,PCHAT_LEN); @@ -880,19 +938,16 @@ void sbbs_t::privchat(bool local) if(sys_status&SS_SPLITP) { lncntr=0; CLS; - ANSI_SAVE(); -#if 0 - if(local) - bprintf(text[SysopIsHere],cfg.sys_op); -#endif - GOTOXY(1,13); + ansi_save(); + ansi_gotoxy(1,13); remote_y=1; bprintf(local ? local_sep : sep ,thisnode.misc&NODE_MSGW ? 'T':' ' ,sectostr(timeleft,tmp) ,thisnode.misc&NODE_NMSG ? 'M':' '); CRLF; - local_y=14; } + local_y=14; + } while(online && (local || !(sys_status&SS_ABORT))) { lncntr=0; @@ -910,7 +965,9 @@ void sbbs_t::privchat(bool local) if(echo) backspace(); localchar--; - localbuf[localline][localchar]=0; } } + localbuf[localline][localchar]=0; + } + } else if(ch==TAB) { if(echo) outchar(' '); @@ -919,7 +976,9 @@ void sbbs_t::privchat(bool local) while(localchar<78 && localchar%8) { if(echo) outchar(' '); - localbuf[localline][localchar++]=' '; } } + localbuf[localline][localchar++]=' '; + } + } else if(ch==CTRL_R) { if(sys_status&SS_SPLITP) { CLS; @@ -932,8 +991,8 @@ void sbbs_t::privchat(bool local) } remote_y=1+remoteline; bputs("\1i_\1n"); /* Fake cursor */ - ANSI_SAVE(); - GOTOXY(1,13); + ansi_save(); + ansi_gotoxy(1,13); bprintf(local ? local_sep : sep ,thisnode.misc&NODE_MSGW ? 'T':' ' ,sectostr(timeleft,tmp) @@ -954,7 +1013,8 @@ void sbbs_t::privchat(bool local) if(ch!=CR) { if(echo) outchar(ch); - localbuf[localline][localchar]=ch; } + localbuf[localline][localchar]=ch; + } if(ch==CR || (localchar>68 && ch==' ') || ++localchar>78) { @@ -962,7 +1022,7 @@ void sbbs_t::privchat(bool local) localchar=0; if(sys_status&SS_SPLITP && local_y==24) { - GOTOXY(1,13); + ansi_gotoxy(1,13); bprintf(local ? local_sep : sep ,thisnode.misc&NODE_MSGW ? 'T':' ' ,sectostr(timeleft,tmp) @@ -971,9 +1031,11 @@ void sbbs_t::privchat(bool local) for(x=13,y=0;x=4) for(i=0;i<4;i++) @@ -1020,7 +1082,7 @@ void sbbs_t::privchat(bool local) activity=1; if(sys_status&SS_SPLITP && !remote_activity) { ansi_getxy(&x,&y); - ANSI_RESTORE(); + ansi_restore(); } attr(cfg.color[clr_chatremote]); if(sys_status&SS_SPLITP && !remote_activity) @@ -1030,18 +1092,23 @@ void sbbs_t::privchat(bool local) if(remotechar) { backspace(); remotechar--; - remotebuf[remoteline][remotechar]=0; } } + remotebuf[remoteline][remotechar]=0; + } + } else if(ch==TAB) { outchar(' '); remotebuf[remoteline][remotechar]=' '; remotechar++; while(remotechar<78 && remotechar%8) { outchar(' '); - remotebuf[remoteline][remotechar++]=' '; } } + remotebuf[remoteline][remotechar++]=' '; + } + } else if(ch>=' ' || ch==CR) { if(ch!=CR) { outchar(ch); - remotebuf[remoteline][remotechar]=ch; } + remotebuf[remoteline][remotechar]=ch; + } if(ch==CR || (remotechar>68 && ch==' ') || ++remotechar>78) { @@ -1058,9 +1125,11 @@ void sbbs_t::privchat(bool local) for(i=0;i<12;i++) { bprintf("\x1b[%d;1H\x1b[K",i+1); if(i<=remoteline) - bprintf("%s\r\n",remotebuf[i]); } + bprintf("%s\r\n",remotebuf[i]); + } remoteline=0; - GOTOXY(1, remote_y=6); } + ansi_gotoxy(1, remote_y=6); + } else { if(remoteline>=4) for(i=0;i<4;i++) @@ -1085,8 +1154,8 @@ void sbbs_t::privchat(bool local) if(sys_status&SS_SPLITP && remote_activity) { bputs("\1i_\1n"); /* Fake cursor */ - ANSI_SAVE(); - GOTOXY(x,y); + ansi_save(); + ansi_gotoxy(x,y); } now=time(NULL); @@ -1158,7 +1227,8 @@ int sbbs_t::getnodetopage(int all, int t if(lastnodemsg) { getnodedat(lastnodemsg,&node,0); if(node.status!=NODE_INUSE && !SYSOP) - lastnodemsg=1; } + lastnodemsg=1; + } for(j=0,i=1;i<=cfg.sys_nodes && i<=cfg.sys_lastnode;i++) { getnodedat(i,&node,0); if(i==cfg.node_num) @@ -1166,14 +1236,17 @@ int sbbs_t::getnodetopage(int all, int t if(node.status==NODE_INUSE || (SYSOP && node.status==NODE_QUIET)) { if(!lastnodemsg) lastnodemsg=i; - j++; } } + j++; + } + } if(!lastnodemsguser[0]) sprintf(lastnodemsguser,"%u",lastnodemsg); if(!j && !telegram) { bputs(text[NoOtherActiveNodes]); - return(0); } + return(0); + } if(all) sprintf(str,text[NodeToSendMsgTo],lastnodemsg); @@ -1193,23 +1266,28 @@ int sbbs_t::getnodetopage(int all, int t getnodedat(j,&node,0); if(node.status!=NODE_INUSE && !SYSOP) { bprintf(text[NodeNIsNotInUse],j); - return(0); } + return(0); + } if(telegram && node.misc&(NODE_POFF|NODE_ANON) && !SYSOP) { bprintf(text[CantPageNode],node.misc&NODE_ANON ? text[UNKNOWN_USER] : username(&cfg,node.useron,tmp)); - return(0); } + return(0); + } strcpy(lastnodemsguser,str); if(telegram) return(node.useron); - return(j); } + return(j); + } if(all && !stricmp(str,"ALL")) return(-1); if(str[0]=='\'') { - j=userdatdupe(0,U_HANDLE,LEN_HANDLE,str+1,0); + j=userdatdupe(0,U_HANDLE,LEN_HANDLE,str+1); if(!j) { bputs(text[UnknownUser]); - return(0); } } + return(0); + } + } else if(str[0]=='#') j=atoi(str+1); else @@ -1222,7 +1300,8 @@ int sbbs_t::getnodetopage(int all, int t l=ahtoul(tmp); if(l&(DELETED|INACTIVE)) { /* Deleted or Inactive User */ bputs(text[UnknownUser]); - return(0); } + return(0); + } for(i=1;i<=cfg.sys_nodes && i<=cfg.sys_lastnode;i++) { getnodedat(i,&node,0); @@ -1231,14 +1310,18 @@ int sbbs_t::getnodetopage(int all, int t if(telegram && node.misc&NODE_POFF && !SYSOP) { bprintf(text[CantPageNode],node.misc&NODE_ANON ? text[UNKNOWN_USER] : username(&cfg,node.useron,tmp)); - return(0); } + return(0); + } if(telegram) return(j); strcpy(lastnodemsguser,str); - return(i); } } + return(i); + } + } if(telegram) { strcpy(lastnodemsguser,str); - return(j); } + return(j); + } bputs(text[UserNotFound]); return(0); } @@ -1284,7 +1367,8 @@ void sbbs_t::nodemsg() if(thisnode.misc&NODE_MSGW) getsmsg(useron.number); CRLF; - RESTORELINE; } + RESTORELINE; + } else nodesync(); } @@ -1306,16 +1390,18 @@ void sbbs_t::nodemsg() if(usernumber==1 && useron.rest&FLAG('S')) { /* ! val fback */ bprintf(text[R_Feedback],cfg.sys_op); - break; } + break; + } if(usernumber!=1 && useron.rest&FLAG('E')) { bputs(text[R_Email]); - break; } + break; + } now=time(NULL); bprintf(text[SendingTelegramToUser] ,username(&cfg,usernumber,tmp),usernumber); sprintf(buf,text[TelegramFmt] ,thisnode.misc&NODE_ANON ? text[UNKNOWN_USER] : useron.alias - ,timestr(&now)); + ,timestr(now)); i=0; logbuf[0]=0; while(online && i<5) { @@ -1329,12 +1415,14 @@ void sbbs_t::nodemsg() strcat(logbuf," "); strcat(logbuf,line); } - i++; } + i++; + } if(!i) break; if(sys_status&SS_ABORT) { CRLF; - break; } + break; + } putsmsg(&cfg,usernumber,buf); sprintf(str,"%s sent telegram to %s #%u" ,useron.alias,username(&cfg,usernumber,tmp),usernumber); @@ -1372,7 +1460,9 @@ void sbbs_t::nodemsg() sprintf(str,"%s sent message to %s on node %d:" ,useron.alias,username(&cfg,usernumber,tmp),i); logline("C",str); - logline(nulstr,line); } } + logline(nulstr,line); + } + } else { /* ALL */ bputs(text[NodeMsgPrompt]); if(!getstr(line,70,K_LINE)) @@ -1387,7 +1477,8 @@ void sbbs_t::nodemsg() if((node.status==NODE_INUSE || (SYSOP && node.status==NODE_QUIET)) && (SYSOP || !(node.misc&NODE_POFF))) - putnmsg(&cfg,i,buf); } + putnmsg(&cfg,i,buf); + } sprintf(str,"%s sent message to all nodes",useron.alias); logline("C",str); logline(nulstr,line); @@ -1397,14 +1488,17 @@ void sbbs_t::nodemsg() bputs("Chat\r\n"); if(action==NODE_PCHT) { /* already in pchat */ done=1; - break; } + break; + } privchat(); action=savenode.action; break; default: bputs("Quit\r\n"); done=1; - break; } } + break; + } + } nodemsg_inside--; if(!nodemsg_inside) sys_status&=~SS_IN_CTRLP; @@ -1437,9 +1531,12 @@ void sbbs_t::guruchat(char* line, char* errormsg(WHERE,ERR_ALLOC,nulstr,512); while(i) { i--; - free(answer[i]); } + free(answer[i]); + } sys_status&=~SS_GURUCHAT; - return; } } + return; + } + } ptr=gurubuf; len=strlen(gurubuf); strupr(line); @@ -1452,17 +1549,20 @@ void sbbs_t::guruchat(char* line, char* continue; if(!isalnum(line[i]) && line[i+1]=='?') /* fix "WHAT ?" */ continue; - cstr[k++]=line[i]; } + cstr[k++]=line[i]; + } cstr[k]=0; while(k) { k--; if(!isalnum(cstr[k])) continue; - break; } + break; + } if(k<1) { for(i=0;i<100;i++) free(answer[i]); - return; } + return; + } if(cstr[k+1]=='?') k++; cstr[k+1]=0; @@ -1472,7 +1572,9 @@ void sbbs_t::guruchat(char* line, char* if(!guruexp(&ptr,cstr)) { while(*ptr && *ptr!='(' && ptrname - ,cfg.sys_nodes+1,':',theanswer); } + ,cfg.sys_nodes+1,':',theanswer); + } CRLF; sprintf(str,"%sguru.log",cfg.logs_dir); if((file=nopen(str,O_WRONLY|O_CREAT|O_APPEND))==-1) @@ -1668,7 +1783,8 @@ void sbbs_t::guruchat(char* line, char* else { if(action==NODE_MCHT) { sprintf(str,"[Multi] "); - write(file,str,strlen(str)); } + write(file,str,strlen(str)); + } sprintf(str,"%s:\r\n",sys_status&SS_USERON ? useron.alias : "UNKNOWN"); write(file,str,strlen(str)); @@ -1679,10 +1795,13 @@ void sbbs_t::guruchat(char* line, char* write(file,str,strlen(str)); write(file,theanswer,strlen(theanswer)); write(file,crlf,2); - close(file); } + close(file); + } if(hu) hangup(); - break; } } + break; + } + } for(i=0;i<100;i++) free(answer[i]); } @@ -1700,7 +1819,8 @@ bool sbbs_t::guruexp(char **ptrptr, char if((**ptrptr)==')') { /* expressions of () are always result */ (*ptrptr)++; - return(true); } + return(true); + } while((**ptrptr)!=')' && (**ptrptr)) { if((**ptrptr)=='[') { (*ptrptr)++; @@ -1711,29 +1831,35 @@ bool sbbs_t::guruexp(char **ptrptr, char cp=strchr(str,']'); if(cp) *cp=0; ar=arstr(NULL,str,&cfg); - c=chk_ar(ar,&useron); + c=chk_ar(ar,&useron,&client); if(ar[0]!=AR_NULL) free(ar); if(!c && _and) { result=false; - break; } + break; + } if(c && _or) { result=true; - break; } + break; + } if(c) result=true; - continue; } + continue; + } if((**ptrptr)=='(') { (*ptrptr)++; c=guruexp(&(*ptrptr),line); if(!c && _and) { result=false; - break; } + break; + } if(c && _or) { result=true; - break; } + break; + } if(c) - result=true; } + result=true; + } if((**ptrptr)==')') break; c=0; @@ -1741,52 +1867,64 @@ bool sbbs_t::guruexp(char **ptrptr, char (*ptrptr)++; while((**ptrptr)!='|' && (**ptrptr)!='&' && (**ptrptr)!=')' &&(**ptrptr)) { str[c++]=(**ptrptr); - (*ptrptr)++; } + (*ptrptr)++; + } str[c]=0; if((**ptrptr)=='|') { if(!c && result) break; _and=false; - _or=true; } + _or=true; + } else if((**ptrptr)=='&') { if(!c && !result) break; _and=true; - _or=false; } + _or=false; + } if(!c) { /* support ((exp)op(exp)) */ (*ptrptr)++; - continue; } + continue; + } if((**ptrptr)!=')') (*ptrptr)++; c=0; /* c now used for start line flag */ if(str[strlen(str)-1]=='^') { /* ^signifies start of line only */ str[strlen(str)-1]=0; - c=true; } + c=true; + } if(str[strlen(str)-1]=='~') { /* ~signifies non-isolated word */ str[strlen(str)-1]=0; cp=strstr(line,str); if(c && cp!=line) - cp=0; } + cp=0; + } else { cp=strstr(line,str); if(cp && c) { if(cp!=line || isalnum(*(cp+strlen(str)))) - cp=0; } + cp=0; + } else { /* must be isolated word */ while(cp) if((cp!=line && isalnum(*(cp-1))) || isalnum(*(cp+strlen(str)))) cp=strstr(cp+strlen(str),str); else - break; } } + break; + } + } if(!cp && _and) { result=false; - break; } + break; + } if(cp && _or) { result=true; - break; } + break; + } if(cp) - result=true; } + result=true; + } nest=0; while((**ptrptr)!=')' && (**ptrptr)) { /* handle nested exp */ if((**ptrptr)=='(') /* (TRUE|(IGNORE)) */ @@ -1794,7 +1932,9 @@ bool sbbs_t::guruexp(char **ptrptr, char (*ptrptr)++; while((**ptrptr)==')' && nest && (**ptrptr)) { nest--; - (*ptrptr)++; } } + (*ptrptr)++; + } + } (*ptrptr)++; /* skip over ')' */ return(result); } @@ -1818,7 +1958,9 @@ void sbbs_t::localguru(char *gurubuf, in ch=sbbs_random(25)+25; while(ch--) { mswait(200); - outchar('.'); } } + outchar('.'); + } + } bprintf(text[SysopIsHere],cfg.guru[gurunum]->name); if(getnodedat(cfg.node_num,&thisnode,true)==0) { thisnode.aux=gurunum;