atcodes.cpp 35.5 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;
rswindell's avatar
rswindell committed
63
	bool	doubled = false;
64
	const char *cp;
65

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

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

97
98
	cp=atcode(sp,str2,sizeof(str2));
	if(cp==NULL)
99
100
		return(0);

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

	return(len);
}

137
const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen)
138
{
139
	char*	tp = NULL;
140
	uint	i;
141
142
	uint	ugrp;
	uint	usub;
143
144
145
146
147
148
149
	long	l;
    stats_t stats;
    node_t  node;
	struct	tm tm;

	str[0]=0;

150
151
152
153
154
155
	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);
156
			if(*tp == '/')
157
158
159
160
161
162
163
164
165
166
167
168
				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;
	}

169
170
171
172
173
	if(strcmp(sp, "CHECKMARK") == 0) {
		outchar(UNICODE_CHECK_MARK, CP437_CHECK_MARK);
		return nulstr;
	}

rswindell's avatar
rswindell committed
174
175
176
177
178
	if(strncmp(sp, "WIDE:", 5) == 0) {
		wide(sp + 5);
		return(nulstr);
	}

179
	if(!strcmp(sp,"VER"))
180
		return(VERSION);
181

182
	if(!strcmp(sp,"REV")) {
183
		safe_snprintf(str,maxlen,"%c",REVISION);
184
185
		return(str);
	}
186

187
	if(!strcmp(sp,"FULL_VER")) {
188
		safe_snprintf(str,maxlen,"%s%c%s",VERSION,REVISION,beta_version);
189
		truncsp(str);
190
#if defined(_DEBUG)
191
		strcat(str," Debug");
192
#endif
193
		return(str);
194
195
	}

196
	if(!strcmp(sp,"VER_NOTICE"))
197
		return(VERSION_NOTICE);
198

199
200
	if(!strcmp(sp,"OS_VER"))
		return(os_version(str));
201
202

#ifdef JAVASCRIPT
203
204
	if(!strcmp(sp,"JS_VER"))
		return((char *)JS_GetImplementationVersion());
205
206
#endif

207
208
	if(!strcmp(sp,"PLATFORM"))
		return(PLATFORM_DESC);
209

210
211
	if(!strcmp(sp,"COPYRIGHT"))
		return(COPYRIGHT_NOTICE);
212

213
	if(!strcmp(sp,"COMPILER")) {
214
215
216
		char compiler[32];
		DESCRIBE_COMPILER(compiler);
		strncpy(str, compiler, maxlen);
217
		return(str);
218
219
	}

220
	if(!strcmp(sp,"UPTIME")) {
221
		extern volatile time_t uptime;
222
223
224
225
		time_t up=0;
		now = time(NULL);
		if (uptime != 0 && now >= uptime)
			up = now-uptime;
226
227
		char   days[64]="";
		if((up/(24*60*60))>=2) {
228
	        sprintf(days,"%lu days ",(ulong)(up/(24L*60L*60L)));
229
230
			up%=(24*60*60);
		}
231
		safe_snprintf(str,maxlen,"%s%lu:%02lu"
232
	        ,days
233
234
			,(ulong)(up/(60L*60L))
			,(ulong)((up/60L)%60L)
235
			);
236
		return(str);
237
238
	}

239
	if(!strcmp(sp,"SERVED")) {
240
		extern volatile ulong served;
241
		safe_snprintf(str,maxlen,"%lu",served);
242
243
244
		return(str);
	}

245
	if(!strcmp(sp,"SOCKET_LIB"))
246
		return(socklib_version(str,SOCKLIB_DESC));
247

248
	if(!strcmp(sp,"MSG_LIB")) {
249
		safe_snprintf(str,maxlen,"SMBLIB %s",smb_lib_ver());
250
251
		return(str);
	}
252

253
254
	if(!strcmp(sp,"BBS") || !strcmp(sp,"BOARDNAME"))
		return(cfg.sys_name);
255

256
	if(!strcmp(sp,"BAUD") || !strcmp(sp,"BPS")) {
257
		safe_snprintf(str,maxlen,"%lu",cur_rate);
258
259
		return(str);
	}
260

rswindell's avatar
rswindell committed
261
262
263
264
265
266
267
268
269
270
271
	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);

272
273
	if(!strcmp(sp,"CONN"))
		return(connection);
274

275
276
	if(!strcmp(sp,"SYSOP"))
		return(cfg.sys_op);
277

