Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

chat.cpp 49.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/* chat.cpp */

/* Synchronet real-time chat functions */

/* $Id$ */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
11
 * Copyright 2007 Rob Swindell - http://www.synchro.net/copyright.html		*
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
 *																			*
 * This program is free software; you can redistribute it and/or			*
 * modify it under the terms of the GNU General Public License				*
 * as published by the Free Software Foundation; either version 2			*
 * of the License, or (at your option) any later version.					*
 * See the GNU General Public License for more details: gpl.txt or			*
 * http://www.fsf.org/copyleft/gpl.html										*
 *																			*
 * Anonymous FTP access to the most recent released source is available at	*
 * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net	*
 *																			*
 * Anonymous CVS access to the development source and modification history	*
 * is available at cvs.synchro.net:/cvsroot/sbbs, example:					*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login			*
 *     (just hit return, no password is necessary)							*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src		*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * You are encouraged to submit any modifications (preferably in Unix diff	*
 * format) via e-mail to mods@synchro.net									*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

#include "sbbs.h"

#define PCHAT_LEN 1000		/* Size of Private chat file */

const char *weekday[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"
				,"Saturday"};
const char *month[]={"January","February","March","April","May","June"
				,"July","August","September","October","November","December"};

47 48
/****************************************************************************/
/****************************************************************************/
rswindell's avatar
rswindell committed
49
void sbbs_t::multinodechat(int channel)
50
{
rswindell's avatar
rswindell committed
51 52
	char	line[256],str[256],ch,done
			,usrs,preusrs,qusrs,*gurubuf=NULL,savch,*p
53 54
			,pgraph[400],buf[400]
			,usr[MAX_NODES],preusr[MAX_NODES],qusr[MAX_NODES];
55
	char	guru_lastanswer[512];
56
	char 	tmp[512];
57 58 59 60
	int 	file;
	long	i,j,k,n;
	node_t 	node;

61 62 63 64 65
	if(useron.rest&FLAG('C')) {
		bputs(text[R_Chat]);
		return; 
	}

rswindell's avatar
rswindell committed
66 67 68 69 70
	if(channel<1 || channel>cfg.total_chans)
		channel=1;

	if(!chan_access(channel-1))
		return;
71
	if(useron.misc&(RIP|WIP|HTML) ||!(useron.misc&EXPERT))
rswindell's avatar
rswindell committed
72 73
		menu("multchat");
	bputs(text[WelcomeToMultiChat]);
74 75 76 77
	if(getnodedat(cfg.node_num,&thisnode,true)==0) {
		thisnode.aux=channel;		
		putnodedat(cfg.node_num,&thisnode);
	}
rswindell's avatar
rswindell committed
78 79
	bprintf(text[WelcomeToChannelN],channel,cfg.chan[channel-1]->name);
	if(gurubuf) {
deuce's avatar
deuce committed
80
		free(gurubuf);
rswindell's avatar
rswindell committed
81 82 83 84 85 86 87
		gurubuf=NULL; }
	if(cfg.chan[channel-1]->misc&CHAN_GURU && cfg.chan[channel-1]->guru<cfg.total_gurus
		&& chk_ar(cfg.guru[cfg.chan[channel-1]->guru]->ar,&useron)) {
		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; }
deuce's avatar
deuce committed
88
		if((gurubuf=(char *)malloc(filelength(file)+1))==NULL) {
rswindell's avatar
rswindell committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
			close(file);
			errormsg(WHERE,ERR_ALLOC,str,filelength(file)+1);
			return; }
		read(file,gurubuf,filelength(file));
		gurubuf[filelength(file)]=0;
		close(file); }
	usrs=0;
	for(i=1;i<=cfg.sys_nodes && i<=cfg.sys_lastnode;i++) {
		if(i==cfg.node_num)
			continue;
		getnodedat(i,&node,0);
		if(node.action!=NODE_MCHT || node.status!=NODE_INUSE)
			continue;
		if(node.aux && (node.aux&0xff)!=channel)
			continue;
		printnodedat(i,&node);
		preusr[usrs]=usr[usrs++]=(char)i; }
	preusrs=usrs;
	if(gurubuf)
		bprintf(text[NodeInMultiChatLocally]
			,cfg.sys_nodes+1,cfg.guru[cfg.chan[channel-1]->guru]->name,channel);
	bputs(text[YoureOnTheAir]);
	done=0;
	while(online && !done) {
		checkline();
		gettimeleft();
		action=NODE_MCHT;
		qusrs=usrs=0;
        for(i=1;i<=cfg.sys_nodes;i++) {
			if(i==cfg.node_num)
				continue;
			getnodedat(i,&node,0);
			if(node.action!=NODE_MCHT
				|| (node.aux && channel && (node.aux&0xff)!=channel))
				continue;
			if(node.status==NODE_QUIET)
				qusr[qusrs++]=(char)i;
			else if(node.status==NODE_INUSE)
				usr[usrs++]=(char)i; }
		if(preusrs>usrs) {
			if(!usrs && channel && cfg.chan[channel-1]->misc&CHAN_GURU
				&& cfg.chan[channel-1]->guru<cfg.total_gurus)
				bprintf(text[NodeJoinedMultiChat]
					,cfg.sys_nodes+1,cfg.guru[cfg.chan[channel-1]->guru]->name
					,channel);
			outchar(BEL);
			for(i=0;i<preusrs;i++) {
				for(j=0;j<usrs;j++)
					if(preusr[i]==usr[j])
						break;
				if(j==usrs) {
					getnodedat(preusr[i],&node,0);
					if(node.misc&NODE_ANON)
						sprintf(str,"%.80s",text[UNKNOWN_USER]);
					else
						username(&cfg,node.useron,str);
					bprintf(text[NodeLeftMultiChat]
						,preusr[i],str,channel); } } }
		else if(preusrs<usrs) {
			if(!preusrs && channel && cfg.chan[channel-1]->misc&CHAN_GURU
				&& cfg.chan[channel-1]->guru<cfg.total_gurus)
				bprintf(text[NodeLeftMultiChat]
					,cfg.sys_nodes+1,cfg.guru[cfg.chan[channel-1]->guru]->name
					,channel);
			outchar(BEL);
			for(i=0;i<usrs;i++) {
				for(j=0;j<preusrs;j++)
					if(usr[i]==preusr[j])
						break;
				if(j==preusrs) {
					getnodedat(usr[i],&node,0);
					if(node.misc&NODE_ANON)
						sprintf(str,"%.80s",text[UNKNOWN_USER]);
					else
						username(&cfg,node.useron,str);
					bprintf(text[NodeJoinedMultiChat]
						,usr[i],str,channel); } } }
		preusrs=usrs;
		for(i=0;i<usrs;i++)
			preusr[i]=usr[i];
		attr(cfg.color[clr_multichat]);
		SYNC;
		sys_status&=~SS_ABORT;
172
		if((ch=inkey(K_NONE,250))!=0 || wordwrap[0]) {
rswindell's avatar
rswindell committed
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
			if(ch=='/') {
				bputs(text[MultiChatCommandPrompt]);
				strcpy(str,"ACELWQ?*");
				if(SYSOP)
					strcat(str,"0");
				i=getkeys(str,cfg.total_chans);
				if(i&0x80000000L) {  /* change channel */
					savch=(char)(i&~0x80000000L);
					if(savch==channel)
						continue;
					if(!chan_access(savch-1))
						continue;
					bprintf(text[WelcomeToChannelN]
						,savch,cfg.chan[savch-1]->name);

					usrs=0;
					for(i=1;i<=cfg.sys_nodes;i++) {
						if(i==cfg.node_num)
							continue;
						getnodedat(i,&node,0);
						if(node.action!=NODE_MCHT
							|| node.status!=NODE_INUSE)
							continue;
						if(node.aux && (node.aux&0xff)!=savch)
							continue;
						printnodedat(i,&node);
						if(node.aux&0x1f00) {	/* password */
							bprintf(text[PasswordProtected]
								,node.misc&NODE_ANON
								? text[UNKNOWN_USER]
								: username(&cfg,node.useron,tmp));
							if(!getstr(str,8,K_UPPER|K_ALPHA|K_LINE))
								break;
							if(strcmp(str,unpackchatpass(tmp,&node)))
								break;
								bputs(text[CorrectPassword]);  }
						preusr[usrs]=usr[usrs++]=(char)i; }
					if(i<=cfg.sys_nodes) {	/* failed password */
						bputs(text[WrongPassword]);
						continue; }
					if(gurubuf) {
deuce's avatar
deuce committed
214
						free(gurubuf);
rswindell's avatar
rswindell committed
215 216 217 218 219 220 221 222 223 224
						gurubuf=NULL; }
					if(cfg.chan[savch-1]->misc&CHAN_GURU
						&& cfg.chan[savch-1]->guru<cfg.total_gurus
						&& chk_ar(cfg.guru[cfg.chan[savch-1]->guru]->ar,&useron
						)) {
						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; }
deuce's avatar
deuce committed
225
						if((gurubuf=(char *)malloc(filelength(file)+1))==NULL) {
rswindell's avatar
rswindell committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
							close(file);
							errormsg(WHERE,ERR_ALLOC,str
								,filelength(file)+1);
							break; }
						read(file,gurubuf,filelength(file));
						gurubuf[filelength(file)]=0;
						close(file); }
					preusrs=usrs;
					if(gurubuf)
						bprintf(text[NodeInMultiChatLocally]
							,cfg.sys_nodes+1
							,cfg.guru[cfg.chan[savch-1]->guru]->name
							,savch);
					channel=savch;
					if(!usrs && cfg.chan[savch-1]->misc&CHAN_PW
						&& !noyes(text[PasswordProtectChanQ])) {
						bputs(text[PasswordPrompt]);
						if(getstr(str,8,K_UPPER|K_ALPHA|K_LINE)) {
244
							getnodedat(cfg.node_num,&thisnode,true);
rswindell's avatar
rswindell committed
245 246 247
							thisnode.aux=channel;
							packchatpass(str,&thisnode); }
						else {
248
							getnodedat(cfg.node_num,&thisnode,true);
rswindell's avatar
rswindell committed
249 250
							thisnode.aux=channel; } }
					else {
251
						getnodedat(cfg.node_num,&thisnode,true);
rswindell's avatar
rswindell committed
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
						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); }
				else switch(i) {	/* other command */
					case '0':	/* Global channel */
						if(!SYSOP)
							break;
                        usrs=0;
						for(i=1;i<=cfg.sys_nodes;i++) {
							if(i==cfg.node_num)
								continue;
							getnodedat(i,&node,0);
							if(node.action!=NODE_MCHT
								|| node.status!=NODE_INUSE)
								continue;
							printnodedat(i,&node);
							preusr[usrs]=usr[usrs++]=(char)i; }
						preusrs=usrs;
273 274 275 276
						if(getnodedat(cfg.node_num,&thisnode,true)==0) {
							thisnode.aux=channel=0;
							putnodedat(cfg.node_num,&thisnode);
						}
rswindell's avatar
rswindell committed
277 278 279 280 281 282 283 284 285 286 287
						break;
					case 'A':   /* Action commands */
						useron.chat^=CHAT_ACTION;
						bprintf("\r\nAction commands are now %s\r\n"
							,useron.chat&CHAT_ACTION
							? text[ON]:text[OFF]);
						putuserrec(&cfg,useron.number,U_CHAT,8
							,ultoa(useron.chat,str,16));
						break;
					case 'C':   /* List of action commands */
						CRLF;
288
						for(i=0;channel && i<cfg.total_chatacts;i++) {
rswindell's avatar
rswindell committed
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
							if(cfg.chatact[i]->actset
								!=cfg.chan[channel-1]->actset)
								continue;
							bprintf("%-*.*s",LEN_CHATACTCMD
								,LEN_CHATACTCMD,cfg.chatact[i]->cmd);
							if(!((i+1)%8)) {
								CRLF; }
							else
								bputs(" "); }
						CRLF;
						break;
					case 'E':   /* Toggle echo */
						useron.chat^=CHAT_ECHO;
						bprintf(text[EchoIsNow]
							,useron.chat&CHAT_ECHO
							? text[ON]:text[OFF]);
						putuserrec(&cfg,useron.number,U_CHAT,8
							,ultoa(useron.chat,str,16));
						break;
					case 'L':	/* list nodes */
						CRLF;
						for(i=1;i<=cfg.sys_nodes && i<=cfg.sys_lastnode;i++) {
							getnodedat(i,&node,0);
							printnodedat(i,&node); }
						CRLF;
						break;
					case 'W':   /* page node(s) */
						j=getnodetopage(0,0);
						if(!j)
							break;
						for(i=0;i<usrs;i++)
							if(usr[i]==j)
								break;
						if(i>=usrs) {
							bputs(text[UserNotFound]);
							break; }

						bputs(text[NodeMsgPrompt]);
						if(!getstr(line,66,K_LINE|K_MSG))
							break;

						sprintf(buf,text[ChatLineFmt]
							,thisnode.misc&NODE_ANON
							? text[AnonUserChatHandle]
							: useron.handle
							,cfg.node_num,'*',line);
						strcat(buf,crlf);
						if(useron.chat&CHAT_ECHO)
							bputs(buf);
338
						putnmsg(&cfg,j,buf);
rswindell's avatar
rswindell committed
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
						break;
					case 'Q':	/* quit */
						done=1;
						break;
					case '*':
						sprintf(str,"%smenu/chan.*",cfg.text_dir);
						if(fexist(str))
							menu("chan");
						else {
							bputs(text[ChatChanLstHdr]);
							bputs(text[ChatChanLstTitles]);
							if(cfg.total_chans>=10) {
								bputs("     ");
								bputs(text[ChatChanLstTitles]); }
							CRLF;
							bputs(text[ChatChanLstUnderline]);
							if(cfg.total_chans>=10) {
								bputs("     ");
								bputs(text[ChatChanLstUnderline]); }
							CRLF;
							if(cfg.total_chans>=10)
								j=(cfg.total_chans/2)+(cfg.total_chans&1);
							else
								j=cfg.total_chans;
							for(i=0;i<j && !msgabort();i++) {
								bprintf(text[ChatChanLstFmt],i+1
									,cfg.chan[i]->name
									,cfg.chan[i]->cost);
								if(cfg.total_chans>=10) {
									k=(cfg.total_chans/2)
										+i+(cfg.total_chans&1);
									if(k<cfg.total_chans) {
										bputs("     ");
										bprintf(text[ChatChanLstFmt]
											,k+1
											,cfg.chan[k]->name
											,cfg.chan[k]->cost); } }
								CRLF; }
							CRLF; }
						break;
					case '?':	/* menu */
						menu("multchat");
381 382 383
						break;	
				} 
			} else {
rswindell's avatar
rswindell committed
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
				ungetkey(ch);
				j=0;
				pgraph[0]=0;
				while(j<5) {
					if(!getstr(line,66,K_WRAP|K_MSG|K_CHAT))
						break;
					if(j) {
						sprintf(str,text[ChatLineFmt]
							,thisnode.misc&NODE_ANON
							? text[AnonUserChatHandle]
							: useron.handle
							,cfg.node_num,':',nulstr);
						sprintf(tmp,"%*s",bstrlen(str),nulstr);
						strcat(pgraph,tmp); }
					strcat(pgraph,line);
					strcat(pgraph,crlf);
					if(!wordwrap[0])
						break;
					j++; }
				if(pgraph[0]) {
404
					if(channel && useron.chat&CHAT_ACTION) {
rswindell's avatar
rswindell committed
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
						for(i=0;i<cfg.total_chatacts;i++) {
							if(cfg.chatact[i]->actset
								!=cfg.chan[channel-1]->actset)
								continue;
							sprintf(str,"%s ",cfg.chatact[i]->cmd);
							if(!strnicmp(str,pgraph,strlen(str)))
								break;
							sprintf(str,"%.*s"
								,LEN_CHATACTCMD+2,pgraph);
							str[strlen(str)-2]=0;
							if(!stricmp(cfg.chatact[i]->cmd,str))
								break; }

						if(i<cfg.total_chatacts) {
							p=pgraph+strlen(str);
							n=atoi(p);
							for(j=0;j<usrs;j++) {
								getnodedat(usr[j],&node,0);
								if(usrs==1) /* no need to search */
									break;
								if(n) {
									if(usr[j]==n)
										break;
									continue; }
								username(&cfg,node.useron,str);
								if(!strnicmp(str,p,strlen(str)))
									break;
								getuserrec(&cfg,node.useron,U_HANDLE
									,LEN_HANDLE,str);
								if(!strnicmp(str,p,strlen(str)))
									break; }
							if(!usrs
								&& cfg.chan[channel-1]->guru<cfg.total_gurus)
								strcpy(str
								,cfg.guru[cfg.chan[channel-1]->guru]->name);
							else if(j>=usrs)
								strcpy(str,"everyone");
							else if(node.misc&NODE_ANON)
								strcpy(str,text[UNKNOWN_USER]);
							else
								username(&cfg,node.useron,str);

							/* Display on same node */
							bprintf(cfg.chatact[i]->out
								,thisnode.misc&NODE_ANON
								? text[UNKNOWN_USER] : useron.alias
								,str);
							CRLF;

							if(usrs && j<usrs) {
								/* Display to dest user */
								sprintf(buf,cfg.chatact[i]->out
									,thisnode.misc&NODE_ANON
									? text[UNKNOWN_USER] : useron.alias
									,"you");
								strcat(buf,crlf);
461
								putnmsg(&cfg,usr[j],buf); }
rswindell's avatar
rswindell committed
462 463 464 465 466 467 468 469 470 471 472 473 474


							/* Display to all other users */
							sprintf(buf,cfg.chatact[i]->out
								,thisnode.misc&NODE_ANON
								? text[UNKNOWN_USER] : useron.alias
								,str);
							strcat(buf,crlf);

							for(i=0;i<usrs;i++) {
								if(i==j)
									continue;
								getnodedat(usr[i],&node,0);
475
								putnmsg(&cfg,usr[i],buf); }
rswindell's avatar
rswindell committed
476 477
							for(i=0;i<qusrs;i++) {
								getnodedat(qusr[i],&node,0);
478
								putnmsg(&cfg,qusr[i],buf); }
rswindell's avatar
rswindell committed
479 480 481 482 483 484 485 486 487 488 489
							continue; } }

					sprintf(buf,text[ChatLineFmt]
						,thisnode.misc&NODE_ANON
						? text[AnonUserChatHandle]
						: useron.handle
						,cfg.node_num,':',pgraph);
					if(useron.chat&CHAT_ECHO)
						bputs(buf);
					for(i=0;i<usrs;i++) {
						getnodedat(usr[i],&node,0);
490 491
						putnmsg(&cfg,usr[i],buf); 
					}
rswindell's avatar
rswindell committed
492 493
					for(i=0;i<qusrs;i++) {
						getnodedat(qusr[i],&node,0);
494 495
						putnmsg(&cfg,qusr[i],buf); 
					}
rswindell's avatar
rswindell committed
496 497
					if(!usrs && channel && gurubuf
						&& cfg.chan[channel-1]->misc&CHAN_GURU)
498 499 500 501
						guruchat(pgraph,gurubuf,cfg.chan[channel-1]->guru,guru_lastanswer);
				} 
			} 
		}
