atcodes.cpp 35.1 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

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

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

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

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

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

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

	return(len);
}

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

	str[0]=0;

144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
	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;
	}

163
	if(!strcmp(sp,"VER"))
164
		return(VERSION);
165

166
	if(!strcmp(sp,"REV")) {
167
		safe_snprintf(str,maxlen,"%c",REVISION);
168
169
		return(str);
	}
170

171
	if(!strcmp(sp,"FULL_VER")) {
172
		safe_snprintf(str,maxlen,"%s%c%s",VERSION,REVISION,beta_version);
173
		truncsp(str);
174
#if defined(_DEBUG)
175
		strcat(str," Debug");
176
#endif
177
		return(str);
178
179
	}

180
	if(!strcmp(sp,"VER_NOTICE"))
181
		return(VERSION_NOTICE);
182

183
184
	if(!strcmp(sp,"OS_VER"))
		return(os_version(str));
185
186

#ifdef JAVASCRIPT
187
188
	if(!strcmp(sp,"JS_VER"))
		return((char *)JS_GetImplementationVersion());
189
190
#endif

191
192
	if(!strcmp(sp,"PLATFORM"))
		return(PLATFORM_DESC);
193

194
195
	if(!strcmp(sp,"COPYRIGHT"))
		return(COPYRIGHT_NOTICE);
196

197
	if(!strcmp(sp,"COMPILER")) {
198
199
200
		char compiler[32];
		DESCRIBE_COMPILER(compiler);
		strncpy(str, compiler, maxlen);
201
		return(str);
202
203
	}

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

223
	if(!strcmp(sp,"SERVED")) {
224
		extern volatile ulong served;
225
		safe_snprintf(str,maxlen,"%lu",served);
226
227
228
		return(str);
	}

229
	if(!strcmp(sp,"SOCKET_LIB"))
230
		return(socklib_version(str,SOCKLIB_DESC));
231

232
	if(!strcmp(sp,"MSG_LIB")) {
233
		safe_snprintf(str,maxlen,"SMBLIB %s",smb_lib_ver());
234
235
		return(str);
	}
236

237
238
	if(!strcmp(sp,"BBS") || !strcmp(sp,"BOARDNAME"))
		return(cfg.sys_name);
239

240
	if(!strcmp(sp,"BAUD") || !strcmp(sp,"BPS")) {
241
		safe_snprintf(str,maxlen,"%lu",cur_rate);
242
243
		return(str);
	}
244

rswindell's avatar
rswindell committed
245
246
247
248
249
250
251
252
253
254
255
	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);

256
257
	if(!strcmp(sp,"CONN"))
		return(connection);
258

259
260
	if(!strcmp(sp,"SYSOP"))
		return(cfg.sys_op);
261

262
263
	if(!strcmp(sp,"LOCATION"))
		return(cfg.sys_location);
264

265
	if(!strcmp(sp,"NODE")) {
266
		safe_snprintf(str,maxlen,"%u",cfg.node_num);
267
268
		return(str);
	}
269

270
	if(!strcmp(sp,"TNODE")) {
271
		safe_snprintf(str,maxlen,"%u",cfg.sys_nodes);
272
273
		return(str);
	}
274

275
276
277
278
279
280
	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];

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

284
285
	if(!strcmp(sp,"INETADDR"))
		return(cfg.sys_inetaddr);
286

287
288
289
	if(!strcmp(sp,"HOSTNAME"))
		return(startup->host_name);

290
	if(!strcmp(sp,"FIDOADDR")) {
291
		if(cfg.total_faddrs)
292
			return(smb_faddrtoa(&cfg.faddr[0],str));
293
		return(nulstr);
294
295
	}

296
	if(!strcmp(sp,"EMAILADDR"))
297
		return(usermailaddr(&cfg, str
298
			,cfg.inetmail_misc&NMAIL_ALIAS ? useron.alias : useron.name));
299

300
301
	if(!strcmp(sp,"QWKID"))
		return(cfg.sys_id);
302

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

