bat_xfer.cpp 24.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
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
39
40
41
42
43
44
/* bat_xfer.cpp */

/* Synchronet batch file transfer functions */

/* $Id$ */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
 * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html		*
 *																			*
 * 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 batch menu section                                           */
/****************************************************************************/
void sbbs_t::batchmenu()
{
45
46
47
48
49
50
    char	str[129],tmp2[250],done=0,ch;
	char 	tmp[512];
	uint	i,n,xfrprot,xfrdir;
    ulong	totalcdt,totalsize,totaltime;
    time_t	start,end;
    file_t	f;
51
52
53

	if(!batdn_total && !batup_total && cfg.upload_dir==INVALID_DIR) {
		bputs(text[NoFilesInBatchQueue]);
54
55
		return; 
	}
56
	if(useron.misc&(RIP|WIP) && !(useron.misc&EXPERT))
57
		menu("batchxfer");
58
59
60
61
62
63
64
65
66
	lncntr=0;
	while(online && !done && (batdn_total || batup_total
		|| cfg.upload_dir!=INVALID_DIR)) {
		if(!(useron.misc&(EXPERT|RIP|WIP))) {
			sys_status&=~SS_ABORT;
			if(lncntr) {
				SYNC;
				CRLF;
				if(lncntr)          /* CRLF or SYNC can cause pause */
67
68
69
70
					pause(); 
			}
			menu("batchxfr"); 
		}
71
72
73
74
75
76
77
78
		ASYNC;
		bputs(text[BatchMenuPrompt]);
		ch=(char)getkeys("BCDLQRU?\r",0);
		if(ch>SP)
			logch(ch,0);
		switch(ch) {
			case '?':
				if(useron.misc&(EXPERT|RIP|WIP))
79
					menu("batchxfr");
80
81
82
83
84
85
86
87
88
				break;
			case CR:
			case 'Q':
				lncntr=0;
				done=1;
				break;
			case 'B':   /* Bi-directional transfers */
				if(useron.rest&FLAG('D')) {
					bputs(text[R_Download]);
89
90
					break; 
				}
91
92
				if(useron.rest&FLAG('U')) {
					bputs(text[R_Upload]);
93
94
					break; 
				}
95
96
				if(!batdn_total) {
					bputs(text[DownloadQueueIsEmpty]);
97
98
					break; 
				}
99
100
				if(!batup_total && cfg.upload_dir==INVALID_DIR) {
					bputs(text[UploadQueueIsEmpty]);
101
102
					break; 
				}
103
104
105
106
107
108
				for(i=0,totalcdt=0;i<batdn_total;i++)
						totalcdt+=batdn_cdt[i];
				if(!(useron.exempt&FLAG('D'))
					&& totalcdt>useron.cdt+useron.freecdt) {
					bprintf(text[YouOnlyHaveNCredits]
						,ultoac(useron.cdt+useron.freecdt,tmp));
109
110
					break; 
				}
111
112
113
				for(i=0,totalsize=totaltime=0;i<batdn_total;i++) {
					totalsize+=batdn_size[i];
					if(!(cfg.dir[batdn_dir[i]]->misc&DIR_TFREE) && cur_cps)
114
115
						totaltime+=batdn_size[i]/(ulong)cur_cps; 
				}
116
117
				if(!(useron.exempt&FLAG('T')) && !SYSOP && totaltime>timeleft) {
					bputs(text[NotEnoughTimeToDl]);
118
119
					break; 
				}
120
				menu("biprot");
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
				if(!create_batchdn_lst())
					break;
				if(!create_batchup_lst())
					break;
				if(!create_bimodem_pth())
					break;
				SYNC;
				mnemonics(text[ProtocolOrQuit]);
				strcpy(tmp2,"Q");
				for(i=0;i<cfg.total_prots;i++)
					if(cfg.prot[i]->bicmd[0] && chk_ar(cfg.prot[i]->ar,&useron)) {
						sprintf(tmp,"%c",cfg.prot[i]->mnemonic);
						strcat(tmp2,tmp); }
				ungetkey(useron.prot);
				ch=(char)getkeys(tmp2,0);
				if(ch=='Q')
					break;
				for(i=0;i<cfg.total_prots;i++)
					if(cfg.prot[i]->bicmd[0] && cfg.prot[i]->mnemonic==ch
						&& chk_ar(cfg.prot[i]->ar,&useron))
						break;
				if(i<cfg.total_prots) {
					xfrprot=i;
					action=NODE_BXFR;
					SYNC;
					for(i=0;i<batdn_total;i++)
						if(cfg.dir[batdn_dir[i]]->seqdev) {
							lncntr=0;
							unpadfname(batdn_name[i],tmp);
							sprintf(tmp2,"%s%s",cfg.temp_dir,tmp);
							if(!fexist(tmp2)) {
								seqwait(cfg.dir[batdn_dir[i]]->seqdev);
								bprintf(text[RetrievingFile],tmp);
								sprintf(str,"%s%s"
									,batdn_alt[i]>0 && batdn_alt[i]<=cfg.altpaths
									? cfg.altpath[batdn_alt[i]-1]
									: cfg.dir[batdn_dir[i]]->path
									,tmp);
								mv(str,tmp2,1); /* copy the file to temp dir */
								getnodedat(cfg.node_num,&thisnode,1);
								thisnode.aux=0xff;
								putnodedat(cfg.node_num,&thisnode);
163
164
165
								CRLF; 
							} 
						}
166
167
168
169
170
171
172
173
174
175
176
177
178
179
					sprintf(str,"%sBATCHDN.LST",cfg.node_dir);
					sprintf(tmp2,"%sBATCHUP.LST",cfg.node_dir);
					start=time(NULL);
					protocol(cmdstr(cfg.prot[xfrprot]->bicmd,str,tmp2,NULL),0);
					end=time(NULL);
					for(i=0;i<batdn_total;i++)
						if(cfg.dir[batdn_dir[i]]->seqdev) {
							unpadfname(batdn_name[i],tmp);
							sprintf(tmp2,"%s%s",cfg.temp_dir,tmp);
							remove(tmp2); }
					batch_upload();
					batch_download(xfrprot);
					if(batdn_total)     /* files still in queue, not xfered */
						notdownloaded(totalsize,start,end);
180
181
					autohangup(); 
				}
182
183
184
185
186
				break;
			case 'C':
				if(batup_total) {
					if(!noyes(text[ClearUploadQueueQ])) {
						batup_total=0;
187
188
189
						bputs(text[UploadQueueCleared]); 
					} 
				}
190
191
192
193
194
195
196
197
198
				if(batdn_total) {
					if(!noyes(text[ClearDownloadQueueQ])) {
						for(i=0;i<batdn_total;i++) {
							f.dir=batdn_dir[i];
							f.datoffset=batdn_offset[i];
							f.size=batdn_size[i];
							strcpy(f.name,batdn_name[i]);
							closefile(&f); }
						batdn_total=0;
199
200
201
						bputs(text[DownloadQueueCleared]); 
					} 
				}
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
				break;
			case 'D':
				if(useron.rest&FLAG('D')) {
					bputs(text[R_Download]);
					break; }
				if(!batdn_total) {
					bputs(text[DownloadQueueIsEmpty]);
					break; }
				start_batch_download();
				break;
			case 'L':
				if(batup_total) {
					bputs(text[UploadQueueLstHdr]);
					for(i=0;i<batup_total;i++)
						bprintf(text[UploadQueueLstFmt],i+1,batup_name[i]
							,batup_desc[i]); }
				if(batdn_total) {
					bputs(text[DownloadQueueLstHdr]);
					for(i=0,totalcdt=0,totalsize=0;i<batdn_total;i++) {
						bprintf(text[DownloadQueueLstFmt],i+1
							,batdn_name[i],ultoac(batdn_cdt[i],tmp)
							,ultoac(batdn_size[i],str)
							,cur_cps
							? sectostr(batdn_size[i]/(ulong)cur_cps,tmp2)
							: "??:??:??");
						totalsize+=batdn_size[i];
						totalcdt+=batdn_cdt[i]; }
					bprintf(text[DownloadQueueTotals]
						,ultoac(totalcdt,tmp),ultoac(totalsize,str),cur_cps
						? sectostr(totalsize/(ulong)cur_cps,tmp2)
						: "??:??:??"); }
				break;  /* Questionable line ^^^, see note above function */
			case 'R':
				if(batup_total) {
					bprintf(text[RemoveWhichFromUlQueue],batup_total);
					n=getnum(batup_total);
					if(n>=1) {
						n--;
						batup_total--;
						while(n<batup_total) {
							batup_dir[n]=batup_dir[n+1];
							batup_misc[n]=batup_misc[n+1];
							batup_alt[n]=batup_alt[n+1];
							strcpy(batup_name[n],batup_name[n+1]);
							strcpy(batup_desc[n],batup_desc[n+1]);
							n++; }
						if(!batup_total)
249
250
251
252
							bputs(text[UploadQueueCleared]); 
					} 
				}
				if(batdn_total) {
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
					bprintf(text[RemoveWhichFromDlQueue],batdn_total);
					n=getnum(batdn_total);
					if(n>=1) {
						n--;
						f.dir=batdn_dir[n];
						strcpy(f.name,batdn_name[n]);
						f.datoffset=batdn_offset[n];
						f.size=batdn_size[n];
						closefile(&f);
						batdn_total--;
						while(n<batdn_total) {
							strcpy(batdn_name[n],batdn_name[n+1]);
							batdn_dir[n]=batdn_dir[n+1];
							batdn_cdt[n]=batdn_cdt[n+1];
							batdn_alt[n]=batdn_alt[n+1];
							batdn_size[n]=batdn_size[n+1];
							batdn_offset[n]=batdn_offset[n+1];
270
271
							n++; 
						}
272
						if(!batdn_total)
273
274
275
							bputs(text[DownloadQueueCleared]); 
					} 
				}
276
277
278
279
				break;
		   case 'U':
				if(useron.rest&FLAG('U')) {
					bputs(text[R_Upload]);
280
281
					break; 
				}
282
283
				if(!batup_total && cfg.upload_dir==INVALID_DIR) {
					bputs(text[UploadQueueIsEmpty]);
284
285
					break; 
				}
286
				menu("batuprot");
287
288
289
290
291
292
293
294
295
296
				if(!create_batchup_lst())
					break;
				if(!create_bimodem_pth())
					break;
				ASYNC;
				mnemonics(text[ProtocolOrQuit]);
				strcpy(str,"Q");
				for(i=0;i<cfg.total_prots;i++)
					if(cfg.prot[i]->batulcmd[0] && chk_ar(cfg.prot[i]->ar,&useron)) {
						sprintf(tmp,"%c",cfg.prot[i]->mnemonic);
297
298
						strcat(str,tmp); 
					}
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
				ch=(char)getkeys(str,0);
				if(ch=='Q')
					break;
				for(i=0;i<cfg.total_prots;i++)
					if(cfg.prot[i]->batulcmd[0] && cfg.prot[i]->mnemonic==ch
						&& chk_ar(cfg.prot[i]->ar,&useron))
						break;
				if(i<cfg.total_prots) {
					sprintf(str,"%sBATCHUP.LST",cfg.node_dir);
					xfrprot=i;
					if(batup_total)
						xfrdir=batup_dir[0];
					else
						xfrdir=cfg.upload_dir;
					action=NODE_ULNG;
					SYNC;
					if(online==ON_REMOTE) {
316
						delfiles(cfg.temp_dir,ALLFILES);
317
318
319
320
						start=time(NULL);
						protocol(cmdstr(cfg.prot[xfrprot]->batulcmd,str,nulstr,NULL),1);
						end=time(NULL);
						if(!(cfg.dir[xfrdir]->misc&DIR_ULTIME))
321
322
							starttime+=end-start; 
					}
323
					batch_upload();
324
					delfiles(cfg.temp_dir,ALLFILES);
325
326
327
328
329
					autohangup(); 
				}
				break; 
		} 
	}
330
	delfiles(cfg.temp_dir,ALLFILES);
331
332
333
334
335
336
337
}