rswindell's avatar
rswindell committed
502
		if(sys_status&SS_ABORT)
503 504
			break; 
	}
rswindell's avatar
rswindell committed
505 506 507
	lncntr=0;
}

508 509
/****************************************************************************/
/****************************************************************************/
rswindell's avatar
rswindell committed
510 511 512 513 514 515 516
bool sbbs_t::guru_page(void)
{
	char	path[MAX_PATH+1];
	char*	gurubuf;
	int 	file;
	long	i;

517 518 519 520 521
	if(useron.rest&FLAG('C')) {
		bputs(text[R_Chat]);
		return(false); 
	}

rswindell's avatar
rswindell committed
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
	if(!cfg.total_gurus) {
		bprintf(text[SysopIsNotAvailable],"The Guru");
		return(false); 
	}
	if(cfg.total_gurus==1 && chk_ar(cfg.guru[0]->ar,&useron))
		i=0;
	else {
		for(i=0;i<cfg.total_gurus;i++)
			uselect(1,i,nulstr,cfg.guru[i]->name,cfg.guru[i]->ar);
		i=uselect(0,0,0,0,0);
		if(i<0)
			return(false); 
	}
	sprintf(path,"%s%s.dat",cfg.ctrl_dir,cfg.guru[i]->code);
	if((file=nopen(path,O_RDONLY))==-1) {
		errormsg(WHERE,ERR_OPEN,path,O_RDONLY);
		return(false); 
	}
deuce's avatar
deuce committed
540
	if((gurubuf=(char *)malloc(filelength(file)+1))==NULL) {
rswindell's avatar
rswindell committed
541 542 543 544 545 546 547 548
		close(file);
		errormsg(WHERE,ERR_ALLOC,path,filelength(file)+1);
		return(false); 
	}
	read(file,gurubuf,filelength(file));
	gurubuf[filelength(file)]=0;
	close(file);
	localguru(gurubuf,i);
deuce's avatar
deuce committed
549
	free(gurubuf);
rswindell's avatar
rswindell committed
550 551 552 553 554 555 556 557 558 559
	return(true);
}

