atcodes.cpp 34.6 KB
Newer Older
1
/* Synchronet "@code" functions */
2
// vi: tabstop=4
3
4
5
6
7
8
9

/* $Id$ */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
10
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
11
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
 *																			*
 * 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"
#include "cmdshell.h"

40
41
42
43
44
45
46
#if defined(_WINSOCKAPI_)
	extern WSADATA WSAData;
	#define SOCKLIB_DESC WSAData.szDescription
#else
	#define	SOCKLIB_DESC NULL
#endif

47
48
49
/****************************************************************************/
/* Returns 0 if invalid @ code. Returns length of @ code if valid.          */
/****************************************************************************/
50
int sbbs_t::show_atcode(const char *instr)
51
{
52
	char	str[128],str2[128],*tp,*sp,*p;
53
    int     len;
54
	int		disp_len;
55
56
	bool	padded_left=false;
	bool	padded_right=false;
57
	bool	centered=false;
58
	bool	zero_padded=false;
rswindell's avatar
rswindell committed
59
	bool	truncated = true;
60
	const char *cp;
61

62
	SAFECOPY(str,instr);
63
64
65
	tp=strchr(str+1,'@');
	if(!tp)                 /* no terminating @ */
		return(0);
66
	sp=strchr(str+1,' ');
67
68
69
70
71
72
	if(sp && sp<tp)         /* space before terminating @ */
		return(0);
	len=(tp-str)+1;
	(*tp)=0;
	sp=(str+1);

73
	disp_len=len;
74
75
76
77
	if((p=strstr(sp,"-L"))!=NULL)
		padded_left=true;
	else if((p=strstr(sp,"-R"))!=NULL)
		padded_right=true;
78
79
	else if((p=strstr(sp,"-C"))!=NULL)
		centered=true;
80
81
	else if((p=strstr(sp,"-Z"))!=NULL)
		zero_padded=true;
rswindell's avatar
rswindell committed
82
83
	else if((p=strstr(sp,"-W"))!=NULL)	/* wrap */
		truncated = false;
84
	if(p!=NULL) {
rswindell's avatar
rswindell committed
85
86
87
		char* lp = p + 2;
		if(*lp && isdigit(*lp))
			disp_len=atoi(lp);
88
		*p=0;
89
	}
90

91
92
	cp=atcode(sp,str2,sizeof(str2));
	if(cp==NULL)
93
94
		return(0);

rswindell's avatar
rswindell committed
95
96
97
98
99
100
101
102
103
104
105
	if(p==NULL || truncated == false)
		disp_len = strlen(cp);

	if(truncated) {
		if(column + disp_len > cols - 1) {
			if(column >= cols - 1)
				disp_len = 0;
			else
				disp_len = (cols - 1) - column;
		}
	}
106
	if(padded_left)
107
		bprintf("%-*.*s",disp_len,disp_len,cp);
108
	else if(padded_right)
109
		bprintf("%*.*s",disp_len,disp_len,cp);
110
	else if(centered) {
rswindell's avatar
rswindell committed
111
		int vlen = strlen(cp);
112
113
114
115
		if(vlen < disp_len) {
			int left = (disp_len - vlen) / 2;
			bprintf("%*s%-*s", left, "", disp_len - left, cp);
		} else
116
			bprintf("%.*s", disp_len, cp);
117
	} else if(zero_padded) {
118
119
		int vlen = strlen(cp);
		if(vlen < disp_len)
120
			bprintf("%-.*s%s", (int)(disp_len - strlen(cp)), "0000000000", cp);
121
122
		else
			bprintf("%.*s", disp_len, cp);
123
	} else
rswindell's avatar
rswindell committed
124
		bprintf("%.*s", disp_len, cp);
125
126
127
128

	return(len);
}

