; $VER: Start 1.5 (16.1.96)

; Provide default strings
Set MSG_CUSTOMER_INFO "Customer information"
Set MSG_INFORMATION "Would you like to receive Amiga information?"
Set MSG_YES "Yes"
Set MSG_NO "No"
Set MSG_SETUP_ERROR1 "Your internet setup is not configured properly;"
Set MSG_SETUP_ERROR2 "please run Internet-Setup first."
Set MSG_INITIALIZING_MODEM "Initializing modem."
Set MSG_DIALING "Dialing"
Set MSG_MODEM_CONNECTION1 "Modem connection ready;"
Set MSG_MODEM_CONNECTION2 "now entering IBM Information Services."
Set MSG_SLIP_CONNECTION "SLIP connection ready."
Set MSG_TIMEOUT "Timeout; hanging up... "
Set MSG_DONE "done."
Set MSG_HANGUP_ERROR "a modem error occured while hanging up the line."
Set MSG_CONNECTION_LOST "Connection was lost."
Set MSG_WELCOME "Welcome to the Internet!"
Set MSG_BUSY "Remote is busy; waiting to redial..."
Set MSG_REDIALING "Redialing."

; Now try the locale approach
IF "$language" EQ "deutsch"
	Set MSG_CUSTOMER_INFO "Kundeninformation"
	Set MSG_INFORMATION "Möchten Sie Amiga-Informationen erhalten?"
	Set MSG_YES "Ja"
	Set MSG_NO "Nein"
	Set MSG_SETUP_ERROR1 "Ihr Internet-Zugang ist noch nicht eingerichtet;"
	Set MSG_SETUP_ERROR2 "bitte rufen Sie jetzt das Programm Internet-Setup auf!"
	Set MSG_INITIALIZING_MODEM "Initialisiere Modem."
	Set MSG_DIALING "Wähle"
	Set MSG_MODEM_CONNECTION1 "Modemverbindung aufgebaut;"
	Set MSG_MODEM_CONNECTION2 "Zugang zu IBM Information Services wird geöffnet."
	Set MSG_SLIP_CONNECTION "SLIP-Verbindung aufgebaut."
	Set MSG_TIMEOUT "Zeitüberschreitung; Verbindung wird abgebrochen... "
	Set MSG_DONE "fertig."
	Set MSG_HANGUP_ERROR "Fehler beim Auflegen."
	Set MSG_CONNECTION_LOST "Verbindung wurde unterbrochen."
	Set MSG_WELCOME "Willkommen im Internet!"
	Set MSG_BUSY "Gegenstelle ist besetzt; warte bis zur Wahlwiederholung..."
	Set MSG_REDIALING "Anwahl wird wiederholt."
EndIF

; Check if the user name is set; if not it will need to be configured.
IF Not Exists ENV:Surfer/UserID
	Echo "${MSG_SETUP_ERROR1}*n${MSG_SETUP_ERROR2}"
	Quit
EndIF

; Ask if the user wants to receive customer information
IF Not Exists ENV:Surfer/AskCustomer
	RequestChoice >ENV:Answer Title "${MSG_CUSTOMER_INFO}" Body "${MSG_INFORMATION}" Gadgets ${MSG_YES} ${MSG_NO}

	IF $Answer EQ 1
		SetEnv Surfer/AskCustomer Yes

		RegistryMsg >T:registry "${Surfer/RealName}" ${Surfer/UserID}@${Surfer/MailDomainName} surfer-registry@amiga.de surfer-registry
		Echo >>T:registry "RealName=*"${Surfer/RealName}*""
		Echo >>T:registry "Address=*"${Surfer/UserID}@${Surfer/MailDomainName}*""
	Else
		SetEnv Surfer/AskCustomer No
	EndIF

	Delete Quiet ENV:Answer

	SetEnv ENVARC:Surfer/AskCustomer ${Surfer/AskCustomer}
EndIF

; Dial into the account
IPDial Script INet:s/ipd.Login echo

; Did the script make a connection?
IF Not Warn
	; Set up the default host file
	Echo >INet:db/hosts "# Local Loopback*n127.0.0.1 localhost*n# THIS machine*n$IPADDRESS ${Surfer/HostName}"

	; Write the slip driver settings file
	SetEnv SANA2/slip0.config "SerName=${Surfer/SerialDevice} SerUnit=${Surfer/SerialUnit} SerBaud=${Surfer/SerialBaud} IPStr=$IPADDRESS CD 7Wire"

	; Start the TCP/IP stack
	StartINet Online=slip.device DestIP=$DESTADDRESS

	; AmIRC may need it
	SetEnv HOSTNAME $IPADDRESS

	; Run AmiPOP
	Stack 20000
	FailAt 100
	Run >NIL: <NIL: AmiPOP Append Delete Checkper NoWindow
	FailAt 10

	; Store these as a backup in case the system collapses,
	; "Restart" can then be used to continue the TCP/IP
	; session
	SetEnv ENVARC:SAFEIPADDRESS $IPADDRESS
	SetEnv ENVARC:SAFEDESTADDRESS $DESTADDRESS

	IF "$Language" EQ "deutsch"
		Echo "*NWillkommen im Internet!*N"
		Echo "Sie können das Fenster mit dem Schließsymbol"
		Echo "links oben schließen.*N"
		Echo "Um im Internet zu surfen, stehen Ihnen die Programme"
		Echo "in den Schubladen »E-Mail«, »FTP«, »IRC« und »WWW«"
		Echo "zur Verfügung."
	Else
		Echo "*NWelcome to the Internet!*N"
		Echo "Click on the close gadget in the upper left corner"
		Echo "to close the window.*N"
		Echo "You can use the applications in the drawers »E-Mail«,"
		Echo "»FTP«, »IRC« und »WWW« to surf the Internet"
	EndIF

	; Send the registration information
	IF ${Surfer/AskCustomer} EQ "Yes"

		; Once should be enough
		SetEnv Surfer/AskCustomer No
		SetEnv ENVARC:Surfer/AskCustomer No

		Run >NIL: SMTPPost <T:registry >NIL:
	EndIF
EndIF
