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

/* Synchronet external program/door section and drop file routines */

/* $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 2005 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
41
42
43
44
45
 *																			*
 * 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"

/****************************************************************************/
/* This is the external programs (doors) section of the bbs                 */
/* Return 1 if no externals available, 0 otherwise. 						*/
/****************************************************************************/
int sbbs_t::xtrn_sec()
{
46
	char	str[MAX_PATH+1];
47
48
49
50
	int		xsec;
	uint	i,j,k,*usrxtrn,usrxtrns,*usrxsec,usrxsecs;
	long	l;

51
52
53
54
55
	if(useron.rest&FLAG('X')) {
		bputs(text[R_ExternalPrograms]);
		return(1);
	}

56
57
	if(!cfg.total_xtrns || !cfg.total_xtrnsecs) {
		bputs(text[NoXtrnPrograms]);
58
59
		return(1); 
	}
60

deuce's avatar
deuce committed
61
	if((usrxtrn=(uint *)malloc(cfg.total_xtrns*sizeof(int)))==NULL) {
62
		errormsg(WHERE,ERR_ALLOC,nulstr,cfg.total_xtrns);
63
64
		return(1); 
	}
deuce's avatar
deuce committed
65
	if((usrxsec=(uint *)malloc(cfg.total_xtrnsecs*sizeof(int)))==NULL) {
66
		errormsg(WHERE,ERR_ALLOC,nulstr,cfg.total_xtrnsecs);
deuce's avatar
deuce committed
67
		free(usrxtrn);
68
69
		return(1); 
	}
70
71
72
73
74
75
76

	while(online) {
		for(i=0,usrxsecs=0;i<cfg.total_xtrnsecs;i++)
			if(chk_ar(cfg.xtrnsec[i]->ar,&useron))
				usrxsec[usrxsecs++]=i;
		if(!usrxsecs) {
			bputs(text[NoXtrnPrograms]);
deuce's avatar
deuce committed
77
78
			free(usrxtrn);
			free(usrxsec);
79
80
			return(1); 
		}
81
		if(usrxsecs>1) {
82
			sprintf(str,"%smenu/xtrn_sec.*",cfg.text_dir);
83
			if(fexist(str)) {
84
				menu("xtrn_sec");
85
86
87
88
				xsec=getnum(usrxsecs);
				if(xsec<=0)
					break;
				xsec--;
89
90
				xsec=usrxsec[xsec]; 
			}
91
92
93
94
			else {
				for(i=0;i<cfg.total_xtrnsecs;i++)
					uselect(1,i,"External Program Section"
						,cfg.xtrnsec[i]->name,cfg.xtrnsec[i]->ar);
95
96
				xsec=uselect(0,0,0,0,0); 
			}
97
			if(xsec==-1)
98
99
				break; 
		}
100
101
102
103
104
105
106
107
		else
			xsec=0;

		while(!chk_ar(cfg.xtrnsec[xsec]->ar,&useron))
			xsec++;

		if(xsec>=cfg.total_xtrnsecs) {
			bputs(text[NoXtrnPrograms]);
deuce's avatar
deuce committed
108
109
			free(usrxtrn);
			free(usrxsec);
110
111
			return(1); 
		}
112
113
114
115
116
117
118
119
120

		while(online) {
			for(i=0,usrxtrns=0;i<cfg.total_xtrns; i++) {
				if(cfg.xtrn[i]->sec!=xsec)
					continue;
				if(cfg.xtrn[i]->misc&EVENTONLY)
					continue;
				if(!chk_ar(cfg.xtrn[i]->ar,&useron))
					continue;
121
122
				usrxtrn[usrxtrns++]=i; 
			}
123
124
125
			if(!usrxtrns) {
				bputs(text[NoXtrnPrograms]);
				pause();
126
127
				break; 
			}
128
			sprintf(str,"%smenu/xtrn%u.*",cfg.text_dir,xsec+1);
129
			if(fexist(str)) {
130
				sprintf(str,"xtrn%u",xsec+1);
131
132
				menu(str); 
			}
133
134
135
136
137
			else {
				bprintf(text[XtrnProgLstHdr],cfg.xtrnsec[xsec]->name);
				bputs(text[XtrnProgLstTitles]);
				if(usrxtrns>=10) {
					bputs("     ");
138
139
					bputs(text[XtrnProgLstTitles]); 
				}
140
141
142
143
				CRLF;
				bputs(text[XtrnProgLstUnderline]);
				if(usrxtrns>=10) {
					bputs("     ");
144
145
					bputs(text[XtrnProgLstUnderline]); 
				}
146
147
148
149
150
151
152
153
154
155
156
157
158
159
				CRLF;
				if(usrxtrns>=10)
					j=(usrxtrns/2)+(usrxtrns&1);
				else
					j=usrxtrns;
				for(i=0;i<j && !msgabort();i++) {
					bprintf(text[XtrnProgLstFmt],i+1
						,cfg.xtrn[usrxtrn[i]]->name,cfg.xtrn[usrxtrn[i]]->cost);
					if(usrxtrns>=10) {
						k=(usrxtrns/2)+i+(usrxtrns&1);
						if(k<usrxtrns) {
							bputs("     ");
							bprintf(text[XtrnProgLstFmt],k+1
								,cfg.xtrn[usrxtrn[k]]->name
160
161
162
163
164
								,cfg.xtrn[usrxtrn[k]]->cost); 
						}
					}
					CRLF; 
				}
165
				ASYNC;
166
167
				mnemonics(text[WhichXtrnProg]); 
			}
168
169
170
171
172
173
174
			getnodedat(cfg.node_num,&thisnode,1);
			thisnode.aux=0; /* aux is 0, only if at menu */
			putnodedat(cfg.node_num,&thisnode);
			action=NODE_XTRN;
			SYNC;
			if((l=getnum(usrxtrns))<1)
				break;
175
176
177
178
179
180
181
182
			l--;
			sprintf(str,"%smenu/xtrn/%s.*",cfg.text_dir,cfg.xtrn[usrxtrn[l]]->code);
			if(fexist(str)) {
				sprintf(str,"xtrn/%s",cfg.xtrn[usrxtrn[l]]->code);
				menu(str);
				lncntr=0;
			}
			exec_xtrn(usrxtrn[l]); 
183

184
185
			if(cfg.xtrn[usrxtrn[l]]->misc&XTRN_PAUSE)
				lncntr=2;	/* force a pause before CLS */
186
		}
187
		if(usrxsecs<2)
188
189
			break; 
	}
deuce's avatar
deuce committed
190
191
	free(usrxtrn);
	free(usrxsec);
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
	return(0);
}


char *hungupstr="\1n\1h%s\1n hung up on \1h%s\1n %s\r\n";

