atcodes.cpp 25.6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/* atcodes.cpp */

/* 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)		*
 *																			*
11
 * Copyright 2010 Rob Swindell - http://www.synchro.net/copyright.html		*
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
40
 *																			*
 * 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"

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

48
49
50
/****************************************************************************/
/* Returns 0 if invalid @ code. Returns length of @ code if valid.          */
/****************************************************************************/
51
int sbbs_t::show_atcode(const char *instr)
52
{
53
	char	str[128],str2[128],*tp,*sp,*p;
54
    int     len;
55
	int		disp_len;
56
57
	bool	padded_left=false;
	bool	padded_right=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
78
	if(p!=NULL) {
		if(*(p+2) && isdigit(*(p+2)))
			disp_len=atoi(p+2);
79
		*p=0;
80
	}
81

82
83
	cp=atcode(sp,str2,sizeof(str2));
	if(cp==NULL)
84
85
86
		return(0);

	if(padded_left)
87
		bprintf("%-*.*s",disp_len,disp_len,cp);
88
	else if(padded_right)
89
		bprintf("%*.*s",disp_len,disp_len,cp);
90
	else
91
		bputs(cp);
92
93
94
95

	return(len);
}

96
const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen)
97
98
99
{
	char*	tp;
	uint	i;
100
101
	uint	ugrp;
	uint	usub;
102
103
104
105
106
107
108
	long	l;
    stats_t stats;
    node_t  node;
	struct	tm tm;

	str[0]=0;

109
	if(!strcmp(sp,"VER"))
110
		return(VERSION);
111

112
	if(!strcmp(sp,"REV")) {
113
		safe_snprintf(str,maxlen,"%c",REVISION);
114
115
		return(str);
	}
116

117
	if(!strcmp(sp,"FULL_VER")) {
118
		safe_snprintf(str,maxlen,"%s%c%s",VERSION,REVISION,beta_version);
119
		truncsp(str);
120
#if defined(_DEBUG)
121
		strcat(str," Debug");
122
#endif
123
		return(str);
124
125
	}

126
	if(!strcmp(sp,"VER_NOTICE"))
127
		return(VERSION_NOTICE);
128

129
130
	if(!strcmp(sp,"OS_VER"))
		return(os_version(str));
131
132

#ifdef JAVASCRIPT
133
134
	if(!strcmp(sp,"JS_VER"))
		return((char *)JS_GetImplementationVersion());
135
136
#endif

137
138
	if(!strcmp(sp,"PLATFORM"))
		return(PLATFORM_DESC);
139

140
141
	if(!strcmp(sp,"COPYRIGHT"))
		return(COPYRIGHT_NOTICE);
142

143
	if(!strcmp(sp,"COMPILER")) {
144
		DESCRIBE_COMPILER(str);
145
		return(str);
146
147
	}

148
	if(!strcmp(sp,"UPTIME")) {
149
150
		extern time_t uptime;
		time_t up=time(NULL)-uptime;
151
152
		if(up<0)
			up=0;
153
154
		char   days[64]="";
		if((up/(24*60*60))>=2) {
155
	        sprintf(days,"%lu days ",(ulong)(up/(24L*60L*60L)));
156
157
			up%=(24*60*60);
		}
158
		safe_snprintf(str,maxlen,"%s%lu:%02lu"
159
	        ,days
160
161
			,(ulong)(up/(60L*60L))
			,(ulong)((up/60L)%60L)
162
			);
163
		return(str);
164
165
	}

166
167
	if(!strcmp(sp,"SERVED")) {
		extern DWORD served;
168
		safe_snprintf(str,maxlen,"%lu",served);
169
170
171
		return(str);
	}

172
	if(!strcmp(sp,"SOCKET_LIB"))
173
		return(socklib_version(str,SOCKLIB_DESC));
174

175
	if(!strcmp(sp,"MSG_LIB")) {
176
		safe_snprintf(str,maxlen,"SMBLIB %s",smb_lib_ver());
177
178
		return(str);
	}
179

180
181
	if(!strcmp(sp,"BBS") || !strcmp(sp,"BOARDNAME"))
		return(cfg.sys_name);
182

183
	if(!strcmp(sp,"BAUD") || !strcmp(sp,"BPS")) {
184
		safe_snprintf(str,maxlen,"%lu",cur_rate);
185
186
		return(str);
	}
187

188
189
	if(!strcmp(sp,"CONN"))
		return(connection);
190

191
192
	if(!strcmp(sp,"SYSOP"))
		return(cfg.sys_op);
193

194
195
	if(!strcmp(sp,"LOCATION"))
		return(cfg.sys_location);
196

197
	if(!strcmp(sp,"NODE")) {
198
		safe_snprintf(str,maxlen,"%u",cfg.node_num);
199
200
		return(str);
	}
201

202
	if(!strcmp(sp,"TNODE")) {
203
		safe_snprintf(str,maxlen,"%u",cfg.sys_nodes);
204
205
		return(str);
	}
206

207
208
	if(!strcmp(sp,"INETADDR"))
		return(cfg.sys_inetaddr);
209

210
211
212
	if(!strcmp(sp,"HOSTNAME"))
		return(startup->host_name);

213
	if(!strcmp(sp,"FIDOADDR")) {
214
		if(cfg.total_faddrs)
215
			return(smb_faddrtoa(&cfg.faddr[0],str));
216
		return(nulstr);
217
218
	}

219
	if(!strcmp(sp,"EMAILADDR"))
220
		return(usermailaddr(&cfg, str
221
			,cfg.inetmail_misc&NMAIL_ALIAS ? useron.alias : useron.name));
222

223
224
	if(!strcmp(sp,"QWKID"))
		return(cfg.sys_id);
225

226
	if(!strcmp(sp,"TIME") || !strcmp(sp,"SYSTIME")) {
227
		now=time(NULL);
228
		memset(&tm,0,sizeof(tm));
229
		localtime_r(&now,&tm);
230
		if(cfg.sys_misc&SM_MILITARY)
231
			safe_snprintf(str,maxlen,"%02d:%02d"
232
233
		        	,tm.tm_hour,tm.tm_min);
		else
234
			safe_snprintf(str,maxlen,"%02d:%02d %s"
235
236
237
				,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");
238
		return(str);
239
240
	}

241
	if(!strcmp(sp,"DATE") || !strcmp(sp,"SYSDATE")) {
242
		now=time(NULL);
243
		return(unixtodstr(&cfg,now,str));
244
	}
245

246
	if(!strcmp(sp,"TMSG")) {
247
248
		l=0;
		for(i=0;i<cfg.total_subs;i++)
249
			l+=getposts(&cfg,i); 		/* l=total posts */
250
		safe_snprintf(str,maxlen,"%lu",l);
251
252
		return(str);
	}
253

254
	if(!strcmp(sp,"TUSER")) {
255
		safe_snprintf(str,maxlen,"%u",total_users(&cfg));
256
257
		return(str);
	}
258

259
	if(!strcmp(sp,"TFILE")) {
260
261
		l=0;
		for(i=0;i<cfg.total_dirs;i++)
262
			l+=getfiles(&cfg,i);
263
		safe_snprintf(str,maxlen,"%lu",l);
264
265
		return(str);
	}
266

267
	if(!strcmp(sp,"TCALLS") || !strcmp(sp,"NUMCALLS")) {
268
		getstats(&cfg,0,&stats);
269
		safe_snprintf(str,maxlen,"%lu",stats.logons);
270
271
		return(str);
	}
272

273
	if(!strcmp(sp,"PREVON") || !strcmp(sp,"LASTCALLERNODE")
274
		|| !strcmp(sp,"LASTCALLERSYSTEM"))
275
		return(lastuseron);
276

277
	if(!strcmp(sp,"CLS")) {
278
		CLS;
279
280
		return(nulstr);
	}
281

282
	if(!strcmp(sp,"PAUSE") || !strcmp(sp,"MORE")) {
283
		pause();
284
285
		return(nulstr);
	}
286

287
	if(!strcmp(sp,"RESETPAUSE")) {
288
		lncntr=0;
289
290
		return(nulstr);
	}
291

292
	if(!strcmp(sp,"NOPAUSE") || !strcmp(sp,"POFF")) {
293
		sys_status^=SS_PAUSEOFF;
294
295
		return(nulstr);
	}
296

297
	if(!strcmp(sp,"PON") || !strcmp(sp,"AUTOMORE")) {
298
		sys_status^=SS_PAUSEON;
299
300
		return(nulstr);
	}
301
302
303
304
305

	/* NOSTOP */

	/* STOP */

306
307
	if(!strcmp(sp,"BELL") || !strcmp(sp,"BEEP"))
		return("\a");
308

309
310
311
	if(!strcmp(sp,"EVENT")) {
		if(event_time==0)
			return("<none>");
312
		return(timestr(event_time));
313
	}
314
315
316

	/* LASTCALL */

317
	if(!strncmp(sp,"NODE",4)) {
318
319
320
		i=atoi(sp+4);
		if(i && i<=cfg.sys_nodes) {
			getnodedat(i,&node,0);
321
322
			printnodedat(i,&node);
		}
323
324
		return(nulstr);
	}
325

326
	if(!strcmp(sp,"WHO")) {
327
		whos_online(true);
328
329
		return(nulstr);
	}
330
331
332

	/* User Codes */

333
334
	if(!strcmp(sp,"USER") || !strcmp(sp,"ALIAS") || !strcmp(sp,"NAME"))
		return(useron.alias);
335

336
	if(!strcmp(sp,"FIRST")) {
337
		safe_snprintf(str,maxlen,"%s",useron.alias);
338
		tp=strchr(str,' ');
339
		if(tp) *tp=0;
340
		return(str);
341
	}
342

343
	if(!strcmp(sp,"USERNUM")) {
344
		safe_snprintf(str,maxlen,"%u",useron.number);
345
346
		return(str);
	}
347

348
	if(!strcmp(sp,"PHONE") || !strcmp(sp,"HOMEPHONE")
349
		|| !strcmp(sp,"DATAPHONE") || !strcmp(sp,"DATA"))
350
		return(useron.phone);
351

352
353
	if(!strcmp(sp,"ADDR1"))
		return(useron.address);
354

355
356
	if(!strcmp(sp,"FROM"))
		return(useron.location);
357

358
	if(!strcmp(sp,"CITY")) {
359
		safe_snprintf(str,maxlen,"%s",useron.location);
360
		char* p=strchr(str,',');
361
362
		if(p) {
			*p=0;
363
364
			return(str);
		}
365
366
		return(nulstr);
	}
367

368
369
	if(!strcmp(sp,"STATE")) {
		char* p=strchr(useron.location,',');
370
371
		if(p) {
			p++;
372
			if(*p==' ')
373
				p++;
374
375
			return(p);
		}
376
377
		return(nulstr);
	}
378

379
380
	if(!strcmp(sp,"CPU"))
		return(useron.comp);
381

382
383
	if(!strcmp(sp,"HOST"))
		return(client_name);
384

385
386
	if(!strcmp(sp,"BDATE"))
		return(useron.birth);
387

388
	if(!strcmp(sp,"AGE")) {
389
		safe_snprintf(str,maxlen,"%u",getage(&cfg,useron.birth));
390
391
		return(str);
	}
rswindell's avatar
rswindell committed
392

393
	if(!strcmp(sp,"CALLS") || !strcmp(sp,"NUMTIMESON")) {
394
		safe_snprintf(str,maxlen,"%u",useron.logons);
395
396
		return(str);
	}
397

398
399
	if(!strcmp(sp,"MEMO"))
		return(unixtodstr(&cfg,useron.pwmod,str));
400

401
	if(!strcmp(sp,"SEC") || !strcmp(sp,"SECURITY")) {
402
		safe_snprintf(str,maxlen,"%u",useron.level);
403
404
		return(str);
	}
405

406
407
	if(!strcmp(sp,"SINCE"))
		return(unixtodstr(&cfg,useron.firston,str));
408

409
	if(!strcmp(sp,"TIMEON") || !strcmp(sp,"TIMEUSED")) {
410
		now=time(NULL);
411
		safe_snprintf(str,maxlen,"%lu",(ulong)(now-logontime)/60L);
412
413
		return(str);
	}
414

415
	if(!strcmp(sp,"TUSED")) {              /* Synchronet only */
416
		now=time(NULL);
417
		return(sectostr(now-logontime,str)+1);
418
	}
419

420
	if(!strcmp(sp,"TLEFT")) {              /* Synchronet only */
421
		gettimeleft();
422
		return(sectostr(timeleft,str)+1);
423
	}
424

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

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

431
	if(!strcmp(sp,"TIMELIMIT")) {
432
		safe_snprintf(str,maxlen,"%u",cfg.level_timepercall[useron.level]);
433
434
		return(str);
	}
435

436
	if(!strcmp(sp,"MINLEFT") || !strcmp(sp,"LEFT") || !strcmp(sp,"TIMELEFT")) {
437
		gettimeleft();
438
		safe_snprintf(str,maxlen,"%lu",timeleft/60);
439
440
		return(str);
	}
441

442
	if(!strcmp(sp,"LASTON"))
443
		return(timestr(useron.laston));
444

445
446
	if(!strcmp(sp,"LASTDATEON"))
		return(unixtodstr(&cfg,useron.laston,str));
447

448
	if(!strcmp(sp,"LASTTIMEON")) {
449
450
		memset(&tm,0,sizeof(tm));
		localtime_r(&useron.laston,&tm);
451
		safe_snprintf(str,maxlen,"%02d:%02d %s"
452
453
			,tm.tm_hour==0 ? 12
			: tm.tm_hour>12 ? tm.tm_hour-12
454
			: tm.tm_hour, tm.tm_min, tm.tm_hour>11 ? "pm":"am");
455
		return(str);
456
457
	}

458
	if(!strcmp(sp,"MSGLEFT") || !strcmp(sp,"MSGSLEFT")) {
459
		safe_snprintf(str,maxlen,"%u",useron.posts);
460
461
		return(str);
	}
462

463
	if(!strcmp(sp,"MSGREAD")) {
464
		safe_snprintf(str,maxlen,"%lu",posts_read);
465
466
		return(str);
	}
467

468
	if(!strcmp(sp,"FREESPACE")) {
469
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,0));
470
471
472
473
		return(str);
	}

	if(!strcmp(sp,"FREESPACEK")) {
474
		safe_snprintf(str,maxlen,"%lu",getfreediskspace(cfg.temp_dir,1024));
475
476
		return(str);
	}