129
const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen)
130
131
132
{
	char*	tp;
	uint	i;
133
134
	uint	ugrp;
	uint	usub;
135
136
137
138
139
140
141
	long	l;
    stats_t stats;
    node_t  node;
	struct	tm tm;

	str[0]=0;

142
	if(!strcmp(sp,"VER"))
143
		return(VERSION);
144

145
	if(!strcmp(sp,"REV")) {
146
		safe_snprintf(str,maxlen,"%c",REVISION);
147
148
		return(str);
	}
149

150
	if(!strcmp(sp,"FULL_VER")) {
151
		safe_snprintf(str,maxlen,"%s%c%s",VERSION,REVISION,beta_version);
152
		truncsp(str);
153
#if defined(_DEBUG)
154
		strcat(str," Debug");
155
#endif
156
		return(str);
157
158
	}

159
	if(!strcmp(sp,"VER_NOTICE"))
160
		return(VERSION_NOTICE);
161

162
163
	if(!strcmp(sp,"OS_VER"))
		return(os_version(str));
164
165

#ifdef JAVASCRIPT
166
167
	if(!strcmp(sp,"JS_VER"))
		return((char *)JS_GetImplementationVersion());
168
169
#endif

170
171
	if(!strcmp(sp,"PLATFORM"))
		return(PLATFORM_DESC);
172

173
174
	if(!strcmp(sp,"COPYRIGHT"))
		return(COPYRIGHT_NOTICE);
175

176
	if(!strcmp(sp,"COMPILER")) {
177
178
179
		char compiler[32];
		DESCRIBE_COMPILER(compiler);
		strncpy(str, compiler, maxlen);
180
		return(str);
181
182
	}

183
	if(!strcmp(sp,"UPTIME")) {
184
		extern volatile time_t uptime;
185
186
187
188
		time_t up=0;
		now = time(NULL);
		if (uptime != 0 && now >= uptime)
			up = now-uptime;
189
190
		char   days[64]="";
		if((up/(24*60*60))>=2) {
191
	        sprintf(days,"%lu days ",(ulong)(up/(24L*60L*60L)));
192
193
			up%=(24*60*60);
		}
194
		safe_snprintf(str,maxlen,"%s%lu:%02lu"
195
	        ,days
196
197
			,(ulong)(up/(60L*60L))
			,(ulong)((up/60L)%60L)
198
			);
199
		return(str);
200
201
	}

202
	if(!strcmp(sp,"SERVED")) {
203
		extern volatile ulong served;
204
		safe_snprintf(str,maxlen,"%lu",served);
205
206
207
		return(str);
	}

208
	if(!strcmp(sp,"SOCKET_LIB"))
209
		return(socklib_version(str,SOCKLIB_DESC));
210

211
	if(!strcmp(sp,"MSG_LIB")) {
212
		safe_snprintf(str,maxlen,"SMBLIB %s",smb_lib_ver());
213
214
		return(str);
	}
215

216
217
	if(!strcmp(sp,"BBS") || !strcmp(sp,"BOARDNAME"))
		return(cfg.sys_name);
218

219
	if(!strcmp(sp,"BAUD") || !strcmp(sp,"BPS")) {
220
		safe_snprintf(str,maxlen,"%lu",cur_rate);
221
222
		return(str);
	}
223

rswindell's avatar
rswindell committed
224
225
226
227
228
229
230
231
232
233
234
	if(!strcmp(sp,"COLS")) {
		safe_snprintf(str,maxlen,"%lu",cols);
		return(str);
	}
	if(!strcmp(sp,"ROWS")) {
		safe_snprintf(str,maxlen,"%lu",rows);
		return(str);
	}
	if(!strcmp(sp,"TERM"))
		return(terminal);

235
236
	if(!strcmp(sp,"CONN"))
		return(connection);
237

238
239
	if(!strcmp(sp,"SYSOP"))
		return(cfg.sys_op);
240

241
242
	if(!strcmp(sp,"LOCATION"))
		return(cfg.sys_location);
243

244
	if(!strcmp(sp,"NODE")) {
245
		safe_snprintf(str,maxlen,"%u",cfg.node_num);
246
247
		return(str);
	}
248

249
	if(!strcmp(sp,"TNODE")) {
250
		safe_snprintf(str,maxlen,"%u",cfg.sys_nodes);
251
252
		return(str);
	}
253

254
255
256
257
258
259
	if(strcmp(sp, "PAGER") == 0)
		return (thisnode.misc&NODE_POFF) ? text[Off] : text[On];

	if(strcmp(sp, "ALERTS") == 0)
		return (thisnode.misc&NODE_AOFF) ? text[Off] : text[On];

260
261
262
	if(strcmp(sp, "SPLITP") == 0)
		return (useron.chat&CHAT_SPLITP) ? text[On] : text[Off];

263
264
	if(!strcmp(sp,"INETADDR"))
		return(cfg.sys_inetaddr);
265

266
267
268
	if(!strcmp(sp,"HOSTNAME"))
		return(startup->host_name);

269
	if(!strcmp(sp,"FIDOADDR")) {
270
		if(cfg.total_faddrs)
271
			return(smb_faddrtoa(&cfg.faddr[0],str));
272
		return(nulstr);
273
274
	}

275
	if(!strcmp(sp,"EMAILADDR"))
276
		return(usermailaddr(&cfg, str
277
			,cfg.inetmail_misc&NMAIL_ALIAS ? useron.alias : useron.name));
278

279
280
	if(!strcmp(sp,"QWKID"))
		return(cfg.sys_id);
281

282
	if(!strcmp(sp,"TIME") || !strcmp(sp,"SYSTIME")) {
283
		now=time(NULL);
284
		memset(&tm,0,sizeof(tm));
285
		localtime_r(&now,&tm);
286
		if(cfg.sys_misc&SM_MILITARY)
287
288
			safe_snprintf(str,maxlen,"%02d:%02d:%02d"
		        	,tm.tm_hour,tm.tm_min,tm.tm_sec);
289
		else
290
			safe_snprintf(str,maxlen,"%02d:%02d %s"
291
292
293
				,tm.tm_hour==0 ? 12
				: tm.tm_hour>12 ? tm.tm_hour-12
				: tm.tm_hour, tm.tm_min, tm.tm_hour>11 ? "pm":"am");
294
		return(str);
295
296
	}

rswindell's avatar
rswindell committed
297
298
299
	if(!strcmp(sp,"TIMEZONE"))
		return(smb_zonestr(sys_timezone(&cfg),str));

300
	if(!strcmp(sp,"DATE") || !strcmp(sp,"SYSDATE")) {
301
		return(unixtodstr(&cfg,time32(NULL),str));
302
	}
303

rswindell's avatar
rswindell committed
304
305
306
	if(!strcmp(sp,"DATETIME"))
		return(timestr(time(NULL)));

rswindell's avatar
rswindell committed
307
308
309
310
311
312
	if(!strcmp(sp,"DATETIMEZONE")) {
		char zone[32];
		safe_snprintf(str, maxlen, "%s %s", timestr(time(NULL)), smb_zonestr(sys_timezone(&cfg),zone));
		return str;
	}

313
	if(!strcmp(sp,"TMSG")) {
314
315
		l=0;
		for(i=0;i<cfg.total_subs;i++)
316
			l+=getposts(&cfg,i); 		/* l=total posts */
317
		safe_snprintf(str,maxlen,"%lu",l);
318
319
		return(str);
	}
320

321
	if(!strcmp(sp,"TUSER")) {
322
		safe_snprintf(str,maxlen,"%u",total_users(&cfg));
323
324
		return(str);
	}
325

326
	if(!strcmp(sp,"TFILE")) {
327
328
		l=0;
		for(i=0;i<cfg.total_dirs;i++)
329
			l+=getfiles(&cfg,i);
330
		safe_snprintf(str,maxlen,"%lu",l);
331
332
		return(str);
	}
333

334
	if(!strcmp(sp,"TCALLS") || !strcmp(sp,"NUMCALLS")) {
335
		getstats(&cfg,0,&stats);
336
		safe_snprintf(str,maxlen,"%lu", (ulong)stats.logons);
337
338
		return(str);
	}
339

340
	if(!strcmp(sp,"PREVON") || !strcmp(sp,"LASTCALLERNODE")
341
		|| !strcmp(sp,"LASTCALLERSYSTEM"))
342
		return(lastuseron);
343

rswindell's avatar
rswindell committed
344
	if(!strcmp(sp,"CLS") || !strcmp(sp,"CLEAR")) {
345
		CLS;
346
347
		return(nulstr);
	}
348

349
	if(!strcmp(sp,"PAUSE") || !strcmp(sp,"MORE")) {
350
		pause();
351
352
		return(nulstr);
	}
353

354
	if(!strcmp(sp,"RESETPAUSE")) {
355
		lncntr=0;
356
357
		return(nulstr);
	}
358

359
	if(!strcmp(sp,"NOPAUSE") || !strcmp(sp,"POFF")) {
360
		sys_status^=SS_PAUSEOFF;
361
362
		return(nulstr);
	}
363

364
	if(!strcmp(sp,"PON") || !strcmp(sp,"AUTOMORE")) {
365
		sys_status^=SS_PAUSEON;
366
367
		return(nulstr);
	}
368

369
370
371
372
373
	if(strncmp(sp, "POS:", 4) == 0) {	// PCBoard	(nn is 1 based)
		i = atoi(sp + 4);
		if(i >= 1)	// Convert to 0-based
			i--;
		for(l = i - column; l > 0; l--)
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
			outchar(' ');
		return nulstr;
	}

	if(strncmp(sp, "DELAY:", 6) == 0) {	// PCBoard
		mswait(atoi(sp + 6) * 100);
		return nulstr;
	}

	if(strcmp(sp, "YESCHAR") == 0) {	// PCBoard
		safe_snprintf(str, maxlen, "%c", text[YNQP][0]);
		return str;
	}

	if(strcmp(sp, "NOCHAR") == 0) {		// PCBoard
		safe_snprintf(str, maxlen, "%c", text[YNQP][1]);
		return str;
	}

	if(strcmp(sp, "QUITCHAR") == 0) {
		safe_snprintf(str, maxlen, "%c", text[YNQP][2]);
		return str;
	}

398
399
400
401
	/* NOSTOP */

	/* STOP */

402
403
	if(!strcmp(sp,"BELL") || !strcmp(sp,"BEEP"))
		return("\a");
404

405
406
407
	if(!strcmp(sp,"EVENT")) {
		if(event_time==0)
			return("<none>");
408
		return(timestr(event_time));
409
	}
410
411
412

	/* LASTCALL */

413
	if(!strncmp(sp,"NODE",4)) {
414
415
416
		i=atoi(sp+4);
		if(i && i<=cfg.sys_nodes) {
			getnodedat(i,&node,0);
417
418
			printnodedat(i,&node);
		}
419
420
		return(nulstr);
	}
421

422
	if(!strcmp(sp,"WHO")) {
423
		whos_online(true);
424
425
		return(nulstr);
	}
426
427
428

	/* User Codes */

429
430
	if(!strcmp(sp,"USER") || !strcmp(sp,"ALIAS") || !strcmp(sp,"NAME"))
		return(useron.alias);
431

432
	if(!strcmp(sp,"FIRST")) {
433
		safe_snprintf(str,maxlen,"%s",useron.alias);
434
		tp=strchr(str,' ');
435
		if(tp) *tp=0;
436
		return(str);
437
	}
438

439
	if(!strcmp(sp,"USERNUM")) {
440
		safe_snprintf(str,maxlen,"%u",useron.number);
441
442
		return(str);
	}
443

444
	if(!strcmp(sp,"PHONE") || !strcmp(sp,"HOMEPHONE")
445
		|| !strcmp(sp,"DATAPHONE") || !strcmp(sp,"DATA"))
446
		return(useron.phone);
447

448
449
	if(!strcmp(sp,"ADDR1"))
		return(useron.address);
450

451
452
	if(!strcmp(sp,"FROM"))
		return(useron.location);
453

454
	if(!strcmp(sp,"CITY")) {
455
		safe_snprintf(str,maxlen,"%s",useron.location);
456
		char* p=strchr(str,',');
457
458
		if(p) {
			*p=0;
459
460
			return(str);
		}
461
462
		return(nulstr);
	}
463

464
465
	if(!strcmp(sp,"STATE")) {
		char* p=strchr(useron.location,',');
466
467
		if(p) {
			p++;
468
			if(*p==' ')
469
				p++;
470
471
			return(p);
		}
472
473
		return(nulstr);
	}
474

475
476
	if(!strcmp(sp,"CPU"))
		return(useron.comp);
477

478
479
	if(!strcmp(sp,"HOST"))
		return(client_name);
480

481
482
	if(!strcmp(sp,"BDATE"))
		return(useron.birth);
483

484
	if(!strcmp(sp,"AGE")) {
485
		safe_snprintf(str,maxlen,"%u",getage(&cfg,useron.birth));
486
487
		return(str);
	}
rswindell's avatar
rswindell committed
488

489
	if(!strcmp(sp,"CALLS") || !strcmp(sp,"NUMTIMESON")) {
490
		safe_snprintf(str,maxlen,"%u",useron.logons);
491
492
		return(str);
	}
493

494
495
	if(!strcmp(sp,"MEMO"))
		return(unixtodstr(&cfg,useron.pwmod,str));
496

497
	if(!strcmp(sp,"SEC") || !strcmp(sp,"SECURITY")) {
498
		safe_snprintf(str,maxlen,"%u",useron.level);
499
500
		return(str);
	}
501

502
503
	if(!strcmp(sp,"SINCE"))
		return(unixtodstr(&cfg,useron.firston,str));
504

505
	if(!strcmp(sp,"TIMEON") || !strcmp(sp,"TIMEUSED")) {
506
		now=time(NULL);
507
		safe_snprintf(str,maxlen,"%lu",(ulong)(now-logontime)/60L);
508
509
		return(str);
	}
510

511
	if(!strcmp(sp,"TUSED")) {              /* Synchronet only */
512
		now=time(NULL);
513
		return(sectostr((uint)(now-logontime),str)+1);
514
	}
515

516
	if(!strcmp(sp,"TLEFT")) {              /* Synchronet only */
517
		gettimeleft();
518
		return(sectostr(timeleft,str)+1);
519
	}
520

521
522
	if(!strcmp(sp,"TPERD"))                /* Synchronet only */
		return(sectostr(cfg.level_timeperday[useron.level],str)+1);
523

524
525
	if(!strcmp(sp,"TPERC"))                /* Synchronet only */
		return(sectostr(cfg.level_timepercall[useron.level],str)+1);
526

527
	if(!strcmp(sp,"TIMELIMIT")) {
528
		safe_snprintf(str,maxlen,"%u",cfg.level_timepercall[useron.level]);
529
530
		return(str);
	}
531

532
	if(!strcmp(sp,"MINLEFT") || !strcmp(sp,"LEFT") || !strcmp(sp,"TIMELEFT")) {
533
		gettimeleft();
534
		safe_snprintf(str,maxlen,"%lu",timeleft/60);
535
536
		return(str);
	}
537

538
	if(!strcmp(sp,"LASTON"))
539
		return(timestr(useron.laston));
540

541
542
	if(!strcmp(sp,"LASTDATEON"))
		return(unixtodstr(&cfg,useron.laston,str));
543

544
	if(!strcmp(sp,"LASTTIMEON")) {
545
		memset(&tm,0,sizeof(tm));
546
		localtime32(&useron.laston,&tm);
547
548
549
550
551
552
553
554
		if(cfg.sys_misc&SM_MILITARY)
			safe_snprintf(str,maxlen,"%02d:%02d:%02d"
				,tm.tm_hour, tm.tm_min, tm.tm_sec);
		else
			safe_snprintf(str,maxlen,"%02d:%02d %s"
				,tm.tm_hour==0 ? 12
				: tm.tm_hour>12 ? tm.tm_hour-12
				: tm.tm_hour, tm.tm_min, tm.tm_hour>11 ? "pm":"am");
555
		return(str);
556
557
	}

558
	if(!strcmp(sp,"MSGLEFT") || !strcmp(sp,"MSGSLEFT")) {
559
		safe_snprintf(str,maxlen,"%u",useron.posts);
560
561
		return(str);
	}
562

563
	if(!strcmp(sp,"MSGREAD")) {
564
		safe_snprintf(str,maxlen,"%lu",posts_read);
565
566
		return(str);
	}
567

568
	if(!strcmp(sp,"FREESPACE")) {
569
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,0));
570
571
572
573
		return(str);
	}

	if(!strcmp(sp,"FREESPACEK")) {
574
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,1024));
575
576
		return(str);
	}
