atcodes.cpp 35.3 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
 *																			*
 * 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"
39
40
#include "utf8.h"
#include "unicode.h"
41
#include "cp437defs.h"
42

43
44
45
46
47
48
49
#if defined(_WINSOCKAPI_)
	extern WSADATA WSAData;
	#define SOCKLIB_DESC WSAData.szDescription
#else
	#define	SOCKLIB_DESC NULL
#endif

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

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

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

94
95
	cp=atcode(sp,str2,sizeof(str2));
	if(cp==NULL)
96
97
		return(0);

rswindell's avatar
rswindell committed
98
99
100
101
102
103
104
105
106
107
108
	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;
		}
	}
109
	if(padded_left)
110
		bprintf("%-*.*s",disp_len,disp_len,cp);
111
	else if(padded_right)
112
		bprintf("%*.*s",disp_len,disp_len,cp);
113
	else if(centered) {
rswindell's avatar
rswindell committed
114
		int vlen = strlen(cp);
115
116
117
118
		if(vlen < disp_len) {
			int left = (disp_len - vlen) / 2;
			bprintf("%*s%-*s", left, "", disp_len - left, cp);
		} else
119
			bprintf("%.*s", disp_len, cp);
120
	} else if(zero_padded) {
121
122
		int vlen = strlen(cp);
		if(vlen < disp_len)
123
			bprintf("%-.*s%s", (int)(disp_len - strlen(cp)), "0000000000", cp);
124
125
		else
			bprintf("%.*s", disp_len, cp);
126
	} else
rswindell's avatar
rswindell committed
127
		bprintf("%.*s", disp_len, cp);
128
129
130
131

	return(len);
}

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

	str[0]=0;

145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
	if(strncmp(sp, "U+", 2) == 0) {	// UNICODE
		enum unicode_codepoint codepoint = (enum unicode_codepoint)strtoul(sp + 2, &tp, 16);
		if(tp == NULL || *tp ==0)
			outchar(codepoint, unicode_to_cp437(codepoint));
		else {
			char fallback = (char)strtoul(tp + 1, NULL, 16);
			if(*tp == '|')
				outchar(codepoint, fallback);
			else if(*tp == '!') {
				char ch = unicode_to_cp437(codepoint);
				if(ch != 0)
					fallback = ch;
				outchar(codepoint, fallback);
			}
			else return NULL; // Invalid @-code
		}
		return nulstr;
	}

164
165
166
167
168
	if(strcmp(sp, "CHECKMARK") == 0) {
		outchar(UNICODE_CHECK_MARK, CP437_CHECK_MARK);
		return nulstr;
	}

169
	if(!strcmp(sp,"VER"))
170
		return(VERSION);
171

172
	if(!strcmp(sp,"REV")) {
173
		safe_snprintf(str,maxlen,"%c",REVISION);
174
175
		return(str);
	}
176

177
	if(!strcmp(sp,"FULL_VER")) {
178
		safe_snprintf(str,maxlen,"%s%c%s",VERSION,REVISION,beta_version);
179
		truncsp(str);
180
#if defined(_DEBUG)
181
		strcat(str," Debug");
182
#endif
183
		return(str);
184
185
	}

186
	if(!strcmp(sp,"VER_NOTICE"))
187
		return(VERSION_NOTICE);
188

189
190
	if(!strcmp(sp,"OS_VER"))
		return(os_version(str));
191
192

#ifdef JAVASCRIPT
193
194
	if(!strcmp(sp,"JS_VER"))
		return((char *)JS_GetImplementationVersion());
195
196
#endif

197
198
	if(!strcmp(sp,"PLATFORM"))
		return(PLATFORM_DESC);
199

200
201
	if(!strcmp(sp,"COPYRIGHT"))
		return(COPYRIGHT_NOTICE);
202

203
	if(!strcmp(sp,"COMPILER")) {
204
205
206
		char compiler[32];
		DESCRIBE_COMPILER(compiler);
		strncpy(str, compiler, maxlen);
207
		return(str);
208
209
	}