/****************************************************************************/
/* Download files from batch queue                                          */
/****************************************************************************/
void sbbs_t::start_batch_download()
{
338
339
340
341
342
343
344
345
	char	ch,str[256],tmp2[256],tmp3[128],fname[64];
	char 	tmp[512];
    int		j;
    uint	i,xfrprot;
    ulong	totalcdt,totalsize,totaltime;
    time_t	start,end,t;
	struct	tm * tm;
    file_t	f;
346
347
348
349
350
351
352
353
354
355

	if(useron.rest&FLAG('D')) {     /* Download restriction */
		bputs(text[R_Download]);
		return; }
	for(i=0,totalcdt=0;i<batdn_total;i++)
		totalcdt+=batdn_cdt[i];
	if(!(useron.exempt&FLAG('D'))
		&& totalcdt>useron.cdt+useron.freecdt) {
		bprintf(text[YouOnlyHaveNCredits]
			,ultoac(useron.cdt+useron.freecdt,tmp));
356
357
		return; 
	}
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387

	if(online==ON_LOCAL) {          /* Local download */
		bputs(text[EnterPath]);
		if(!getstr(str,60,K_LINE|K_UPPER))
			return;
		backslash(str);
		for(i=0;i<batdn_total;i++) {
			curdirnum=batdn_dir[i]; 		/* for ARS */
			lncntr=0;
			unpadfname(batdn_name[i],tmp);
			sprintf(tmp2,"%s%s",str,tmp);
			seqwait(cfg.dir[batdn_dir[i]]->seqdev);
			bprintf(text[RetrievingFile],tmp);
			sprintf(tmp3,"%s%s"
				,batdn_alt[i]>0 && batdn_alt[i]<=cfg.altpaths
				? cfg.altpath[batdn_alt[i]-1]
				: cfg.dir[batdn_dir[i]]->path
				,tmp);
			j=mv(tmp3,tmp2,1);
			getnodedat(cfg.node_num,&thisnode,1);
			thisnode.aux=30; /* clear the seq dev # */
			putnodedat(cfg.node_num,&thisnode);
			CRLF;
			if(j)   /* copy unsuccessful */
				return;
			for(j=0;j<cfg.total_dlevents;j++)
				if(!stricmp(cfg.dlevent[j]->ext,batdn_name[i]+9)
					&& chk_ar(cfg.dlevent[j]->ar,&useron)) {
					bputs(cfg.dlevent[j]->workstr);
					external(cmdstr(cfg.dlevent[j]->cmd,tmp2,nulstr,NULL),EX_OUTL);
388
389
					CRLF; 
				}
390
391
392
393
394
395
396
397
398
			}
		for(i=0;i<batdn_total;i++) {
			curdirnum=batdn_dir[i]; 		/* for ARS */
			f.dir=batdn_dir[i];
			strcpy(f.name,batdn_name[i]);
			f.datoffset=batdn_offset[i];
			f.size=batdn_size[i];
			f.altpath=batdn_alt[i];
			downloadfile(&f);
399
400
			closefile(&f); 
		}
401
		batdn_total=0;
402
403
		return; 
	}
404
405
406
407

	for(i=0,totalsize=totaltime=0;i<batdn_total;i++) {
		totalsize+=batdn_size[i];
		if(!(cfg.dir[batdn_dir[i]]->misc&DIR_TFREE) && cur_cps)
408
409
			totaltime+=batdn_size[i]/(ulong)cur_cps; 
	}
410
411
	if(!(useron.exempt&FLAG('T')) && !SYSOP && totaltime>timeleft) {
		bputs(text[NotEnoughTimeToDl]);
412
413
		return; 
	}
414
	menu("batdprot");
415
416
417
418
419
420
421
422
423
424
	if(!create_batchdn_lst())
		return;
	if(!create_bimodem_pth())
		return;
	ASYNC;
	mnemonics(text[ProtocolOrQuit]);
	strcpy(tmp2,"Q");
	for(i=0;i<cfg.total_prots;i++)
		if(cfg.prot[i]->batdlcmd[0] && chk_ar(cfg.prot[i]->ar,&useron)) {
			sprintf(tmp,"%c",cfg.prot[i]->mnemonic);
425
426
			strcat(tmp2,tmp); 
		}
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
	ungetkey(useron.prot);
	ch=(char)getkeys(tmp2,0);
	if(ch=='Q' || sys_status&SS_ABORT)
		return;
	for(i=0;i<cfg.total_prots;i++)
		if(cfg.prot[i]->batdlcmd[0] && cfg.prot[i]->mnemonic==ch
			&& chk_ar(cfg.prot[i]->ar,&useron))
			break;
	if(i<cfg.total_prots) {
		xfrprot=i;
		for(i=0;i<batdn_total;i++) {
			curdirnum=batdn_dir[i]; 		/* for ARS */
			unpadfname(batdn_name[i],fname);
			if(cfg.dir[batdn_dir[i]]->seqdev) {
				lncntr=0;
				sprintf(tmp2,"%s%s",cfg.temp_dir,fname);
				if(!fexist(tmp2)) {
					seqwait(cfg.dir[batdn_dir[i]]->seqdev);
					bprintf(text[RetrievingFile],fname);
					sprintf(str,"%s%s"
						,batdn_alt[i]>0 && batdn_alt[i]<=cfg.altpaths
						? cfg.altpath[batdn_alt[i]-1]
						: cfg.dir[batdn_dir[i]]->path
						,fname);
					mv(str,tmp2,1); /* copy the file to temp dir */
					getnodedat(cfg.node_num,&thisnode,1);
					thisnode.aux=40; /* clear the seq dev # */
					putnodedat(cfg.node_num,&thisnode);
455
456
457
					CRLF; 
				} 
			}
458
459
460
461
462
463
464
465
466
467
468
469
470
471
			else
				sprintf(tmp2,"%s%s"
					,batdn_alt[i]>0 && batdn_alt[i]<=cfg.altpaths
					? cfg.altpath[batdn_alt[i]-1]
					: cfg.dir[batdn_dir[i]]->path
					,fname);
			sprintf(str,"total_dlevents=%d",cfg.total_dlevents);
			for(j=0;j<cfg.total_dlevents;j++) {
				if(stricmp(cfg.dlevent[j]->ext,batdn_name[i]+9))
					continue;
				if(!chk_ar(cfg.dlevent[j]->ar,&useron))
					continue;
				bputs(cfg.dlevent[j]->workstr);
				external(cmdstr(cfg.dlevent[j]->cmd,tmp2,nulstr,NULL),EX_OUTL);
472
				CRLF; 
473
			}
474
		}
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493

		sprintf(str,"%sBATCHDN.LST",cfg.node_dir);
		getnodedat(cfg.node_num,&thisnode,1);
		action=NODE_DLNG;
		t=now;
		if(cur_cps) 
			t+=(totalsize/(ulong)cur_cps);
		tm=gmtime(&t);
		if(tm==NULL)
			return;
		thisnode.aux=(tm->tm_hour*60)+tm->tm_min;
		thisnode.action=action;
		putnodedat(cfg.node_num,&thisnode); /* calculate ETA */
		start=time(NULL);
		protocol(cmdstr(cfg.prot[xfrprot]->batdlcmd,str,nulstr,NULL),0);
		end=time(NULL);
		batch_download(xfrprot);
		if(batdn_total)
			notdownloaded(totalsize,start,end);
494
		autohangup(); 
495
	}
496
}
497
498
499
500
501
502
503
504
505
506
507
508
509
510