577

578
	if(!strcmp(sp,"UPBYTES")) {
579
		safe_snprintf(str,maxlen,"%lu",useron.ulb);
580
581
		return(str);
	}
582

583
	if(!strcmp(sp,"UPK")) {
584
		safe_snprintf(str,maxlen,"%lu",useron.ulb/1024L);
585
586
		return(str);
	}
587

588
	if(!strcmp(sp,"UPS") || !strcmp(sp,"UPFILES")) {
589
		safe_snprintf(str,maxlen,"%u",useron.uls);
590
591
		return(str);
	}
592

593
	if(!strcmp(sp,"DLBYTES")) {
594
		safe_snprintf(str,maxlen,"%lu",useron.dlb);
595
596
		return(str);
	}
597

598
	if(!strcmp(sp,"DOWNK")) {
599
		safe_snprintf(str,maxlen,"%lu",useron.dlb/1024L);
600
601
		return(str);
	}
602

603
	if(!strcmp(sp,"DOWNS") || !strcmp(sp,"DLFILES")) {
604
		safe_snprintf(str,maxlen,"%u",useron.dls);
605
606
		return(str);
	}
607

608
	if(!strcmp(sp,"LASTNEW"))
609
		return(unixtodstr(&cfg,(time32_t)ns_time,str));
