atcodes.cpp 34.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
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;
59
	const char *cp;
60

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

72
	disp_len=len;
73
74
75
76
	if((p=strstr(sp,"-L"))!=NULL)
		padded_left=true;
	else if((p=strstr(sp,"-R"))!=NULL)
		padded_right=true;
77
78
	else if((p=strstr(sp,"-C"))!=NULL)
		centered=true;
79
80
	else if((p=strstr(sp,"-Z"))!=NULL)
		zero_padded=true;
81
82
83
	if(p!=NULL) {
		if(*(p+2) && isdigit(*(p+2)))
			disp_len=atoi(p+2);
84
		*p=0;
85
	}
86

87
88
	cp=atcode(sp,str2,sizeof(str2));
	if(cp==NULL)
89
90
91
		return(0);

	if(padded_left)
92
		bprintf("%-*.*s",disp_len,disp_len,cp);
93
	else if(padded_right)
94
		bprintf("%*.*s",disp_len,disp_len,cp);
95
	else if(centered) {
rswindell's avatar
rswindell committed
96
		int vlen = strlen(cp);
97
98
99
100
		if(vlen < disp_len) {
			int left = (disp_len - vlen) / 2;
			bprintf("%*s%-*s", left, "", disp_len - left, cp);
		} else
101
			bprintf("%.*s", disp_len, cp);
102
	} else if(zero_padded) {
103
104
		int vlen = strlen(cp);
		if(vlen < disp_len)
105
			bprintf("%-.*s%s", (int)(disp_len - strlen(cp)), "0000000000", cp);
106
107
		else
			bprintf("%.*s", disp_len, cp);
108
	} else
109
		bputs(cp);
110
111
112
113

	return(len);
}

114
const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen)
115
116
117
{
	char*	tp;
	uint	i;
118
119
	uint	ugrp;
	uint	usub;
120
121
122
123
124
125
126
	long	l;
    stats_t stats;
    node_t  node;
	struct	tm tm;

	str[0]=0;

127
	if(!strcmp(sp,"VER"))
128
		return(VERSION);
129

130
	if(!strcmp(sp,"REV")) {
131
		safe_snprintf(str,maxlen,"%c",REVISION);
132
133
		return(str);
	}
134

135
	if(!strcmp(sp,"FULL_VER")) {
136
		safe_snprintf(str,maxlen,"%s%c%s",VERSION,REVISION,beta_version);
137
		truncsp(str);
138
#if defined(_DEBUG)
139
		strcat(str," Debug");
140
#endif
141
		return(str);
142
143
	}

144
	if(!strcmp(sp,"VER_NOTICE"))
145
		return(VERSION_NOTICE);
146

147
148
	if(!strcmp(sp,"OS_VER"))
		return(os_version(str));
149
150

#ifdef JAVASCRIPT
151
152
	if(!strcmp(sp,"JS_VER"))
		return((char *)JS_GetImplementationVersion());
153
154
#endif

155
156
	if(!strcmp(sp,"PLATFORM"))
		return(PLATFORM_DESC);
157

158
159
	if(!strcmp(sp,"COPYRIGHT"))
		return(COPYRIGHT_NOTICE);
160

161
	if(!strcmp(sp,"COMPILER")) {
162
163
164
		char compiler[32];
		DESCRIBE_COMPILER(compiler);
		strncpy(str, compiler, maxlen);
165
		return(str);
166
167
	}

168
	if(!strcmp(sp,"UPTIME")) {
169
		extern volatile time_t uptime;
170
171
172
173
		time_t up=0;
		now = time(NULL);
		if (uptime != 0 && now >= uptime)
			up = now-uptime;
174
175
		char   days[64]="";
		if((up/(24*60*60))>=2) {
176
	        sprintf(days,"%lu days ",(ulong)(up/(24L*60L*60L)));
177
178
			up%=(24*60*60);
		}
179
		safe_snprintf(str,maxlen,"%s%lu:%02lu"
180
	        ,days
181
182
			,(ulong)(up/(60L*60L))
			,(ulong)((up/60L)%60L)
183
			);
184
		return(str);
185
186
	}

187
	if(!strcmp(sp,"SERVED")) {
188
		extern volatile ulong served;
189
		safe_snprintf(str,maxlen,"%lu",served);
190
191
192
		return(str);
	}

193
	if(!strcmp(sp,"SOCKET_LIB"))
194
		return(socklib_version(str,SOCKLIB_DESC));
195

196
	if(!strcmp(sp,"MSG_LIB")) {
197
		safe_snprintf(str,maxlen,"SMBLIB %s",smb_lib_ver());
198
199
		return(str);
	}
200

201
202
	if(!strcmp(sp,"BBS") || !strcmp(sp,"BOARDNAME"))
		return(cfg.sys_name);
203

204
	if(!strcmp(sp,"BAUD") || !strcmp(sp,"BPS")) {
205
		safe_snprintf(str,maxlen,"%lu",cur_rate);
206
207
		return(str);
	}
208

rswindell's avatar
rswindell committed
209
210
211
212
213
214
215
216
217
218
219
	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);