/****************************************************************************/
/* The chat section                                                         */
/****************************************************************************/
void sbbs_t::chatsection()
{
	char	str[256],ch,no_rip_menu;

560 561 562 563 564
	if(useron.rest&FLAG('C')) {
		bputs(text[R_Chat]);
		return; 
	}

565
	action=NODE_CHAT;
566
	if(useron.misc&(RIP|WIP|HTML) || !(useron.misc&EXPERT))
567
		menu("chat");
568 569 570 571 572
	ASYNC;
	bputs(text[ChatPrompt]);
	while(online) {
		no_rip_menu=0;
		ch=(char)getkeys("ACDJPQST?\r",0);
573
		if(ch>' ')
574 575 576 577 578
			logch(ch,0);
		switch(ch) {
			case 'S':
				useron.chat^=CHAT_SPLITP;
				putuserrec(&cfg,useron.number,U_CHAT,8
579
					,ultoa(useron.chat,str,16));
580 581 582 583 584 585 586
				bprintf("\r\nPrivate split-screen chat is now: %s\r\n"
					,useron.chat&CHAT_SPLITP ? text[ON]:text[OFF]);
				break;
			case 'A':
				CRLF;
				useron.chat^=CHAT_NOACT;
				putuserrec(&cfg,useron.number,U_CHAT,8
587
					,ultoa(useron.chat,str,16));
588 589 590 591
				if(getnodedat(cfg.node_num,&thisnode,true)==0) {
					thisnode.misc^=NODE_AOFF;
					printnodedat(cfg.node_num,&thisnode);
				}
592 593 594 595 596 597 598
				putnodedat(cfg.node_num,&thisnode);
				no_rip_menu=true;
				break;
			case 'D':
				CRLF;
				useron.chat^=CHAT_NOPAGE;
				putuserrec(&cfg,useron.number,U_CHAT,8
599
					,ultoa(useron.chat,str,16));
600 601 602 603
				if(getnodedat(cfg.node_num,&thisnode,true)==0) {
					thisnode.misc^=NODE_POFF;
					printnodedat(cfg.node_num,&thisnode);
				}
604 605 606 607
				putnodedat(cfg.node_num,&thisnode);
				no_rip_menu=true;
				break;
			case 'J':
rswindell's avatar
rswindell committed
608
				multinodechat();
609 610 611 612 613 614
				break;
			case 'P':   /* private node-to-node chat */
				privchat();
				break;
			case 'C':
				no_rip_menu=1;
rswindell's avatar
rswindell committed
615 616
				if(sysop_page())
					break;
617 618 619 620 621 622
				if(cfg.total_gurus && chk_ar(cfg.guru[0]->ar,&useron)) {
					sprintf(str,text[ChatWithGuruInsteadQ],cfg.guru[0]->name);
					if(!yesno(str))
						break; }
				else
					break;
rswindell's avatar
rswindell committed
623
				/* FALL-THROUGH */
624
			case 'T':
rswindell's avatar
rswindell committed
625
				guru_page();
626 627 628 629
				no_rip_menu=1;
				break;
			case '?':
				if(useron.misc&EXPERT)
630
					menu("chat");
631 632 633
				break;
			default:	/* 'Q' or <CR> */
				lncntr=0;
rswindell's avatar
rswindell committed
634
//				if(gurubuf)
deuce's avatar
deuce committed
635
//					free(gurubuf);
636 637
				return; }
		action=NODE_CHAT;
638
		if(!(useron.misc&EXPERT) || useron.misc&(WIP|HTML)
639
			|| (useron.misc&RIP && !no_rip_menu)) {
640 641
			menu("chat"); 
		}
642 643
		ASYNC;
		bputs(text[ChatPrompt]); }
rswindell's avatar
rswindell committed
644
//	if(gurubuf)
deuce's avatar
deuce committed
645
//		free(gurubuf);
646 647
}

