atcodes.cpp 36.4 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
	if(strchr(sp, ':') != NULL)
		p = NULL;
	else if((p=strstr(sp,"-L"))!=NULL)
81
82
83
		padded_left=true;
	else if((p=strstr(sp,"-R"))!=NULL)
		padded_right=true;
84
85
	else if((p=strstr(sp,"-C"))!=NULL)
		centered=true;
rswindell's avatar
rswindell committed
86
	else if((p=strstr(sp,"-W"))!=NULL)	/* wide */
rswindell's avatar
rswindell committed
87
		doubled=true;
88
89
	else if((p=strstr(sp,"-Z"))!=NULL)
		zero_padded=true;
rswindell's avatar
rswindell committed
90
	else if((p=strstr(sp,"->"))!=NULL)	/* wrap */
rswindell's avatar
rswindell committed
91
		truncated = false;
92
	if(p!=NULL) {
rswindell's avatar
rswindell committed
93
94
95
		char* lp = p + 2;
		if(*lp && isdigit(*lp))
			disp_len=atoi(lp);
96
		*p=0;
97
	}
98

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

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

	return(len);
}

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

	str[0]=0;

152
153
	if(strncmp(sp, "U+", 2) == 0) {	// UNICODE
		enum unicode_codepoint codepoint = (enum unicode_codepoint)strtoul(sp + 2, &tp, 16);
rswindell's avatar
rswindell committed
154
		if(tp == NULL || *tp == 0)
155
			outchar(codepoint, unicode_to_cp437(codepoint));
rswindell's avatar
rswindell committed
156
157
		else if(*tp == ':')
			outchar(codepoint, tp + 1);
158
159
		else {
			char fallback = (char)strtoul(tp + 1, NULL, 16);
rswindell's avatar
rswindell committed
160
			if(*tp == ',')
161
162
163
164
165
166
167
168
169
170
171
172
				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;
	}

173
174
175
176
177
	if(strcmp(sp, "CHECKMARK") == 0) {
		outchar(UNICODE_CHECK_MARK, CP437_CHECK_MARK);
		return nulstr;
	}

rswindell's avatar
rswindell committed
178
179
180
181
	if(strcmp(sp, "ELLIPSIS") == 0) {
		outchar(UNICODE_HORIZONTAL_ELLIPSIS, "...");
		return nulstr;
	}
182
	if(strcmp(sp, "COPY") == 0) {
rswindell's avatar
rswindell committed
183
184
185
186
187
188
189
		outchar(UNICODE_COPYRIGHT_SIGN, "(C)");
		return nulstr;
	}
	if(strcmp(sp, "SOUNDCOPY") == 0) {
		outchar(UNICODE_SOUND_RECORDING_COPYRIGHT, "(P)");
		return nulstr;
	}
rswindell's avatar
rswindell committed
190
191
192
193
	if(strcmp(sp, "REGISTERED") == 0) {
		outchar(UNICODE_REGISTERED_SIGN, "(R)");
		return nulstr;
	}
rswindell's avatar
rswindell committed
194
195
196
197
198
199
200
201
202
203
204
205
206
	if(strcmp(sp, "TRADEMARK") == 0) {
		outchar(UNICODE_TRADE_MARK_SIGN, "(TM)");
		return nulstr;
	}
	if(strcmp(sp, "DEGREE_C") == 0) {
		outchar(UNICODE_DEGREE_CELSIUS, "\xF8C");
		return nulstr;
	}
	if(strcmp(sp, "DEGREE_F") == 0) {
		outchar(UNICODE_DEGREE_FAHRENHEIT, "\xF8F");
		return nulstr;
	}

rswindell's avatar
rswindell committed
207
208
209
210
211
	if(strncmp(sp, "WIDE:", 5) == 0) {
		wide(sp + 5);
		return(nulstr);
	}

212
	if(!strcmp(sp,"VER"))
213
		return(VERSION);
214

215
	if(!strcmp(sp,"REV")) {
216
		safe_snprintf(str,maxlen,"%c",REVISION);
217
218
		return(str);
	}
219

220
	if(!strcmp(sp,"FULL_VER")) {
221
		safe_snprintf(str,maxlen,"%s%c%s",VERSION,REVISION,beta_version);
222
		truncsp(str);
223
#if defined(_DEBUG)
224
		strcat(str," Debug");
225
#endif
226
		return(str);
227
228
	}

229
	if(!strcmp(sp,"VER_NOTICE"))
230
		return(VERSION_NOTICE);
231

232
233
	if(!strcmp(sp,"OS_VER"))
		return(os_version(str));
234
235

#ifdef JAVASCRIPT
236
237
	if(!strcmp(sp,"JS_VER"))
		return((char *)JS_GetImplementationVersion());
238
239
#endif

240
241
	if(!strcmp(sp,"PLATFORM"))
		return(PLATFORM_DESC);
242

243
244
	if(!strcmp(sp,"COPYRIGHT"))
		return(COPYRIGHT_NOTICE);
245

246
	if(!strcmp(sp,"COMPILER")) {
247
248
249
		char compiler[32];
		DESCRIBE_COMPILER(compiler);
		strncpy(str, compiler, maxlen);
250
		return(str);
251
252
	}

253
	if(!strcmp(sp,"UPTIME")) {
254
		extern volatile time_t uptime;
255
256
257
258
		time_t up=0;
		now = time(NULL);
		if (uptime != 0 && now >= uptime)
			up = now-uptime;
259
260
		char   days[64]="";
		if((up/(24*60*60))>=2) {
261
	        sprintf(days,"%lu days ",(ulong)(up/(24L*60L*60L)));
262
263
			up%=(24*60*60);
		}
264
		safe_snprintf(str,maxlen,"%s%lu:%02lu"
265
	        ,days
266
267
			,(ulong)(up/(60L*60L))
			,(ulong)((up/60L)%60L)
268
			);
269
		return(str);
270
271
	}

272
	if(!strcmp(sp,"SERVED")) {
273
		extern volatile ulong served;
274
		safe_snprintf(str,maxlen,"%lu",served);
275
276
277
		return(str);
	}

278
	if(!strcmp(sp,"SOCKET_LIB"))
279
		return(socklib_version(str,SOCKLIB_DESC));
280

281
	if(!strcmp(sp,"MSG_LIB")) {
282
		safe_snprintf(str,maxlen,"SMBLIB %s",smb_lib_ver());
283
284
		return(str);
	}
285

286
287
	if(!strcmp(sp,"BBS") || !strcmp(sp,"BOARDNAME"))
		return(cfg.sys_name);
288

289
	if(!strcmp(sp,"BAUD") || !strcmp(sp,"BPS")) {
290
		safe_snprintf(str,maxlen,"%lu",cur_rate);
291
292
		return(str);
	}
293

rswindell's avatar
rswindell committed
294
295
296
297
298
299
300
301
	if(!strcmp(sp,"COLS")) {
		safe_snprintf(str,maxlen,"%lu",cols);
		return(str);
	}
	if(!strcmp(sp,"ROWS")) {
		safe_snprintf(str,maxlen,"%lu",rows);
		return(str);
	}
302
303
304
305
306
	if(strcmp(sp,"TERM") == 0)
		return term_type();

	if(strcmp(sp,"CHARSET") == 0)
		return term_charset();
rswindell's avatar
rswindell committed
307

308
309
	if(!strcmp(sp,"CONN"))
		return(connection);
310

311
312
	if(!strcmp(sp,"SYSOP"))
		return(cfg.sys_op);
313

314
315
	if(!strcmp(sp,"LOCATION"))
		return(cfg.sys_location);
316

317
	if(!strcmp(sp,"NODE")) {
318
		safe_snprintf(str,maxlen,"%u",cfg.node_num);
319
320
		return(str);
	}
321

322
	if(!strcmp(sp,"TNODE")) {
323
		safe_snprintf(str,maxlen,"%u",cfg.sys_nodes);
324
325
		return(str);
	}
326

327
328
329
330
331
332
	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];

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