220
221
	if(!strcmp(sp,"CONN"))
		return(connection);
222

223
224
	if(!strcmp(sp,"SYSOP"))
		return(cfg.sys_op);
225

226
227
	if(!strcmp(sp,"LOCATION"))
		return(cfg.sys_location);
228

229
	if(!strcmp(sp,"NODE")) {
230
		safe_snprintf(str,maxlen,"%u",cfg.node_num);
231
232
		return(str);
	}
233

234
	if(!strcmp(sp,"TNODE")) {
235
		safe_snprintf(str,maxlen,"%u",cfg.sys_nodes);
236
237
		return(str);
	}
238

239
240
241
242
243
244
	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];

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

248
249
	if(!strcmp(sp,"INETADDR"))
		return(cfg.sys_inetaddr);
250

251
252
253
	if(!strcmp(sp,"HOSTNAME"))
		return(startup->host_name);

254
	if(!strcmp(sp,"FIDOADDR")) {
255
		if(cfg.total_faddrs)
256
			return(smb_faddrtoa(&cfg.faddr[0],str));
257
		return(nulstr);
258
259
	}

260
	if(!strcmp(sp,"EMAILADDR"))
261
		return(usermailaddr(&cfg, str
262
			,cfg.inetmail_misc&NMAIL_ALIAS ? useron.alias : useron.name));
263

264
265
	if(!strcmp(sp,"QWKID"))
		return(cfg.sys_id);
266