477

478
	if(!strcmp(sp,"UPBYTES")) {
479
		safe_snprintf(str,maxlen,"%lu",useron.ulb);
480
481
		return(str);
	}
482

483
	if(!strcmp(sp,"UPK")) {
484
		safe_snprintf(str,maxlen,"%lu",useron.ulb/1024L);
485
486
		return(str);
	}
487

488
	if(!strcmp(sp,"UPS") || !strcmp(sp,"UPFILES")) {
489
		safe_snprintf(str,maxlen,"%u",useron.uls);
490
491
		return(str);
	}
492

493
	if(!strcmp(sp,"DLBYTES")) {
494
		safe_snprintf(str,maxlen,"%lu",useron.dlb);
495
496
		return(str);
	}
497

498
	if(!strcmp(sp,"DOWNK")) {
499
		safe_snprintf(str,maxlen,"%lu",useron.dlb/1024L);
500
501
		return(str);
	}
502

503
	if(!strcmp(sp,"DOWNS") || !strcmp(sp,"DLFILES")) {
504
		safe_snprintf(str,maxlen,"%u",useron.dls);
505
506
		return(str);
	}
507

508
509
	if(!strcmp(sp,"LASTNEW"))
		return(unixtodstr(&cfg,ns_time,str));
510

511
	if(!strcmp(sp,"NEWFILETIME"))