648 649
/****************************************************************************/
/****************************************************************************/
rswindell's avatar
rswindell committed
650
bool sbbs_t::sysop_page(void)
651
{
652 653
	char	str[256];
	int		i;
654

655 656 657 658 659
	if(useron.rest&FLAG('C')) {
		bputs(text[R_Chat]);
		return(false); 
	}

rswindell's avatar
rswindell committed
660 661 662 663
	if(startup->options&BBS_OPT_SYSOP_AVAILABLE 
		|| (cfg.sys_chat_ar[0] && chk_ar(cfg.sys_chat_ar,&useron))
		|| useron.exempt&FLAG('C')) {

664 665 666
		sprintf(str,"%s paged sysop for chat",useron.alias);
		logline("C",str);

rswindell's avatar
rswindell committed
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694
		for(i=0;i<cfg.total_pages;i++)
			if(chk_ar(cfg.page[i]->ar,&useron))
				break;
		if(i<cfg.total_pages) {
			bprintf(text[PagingGuru],cfg.sys_op);
			external(cmdstr(cfg.page[i]->cmd,nulstr,nulstr,NULL)
				,cfg.page[i]->misc&IO_INTS ? EX_OUTL|EX_OUTR|EX_INR
					: EX_OUTL); }
		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; }
		else {
			sys_status^=SS_SYSPAGE;
			bprintf(text[SysopPageIsNow]
				,sys_status&SS_SYSPAGE ? text[ON] : text[OFF]);
			nosound();	
		}

		return(true);
	}

	bprintf(text[SysopIsNotAvailable],cfg.sys_op);

	return(false);
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
}