210
	if(!strcmp(sp,"UPTIME")) {
211
		extern volatile time_t uptime;
212
213
214
215
		time_t up=0;
		now = time(NULL);
		if (uptime != 0 && now >= uptime)
			up = now-uptime;
216
217
		char   days[64]="";
		if((up/(24*60*60))>=2) {
218
	        sprintf(days,"%lu days ",(ulong)(up/(24L*60L*60L)));
219
220
			up%=(24*60*60);
		}
221
		safe_snprintf(str,maxlen,"%s%lu:%02lu"
222
	        ,days
223
224
			,(ulong)(up/(60L*60L))
			,(ulong)((up/60L)%60L)
225
			);
226
		return(str);
227
228
	}

229
	if(!strcmp(sp,"SERVED")) {
230
		extern volatile ulong served;
231
		safe_snprintf(str,maxlen,"%lu",served);
232
233
234
		return(str);
	}

235
	if(!strcmp(sp,"SOCKET_LIB"))
236
		return(socklib_version(str,SOCKLIB_DESC));
237

238
	if(!strcmp(sp,"MSG_LIB")) {
239
		safe_snprintf(str,maxlen,"SMBLIB %s",smb_lib_ver());
240
241
		return(str);
	}
242

243
244
	if(!strcmp(sp,"BBS") || !strcmp(sp,"BOARDNAME"))
		return(cfg.sys_name);
245

246
	if(!strcmp(sp,"BAUD") || !strcmp(sp,"BPS")) {
247
		safe_snprintf(str,maxlen,"%lu",cur_rate);
248
249
		return(str);
	}
250

rswindell's avatar
rswindell committed
251
252
253
254
255
256
257
258
259
260
261
	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);

262
263
	if(!strcmp(sp,"CONN"))
		return(connection);
264

265
266
	if(!strcmp(sp,"SYSOP"))
		return(cfg.sys_op);
267

268
269
	if(!strcmp(sp,"LOCATION"))
		return(cfg.sys_location);
270

271
	if(!strcmp(sp,"NODE")) {
272
		safe_snprintf(str,maxlen,"%u",cfg.node_num);
273
274
		return(str);
	}
275

276
	if(!strcmp(sp,"TNODE")) {
277
		safe_snprintf(str,maxlen,"%u",cfg.sys_nodes);
278
279
		return(str);
	}
280

281
282
283
284
285
286
	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];

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

290
291
	if(!strcmp(sp,"INETADDR"))
		return(cfg.sys_inetaddr);
292

293
294
295
	if(!strcmp(sp,"HOSTNAME"))
		return(startup->host_name);

296
	if(!strcmp(sp,"FIDOADDR")) {
297
		if(cfg.total_faddrs)
298
			return(smb_faddrtoa(&cfg.faddr[0],str));
299
		return(nulstr);
300
301
	}

302
	if(!strcmp(sp,"EMAILADDR"))
303
		return(usermailaddr(&cfg, str
304
			,cfg.inetmail_misc&NMAIL_ALIAS ? useron.alias : useron.name));
305

306
307
	if(!strcmp(sp,"QWKID"))
		return(cfg.sys_id);
308