/****************************************************************************/
/* Convert C string to pascal string										*/
/****************************************************************************/
void str2pas(char *instr, char *outstr)
{
	int i;

	outstr[0]=(char)strlen(instr);
	for(i=0;i<outstr[0];i++)
		outstr[i+1]=instr[i];
}

/****************************************************************************/
/* Convert from unix time (seconds since 1/70) to julian (days since 1900)	*/
/****************************************************************************/
213
int unixtojulian(time_t unix_time)
214
215
216
{
	int days[12]={0,31,59,90,120,151,181,212,243,273,304,334};
	long j;
217
	struct tm tm;
218

219
	if(localtime_r(&unix_time,&tm)==NULL)
220
		return(0);
221
222
	j=36525L*(1900+tm.tm_year);
	if(!(j%100) && (tm.tm_mon+1)<3)
223
224
		j--;
	j=(j-(1900*36525))/100;
225
	j+=tm.tm_mday+days[tm.tm_mon];
226
227
228
229
230
231
	return(j);
}

/****************************************************************************/
/* Convert julian date into unix format 									*/
/****************************************************************************/
232
233
234
#ifdef __BORLANDC__
#pragma argsused
#endif
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
time_t juliantounix(ulong j)
{
#if 0 /* julian time */
    int days[2][12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334,
                       0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};
    long temp;
	int leap,counter;
	struct tm tm;

	if(!j) return(0L);

	tm.tm_year=((100L*j)/36525L)-1900;
	temp=(long)date.da_year*36525L;
	date.da_year+=1900;
	j-=temp/100L;

	if (!(temp%100)) {
		j++;
253
254
		leap=1; 
	}
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
	else leap=0;

	for(date.da_mon=counter=0;counter<12;counter++)
		if(days[leap][counter]<j)
			date.da_mon=counter;

	date.da_day=j-days[leap][date.da_mon];
	date.da_mon++;	/* go from 0 to 1 based */

	curtime.ti_hour=curtime.ti_min=curtime.ti_sec=0;
	return(dostounix(&date,&curtime));
#else
	return((time_t)-1);
#endif
}

271
272
273
274
275
#ifdef __unix__
static void lfexpand(char *str, ulong misc)
{
	char *p;
	char newstr[1024];
rswindell's avatar
rswindell committed
276
	size_t len=0;
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293

	if(misc&XTRN_NATIVE)
		return;

	for(p=str;*p && len < sizeof(newstr)-1;p++) {
		if(*p=='\n')
			newstr[len++]='\r';
		newstr[len++]=*p;
	}

	newstr[len]=0;
	strcpy(str,newstr);
}
#else
	#define lfexpand(str, misc)
#endif

294
295
296
297
298
299
/****************************************************************************/
/* Creates various types of xtrn (Doors, Chains, etc.) data (drop) files.	*/
/****************************************************************************/
void sbbs_t::xtrndat(char *name, char *dropdir, uchar type, ulong tleft
					,ulong misc)
{
300
301
	char	str[1024],tmp2[128],c,*p;
	char 	tmp[512];
302
303
304
	int		i,file;
	ushort	w;
	long	l;
305
306
	struct tm tm;
	struct tm tl;
307
308
309
	stats_t stats;

	if(type==XTRN_SBBS) {	/* SBBS XTRN.DAT file */
310
311
312
313
		strcpy(tmp,"XTRN.DAT");
		if(misc&XTRN_LWRCASE)
			strlwr(tmp);
		sprintf(str,"%s%s",dropdir,tmp);
314
315
		if((file=nopen(str,O_WRONLY|O_CREAT|O_TRUNC|O_TEXT))==-1) {
			errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_TRUNC|O_TEXT);
316
317
			return; 
		}
318

319
		sprintf(str,"%s\n%s\n%s\n%s\n"
320
321
322
323
			,name								/* User name */
			,cfg.sys_name						/* System name */
			,cfg.sys_op 						/* Sysop name */
			,cfg.sys_guru); 					/* Guru name */
324
		lfexpand(str,misc);
325
326
		write(file,str,strlen(str));

327
		sprintf(str,"%s\n%s\n%u\n%u\n%lu\n%s\n%lu\n%lu\n"
328
329
330
331
332
333
334
335
336
337
			,cfg.ctrl_dir						/* Ctrl dir */
			,cfg.data_dir						/* Data dir */
			,cfg.sys_nodes						/* Total system nodes */
			,cfg.node_num						/* Current node */
			,tleft								/* User Timeleft in seconds */
			,useron.misc&ANSI					/* User ANSI ? (Yes/Mono/No) */
				? useron.misc&COLOR
				? "Yes":"Mono":"No"
			,rows								/* User Screen lines */
			,useron.cdt+useron.freecdt);		/* User Credits */
338
		lfexpand(str,misc);
339
340
		write(file,str,strlen(str));

341
		sprintf(str,"%u\n%u\n%s\n%c\n%u\n%s\n"
342
343
344
345
346
347
			,useron.level						/* User main level */
			,useron.level						/* User transfer level */
			,useron.birth						/* User birthday */
			,useron.sex 						/* User sex (M/F) */
			,useron.number						/* User number */
			,useron.phone); 					/* User phone number */
348
		lfexpand(str,misc);
349
350
		write(file,str,strlen(str));

351
352
		sprintf(str,"%u\n%u\n%x\n%lu\n%s\n%s\n"
			"%s\n%s\n%s\n%s\n%s\n%s\n%lu\n"
353
354
355
356
357
358
359
360
361
362
363
364
			,misc&IO_INTS ? 0:cfg.com_port		/* Com port or 0 if !FOSSIL */
			,cfg.com_irq						/* Com IRQ */
			,cfg.com_base						/* Com base in hex */
			,dte_rate							/* Com rate */
			,"Yes"								/* Hardware flow ctrl Y/N */
			,"Yes"								/* Locked DTE rate Y/N */
			,cfg.mdm_init						/* Modem initialization string */
			,cfg.mdm_spec						/* Modem special init string */
			,cfg.mdm_term						/* Modem terminal mode init str */
			,cfg.mdm_dial						/* Modem dial string */
			,cfg.mdm_offh						/* Modem off-hook string */
			,cfg.mdm_answ						/* Modem answer string */
365
			,0L
366
			);
367
		lfexpand(str,misc);
368
369
		write(file,str,strlen(str));

370
		sprintf(str,"%u\n",cfg.total_xtrns);
371
		lfexpand(str,misc);
372
373
374
375
376
377
378
		write(file,str,strlen(str));			/* Total external programs */

		for(i=0;i<cfg.total_xtrns;i++) {		/* Each program's name */
			if(SYSOP || chk_ar(cfg.xtrn[i]->ar,&useron))
				strcpy(str,cfg.xtrn[i]->name);
			else
				str[0]=0;						/* Blank if no access */
379
380
			strcat(str,"\n");
			lfexpand(str,misc);
381
382
			write(file,str,strlen(str)); 
		}
383

384
		sprintf(str,"%s\n%s\n"
385
386
387
			,ltoaf(useron.flags1,tmp)			/* Main flags */
			,ltoaf(useron.flags2,tmp2)			/* Transfer flags */
			);
388
		lfexpand(str,misc);
389
390
		write(file,str,strlen(str));

391
		sprintf(str,"%s\n%s\n%lx\n%s\n%s\n%s\n"
392
393
			,ltoaf(useron.exempt,tmp)			/* Exemptions */
			,ltoaf(useron.rest,tmp2)			/* Restrictions */
394
			,(long)useron.expire				/* Expiration date in unix form */
395
396
397
398
			,useron.address 					/* Address */
			,useron.location					/* City/State */
			,useron.zipcode 					/* Zip/Postal code */
			);
399
		lfexpand(str,misc);
400
401
		write(file,str,strlen(str));

402
403
		sprintf(str,"%s\n%s\n%d\n%s\n%lu\n%s\n%s\n%s\n%s\n"
			"%lx\n%d\n"
404
405
			,ltoaf(useron.flags3,tmp)			/* Flag set #3 */
			,ltoaf(useron.flags4,tmp2)			/* Flag set #4 */
406
			,0									/* Time-slice type */
407
408
409
410
411
412
413
			,useron.name						/* Real name/company */
			,cur_rate							/* DCE rate */
			,cfg.exec_dir
			,cfg.text_dir
			,cfg.temp_dir
			,cfg.sys_id
			,cfg.node_misc
414
			,misc&IO_INTS ? INVALID_SOCKET : client_socket_dup
415
			);
416
		lfexpand(str,misc);
417
418
		write(file,str,strlen(str));

419
420
		close(file); 
	}