/****************************************************************************/
/* Returns 1 if user online has access to channel "channum"                 */
/****************************************************************************/
bool sbbs_t::chan_access(uint cnum)
{

	if(!cfg.total_chans || cnum>=cfg.total_chans || !chk_ar(cfg.chan[cnum]->ar,&useron)) {
		bputs(text[CantAccessThatChannel]);
		return(false); }
	if(!(useron.exempt&FLAG('J')) && cfg.chan[cnum]->cost>useron.cdt+useron.freecdt) {
		bputs(text[NotEnoughCredits]);
		return(false); }
	return(true);
}

712 713 714
/****************************************************************************/
/* Private split-screen (or interspersed) chat with node or local sysop		*/
/****************************************************************************/
715 716 717 718
void sbbs_t::privchat(bool local)
{
	char	str[128],c,*p,localbuf[5][81],remotebuf[5][81]
			,localline=0,remoteline=0,localchar=0,remotechar=0
719 720 721
			,*sep=text[PrivateChatSeparator]
			,*local_sep=text[SysopChatSeparator]
			;
722
	char 	tmp[512];
723
	char	outpath[MAX_PATH+1];
724
	char	inpath[MAX_PATH+1];
725 726
	uchar	ch;
	int 	in,out,i,n,echo=1,x,y,activity,remote_activity;
727
    int		local_y=1,remote_y=1;
728
	node_t	node;
729
	time_t	last_nodechk=0;
730

731 732 733 734 735
	if(useron.rest&FLAG('C')) {
		bputs(text[R_Chat]);
		return; 
	}

736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
	if(local) 
		n=0;
	else {
		n=getnodetopage(0,0);
		if(!n)
			return;
		if(n==cfg.node_num) {
			bputs(text[NoNeedToPageSelf]);
			return; }
		getnodedat(n,&node,0);
		if(node.action==NODE_PCHT && node.aux!=cfg.node_num) {
			bprintf(text[NodeNAlreadyInPChat],n);
			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; }
		if(node.action!=NODE_PAGE) {
755
			bprintf(text[PagingUser]
756
				,node.misc&NODE_ANON ? text[UNKNOWN_USER] : username(&cfg,node.useron,tmp)
757
				,node.misc&NODE_ANON ? 0 : node.useron);
758 759 760
			sprintf(str,text[NodePChatPageMsg]
				,cfg.node_num,thisnode.misc&NODE_ANON
					? text[UNKNOWN_USER] : useron.alias);
761
			putnmsg(&cfg,n,str);
762 763
			sprintf(str,"%s paged %s on node %d to private chat"
				,useron.alias,username(&cfg,node.useron,tmp),n);
764 765
			logline("C",str); }

766 767 768 769 770
		if(getnodedat(cfg.node_num,&thisnode,true)==0) {
			thisnode.action=action=NODE_PAGE;
			thisnode.aux=n;
			putnodedat(cfg.node_num,&thisnode);
		}
771 772 773 774 775 776 777 778 779 780

		if(node.action!=NODE_PAGE || node.aux!=cfg.node_num) {
			bprintf(text[WaitingForNodeInPChat],n);
			while(online && !(sys_status&SS_ABORT)) {
				getnodedat(n,&node,0);
				if((node.action==NODE_PAGE || node.action==NODE_PCHT)
					&& node.aux==cfg.node_num) {
					bprintf(text[NodeJoinedPrivateChat]
						,n,node.misc&NODE_ANON ? text[UNKNOWN_USER]
							: username(&cfg,node.useron,tmp));
781 782
					break; 
				}
783 784 785
				action=NODE_PAGE;
				checkline();
				gettimeleft();
786
				SYNC; 
787
				inkey(K_NONE,500);
788 789
			} 
		}
790 791
	}

792 793
	gettimeleft();

794 795 796 797 798 799
	if(getnodedat(cfg.node_num,&thisnode,true)==0) {
		thisnode.action=action=NODE_PCHT;
		thisnode.aux=n;
		thisnode.misc&=~NODE_LCHAT;
		putnodedat(cfg.node_num,&thisnode);
	}
800 801 802 803

	if(!online || sys_status&SS_ABORT)
		return;

804 805
	if(((sys_status&SS_USERON && useron.chat&CHAT_SPLITP) || !(sys_status&SS_USERON))
		&& term_supports(ANSI) && rows>=24)
806
		sys_status|=SS_SPLITP;
807 808
	else
		sys_status&=~SS_SPLITP;
809 810
	/*
	if(!(useron.misc&EXPERT))
811
		menu("privchat");
812 813 814 815 816 817 818 819 820
	*/

	if(!(sys_status&SS_SPLITP)) {
		if(local)
			bprintf(text[SysopIsHere],cfg.sys_op);
		else
			bputs(text[WelcomeToPrivateChat]);
	}

821
	sprintf(outpath,"%schat.dab",cfg.node_dir);
822
	if((out=sopen(outpath,O_RDWR|O_CREAT|O_BINARY,SH_DENYNO,DEFFILEMODE))==-1) {
823
		errormsg(WHERE,ERR_OPEN,outpath,O_RDWR|O_DENYNONE|O_CREAT);
824 825
		return; 
	}
826 827

	if(local)
828
		sprintf(inpath,"%slchat.dab",cfg.node_dir);
829
	else
830 831
		sprintf(inpath,"%schat.dab",cfg.node_path[n-1]);
	if(!fexist(inpath))		/* Wait while it's created for the first time */
832
		mswait(2000);
833
	if((in=sopen(inpath,O_RDWR|O_CREAT|O_BINARY,SH_DENYNO,DEFFILEMODE))==-1) {
834 835 836 837
		close(out);
		errormsg(WHERE,ERR_OPEN,str,O_RDWR|O_DENYNONE|O_CREAT);
		return; }

deuce's avatar
deuce committed
838
	if((p=(char *)malloc(PCHAT_LEN))==NULL) {
839 840 841 842 843 844 845
		close(in);
		close(out);
		errormsg(WHERE,ERR_ALLOC,str,PCHAT_LEN);
		return; }
	memset(p,0,PCHAT_LEN);
	write(in,p,PCHAT_LEN);
	write(out,p,PCHAT_LEN);
deuce's avatar
deuce committed
846
	free(p);
847 848 849
	lseek(in,0L,SEEK_SET);
	lseek(out,0L,SEEK_SET);

850 851 852 853
	if(getnodedat(cfg.node_num,&thisnode,true)==0) {
		thisnode.misc&=~NODE_RPCHT; 		/* Clear "reset pchat flag" */
		putnodedat(cfg.node_num,&thisnode);
	}
854 855

	if(!local) {
856 857 858 859
		if(getnodedat(n,&node,true)==0) {
			node.misc|=NODE_RPCHT;				/* Set "reset pchat flag" */
			putnodedat(n,&node); 				/* on other node */
		}
860 861 862 863 864 865 866 867 868 869 870 871 872

											/* Wait for other node */
											/* to acknowledge and reset */
		while(online && !(sys_status&SS_ABORT)) {
			getnodedat(n,&node,0);
			if(!(node.misc&NODE_RPCHT))
				break;
			getnodedat(cfg.node_num,&thisnode,0);
			if(thisnode.misc&NODE_RPCHT)
				break;
			checkline();
			gettimeleft();
			SYNC;
873 874
			SLEEP(500); 
		}
875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890
	}

	action=NODE_PCHT;
	SYNC;

	if(sys_status&SS_SPLITP) {
		lncntr=0;
		CLS;
		ANSI_SAVE();
#if 0
		if(local)
			bprintf(text[SysopIsHere],cfg.sys_op);
#endif
		GOTOXY(1,13);
		remote_y=1;
		bprintf(local ? local_sep : sep
891
			,thisnode.misc&NODE_MSGW ? 'T':' '
892
			,sectostr(timeleft,tmp)
893
			,thisnode.misc&NODE_NMSG ? 'M':' ');
894 895 896 897 898 899 900 901 902 903
		CRLF;
		local_y=14; }

	while(online && (local || !(sys_status&SS_ABORT))) {
		lncntr=0;
		if(sys_status&SS_SPLITP)
			lbuflen=0;
		action=NODE_PCHT;
		activity=0;
		remote_activity=0;
904
		if((ch=inkey(K_GETSTR,100))!=0) {
905 906 907
			activity=1;
			if(echo)
				attr(cfg.color[clr_chatlocal]);
908
			if(ch==BS || ch==DEL) {
909 910
				if(localchar) {
					if(echo)
911
						backspace();
912 913 914 915
					localchar--;
					localbuf[localline][localchar]=0; } }
			else if(ch==TAB) {
				if(echo)
916 917
					outchar(' ');
				localbuf[localline][localchar]=' ';
918 919 920
				localchar++;
				while(localchar<78 && localchar%8) {
					if(echo)
921 922
						outchar(' ');
					localbuf[localline][localchar++]=' '; } }
923
			else if(ch==CTRL_R) {
924 925 926 927 928 929 930 931 932 933 934 935 936 937
				if(sys_status&SS_SPLITP) {
					CLS;
					attr(cfg.color[clr_chatremote]);
					remotebuf[remoteline][remotechar]=0;
					for(i=0;i<=remoteline;i++) {
						bputs(remotebuf[i]); 
						if(i!=remoteline) 
							bputs(crlf);
					}
					remote_y=1+remoteline;
					bputs("\1i_\1n");  /* Fake cursor */
					ANSI_SAVE();
					GOTOXY(1,13);
					bprintf(local ? local_sep : sep
938
						,thisnode.misc&NODE_MSGW ? 'T':' '
939
						,sectostr(timeleft,tmp)
940
						,thisnode.misc&NODE_NMSG ? 'M':' ');
941 942 943 944 945 946 947 948 949 950
					CRLF;
					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;
				}
951
				continue;
952
			}
953
			else if(ch>=' ' || ch==CR) {
954 955 956 957 958
				if(ch!=CR) {
					if(echo)
						outchar(ch);
					localbuf[localline][localchar]=ch; }

959
				if(ch==CR || (localchar>68 && ch==' ') || ++localchar>78) {
960 961 962 963 964 965 966

					localbuf[localline][localchar]=0;
					localchar=0;

					if(sys_status&SS_SPLITP && local_y==24) {
						GOTOXY(1,13);
						bprintf(local ? local_sep : sep
967
							,thisnode.misc&NODE_MSGW ? 'T':' '
968
							,sectostr(timeleft,tmp)
969
							,thisnode.misc&NODE_NMSG ? 'M':' ');
970 971
						attr(cfg.color[clr_chatlocal]);
						for(x=13,y=0;x<rows;x++,y++) {
972
							rprintf("\x1b[%d;1H\x1b[K",x+1);
973 974 975 976 977 978 979 980 981 982 983 984 985 986
							if(y<=localline)
								bprintf("%s\r\n",localbuf[y]); }
						GOTOXY(1,local_y=(15+localline));
						localline=0; }
					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)
987
								cleartoeol(); 
988 989
						} 
					}
990
					// SYNC;
991 992
				} 
			}
