Skip to content

Latest commit

 

History

History
338 lines (315 loc) · 9.63 KB

file8.pas

File metadata and controls

338 lines (315 loc) · 9.63 KB
 
Nov 25, 2000
Nov 25, 2000
1
{$A+,B+,E+,F+,I+,L+,N-,O+,R-,S+,V-}
Nov 18, 2000
Nov 18, 2000
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
unit file8;
interface
uses
crt,dos,
{rcg11172000 no overlay under Linux.}
{overlay,}
myio,
file0, file6, file7,
execbat,
common;
procedure ymbadd(fname:astr);
procedure send1(fn:astr; var dok,kabort:boolean);
procedure receive1(fn:astr; resumefile:boolean; var dok,kabort,addbatch:boolean);
implementation
procedure abeep;
var a,b,c,i,j:integer;
begin
for j:=1 to 3 do begin
for i:=1 to 3 do begin
a:=i*500;
b:=a;
while (b>a-300) do begin
sound(b);
dec(b,50);
c:=a+1000;
while (c>a+700) do begin
sound(c); dec(c,50);
delay(2);
end;
end;
end;
delay(50);
nosound;
end;
end;
function checkfileratio:integer;
var i,r,t:real;
j:integer;
badratio:boolean;
begin
t:=thisuser.dk;
if (numbatchfiles<>0) then
for j:=1 to numbatchfiles do begin
loaduboard(batch[j].section);
if (not (fbnoratio in memuboard.fbstat)) then
t:=t+(batch[j].blks div 8);
end;
badratio:=FALSE;
r:=(t+0.001)/(thisuser.uk+0.001);
if (r>systat.dlkratio[thisuser.sl]) then badratio:=TRUE;
i:=(thisuser.downloads+numbatchfiles+0.001)/(thisuser.uploads+0.001);
if (i>systat.dlratio[thisuser.sl]) then badratio:=TRUE;
if ((aacs(systat.nodlratio)) or (fnodlratio in thisuser.ac)) then
badratio:=FALSE;
if (not systat.uldlratio) then badratio:=FALSE;
checkfileratio:=0;
if (badratio) then
if (numbatchfiles=0) then checkfileratio:=1 else checkfileratio:=2;
loaduboard(fileboard);
if (fbnoratio in memuboard.fbstat) then checkfileratio:=0;
end;
procedure ymbadd(fname:astr);
var t1,t2:real;
f:file of byte;
ff:ulfrec;
dt:datetimerec;
sof:longint;
ior:word;
slrn,rn,pl,fblks:integer;
slfn:astr;
ffo:boolean;
begin
ffo:=(filerec(ulff).mode<>fmclosed);
nl;
fname:=sqoutsp(fname);
if (exist(fname)) then begin
assign(f,fname); reset(f);
sof:=filesize(f);
fblks:=trunc((sof+127.0)/128.0);
t1:=rte*fblks;
close(f);
t2:=batchtime+t1;
if (t2>nsl) then print('Not enough time left in queue.')
else
if (numbatchfiles=20) then print('Batch queue full.')
else begin
inc(numbatchfiles);
with batch[numbatchfiles] do begin
if (fileboard<>-1) then begin
slrn:=lrn; slfn:=lfn;
if ffo then close(ulff);
recno(stripname(fname),pl,rn);
seek(ulff,rn); read(ulff,ff);
close(ulff);
if ffo then fiscan(pl);
lrn:=slrn; lfn:=slfn;
pts:=ff.filepoints;
blks:=ff.blocks;
end else begin
pts:=unlisted_filepoints;
blks:=fblks;
end;
fn:=sqoutsp(fname);
tt:=t1;
section:=fileboard;
batchtime:=t2;
sysoplog('Added '+stripname(fn)+' to batch queue.');
sprint(fstring.batchadd);
r2dt(batchtime,dt);
print('Batch - Files: '+cstr(numbatchfiles)+' Time: '+longtim(dt));
end;
end;
end else
print('File doesn''t exist');
end;
procedure addtologupdown;
var s:astr;
begin
s:=' ULs: '+cstr(trunc(thisuser.uk))+'k in '+cstr(thisuser.uploads)+' file';
if thisuser.uploads<>1 then s:=s+'s';
s:=s+' - DLs: '+cstr(trunc(thisuser.dk))+'k in '+cstr(thisuser.downloads)+' file';
if thisuser.downloads<>1 then s:=s+'s';
sysoplog(s);
end;
procedure send1(fn:astr; var dok,kabort:boolean);
var f:text;
ff:file;
f1:ulfrec;
nfn,cp,slfn,s:astr;
st:real;
filsize:longint;
dcode:word; { dos exit code }
p,i,sx,sy,t,pl,rn,slrn,errlevel:integer;
g,c:char;
b,done1,foundit:boolean;
begin
done1:=FALSE;
reset(xf);
repeat
nl;
sprompt('^4Protocol (^0?^4=^0list^4) : ^3'); mpkey(s);
if (s='?') then begin
nl;
showprots(FALSE,TRUE,FALSE,FALSE);
end else begin
p:=findprot(s,FALSE,TRUE,FALSE,FALSE);
if (p=-99) then print('Invalid entry.') else done1:=TRUE;
end;
until (done1) or (hangup);
dok:=TRUE; kabort:=FALSE;
if (-p in [1,2,3,4,12]) or (p in [1..200]) then
case checkfileratio of
1:begin
nl;
sprint(fstring.unbalance);
nl;
prompt('You have DLed: '+cstr(trunc(thisuser.dk))+'k in '+cstr(thisuser.downloads)+' file');
if thisuser.downloads<>1 then print('s') else nl;
prompt('You have ULed: '+cstr(trunc(thisuser.uk))+'k in '+cstr(thisuser.uploads)+' file');
if thisuser.uploads<>1 then print('s') else nl;
nl;
print(' 1 upload for every '+cstr(systat.dlratio[thisuser.sl])+' downloads must be maintained.');
print(' 1k must be uploaded for every '+cstr(systat.dlkratio[thisuser.sl])+'k downloaded.');
sysoplog('Tried to download while ratio out of balance:');
addtologupdown;
p:=-11;
end;
2:begin
nl;
sprint(fstring.unbalance);
nl;
print('Assuming you download the files already in the batch queue,');
print('your upload/download ratio would be out of balance.');
sysoplog('Tried to add to batch queue while ratio out of balance:');
addtologupdown;
p:=-11;
end;
end;
if (p>=0) then begin seek(xf,p); read(xf,protocol); end;
close(xf);
lastprot:=p;
case p of
-12:ymbadd(fn);
-11:;
-10:begin dok:=FALSE; kabort:=TRUE; end;
(* -4:if (incom) then send(TRUE,TRUE,fn,dok,kabort,FALSE,rte);
-3:if (incom) then send(FALSE,TRUE,fn,dok,kabort,FALSE,rte);
-2:if (incom) then send(FALSE,FALSE,fn,dok,kabort,FALSE,rte);*)
-1:if (not trm) then sendascii(fn);
(* -2:if (not trm) then begin
assign(f,fn);
{$I-} reset(f); {$I+}
if (ioresult<>0) then print('File not found.')
else begin
kabort:=FALSE;
clrscr;
sx:=wherex; sy:=wherey;
window(1,25,80,25);
textcolor(11); textbackground(1);
gotoxy(1,1);
for t:=1 to 80 do write(' ');
gotoxy(1,1);
write('Sending ASCII File '+fn+' -- Please Wait');
textcolor(7); textbackground(0);
window(1,1,80,24);
gotoxy(sx,sy);
repeat
read(f,g);
o(g); write(g);
until (eof(f)) or (kabort);
close(f);
end;
end;*)
else
if (incom) then begin
cp:=bproline1(protocol.dlcmd);
bproline(cp,sqoutsp(fn));
if (useron) then star('Send ready.');
if (useron) then shel(caps(thisuser.name)+' is downloading!') else
shel('Sending file(s)...');
b:=systat.swapshell; systat.swapshell:=FALSE;
pexecbatch(FALSE,'tgtemp2.bat','tgtest2.$$$',start_dir,cp,errlevel);
systat.swapshell:=b;
shel2;
foundit:=FALSE; i:=0;
while ((i<6) and (not foundit)) do begin
inc(i);
if (value(protocol.dlcode[i])=errlevel) then foundit:=TRUE;
end;
dok:=TRUE;
if ((foundit) and (not (xbxferokcode in protocol.xbstat))) then dok:=FALSE;
if ((not foundit) and (xbxferokcode in protocol.xbstat)) then dok:=FALSE;
end;
end;
if (trm) then begin incom:=FALSE; outcom:=FALSE; end;
if (not useron) and (not kabort) then begin
cursoron(FALSE);
setwindow(wind,36,8,80,12,4,0,1);
gotoxy(3,2); tc(14);
if dok then write('Transfer successful.') else
write('Transfer unsuccessful.');
st:=timer;
while (not keypressed) and (tcheck(st,5)) do abeep;
if keypressed then c:=readkey;
removewindow(wind);
cursoron(TRUE);
incom:=FALSE; outcom:=FALSE;
end;
end;
procedure receive1(fn:astr; resumefile:boolean; var dok,kabort,addbatch:boolean);
var cp,nfn,s:astr;
st:real;
filsize:longint;
p,i,t,fno,sx,sy,nof,errlevel:integer;
c:char;
b,done1,foundit:boolean;
begin
done1:=FALSE;
reset(xf);
repeat
nl;
sprompt('^4Protocol (^0?^4=^0list^4) : ^3'); mpkey(s);
if (s='?') then begin
nl;
showprots(TRUE,FALSE,FALSE,resumefile);
end else begin
p:=findprot(s,TRUE,FALSE,FALSE,resumefile);
if (p=-99) then print('Invalid entry.') else done1:=TRUE;
end;
until (done1) or (hangup);
if (not useron) then begin incom:=TRUE; outcom:=TRUE; end;
dok:=TRUE; kabort:=FALSE;
if (p>=0) then begin seek(xf,p); read(xf,protocol); end;
close(xf);
case p of
-12:addbatch:=TRUE;
-11,-10:begin dok:=FALSE; kabort:=TRUE; end;
-1:if (not trm) then recvascii(fn,dok,rte);
else
if (incom) then begin
cp:=bproline1(protocol.ulcmd);
bproline(cp,sqoutsp(fn));
if (useron) then star('Receive ready.');
if (useron) then shel(caps(thisuser.name)+' is uploading!') else
shel('Receiving file(s)...');
b:=systat.swapshell; systat.swapshell:=FALSE;
pexecbatch(FALSE,'tgtemp2.bat','tgtest2.$$$',start_dir,cp,errlevel);
systat.swapshell:=b;
shel2;
foundit:=FALSE; i:=0;
while ((i<6) and (not foundit)) do begin
inc(i);
if (value(protocol.ulcode[i])=errlevel) then foundit:=TRUE;
end;
dok:=TRUE;
if ((foundit) and (not (xbxferokcode in protocol.xbstat))) then dok:=FALSE;
if ((not foundit) and (xbxferokcode in protocol.xbstat)) then dok:=FALSE;
end;
end;
if (not useron) and (not kabort) then begin
cursoron(FALSE);
setwindow(wind,36,8,80,12,4,0,1);
gotoxy(3,2); tc(14);
if (dok) then write('Transfer successful.') else
write('Transfer unsuccessful.');
st:=timer;
while (not keypressed) and (tcheck(st,5)) do abeep;
if (keypressed) then c:=readkey;
removewindow(wind);
cursoron(TRUE);
incom:=FALSE; outcom:=FALSE;
end;
end;
end.