336
337
	if(!strcmp(sp,"INETADDR"))
		return(cfg.sys_inetaddr);
338

339
340
341
	if(!strcmp(sp,"HOSTNAME"))
		return(startup->host_name);

342
	if(!strcmp(sp,"FIDOADDR")) {
343
		if(cfg.total_faddrs)
344
			return(smb_faddrtoa(&cfg.faddr[0],str));
345
		return(nulstr);
346
347
	}

348
	if(!strcmp(sp,"EMAILADDR"))
349
		return(usermailaddr(&cfg, str
350
			,cfg.inetmail_misc&NMAIL_ALIAS ? useron.alias : useron.name));
351

352
353
	if(!strcmp(sp,"QWKID"))
		return(cfg.sys_id);
354

355
	if(!strcmp(sp,"TIME") || !strcmp(sp,"SYSTIME")) {
356
		now=time(NULL);
357
		memset(&tm,0,sizeof(tm));
358
		localtime_r(&now,&tm);
359
		if(cfg.sys_misc&SM_MILITARY)
360
361
			safe_snprintf(str,maxlen,"%02d:%02d:%02d"
		        	,tm.tm_hour,tm.tm_min,tm.tm_sec);
362
		else
363
			safe_snprintf(str,maxlen,"%02d:%02d %s"
364
365
366
				,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");
367
		return(str);
368
369
	}

rswindell's avatar
rswindell committed
370
371
372
	if(!strcmp(sp,"TIMEZONE"))
		return(smb_zonestr(sys_timezone(&cfg),str));

373
	if(!strcmp(sp,"DATE") || !strcmp(sp,"SYSDATE")) {
374
		return(unixtodstr(&cfg,time32(NULL),str));
375
	}
376

rswindell's avatar
rswindell committed
377
378
379
	if(!strcmp(sp,"DATETIME"))
		return(timestr(time(NULL)));

rswindell's avatar
rswindell committed
380
381
382
383
384
	if(!strcmp(sp,"DATETIMEZONE")) {
		char zone[32];
		safe_snprintf(str, maxlen, "%s %s", timestr(time(NULL)), smb_zonestr(sys_timezone(&cfg),zone));
		return str;
	}
385
386
387
388
	
	if(strcmp(sp, "DATEFMT") == 0) {
		return cfg.sys_misc&SM_EURODATE ? "DD/MM/YY" : "MM/DD/YY";
	}
rswindell's avatar
rswindell committed
389

390
	if(!strcmp(sp,"TMSG")) {
391
392
		l=0;
		for(i=0;i<cfg.total_subs;i++)
393
			l+=getposts(&cfg,i); 		/* l=total posts */
394
		safe_snprintf(str,maxlen,"%lu",l);
395
396
		return(str);
	}
397

398
	if(!strcmp(sp,"TUSER")) {
399
		safe_snprintf(str,maxlen,"%u",total_users(&cfg));
400
401
		return(str);
	}
402

403
	if(!strcmp(sp,"TFILE")) {
404
405
		l=0;
		for(i=0;i<cfg.total_dirs;i++)
406
			l+=getfiles(&cfg,i);
407
		safe_snprintf(str,maxlen,"%lu",l);
408
409
		return(str);
	}
410

411
	if(!strcmp(sp,"TCALLS") || !strcmp(sp,"NUMCALLS")) {
412
		getstats(&cfg,0,&stats);
413
		safe_snprintf(str,maxlen,"%lu", (ulong)stats.logons);
414
415
		return(str);
	}
416

417
	if(!strcmp(sp,"PREVON") || !strcmp(sp,"LASTCALLERNODE")
418
		|| !strcmp(sp,"LASTCALLERSYSTEM"))
419
		return(lastuseron);
420

rswindell's avatar
rswindell committed
421
	if(!strcmp(sp,"CLS") || !strcmp(sp,"CLEAR")) {
422
		CLS;
423
424
		return(nulstr);
	}
425

426
	if(!strcmp(sp,"PAUSE") || !strcmp(sp,"MORE")) {
427
		pause();
428
429
		return(nulstr);
	}
430

431
	if(!strcmp(sp,"RESETPAUSE")) {
432
		lncntr=0;
433
434
		return(nulstr);
	}
435

436
	if(!strcmp(sp,"NOPAUSE") || !strcmp(sp,"POFF")) {
437
		sys_status^=SS_PAUSEOFF;
438
439
		return(nulstr);
	}
440

441
	if(!strcmp(sp,"PON") || !strcmp(sp,"AUTOMORE")) {
442
		sys_status^=SS_PAUSEON;
443
444
		return(nulstr);
	}
445

446
447
448
449
450
	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--)
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
			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;
	}