rswindell's avatar
rswindell committed
318
319
320
	if(!strcmp(sp,"TIMEZONE"))
		return(smb_zonestr(sys_timezone(&cfg),str));

321
	if(!strcmp(sp,"DATE") || !strcmp(sp,"SYSDATE")) {
322
		return(unixtodstr(&cfg,time32(NULL),str));
323
	}
324

rswindell's avatar
rswindell committed
325
326
327
	if(!strcmp(sp,"DATETIME"))
		return(timestr(time(NULL)));

rswindell's avatar
rswindell committed
328
329
330
331
332
333
	if(!strcmp(sp,"DATETIMEZONE")) {
		char zone[32];
		safe_snprintf(str, maxlen, "%s %s", timestr(time(NULL)), smb_zonestr(sys_timezone(&cfg),zone));
		return str;
	}

334
	if(!strcmp(sp,"TMSG")) {
335
336
		l=0;
		for(i=0;i<cfg.total_subs;i++)
337
			l+=getposts(&cfg,i); 		/* l=total posts */
338
		safe_snprintf(str,maxlen,"%lu",l);
339
340
		return(str);
	}
341

342
	if(!strcmp(sp,"TUSER")) {
343
		safe_snprintf(str,maxlen,"%u",total_users(&cfg));
344
345
		return(str);
	}
346

347
	if(!strcmp(sp,"TFILE")) {
348
349
		l=0;
		for(i=0;i<cfg.total_dirs;i++)
350
			l+=getfiles(&cfg,i);
351
		safe_snprintf(str,maxlen,"%lu",l);
352
353
		return(str);
	}
354

355
	if(!strcmp(sp,"TCALLS") || !strcmp(sp,"NUMCALLS")) {
356
		getstats(&cfg,0,&stats);
357
		safe_snprintf(str,maxlen,"%lu", (ulong)stats.logons);
358
359
		return(str);
	}
360

361
	if(!strcmp(sp,"PREVON") || !strcmp(sp,"LASTCALLERNODE")
362
		|| !strcmp(sp,"LASTCALLERSYSTEM"))
363
		return(lastuseron);
364

rswindell's avatar
rswindell committed
365
	if(!strcmp(sp,"CLS") || !strcmp(sp,"CLEAR")) {
366
		CLS;
367
368
		return(nulstr);
	}
369

370
	if(!strcmp(sp,"PAUSE") || !strcmp(sp,"MORE")) {
371
		pause();
372
373
		return(nulstr);
	}
374

375
	if(!strcmp(sp,"RESETPAUSE")) {
376
		lncntr=0;
377
378
		return(nulstr);
	}
379

380
	if(!strcmp(sp,"NOPAUSE") || !strcmp(sp,"POFF")) {
381
		sys_status^=SS_PAUSEOFF;
382
383
		return(nulstr);
	}
384

385
	if(!strcmp(sp,"PON") || !strcmp(sp,"AUTOMORE")) {
386
		sys_status^=SS_PAUSEON;
387
388
		return(nulstr);
	}
389

390
391
392
393
394
	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--)
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
			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;
	}

419
420
421
422
	/* NOSTOP */

	/* STOP */

423
424
	if(!strcmp(sp,"BELL") || !strcmp(sp,"BEEP"))
		return("\a");
425

426
427
428
	if(!strcmp(sp,"EVENT")) {
		if(event_time==0)
			return("<none>");
429
		return(timestr(event_time));
430
	}
431
432
433

	/* LASTCALL */

434
	if(!strncmp(sp,"NODE",4)) {
435
436
437
		i=atoi(sp+4);
		if(i && i<=cfg.sys_nodes) {
			getnodedat(i,&node,0);
438
439
			printnodedat(i,&node);
		}
440
441
		return(nulstr);
	}
442

443
	if(!strcmp(sp,"WHO")) {
444
		whos_online(true);
445
446
		return(nulstr);
	}
447
448
449

	/* User Codes */

450
451
	if(!strcmp(sp,"USER") || !strcmp(sp,"ALIAS") || !strcmp(sp,"NAME"))
		return(useron.alias);
