/***********************************
 **     MagiCall BBS Script       **
 **     --------------------      **
 ***********************************/

options results

/****************/
/* Main Program */
/****************/

'set serial_duplex echo'                          /* echo back incoming chars */
'set path_upload MagiCall:rexx/bbs_download'      /* set up+download directory */
'set path_download MagiCall:rexx/bbs_download'

do i=1 to 9999999

	call sleep

	call login

	if result ~= 0 then do

		call menu

        do j=1 to 999999

			'send "\r\nCommand (L,U,D,?,Q): "'
			'input "" 59'
			if rc~=0 then leave

			if result=="?" then call menu

			if result="q" | result="Q" | result="timeout" then leave
			if result="l" | result="L" then call list
			if result="u" | result="U" then call upload
			if result="d" | result="D" then call download

		end

	end

	call logout

end

exit 0



/***************************/
/* sleep: Warten auf Anruf */
/***************************/

sleep: procedure

	'print "^LMagiCall BBS\r\n"'
	'print "------------\r\n\r\n"'
	'print "Waiting for a RING...\r\n"'
	'wait "RING"'
	'send ata\r'
	'print "\r\nWaiting for a CONNECT...\r\n"'
	'wait "CONNECT" 30'

	return


/*************************************************************/
/* login: Einloggen des Users. Liefert 1 bei korrektem Login */
/*************************************************************/

login: procedure

	'send "^L------------\r\n"'
	'send "MagiCall BBS\r\n"'
	'send "------------\r\n"'

	do i=1 to 3

		'send "\r\nEnter Password: "'
		'input "\r" 30'
		if rc~=0 then return 0
		if result=="miracel" then return 1 /* Hier steht das Passwort */
	end

	return 0



/**************************/
/* logout: User ausloggen */
/**************************/

logout: procedure
	'send "\r\n\r\n\r\nLogging you out!\r\n"'
	'send \query[modem_hangup]'
	return




/*************************/
/* download: File senden */
/*************************/

download: procedure
	'send "\r\n\r\nEnter Filename: "'
	'input "\r" 30'
	if rc~=0 | result="" then return 0
	file="MagiCall:Rexx/bbs_download/"||result
	'send "\r\n\r\nSending file(s) now, using ZModem...\r\n"'
    upload file
    if rc~=0	then 'send "\r\nSorry, your download failed!\r\n"'
				else 'send "\r\nDownload successfull!\r\n"'
	return



/**************************/
/* upload: File empfangen */
/**************************/

upload: procedure
	'send "\r\n\r\nSend file(s) now, using ZModem...\r\n"'
	download
    if rc~=0	then 'send "\r\nSorry, your upload failed!\r\n"'
				else 'send "\r\nUpload successfull!\r\n"'
	return



/****************************/
/* list: Directory ausgeben */
/****************************/

list: procedure

	address command 'list >t:macbbs.tmp MagiCall:rexx/bbs_download'
	'send \r\n\r\n'
	'sendfile t:macbbs.tmp'
	return



/***********************/
/* menu: Menü ausgeben */
/***********************/

menu: procedure

	'send "\r\n\r\n\r\n------------------\r\n"'
	'send "MagiCall BBS Menu\r\n"'
	'send "------------------\r\n\r\n"'

	'send "[L]  List Files\r\n"'
	'send "[D]  Download\r\n"'
	'send "[U]  Upload\r\n"'
	'send "[?]  Show Menu\r\n"'
	'send "[Q]  Quit\r\n"'

	return