475
476
477
478
	/* NOSTOP */

	/* STOP */

479
480
	if(!strcmp(sp,"BELL") || !strcmp(sp,"BEEP"))
		return("\a");
481

482
483
484
	if(!strcmp(sp,"EVENT")) {
		if(event_time==0)
			return("<none>");
485
		return(timestr(event_time));
486
	}
487
488
489

	/* LASTCALL */

490
	if(!strncmp(sp,"NODE",4)) {
491
492
493
		i=atoi(sp+4);
		if(i && i<=cfg.sys_nodes) {
			getnodedat(i,&node,0);
494
495
			printnodedat(i,&node);
		}
496
497
		return(nulstr);
	}
498

499
	if(!strcmp(sp,"WHO")) {
500
		whos_online(true);
501
502
		return(nulstr);
	}
503
504
505

	/* User Codes */

506
507
	if(!strcmp(sp,"USER") || !strcmp(sp,"ALIAS") || !strcmp(sp,"NAME"))
		return(useron.alias);
508

509
	if(!strcmp(sp,"FIRST")) {
510
		safe_snprintf(str,maxlen,"%s",useron.alias);
511
		tp=strchr(str,' ');
512
		if(tp) *tp=0;
513
		return(str);
514
	}
515

516
	if(!strcmp(sp,"USERNUM")) {
517
		safe_snprintf(str,maxlen,"%u",useron.number);
518
519
		return(str);
	}