452

453
	if(!strcmp(sp,"FIRST")) {
454
		safe_snprintf(str,maxlen,"%s",useron.alias);
455
		tp=strchr(str,' ');
456
		if(tp) *tp=0;
457
		return(str);
458
	}
459

460
	if(!strcmp(sp,"USERNUM")) {
461
		safe_snprintf(str,maxlen,"%u",useron.number);
462
463
		return(str);
	}
464

465
	if(!strcmp(sp,"PHONE") || !strcmp(sp,"HOMEPHONE")
466
		|| !strcmp(sp,"DATAPHONE") || !strcmp(sp,"DATA"))
467
		return(useron.phone);
468

469
470
	if(!strcmp(sp,"ADDR1"))
		return(useron.address);
471

472
473
	if(!strcmp(sp,"FROM"))
		return(useron.location);
474

475
	if(!strcmp(sp,"CITY")) {
476
		safe_snprintf(str,maxlen,"%s",useron.location);
477
		char* p=strchr(str,',');
478
479
		if(p) {
			*p=0;
480
481
			return(str);
		}
482
483
		return(nulstr);
	}
484

485
486
	if(!strcmp(sp,"STATE")) {
		char* p=strchr(useron.location,',');
487
488
		if(p) {
			p++;
489
			if(*p==' ')
490
				p++;
491
492
			return(p);
		}
493
494
		return(nulstr);
	}
495

496
497
	if(!strcmp(sp,"CPU"))
		return(useron.comp);
498

499
500
	if(!strcmp(sp,"HOST"))
		return(client_name);
501

502
503
	if(!strcmp(sp,"BDATE"))
		return(useron.birth);
504

505
	if(!strcmp(sp,"AGE")) {
506
		safe_snprintf(str,maxlen,"%u",getage(&cfg,useron.birth));
507
508
		return(str);
	}
rswindell's avatar
rswindell committed
509

510
	if(!strcmp(sp,"CALLS") || !strcmp(sp,"NUMTIMESON")) {
511
		safe_snprintf(str,maxlen,"%u",useron.logons);
512
513
		return(str);
	}
514

515
516
	if(!strcmp(sp,"MEMO"))
		return(unixtodstr(&cfg,useron.pwmod,str));
517

518
	if(!strcmp(sp,"SEC") || !strcmp(sp,"SECURITY")) {
519
		safe_snprintf(str,maxlen,"%u",useron.level);
520
521
		return(str);
	}
522

523
524
	if(!strcmp(sp,"SINCE"))
		return(unixtodstr(&cfg,useron.firston,str));
525

526
	if(!strcmp(sp,"TIMEON") || !strcmp(sp,"TIMEUSED")) {
527
		now=time(NULL);
528
		safe_snprintf(str,maxlen,"%lu",(ulong)(now-logontime)/60L);
529
530
		return(str);
	}
531

532
	if(!strcmp(sp,"TUSED")) {              /* Synchronet only */
533
		now=time(NULL);
534
		return(sectostr((uint)(now-logontime),str)+1);
535
	}
536

537
	if(!strcmp(sp,"TLEFT")) {              /* Synchronet only */
538
		gettimeleft();
539
		return(sectostr(timeleft,str)+1);
540
	}
541

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

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

548
	if(!strcmp(sp,"TIMELIMIT")) {
549
		safe_snprintf(str,maxlen,"%u",cfg.level_timepercall[useron.level]);
550
551
		return(str);
	}
552

553
	if(!strcmp(sp,"MINLEFT") || !strcmp(sp,"LEFT") || !strcmp(sp,"TIMELEFT")) {
554
		gettimeleft();
555
		safe_snprintf(str,maxlen,"%lu",timeleft/60);
556
557
		return(str);
	}
558

559
	if(!strcmp(sp,"LASTON"))
560
		return(timestr(useron.laston));
561

562
563
	if(!strcmp(sp,"LASTDATEON"))
		return(unixtodstr(&cfg,useron.laston,str));