/****************************************************************************/
/* Creates the file BATCHDN.LST in the node directory. Returns true if      */
/* everything goes okay, false if not.                                      */
/****************************************************************************/
bool sbbs_t::create_batchdn_lst()
{
	char	str[256];
	int		file;
	uint	i;

	sprintf(str,"%sBATCHDN.LST",cfg.node_dir);
	if((file=nopen(str,O_WRONLY|O_CREAT|O_TRUNC))==-1) {
		errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_TRUNC);
511
512
		return(false); 
	}
513
514
515
516
517
518
519
520
521
	for(i=0;i<batdn_total;i++) {
		if(batdn_dir[i]>=cfg.total_dirs || cfg.dir[batdn_dir[i]]->seqdev)
			strcpy(str,cfg.temp_dir);
		else
			strcpy(str,batdn_alt[i]>0 && batdn_alt[i]<=cfg.altpaths
				? cfg.altpath[batdn_alt[i]-1] : cfg.dir[batdn_dir[i]]->path);
		write(file,str,strlen(str));
		unpadfname(batdn_name[i],str);
		strcat(str,crlf);
522
523
		write(file,str,strlen(str)); 
	}
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
	close(file);
	return(true);
}

/****************************************************************************/
/* Creates the file BATCHUP.LST in the node directory. Returns true if      */
/* everything goes okay, false if not.                                      */
/* This list is not used by any protocols to date.                          */
/****************************************************************************/
bool sbbs_t::create_batchup_lst()
{
    char	str[256];
    int		file;
	uint	i;

	sprintf(str,"%sBATCHUP.LST",cfg.node_dir);
	if((file=nopen(str,O_WRONLY|O_CREAT|O_TRUNC))==-1) {
		errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_TRUNC);
542
543
		return(false); 
	}