278
279
	if(!strcmp(sp,"LOCATION"))
		return(cfg.sys_location);
280

281
	if(!strcmp(sp,"NODE")) {
282
		safe_snprintf(str,maxlen,"%u",cfg.node_num);
283
284
		return(str);
	}
285

286
	if(!strcmp(sp,"TNODE")) {
287
		safe_snprintf(str,maxlen,"%u",cfg.sys_nodes);
288
289
		return(str);
	}
290

291
292
293
294
295
296
	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];

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

300
301
	if(!strcmp(sp,"INETADDR"))
		return(cfg.sys_inetaddr);
302

303
304
305
	if(!strcmp(sp,"HOSTNAME"))
		return(startup->host_name);

306
	if(!strcmp(sp,"FIDOADDR")) {
307
		if(cfg.total_faddrs)
308
			return(smb_faddrtoa(&cfg.faddr[0],str));
309
		return(nulstr);
310
311
	}

312
	if(!strcmp(sp,"EMAILADDR"))
313
		return(usermailaddr(&cfg, str
314
			,cfg.inetmail_misc&NMAIL_ALIAS ? useron.alias : useron.name));
315

316
317
	if(!strcmp(sp,"QWKID"))
		return(cfg.sys_id);
318

319
	if(!strcmp(sp,"TIME") || !strcmp(sp,"SYSTIME")) {
320
		now=time(NULL);
321
		memset(&tm,0,sizeof(tm));
322
		localtime_r(&now,&tm);
323
		if(cfg.sys_misc&SM_MILITARY)
324
325
			safe_snprintf(str,maxlen,"%02d:%02d:%02d"
		        	,tm.tm_hour,tm.tm_min,tm.tm_sec);
326
		else
327
			safe_snprintf(str,maxlen,"%02d:%02d %s"
328
329
330
				,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");
331
		return(str);
332
333
	}

rswindell's avatar
rswindell committed
334
335
336
	if(!strcmp(sp,"TIMEZONE"))
		return(smb_zonestr(sys_timezone(&cfg),str));

337
	if(!strcmp(sp,"DATE") || !strcmp(sp,"SYSDATE")) {
338
		return(unixtodstr(&cfg,time32(NULL),str));
339
	}
340

rswindell's avatar
rswindell committed
341
342
343
	if(!strcmp(sp,"DATETIME"))
		return(timestr(time(NULL)));

rswindell's avatar
rswindell committed
344
345
346
347
348
	if(!strcmp(sp,"DATETIMEZONE")) {
		char zone[32];
		safe_snprintf(str, maxlen, "%s %s", timestr(time(NULL)), smb_zonestr(sys_timezone(&cfg),zone));
		return str;
	}
349
350
351
352
	
	if(strcmp(sp, "DATEFMT") == 0) {
		return cfg.sys_misc&SM_EURODATE ? "DD/MM/YY" : "MM/DD/YY";
	}
rswindell's avatar
rswindell committed
353

354
	if(!strcmp(sp,"TMSG")) {
355
356
		l=0;
		for(i=0;i<cfg.total_subs;i++)
357
			l+=getposts(&cfg,i); 		/* l=total posts */
358
		safe_snprintf(str,maxlen,"%lu",l);
359
360
		return(str);
	}
361

362
	if(!strcmp(sp,"TUSER")) {
363
		safe_snprintf(str,maxlen,"%u",total_users(&cfg));
364
365
		return(str);
	}
366

367
	if(!strcmp(sp,"TFILE")) {
368
369
		l=0;
		for(i=0;i<cfg.total_dirs;i++)
370
			l+=getfiles(&cfg,i);
371
		safe_snprintf(str,maxlen,"%lu",l);
372
373
		return(str);
	}
374

375
	if(!strcmp(sp,"TCALLS") || !strcmp(sp,"NUMCALLS")) {
376
		getstats(&cfg,0,&stats);
377
		safe_snprintf(str,maxlen,"%lu", (ulong)stats.logons);
378
379
		return(str);
	}
380

381
	if(!strcmp(sp,"PREVON") || !strcmp(sp,"LASTCALLERNODE")
382
		|| !strcmp(sp,"LASTCALLERSYSTEM"))
383
		return(lastuseron);
384

rswindell's avatar
rswindell committed
385
	if(!strcmp(sp,"CLS") || !strcmp(sp,"CLEAR")) {
386
		CLS;
387
388
		return(nulstr);
	}
389

390
	if(!strcmp(sp,"PAUSE") || !strcmp(sp,"MORE")) {
391
		pause();
392
393
		return(nulstr);
	}
394

395
	if(!strcmp(sp,"RESETPAUSE")) {
396
		lncntr=0;
397
398
		return(nulstr);
	}
399

400
	if(!strcmp(sp,"NOPAUSE") || !strcmp(sp,"POFF")) {
401
		sys_status^=SS_PAUSEOFF;
402
403
		return(nulstr);
	}
404

405
	if(!strcmp(sp,"PON") || !strcmp(sp,"AUTOMORE")) {
406
		sys_status^=SS_PAUSEON;
407
408
		return(nulstr);
	}
409

410
411
412
413
414
	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--)
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
			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;
	}