421
422

	else if(type==XTRN_WWIV) {	/*	WWIV CHAIN.TXT File */
423
424
425
426
		strcpy(tmp,"CHAIN.TXT");
		if(misc&XTRN_LWRCASE)
			strlwr(tmp);
		sprintf(str,"%s%s",dropdir,tmp);
427
428
		if((file=nopen(str,O_WRONLY|O_CREAT|O_TRUNC|O_TEXT))==-1) {
			errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_TRUNC|O_TEXT);
429
430
			return; 
		}
431

432
433
434
		if(tleft>0x7fff)	/* Reduce time-left for broken 16-bit doors		*/
			tleft=0x7fff;	/* That interpret this value as a signed short	*/

435
		sprintf(str,"%u\n%s\n%s\n%s\n%u\n%c\n"
436
437
438
439
440
441
442
			,useron.number						/* User number */
			,name								/* User name */
			,useron.name						/* User real name */
			,nulstr 							/* User call sign */
			,getage(&cfg,useron.birth)			/* User age */
			,useron.sex);						/* User sex (M/F) */
		strupr(str);
443
		lfexpand(str,misc);
444
445
		write(file,str,strlen(str));

446
		sprintf(str,"%lu\n%s\n%u\n%lu\n%u\n%u\n%u\n%u\n%u\n"
447
448
			,useron.cdt+useron.freecdt			/* Gold */
			,unixtodstr(&cfg,useron.laston,tmp)	/* User last on date */
449
			,cols 								/* User screen width */
450
451
452
453
454
455
			,rows								/* User screen length */
			,useron.level						/* User SL */
			,0									/* Cosysop? */
			,SYSOP								/* Sysop? (1/0) */
			,(useron.misc&ANSI) ? 1:0			/* ANSI ? (1/0) */
			,online==ON_REMOTE);				/* Remote (1/0) */
456
		lfexpand(str,misc);
457
458
		write(file,str,strlen(str));

459
460
		sprintf(str,"%lu\n%s\n%s\n%s\n%lu\n%d\n%s\n%s\n"
			"%u\n%u\n%lu\n%u\n%lu\n%u\n%s\n"
461
462
463
			,tleft								/* Time left in seconds */
			,cfg.node_dir						/* Gfiles dir (log dir) */
			,cfg.data_dir						/* Data dir */
464
			,"node.log"                         /* Name of log file */
465
466
467
468
469
470
471
472
473
474
475
			,dte_rate							/* DTE rate */
			,cfg.com_port						/* COM port number */
			,cfg.sys_name						/* System name */
			,cfg.sys_op 						/* Sysop name */
			,0									/* Logon time (sec past 12am) */
			,0									/* Current time (sec past 12am) */
			,useron.ulb/1024UL					/* User uploaded kbytes */
			,useron.uls 						/* User uploaded files */
			,useron.dlb/1024UL					/* User downloaded kbytes */
			,useron.dls 						/* User downloaded files */
			,"8N1");                            /* Data, parity, stop bits */
476
		lfexpand(str,misc);
477
478
		write(file,str,strlen(str));

479
480
		close(file); 
	}
481
482

	else if(type==XTRN_GAP) {	/* Gap DOOR.SYS File */
483
484
485
486
		strcpy(tmp,"DOOR.SYS");
		if(misc&XTRN_LWRCASE)
			strlwr(tmp);
		sprintf(str,"%s%s",dropdir,tmp);
487
488
		if((file=nopen(str,O_WRONLY|O_CREAT|O_TRUNC|O_TEXT))==-1) {
			errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_TRUNC|O_TEXT);
489
490
			return; 
		}
491

492
493
494
		if(tleft>0x7fff)	/* Reduce time-left for broken 16-bit doors		*/
			tleft=0x7fff;	/* That interpret this value as a signed short	*/

495
496
497
498
499
500
501
502
		/* Note about door.sys, line 2 (April-24-2005):
		   It *should* be the DCE rate (any number, including the popular modem
		   DCE rates of 14400, 28800, and 33600).  However, according to Deuce,
		   doors created with the DMlib door kit choke with "Error -25: Illegal
		   baud rate" if this isn't a valid FOSSIL baud (DTE) rate, so we're
		   changing this value to the DTE rate until/unless some other doors
		   have an issue with that. <sigh>
		*/
503
		sprintf(str,"COM%d:\n%lu\n%u\n%u\n%lu\n%c\n%c\n%c\n%c\n"
504
			,online==ON_REMOTE ? cfg.com_port:0	/* 01: COM port - 0 if Local */
505
			,dte_rate /* was cur_rate */		/* 02: DCE rate, see note above */
506
507
508
509
510
511
512
			,8									/* 03: Data bits */
			,cfg.node_num						/* 04: Node number */
			,dte_rate							/* 05: DTE rate */
			,console&CON_L_ECHO ? 'Y':'N'       /* 06: Screen display */
			,'Y'                                /* 07: Printer toggle */
			,'Y'                                /* 08: Page bell */
			,'Y');                              /* 09: Caller alarm */