993 994 995 996 997 998 999 1000 1001 1002 1003

			read(out,&c,1);
			lseek(out,-1L,SEEK_CUR);
			if(!c)		/* hasn't wrapped */
				write(out,&ch,1);
			else {
				if(!tell(out))
					lseek(out,0L,SEEK_END);
				lseek(out,-1L,SEEK_CUR);
				ch=0;
				write(out,&ch,1);
1004 1005 1006
				lseek(out,-1L,SEEK_CUR); 
			}
			utime(outpath,NULL);	/* update mod time for NFS/smbfs nodes */
1007 1008
			if(tell(out)>=PCHAT_LEN)
				lseek(out,0L,SEEK_SET);
1009
		}
1010 1011 1012 1013 1014 1015
		else while(online) {
			if(!(sys_status&SS_SPLITP))
				remotechar=localchar;
			if(tell(in)>=PCHAT_LEN)
				lseek(in,0L,SEEK_SET);
			ch=0;
1016
			utime(inpath,NULL);
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
			read(in,&ch,1);
			lseek(in,-1L,SEEK_CUR);
			if(!ch) break;					  /* char from other node */
			activity=1;
			if(sys_status&SS_SPLITP && !remote_activity) {
				ansi_getxy(&x,&y);
				ANSI_RESTORE();
			}
			attr(cfg.color[clr_chatremote]);
			if(sys_status&SS_SPLITP && !remote_activity)
1027
				backspace();             /* Delete fake cursor */
1028
			remote_activity=1;
1029
			if(ch==BS || ch==DEL) {
1030
				if(remotechar) {
1031
					backspace();
1032 1033 1034
					remotechar--;
					remotebuf[remoteline][remotechar]=0; } }
			else if(ch==TAB) {
1035 1036
				outchar(' ');
				remotebuf[remoteline][remotechar]=' ';
1037 1038
				remotechar++;
				while(remotechar<78 && remotechar%8) {
1039 1040 1041
					outchar(' ');
					remotebuf[remoteline][remotechar++]=' '; } }
			else if(ch>=' ' || ch==CR) {
1042 1043 1044 1045
				if(ch!=CR) {
					outchar(ch);
					remotebuf[remoteline][remotechar]=ch; }

1046
				if(ch==CR || (remotechar>68 && ch==' ') || ++remotechar>78) {
1047 1048 1049 1050 1051 1052 1053

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

					if(sys_status&SS_SPLITP && remote_y==12) {
						CRLF;
						bprintf(local ? local_sep : sep
1054
							,thisnode.misc&NODE_MSGW ? 'T':' '
1055
							,sectostr(timeleft,tmp)
1056
							,thisnode.misc&NODE_NMSG ? 'M':' ');
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
						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]); }
						remoteline=0;
						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)