544
545
546
547
548
549
550
551
552
	for(i=0;i<batup_total;i++) {
		if(batup_dir[i]>=cfg.total_dirs)
			strcpy(str,cfg.temp_dir);
		else
			strcpy(str,batup_alt[i]>0 && batup_alt[i]<=cfg.altpaths
				? cfg.altpath[batup_alt[i]-1] : cfg.dir[batup_dir[i]]->path);
		write(file,str,strlen(str));
		unpadfname(batup_name[i],str);
		strcat(str,crlf);
553
554
		write(file,str,strlen(str)); 
	}
555
556
557
558
559
560
561
562
563
564
565
	close(file);
	return(true);
}

/****************************************************************************/
/* Creates the file BIMODEM.PTH in the node directory. Returns true if      */
/* everything goes okay, false if not.                                      */
/****************************************************************************/
bool sbbs_t::create_bimodem_pth()
{
    char	str[256],tmp2[512];
566
	char 	tmp[512];
567
568
569
570
571
572
    int		file;
	uint	i;

	sprintf(str,"%sBIMODEM.PTH",cfg.node_dir);  /* Create bimodem file */
	if((file=nopen(str,O_WRONLY|O_CREAT|O_TRUNC))==-1) {
		errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_CREAT|O_TRUNC);
573
574
		return(false); 
	}