267
	if(!strcmp(sp,"TIME") || !strcmp(sp,"SYSTIME")) {
268
		now=time(NULL);
269
		memset(&tm,0,sizeof(tm));
270
		localtime_r(&now,&tm);
271
		if(cfg.sys_misc&SM_MILITARY)
272
273
			safe_snprintf(str,maxlen,"%02d:%02d:%02d"
		        	,tm.tm_hour,tm.tm_min,tm.tm_sec);
274
		else
275
			safe_snprintf(str,maxlen,"%02d:%02d %s"
276
277
278
				,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");
279
		return(str);
280
281
	}

rswindell's avatar
rswindell committed
282
283
284
	if(!strcmp(sp,"TIMEZONE"))
		return(smb_zonestr(sys_timezone(&cfg),str));

285
	if(!strcmp(sp,"DATE") || !strcmp(sp,"SYSDATE")) {
286
		return(unixtodstr(&cfg,time32(NULL),str));
287
	}
288

rswindell's avatar
rswindell committed
289
290
291
	if(!strcmp(sp,"DATETIME"))
		return(timestr(time(NULL)));

292
	if(!strcmp(sp,"TMSG")) {
293
294
		l=0;
		for(i=0;i<cfg.total_subs;i++)
295
			l+=getposts(&cfg,i); 		/* l=total posts */
296
		safe_snprintf(str,maxlen,"%lu",l);
297
298
		return(str);
	}
299

300
	if(!strcmp(sp,"TUSER")) {
301
		safe_snprintf(str,maxlen,"%u",total_users(&cfg));
302
303
		return(str);
	}
304

305
	if(!strcmp(sp,"TFILE")) {
306
307
		l=0;
		for(i=0;i<cfg.total_dirs;i++)
308
			l+=getfiles(&cfg,i);
309
		safe_snprintf(str,maxlen,"%lu",l);
310
311
		return(str);
	}
312

313
	if(!strcmp(sp,"TCALLS") || !strcmp(sp,"NUMCALLS")) {
314
		getstats(&cfg,0,&stats);
315
		safe_snprintf(str,maxlen,"%lu", (ulong)stats.logons);
316
317
		return(str);
	}
318

319
	if(!strcmp(sp,"PREVON") || !strcmp(sp,"LASTCALLERNODE")
320
		|| !strcmp(sp,"LASTCALLERSYSTEM"))
321
		return(lastuseron);
322

rswindell's avatar
rswindell committed
323
	if(!strcmp(sp,"CLS") || !strcmp(sp,"CLEAR")) {
324
		CLS;
325
326
		return(nulstr);
	}
327

328
	if(!strcmp(sp,"PAUSE") || !strcmp(sp,"MORE")) {
329
		pause();
330
331
		return(nulstr);
	}
332

333
	if(!strcmp(sp,"RESETPAUSE")) {
334
		lncntr=0;
335
336
		return(nulstr);
	}
337

338
	if(!strcmp(sp,"NOPAUSE") || !strcmp(sp,"POFF")) {
339
		sys_status^=SS_PAUSEOFF;
340
341
		return(nulstr);
	}
342

343
	if(!strcmp(sp,"PON") || !strcmp(sp,"AUTOMORE")) {
344
		sys_status^=SS_PAUSEON;
345
346
		return(nulstr);
	}
347

348
349
350
351
352
	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--)
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
			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;
	}

377
378
379
380
	/* NOSTOP */

	/* STOP */

381
382
	if(!strcmp(sp,"BELL") || !strcmp(sp,"BEEP"))
		return("\a");
383

384
385
386
	if(!strcmp(sp,"EVENT")) {
		if(event_time==0)
			return("<none>");
387
		return(timestr(event_time));
388
	}
389
390
391

	/* LASTCALL */

392
	if(!strncmp(sp,"NODE",4)) {
393
394
395
		i=atoi(sp+4);
		if(i && i<=cfg.sys_nodes) {
			getnodedat(i,&node,0);
396
397
			printnodedat(i,&node);
		}
398
399
		return(nulstr);
	}
400

401
	if(!strcmp(sp,"WHO")) {
402
		whos_online(true);
403
404
		return(nulstr);
	}
405
406
407

	/* User Codes */

408
409
	if(!strcmp(sp,"USER") || !strcmp(sp,"ALIAS") || !strcmp(sp,"NAME"))
		return(useron.alias);
410

411
	if(!strcmp(sp,"FIRST")) {
412
		safe_snprintf(str,maxlen,"%s",useron.alias);
413
		tp=strchr(str,' ');
414
		if(tp) *tp=0;
415
		return(str);
416
	}
417

418
	if(!strcmp(sp,"USERNUM")) {
419
		safe_snprintf(str,maxlen,"%u",useron.number);
420
421
		return(str);
	}
422

423
	if(!strcmp(sp,"PHONE") || !strcmp(sp,"HOMEPHONE")
424
		|| !strcmp(sp,"DATAPHONE") || !strcmp(sp,"DATA"))
425
		return(useron.phone);
426

427
428
	if(!strcmp(sp,"ADDR1"))
		return(useron.address);
429

430
431
	if(!strcmp(sp,"FROM"))
		return(useron.location);
432

433
	if(!strcmp(sp,"CITY")) {
434
		safe_snprintf(str,maxlen,"%s",useron.location);
435
		char* p=strchr(str,',');
436
437
		if(p) {
			*p=0;
438
439
			return(str);
		}
440
441
		return(nulstr);
	}
442

443
444
	if(!strcmp(sp,"STATE")) {
		char* p=strchr(useron.location,',');
445
446
		if(p) {
			p++;
447
			if(*p==' ')
448
				p++;
449
450
			return(p);
		}
451
452
		return(nulstr);
	}