439
440
441
442
	/* NOSTOP */

	/* STOP */

443
444
	if(!strcmp(sp,"BELL") || !strcmp(sp,"BEEP"))
		return("\a");
445

446
447
448
	if(!strcmp(sp,"EVENT")) {
		if(event_time==0)
			return("<none>");
449
		return(timestr(event_time));
450
	}
451
452
453

	/* LASTCALL */

454
	if(!strncmp(sp,"NODE",4)) {
455
456
457
		i=atoi(sp+4);
		if(i && i<=cfg.sys_nodes) {
			getnodedat(i,&node,0);
458
459
			printnodedat(i,&node);
		}
460
461
		return(nulstr);
	}
462

463
	if(!strcmp(sp,"WHO")) {
464
		whos_online(true);
465
466
		return(nulstr);
	}
467
468
469

	/* User Codes */

470
471
	if(!strcmp(sp,"USER") || !strcmp(sp,"ALIAS") || !strcmp(sp,"NAME"))
		return(useron.alias);
472

473
	if(!strcmp(sp,"FIRST")) {
474
		safe_snprintf(str,maxlen,"%s",useron.alias);
475
		tp=strchr(str,' ');
476
		if(tp) *tp=0;
477
		return(str);
478
	}
479

480
	if(!strcmp(sp,"USERNUM")) {
481
		safe_snprintf(str,maxlen,"%u",useron.number);
482
483
		return(str);
	}
484

485
	if(!strcmp(sp,"PHONE") || !strcmp(sp,"HOMEPHONE")
486
		|| !strcmp(sp,"DATAPHONE") || !strcmp(sp,"DATA"))
487
		return(useron.phone);
488

489
490
	if(!strcmp(sp,"ADDR1"))
		return(useron.address);
491

492
493
	if(!strcmp(sp,"FROM"))
		return(useron.location);
494

495
	if(!strcmp(sp,"CITY")) {
496
		safe_snprintf(str,maxlen,"%s",useron.location);
497
		char* p=strchr(str,',');
498
499
		if(p) {
			*p=0;
500
501
			return(str);
		}
502
503
		return(nulstr);
	}
504

505
506
	if(!strcmp(sp,"STATE")) {
		char* p=strchr(useron.location,',');
507
508
		if(p) {
			p++;
509
			if(*p==' ')
510
				p++;
511
512
			return(p);
		}
513
514
		return(nulstr);
	}
515

516
517
	if(!strcmp(sp,"CPU"))
		return(useron.comp);
518

519
520
	if(!strcmp(sp,"HOST"))
		return(client_name);
521

522
523
	if(!strcmp(sp,"BDATE"))
		return(useron.birth);
524

525
	if(!strcmp(sp,"AGE")) {
526
		safe_snprintf(str,maxlen,"%u",getage(&cfg,useron.birth));
527
528
		return(str);
	}
rswindell's avatar
rswindell committed
529

530
	if(!strcmp(sp,"CALLS") || !strcmp(sp,"NUMTIMESON")) {
531
		safe_snprintf(str,maxlen,"%u",useron.logons);
532
533
		return(str);
	}
534

535
536
	if(!strcmp(sp,"MEMO"))
		return(unixtodstr(&cfg,useron.pwmod,str));
537

538
	if(!strcmp(sp,"SEC") || !strcmp(sp,"SECURITY")) {
539
		safe_snprintf(str,maxlen,"%u",useron.level);
540
541
		return(str);
	}
542

543
544
	if(!strcmp(sp,"SINCE"))
		return(unixtodstr(&cfg,useron.firston,str));
545

546
	if(!strcmp(sp,"TIMEON") || !strcmp(sp,"TIMEUSED")) {
547
		now=time(NULL);
548
		safe_snprintf(str,maxlen,"%lu",(ulong)(now-logontime)/60L);
549
550
		return(str);
	}