309
	if(!strcmp(sp,"TIME") || !strcmp(sp,"SYSTIME")) {
310
		now=time(NULL);
311
		memset(&tm,0,sizeof(tm));
312
		localtime_r(&now,&tm);
313
		if(cfg.sys_misc&SM_MILITARY)
314
315
			safe_snprintf(str,maxlen,"%02d:%02d:%02d"
		        	,tm.tm_hour,tm.tm_min,tm.tm_sec);
316
		else
317
			safe_snprintf(str,maxlen,"%02d:%02d %s"
318
319
320
				,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");
321
		return(str);
322
323
	}

rswindell's avatar
rswindell committed
324
325
326
	if(!strcmp(sp,"TIMEZONE"))
		return(smb_zonestr(sys_timezone(&cfg),str));

327
	if(!strcmp(sp,"DATE") || !strcmp(sp,"SYSDATE")) {
328
		return(unixtodstr(&cfg,time32(NULL),str));
329
	}
330

rswindell's avatar
rswindell committed
331
332
333
	if(!strcmp(sp,"DATETIME"))
		return(timestr(time(NULL)));

rswindell's avatar
rswindell committed
334
335
336
337
338
	if(!strcmp(sp,"DATETIMEZONE")) {
		char zone[32];
		safe_snprintf(str, maxlen, "%s %s", timestr(time(NULL)), smb_zonestr(sys_timezone(&cfg),zone));
		return str;
	}
339
340
341
342
	
	if(strcmp(sp, "DATEFMT") == 0) {
		return cfg.sys_misc&SM_EURODATE ? "DD/MM/YY" : "MM/DD/YY";
	}
rswindell's avatar
rswindell committed
343

344
	if(!strcmp(sp,"TMSG")) {
345
346
		l=0;
		for(i=0;i<cfg.total_subs;i++)
347
			l+=getposts(&cfg,i); 		/* l=total posts */
348
		safe_snprintf(str,maxlen,"%lu",l);
349
350
		return(str);
	}
351

352
	if(!strcmp(sp,"TUSER")) {
353
		safe_snprintf(str,maxlen,"%u",total_users(&cfg));
354
355
		return(str);
	}
356

357
	if(!strcmp(sp,"TFILE")) {
358
359
		l=0;
		for(i=0;i<cfg.total_dirs;i++)
360
			l+=getfiles(&cfg,i);
361
		safe_snprintf(str,maxlen,"%lu",l);
362
363
		return(str);
	}
364

365
	if(!strcmp(sp,"TCALLS") || !strcmp(sp,"NUMCALLS")) {
366
		getstats(&cfg,0,&stats);
367
		safe_snprintf(str,maxlen,"%lu", (ulong)stats.logons);
368
369
		return(str);
	}
370

371
	if(!strcmp(sp,"PREVON") || !strcmp(sp,"LASTCALLERNODE")
372
		|| !strcmp(sp,"LASTCALLERSYSTEM"))
373
		return(lastuseron);
374

rswindell's avatar
rswindell committed
375
	if(!strcmp(sp,"CLS") || !strcmp(sp,"CLEAR")) {
376
		CLS;
377
378
		return(nulstr);
	}
379

380
	if(!strcmp(sp,"PAUSE") || !strcmp(sp,"MORE")) {
381
		pause();
382
383
		return(nulstr);
	}
384

385
	if(!strcmp(sp,"RESETPAUSE")) {
386
		lncntr=0;
387
388
		return(nulstr);
	}
389

390
	if(!strcmp(sp,"NOPAUSE") || !strcmp(sp,"POFF")) {
391
		sys_status^=SS_PAUSEOFF;
392
393
		return(nulstr);
	}
394

395
	if(!strcmp(sp,"PON") || !strcmp(sp,"AUTOMORE")) {
396
		sys_status^=SS_PAUSEON;
397
398
		return(nulstr);
	}
399

400
401
402
403
404
	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--)
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
			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;
	}

429
430
431
432
	/* NOSTOP */

	/* STOP */

433
434
	if(!strcmp(sp,"BELL") || !strcmp(sp,"BEEP"))
		return("\a");
435

436
437
438
	if(!strcmp(sp,"EVENT")) {
		if(event_time==0)
			return("<none>");
439
		return(timestr(event_time));
440
	}
441
442
443

	/* LASTCALL */

444
	if(!strncmp(sp,"NODE",4)) {
445
446
447
		i=atoi(sp+4);
		if(i && i<=cfg.sys_nodes) {
			getnodedat(i,&node,0);
448
449
			printnodedat(i,&node);
		}
450
451
		return(nulstr);
	}
452

453
	if(!strcmp(sp,"WHO")) {
454
		whos_online(true);
455
456
		return(nulstr);
	}
457
458
459

	/* User Codes */

460
461
	if(!strcmp(sp,"USER") || !strcmp(sp,"ALIAS") || !strcmp(sp,"NAME"))
		return(useron.alias);