610

611
	if(!strcmp(sp,"NEWFILETIME"))
612
		return(timestr(ns_time));
613
614
615

	/* MAXDL */

616
	if(!strcmp(sp,"MAXDK") || !strcmp(sp,"DLKLIMIT") || !strcmp(sp,"KBLIMIT")) {
617
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]/1024L);
618
619
		return(str);
	}
620

621
	if(!strcmp(sp,"DAYBYTES")) {    /* amt of free cdts used today */
622
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]-useron.freecdt);
623
624
		return(str);
	}
625

626
	if(!strcmp(sp,"BYTELIMIT")) {
627
		safe_snprintf(str,maxlen,"%ld", (long)cfg.level_freecdtperday[useron.level]);
628
629
		return(str);
	}
630

631
	if(!strcmp(sp,"KBLEFT")) {
632
		safe_snprintf(str,maxlen,"%lu",(useron.cdt+useron.freecdt)/1024L);
633
634
		return(str);
	}
635

636
	if(!strcmp(sp,"BYTESLEFT")) {
637
		safe_snprintf(str,maxlen,"%lu",useron.cdt+useron.freecdt);
638
639
		return(str);
	}
640

641
	if(!strcmp(sp,"CONF")) {
642
		safe_snprintf(str,maxlen,"%s %s"
643
644
			,usrgrps ? cfg.grp[usrgrp[curgrp]]->sname :nulstr
			,usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr);
645
646
		return(str);
	}
