Skip to content
Snippets Groups Projects
chat.cpp 51.2 KiB
Newer Older
						,thisnode.misc&NODE_MSGW ? 'T':' '
						,sectostr(timeleft,tmp)
						,thisnode.misc&NODE_NMSG ? 'M':' ');
					attr(cfg.color[clr_chatlocal]);
					localbuf[localline][localchar]=0;
					for(i=0;i<=localline;i++) {
						bputs(localbuf[i]);
						if(i!=localline) 
							bputs(crlf);
					}
					local_y=15+localline;
				}
			else if(ch>=' ' || ch==CR) {
				if(ch!=CR) {
					if(echo)
						outchar(ch);
					localbuf[localline][localchar]=ch; 
				}
				if(ch==CR || (localchar>68 && ch==' ') || ++localchar>78) {
					lprintf(LOG_DEBUG, "chat line wrapped, localchar=%d, ch=%x", localchar, ch);
					localbuf[localline][localchar]=0;
					localchar=0;

					if(sys_status&SS_SPLITP && local_y >= rows) {
							,thisnode.misc&NODE_MSGW ? 'T':' '
							,sectostr(timeleft,tmp)
							,thisnode.misc&NODE_NMSG ? 'M':' ');
						attr(cfg.color[clr_chatlocal]);
						for(x=13,y=0;x<rows;x++,y++) {
							if(y<=localline)
								bprintf("%s\r\n",localbuf[y]); 
						}
						ansi_gotoxy(1,local_y=(15+localline));
					else {
						if(localline>=4)
							for(i=0;i<4;i++)
								memcpy(localbuf[i],localbuf[i+1],81);
						else
							localline++;
						if(echo) {
							CRLF;
		            		local_y++;
							if(sys_status&SS_SPLITP)
			(void)read(out,&c,1);
			(void)lseek(out,-1L,SEEK_CUR);
			if(!c)		/* hasn't wrapped */
				wr = write(out,&ch,1);
			else {
				if(!tell(out))
					lseek(out,0L,SEEK_END);
				lseek(out,-1L,SEEK_CUR);
				ch=0;
				wr = write(out,&ch,1);
			if(wr != 1)
				lprintf(LOG_ERR, "write of character 0x%02X to %s returned %d", ch, outpath, wr);
			else if(ch < ' ')
				lprintf(LOG_DEBUG, "wrote control character %u (%s) to %s", ch, c_escape_char(ch), outpath);
			else
				lprintf(LOG_DEBUG, "wrote character '%c' to %s", ch, outpath);

			utime(outpath,NULL);	/* update mod time for NFS/smbfs nodes */
			if(tell(out)>=PCHAT_LEN)
				lseek(out,0L,SEEK_SET);
		else while(online) {
			if(!(sys_status&SS_SPLITP))
				remotechar=localchar;
			if(tell(in)>=PCHAT_LEN)
				lseek(in,0L,SEEK_SET);
			ch=0;
			int rd = read(in,&ch,1);
			if(rd != 1) {
				lprintf(LOG_ERR, "read character from %s returned %d instead of 1", inpath, rd);
			(void)lseek(in,-1L,SEEK_CUR);
			if(!ch) break;					  /* char from other node */
			if(ch < ' ')
				lprintf(LOG_DEBUG, "read control character %u (%s) from %s", ch, c_escape_char(ch), inpath);
			else
				lprintf(LOG_DEBUG, "read character '%c' from %s", ch, inpath);
			activity=1;
			if(sys_status&SS_SPLITP && !remote_activity) {
				ansi_getxy(&x,&y);
			}
			attr(cfg.color[clr_chatremote]);
			if(sys_status&SS_SPLITP && !remote_activity)
				backspace();             /* Delete fake cursor */
			remote_activity=1;
			if(ch==BS || ch==DEL) {
				if(remotechar) {
					remotebuf[remoteline][remotechar]=0; 
				} 
			}
			else if(ch==TAB) {
				outchar(' ');
				remotebuf[remoteline][remotechar]=' ';
				remotechar++;
				while(remotechar<78 && remotechar%8) {
					remotebuf[remoteline][remotechar++]=' '; 
				} 
			}
			else if(ch>=' ' || ch==CR) {
				if(ch!=CR) {
					outchar(ch);
					remotebuf[remoteline][remotechar]=ch; 
				}
				if(ch==CR || (remotechar>68 && ch==' ') || ++remotechar>78) {

					remotebuf[remoteline][remotechar]=0;
					remotechar=0;

					if(sys_status&SS_SPLITP && remote_y==12) {
						CRLF;
							,thisnode.misc&NODE_MSGW ? 'T':' '
							,sectostr(timeleft,tmp)
							,thisnode.misc&NODE_NMSG ? 'M':' ');
						attr(cfg.color[clr_chatremote]);
						for(i=0;i<12;i++) {
							bprintf("\x1b[%d;1H\x1b[K",i+1);
							if(i<=remoteline)
								bprintf("%s\r\n",remotebuf[i]); 
						}
						ansi_gotoxy(1, remote_y=6); 
					}
					else {
						if(remoteline>=4)
							for(i=0;i<4;i++)
								memcpy(remotebuf[i],remotebuf[i+1],81);
						else
							remoteline++;
						if(echo) {
							CRLF;
		            		remote_y++;
							if(sys_status&SS_SPLITP)
			if(write(in,&ch,1) != 1)
				lprintf(LOG_ERR, "write of NUL to %s returned %d", inpath, wr);

			if(!(sys_status&SS_SPLITP))
				localchar=remotechar;
			}

		if(sys_status&SS_SPLITP && remote_activity) {
			bputs("\1i_\1n");  /* Fake cursor */
		now=time(NULL);
		if(!activity && now!=last_nodechk) {	/* no activity so chk node.dab */

			if(!localchar) {
				if(sys_status&SS_SPLITP) {
					getnodedat(cfg.node_num,&thisnode,0);
					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) {
							thisnode.misc&=~NODE_UDAT;
							putnodedat(cfg.node_num,&thisnode); 
						}
					} 
				}
				else
					nodesync(); 
			}

				getnodedat(n,&node,0);
				if((node.action!=NODE_PCHT && node.action!=NODE_PAGE)
					|| node.aux!=cfg.node_num) {
					bprintf(text[NodeLeftPrivateChat]
						,n,node.misc&NODE_ANON ? text[UNKNOWN_USER]
						: username(&cfg,node.useron,tmp));
					break; 
				}
			}
			getnodedat(cfg.node_num,&thisnode,0);
			if(thisnode.action!=NODE_PCHT) {
				action=thisnode.action;
				bputs(text[EndOfChat]);
				break;
			}
			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) {
					thisnode.misc&=~NODE_RPCHT;
					putnodedat(cfg.node_num,&thisnode); 
				}
	if(sys_status&SS_SPLITP)
		CLS;
	sys_status&=~(SS_SPLITP|SS_ABORT);
	close(in);
	close(out);
}


int sbbs_t::getnodetopage(int all, int telegram)
{
	char	str[128];
	uint 	i,j;
	node_t	node;

	if(!lastnodemsg)
		lastnodemsguser[0]=0;
	if(lastnodemsg) {
		getnodedat(lastnodemsg,&node,0);
		if(node.status!=NODE_INUSE && !SYSOP)
	for(j=0,i=1;i<=cfg.sys_nodes && i<=cfg.sys_lastnode;i++) {
		getnodedat(i,&node,0);
		if(i==cfg.node_num)
			continue;
		if(node.status==NODE_INUSE || (SYSOP && node.status==NODE_QUIET)) {
			if(!lastnodemsg)
				lastnodemsg=i;

	if(!lastnodemsguser[0])
		sprintf(lastnodemsguser,"%u",lastnodemsg);

	if(!j && !telegram) {
		bputs(text[NoOtherActiveNodes]);

	if(all)
		sprintf(str,text[NodeToSendMsgTo],lastnodemsg);
	else
		sprintf(str,text[NodeToPrivateChat],lastnodemsg);
	mnemonics(str);

Rob Swindell's avatar
Rob Swindell committed
	SAFECOPY(str,lastnodemsguser);
	getstr(str,LEN_ALIAS,K_LINE|K_EDIT|K_AUTODEL);
	if(sys_status&SS_ABORT) {
		sys_status&= ~SS_ABORT;
	if(!str[0])
		return(0);

	j=atoi(str);
	if(j && j<=cfg.sys_lastnode && j<=cfg.sys_nodes) {
		getnodedat(j,&node,0);
		if(node.status!=NODE_INUSE && !SYSOP) {
			bprintf(text[NodeNIsNotInUse],j);
		if(telegram && node.misc&(NODE_POFF|NODE_ANON) && !SYSOP) {
			bprintf(text[CantPageNode],node.misc&NODE_ANON
				? text[UNKNOWN_USER] : username(&cfg,node.useron,tmp));
Rob Swindell's avatar
Rob Swindell committed
		SAFECOPY(lastnodemsguser,str);
		if(telegram)
			return(node.useron);
	if(all && !stricmp(str,"ALL"))
		return(-1);

	if(str[0]=='\'') {
		j=finduserstr(0, USER_HANDLE, str+1);
		if(!j) {
			bputs(text[UnknownUser]);
	else if(str[0]=='#')
		j=atoi(str+1);
	else
		j=finduser(str);
	if(!j)
		return(0);
	if(j>lastuser(&cfg))
		return(0);
	if(getusermisc(&cfg, j) & (DELETED|INACTIVE)) {              /* Deleted or Inactive User */
		bputs(text[UnknownUser]);

	for(i=1;i<=cfg.sys_nodes && i<=cfg.sys_lastnode;i++) {
		getnodedat(i,&node,0);
		if((node.status==NODE_INUSE || (SYSOP && node.status==NODE_QUIET))
			&& node.useron==j) {
			if(telegram && node.misc&NODE_POFF && !SYSOP) {
				bprintf(text[CantPageNode],node.misc&NODE_ANON
					? text[UNKNOWN_USER] : username(&cfg,node.useron,tmp));
			if(telegram)
				return(j);
Rob Swindell's avatar
Rob Swindell committed
			SAFECOPY(lastnodemsguser,str);
	if(telegram) {
	bputs(text[UserNotFound]);
	return(0);
}


/****************************************************************************/
/* Sending single line messages between nodes                               */
/****************************************************************************/
void sbbs_t::nodemsg()
{
	char	str[256],line[256],buf[512],logbuf[512],ch=0;
	int 	i,usernumber,done=0;
	node_t	node,savenode;

	if(nodemsg_inside>1)	/* nested once only */
		return;
	nodemsg_inside++;
	if(cfg.privatemsg_mod[0] != '\0') {
		exec_bin(cfg.privatemsg_mod, &main_csi);
		nodemsg_inside--;
		return;
	}
	sys_status|=SS_IN_CTRLP;
	getnodedat(cfg.node_num,&savenode,0);
	wordwrap[0]=0;
	while(online && !done) {
		if(useron.rest&FLAG('C')) {
			bputs(text[R_SendMessages]);
		SYNC;
		mnemonics(text[PrivateMsgPrompt]);
		sys_status&=~SS_ABORT;
		while(online) { 	 /* Watch for incoming messages */
			ch=toupper(inkey(K_NONE,1000));
			if(ch && strchr("TMCQ\r",ch))
				break;
			if(sys_status&SS_ABORT)
				break;
			if(getnodedat(cfg.node_num,&thisnode,false)==0) {
				if(thisnode.misc&(NODE_MSGW|NODE_NMSG)) {
					lncntr=0;	/* prevent pause prompt */
					SAVELINE;
					CRLF;
					if(thisnode.misc&NODE_NMSG)
						getnmsg();
					if(thisnode.misc&NODE_MSGW)
						getsmsg(useron.number);
					CRLF;
			gettimeleft();

		if(!online || sys_status&SS_ABORT) {
			sys_status&=~SS_ABORT;
			CRLF;

		switch(toupper(ch)) {
			case 'T':   /* Telegram */
				bputs("Telegram\r\n");
				usernumber=getnodetopage(0,1);
				if(!usernumber)
					break;

				if(usernumber==1 && useron.rest&FLAG('S')) { /* ! val fback */
					bprintf(text[R_Feedback],cfg.sys_op);
				if(usernumber!=1 && useron.rest&FLAG('E')) {
					bputs(text[R_Email]);
				now=time(NULL);
				bprintf(text[SendingTelegramToUser]
					,username(&cfg,usernumber,tmp),usernumber);
				sprintf(buf,text[TelegramFmt]
					,thisnode.misc&NODE_ANON ? text[UNKNOWN_USER] : useron.alias
				i=0;
				logbuf[0]=0;
				while(online && i<5) {
					bprintf("%4s",nulstr);
					if(!getstr(line,70,K_WRAP|K_MSG))
						break;
					SAFEPRINTF2(str,"%4s%s\r\n",nulstr,line);
					if(line[0]) {
						if(i)
							SAFECAT(logbuf,"   ");
						SAFECAT(logbuf,line);
				if(!i)
					break;
				if(sys_status&SS_ABORT) {
					CRLF;
				putsmsg(&cfg,usernumber,buf);
				sprintf(str,"sent telegram to %s #%u"
					,username(&cfg,usernumber,tmp),usernumber);
				logline("C",str);
				logline(nulstr,logbuf);
				bprintf(text[MsgSentToUser],"Telegram"
					,username(&cfg,usernumber,tmp),usernumber);
				break;
			case 'M':   /* Message */
				bputs("Message\r\n");
				i=getnodetopage(1,0);
				if(!i)
					break;
				if(i!=-1) {
					getnodedat(i,&node,0);
					usernumber=node.useron;
					if(node.misc&NODE_POFF && !SYSOP)
						bprintf(text[CantPageNode],node.misc&NODE_ANON
							? text[UNKNOWN_USER] : username(&cfg,node.useron,tmp));
					else {
						bprintf(text[SendingMessageToUser]
							,node.misc&NODE_ANON ? text[UNKNOWN_USER]
							: username(&cfg,node.useron,tmp)
							,node.misc&NODE_ANON ? 0 : node.useron);
						bputs(text[NodeMsgPrompt]);
						if(!getstr(line,69,K_LINE))
							break;
						sprintf(buf,text[NodeMsgFmt],cfg.node_num
							,thisnode.misc&NODE_ANON
								? text[UNKNOWN_USER] : useron.alias,line);
						if(!(node.misc&NODE_ANON))
							bprintf(text[MsgSentToUser],"Message"
								,username(&cfg,usernumber,tmp),usernumber);
						sprintf(str,"sent message to %s on node %d:"
							,username(&cfg,usernumber,tmp),i);
						logline("C",str);
				else {	/* ALL */
					bputs(text[NodeMsgPrompt]);
					if(!getstr(line,70,K_LINE))
						break;
					sprintf(buf,text[AllNodeMsgFmt],cfg.node_num
						,thisnode.misc&NODE_ANON
							? text[UNKNOWN_USER] : useron.alias,line);
					for(i=1;i<=cfg.sys_nodes;i++) {
						if(i==cfg.node_num)
							continue;
						getnodedat(i,&node,0);
						if((node.status==NODE_INUSE
							|| (SYSOP && node.status==NODE_QUIET))
							&& (SYSOP || !(node.misc&NODE_POFF)))
					SAFECOPY(str,"sent message to all nodes");
					logline("C",str);
					logline(nulstr,line); 
				}
				break;
			case 'C':   /* Chat */
				bputs("Chat\r\n");
				if(action==NODE_PCHT) { /* already in pchat */
					done=1;
				privchat();
				action=savenode.action;
				break;
			default:
				bputs("Quit\r\n");
				done=1;
	nodemsg_inside--;
	if(!nodemsg_inside)
		sys_status&=~SS_IN_CTRLP;
	if(getnodedat(cfg.node_num,&thisnode,true)==0) {
		thisnode.action=action=savenode.action;
		thisnode.aux=savenode.aux;
		thisnode.extaux=savenode.extaux;
		putnodedat(cfg.node_num,&thisnode);
	}
}

/****************************************************************************/
/* The guru will respond from the 'guru' buffer to 'line'                   */
/****************************************************************************/
void sbbs_t::guruchat(char* line, char* gurubuf, int gurunum, char* last_answer)
	char	str[512],cstr[512],*ptr,*answer[100],theanswer[1024]
			,mistakes=1,hu=0;
	uint 	c,i,j,k,answers;
	long 	len;
	struct	tm tm;

	now=time(NULL);

	for(i=0;i<100;i++) {
		if((answer[i]=(char *)malloc(512))==NULL) {
			errormsg(WHERE,ERR_ALLOC,nulstr,512);
			sys_status&=~SS_GURUCHAT;
	ptr=gurubuf;
	len=strlen(gurubuf);
	strupr(line);
	j=strlen(line);
	k=0;
	for(i=0;i<j;i++) {
		if(line[i]<0 || !IS_ALPHANUMERIC(line[i])) {
			if(!k)	/* beginning non-alphanumeric */
				continue;
			if(line[i]==line[i+1])	/* redundant non-alnum */
				continue;
			if(line[i+1]=='?')	/* fix "WHAT ?" */
				continue;
		}
	while(k) {
		k--;
		if(!IS_ALPHANUMERIC(cstr[k]))
	if(k<1) {
		for(i=0;i<100;i++)
			free(answer[i]);
	if(cstr[k+1]=='?')
		k++;
	cstr[k+1]=0;
	while(*ptr && ptr<gurubuf+len) {
		if(*ptr=='(') {
			ptr++;
			if(!guruexp(&ptr,cstr)) {
				while(*ptr && *ptr!='(' && ptr<gurubuf+len)
					ptr++;
		else {
			while(*ptr && *ptr!=LF && ptr<gurubuf+len) /* skip LF after ')' */
				ptr++;
			ptr++;
			answers=0;
			while(*ptr && answers<100 && ptr<gurubuf+len) {
				i=0;
				while(*ptr && *ptr!=CR && *ptr!=LF && i<511 && ptr<gurubuf+len) {
					answer[answers][i]=*ptr;
					ptr++;
					i++;
					/* multi-line answer */
					if(*ptr=='\\' && (*(ptr+1)==CR || *(ptr+1)==LF)) {
						ptr++;	/* skip \ */
						while(*ptr && *ptr<' ') ptr++;	/* skip [CR]LF */
						answer[answers][i++]=CR;
				answer[answers][i]=0;
				if(!strlen(answer[answers]) || answer[answers][0]=='(') {
					ptr-=strlen(answer[answers]);
				while(*ptr && *ptr<' ') ptr++;	/* skip [CR]LF */
			if(answers==100)
				while(*ptr && *ptr!='(' && ptr<gurubuf+len)
					ptr++;
			/* Try to not repeat yourself */
			for(j=0;j<answers;j++) {
				i=sbbs_random(answers);
				if(stricmp(answer[i],last_answer))
					break;
			}
			strcpy(last_answer,answer[i]);
			for(j=0,k=0;answer[i][j];j++) {
				if(answer[i][j]=='`') {
					j++;
					theanswer[k]=0;
					switch(toupper(answer[i][j])) {
						case 'A':
							if(sys_status&SS_USERON) {
								SAFECAT(theanswer,useron.alias);
							} else {
								SAFECAT(theanswer,text[UNKNOWN_USER]);
							}
								getbirthdstr(&cfg, useron.birth, theanswer, sizeof(theanswer));
                    		if(sys_status&SS_USERON) {
								SAFECAT(theanswer,useron.comp);
							} else {
								SAFECAT(theanswer,"PC Jr.");
							}
								SAFECAT(theanswer,u64toac(useron.dlb,tmp));
							SAFECAT(theanswer,cfg.guru[gurunum]->name);
							break;
						case 'H':
							hu=1;
							break;
						case 'I':
							break;
						case 'J':
							sprintf(tmp,"%u",tm.tm_mday);
							break;
						case 'L':
                    		if(sys_status&SS_USERON) {
								SAFECAT(theanswer,ultoa(useron.level,tmp,10));
							} else {
								SAFECAT(theanswer,"0");
							}
							SAFECAT(theanswer,month[tm.tm_mon]);
							break;
						case 'N':   /* Note */
                    		if(sys_status&SS_USERON) {
								SAFECAT(theanswer,useron.note);
							} else {
								SAFECAT(theanswer,text[UNKNOWN_USER]);
							}
                    		if(sys_status&SS_USERON) {
								SAFECAT(theanswer,useron.phone);
							} else {
								SAFECAT(theanswer,"000-000-0000");
							}
							break;
						case 'Q':
								sys_status&=~SS_GURUCHAT;
							break;
						case 'R':
                    		if(sys_status&SS_USERON) {
								SAFECAT(theanswer,useron.name);
							} else {
								SAFECAT(theanswer,text[UNKNOWN_USER]);
							}
							break;
						case 'T':
							sprintf(tmp,"%u:%02u",tm.tm_hour>12 ? tm.tm_hour-12
								: tm.tm_hour,tm.tm_min);
								SAFECAT(theanswer,u64toac(useron.ulb,tmp));
							SAFECAT(theanswer,weekday[tm.tm_wday]);
							break;
						case 'Y':   /* Current year */
							sprintf(tmp,"%u",1900+tm.tm_year);
							if(sys_status&SS_USERON) {
								SAFECAT(theanswer,useron.zipcode);
							} else {
								SAFECAT(theanswer,"90210");
							}
							break;
						case '$':   /* Credits */
								SAFECAT(theanswer,u64toac(useron.cdt,tmp));
                    		if(sys_status&SS_USERON) {
								SAFECAT(theanswer,ultoa(getage(&cfg,useron.birth)
							break;
						case '!':
							mistakes=!mistakes;
							break;
						case '_':
							mswait(500);
					theanswer[k++]=answer[i][j]; 
			}
			theanswer[k]=0;
			mswait(500+sbbs_random(1000));	 /* thinking time */
			if(action!=NODE_MCHT) {
				for(i=0;i<k;i++) {
					if(i && mistakes && theanswer[i]!=theanswer[i-1] &&
						((!IS_ALPHANUMERIC(theanswer[i]) && !sbbs_random(100))
						|| (IS_ALPHANUMERIC(theanswer[i]) && !sbbs_random(30)))) {
						c=j=((uint)sbbs_random(3)+1);	/* 1 to 3 chars */
						if(c<strcspn(theanswer+(i+1),"\0., "))
							c=j=1;
						while(j) {
							outchar(97+sbbs_random(26));
							mswait(25+sbbs_random(150));
						if(sbbs_random(100)) {
							mswait(100+sbbs_random(300));
					outchar(theanswer[i]);
					if(theanswer[i]==theanswer[i+1])
					if(theanswer[i]==' ')
			else {
				mswait(strlen(theanswer)*100);
				bprintf(text[ChatLineFmt],cfg.guru[gurunum]->name
					,cfg.sys_nodes+1,':',theanswer); 
			}
			sprintf(str,"%sguru.log",cfg.logs_dir);
			if((fp = fopenlog(&cfg, str)) == NULL)
				errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_APPEND);
			else {
				xpDateTime_to_isoDateTimeStr(xpDateTime_now(), "-", " ", ":", 0, str, sizeof(str)-3);
				fprintf(fp, "%s\r\n", str);
				if(action==NODE_MCHT) {
					fprintf(fp, "[Multi] ");
				fprintf(fp,"%s:\r\n",sys_status&SS_USERON
					? useron.alias : "UNKNOWN");
				fprintf(fp,"%s",line);
				if(action!=NODE_MCHT)
					fprintf(fp,"\r\n");
				fprintf(fp,"%s:\r\n",cfg.guru[gurunum]->name);
				fprintf(fp,"%s\r\n",theanswer);
				fcloselog(fp); 
	for(i=0;i<100;i++)
		free(answer[i]);
}

/****************************************************************************/
/* An expression from the guru's buffer 'ptrptr' is evaluated and true or   */
/* false is returned.                                                       */
/****************************************************************************/
bool sbbs_t::guruexp(char **ptrptr, char *line)
{
	bool	result=false,_and=false,_or=false;
	uchar	*ar;

	if((**ptrptr)==')') {	/* expressions of () are always result */
		(*ptrptr)++;
	while((**ptrptr)!=')' && (**ptrptr)) {
		if((**ptrptr)=='[') {
			(*ptrptr)++;
			SAFECOPY(str,*ptrptr);
			while(**ptrptr && (**ptrptr)!=']')
				(*ptrptr)++;
			(*ptrptr)++;
			cp=strchr(str,']');
			if(cp) *cp=0;
rswindell's avatar
rswindell committed
			c=chk_ar(ar,&useron,&client);
		if((**ptrptr)=='(') {
			(*ptrptr)++;
			c=guruexp(&(*ptrptr),line);
		if((**ptrptr)==')')
			break;
		c=0;
		while((**ptrptr) && IS_WHITESPACE(**ptrptr))
			(*ptrptr)++;
		while((**ptrptr)!='|' && (**ptrptr)!='&' && (**ptrptr)!=')' &&(**ptrptr)) {
			str[c++]=(**ptrptr);
		str[c]=0;
		if((**ptrptr)=='|') {
			if(!c && result)
				break;
		else if((**ptrptr)=='&') {
			if(!c && !result)
				break;
		if(!c) {				/* support ((exp)op(exp)) */
			(*ptrptr)++;
		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;
		if(str[strlen(str)-1]=='~') {	/* ~signifies non-isolated word */
			str[strlen(str)-1]=0;
			cp=strstr(line,str);
			if(c && cp!=line)
		else {
			cp=strstr(line,str);
			if(cp && c) {
				if(cp!=line || IS_ALPHANUMERIC(*(cp+strlen(str))))
			else {	/* must be isolated word */
				while(cp)
					if((cp!=line && IS_ALPHANUMERIC(*(cp-1)))
						|| IS_ALPHANUMERIC(*(cp+strlen(str))))
						cp=strstr(cp+strlen(str),str);
					else
	nest=0;
	while((**ptrptr)!=')' && (**ptrptr)) {		/* handle nested exp */
		if((**ptrptr)=='(')						/* (TRUE|(IGNORE)) */
			nest++;
		(*ptrptr)++;
		while((**ptrptr)==')' && nest && (**ptrptr)) {
			nest--;
	(*ptrptr)++;	/* skip over ')' */
	return(result);
}

/****************************************************************************/
/* Guru chat with the appearance of Local chat with sysop.                  */
/****************************************************************************/
void sbbs_t::localguru(char *gurubuf, int gurunum)
{
	char	ch,str[256];
	int 	con=console;		 /* save console state */
	char	lastanswer[512];

	if(sys_status&SS_GURUCHAT || !cfg.total_gurus)
		return;
	sys_status|=SS_GURUCHAT;
	console&=~(CON_L_ECHOX|CON_R_ECHOX);	/* turn off X's */
	console|=(CON_L_ECHO|CON_R_ECHO);					/* make sure echo is on */
	if(action==NODE_CHAT) {	/* only page if from chat section */
		bprintf(text[PagingGuru],cfg.guru[gurunum]->name);