513
		lfexpand(str,misc);
514
515
		write(file,str,strlen(str));

516
		sprintf(str,"%s\n%s\n%s\n%s\n%s\n"
517
518
519
520
521
			,name								/* 10: User name */
			,useron.location					/* 11: User location */
			,useron.phone						/* 12: User home phone */
			,useron.phone						/* 13: User work/data phone */
			,useron.pass);						/* 14: User password */
522
		lfexpand(str,misc);
523
524
		write(file,str,strlen(str));

525
		sprintf(str,"%u\n%u\n%s\n%lu\n%lu\n%s\n"
526
527
528
529
530
531
532
			,useron.level						/* 15: User security level */
			,useron.logons						/* 16: User total logons */
			,unixtodstr(&cfg,useron.laston,tmp)	/* 17: User last on date */
			,tleft								/* 18: User time left in sec */
			,tleft/60							/* 19: User time left in min */
			,useron.misc&NO_EXASCII 			/* 20: GR if COLOR ANSI */
				? "7E" : (useron.misc&(ANSI|COLOR))==(ANSI|COLOR) ? "GR" : "NG");
533
		lfexpand(str,misc);
534
535
		write(file,str,strlen(str));

536
		sprintf(str,"%lu\n%c\n%s\n%u\n%s\n%u\n%c\n%u\n%u\n"
537
538
539
540
541
542
543
544
545
			,rows								/* 21: User screen length */
			,useron.misc&EXPERT ? 'Y':'N'       /* 22: Expert? (Y/N) */
			,ltoaf(useron.flags1,tmp2)			/* 23: Registered conferences */
			,0									/* 24: Conference came from */
			,unixtodstr(&cfg,useron.expire,tmp)	/* 25: User expiration date */
			,useron.number						/* 26: User number */
			,'Y'                                /* 27: Default protocol */
			,useron.uls 						/* 28: User total uploads */
			,useron.dls);						/* 29: User total downloads */
546
		lfexpand(str,misc);
547
548
		write(file,str,strlen(str));

549
550
		sprintf(str,"%u\n%lu\n%s\n%s\n%s\n%s"
			"\n%s\n%02d:%02d\n%c\n"
551
552
553
554
555
556
557
558
559
560
			,0									/* 30: Kbytes downloaded today */
			,(useron.cdt+useron.freecdt)/1024UL /* 31: Max Kbytes to download today */
			,useron.birth						/* 32: User birthday */
			,cfg.node_dir						/* 33: Path to MAIN directory */
			,cfg.data_dir						/* 34: Path to GEN directory */
			,cfg.sys_op 						/* 35: Sysop name */
			,nulstr 							/* 36: Alias name */
			,0 // sys_eventtime/60				/* 37: Event time HH:MM */
			,0 // sys_eventtime%60
			,'Y');                              /* 38: Error correcting connection */
561
		lfexpand(str,misc);
562
563
		write(file,str,strlen(str));

564
		localtime_r(&ns_time,&tm);
565
		sprintf(str,"%c\n%c\n%u\n%lu\n%02d/%02d/%02d\n"
566
567
568
569
570
			,(useron.misc&(NO_EXASCII|ANSI|COLOR))==ANSI
				? 'Y':'N'                       /* 39: ANSI supported but NG mode */
			,'Y'                                /* 40: Use record locking */
			,14 								/* 41: BBS default color */
			,useron.min 						/* 42: Time credits in minutes */
571
572
573
			,tm.tm_mon+1						/* 43: File new-scan date */
			,tm.tm_mday
			,TM_YEAR(tm.tm_year));
574
		lfexpand(str,misc);
575
576
		write(file,str,strlen(str));

577
578
		localtime_r(&logontime,&tm);
		localtime_r(&useron.laston,&tl);
579
580
		sprintf(str,"%02d:%02d\n%02d:%02d\n%u\n%u\n%lu\n"
			"%lu\n%s\n%u\n%u\n"
581
			,tm.tm_hour							/* 44: Time of this call */
582
			,tm.tm_min
583
			,tl.tm_hour							/* 45: Time of last call */
584
			,tl.tm_min
585
586
587
588
589
590
591
			,999								/* 46: Max daily files available */
			,0									/* 47: Files downloaded so far today */
			,useron.ulb/1024UL					/* 48: Total Kbytes uploaded */
			,useron.dlb/1024UL					/* 49: Total Kbytes downloaded */
			,useron.comment 					/* 50: User comment */
			,0									/* 51: Total doors opened */
			,useron.posts); 					/* 52: User message left */
592
		lfexpand(str,misc);
593
594
		write(file,str,strlen(str));

595
596
		close(file); 
	}
597
598
599

	else if(type==XTRN_RBBS || type==XTRN_RBBS1) {
		if(type==XTRN_RBBS)
600
			sprintf(tmp,"DORINFO%X.DEF",cfg.node_num);   /* support 1-F */
601
		else
602
603
604
605
			sprintf(tmp,"DORINFO1.DEF");
		if(misc&XTRN_LWRCASE)
			strlwr(tmp);
		sprintf(str,"%s%s",dropdir,tmp);
606
607
		if((file=nopen(str,O_WRONLY|O_CREAT|O_TRUNC|O_TEXT))==-1) {
			errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_TRUNC|O_TEXT);
608
609
			return; 
		}
610
611

		strcpy(tmp,cfg.sys_op);
612
		p=strchr(tmp,' ');
613
614
615
616
617
		if(p)
			*(p++)=0;
		else
			p=nulstr;

618
		sprintf(str,"%s\n%s\n%s\nCOM%d\n%lu BAUD,N,8,1\n%u\n"
619
620
621
622
623
624
625
			,cfg.sys_name						/* Name of BBS */
			,tmp								/* Sysop's firstname */
			,p									/* Sysop's lastname */
			,online==ON_REMOTE ? cfg.com_port:0 /* COM port number, 0 if local */
			,dte_rate							/* DTE rate */
			,0);								/* Network type */
		strupr(str);
626
		lfexpand(str,misc);
627
628
629
		write(file,str,strlen(str));

		strcpy(tmp,name);
630
		p=strchr(tmp,' ');
631
632
633
634
		if(p)
			*(p++)=0;
		else
			p=nulstr;
635
		sprintf(str,"%s\n%s\n%s\n%u\n%u\n%lu\n"
636
637
638
639
640
641
642
			,tmp								/* User's firstname */
			,p									/* User's lastname */
			,useron.location					/* User's city */
			,(useron.misc&ANSI)==ANSI			/* 1=ANSI 0=ASCII */
			,useron.level						/* Security level */
			,tleft/60); 						/* Time left in minutes */
		strupr(str);
