atcodes.cpp 33.4 KB
Newer Older
1
2
3
4
5
6
7
8
/* Synchronet "@code" functions */

/* $Id$ */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
9
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
10
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
41
42
43
44
45
#if defined(_WINSOCKAPI_)
	extern WSADATA WSAData;
	#define SOCKLIB_DESC WSAData.szDescription
#else
	#define	SOCKLIB_DESC NULL
#endif

46
47
48
/****************************************************************************/
/* Returns 0 if invalid @ code. Returns length of @ code if valid.          */
/****************************************************************************/
49
int sbbs_t::show_atcode(const char *instr)
50
{
51
	char	str[128],str2[128],*tp,*sp,*p;
52
    int     len;
53
	int		disp_len;
54
55
	bool	padded_left=false;
	bool	padded_right=false;
56
	bool	centered=false;
57
	bool	zero_padded=false;
58
	const char *cp;
59

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

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

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

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

	return(len);
}

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

	str[0]=0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

238
239
	if(!strcmp(sp,"INETADDR"))
		return(cfg.sys_inetaddr);
240

241
242
243
	if(!strcmp(sp,"HOSTNAME"))
		return(startup->host_name);

244
	if(!strcmp(sp,"FIDOADDR")) {
245
		if(cfg.total_faddrs)
246
			return(smb_faddrtoa(&cfg.faddr[0],str));
247
		return(nulstr);
248
249
	}

250
	if(!strcmp(sp,"EMAILADDR"))
251
		return(usermailaddr(&cfg, str
252
			,cfg.inetmail_misc&NMAIL_ALIAS ? useron.alias : useron.name));
253

254
255
	if(!strcmp(sp,"QWKID"))
		return(cfg.sys_id);
256