520

521
	if(!strcmp(sp,"PHONE") || !strcmp(sp,"HOMEPHONE")
522
		|| !strcmp(sp,"DATAPHONE") || !strcmp(sp,"DATA"))
523
		return(useron.phone);
524

525
526
	if(!strcmp(sp,"ADDR1"))
		return(useron.address);
527

528
529
	if(!strcmp(sp,"FROM"))
		return(useron.location);
530

531
	if(!strcmp(sp,"CITY")) {
532
		safe_snprintf(str,maxlen,"%s",useron.location);
533
		char* p=strchr(str,',');
534
535
		if(p) {
			*p=0;
536
537
			return(str);
		}
538
539
		return(nulstr);
	}
540

541
542
	if(!strcmp(sp,"STATE")) {
		char* p=strchr(useron.location,',');
543
544
		if(p) {
			p++;
545
			if(*p==' ')
546
				p++;
547
548
			return(p);
		}
549
550
		return(nulstr);
	}
551

552
553
	if(!strcmp(sp,"CPU"))
		return(useron.comp);
554

555
556
	if(!strcmp(sp,"HOST"))
		return(client_name);
557

558
559
	if(!strcmp(sp,"BDATE"))
		return(useron.birth);
560

561
	if(!strcmp(sp,"AGE")) {
562
		safe_snprintf(str,maxlen,"%u",getage(&cfg,useron.birth));
563
564
		return(str);
	}
rswindell's avatar
rswindell committed
565

566
	if(!strcmp(sp,"CALLS") || !strcmp(sp,"NUMTIMESON")) {
567
		safe_snprintf(str,maxlen,"%u",useron.logons);
568
569
		return(str);
	}
570

571
572
	if(!strcmp(sp,"MEMO"))
		return(unixtodstr(&cfg,useron.pwmod,str));
573

574
	if(!strcmp(sp,"SEC") || !strcmp(sp,"SECURITY")) {
575
		safe_snprintf(str,maxlen,"%u",useron.level);
576
577
		return(str);
	}
578

579
580
	if(!strcmp(sp,"SINCE"))
		return(unixtodstr(&cfg,useron.firston,str));
581