647

648
	if(!strcmp(sp,"CONFNUM")) {
649
		safe_snprintf(str,maxlen,"%u %u",curgrp+1,cursub[curgrp]+1);
650
651
		return(str);
	}
652

653
	if(!strcmp(sp,"NUMDIR")) {
654
		safe_snprintf(str,maxlen,"%u %u",usrlibs ? curlib+1 : 0,usrlibs ? curdir[curlib]+1 : 0);
655
656
		return(str);
	}
657

658
659
	if(!strcmp(sp,"EXDATE") || !strcmp(sp,"EXPDATE"))
		return(unixtodstr(&cfg,useron.expire,str));
660

661
	if(!strcmp(sp,"EXPDAYS")) {
662
		now=time(NULL);
663
		l=(long)(useron.expire-now);
664
665
		if(l<0)
			l=0;
666
		safe_snprintf(str,maxlen,"%lu",l/(1440L*60L));
667
668
		return(str);
	}
669

670
671
	if(!strcmp(sp,"MEMO1"))
		return(useron.note);
672

673
674
	if(!strcmp(sp,"MEMO2") || !strcmp(sp,"COMPANY"))
		return(useron.name);
675

676
677
	if(!strcmp(sp,"ZIP"))
		return(useron.zipcode);
678

679
	if(!strcmp(sp,"HANGUP")) {
680
		hangup();
681
682
		return(nulstr);
	}