643
		lfexpand(str,misc);
644
645
646
647
		write(file,str,strlen(str));

		close(file);

648
649
650
651
		strcpy(tmp,"EXITINFO.BBS");
		if(misc&XTRN_LWRCASE)
			strlwr(tmp);
		sprintf(str,"%s%s",dropdir,tmp);
652
653
		if((file=nopen(str,O_WRONLY|O_CREAT|O_TRUNC))==-1) {
			errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_TRUNC);
654
655
			return; 
		}
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
		w=(WORD)dte_rate;
		write(file,&w,sizeof(short));			/* BaudRate */
		/* SysInfo */
		getstats(&cfg,0,&stats);
		write(file,&stats.logons,sizeof(long)); /* CallCount */
		write(file,nulstr,36);					/* LastCallerName */
		write(file,nulstr,36);					/* LastCallerAlias */
		write(file,nulstr,92);					/* ExtraSpace */
		/* TimeLogInfo */
		write(file,nulstr,9);					/* StartDate */
		write(file,nulstr,24*sizeof(short));	/* BusyPerHour */
		write(file,nulstr,7*sizeof(short));		/* BusyPerDay */
		/* UserInfo */
		str2pas(name,str);				/* Name */
		write(file,str,36);
		str2pas(useron.location,str);
		write(file,str,26); 					/* City */
		str2pas(useron.pass,str);
		write(file,str,16); 					/* Pwd */
		str2pas(useron.phone,str);
		write(file,str,13); 					/* DataPhone */
		write(file,str,13); 					/* HomePhone */
678
679
		localtime_r(&useron.laston,&tm);
		sprintf(tmp,"%02d:%02d",tm.tm_hour,tm.tm_min);
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
		str2pas(tmp,str);
		write(file,str,6);						/* LastTime */
		unixtodstr(&cfg,useron.laston,tmp);
		str2pas(tmp,str);
		write(file,str,9);						/* LastDate */
		c=0;
		if(useron.misc&DELETED) c|=(1<<0);
		if(useron.misc&CLRSCRN) c|=(1<<1);
		if(useron.misc&UPAUSE)	 c|=(1<<2);
		if(useron.misc&ANSI)	c|=(1<<3);
		if(useron.sex=='F')     c|=(1<<7);
		write(file,&c,1);						/* Attrib */
		write(file,&useron.flags1,4);			/* Flags */
		w=0;
		write(file,&w,sizeof(short)); 			/* Credit */
		write(file,&w,sizeof(short)); 			/* Pending */
		write(file,&useron.posts,sizeof(short));/* TimesPosted */
		write(file,&w,sizeof(short)); 			/* HighMsgRead */
		w=useron.level;
		write(file,&w,sizeof(short)); 			/* SecLvl */
		w=0;
		write(file,&w,sizeof(short)); 			/* Times */
		write(file,&useron.uls,sizeof(short));	/* Ups */
		write(file,&useron.dls,sizeof(short));	/* Downs */
		w=(ushort)(useron.ulb/1024UL);
		write(file,&w,sizeof(short)); 			/* UpK */
		w=(ushort)(useron.dlb/1024UL);
		write(file,&w,sizeof(short)); 			/* DownK */
		w=(ushort)(logon_dlb/1024UL);
		write(file,&w,sizeof(short)); 			/* TodayK */
		w=0;
		write(file,&w,sizeof(short)); 			/* Elapsed */
		write(file,&w,sizeof(short)); 			/* Len */
		write(file,&w,sizeof(short)); 			/* CombinedPtr */
		write(file,&w,sizeof(short)); 			/* AliasPtr */
		l=0;
		write(file,&l,sizeof(long));			/* Birthday (as a long?) */
		/* EventInfo */
		c=0;
		write(file,&c,sizeof(char));			/* Status */
		write(file,&l /* sys_eventtime */,sizeof(long));	/* RunTime */
		write(file,&c,sizeof(char));			/* ErrorLevel */
		c='\xff';
		write(file,&c,sizeof(char));			/* Days */
		// c=sys_eventnode==node_num || sys_misc&SM_TIMED_EX ? 1 : 0;
		c=0;
		write(file,&c,sizeof(char));			/* Forced */
		if(!cfg.total_events)
			l=0;
		else
			l=cfg.event[0]->last;
		write(file,&l,sizeof(long));			/* LastTimeRun */
		memset(str,0,40);
		write(file,str,7);						/* Spare */

		c=0;
		write(file,&c,1);						/* NetMailEntered */
		write(file,&c,1);						/* EchoMailEntered */

739
740
		localtime_r(&logontime,&tm);
		sprintf(tmp,"%02d:%02d",tm.tm_hour,tm.tm_min);
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
		str2pas(tmp,str);
		write(file,str,6);						/* LoginTime */
		unixtodstr(&cfg,logontime,tmp);
		str2pas(tmp,str);
		write(file,str,9);						/* LoginDate */
		write(file,&cfg.level_timepercall[useron.level],sizeof(short));  /* TmLimit */
		write(file,&logontime,sizeof(long));	/* LoginSec */
		write(file,&useron.cdt,sizeof(long));	/* Credit */
		write(file,&useron.number,sizeof(short)); /* UserRecNum */
		write(file,&i,2);						/* ReadThru */
		write(file,&i,2);						/* PageTimes */
		write(file,&i,2);						/* DownLimit */
		c=sys_status&SS_SYSPAGE ? 1:0;
		write(file,&c,1);						/* WantChat */
		c=0;
		write(file,&c,1);						/* GosubLevel */

		memset(str,0,255);
		for(i=1;i<20;i++)
			write(file,str,9);					/* GosubData */
		write(file,str,9);						/* Menu */
		c=useron.misc&CLRSCRN ? 1:0;
		write(file,&c,1);						/* ScreenClear */
		c=useron.misc&UPAUSE ? 1:0;
		write(file,&c,1);						/* MorePrompts */
		c=useron.misc&NO_EXASCII ? 0:1;
		write(file,&c,1);						/* GraphicsMode */
		c=useron.xedit ? 1:0;
		write(file,&c,1);						/* ExternEdit */
		i=rows;
		write(file,&i,2);						/* ScreenLength */
		c=1;
		write(file,&c,1);						/* MNP_Connect */
		write(file,str,49); 					/* ChatReason */
		c=0;
		write(file,&c,1);						/* ExternLogoff */
		c=useron.misc&ANSI ? 1:0;
		write(file,&c,1);						/* ANSI_Capable */
		close(file);
780
	}