564

565
	if(!strcmp(sp,"LASTTIMEON")) {
566
		memset(&tm,0,sizeof(tm));
567
		localtime32(&useron.laston,&tm);
568
569
570
571
572
573
574
575
		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");
576
		return(str);
577
578
	}

579
	if(!strcmp(sp,"MSGLEFT") || !strcmp(sp,"MSGSLEFT")) {
580
		safe_snprintf(str,maxlen,"%u",useron.posts);
581
582
		return(str);
	}
583

584
	if(!strcmp(sp,"MSGREAD")) {
585
		safe_snprintf(str,maxlen,"%lu",posts_read);
586
587
		return(str);
	}
588

589
	if(!strcmp(sp,"FREESPACE")) {
590
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,0));
591
592
593
594
		return(str);
	}

	if(!strcmp(sp,"FREESPACEK")) {
595
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,1024));
596
597
		return(str);
	}
598

599
	if(!strcmp(sp,"UPBYTES")) {
600
		safe_snprintf(str,maxlen,"%lu",useron.ulb);
601
602
		return(str);
	}
603

604
	if(!strcmp(sp,"UPK")) {
605
		safe_snprintf(str,maxlen,"%lu",useron.ulb/1024L);
606
607
		return(str);
	}
608

609
	if(!strcmp(sp,"UPS") || !strcmp(sp,"UPFILES")) {
610
		safe_snprintf(str,maxlen,"%u",useron.uls);
611
612
		return(str);
	}
613

614
	if(!strcmp(sp,"DLBYTES")) {
615
		safe_snprintf(str,maxlen,"%lu",useron.dlb);
616
617
		return(str);
	}
618

619
	if(!strcmp(sp,"DOWNK")) {
620
		safe_snprintf(str,maxlen,"%lu",useron.dlb/1024L);
621
622
		return(str);
	}
623

624
	if(!strcmp(sp,"DOWNS") || !strcmp(sp,"DLFILES")) {
625
		safe_snprintf(str,maxlen,"%u",useron.dls);
626
627
		return(str);
	}
628

629
	if(!strcmp(sp,"LASTNEW"))
630
		return(unixtodstr(&cfg,(time32_t)ns_time,str));
631

632
	if(!strcmp(sp,"NEWFILETIME"))
633
		return(timestr(ns_time));
634
635
636

	/* MAXDL */

637
	if(!strcmp(sp,"MAXDK") || !strcmp(sp,"DLKLIMIT") || !strcmp(sp,"KBLIMIT")) {
638
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]/1024L);
639
640
		return(str);
	}
641

642
	if(!strcmp(sp,"DAYBYTES")) {    /* amt of free cdts used today */
643
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]-useron.freecdt);
644
645
		return(str);
	}
646

647
	if(!strcmp(sp,"BYTELIMIT")) {
648
		safe_snprintf(str,maxlen,"%ld", (long)cfg.level_freecdtperday[useron.level]);
649
650
		return(str);
	}
651

652
	if(!strcmp(sp,"KBLEFT")) {
653
		safe_snprintf(str,maxlen,"%lu",(useron.cdt+useron.freecdt)/1024L);
654
655
		return(str);
	}
656

657
	if(!strcmp(sp,"BYTESLEFT")) {
658
		safe_snprintf(str,maxlen,"%lu",useron.cdt+useron.freecdt);
659
660
		return(str);
	}
661

662
	if(!strcmp(sp,"CONF")) {
663
		safe_snprintf(str,maxlen,"%s %s"
664
665
			,usrgrps ? cfg.grp[usrgrp[curgrp]]->sname :nulstr
			,usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr);
666
667
		return(str);
	}
668

669
	if(!strcmp(sp,"CONFNUM")) {
670
		safe_snprintf(str,maxlen,"%u %u",curgrp+1,cursub[curgrp]+1);
671
672
		return(str);
	}
673

674
	if(!strcmp(sp,"NUMDIR")) {
675
		safe_snprintf(str,maxlen,"%u %u",usrlibs ? curlib+1 : 0,usrlibs ? curdir[curlib]+1 : 0);
676
677
		return(str);
	}