582
	if(!strcmp(sp,"TIMEON") || !strcmp(sp,"TIMEUSED")) {
583
		now=time(NULL);
584
		safe_snprintf(str,maxlen,"%lu",(ulong)(now-logontime)/60L);
585
586
		return(str);
	}
587

588
	if(!strcmp(sp,"TUSED")) {              /* Synchronet only */
589
		now=time(NULL);
590
		return(sectostr((uint)(now-logontime),str)+1);
591
	}
592

593
	if(!strcmp(sp,"TLEFT")) {              /* Synchronet only */
594
		gettimeleft();
595
		return(sectostr(timeleft,str)+1);
596
	}
597

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

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

604
	if(!strcmp(sp,"TIMELIMIT")) {
605
		safe_snprintf(str,maxlen,"%u",cfg.level_timepercall[useron.level]);
606
607
		return(str);
	}
608

609
	if(!strcmp(sp,"MINLEFT") || !strcmp(sp,"LEFT") || !strcmp(sp,"TIMELEFT")) {
610
		gettimeleft();
611
		safe_snprintf(str,maxlen,"%lu",timeleft/60);
612
613
		return(str);
	}
614

615
	if(!strcmp(sp,"LASTON"))
616
		return(timestr(useron.laston));
617

618
619
	if(!strcmp(sp,"LASTDATEON"))
		return(unixtodstr(&cfg,useron.laston,str));
620

621
	if(!strcmp(sp,"LASTTIMEON")) {
622
		memset(&tm,0,sizeof(tm));
623
		localtime32(&useron.laston,&tm);
624
625
626
627
628
629
630
631
		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");
632
		return(str);
633
634
	}

635
	if(!strcmp(sp,"MSGLEFT") || !strcmp(sp,"MSGSLEFT")) {
636
		safe_snprintf(str,maxlen,"%u",useron.posts);
637
638
		return(str);
	}
639

640
	if(!strcmp(sp,"MSGREAD")) {
641
		safe_snprintf(str,maxlen,"%lu",posts_read);
642
643
		return(str);
	}
644

645
	if(!strcmp(sp,"FREESPACE")) {
646
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,0));
647
648
649
650
		return(str);
	}

	if(!strcmp(sp,"FREESPACEK")) {
651
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,1024));
652
653
		return(str);
	}
654

655
	if(!strcmp(sp,"UPBYTES")) {
656
		safe_snprintf(str,maxlen,"%lu",useron.ulb);
657
658
		return(str);
	}
659

660
	if(!strcmp(sp,"UPK")) {
661
		safe_snprintf(str,maxlen,"%lu",useron.ulb/1024L);
662
663
		return(str);
	}
664

665
	if(!strcmp(sp,"UPS") || !strcmp(sp,"UPFILES")) {
666
		safe_snprintf(str,maxlen,"%u",useron.uls);
667
668
		return(str);
	}
669

670
	if(!strcmp(sp,"DLBYTES")) {
671
		safe_snprintf(str,maxlen,"%lu",useron.dlb);
672
673
		return(str);
	}
674

675
	if(!strcmp(sp,"DOWNK")) {
676
		safe_snprintf(str,maxlen,"%lu",useron.dlb/1024L);
677
678
		return(str);
	}
679

680
	if(!strcmp(sp,"DOWNS") || !strcmp(sp,"DLFILES")) {
681
		safe_snprintf(str,maxlen,"%u",useron.dls);
682
683
		return(str);
	}
684

685
	if(!strcmp(sp,"LASTNEW"))
686
		return(unixtodstr(&cfg,(time32_t)ns_time,str));
687

688
	if(!strcmp(sp,"NEWFILETIME"))
689
		return(timestr(ns_time));
690
691
692

	/* MAXDL */

693
	if(!strcmp(sp,"MAXDK") || !strcmp(sp,"DLKLIMIT") || !strcmp(sp,"KBLIMIT")) {
694
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]/1024L);
695
696
		return(str);
	}
697

698
	if(!strcmp(sp,"DAYBYTES")) {    /* amt of free cdts used today */
699
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]-useron.freecdt);
700
701
		return(str);
	}
702