257
	if(!strcmp(sp,"TIME") || !strcmp(sp,"SYSTIME")) {
258
		now=time(NULL);
259
		memset(&tm,0,sizeof(tm));
260
		localtime_r(&now,&tm);
261
		if(cfg.sys_misc&SM_MILITARY)
262
263
			safe_snprintf(str,maxlen,"%02d:%02d:%02d"
		        	,tm.tm_hour,tm.tm_min,tm.tm_sec);
264
		else
265
			safe_snprintf(str,maxlen,"%02d:%02d %s"
266
267
268
				,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");
269
		return(str);
270
271
	}

rswindell's avatar
rswindell committed
272
273
274
	if(!strcmp(sp,"TIMEZONE"))
		return(smb_zonestr(sys_timezone(&cfg),str));

275
	if(!strcmp(sp,"DATE") || !strcmp(sp,"SYSDATE")) {
276
		return(unixtodstr(&cfg,time32(NULL),str));
277
	}
278

rswindell's avatar
rswindell committed
279
280
281
	if(!strcmp(sp,"DATETIME"))
		return(timestr(time(NULL)));

282
	if(!strcmp(sp,"TMSG")) {
283
284
		l=0;
		for(i=0;i<cfg.total_subs;i++)
285
			l+=getposts(&cfg,i); 		/* l=total posts */
286
		safe_snprintf(str,maxlen,"%lu",l);
287
288
		return(str);
	}
289

290
	if(!strcmp(sp,"TUSER")) {
291
		safe_snprintf(str,maxlen,"%u",total_users(&cfg));
292
293
		return(str);
	}
294

295
	if(!strcmp(sp,"TFILE")) {
296
297
		l=0;
		for(i=0;i<cfg.total_dirs;i++)
298
			l+=getfiles(&cfg,i);
299
		safe_snprintf(str,maxlen,"%lu",l);
300
301
		return(str);
	}
302

303
	if(!strcmp(sp,"TCALLS") || !strcmp(sp,"NUMCALLS")) {
304
		getstats(&cfg,0,&stats);
305
		safe_snprintf(str,maxlen,"%lu",stats.logons);
306
307
		return(str);
	}
308

309
	if(!strcmp(sp,"PREVON") || !strcmp(sp,"LASTCALLERNODE")
310
		|| !strcmp(sp,"LASTCALLERSYSTEM"))
311
		return(lastuseron);
312

rswindell's avatar
rswindell committed
313
	if(!strcmp(sp,"CLS") || !strcmp(sp,"CLEAR")) {
314
		CLS;
315
316
		return(nulstr);
	}
317

318
	if(!strcmp(sp,"PAUSE") || !strcmp(sp,"MORE")) {
319
		pause();
320
321
		return(nulstr);
	}
322

323
	if(!strcmp(sp,"RESETPAUSE")) {
324
		lncntr=0;
325
326
		return(nulstr);
	}
327

328
	if(!strcmp(sp,"NOPAUSE") || !strcmp(sp,"POFF")) {
329
		sys_status^=SS_PAUSEOFF;
330
331
		return(nulstr);
	}
332

333
	if(!strcmp(sp,"PON") || !strcmp(sp,"AUTOMORE")) {
334
		sys_status^=SS_PAUSEON;
335
336
		return(nulstr);
	}
337
338
339
340
341

	/* NOSTOP */

	/* STOP */

342
343
	if(!strcmp(sp,"BELL") || !strcmp(sp,"BEEP"))
		return("\a");
344

345
346
347
	if(!strcmp(sp,"EVENT")) {
		if(event_time==0)
			return("<none>");
348
		return(timestr(event_time));
349
	}
350
351
352

	/* LASTCALL */

353
	if(!strncmp(sp,"NODE",4)) {
354
355
356
		i=atoi(sp+4);
		if(i && i<=cfg.sys_nodes) {
			getnodedat(i,&node,0);
357
358
			printnodedat(i,&node);
		}
359
360
		return(nulstr);
	}
361

362
	if(!strcmp(sp,"WHO")) {
363
		whos_online(true);
364
365
		return(nulstr);
	}
366
367
368

	/* User Codes */

369
370
	if(!strcmp(sp,"USER") || !strcmp(sp,"ALIAS") || !strcmp(sp,"NAME"))
		return(useron.alias);
371

372
	if(!strcmp(sp,"FIRST")) {
373
		safe_snprintf(str,maxlen,"%s",useron.alias);
374
		tp=strchr(str,' ');
375
		if(tp) *tp=0;
376
		return(str);
377
	}
378

379
	if(!strcmp(sp,"USERNUM")) {
380
		safe_snprintf(str,maxlen,"%u",useron.number);
381
382
		return(str);
	}
383

384
	if(!strcmp(sp,"PHONE") || !strcmp(sp,"HOMEPHONE")
385
		|| !strcmp(sp,"DATAPHONE") || !strcmp(sp,"DATA"))
386
		return(useron.phone);
387

388
389
	if(!strcmp(sp,"ADDR1"))
		return(useron.address);
390

391
392
	if(!strcmp(sp,"FROM"))
		return(useron.location);
393

394
	if(!strcmp(sp,"CITY")) {
395
		safe_snprintf(str,maxlen,"%s",useron.location);
396
		char* p=strchr(str,',');
397
398
		if(p) {
			*p=0;
399
400
			return(str);
		}
401
402
		return(nulstr);
	}
403

404
405
	if(!strcmp(sp,"STATE")) {
		char* p=strchr(useron.location,',');
406
407
		if(p) {
			p++;
408
			if(*p==' ')
409
				p++;
410
411
			return(p);
		}
412
413
		return(nulstr);
	}
414

415
416
	if(!strcmp(sp,"CPU"))
		return(useron.comp);
417

418
419
	if(!strcmp(sp,"HOST"))
		return(client_name);
420

421
422
	if(!strcmp(sp,"BDATE"))
		return(useron.birth);
423

424
	if(!strcmp(sp,"AGE")) {
425
		safe_snprintf(str,maxlen,"%u",getage(&cfg,useron.birth));
426
427
		return(str);
	}
rswindell's avatar
rswindell committed
428

429
	if(!strcmp(sp,"CALLS") || !strcmp(sp,"NUMTIMESON")) {
430
		safe_snprintf(str,maxlen,"%u",useron.logons);
431
432
		return(str);
	}
433

434
435
	if(!strcmp(sp,"MEMO"))
		return(unixtodstr(&cfg,useron.pwmod,str));
436

437
	if(!strcmp(sp,"SEC") || !strcmp(sp,"SECURITY")) {
438
		safe_snprintf(str,maxlen,"%u",useron.level);
439
440
		return(str);
	}
441

442
443
	if(!strcmp(sp,"SINCE"))
		return(unixtodstr(&cfg,useron.firston,str));
444

445
	if(!strcmp(sp,"TIMEON") || !strcmp(sp,"TIMEUSED")) {
446
		now=time(NULL);
447
		safe_snprintf(str,maxlen,"%lu",(ulong)(now-logontime)/60L);
448
449
		return(str);
	}
450

451
	if(!strcmp(sp,"TUSED")) {              /* Synchronet only */
452
		now=time(NULL);
453
		return(sectostr((uint)(now-logontime),str)+1);
454
	}
455

456
	if(!strcmp(sp,"TLEFT")) {              /* Synchronet only */
457
		gettimeleft();
458
		return(sectostr(timeleft,str)+1);
459
	}
460

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

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

467
	if(!strcmp(sp,"TIMELIMIT")) {
468
		safe_snprintf(str,maxlen,"%u",cfg.level_timepercall[useron.level]);
469
470
		return(str);
	}
471

472
	if(!strcmp(sp,"MINLEFT") || !strcmp(sp,"LEFT") || !strcmp(sp,"TIMELEFT")) {
473
		gettimeleft();
474
		safe_snprintf(str,maxlen,"%lu",timeleft/60);
475
476
		return(str);
	}
477

478
	if(!strcmp(sp,"LASTON"))
479
		return(timestr(useron.laston));
480

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

484
	if(!strcmp(sp,"LASTTIMEON")) {
485
		memset(&tm,0,sizeof(tm));
486
		localtime32(&useron.laston,&tm);
487
488
489
490
491
492
493
494
		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");
495
		return(str);
496
497
	}

498
	if(!strcmp(sp,"MSGLEFT") || !strcmp(sp,"MSGSLEFT")) {
499
		safe_snprintf(str,maxlen,"%u",useron.posts);
500
501
		return(str);
	}
502

503
	if(!strcmp(sp,"MSGREAD")) {
504
		safe_snprintf(str,maxlen,"%lu",posts_read);
505
506
		return(str);
	}
507

508
	if(!strcmp(sp,"FREESPACE")) {
509
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,0));
510
511
512
513
		return(str);
	}

	if(!strcmp(sp,"FREESPACEK")) {
514
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,1024));
515
516
		return(str);
	}