453

454
455
	if(!strcmp(sp,"CPU"))
		return(useron.comp);
456

457
458
	if(!strcmp(sp,"HOST"))
		return(client_name);
459

460
461
	if(!strcmp(sp,"BDATE"))
		return(useron.birth);
462

463
	if(!strcmp(sp,"AGE")) {
464
		safe_snprintf(str,maxlen,"%u",getage(&cfg,useron.birth));
465
466
		return(str);
	}
rswindell's avatar
rswindell committed
467

468
	if(!strcmp(sp,"CALLS") || !strcmp(sp,"NUMTIMESON")) {
469
		safe_snprintf(str,maxlen,"%u",useron.logons);
470
471
		return(str);
	}
472

473
474
	if(!strcmp(sp,"MEMO"))
		return(unixtodstr(&cfg,useron.pwmod,str));
475

476
	if(!strcmp(sp,"SEC") || !strcmp(sp,"SECURITY")) {
477
		safe_snprintf(str,maxlen,"%u",useron.level);
478
479
		return(str);
	}
480

481
482
	if(!strcmp(sp,"SINCE"))
		return(unixtodstr(&cfg,useron.firston,str));
483

484
	if(!strcmp(sp,"TIMEON") || !strcmp(sp,"TIMEUSED")) {
485
		now=time(NULL);
486
		safe_snprintf(str,maxlen,"%lu",(ulong)(now-logontime)/60L);
487
488
		return(str);
	}
489

490
	if(!strcmp(sp,"TUSED")) {              /* Synchronet only */
491
		now=time(NULL);
492
		return(sectostr((uint)(now-logontime),str)+1);
493
	}
494

495
	if(!strcmp(sp,"TLEFT")) {              /* Synchronet only */
496
		gettimeleft();
497
		return(sectostr(timeleft,str)+1);
498
	}
499

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

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

506
	if(!strcmp(sp,"TIMELIMIT")) {
507
		safe_snprintf(str,maxlen,"%u",cfg.level_timepercall[useron.level]);
508
509
		return(str);
	}
510

511
	if(!strcmp(sp,"MINLEFT") || !strcmp(sp,"LEFT") || !strcmp(sp,"TIMELEFT")) {
512
		gettimeleft();
513
		safe_snprintf(str,maxlen,"%lu",timeleft/60);
514
515
		return(str);
	}
516

517
	if(!strcmp(sp,"LASTON"))
518
		return(timestr(useron.laston));
519

520
521
	if(!strcmp(sp,"LASTDATEON"))
		return(unixtodstr(&cfg,useron.laston,str));
522

523
	if(!strcmp(sp,"LASTTIMEON")) {
524
		memset(&tm,0,sizeof(tm));
525
		localtime32(&useron.laston,&tm);
526
527
528
529
530
531
532
533
		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");
534
		return(str);
535
536
	}

537
	if(!strcmp(sp,"MSGLEFT") || !strcmp(sp,"MSGSLEFT")) {
538
		safe_snprintf(str,maxlen,"%u",useron.posts);
539
540
		return(str);
	}
541

542
	if(!strcmp(sp,"MSGREAD")) {
543
		safe_snprintf(str,maxlen,"%lu",posts_read);
544
545
		return(str);
	}
546

547
	if(!strcmp(sp,"FREESPACE")) {
548
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,0));
549
550
551
552
		return(str);
	}

	if(!strcmp(sp,"FREESPACEK")) {
553
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,1024));
554
555
		return(str);
	}
556

557
	if(!strcmp(sp,"UPBYTES")) {
558
		safe_snprintf(str,maxlen,"%lu",useron.ulb);
559
560
		return(str);
	}
561

562
	if(!strcmp(sp,"UPK")) {
563
		safe_snprintf(str,maxlen,"%lu",useron.ulb/1024L);
564
565
		return(str);
	}
566

567
	if(!strcmp(sp,"UPS") || !strcmp(sp,"UPFILES")) {
568
		safe_snprintf(str,maxlen,"%u",useron.uls);
569
570
		return(str);
	}