781
782

	else if(type==XTRN_WILDCAT) { /* WildCat CALLINFO.BBS File */
783
784
785
786
		strcpy(tmp,"CALLINFO.BBS");
		if(misc&XTRN_LWRCASE)
			strlwr(tmp);
		sprintf(str,"%s%s",dropdir,tmp);
787
788
		if((file=nopen(str,O_WRONLY|O_CREAT|O_TRUNC|O_TEXT))==-1) {
			errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_TRUNC|O_TEXT);
789
790
			return; 
		}
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814

		if(online==ON_LOCAL) i=5;
		else
			switch(dte_rate) {
				case 300:
					i=1;
					break;
				case 1200:
					i=2;
					break;
				case 2400:
					i=0;
					break;
				case 9600:
					i=3;
					break;
				case 19200:
					i=4;
					break;
				case 38400:
					i=6;
					break;
				default:
					i=7;
815
816
					break; 
		}
817
		sprintf(str,"%s\n%u\n%s\n%u\n%lu\n%s\n%s\n%u\n"
818
819
820
821
822
823
824
825
			,name								/* User name */
			,i									/* DTE rate */
			,useron.location					/* User location */
			,useron.level						/* Security level */
			,tleft/60							/* Time left in min */
			,useron.misc&ANSI ? "COLOR":"MONO"  /* ANSI ??? */
			,useron.pass						/* Password */
			,useron.number);					/* User number */
826
		lfexpand(str,misc);
827
828
		write(file,str,strlen(str));

829
		localtime_r(&now,&tm);
830
		sprintf(str,"%lu\n%02d:%02d\n%02d:%02d %02d/%02d/%02d\n%s\n"
831
			,tleft								/* Time left in seconds */
832
833
834
835
			,tm.tm_hour,tm.tm_min 			/* Current time HH:MM */
			,tm.tm_hour,tm.tm_min 			/* Current time and date HH:MM */
			,tm.tm_mon+1,tm.tm_mday			/* MM/DD/YY */
			,TM_YEAR(tm.tm_year)
836
			,nulstr);							/* Conferences with access */
837
		lfexpand(str,misc);
838
839
		write(file,str,strlen(str));

840
		localtime_r(&useron.laston,&tm);
841
		sprintf(str,"%u\n%u\n%u\n%u\n%s\n%s %02u:%02u\n"
842
843
844
845
846
847
			,0									/* Daily download total */
			,0									/* Max download files */
			,0									/* Daily download k total */
			,0									/* Max download k total */
			,useron.phone						/* User phone number */
			,unixtodstr(&cfg,useron.laston,tmp)	/* Last on date and time */
848
849
			,tm.tm_hour						/* MM/DD/YY  HH:MM */
			,tm.tm_min);
850
		lfexpand(str,misc);
851
852
		write(file,str,strlen(str));

853
		localtime_r(&ns_time,&tm);
854
855
		sprintf(str,"%s\n%s\n%02d/%02d/%02d\n%u\n%lu\n%u"
			"\n%u\n%u\n"
856
857
858
			,useron.misc&EXPERT 				/* Expert or Novice mode */
				? "EXPERT":"NOVICE"
			,"All"                              /* Transfer Protocol */
859
860
			,tm.tm_mon+1,tm.tm_mday			/* File new-scan date */
			,TM_YEAR(tm.tm_year)				/* in MM/DD/YY */
861
862
863
864
865
			,useron.logons						/* Total logons */
			,rows								/* Screen length */
			,0									/* Highest message read */
			,useron.uls 						/* Total files uploaded */
			,useron.dls);						/* Total files downloaded */
866
		lfexpand(str,misc);
867
868
		write(file,str,strlen(str));

869
		sprintf(str,"%u\n%s\nCOM%u\n%s\n%lu\n%s\n%s\n"
870
871
872
873
874
875
876
			,8									/* Data bits */
			,online==ON_LOCAL?"LOCAL":"REMOTE"  /* Online local or remote */
			,cfg.com_port						/* COMx port */
			,useron.birth						/* User birthday */
			,dte_rate							/* DTE rate */
			,"FALSE"                            /* Already connected? */
			,"Normal Connection");              /* Normal or ARQ connect */
877
		lfexpand(str,misc);
878
879
		write(file,str,strlen(str));

880
		localtime_r(&now,&tm);
881
		sprintf(str,"%02d/%02d/%02d %02d:%02d\n%u\n%u\n"
882
883
884
			,tm.tm_mon+1,tm.tm_mday			/* Current date MM/DD/YY */
			,TM_YEAR(tm.tm_year)
			,tm.tm_hour,tm.tm_min 			/* Current time HH:MM */
885
886
			,cfg.node_num						/* Node number */
			,0);								/* Door number */
887
		lfexpand(str,misc);
888
889
		write(file,str,strlen(str));

890
891
		close(file); 
	}
892
893

	else if(type==XTRN_PCBOARD) { /* PCBoard Files */
894
895
896
897
		strcpy(tmp,"PCBOARD.SYS");
		if(misc&XTRN_LWRCASE)
			strlwr(tmp);
		sprintf(str,"%s%s",dropdir,tmp);
898
899
		if((file=nopen(str,O_WRONLY|O_CREAT|O_TRUNC))==-1) {
			errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_TRUNC);
900
901
			return; 
		}
902
903
904
905
906

		sprintf(str,"%2d%2d%2d%2d%c%2d%c%c%5u%-5.5s"
			,-1 								/* Display on/off */
			,0									/* Printer on/off */
			,sys_status&SS_SYSPAGE ? -1:0		/* Page Bell on/off */
907
			,startup->answer_sound[0] ? -1:0	/* Caller Alarm on/off */
908
			,' ' 								/* Sysop next flag */
909
910
911
912
913
914
915
916
917
918
919
920
			,0									/* Error corrected */
			,useron.misc&NO_EXASCII ? '7'       /* Graphics mode */
				: (useron.misc&(COLOR|ANSI))==(COLOR|ANSI) ? 'Y':'N'
			,'A'                                /* Node chat status */
			,(uint)dte_rate 					/* DTE Port Speed */
			,connection 						/* Connection description */
			);
		write(file,str,23);

		write(file,&useron.number,2);			/* User record number */

		strcpy(tmp,name);
921
		p=strchr(tmp,' ');
922
923
924
925
926
927
		if(p) *p=0;
		sprintf(str,"%-15.15s%-12s"
			,tmp								/* User's first name */
			,useron.pass);						/* User's password */
		write(file,str,27);

928
		if(localtime_r(&logontime,&tm)==NULL)
929
930
			i=0;
		else
931
			i=(tm.tm_hour*60)+tm.tm_min;