683
684
685

	/* Synchronet Specific */

686
	if(!strncmp(sp,"SETSTR:",7)) {
687
		strcpy(main_csi.str,sp+7);
688
689
		return(nulstr);
	}
690

691
	if(!strncmp(sp,"EXEC:",5)) {
692
		exec_bin(sp+5,&main_csi);
693
694
		return(nulstr);
	}
695

696
	if(!strncmp(sp,"EXEC_XTRN:",10)) {
697
		for(i=0;i<cfg.total_xtrns;i++)
698
			if(!stricmp(cfg.xtrn[i]->code,sp+10))
699
700
701
702
703
704
				break;
		if(i<cfg.total_xtrns)
			exec_xtrn(i);
		return(nulstr);
	}

705
	if(!strncmp(sp,"MENU:",5)) {
706
		menu(sp+5);
707
708
		return(nulstr);
	}
709

710
711
712
713
714
	if(!strncmp(sp,"CONDMENU:",9)) {
		menu(sp+9, P_NOERROR);
		return(nulstr);
	}

715
716
717
718
	if(!strncmp(sp,"TYPE:",5)) {
		printfile(cmdstr(sp+5,nulstr,nulstr,str),0);
		return(nulstr);
	}
719

720
	if(!strncmp(sp,"INCLUDE:",8)) {
721
		printfile(cmdstr(sp+8,nulstr,nulstr,str),P_NOCRLF|P_SAVEATR);
722
723
724
		return(nulstr);
	}