571

572
	if(!strcmp(sp,"DLBYTES")) {
573
		safe_snprintf(str,maxlen,"%lu",useron.dlb);
574
575
		return(str);
	}
576

577
	if(!strcmp(sp,"DOWNK")) {
578
		safe_snprintf(str,maxlen,"%lu",useron.dlb/1024L);
579
580
		return(str);
	}
581

582
	if(!strcmp(sp,"DOWNS") || !strcmp(sp,"DLFILES")) {
583
		safe_snprintf(str,maxlen,"%u",useron.dls);
584
585
		return(str);
	}
586

587
	if(!strcmp(sp,"LASTNEW"))
588
		return(unixtodstr(&cfg,(time32_t)ns_time,str));
589

590
	if(!strcmp(sp,"NEWFILETIME"))
591
		return(timestr(ns_time));
592
593
594

	/* MAXDL */

595
	if(!strcmp(sp,"MAXDK") || !strcmp(sp,"DLKLIMIT") || !strcmp(sp,"KBLIMIT")) {
596
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]/1024L);
597
598
		return(str);
	}
599

600
	if(!strcmp(sp,"DAYBYTES")) {    /* amt of free cdts used today */
601
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]-useron.freecdt);
602
603
		return(str);
	}
604

605
	if(!strcmp(sp,"BYTELIMIT")) {
606
		safe_snprintf(str,maxlen,"%ld", (long)cfg.level_freecdtperday[useron.level]);
607
608
		return(str);
	}
609

610
	if(!strcmp(sp,"KBLEFT")) {
611
		safe_snprintf(str,maxlen,"%lu",(useron.cdt+useron.freecdt)/1024L);
612
613
		return(str);
	}
614

615
	if(!strcmp(sp,"BYTESLEFT")) {
616
		safe_snprintf(str,maxlen,"%lu",useron.cdt+useron.freecdt);
617
618
		return(str);
	}
619

620
	if(!strcmp(sp,"CONF")) {
621
		safe_snprintf(str,maxlen,"%s %s"
622
623
			,usrgrps ? cfg.grp[usrgrp[curgrp]]->sname :nulstr
			,usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr);
624
625
		return(str);
	}
626

627
	if(!strcmp(sp,"CONFNUM")) {
628
		safe_snprintf(str,maxlen,"%u %u",curgrp+1,cursub[curgrp]+1);
629
630
		return(str);
	}
631

632
	if(!strcmp(sp,"NUMDIR")) {
633
		safe_snprintf(str,maxlen,"%u %u",usrlibs ? curlib+1 : 0,usrlibs ? curdir[curlib]+1 : 0);
634
635
		return(str);
	}
636

637
638
	if(!strcmp(sp,"EXDATE") || !strcmp(sp,"EXPDATE"))
		return(unixtodstr(&cfg,useron.expire,str));
639

640
	if(!strcmp(sp,"EXPDAYS")) {
641
		now=time(NULL);
642
		l=(long)(useron.expire-now);
643
644
		if(l<0)
			l=0;
645
		safe_snprintf(str,maxlen,"%lu",l/(1440L*60L));
646
647
		return(str);
	}
648

649
650
	if(!strcmp(sp,"MEMO1"))
		return(useron.note);
651

652
653
	if(!strcmp(sp,"MEMO2") || !strcmp(sp,"COMPANY"))
		return(useron.name);
654

655
656
	if(!strcmp(sp,"ZIP"))
		return(useron.zipcode);
657

658
	if(!strcmp(sp,"HANGUP")) {
659
		hangup();
660
661
		return(nulstr);
	}
662
663
664

	/* Synchronet Specific */

665
	if(!strncmp(sp,"SETSTR:",7)) {
666
		strcpy(main_csi.str,sp+7);
667
668
		return(nulstr);
	}
669

670
	if(!strncmp(sp,"EXEC:",5)) {
671
		exec_bin(sp+5,&main_csi);
672
673
		return(nulstr);
	}
674