512
		return(timestr(ns_time));
513
514
515

	/* MAXDL */

516
	if(!strcmp(sp,"MAXDK") || !strcmp(sp,"DLKLIMIT") || !strcmp(sp,"KBLIMIT")) {
517
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]/1024L);
518
519
		return(str);
	}
520

521
	if(!strcmp(sp,"DAYBYTES")) {    /* amt of free cdts used today */
522
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]-useron.freecdt);
523
524
		return(str);
	}
525

526
	if(!strcmp(sp,"BYTELIMIT")) {
527
		safe_snprintf(str,maxlen,"%lu",cfg.level_freecdtperday[useron.level]);
528
529
		return(str);
	}
530

531
	if(!strcmp(sp,"KBLEFT")) {
532
		safe_snprintf(str,maxlen,"%lu",(useron.cdt+useron.freecdt)/1024L);
533
534
		return(str);
	}
535

536
	if(!strcmp(sp,"BYTESLEFT")) {
537
		safe_snprintf(str,maxlen,"%lu",useron.cdt+useron.freecdt);
538
539
		return(str);
	}
540

541
	if(!strcmp(sp,"CONF")) {
542
		safe_snprintf(str,maxlen,"%s %s"
543
544
			,usrgrps ? cfg.grp[usrgrp[curgrp]]->sname :nulstr
			,usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr);
545
546
		return(str);
	}