932
933
934
935
936
937
		write(file,&i,2);						/* Logon time in min since mid */

		now=time(NULL);
		i=-(((now-starttime)/60)+useron.ttoday);/* Negative minutes used */
		write(file,&i,2);

938
		sprintf(str,"%02d:%02d",tm.tm_hour,tm.tm_min);
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
		write(file,str,5);

		i=cfg.level_timepercall[useron.level];	/* Time allowed on */
		write(file,&i,2);

		i=0;									/* Allowed K-bytes for D/L */
		write(file,&i,2);
		write(file,&i,1);						/* Conference user was in */
		write(file,&i,2);						/* Conferences joined */
		write(file,&i,2);						/* "" */
		write(file,&i,2);						/* "" */
		write(file,&i,2);						/* Conferences scanned */
		write(file,&i,2);						/* "" */
		write(file,&i,2);						/* Conference add time */
		write(file,&i,2);						/* Upload/Sysop Chat time min */

		strcpy(str,"    ");
		write(file,str,4);						/* Language extension */

		sprintf(str,"%-25.25s",name);           /* User's full name */
		write(file,str,25);

		i=(tleft/60);
		write(file,&i,2);						/* Minutes remaining */

		write(file,&cfg.node_num,1);			/* Node number */

		sprintf(str,"%02d:%02d%2d%2d"           /* Scheduled Event time */
			,0 // sys_eventtime/60
			,0 // sys_eventtime%60
			,0 // sys_timed[0] ? -1:0				 /* Event active ? */
			,0									/* Slide event ? */
			);
		write(file,str,9);

		l=0L;
		write(file,&l,4);						/* Memorized message number */

		sprintf(str,"%d%c%c%d%s%c%c%d%d%d%c%c"
			,cfg.com_port						/* COM Port number */
979
980
			,' ' 								/* Reserved */
			,' ' 								/* "" */
981
982
983
984
985
986
987
988
989
990
991
992
			,(useron.misc&ANSI)==ANSI			/* 1=ANSI 0=NO ANSI */
			,"01-01-80"                         /* last event date */
			,0,0								/* last event minute */
			,0									/* caller exited to dos */
			,sys_status&SS_EVENT ? 1:0			/* event up coming */
			,0									/* stop uploads */
			,0,0								/* conference user was in */
			);
		write(file,str,19);

		close(file);			/* End of PCBOARD.SYS creation */

993
994
995
996
		strcpy(tmp,"USERS.SYS");
		if(misc&XTRN_LWRCASE)
			strlwr(tmp);
		sprintf(str,"%s%s",dropdir,tmp);
997
998
		if((file=nopen(str,O_WRONLY|O_CREAT|O_TRUNC))==-1) {
			errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_TRUNC);
999
1000
			return; 
		}
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036

		/* Write goof-ball header */

		i=145;
		write(file,&i,2);		/* PCBoard version number (i.e. 145) */
		l=useron.number;
		write(file,&l,4);		/* Record number for USER's file */
		i=218;
		write(file,&i,2);		/* Size of "fixed" user record */
		i=1;
		write(file,&i,2);		/* Number of conference areas */
		i=7;
		write(file,&i,2);		/* Number of bit map fields for conferences */
		i=5;
		write(file,&i,2);		/* Size of each bit map field */
		memset(str,0,15);
		write(file,str,15); 	/* Name of Third Party Application (if any) */
		i=0;
		write(file,&i,2);		/* Version number for application (if any) */
		write(file,&i,2);		/* Size of a "fixed length" record (if any) */
		write(file,&i,2);		/* Size of conference record (if any) */
		l=0;
		write(file,&l,4);		/* Offset of AppRec into USERS.INF (if any) */
		i=0;
		write(file,&i,1);		/* 1, if USERS.SYS file has been updated */

		/* Write fixed record portion */

		write(file,name,26);			/* Name */
		sprintf(str,"%.24s",useron.location);
		write(file,str,25); 			/* Location */
		write(file,useron.pass,13); 	/* Password */
		write(file,useron.phone,14);	/* Business or Data Phone */
		write(file,useron.phone,14);	/* Home or Voice Phone */
		i=unixtojulian(useron.laston);
		write(file,&i,2);				/* Date last on */
1037
1038
		localtime_r(&useron.laston,&tm);
		sprintf(str,"%02d:%02d",tm.tm_hour,tm.tm_min);
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
		write(file,str,6);				/* Last time on */
		if(useron.misc&EXPERT)
			i=1;
		else
			i=0;
		write(file,&i,1);				/* Expert mode */
		i='Z';
		write(file,&i,1);				/* Protocol (A-Z) */
		if(useron.misc&CLRSCRN)
			i=2;
		else
			i=0;
		write(file,&i,1);				/* bit packed flags */
		i=0;
		write(file,&i,2);				/* DOS date for last DIR Scan */
		i=useron.level;
		write(file,&i,2);				/* Security level */
		write(file,&useron.logons,2);	/* Number of times caller has connected */
		c=(char)rows;
		write(file,&c,1);				/* Page length */
		write(file,&useron.uls,2);		/* Number of uploads */
		write(file,&useron.dls,2);		/* Number of downloads */
		l=0;
		write(file,&l,4);				/* Number of download bytes today */
		write(file,&useron.note,31);	/* Comment #1 */
		write(file,&useron.comp,31);	/* Comment #2 */
		i=(now-starttime)/60;
		write(file,&i,2);				/* Minutes online (this logon?) */
		i=unixtojulian(useron.expire);
		write(file,&i,2);				/* Expiration date */
		i=cfg.expired_level;
		write(file,&i,2);				/* Expired security level */
		i=1;
		write(file,&i,2);				/* Current conference */
		write(file,&useron.dlb,4);		/* Bytes downloaded */
		write(file,&useron.ulb,4);		/* Bytes uploaded */
		if(useron.misc&DELETED)
			i=1;
		else
			i=0;
		write(file,&i,1);				/* Deleted? */
		l=useron.number;
		write(file,&l,4);				/* Record number in USERS.INF file */
		l=0;
		memset(str,0,9);
		write(file,str,9);				/* Reserved */
		write(file,&l,4);				/* Number of messages read */
		l=useron.posts+useron.emails+useron.fbacks;
		write(file,&l,4);				/* Number of messages left */
		close(file);

		/* End of USERS.SYS creation */
1091
	}
1092
1093

	else if(type==XTRN_SPITFIRE) {	 /* SpitFire SFDOORS.DAT File */
1094
1095
1096
1097
		strcpy(tmp,"SFDOORS.DAT");
		if(misc&XTRN_LWRCASE)
			strlwr(tmp);
		sprintf(str,"%s%s",dropdir,tmp);
1098
1099
		if((file=nopen(str,O_WRONLY|O_CREAT|O_TRUNC|O_TEXT))==-1) {
			errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_TRUNC|O_TEXT);
1100
1101
			return; 
		}