675
	if(!strncmp(sp,"EXEC_XTRN:",10)) {
676
		for(i=0;i<cfg.total_xtrns;i++)
677
			if(!stricmp(cfg.xtrn[i]->code,sp+10))
678
679
680
681
682
683
				break;
		if(i<cfg.total_xtrns)
			exec_xtrn(i);
		return(nulstr);
	}

684
	if(!strncmp(sp,"MENU:",5)) {
685
		menu(sp+5);
686
687
		return(nulstr);
	}
688

689
690
691
692
693
	if(!strncmp(sp,"CONDMENU:",9)) {
		menu(sp+9, P_NOERROR);
		return(nulstr);
	}

694
695
696
697
	if(!strncmp(sp,"TYPE:",5)) {
		printfile(cmdstr(sp+5,nulstr,nulstr,str),0);
		return(nulstr);
	}
698

699
	if(!strncmp(sp,"INCLUDE:",8)) {
700
		printfile(cmdstr(sp+8,nulstr,nulstr,str),P_NOCRLF|P_SAVEATR);
701
702
703
		return(nulstr);
	}

704
705
	if(!strcmp(sp,"QUESTION"))
		return(question);
706

707
708
	if(!strcmp(sp,"HANDLE"))
		return(useron.handle);
709

710
711
	if(!strcmp(sp,"CID") || !strcmp(sp,"IP"))
		return(cid);
712

deuce's avatar
deuce committed
713
714
	if(!strcmp(sp,"LOCAL-IP"))
		return(local_addr);
715

716
717
	if(!strcmp(sp,"CRLF"))
		return("\r\n");
718

719
	if(!strcmp(sp,"PUSHXY")) {
720
		ansi_save();
721
722
		return(nulstr);
	}
723

724
	if(!strcmp(sp,"POPXY")) {
725
		ansi_restore();
726
727
		return(nulstr);
	}
728

rswindell's avatar
rswindell committed
729
730
731
732
733
734
735
736
737
738
	if(!strcmp(sp,"HOME")) {
		cursor_home();
		return(nulstr);
	}

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

739
	if(!strcmp(sp,"CLR2EOL") || !strcmp(sp,"CLREOL")) {
rswindell's avatar
rswindell committed
740
741
742
743
744
745
746
747
748
		cleartoeol();
		return(nulstr);
	}

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

749
	if(!strncmp(sp,"UP:",3)) {
750
		cursor_up(atoi(sp+3));
751
752
		return(str);
	}
753

754
	if(!strncmp(sp,"DOWN:",5)) {
755
		cursor_down(atoi(sp+5));
756
757
		return(str);
	}
758

759
	if(!strncmp(sp,"LEFT:",5)) {
760
		cursor_left(atoi(sp+5));
761
762
		return(str);
	}
763

764
	if(!strncmp(sp,"RIGHT:",6)) {
765
		cursor_right(atoi(sp+6));
766
767
		return(str);
	}
768

769
	if(!strncmp(sp,"GOTOXY:",7)) {
770
771
772
		tp=strchr(sp,',');
		if(tp!=NULL) {
			tp++;
773
			ansi_gotoxy(atoi(sp+7),atoi(tp));
774
		}
775
		return(nulstr);
776
777
	}

778
779
780
781
782
783
784
	if(!strcmp(sp,"GRP")) {
		if(SMB_IS_OPEN(&smb)) {
			if(smb.subnum==INVALID_SUB)
				return("Local");
			if(smb.subnum<cfg.total_subs)
				return(cfg.grp[cfg.sub[smb.subnum]->grp]->sname);
		}
785
		return(usrgrps ? cfg.grp[usrgrp[curgrp]]->sname : nulstr);
786
	}
787

788
789
790
791
792
793
794
	if(!strcmp(sp,"GRPL")) {
		if(SMB_IS_OPEN(&smb)) {
			if(smb.subnum==INVALID_SUB)
				return("Local");
			if(smb.subnum<cfg.total_subs)
				return(cfg.grp[cfg.sub[smb.subnum]->grp]->lname);
		}
rswindell's avatar