.KEY DISCONNECT/S
.BRA {
.KET }

; $VER: stop 1.1 (21.10.1997)
; Break rc5v2 process
;
; Use this script to shutdown the rc5v2 process.
; Place it in the same dir you have the rc5v2 client in.
; Set the Script protection bit on (protect +s stop).
;
; This is a do-what-you-want-with-it product  ;-)
;
; AmigaPhil@ping.be  http://www.ping.be/amigaphil/
;
; USAGE: open a shell and type:
; ------
; STOP          First send a break signal to the rc5v2
;                 client running,
;               then check if Miami is online and if you
;                 want to put it offline (option DISCONNECT).
;               If Miami is offline, quit it.
;               If instead AmiTCP was used to run the client,
;                 quit AmiTCP (and flush mem with the
;                 DISCONNECT option).
;
FailAt 21

status command rc5v2 >env:rc5v2proc
If NOT Warn
    break $rc5v2proc
    echo "Break sent to rc5v2."
    echo "Please wait..."
    echo ""
    wait 3 secs
EndIf
Lab breakrc5v2
status command rc5v2 >NIL:
If NOT Warn
    wait 3 secs
    Skip breakrc5v2 Back
EndIf
echo "The rc5v2 process is shutdown."
If `rx "say show('P','BLITZBLANK')"` EQ 1  ; if BlitzBlanker exists
   rx "address 'BLITZBLANK'; 'RELOAD'"     ; reset its config
EndIf

; ***
; *** Check if Miami is online.
; ***

if `rx "say show('P','MIAMI.1')"` EQ 1 ; *** is Miami running ?
  rx >NIL: "options results; address 'MIAMI.1'; ISONLINE; return RC"
  if $rc EQ 1                          ; *** Miami was online.
    if {DISCONNECT}                          ; *** Put it offline ?
      rx "address 'MIAMI.1'; OFFLINE"
Lab monline
      rx >NIL: "options results; address 'MIAMI.1'; ISONLINE; return RC"
      if $rc EQ 1
        wait 3 secs
        Skip monline Back
      EndIf
      echo "Miami is now offline."                 ; *** Quitting...
      echo "Quitting Miami..."
      echo ""
      rx "address 'MIAMI.1'; QUIT"
      avail >NIL: FLUSH                            ; *** Flushing mem.
      quit
    else                                     ; *** Or keep it online ?
      echo "Miami still is online."
      echo ""
      quit
    EndIf
  else                                 ; *** Miami was not online.
    echo "Quitting Miami..."                 ; *** Quitting...
    echo ""
    rx "address 'MIAMI.1'; QUIT"
    quit
  EndIf
EndIf

; ***
; *** Maybe AmiTCP was used to
; *** run the rc5v2 offline.
; *** So kill AmiTCP now.
; ***

Version bsdsocket.library >nil:
If NOT Warn
  Rx "address AMITCP; KILL"
  If {DISCONNECT}                      ; *** if DISCONNECT option given
    Wait 3 secs
    If `rx "Say Show(ports, AMITCP)"` EQ 0
      Avail >NIL: FLUSH                      ; *** Flushing mem.
    else
      Echo "Memory NOT flushed!"
    EndIf
  EndIf
else
  Echo "AmiTCP/IP is not running."
EndIf