551

552
	if(!strcmp(sp,"TUSED")) {              /* Synchronet only */
553
		now=time(NULL);
554
		return(sectostr((uint)(now-logontime),str)+1);
555
	}
556

557
	if(!strcmp(sp,"TLEFT")) {              /* Synchronet only */
558
		gettimeleft();
559
		return(sectostr(timeleft,str)+1);
560
	}
561

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

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

568
	if(!strcmp(sp,"TIMELIMIT")) {
569
		safe_snprintf(str,maxlen,"%u",cfg.level_timepercall[useron.level]);
570
571
		return(str);
	}
572

573
	if(!strcmp(sp,"MINLEFT") || !strcmp(sp,"LEFT") || !strcmp(sp,"TIMELEFT")) {
574
		gettimeleft();
575
		safe_snprintf(str,maxlen,"%lu",timeleft/60);
576
577
		return(str);
	}
578

579
	if(!strcmp(sp,"LASTON"))
580
		return(timestr(useron.laston));
581

582
583
	if(!strcmp(sp,"LASTDATEON"))
		return(unixtodstr(&cfg,useron.laston,str));
584

585
	if(!strcmp(sp,"LASTTIMEON")) {
586
		memset(&tm,0,sizeof(tm));
587
		localtime32(&useron.laston,&tm);
588
589
590
591
592
593
594
595
		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");
596
		return(str);
597
598
	}

599
	if(!strcmp(sp,"MSGLEFT") || !strcmp(sp,"MSGSLEFT")) {
600
		safe_snprintf(str,maxlen,"%u",useron.posts);
601
602
		return(str);
	}
603

604
	if(!strcmp(sp,"MSGREAD")) {
605
		safe_snprintf(str,maxlen,"%lu",posts_read);
606
607
		return(str);
	}
608

609
	if(!strcmp(sp,"FREESPACE")) {
610
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,0));
611
612
613
614
		return(str);
	}

	if(!strcmp(sp,"FREESPACEK")) {
615
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,1024));
616
617
		return(str);
	}
618

619
	if(!strcmp(sp,"UPBYTES")) {
620
		safe_snprintf(str,maxlen,"%lu",useron.ulb);
621
622
		return(str);
	}
623

624
	if(!strcmp(sp,"UPK")) {
625
		safe_snprintf(str,maxlen,"%lu",useron.ulb/1024L);
626
627
		return(str);
	}
628

629
	if(!strcmp(sp,"UPS") || !strcmp(sp,"UPFILES")) {
630
		safe_snprintf(str,maxlen,"%u",useron.uls);
631
632
		return(str);
	}
633

634
	if(!strcmp(sp,"DLBYTES")) {
635
		safe_snprintf(str,maxlen,"%lu",useron.dlb);
636
637
		return(str);
	}
638

639
	if(!strcmp(sp,"DOWNK")) {
640
		safe_snprintf(str,maxlen,"%lu",useron.dlb/1024L);
641
642
		return(str);
	}
643

644
	if(!strcmp(sp,"DOWNS") || !strcmp(sp,"DLFILES")) {
645
		safe_snprintf(str,maxlen,"%u",useron.dls);
646
647
		return(str);
	}
648

649
	if(!strcmp(sp,"LASTNEW"))
650
		return(unixtodstr(&cfg,(time32_t)ns_time,str));
651

652
	if(!strcmp(sp,"NEWFILETIME"))
653
		return(timestr(ns_time));
654
655
656

	/* MAXDL */

657
	if(!strcmp(sp,"MAXDK") || !strcmp(sp,"DLKLIMIT") || !strcmp(sp,"KBLIMIT")) {
658
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]/1024L);
659
660
		return(str);
	}
661

662
	if(!strcmp(sp,"DAYBYTES")) {    /* amt of free cdts used today */
663
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]-useron.freecdt);
664
665
		return(str);
	}
666

667
	if(!strcmp(sp,"BYTELIMIT")) {
668
		safe_snprintf(str,maxlen,"%ld", (long)cfg.level_freecdtperday[useron.level]);
669
670
		return(str);
	}
671

672
	if(!strcmp(sp,"KBLEFT")) {
673
		safe_snprintf(str,maxlen,"%lu",(useron.cdt+useron.freecdt)/1024L);
674
675
		return(str);
	}
676