575
576
577
578
579
580
581
	for(i=0;i<batup_total;i++) {
		sprintf(str,"%s%s",batup_dir[i]>=cfg.total_dirs ? cfg.temp_dir
			: batup_alt[i]>0 && batup_alt[i]<=cfg.altpaths
			? cfg.altpath[batup_alt[i]-1] : cfg.dir[batup_dir[i]]->path
			,unpadfname(batup_name[i],tmp));
		sprintf(tmp2,"D       %-80.80s%-160.160s"
			,unpadfname(batup_name[i],tmp),str);
582
583
		write(file,tmp2,248); 
	}
584
585
586
587
588
589
590
	for(i=0;i<batdn_total;i++) {
		sprintf(str,"%s%s"
			,(batdn_dir[i]>=cfg.total_dirs || cfg.dir[batdn_dir[i]]->seqdev)
			? cfg.temp_dir : batdn_alt[i]>0 && batdn_alt[i]<=cfg.altpaths
				? cfg.altpath[batdn_alt[i]-1] : cfg.dir[batdn_dir[i]]->path
				,unpadfname(batdn_name[i],tmp));
		sprintf(tmp2,"U       %-240.240s",str);
591
592
		write(file,tmp2,248); 
	}
593
594
595
596
597
598
599
600
601
602
	close(file);
	return(true);
}