703
	if(!strcmp(sp,"BYTELIMIT")) {
704
		safe_snprintf(str,maxlen,"%ld", (long)cfg.level_freecdtperday[useron.level]);
705
706
		return(str);
	}
707

708
	if(!strcmp(sp,"KBLEFT")) {
709
		safe_snprintf(str,maxlen,"%lu",(useron.cdt+useron.freecdt)/1024L);
710
711
		return(str);
	}
712

713
	if(!strcmp(sp,"BYTESLEFT")) {
714
		safe_snprintf(str,maxlen,"%lu",useron.cdt+useron.freecdt);
715
716
		return(str);
	}
717

718
	if(!strcmp(sp,"CONF")) {
719
		safe_snprintf(str,maxlen,"%s %s"
720
721
			,usrgrps ? cfg.grp[usrgrp[curgrp]]->sname :nulstr
			,usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr);
722
723
		return(str);
	}
724

725
	if(!strcmp(sp,"CONFNUM")) {
726
		safe_snprintf(str,maxlen,"%u %u",curgrp+1,cursub[curgrp]+1);
727
728
		return(str);
	}
729

730
	if(!strcmp(sp,"NUMDIR")) {
731
		safe_snprintf(str,maxlen,"%u %u",usrlibs ? curlib+1 : 0,usrlibs ? curdir[curlib]+1 : 0);
732
733
		return(str);
	}
734

735
736
	if(!strcmp(sp,"EXDATE") || !strcmp(sp,"EXPDATE"))
		return(unixtodstr(&cfg,useron.expire,str));
737

738
	if(!strcmp(sp,"EXPDAYS")) {
739
		now=time(NULL);
740
		l=(long)(useron.expire-now);
741
742
		if(l<0)
			l=0;
743
		safe_snprintf(str,maxlen,"%lu",l/(1440L*60L));
744
745
		return(str);
	}
746

747
748
	if(!strcmp(sp,"MEMO1"))
		return(useron.note);
749

750
751
	if(!strcmp(sp,"MEMO2") || !strcmp(sp,"COMPANY"))
		return(useron.name);
752

753
754
	if(!strcmp(sp,"ZIP"))
		return(useron.zipcode);
755

756
	if(!strcmp(sp,"HANGUP")) {
757
		hangup();
758
759
		return(nulstr);
	}
760
761
762

	/* Synchronet Specific */

763
	if(!strncmp(sp,"SETSTR:",7)) {
764
		strcpy(main_csi.str,sp+7);
765
766
		return(nulstr);
	}
767

768
	if(!strncmp(sp,"EXEC:",5)) {
769
		exec_bin(sp+5,&main_csi);
770
771
		return(nulstr);
	}
772

773
	if(!strncmp(sp,"EXEC_XTRN:",10)) {
774
		for(i=0;i<cfg.total_xtrns;i++)
775
			if(!stricmp(cfg.xtrn[i]->code,sp+10))
776
777
778
779
780
781
				break;
		if(i<cfg.total_xtrns)
			exec_xtrn(i);
		return(nulstr);
	}

782
	if(!strncmp(sp,"MENU:",5)) {
783
		menu(sp+5);
784
785
		return(nulstr);
	}
786

787
788
789
790
791
	if(!strncmp(sp,"CONDMENU:",9)) {
		menu(sp+9, P_NOERROR);
		return(nulstr);
	}

792
793
794
795
	if(!strncmp(sp,"TYPE:",5)) {
		printfile(cmdstr(sp+5,nulstr,nulstr,str),0);
		return(nulstr);
	}
796

797
	if(!strncmp(sp,"INCLUDE:",8)) {
798
		printfile(cmdstr(sp+8,nulstr,nulstr,str),P_NOCRLF|P_SAVEATR);
799
800
801
		return(nulstr);
	}

802
803
	if(!strcmp(sp,"QUESTION"))
		return(question);
804

805
806
	if(!strcmp(sp,"HANDLE"))
		return(useron.handle);
807

808
809
	if(!strcmp(sp,"CID") || !strcmp(sp,"IP"))
		return(cid);
810

deuce's avatar
deuce committed
811
812
	if(!strcmp(sp,"LOCAL-IP"))
		return(local_addr);
813