1102
1103

		now=time(NULL);
1104
		if(localtime_r(&now,&tm)==NULL)
1105
1106
			l=0;
		else
1107
1108
			l=((((long)tm.tm_hour*60L)+(long)tm.tm_min)*60L)
				+(long)tm.tm_sec;
1109
1110

		strcpy(tmp,name);
1111
		if((p=strchr(tmp,' '))!=NULL)
1112
1113
			*p=0;

1114
		sprintf(str,"%u\n%s\n%s\n%s\n%lu\n%u\n%lu\n%lu\n"
1115
1116
1117
1118
1119
1120
1121
1122
1123
			,useron.number						/* User number */
			,name								/* User name */
			,useron.pass						/* Password */
			,tmp								/* User's first name */
			,dte_rate							/* DTE Rate */
			,cfg.com_port						/* COM Port */
			,tleft/60							/* Time left in minutes */
			,l									/* Seconds since midnight (now) */
			);
1124
		lfexpand(str,misc);
1125
1126
		write(file,str,strlen(str));

1127
		if(localtime_r(&logontime,&tm)==NULL)
1128
1129
			l=0;
		else
1130
1131
			l=((((long)tm.tm_hour*60L)+(long)tm.tm_min)*60L)
				+(long)tm.tm_sec;
1132

1133
		sprintf(str,"%s\n%s\n%u\n%u\n%u\n%u\n%lu\n%lu\n%s\n"
1134
1135
			"%s\n%s\n%lu\n%s\n%u\n%u\n%u\n%u\n%u\n%lu\n%u\n"
			"%lu\n%lu\n%s\n%s\n"
1136
1137
1138
1139
1140
1141
1142
			,dropdir
			,useron.misc&ANSI ? "TRUE":"FALSE"  /* ANSI ? True or False */
			,useron.level						/* Security level */
			,useron.uls 						/* Total uploads */
			,useron.dls 						/* Total downloads */
			,cfg.level_timepercall[useron.level]/* Minutes allowed this call */
			,l									/* Secs since midnight (logon) */
1143
			,(long)(starttime-logontime)		/* Extra time in seconds */
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
			,"FALSE"                            /* Sysop next? */
			,"FALSE"                            /* From Front-end? */
			,"FALSE"                            /* Software Flow Control? */
			,dte_rate							/* DTE Rate */
			,"FALSE"                            /* Error correcting connection? */
			,0									/* Current conference */
			,0									/* Current file dir */
			,cfg.node_num						/* Node number */
			,15 								/* Downloads allowed per day */
			,0									/* Downloads already this day */
1154
			,100000L 							/* Download bytes allowed/day */
1155
1156
1157
1158
1159
1160
			,0									/* Downloaded bytes already today */
			,useron.ulb/1024L					/* Kbytes uploaded */
			,useron.dlb/1024L					/* Kbytes downloaded */
			,useron.phone						/* Phone Number */
			,useron.location					/* City, State */
			);
1161
		lfexpand(str,misc);
1162
1163
		write(file,str,strlen(str));

1164
1165
		close(file); 
	}
1166
1167

	else if(type==XTRN_UTI) { /* UTI v2.1 - UTIDOOR.TXT */
1168
1169
1170
1171
		strcpy(tmp,"UTIDOOR.TXT");
		if(misc&XTRN_LWRCASE)
			strlwr(tmp);
		sprintf(str,"%s%s",dropdir,tmp);
1172
1173
		if((file=nopen(str,O_WRONLY|O_CREAT|O_TRUNC|O_TEXT))==-1) {
			errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_TRUNC|O_TEXT);
1174
1175
			return; 
		}
1176
1177
1178

		strcpy(tmp,name);
		strupr(tmp);
1179
		sprintf(str,"%s\n%lu\n%u\n%lu\n%lu\n"
1180
1181
1182
1183
1184
			,tmp								/* User name */
			,cur_rate							/* Actual BPS rate */
			,online==ON_LOCAL ? 0: cfg.com_port /* COM Port */
			,dte_rate							/* DTE rate */
			,tleft);							/* Time left in sec */
1185
		lfexpand(str,misc);
1186
1187
		write(file,str,strlen(str));

1188
1189
		close(file); 
	}
1190
1191

	else if(type==XTRN_SR) { /* Solar Realms DOORFILE.SR */
1192
1193
1194
1195
		strcpy(tmp,"DOORFILE.SR");
		if(misc&XTRN_LWRCASE)
			strlwr(tmp);
		sprintf(str,"%s%s",dropdir,tmp);
1196
1197
		if((file=nopen(str,O_WRONLY|O_CREAT|O_TRUNC|O_TEXT))==-1) {
			errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_TRUNC|O_TEXT);
1198
1199
			return; 
		}
1200

1201
		sprintf(str,"%s\n%d\n%d\n%lu\n%lu\n%u\n%lu\n"
1202
1203
1204
1205
1206
1207
1208
1209
			,name								/* Complete name of user */
			,useron.misc&ANSI ? 1:0 			/* ANSI ? */
			,useron.misc&NO_EXASCII ? 0:1		/* IBM characters ? */
			,rows								/* Page length */
			,dte_rate							/* Baud rate */
			,online==ON_LOCAL ? 0:cfg.com_port	/* COM port */
			,tleft/60							/* Time left (in minutes) */
			);
1210
		lfexpand(str,misc);
1211
		write(file,str,strlen(str));
1212
1213
		close(file); 
	}
1214
1215

	else if(type==XTRN_TRIBBS) { /* TRIBBS.SYS */
1216
1217
1218
1219
		strcpy(tmp,"TRIBBS.SYS");
		if(misc&XTRN_LWRCASE)
			strlwr(tmp);
		sprintf(str,"%s%s",dropdir,tmp);
1220
1221
		if((file=nopen(str,O_WRONLY|O_CREAT|O_TRUNC|O_TEXT))==-1) {
			errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_TRUNC|O_TEXT);
1222
1223
			return; 
		}
1224

1225
		sprintf(str,"%u\n%s\n%s\n%u\n%c\n%c\n%lu\n%s\n%s\n%s\n"
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
			,useron.number						/* User's record number */
			,name								/* User's name */
			,useron.pass						/* User's password */
			,useron.level						/* User's level */
			,useron.misc&EXPERT ? 'Y':'N'       /* Expert? */
			,useron.misc&ANSI ? 'Y':'N'         /* ANSI? */
			,tleft/60							/* Minutes left */
			,useron.phone						/* User's phone number */
			,useron.location					/* User's city and state */
			,useron.birth						/* User's birth date */
			);
1237
		lfexpand(str,misc);