/****************************************************************************/
/* Processes files that were supposed to be received in the batch queue     */
/****************************************************************************/
void sbbs_t::batch_upload()
{
    char	str1[256],str2[256];
603
	char 	tmp[512];
604
605
	uint	i,j,x,y;
    file_t	f;
606
607
	DIR*	dir;
	DIRENT*	dirent;
608
609
610
611
612
613
614
615
616
617
618

	for(i=0;i<batup_total;) {
		curdirnum=batup_dir[i]; 			/* for ARS */
		lncntr=0;                               /* defeat pause */
		unpadfname(batup_name[i],tmp);
		sprintf(str1,"%s%s",cfg.temp_dir,tmp);
		sprintf(str2,"%s%s",cfg.dir[batup_dir[i]]->path,tmp);
		if(fexist(str1) && fexist(str2)) { /* file's in two places */
			bprintf(text[FileAlreadyThere],batup_name[i]);
			remove(str1);    /* this is the one received */
			i++;
619
620
			continue; 
		}
621
622
623
624
625
626
627
628
629
630
631
632
633
634
		if(fexist(str1))
			mv(str1,str2,0);
		strcpy(f.name,batup_name[i]);
		strcpy(f.desc,batup_desc[i]);
		f.dir=batup_dir[i];
		f.misc=batup_misc[i];
		f.altpath=batup_alt[i];
		if(uploadfile(&f)) {
			batup_total--;
			for(j=i;j<batup_total;j++) {
				batup_dir[j]=batup_dir[j+1];
				batup_alt[j]=batup_alt[j+1];
				batup_misc[j]=batup_misc[j+1];
				strcpy(batup_name[j],batup_name[j+1]);
635
636
637
638
639
				strcpy(batup_desc[j],batup_desc[j+1]); 
			} 
		}
		else i++; 
	}
640
641
	if(cfg.upload_dir==INVALID_DIR)
		return;
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
	dir=opendir(cfg.temp_dir);
	while((dirent=readdir(dir))!=NULL) {
		sprintf(str1,"%s%s",cfg.temp_dir,dirent->d_name);
		if(isdir(str1))
			continue;
		memset(&f,0,sizeof(file_t));
		f.dir=cfg.upload_dir;
		padfname(dirent->d_name,f.name);
		strupr(f.name);
		for(x=0;x<usrlibs;x++) {
			for(y=0;y<usrdirs[x];y++)
				if(cfg.dir[usrdir[x][y]]->misc&DIR_DUPES
					&& findfile(&cfg,usrdir[x][y],f.name))
					break;
			if(y<usrdirs[x])
				break; 
658
		}
659
660
661
662
663
664
665
666
667
668
		sprintf(str2,"%s%s",cfg.dir[f.dir]->path,dirent->d_name);
		if(x<usrlibs || fexist(str2)) {
			bprintf(text[FileAlreadyOnline],f.name);
			remove(str1); 
		} else {
			mv(str1,str2,0);
			uploadfile(&f); 
		}
	}
	closedir(dir);
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
}