725
726
	if(!strcmp(sp,"QUESTION"))
		return(question);
727

728
729
	if(!strcmp(sp,"HANDLE"))
		return(useron.handle);
730

731
732
	if(!strcmp(sp,"CID") || !strcmp(sp,"IP"))
		return(cid);
733

deuce's avatar
deuce committed
734
735
	if(!strcmp(sp,"LOCAL-IP"))
		return(local_addr);
736

737
738
	if(!strcmp(sp,"CRLF"))
		return("\r\n");
739

740
	if(!strcmp(sp,"PUSHXY")) {
741
		ansi_save();
742
743
		return(nulstr);
	}
744

745
	if(!strcmp(sp,"POPXY")) {
746
		ansi_restore();
747
748
		return(nulstr);
	}
749

rswindell's avatar
rswindell committed
750
751
752
753
754
755
756
757
758
759
	if(!strcmp(sp,"HOME")) {
		cursor_home();
		return(nulstr);
	}

	if(!strcmp(sp,"CLRLINE")) {
		clearline();
		return(nulstr);
	}

760
	if(!strcmp(sp,"CLR2EOL") || !strcmp(sp,"CLREOL")) {
rswindell's avatar
rswindell committed
761
762
763
764
765
766
767
768
769
		cleartoeol();
		return(nulstr);
	}

	if(!strcmp(sp,"CLR2EOS")) {
		cleartoeos();
		return(nulstr);
	}

770
	if(!strncmp(sp,"UP:",3)) {
771
		cursor_up(atoi(sp+3));
772
773
		return(str);
	}
774

775
	if(!strncmp(sp,"DOWN:",5)) {
776
		cursor_down(atoi(sp+5));
777
778
		return(str);
	}
779

780
	if(!strncmp(sp,"LEFT:",5)) {
781
		cursor_left(atoi(sp+5));
782
783
		return(str);
	}
784

785
	if(!strncmp(sp,"RIGHT:",6)) {
786
		cursor_right(atoi(sp+6));
787
788
		return(str);
	}
789

790
	if(!strncmp(sp,"GOTOXY:",7)) {
791
792
793
		tp=strchr(sp,',');
		if(tp!=NULL) {
			tp++;
794
			ansi_gotoxy(atoi(sp+7),atoi(tp));
795
		}
796
		return(nulstr);