1074 1075 1076 1077 1078
								cleartoeol(); 
						} 
					} 
				} 
			}
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
			ch=0;
			write(in,&ch,1);

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

		if(sys_status&SS_SPLITP && remote_activity) {
			bputs("\1i_\1n");  /* Fake cursor */
			ANSI_SAVE();
1089 1090
			GOTOXY(x,y); 
		}
1091

1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111
		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(); 
			}

1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
			if(!local) {
				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);
1131 1132 1133 1134
				if(getnodedat(cfg.node_num,&thisnode,true)==0) {
					thisnode.misc&=~NODE_RPCHT;
					putnodedat(cfg.node_num,&thisnode); 
				}
1135
			}
1136 1137
			last_nodechk=now;
			gettimeleft(); 
1138 1139
		}
	}
1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150
	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];
1151
	char 	tmp[512];
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251
	uint 	i,j;
	ulong	l;
	node_t	node;

	if(!lastnodemsg)
		lastnodemsguser[0]=0;
	if(lastnodemsg) {
		getnodedat(lastnodemsg,&node,0);
		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);
		if(i==cfg.node_num)
			continue;
		if(node.status==NODE_INUSE || (SYSOP && node.status==NODE_QUIET)) {
			if(!lastnodemsg)
				lastnodemsg=i;
			j++; } }

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

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

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

	strcpy(str,lastnodemsguser);
	getstr(str,LEN_ALIAS,K_UPRLWR|K_LINE|K_EDIT|K_AUTODEL);
	if(sys_status&SS_ABORT)
		return(0);
	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);
			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); }
		strcpy(lastnodemsguser,str);
		if(telegram)
			return(node.useron);
		return(j); }
	if(all && !stricmp(str,"ALL"))
		return(-1);

	if(str[0]=='\'') {
		j=userdatdupe(0,U_HANDLE,LEN_HANDLE,str+1,0);
		if(!j) {
			bputs(text[UnknownUser]);
			return(0); } }
	else if(str[0]=='#')
		j=atoi(str+1);
	else
		j=finduser(str);
	if(!j)
		return(0);
	if(j>lastuser(&cfg))
		return(0);
	getuserrec(&cfg,j,U_MISC,8,tmp);
	l=ahtoul(tmp);
	if(l&(DELETED|INACTIVE)) {              /* Deleted or Inactive User */
		bputs(text[UnknownUser]);
		return(0); }

	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