/****************************************************************************/
/* Processes files that were supposed to be sent from the batch queue       */
/* xfrprot is -1 if downloading files from within QWK (no DSZLOG)           */
/****************************************************************************/
void sbbs_t::batch_download(int xfrprot)
{
    uint	i,j;
    file_t	f;

	for(i=0;i<batdn_total;) {
		lncntr=0;                               /* defeat pause */
		f.dir=curdirnum=batdn_dir[i];
		strcpy(f.name,batdn_name[i]);
		f.datoffset=batdn_offset[i];
		f.size=batdn_size[i];
	/*											   Removed 05/18/95
		if(cfg.dir[f.dir]->misc&DIR_TFREE && cur_cps)  Looks like it gave back double
			starttime+=f.size/(ulong)cur_cps;
	*/
		f.altpath=batdn_alt[i];
		if(xfrprot==-1 || (cfg.prot[xfrprot]->misc&PROT_DSZLOG && checkprotlog(&f))
			|| !(cfg.prot[xfrprot]->misc&PROT_DSZLOG)) {
			if(cfg.dir[f.dir]->misc&DIR_TFREE && cur_cps)
				starttime+=f.size/(ulong)cur_cps;
			downloadfile(&f);
			closefile(&f);
			batdn_total--;
			for(j=i;j<batdn_total;j++) {
				strcpy(batdn_name[j],batdn_name[j+1]);
				batdn_dir[j]=batdn_dir[j+1];
				batdn_cdt[j]=batdn_cdt[j+1];
				batdn_alt[j]=batdn_alt[j+1];
				batdn_size[j]=batdn_size[j+1];
704
705
706
707
708
				batdn_offset[j]=batdn_offset[j+1]; 
			} 
		}
		else i++; 
	}
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
739
}

/****************************************************************************/
/* Adds a list of files to the batch download queue 						*/
/****************************************************************************/
void sbbs_t::batch_add_list(char *list)
{
    char	str[128];
	int		file;
	uint	i,j,k;
    FILE *	stream;
	file_t	f;

	if((stream=fnopen(&file,list,O_RDONLY))!=NULL) {
		bputs(text[SearchingAllLibs]);
		while(!feof(stream)) {
			checkline();
			if(!online)
				break;
			if(!fgets(str,127,stream))
				break;
			truncsp(str);
			sprintf(f.name,"%.12s",str);
			strupr(f.name);
			lncntr=0;
			for(i=k=0;i<usrlibs;i++) {
				for(j=0;j<usrdirs[i];j++,k++) {
					outchar('.');
					if(k && !(k%5))
						bputs("\b\b\b\b\b     \b\b\b\b\b");
					if(findfile(&cfg,usrdir[i][j],f.name))
740
741
						break; 
				}
742
				if(j<usrdirs[i])
743
744
					break; 
			}
745
746
747
748
749
750
751
752
			if(i<usrlibs) {
				f.dir=usrdir[i][j];
				getfileixb(&cfg,&f);
				f.size=0;
				getfiledat(&cfg,&f);
				if(f.size==-1L)
					bprintf(text[FileIsNotOnline],f.name);
				else
753
754
755
					addtobatdl(&f); 
			} 
		}
756
757
		fclose(stream);
		remove(list);
758
759
		CRLF; 
	}
760
761
762
763
764
765
766
}