517

518
	if(!strcmp(sp,"UPBYTES")) {
519
		safe_snprintf(str,maxlen,"%lu",useron.ulb);
520
521
		return(str);
	}
522

523
	if(!strcmp(sp,"UPK")) {
524
		safe_snprintf(str,maxlen,"%lu",useron.ulb/1024L);
525
526
		return(str);
	}
527

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

533
	if(!strcmp(sp,"DLBYTES")) {
534
		safe_snprintf(str,maxlen,"%lu",useron.dlb);
535
536
		return(str);
	}
537

538
	if(!strcmp(sp,"DOWNK")) {
539
		safe_snprintf(str,maxlen,"%lu",useron.dlb/1024L);
540
541
		return(str);
	}
542

543
	if(!strcmp(sp,"DOWNS") || !strcmp(sp,"DLFILES")) {
544
		safe_snprintf(str,maxlen,"%u",useron.dls);
545
546
		return(str);
	}
547

548
	if(!strcmp(sp,"LASTNEW"))
549
		return(unixtodstr(&cfg,(time32_t)ns_time,str));
550

551
	if(!strcmp(sp,"NEWFILETIME"))
552
		return(timestr(ns_time));
553
554
555

	/* MAXDL */

556
	if(!strcmp(sp,"MAXDK") || !strcmp(sp,"DLKLIMIT") || !strcmp(sp,"KBLIMIT")) {
557
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]/1024L);
558
559
		return(str);
	}
560

561
	if(!strcmp(sp,"DAYBYTES")) {    /* amt of free cdts used today */
562
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]-useron.freecdt);
563
564
		return(str);
	}
565

566
	if(!strcmp(sp,"BYTELIMIT")) {
567
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]);
568
569
		return(str);
	}
570

571
	if(!strcmp(sp,"KBLEFT")) {
572
		safe_snprintf(str,maxlen,"%lu",(useron.cdt+useron.freecdt)/1024L);
573
574
		return(str);
	}
575

576
	if(!strcmp(sp,"BYTESLEFT")) {
577
		safe_snprintf(str,maxlen,"%lu",useron.cdt+useron.freecdt);
578
579
		return(str);
	}
580

581
	if(!strcmp(sp,"CONF")) {
582
		safe_snprintf(str,maxlen,"%s %s"
583
584
			,usrgrps ? cfg.grp[usrgrp[curgrp]]->sname :nulstr
			,usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr);
585
586
		return(str);
	}
587

588
	if(!strcmp(sp,"CONFNUM")) {
589
		safe_snprintf(str,maxlen,"%u %u",curgrp+1,cursub[curgrp]+1);
590
591
		return(str);
	}
592

593
	if(!strcmp(sp,"NUMDIR")) {
594
		safe_snprintf(str,maxlen,"%u %u",usrlibs ? curlib+1 : 0,usrlibs ? curdir[curlib]+1 : 0);
595
596
		return(str);
	}
597

598
599
	if(!strcmp(sp,"EXDATE") || !strcmp(sp,"EXPDATE"))
		return(unixtodstr(&cfg,useron.expire,str));
600

601
	if(!strcmp(sp,"EXPDAYS")) {
602
		now=time(NULL);
603
		l=(long)(useron.expire-now);
604
605
		if(l<0)
			l=0;
606
		safe_snprintf(str,maxlen,"%lu",l/(1440L*60L));
607
608
		return(str);
	}
609

610
611
	if(!strcmp(sp,"MEMO1"))
		return(useron.note);
612