462

463
	if(!strcmp(sp,"FIRST")) {
464
		safe_snprintf(str,maxlen,"%s",useron.alias);
465
		tp=strchr(str,' ');
466
		if(tp) *tp=0;
467
		return(str);
468
	}
469

470
	if(!strcmp(sp,"USERNUM")) {
471
		safe_snprintf(str,maxlen,"%u",useron.number);
472
473
		return(str);
	}
474

475
	if(!strcmp(sp,"PHONE") || !strcmp(sp,"HOMEPHONE")
476
		|| !strcmp(sp,"DATAPHONE") || !strcmp(sp,"DATA"))
477
		return(useron.phone);
478

479
480
	if(!strcmp(sp,"ADDR1"))
		return(useron.address);
481

482
483
	if(!strcmp(sp,"FROM"))
		return(useron.location);
484

485
	if(!strcmp(sp,"CITY")) {
486
		safe_snprintf(str,maxlen,"%s",useron.location);
487
		char* p=strchr(str,',');
488
489
		if(p) {
			*p=0;
490
491
			return(str);
		}
492
493
		return(nulstr);
	}
494

495
496
	if(!strcmp(sp,"STATE")) {
		char* p=strchr(useron.location,',');
497
498
		if(p) {
			p++;
499
			if(*p==' ')
500
				p++;
501
502
			return(p);
		}
503
504
		return(nulstr);
	}
505

506
507
	if(!strcmp(sp,"CPU"))
		return(useron.comp);
508

509
510
	if(!strcmp(sp,"HOST"))
		return(client_name);
511

512
513
	if(!strcmp(sp,"BDATE"))
		return(useron.birth);
514

515
	if(!strcmp(sp,"AGE")) {
516
		safe_snprintf(str,maxlen,"%u",getage(&cfg,useron.birth));
517
518
		return(str);
	}
rswindell's avatar
rswindell committed
519

520
	if(!strcmp(sp,"CALLS") || !strcmp(sp,"NUMTIMESON")) {
521
		safe_snprintf(str,maxlen,"%u",useron.logons);
522
523
		return(str);
	}
524

525
526
	if(!strcmp(sp,"MEMO"))
		return(unixtodstr(&cfg,useron.pwmod,str));
527

528
	if(!strcmp(sp,"SEC") || !strcmp(sp,"SECURITY")) {
529
		safe_snprintf(str,maxlen,"%u",useron.level);
530
531
		return(str);
	}
532

533
534
	if(!strcmp(sp,"SINCE"))
		return(unixtodstr(&cfg,useron.firston,str));
535

536
	if(!strcmp(sp,"TIMEON") || !strcmp(sp,"TIMEUSED")) {
537
		now=time(NULL);
538
		safe_snprintf(str,maxlen,"%lu",(ulong)(now-logontime)/60L);
539
540
		return(str);
	}
541

542
	if(!strcmp(sp,"TUSED")) {              /* Synchronet only */
543
		now=time(NULL);
544
		return(sectostr((uint)(now-logontime),str)+1);
545
	}
546

547
	if(!strcmp(sp,"TLEFT")) {              /* Synchronet only */
548
		gettimeleft();
549
		return(sectostr(timeleft,str)+1);
550
	}
551

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

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

558
	if(!strcmp(sp,"TIMELIMIT")) {
559
		safe_snprintf(str,maxlen,"%u",cfg.level_timepercall[useron.level]);
560
561
		return(str);
	}
562

563
	if(!strcmp(sp,"MINLEFT") || !strcmp(sp,"LEFT") || !strcmp(sp,"TIMELEFT")) {
564
		gettimeleft();
565
		safe_snprintf(str,maxlen,"%lu",timeleft/60);
566
567
		return(str);
	}
568

569
	if(!strcmp(sp,"LASTON"))
570
		return(timestr(useron.laston));
571

572
573
	if(!strcmp(sp,"LASTDATEON"))
		return(unixtodstr(&cfg,useron.laston,str));
574