/**************************************************************************/
/* Add file 'f' to batch download queue. Return 1 if successful, 0 if not */
/**************************************************************************/
bool sbbs_t::addtobatdl(file_t* f)
{
767
768
769
770
    char	str[256],tmp2[256];
	char 	tmp[512];
    uint	i;
	ulong	totalcdt, totalsize, totaltime;
771
772
773

	if(useron.rest&FLAG('D')) {
		bputs(text[R_Download]);
774
775
		return(false); 
	}
776
777
778
779
780
781
782
	/***
	sprintf(str,"%s%s",f->altpath>0 && f->altpath<=altpaths ? altpath[f->altpath-1]
		: cfg.dir[f->dir]->path,unpadfname(f->name,tmp));
	***/
	for(i=0;i<batdn_total;i++) {
		if(!strcmp(batdn_name[i],f->name) && f->dir==batdn_dir[i]) {
			bprintf(text[FileAlreadyInQueue],f->name);
783
784
785
			return(false); 
		} 
	}
786
787
788
	if(f->size<=0 /* !fexist(str) */) {
		bprintf(text[CantAddToQueue],f->name);
		bputs(text[FileIsNotOnline]);
789
790
		return(false); 
	}
791
792
793
	if(batdn_total>=cfg.max_batdn) {
		bprintf(text[CantAddToQueue],f->name);
		bputs(text[BatchDlQueueIsFull]);
794
795
		return(false); 
	}
796
797
798
799
800
801
802
	for(i=0,totalcdt=0;i<batdn_total;i++)
		totalcdt+=batdn_cdt[i];
	if(cfg.dir[f->dir]->misc&DIR_FREE) f->cdt=0L;
	totalcdt+=f->cdt;
	if(!(useron.exempt&FLAG('D')) && totalcdt>useron.cdt+useron.freecdt) {
		bprintf(text[CantAddToQueue],f->name);
		bprintf(text[YouOnlyHaveNCredits],ultoac(useron.cdt+useron.freecdt,tmp));
803
804
		return(false); 
	}
805
806
807
	if(!chk_ar(cfg.dir[f->dir]->dl_ar,&useron)) {
		bprintf(text[CantAddToQueue],f->name);
		bputs(text[CantDownloadFromDir]);
808
809
		return(false); 
	}
810
811
812
	for(i=0,totalsize=totaltime=0;i<batdn_total;i++) {
		totalsize+=batdn_size[i];
		if(!(cfg.dir[batdn_dir[i]]->misc&DIR_TFREE) && cur_cps)
813
814
			totaltime+=batdn_size[i]/(ulong)cur_cps; 
	}
815
816
817
818
819
820
	totalsize+=f->size;
	if(!(cfg.dir[f->dir]->misc&DIR_TFREE) && cur_cps)
		totaltime+=f->size/(ulong)cur_cps;
	if(!(useron.exempt&FLAG('T')) && totaltime>timeleft) {
		bprintf(text[CantAddToQueue],f->name);
		bputs(text[NotEnoughTimeToDl]);
821
822
		return(false); 
	}
823
824
825
826
827
828
829
830
831
832
833
834
835
836
	strcpy(batdn_name[batdn_total],f->name);
	batdn_dir[batdn_total]=f->dir;
	batdn_cdt[batdn_total]=f->cdt;
	batdn_offset[batdn_total]=f->datoffset;
	batdn_size[batdn_total]=f->size;
	batdn_alt[batdn_total]=f->altpath;
	batdn_total++;
	openfile(f);
	bprintf(text[FileAddedToBatDlQueue]
		,f->name,batdn_total,cfg.max_batdn,ultoac(totalcdt,tmp)
		,ultoac(totalsize,tmp2)
		,sectostr(totalsize/(ulong)cur_cps,str));
	return(true);
}