613
614
	if(!strcmp(sp,"MEMO2") || !strcmp(sp,"COMPANY"))
		return(useron.name);
615

616
617
	if(!strcmp(sp,"ZIP"))
		return(useron.zipcode);
618

619
	if(!strcmp(sp,"HANGUP")) {
620
		hangup();
621
622
		return(nulstr);
	}
623
624
625

	/* Synchronet Specific */

626
	if(!strncmp(sp,"SETSTR:",7)) {
627
		strcpy(main_csi.str,sp+7);
628
629
		return(nulstr);
	}
630

631
	if(!strncmp(sp,"EXEC:",5)) {
632
		exec_bin(sp+5,&main_csi);
633
634
		return(nulstr);
	}
635

636
	if(!strncmp(sp,"EXEC_XTRN:",10)) {
637
		for(i=0;i<cfg.total_xtrns;i++)
638
			if(!stricmp(cfg.xtrn[i]->code,sp+10))
639
640
641
642
643
644
				break;
		if(i<cfg.total_xtrns)
			exec_xtrn(i);
		return(nulstr);
	}

645
	if(!strncmp(sp,"MENU:",5)) {
646
		menu(sp+5);
647
648
		return(nulstr);
	}
649

650
651
652
653
654
	if(!strncmp(sp,"CONDMENU:",9)) {
		menu(sp+9, P_NOERROR);
		return(nulstr);
	}

655
656
657
658
	if(!strncmp(sp,"TYPE:",5)) {
		printfile(cmdstr(sp+5,nulstr,nulstr,str),0);
		return(nulstr);
	}
659

660
	if(!strncmp(sp,"INCLUDE:",8)) {
661
		printfile(cmdstr(sp+8,nulstr,nulstr,str),P_NOCRLF|P_SAVEATR);
662
663
664
		return(nulstr);
	}

665
666
	if(!strcmp(sp,"QUESTION"))
		return(question);
667

668
669
	if(!strcmp(sp,"HANDLE"))
		return(useron.handle);
670

671
672
	if(!strcmp(sp,"CID") || !strcmp(sp,"IP"))
		return(cid);
673

deuce's avatar
deuce committed
674
675
	if(!strcmp(sp,"LOCAL-IP"))
		return(local_addr);
676

677
678
	if(!strcmp(sp,"CRLF"))
		return("\r\n");
679

680
	if(!strcmp(sp,"PUSHXY")) {
681
		ansi_save();
682
683
		return(nulstr);
	}
684

685
	if(!strcmp(sp,"POPXY")) {
686
		ansi_restore();
687
688
		return(nulstr);
	}
689

rswindell's avatar
rswindell committed
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
	if(!strcmp(sp,"HOME")) {
		cursor_home();
		return(nulstr);
	}

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

	if(!strcmp(sp,"CLR2EOL")) {
		cleartoeol();
		return(nulstr);
	}

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

710
	if(!strncmp(sp,"UP:",3)) {
711
		cursor_up(atoi(sp+3));
712
713
		return(str);
	}
714

715
	if(!strncmp(sp,"DOWN:",5)) {
716
		cursor_down(atoi(sp+5));
717
718
		return(str);
	}
719

720
	if(!strncmp(sp,"LEFT:",5)) {
721
		cursor_left(atoi(sp+5));
722
723
		return(str);
	}
724

725
	if(!strncmp(sp,"RIGHT:",6)) {
726
		cursor_right(atoi(sp+6));
727
728
		return(str);
	}
729

730
	if(!strncmp(sp,"GOTOXY:",7)) {
731
732
733
		tp=strchr(sp,',');
		if(tp!=NULL) {
			tp++;
734
			ansi_gotoxy(atoi(sp+7),atoi(tp));
735
		}
736
		return(nulstr);
737
738
	}

739
740
741
742
743
744
745
	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);
		}
746
		return(usrgrps ? cfg.grp[usrgrp[curgrp]]->sname : nulstr);
747
	}
748

749
750
751
752
753
754
755
	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);
		}
756
		return(usrgrps ? cfg.grp[usrgrp[curgrp]]->lname : nulstr);
757
	}
758

759
	if(!strcmp(sp,"GN")) {
760
761
		if(SMB_IS_OPEN(&smb))
			ugrp=getusrgrp(smb.subnum);
762
		else
763
			ugrp=usrgrps ? curgrp+1 : 0;
764
		safe_snprintf(str,maxlen,"%u",ugrp);
765
766
		return(str);
	}
767

768
	if(!strcmp(sp,"GL")) {
769
770
		if(SMB_IS_OPEN(&smb))
			ugrp=getusrgrp(smb.subnum);
771
		else
772
			ugrp=usrgrps ? curgrp+1 : 0;
773
		safe_snprintf(str,maxlen,"%-4u",ugrp);