547

548
	if(!strcmp(sp,"CONFNUM")) {
549
		safe_snprintf(str,maxlen,"%u %u",curgrp+1,cursub[curgrp]+1);
550
551
		return(str);
	}
552

553
	if(!strcmp(sp,"NUMDIR")) {
554
		safe_snprintf(str,maxlen,"%u %u",usrlibs ? curlib+1 : 0,usrlibs ? curdir[curlib]+1 : 0);
555
556
		return(str);
	}
557

558
559
	if(!strcmp(sp,"EXDATE") || !strcmp(sp,"EXPDATE"))
		return(unixtodstr(&cfg,useron.expire,str));
560

561
	if(!strcmp(sp,"EXPDAYS")) {
562
563
564
565
		now=time(NULL);
		l=useron.expire-now;
		if(l<0)
			l=0;
566
		safe_snprintf(str,maxlen,"%lu",l/(1440L*60L));
567
568
		return(str);
	}
569

570
571
	if(!strcmp(sp,"MEMO1"))
		return(useron.note);
572

573
574
	if(!strcmp(sp,"MEMO2") || !strcmp(sp,"COMPANY"))
		return(useron.name);
575

576
577
	if(!strcmp(sp,"ZIP"))
		return(useron.zipcode);
578

579
	if(!strcmp(sp,"HANGUP")) {
580
		hangup();
581
582
		return(nulstr);
	}
