/********************** Hydra/3 - Postprocessing Unit ***********************
*									    *
*	  Copyright 1995 by Dreamer/1oo% and Neurodancer/1oo%		    *
*									    *
****************************************************************************/

signal on Syntax

/************************** Multilanguage Config ***************************/

/* language 0 */

Offcom.0	="O"	/* Logoff-Command! */
yeppo.0		="Y"
asksl.0		="Clear Selectlist now?"
thanx.0		="Thank You for using Hydra/3!"
fincom.0	="Found incomplete Uploads:"
contUL.0	="Do You want to continue uploading them later? "
deliUL.0	="Deleting incomplete Uploads..."
logoff.0	="c7[c3Ac7]c2bort logoff and return to BBS.  c7[c3Dc7]c2isconnect now.  c6Countdown:"


/* language 1 */

Offcom.1	="O"	/* Logoff-Command! */
yeppo.1		="J"
asksl.1		="Gemerkte Files vergessen?"
thanx.1		="Vielen Dank!"
fincom.1	="Unvollstaendige Uploads gefunden:"
contUL.1	="Willst Du diese Files apäter weiter uploaden? "
deliUL.1	="Lösche die unvollstaendigen Uploads..."
logoff.1	="c2Logoff c7[c3Ac7]c2brechen, zurueck in die BBS. Sofortiger c7[c3Dc7]c2isconnect. c6Countdown:"

/**************************** set some stuff *******************************/

version="o.27"

options results; bufferflush
logoff=getclip('Logoff')
setclip('Logoff')
setclip('LostStuff')
setclip('lclist')
setclip('myloc')

setobject 0 ; putuser 68
getuser 23 ; port=result
getuser 39 ; uucpdir="Mail:Users/"result
getuser 1100452 ; lng=result
getuser 1209644 ; num=result
getuser 1306724 ; UDloc=substr(result,7,1)
getuser 1306724 ; myloc=result
getuser 2307346 ; temppath=result

transmit x2c(196631196E32196332197A342048796472612F33202D20506F737470726F63657373696E6720556E6974202D2019633356)version||x2c(20197A30)

/********************** if AO-Bit was set, unset it ************************/

getuser 1100662 ; privs=d2c(result+(result<0)*256)
aopriv=BitTST(privs,5)
if getclip(port'aopriv')='SET!' then do
	privs=c2d(BitCLR(privs,5))
	privs=privs-(privs>127)*256
	setobject privs ; putuser 1100662
	call setclip(port'aopriv')
end

/*************** check, if there where some incomplete Uploads *************/

if (exists(uucpdir'/Hydra.BAD/BAD-XFER.LOG') & getclip(port'resume')~='SET!') then do
	transmit "n2c3"fincom.lng"c7"
	open(bad,uucpdir'/Hydra.BAD/BAD-XFER.LOG','R')
		do until ~eof(bad)
			Logline = readln(bad)
			parse var logline fname badname fsize x
			badsize=word(statef(uucpdir"/Hydra.BAD/"badname),2)
			transmit "c6"left(fname,20," ")" c7- c6"right(badsize,8," ")" c7of c6"right(fsize,8," ")" c7Bytes"
		end
	close(bad)
	prompt 1 YESNO "n1c2"contUL.lng"c7[c3"yeppo.lng"c7/c2nc7] "
	if upper(result)="YES" then nop
	else do
		transmit "c3n1"deliUL.lng"n1"
		call delete(uucpdir'/Hydra.BAD/BAD-XFER.#?')
	end
	drop Logline
end

call setclip(port'resume')

/********************* insert Credz 4 ULer in Filelist ********************/

if exists(temppath||port'HydraCred')&exists(myloc"data/_Items3") then do

	open(cred,temppath||port'HydraCred','R')
	Cline=readln(cred)
	if eof(cred) then break

	open(file,myloc"data/_Items3","R");
		Itemdat=readch(file,65536);
	close(file);

	do until eof(cred)
		CName=word(Cline,1)
		BSize=word(Cline,2)
		Bcred=word(Cline,3)
		Fcred=word(Cline,4)

		BSize=d2c(BSize);
		Bcred=d2c(Bcred);
		Fcred=d2c(Fcred)
		Fnumb=d2c(1); found=0

		ILen=length(Itemdat)
		do i=1 by 168 to ILen while found=0;if substr(Itemdat,i,length(Cname))=Cname then do;found=1;adr=i;end;end

		if found=1 then do
			Itemdat=overlay(Bcred,Itemdat,adr+116+4-length(Bcred))
			Itemdat=overlay(Fcred,Itemdat,adr+120+4-length(Fcred))
			Itemdat=overlay(Bsize,Itemdat,adr+124+4-length(Bsize))
			Itemdat=overlay(Fnumb,Itemdat,adr+128+2-length(Fnumb))
			found=0
		end
		Cline=readln(cred)
	end

	open(file,myloc"data/_Items3","W");
			writech(file,Itemdat);
	close(file)
	close(cred)
end

/*********************** asking for selectlist-reset ***********************/

if num~=0 & logoff<2 then do
	prompt 1 YESNO "n1c2"asksl.lng" c7[c3"yeppo.lng"c7/c2nc7] "
	if upper(result)="YES" then do
		setobject 0 ; putuser 1209644
	end
end
else do
	setobject 0 ; putuser 1209644
end

/*************************** Enable Idle-Timer *****************************/

setobject 0 ; putuser 1110341

/*************************** Clean Up temppath *****************************/

call delete(temppath||port'HydFileLst')
call delete(temppath||port'HydraLog')
call delete(temppath||port'HydraCred')

/***************** check for disabled OLMs and enable them *****************/

if exists(temppath'__olm'port) then
	call rename(temppath"__olm"port, temppath"_olm"port)

/********************************* END ! ***********************************/

transmit "n1c6"thanx.lng"n1"

if logoff=3 then do 
	sendstring "n1"logoff.lng"   c7"
	do cnt=10 to 1 by -1
		cntstr=right(cnt,2," ")
		sendstring "<2"cntstr;	maygetchar
		if upper(result)="A" then do
			sendstring "n1"; exit
		end
		if upper(result)="D" then do
			sendstring "n1"; addkeys Offcom.lng||"!`"; exit
		end
		delay(50)
	end
	sendstring "<2 0n1"; addkeys Offcom.lng||"!`"; exit
end

exit

syntax:
emsg="r0c2 Line: c7"sigl"c2, c7"rc"c2 -c6 "errortext(rc)
getuser 23 ; port=result
transmit "n1c1r1 Error occured! "emsg
if exists("SysData:Log/port"port) then open(clog,"SysData:Log/port"port,"A")
	else open(clog,"SysData:Log/port"port,"W")
writeln(clog,"c2             c1Hydra Error (Post): "emsg)
close(clog)
transmit "c1Important: c2Please report the sysop about the c3linec2 and the c3error-numberc2!"
transmit "c6Any Key to Continue! g0"
exit