678

679
680
	if(!strcmp(sp,"EXDATE") || !strcmp(sp,"EXPDATE"))
		return(unixtodstr(&cfg,useron.expire,str));
681

682
	if(!strcmp(sp,"EXPDAYS")) {
683
		now=time(NULL);
684
		l=(long)(useron.expire-now);
685
686
		if(l<0)
			l=0;
687
		safe_snprintf(str,maxlen,"%lu",l/(1440L*60L));
688
689
		return(str);
	}
690

691
692
	if(!strcmp(sp,"MEMO1"))
		return(useron.note);
693

694
695
	if(!strcmp(sp,"MEMO2") || !strcmp(sp,"COMPANY"))
		return(useron.name);
696

697
698
	if(!strcmp(sp,"ZIP"))
		return(useron.zipcode);
699

700
	if(!strcmp(sp,"HANGUP")) {
701
		hangup();
702
703
		return(nulstr);
	}
704
705
706

	/* Synchronet Specific */

707
	if(!strncmp(sp,"SETSTR:",7)) {
708
		strcpy(main_csi.str,sp+7);
709
710
		return(nulstr);
	}
711

712
	if(!strncmp(sp,"EXEC:",5)) {
713
		exec_bin(sp+5,&main_csi);
714
715
		return(nulstr);
	}
716

717
	if(!strncmp(sp,"EXEC_XTRN:",10)) {
718
		for(i=0;i<cfg.total_xtrns;i++)
719
			if(!stricmp(cfg.xtrn[i]->code,sp+10))
720
721
722
723
724
725
				break;
		if(i<cfg.total_xtrns)
			exec_xtrn(i);
		return(nulstr);
	}

726
	if(!strncmp(sp,"MENU:",5)) {
727
		menu(sp+5);
728
729
		return(nulstr);
	}
730

731
732
733
734
735
	if(!strncmp(sp,"CONDMENU:",9)) {
		menu(sp+9, P_NOERROR);
		return(nulstr);
	}

736
737
738
739
	if(!strncmp(sp,"TYPE:",5)) {
		printfile(cmdstr(sp+5,nulstr,nulstr,str),0);
		return(nulstr);
	}
740

741
	if(!strncmp(sp,"INCLUDE:",8)) {
742
		printfile(cmdstr(sp+8,nulstr,nulstr,str),P_NOCRLF|P_SAVEATR);
743
744
745
		return(nulstr);
	}

746
747
	if(!strcmp(sp,"QUESTION"))
		return(question);
748

749
750
	if(!strcmp(sp,"HANDLE"))
		return(useron.handle);
751

752
753
	if(!strcmp(sp,"CID") || !strcmp(sp,"IP"))
		return(cid);
754

deuce's avatar
deuce committed
755
756
	if(!strcmp(sp,"LOCAL-IP"))
		return(local_addr);
757

758
759
	if(!strcmp(sp,"CRLF"))
		return("\r\n");
760

761
	if(!strcmp(sp,"PUSHXY")) {
762
		ansi_save();
763
764
		return(nulstr);
	}
765

766
	if(!strcmp(sp,"POPXY")) {
767
		ansi_restore();
768
769
		return(nulstr);
	}
770

rswindell's avatar
rswindell committed
771
772
773
774
775
776
777
778
779
780
	if(!strcmp(sp,"HOME")) {
		cursor_home();
		return(nulstr);
	}

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

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

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

791
	if(!strncmp(sp,"UP:",3)) {
792
		cursor_up(atoi(sp+3));
793
794
		return(str);
	}
795

796
	if(!strncmp(sp,"DOWN:",5)) {
797
		cursor_down(atoi(sp+5));
798
799
		return(str);
	}
800

801
	if(!strncmp(sp,"LEFT:",5)) {
802
		cursor_left(atoi(sp+5));
803
804
		return(str);
	}
805

806
	if(!strncmp(sp,"RIGHT:",6)) {