677
	if(!strcmp(sp,"BYTESLEFT")) {
678
		safe_snprintf(str,maxlen,"%lu",useron.cdt+useron.freecdt);
679
680
		return(str);
	}
681

682
	if(!strcmp(sp,"CONF")) {
683
		safe_snprintf(str,maxlen,"%s %s"
684
685
			,usrgrps ? cfg.grp[usrgrp[curgrp]]->sname :nulstr
			,usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr);
686
687
		return(str);
	}
688

689
	if(!strcmp(sp,"CONFNUM")) {
690
		safe_snprintf(str,maxlen,"%u %u",curgrp+1,cursub[curgrp]+1);
691
692
		return(str);
	}
693

694
	if(!strcmp(sp,"NUMDIR")) {
695
		safe_snprintf(str,maxlen,"%u %u",usrlibs ? curlib+1 : 0,usrlibs ? curdir[curlib]+1 : 0);
696
697
		return(str);
	}
698

699
700
	if(!strcmp(sp,"EXDATE") || !strcmp(sp,"EXPDATE"))
		return(unixtodstr(&cfg,useron.expire,str));
701

702
	if(!strcmp(sp,"EXPDAYS")) {
703
		now=time(NULL);
704
		l=(long)(useron.expire-now);
705
706
		if(l<0)
			l=0;
707
		safe_snprintf(str,maxlen,"%lu",l/(1440L*60L));
708
709
		return(str);
	}
710

711
712
	if(!strcmp(sp,"MEMO1"))
		return(useron.note);
713

714
715
	if(!strcmp(sp,"MEMO2") || !strcmp(sp,"COMPANY"))
		return(useron.name);
716

717
718
	if(!strcmp(sp,"ZIP"))
		return(useron.zipcode);
719

720
	if(!strcmp(sp,"HANGUP")) {
721
		hangup();
722
723
		return(nulstr);
	}
724
725
726

	/* Synchronet Specific */

727
	if(!strncmp(sp,"SETSTR:",7)) {
728
		strcpy(main_csi.str,sp+7);
729
730
		return(nulstr);
	}
731

732
	if(!strncmp(sp,"EXEC:",5)) {
733
		exec_bin(sp+5,&main_csi);
734
735
		return(nulstr);
	}
736

737
	if(!strncmp(sp,"EXEC_XTRN:",10)) {
738
		for(i=0;i<cfg.total_xtrns;i++)
739
			if(!stricmp(cfg.xtrn[i]->code,sp+10))
740
741
742
743
744
745
				break;
		if(i<cfg.total_xtrns)
			exec_xtrn(i);
		return(nulstr);
	}

746
	if(!strncmp(sp,"MENU:",5)) {
747
		menu(sp+5);
748
749
		return(nulstr);
	}
750

751
752
753
754
755
	if(!strncmp(sp,"CONDMENU:",9)) {
		menu(sp+9, P_NOERROR);
		return(nulstr);
	}

756
757
758
759
	if(!strncmp(sp,"TYPE:",5)) {
		printfile(cmdstr(sp+5,nulstr,nulstr,str),0);
		return(nulstr);
	}
760

761
	if(!strncmp(sp,"INCLUDE:",8)) {
762
		printfile(cmdstr(sp+8,nulstr,nulstr,str),P_NOCRLF|P_SAVEATR);
763
764
765
		return(nulstr);
	}

766
767
	if(!strcmp(sp,"QUESTION"))
		return(question);
768

769
770
	if(!strcmp(sp,"HANDLE"))
		return(useron.handle);
771

772
773
	if(!strcmp(sp,"CID") || !strcmp(sp,"IP"))
		return(cid);
774

deuce's avatar
deuce committed
775
776
	if(!strcmp(sp,"LOCAL-IP"))
		return(local_addr);
777

778
779
	if(!strcmp(sp,"CRLF"))
		return("\r\n");
780

781
	if(!strcmp(sp,"PUSHXY")) {
782
		ansi_save();
783
784
		return(nulstr);
	}
785

786
	if(!strcmp(sp,"POPXY")) {
787
		ansi_restore();
788
789
		return(nulstr);
	}
790

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

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

801
	if(!strcmp(sp,"CLR2EOL") || !strcmp(sp,"CLREOL")) {
rswindell's avatar
rswindell committed
802
803
804
805
806
807
808
809
810
		cleartoeol();
		return(nulstr);
	}

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

811
	if(!strncmp(sp,"UP:",3)) {
812
		cursor_up(atoi(sp+3));
rswindell's avatar