575
	if(!strcmp(sp,"LASTTIMEON")) {
576
		memset(&tm,0,sizeof(tm));
577
		localtime32(&useron.laston,&tm);
578
579
580
581
582
583
584
585
		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");
586
		return(str);
587
588
	}

589
	if(!strcmp(sp,"MSGLEFT") || !strcmp(sp,"MSGSLEFT")) {
590
		safe_snprintf(str,maxlen,"%u",useron.posts);
591
592
		return(str);
	}
593

594
	if(!strcmp(sp,"MSGREAD")) {
595
		safe_snprintf(str,maxlen,"%lu",posts_read);
596
597
		return(str);
	}
598

599
	if(!strcmp(sp,"FREESPACE")) {
600
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,0));
601
602
603
604
		return(str);
	}

	if(!strcmp(sp,"FREESPACEK")) {
605
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,1024));
606
607
		return(str);
	}
608

609
	if(!strcmp(sp,"UPBYTES")) {
610
		safe_snprintf(str,maxlen,"%lu",useron.ulb);
611
612
		return(str);
	}
613

614
	if(!strcmp(sp,"UPK")) {
615
		safe_snprintf(str,maxlen,"%lu",useron.ulb/1024L);
616
617
		return(str);
	}
618

619
	if(!strcmp(sp,"UPS") || !strcmp(sp,"UPFILES")) {
620
		safe_snprintf(str,maxlen,"%u",useron.uls);
621
622
		return(str);
	}
623

624
	if(!strcmp(sp,"DLBYTES")) {
625
		safe_snprintf(str,maxlen,"%lu",useron.dlb);
626
627
		return(str);
	}
628

629
	if(!strcmp(sp,"DOWNK")) {
630
		safe_snprintf(str,maxlen,"%lu",useron.dlb/1024L);
631
632
		return(str);
	}
633

634
	if(!strcmp(sp,"DOWNS") || !strcmp(sp,"DLFILES")) {
635
		safe_snprintf(str,maxlen,"%u",useron.dls);
636
637
		return(str);
	}
638

639
	if(!strcmp(sp,"LASTNEW"))
640
		return(unixtodstr(&cfg,(time32_t)ns_time,str));
641

642
	if(!strcmp(sp,"NEWFILETIME"))
643
		return(timestr(ns_time));
644
645
646

	/* MAXDL */

647
	if(!strcmp(sp,"MAXDK") || !strcmp(sp,"DLKLIMIT") || !strcmp(sp,"KBLIMIT")) {
648
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]/1024L);
649
650
		return(str);
	}
651

652
	if(!strcmp(sp,"DAYBYTES")) {    /* amt of free cdts used today */
653
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]-useron.freecdt);
654
655
		return(str);
	}
656

657
	if(!strcmp(sp,"BYTELIMIT")) {
658
		safe_snprintf(str,maxlen,"%ld", (long)cfg.level_freecdtperday[useron.level]);
659
660
		return(str);
	}
661

662
	if(!strcmp(sp,"KBLEFT")) {
663
		safe_snprintf(str,maxlen,"%lu",(useron.cdt+useron.freecdt)/1024L);
664
665
		return(str);
	}
666

667
	if(!strcmp(sp,"BYTESLEFT")) {
668
		safe_snprintf(str,maxlen,"%lu",useron.cdt+useron.freecdt);
669
670
		return(str);
	}
671

672
	if(!strcmp(sp,"CONF")) {
673
		safe_snprintf(str,maxlen,"%s %s"
674
675
			,usrgrps ? cfg.grp[usrgrp[curgrp]]->sname :nulstr
			,usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr);
676
677
		return(str);
	}
678

679
	if(!strcmp(sp,"CONFNUM")) {
680
		safe_snprintf(str,maxlen,"%u %u",curgrp+1,cursub[curgrp]+1);
681
682
		return(str);
	}
683

684
	if(!strcmp(sp,"NUMDIR")) {
685
		safe_snprintf(str,maxlen,"%u %u",usrlibs ? curlib+1 : 0,usrlibs ? curdir[curlib]+1 : 0);
686
687
		return(str);
	}
