home *** CD-ROM | disk | FTP | other *** search
/ Dream 42 / Amiga_Dream_42.iso / RiscPC / Internet / Connexion / SPak.spk / !SLIPdial_Scripts_Demon < prev    next >
Encoding:
Text File  |  1994-12-05  |  10.7 KB  |  367 lines

  1. #slipdial
  2. #--------------------------------------------------------------------
  3. # Script : demon
  4. # !SlipDial 0.29 Demon Script - R.W.Orwin 1994 (rob@wong.demon.co.uk)
  5. #                Sprites by James Woodman (woody@bacchus.demon.co.uk)
  6. #
  7. # Revised: Alan Fitch 940627 : note now hardwired to work with USR
  8. #                              modems.
  9. # Revised: Alan Fitch 940629 : to send long modem strings using the
  10. #                              USR driver by quoting them in quotes.
  11. #                              (comment above no longer applies)
  12. # Revised: Alan Fitch 940702 : to rename "hg" to "mercury_pin"
  13. # Revised: Alan Fitch 940708 : to release modem correctly if no prompt
  14. #                              received (e.g. login, password, protocol etc).
  15. # Revised: Alan Fitch 940717 : Newsrate added
  16. # Revised: Alan Fitch 940803 : betanews also calls convmail
  17. # Revised: Alan Fitch 940911 : To use newsbase/ttfn
  18. # Revised: Alan Fitch 940911 : Task killing tidied up.
  19. # Revised: Alan Fitch 940912 : To add Isle of Wight 'phone number
  20. # Revised: Alan Fitch 940926 : TCPIP$dir changed to TCPIP2$dir
  21. # Revised: Alan Fitch 940928 : Removed references to Internet$Dir
  22. # Revised: Alan Fitch 940929 : Stopped using tmstrt, tmend, diff to create a #                              short delay - now fixed to 3 seconds.
  23. # Revised: Alan Fitch 941005 : order of startup of newsbase and TTFN swapped.#                              TTFN must start first for everything 
  24. #                              to work properly.
  25. # Revised: Alan Fitch 941117 : to rename sprites to hg_on/hg_off so
  26. #                              standard DemonSpr sprite file will still work
  27. #
  28.  
  29. call initMain
  30. call configure
  31. call setserial
  32. call makemenus
  33. # change following line to "call mercury_on" for default use of mercury
  34. call mercury_on
  35.  
  36. #
  37. # main loop
  38. #
  39. :loop
  40. message /close
  41. wait /event
  42. goto loop
  43. exit
  44.  
  45. # end of program
  46. #--------------------------------------------------------------------
  47.                 
  48. #====================================================================
  49. # SUBROUTINES
  50. #====================================================================
  51.  
  52. #-----------------------------------------------------------
  53. #Subroutine: bra
  54. #calls bradford pop: returns via subroutine dodial
  55. #-----------------------------------------------------------
  56. :bra
  57. set phonenum 01274755066
  58. set costband b
  59. goto dodial
  60.  
  61. #-----------------------------------------------------------
  62. # Subroutine: lon
  63. # calls london demon phone number: returns via  subroutine
  64. # dodial.
  65. #-----------------------------------------------------------
  66. :lon
  67. set phonenum 01813434848
  68. set costband b1
  69. goto dodial
  70.  
  71. #-----------------------------------------------------------
  72. #Subroutine: lee
  73. #calls leeds demon pop: returns via subroutine dodial
  74. #-----------------------------------------------------------
  75. :lee
  76. set phonenum 0532415890
  77. set costband b
  78. goto dodial
  79.  
  80. #-----------------------------------------------------------
  81. # Subroutine: edi
  82. # calls edinburgh demon phone number: returns via subroutine
  83. # dodial.
  84. #-----------------------------------------------------------
  85. :edi
  86. set phonenum 01315528883
  87. set costband b
  88. goto dodial
  89.  
  90. #-----------------------------------------------------------
  91. # Subroutine: war
  92. # calls warrington demon phone number: returns via  
  93. # subroutine dodial.
  94. #-----------------------------------------------------------
  95. :war
  96. set phonenum 01925411383
  97. set costband b
  98. goto dodial
  99.  
  100. #-----------------------------------------------------------
  101. # Subroutine: red
  102. # calls Reading demon phone number: returns via subroutine
  103. # dodial.
  104. #-----------------------------------------------------------
  105. :red
  106. set phonenum 01734328989
  107. set costband b1
  108. goto dodial
  109.                  
  110. #-----------------------------------------------------------
  111. # Subroutine: IOW
  112. # calls Isle of Wight demon phone number: returns via 
  113. # subroutine dodial.
  114. #-----------------------------------------------------------
  115. :IOW
  116. set phonenum 01983523306
  117. set costband b1
  118. goto dodial
  119.  
  120. #-----------------------------------------------------------
  121. # Subroutine: dodial
  122. # Note: has multiple entry points from "goto" statements
  123. # above.  However it finally returns to the main waiting
  124. # loop.
  125. #-----------------------------------------------------------
  126. :dodial               
  127.  
  128. #convert any outgoing mail/news
  129. if (?file <Rucp$Dir>.uucp.spool.post.c.*) call convmail
  130. if (?file <Rucp$Dir>.uucp.spool.news.c.*) call convmail
  131. if (?file <Rucp$Dir>.uucp.spool.betanews.c.*) call convmail
  132.  
  133. # Timers to compute the call cost.
  134. set coststrt 0
  135. set costend 0
  136.  
  137. # kill Incorp if it is running, and was started from SlipDial
  138. #task /kill="Incorp"
  139. task /kill="Newsbase"
  140. task /kill="TTFN"
  141.  
  142. # Claim the device driver
  143. if (!claim 3) return 0
  144.  
  145. # initialise modem
  146. init 
  147.  
  148. # dial the number, return to main menu if failed.
  149. retry 50 15
  150. if (!dial /nodial=15 /nocar=10 /busy=2 %mercury_pin%phonenum) return 0
  151.  
  152. #
  153. # arrive here if dial succeeded
  154. # get username/password prompts to authenticate self to server.
  155. # after each prompt, return to main menu if failed.
  156. #
  157.  
  158. # initialise timer for call cost
  159. set coststrt %$time
  160.  
  161. if (!wait /del=20 ogin:) goto bad_finish
  162. send %nodename
  163.  
  164. if (!wait /del=20 word:) goto bad_finish
  165. send %password
  166.  
  167. if (!wait /del=50 ocol:) goto bad_finish
  168. send %protocol
  169.  
  170. message /capture="IP" /end="HELLO" /maxlines=7 /centre
  171. ipget 158.
  172. if (!wait /del=30 HELLO) return 0
  173.  
  174. wait /delay=10 "a while"
  175. task /name="TCP/IP" <TCPIP2$dir>.!Run
  176.  
  177. # watch out for carrier detect to go low
  178. alarm /dcd "goto good_finish"
  179. :loop2
  180. wait /event
  181. goto loop2
  182.  
  183. #
  184. # Call has been finished successfully, so release the port
  185. #
  186. :good_finish
  187. task /kill="TCP/IP"
  188. message /close
  189. message "Call finished successfully" /centre
  190. release
  191. call costcalc
  192.  
  193. # now pause for 2 seconds to allow RISC OS to sort out the display.
  194. pause 2
  195.  
  196. #
  197. # Compute the news transfer rate, and display it.
  198. #
  199. # This would probably go wrong if the DemNews file still existed from
  200. # a previous call, i.e. old news hadn't been transferred out of the 
  201. # Mail$Dir directory.  This shouldn't happen if this script is always used
  202. # as it automatically uses the convmail procedure to move new news into
  203. # ReadNews format.
  204. #
  205.  
  206. # Check if the news file exists.
  207. set newsExists {?file <Mail$Dir>.folder.DemNews}
  208. case %newsExists
  209. when 1 2 3; set nrate {newsrate Dem}; message "news rate %nrate cps" /centre
  210. when 0; message "no news downloaded" /centre
  211. endcase
  212. unset newsExists
  213. unset nrate
  214.  
  215. #
  216. # Following small section is for users of !ReadNews & !Rucp & RN Filters
  217. # <Internet$Dir> should be set to directory where all of above can be found.
  218. #
  219. #task "<Internet$Dir>.ka9q->rucp { > null: }"
  220. #task "<Internet$Dir>.!Incorp.!Run"
  221. task /name="TTFN" <TTFN$Dir>.!Run
  222. task /name="Newsbase" <NewsBase$Dir>.!Run
  223.  
  224. #now trim DemHist File
  225. call trimfile <NNTP$Dir>.DemHist
  226. return 1
  227.  
  228. #
  229. # Call failed in some way
  230. #
  231. :bad_finish
  232. message "Call setup failed" /centre
  233. release
  234. call costcalc
  235. message/close
  236. return 0
  237.  
  238. #-----------------------------------------------------------
  239. # Subroutine: convmail
  240. # Convert mail between rucp and ka9q formats.
  241. # above.  However it finally returns to the main waiting
  242. # loop.
  243. #-----------------------------------------------------------
  244. :convmail
  245. #task "<Internet$Dir>.rucp->ka9q { > null: }"
  246. return 1
  247.  
  248. #-----------------------------------------------------------
  249. # Subroutine: trimfile
  250. # Trim a specified history file.
  251. #-----------------------------------------------------------
  252. :trimfile
  253. if (?lt {?file/size %p1} 5000) return
  254. copy/tail=200 %p1 %p1-T;delete %p1;move %p1-T %p1
  255. return 1
  256.  
  257. #-----------------------------------------------------------
  258. # Subroutine: costcalc
  259. # Compute the cost of the call as far as possible.
  260. #-----------------------------------------------------------
  261. :costcalc
  262. set costend %$time
  263. set costlen {eval "%costend-%coststrt"}
  264. unset costend
  265. return 1
  266.  
  267. #-----------------------------------------------------------
  268. # Subroutine: Mercury
  269. # Toggle the mercury switch
  270. #-----------------------------------------------------------
  271. :mercury
  272. if (?eq %mercury_pin %mercury) goto mercury_off
  273. # Set the Mercury switch to ON.
  274. :mercury_on
  275. icon /id="Mercury" /action="call mercury" hgon
  276. set mercury_pin %mercury
  277. goto mercury_return
  278. # else Set the Mercury switch to OFF.
  279. :mercury_off
  280. icon /id="Mercury" /action="call mercury" hgoff
  281. set mercury_pin ""
  282. :mercury_return
  283. return 1
  284.  
  285. #-----------------------------------------------------------
  286. # Subroutine: makemenus
  287. # Defines the menus for dialling etc.
  288. #-----------------------------------------------------------
  289. :makemenus
  290. menu "Edinburgh:call edi" "London:call lon" "Reading:call red" "Warrington:call war" "IsleofWight:call IOW" "Leeds:call lee" "Bradford:call bra"
  291. menu /icon="Mercury" "Mercury On:call mercury_on" "Mercury Off:call mercury_off" 
  292. return 1
  293.  
  294. #-----------------------------------------------------------
  295. # Subroutine: setserial
  296. # Set Serial Port/Driver Parameters
  297. #-----------------------------------------------------------
  298. :setserial
  299. driver USR
  300. port %wport %prtnum
  301. speed %speed
  302. set protocol slip
  303. return 1
  304.  
  305. #-----------------------------------------------------------
  306. # Subroutine: setup1
  307. # Called to setup defaults if no configuration file present.
  308. #-----------------------------------------------------------
  309. :setup1
  310. input/prompt="Enter Serial Block Driver Name" wport
  311. input/prompt="Enter Serial Port Number (if relevant)" prtnum
  312. input/prompt="Enter Your Modem->Computer Speed (bps):" speed
  313. input/prompt="Enter Your Demon Nodename:" nodename
  314. input/prompt="Enter Your Password:" password
  315. input/prompt="Enter Your Mercury PIN:" mercury
  316. open/id=conf/write %filename
  317. write/id=conf %wport
  318. write/id=conf %prtnum
  319. write/id=conf %speed
  320. write/id=conf %nodename
  321. write/id=conf %password
  322. write/id=conf %mercury
  323. close/id=conf
  324. return 1
  325.  
  326. #-----------------------------------------------------------
  327. # Subroutine: configure
  328. # This loads password config from file or prompts for data 
  329. # to create file.
  330. #-----------------------------------------------------------
  331. :configure
  332. set filename {?file/expand slipdial:demonconfg}
  333. if (!?file %filename) call setup1
  334. open/read/id=conf/error="return" %filename
  335. read/id=conf/eof="goto closeconf" wport
  336. read/id=conf/eof="goto closeconf" prtnum
  337. read/id=conf/eof="goto closeconf" speed
  338. read/id=conf/eof="goto closeconf" nodename
  339. read/id=conf/eof="goto closeconf" password
  340. read/id=conf/eof="goto closeconf" mercury
  341. :closeconf
  342. close/id=conf
  343. return
  344.  
  345. #-----------------------------------------------------------
  346. # Subroutine: initMain
  347. # General initialisation.
  348. #-----------------------------------------------------------
  349. :initMain                
  350. # remove comment from following line for tracing
  351. #trace "SlipDial:logoutput"
  352. debug 3
  353. icon /file="SlipDial:DemonSpr"
  354. set mercury_pin ""
  355. #
  356. # Following lines will have to be setup for your location in the
  357. # country.
  358. #
  359. # Default costband.  Should be adjusted for each menu item which can
  360. # call a number (see subroutine :lon for instance).
  361. set costband b1
  362. return 1
  363.  
  364.  
  365.  
  366.