583
584
585

	/* Synchronet Specific */

586
	if(!strncmp(sp,"SETSTR:",7)) {
587
		strcpy(main_csi.str,sp+7);
588
589
		return(nulstr);
	}
590

591
	if(!strncmp(sp,"EXEC:",5)) {
592
		exec_bin(sp+5,&main_csi);
593
594
		return(nulstr);
	}
595

596
	if(!strncmp(sp,"EXEC_XTRN:",10)) {
597
		for(i=0;i<cfg.total_xtrns;i++)
598
			if(!stricmp(cfg.xtrn[i]->code,sp+10))
599
600
601
602
603
604
				break;
		if(i<cfg.total_xtrns)
			exec_xtrn(i);
		return(nulstr);
	}

605
	if(!strncmp(sp,"MENU:",5)) {
606
		menu(sp+5);
607
608
		return(nulstr);
	}
609

610
611
612
613
	if(!strncmp(sp,"TYPE:",5)) {
		printfile(cmdstr(sp+5,nulstr,nulstr,str),0);
		return(nulstr);
	}
614

615
	if(!strncmp(sp,"INCLUDE:",8)) {
616
		printfile(cmdstr(sp+8,nulstr,nulstr,str),P_NOCRLF|P_SAVEATR);
617
618
619
		return(nulstr);
	}

620
621
	if(!strcmp(sp,"QUESTION"))
		return(question);
622

623
624
	if(!strcmp(sp,"HANDLE"))
		return(useron.handle);
625

626
627
	if(!strcmp(sp,"CID") || !strcmp(sp,"IP"))
		return(cid);
628