688

689
690
	if(!strcmp(sp,"EXDATE") || !strcmp(sp,"EXPDATE"))
		return(unixtodstr(&cfg,useron.expire,str));
691

692
	if(!strcmp(sp,"EXPDAYS")) {
693
		now=time(NULL);
694
		l=(long)(useron.expire-now);
695
696
		if(l<0)
			l=0;
697
		safe_snprintf(str,maxlen,"%lu",l/(1440L*60L));
698
699
		return(str);
	}
700

701
702
	if(!strcmp(sp,"MEMO1"))
		return(useron.note);
703

704
705
	if(!strcmp(sp,"MEMO2") || !strcmp(sp,"COMPANY"))
		return(useron.name);
706

707
708
	if(!strcmp(sp,"ZIP"))
		return(useron.zipcode);
709

710
	if(!strcmp(sp,"HANGUP")) {
711
		hangup();
712
713
		return(nulstr);
	}
714
715
716

	/* Synchronet Specific */

717
	if(!strncmp(sp,"SETSTR:",7)) {
718
		strcpy(main_csi.str,sp+7);
719
720
		return(nulstr);
	}
721

722
	if(!strncmp(sp,"EXEC:",5)) {
723
		exec_bin(sp+5,&main_csi);
724
725
		return(nulstr);
	}
726

727
	if(!strncmp(sp,"EXEC_XTRN:",10)) {
728
		for(i=0;i<cfg.total_xtrns;i++)
729
			if(!stricmp(cfg.xtrn[i]->code,sp+10))
730
731
732
733
734
735
				break;
		if(i<cfg.total_xtrns)
			exec_xtrn(i);
		return(nulstr);
	}

736
	if(!strncmp(sp,"MENU:",5)) {
737
		menu(sp+5);
738
739
		return(nulstr);
	}
740

741
742
743
744
745
	if(!strncmp(sp,"CONDMENU:",9)) {
		menu(sp+9, P_NOERROR);
		return(nulstr);
	}

746
747
748
749
	if(!strncmp(sp,"TYPE:",5)) {
		printfile(cmdstr(sp+5,nulstr,nulstr,str),0);
		return(nulstr);
	}
750

751
	if(!strncmp(sp,"INCLUDE:",8)) {
752
		printfile(cmdstr(sp+8,nulstr,nulstr,str),P_NOCRLF|P_SAVEATR);
753
754
755
		return(nulstr);
	}

756
757
	if(!strcmp(sp,"QUESTION"))
		return(question);
758

759
760
	if(!strcmp(sp,"HANDLE"))
		return(useron.handle);
761

762
763
	if(!strcmp(sp,"CID") || !strcmp(sp,"IP"))
		return(cid);
764

deuce's avatar
deuce committed
765
766
	if(!strcmp(sp,"LOCAL-IP"))
		return(local_addr);
767

768
769
	if(!strcmp(sp,"CRLF"))
		return("\r\n");
770

771
	if(!strcmp(sp,"PUSHXY")) {
772
		ansi_save();
773
774
		return(nulstr);
	}
775

776
	if(!strcmp(sp,"POPXY")) {
777
		ansi_restore();
778
779
		return(nulstr);
	}
780

rswindell's avatar
rswindell committed
781
782
783
784
785
786
787
788
789
790
	if(!strcmp(sp,"HOME")) {
		cursor_home();
		return(nulstr);
	}

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

791
	if(!strcmp(sp,"CLR2EOL") || !strcmp(sp,"CLREOL")) {
rswindell's avatar
rswindell committed
792
793
794
795
796
797
798
799
800
		cleartoeol();
		return(nulstr);
	}

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

801
	if(!strncmp(sp,"UP:",3)) {
802
		cursor_up(atoi(sp+3));
803
804
		return(str);
	}
805

806
	if(!strncmp(sp,"DOWN:",5)) {
807
		cursor_down(atoi(sp+5));
808
809
		return(str);
	}
810

811
	if