629
	if(!strcmp(sp,"LOCAL-IP")) {
630
		struct in_addr in_addr;
631
		in_addr.s_addr=local_addr;
632
		return(inet_ntoa(in_addr));
633
634
	}

635
636
	if(!strcmp(sp,"CRLF"))
		return("\r\n");
637

638
	if(!strcmp(sp,"PUSHXY")) {
639
		ansi_save();
640
641
		return(nulstr);
	}
642

643
	if(!strcmp(sp,"POPXY")) {
644
		ansi_restore();
645
646
		return(nulstr);
	}
647

648
	if(!strncmp(sp,"UP:",3)) {
649
		cursor_up(atoi(sp+3));
650
651
		return(str);
	}
652

653
	if(!strncmp(sp,"DOWN:",5)) {
654
		cursor_down(atoi(sp+5));
655
656
		return(str);
	}
657

658
	if(!strncmp(sp,"LEFT:",5)) {
659
		cursor_left(atoi(sp+5));
660
661
		return(str);
	}
662

663
	if(!strncmp(sp,"RIGHT:",6)) {
664
		cursor_right(atoi(sp+6));
665
666
		return(str);
	}
667

668
	if(!strncmp(sp,"GOTOXY:",7)) {
669
670
671
		tp=strchr(sp,',');
		if(tp!=NULL) {
			tp++;
672
			ansi_gotoxy(atoi(sp+7),atoi(tp));
673
		}
674
		return(nulstr);
675
676
	}

677
678
679
680
681
682
683
	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);
		}
684
		return(usrgrps ? cfg.grp[usrgrp[curgrp]]->sname : nulstr);
685
	}
686

687
688
689
690
691
692
693
	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);
		}
694
		return(usrgrps ? cfg.grp[usrgrp[curgrp]]->lname : nulstr);
695
	}
696

697
	if(!strcmp(sp,"GN")) {
698
699
		if(SMB_IS_OPEN(&smb))
			ugrp=getusrgrp(smb.subnum);
700
		else
701
			ugrp=usrgrps ? curgrp+1 : 0;
702
		safe_snprintf(str,maxlen,"%u",ugrp);
703
704
		return(str);
	}
705

706
	if(!strcmp(sp,"GL")) {
707
708
		if(SMB_IS_OPEN(&smb))
			ugrp=getusrgrp(smb.subnum);
709
		else
710
			ugrp=usrgrps ? curgrp+1 : 0;
711
		safe_snprintf(str,maxlen,"%-4u",ugrp);
712
713
		return(str);
	}
714

715
	if(!strcmp(sp,"GR")) {
716
717
		if(SMB_IS_OPEN(&smb))
			ugrp=getusrgrp(smb.subnum);
718
		else
719
			ugrp=usrgrps ? curgrp+1 : 0;
720
		safe_snprintf(str,maxlen,"%4u",ugrp);
721
722
		return(str);
	}
723

724
725
726
727
728
729
730
	if(!strcmp(sp,"SUB")) {
		if(SMB_IS_OPEN(&smb)) {
			if(smb.subnum==INVALID_SUB)
				return("Mail");
			else if(smb.subnum<cfg.total_subs)
				return(cfg.sub[smb.subnum]->sname);
		}
731
		return(usrgrps ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->sname : nulstr);
732
	}
733

734
735
736
737
738
739
740
	if(!strcmp(sp,"SUBL")) {
		if(SMB_IS_OPEN(&smb)) {
			if(smb.subnum==INVALID_SUB)
				return("Mail");
			else if(smb.subnum<cfg.total_subs)
				return(cfg.sub[smb.subnum]->lname);
		}
741
		return(usrgrps  ? cfg.sub[usrsub[curgrp][cursub[curgrp]]]->lname : nulstr);
742
	}
743

744
	if(!strcmp(sp,"SN")) {
745
746
747
748
		if(SMB_IS_OPEN(&smb))
			usub=getusrsub(smb.subnum);
		else
			usub=usrgrps ? cursub[curgrp]+1 : 0;
749
		safe_snprintf(str,maxlen,"%u",usub);
750
751
		return(str);
	}
752