home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 September / PCO_0998.ISO / filesbbs / dos / sbbs230b.exe / EXEC.LZH / QNET.SRC < prev    next >
Encoding:
Text File  |  1996-04-26  |  10.1 KB  |  478 lines

  1. # QNET.SRC
  2.  
  3. ###############################################################################
  4. #          Baja module for performing QWKnet call-outs              #
  5. #           Requires Synchronet v2.3 and Baja v2.10              #
  6. #            Copyright 1996 Digital Dynamics               #
  7. ###############################################################################
  8.  
  9. # Usage: *QNET HUBID PHONE PASSWORD ATTEMPTS
  10. # Example: *QNET VERT 1-714-529-9721 YOURPASS 100
  11.  
  12. # You may use the QNET.BIN module INSTEAD of your normal terminal/script
  13. # QWKnet call-out routine. You can do this by changing
  14. #
  15. # SCFG->Networks->QWK->Hubs->VERT->Call-out Command Line to:
  16. #
  17. # *QNET VERT 1-714-529-9721 YOURPASS 100
  18. #
  19. # The asterisk is important! 100 is the number of dial attempts, YOURPASS is
  20. # your QWKnet password here on Vertrauen. Remove 1-714 if you're in the 714
  21. # area code.
  22. #
  23. # No modification or recompilation of this module should be necessary.
  24.  
  25. !include sbbsdefs.inc
  26. !include file_io.inc
  27.  
  28. # Constants (change for your preferences)
  29.  
  30. !define INIT_ATTEMPTS 5
  31. !define MAX_INACTIVITY      30    # 30 seconds of host inactivity
  32.  
  33. # Must be FIRST function call (or module will immediately terminate)
  34. set _online ON_LOCAL
  35. # print_local "QNET.SRC\r\n"
  36. # Force DCD to be assumed HIGH and user online and NO screen pausing
  37. or _sys_status SS_DCDHIGH|SS_USERON|SS_PAUSEOFF
  38. # Turn off the ^C status flag
  39. not _sys_status SS_ABORT
  40. # Set console for Local Input/Output only
  41. set _console CON_L_INPUT|CON_L_ECHO
  42.  
  43. # Make sure there is a COM port configured
  44. compare _DTE_RATE 0
  45. if_equal
  46.     print "BAJAQNET: No COM port configured.\7\r\n\r\n"
  47.     pause
  48.     return
  49.     end_if
  50.  
  51. # Variables
  52. int i start connect end logfile argc argv attempt result
  53. str tmp rep qwk log hubid phone password attempts
  54.  
  55. # Mark beginning time
  56. time start
  57. set connect 0
  58.  
  59. # Process command line arguments
  60. set hubid ""
  61. set phone ""
  62. set password ""
  63. set attempts ""
  64.  
  65. set _lncntr 0
  66. cls
  67. strupr str
  68. # Display command line
  69. print "BAJAQNET: %s\r\n"
  70. set argc 0
  71. :process_args
  72. compare_str ""
  73. if_true
  74.     goto end_args
  75.     end_if
  76. sprintf tmp "%.1s" str
  77. shift_str 1
  78. compare tmp " "
  79. if_true
  80.     add argc 1
  81.     goto process_args
  82.     end_if
  83. switch argc
  84.     case 0
  85.         strcat hubid tmp
  86.         end_case
  87.     case 1
  88.         strcat phone tmp
  89.         end_case
  90.     case 2
  91.         strcat password tmp
  92.         end_case
  93.     case 3
  94.         strcat attempts tmp
  95.         end_case
  96.     default
  97.         goto usage
  98.     end_switch
  99. goto process_args
  100.  
  101. :usage
  102. crlf
  103. print "Usage: QNET hubid phone password attempts\r\n\r\n"
  104. print "Example: QNET VERT 1-714-529-9721 YOURPASS 100\r\n\r\n\7"
  105. pause
  106. return
  107.  
  108. :end_args
  109. compare hubid ""
  110. if_true
  111.     goto usage
  112.     end_if
  113. compare phone ""
  114. if_true
  115.     goto usage
  116.     end_if
  117. compare password ""
  118. if_true
  119.     goto usage
  120.     end_if
  121. compare attempts ""
  122. if_true
  123.     goto usage
  124.     end_if
  125.  
  126. sprintf log "%%j\%s.LOG" hubid
  127. sprintf rep "%%j\%s.REP" hubid
  128. sprintf qwk "%%j\%s.QWK" hubid
  129. chkfile qwk
  130. if_true
  131.     printf "\7BAJAQNET: %s already exists!\r\n" qwk
  132.     set i 0
  133.     :check_qwk
  134.     sprintf qwk "%%j%s.QW%ld" hubid i
  135.     chkfile qwk
  136.     if_true
  137.         printf "\7BAJAQNET: %s already exists!\r\n" qwk
  138.         add i 1
  139.         compare i 10
  140.         if_equal
  141.             goto exit
  142.             end_if
  143.         goto check_qwk
  144.         end_if
  145.     end_if
  146.  
  147. fopen logfile O_WRONLY|O_APPEND|O_CREAT log
  148. if_false
  149.     printf "\7BAJAQNET: Error (%d) opening %s\r\n" _errno log
  150.     goto exit
  151.     end_if
  152.  
  153. time_str str start
  154. fprintf logfile "BAJAQNET: Launched: %s\r\n" str
  155.  
  156. # Required for receiving responses from modem
  157. set _online ON_REMOTE
  158. or _console CON_R_INPUT
  159.  
  160. set attempt 0
  161. :init
  162. call flush_input
  163. add attempt 1
  164. compare attempt INIT_ATTEMPTS
  165. if_greater
  166.     setstr "BAJAQNET: Modem initialization failed!\r\n"
  167.     print str
  168.     fwrite logfile str
  169.     goto exit
  170.         end_if
  171. print "BAJAQNET: Initializing modem\r\n"
  172.  
  173. print_remote "ATX4E0H0M0V0\r"
  174. getstr str 80 K_NOECHO
  175. if_false
  176.     print "BAJAQNET: No response\r\n"
  177.     goto exit
  178.     end_if
  179. compare_str "0"
  180. if_false
  181.     print "BAJAQNET: Modem returned %s\r\n"
  182.     goto init
  183.     end_if
  184.  
  185. set attempt 0
  186. :dial
  187. add attempt 1
  188. compare attempt attempts
  189. if_greater
  190.     fprintf logfile "BAJAQNET: No connect after %s attempts\r\n" attempts
  191.     goto exit
  192.     end_if
  193. printf "BAJAQNET: Dialing %s at %s (Attempt: %ld of %s)\r\n" hubid phone attempt attempts
  194. mswait 1000
  195. copy str phone
  196. print_remote "ATDT%s\r"
  197. getstr str 80 K_NOECHO
  198. if_false
  199.     goto exit
  200.     end_if
  201. print "BAJAQNET: "
  202. copy result str
  203. switch result
  204.     case 0
  205.         print "Modem responded with '%s'\r\n"
  206.         fprintf logfile "BAJAQNET: Modem repsoned with '%s'\r\n" str
  207.         goto dial
  208.     case 2
  209.         print "RING\r\n"
  210.         goto dial
  211.     case 3
  212.         print "NO CARRIER\r\n"
  213.         goto dial
  214.     case 4
  215.         print "ERROR\r\n"
  216.         goto dial
  217.     case 6
  218.         print "NO DIALTONE\r\n"
  219.         goto dial
  220.     case 7
  221.         print "BUSY\r\n"
  222.         goto dial
  223.     case 8
  224.         print "NO ANSWER\r\n"
  225.         goto dial
  226.     default
  227.         print "Connection established (Result Code: %s)\r\n"
  228.         time connect
  229.         ftime_str str "%X" connect
  230.         fprintf logfile "BAJAQNET: Connected: %s\r\n" str
  231.     end_switch
  232.  
  233. # Normal use of DCD
  234. not _sys_status SS_DCDHIGH
  235. # Wait a second
  236. mswait 1000
  237. # Send ESC ESC for front-end mailers
  238. print_remote "\x1b\x1b"
  239. # Wait for NN: prompt
  240. print "BAJAQNET: Waiting for NN: prompt "
  241. setstr "NN:"
  242. call waitfor
  243. print " \r\n"
  244. # Notify Hub of Script Type and Version
  245. print_remote "Baja Qnet Version 1.10"
  246. mswait 2000
  247. # Send our QWK ID
  248. print_remote "\24%q\r"
  249. # Wait for PW: prompt
  250. print "BAJAQNET: Waiting for PW: prompt "
  251. setstr "PW:"
  252. call waitfor
  253. print " \r\n"
  254. # Send our PASSWORD
  255. copy str password
  256. print_remote "%s\r"
  257. # Wait for QWK: prompt
  258. print "BAJAQNET: Waiting for QWK: prompt "
  259. setstr "QWK:"
  260. call waitfor
  261. print " \r\n"
  262.  
  263. chkfile rep
  264. if_true
  265.     ###################
  266.     # Send REP packet #
  267.     ###################
  268.     print "BAJAQNET: Sending REP packet\r\n"
  269.     print_remote "UZN"
  270.     mswait 1000
  271.     call flush_input
  272.     send_file_via Z rep
  273.     get_file_length i rep
  274.     sprintf str "BAJAQNET: Upload of REP packet (%lu bytes) " i
  275.     print str
  276.     fwrite logfile str
  277.     if_true
  278.         print "successful\r\n"
  279.         fprintf logfile "successful\r\n"
  280.         remove_file rep
  281.     else
  282.         print "\7UNSUCCESSFUL!\r\n"
  283.         fprintf logfile "UNSUCCESSFUL!\r\n"
  284.         end_if
  285.     #mswait 1000
  286.     #call flush_input
  287.     # Wait for QWK: prompt
  288.     print "BAJAQNET: Waiting for QWK: prompt "
  289.     setstr "QWK:"
  290.     call waitfor
  291.     print " \r\n"
  292.     end_if
  293.  
  294. #######################
  295. # Download QWK packet #
  296. #######################
  297. print "BAJAQNET: Scanning for new messages "
  298. int sm nm ss
  299.  
  300. print_remote "DL"
  301. setstr "PROTOCOL OR "
  302. call waitfor
  303. print " \r\n"
  304. if_false
  305.     setstr "BAJAQNET: No new messages.\r\n"
  306.     print str
  307.     fwrite logfile str
  308.     print_remote "Q"
  309.     goto exit
  310.     end_if
  311. print "BAJAQNET: Receiving QWK packet\r\n"
  312. print_remote "ZN"
  313. mswait 1000
  314. call flush_input
  315. receive_file_via Z qwk
  316. sprintf str "BAJAQNET: Download of QWK packet "
  317. print_local "%s"
  318. fwrite logfile str
  319. chkfile qwk
  320. if_true
  321.     get_file_length i qwk
  322.     sprintf str "(%lu bytes) successful\r\n" i
  323. else
  324.     setstr "UNSUCCESSFUL!\r\n"
  325.     end_if
  326. print_local "%s"
  327. fwrite logfile str
  328. mswait 2000
  329. copy _sys_misc sm
  330. copy _node_misc nm
  331. print_remote "Q"
  332. goto exit
  333.  
  334. ###############################################################################
  335. # Wait for a specific text string (contained in current command string)       #
  336. # Automatically hits ENTER for HIT A KEY prompts                  #
  337. # Times-out after 30 seconds of host inactivity                   #
  338. # Sets logic state to TRUE if the string is located and returns           #
  339. # Sets logic state to FALSE if QWK: is found before the string and returns    #
  340. ###############################################################################
  341. :waitfor
  342. str waitforstr waitforbuf
  343. int cursor t1 t2
  344. copy waitforstr str
  345. :waitfor_reset
  346. set waitforbuf ""
  347. :waitfor_nextchar
  348. time t1
  349. :waitfor_checkinput
  350. inkey
  351. if_false
  352.     time t2
  353.     sub t2 t1
  354.     compare t2 MAX_INACTIVITY
  355.     if_greater
  356.         goto timeout
  357.         end_if
  358.     goto waitfor_checkinput
  359.     end_if
  360.  
  361. # Control key?
  362. compare_keys "^M^J^L^G^H"
  363. if_true
  364.     :spin_cursor
  365.     and cursor 3
  366.     switch cursor
  367.         case 0
  368.             print_local "-"
  369.             end_case
  370.         case 1
  371.             print_local "\\"
  372.             end_case
  373.         case 2
  374.             print_local "|"
  375.             end_case
  376.         case 3
  377.             print_local "/"
  378.             end_case
  379.         end_switch
  380.     print_local "\b"
  381.     add cursor 1
  382.     # Clear input buffer and continue
  383.     goto waitfor_reset
  384.     end_if
  385.  
  386. ungetkey
  387. :waitfor_additional
  388. inkey
  389. if_true
  390.     compare_keys "^M^J^L^G^H"
  391.     if_true
  392.         # Clear ungetkey buffer
  393.         setstr "\r"
  394.         ungetstr
  395.         getstr str 0 K_NOECHO
  396.         goto spin_cursor
  397.         end_if
  398.     ungetkey
  399.     goto waitfor_additional
  400.     end_if
  401. setstr "\r"
  402. ungetstr
  403. getstr str 128 K_NOECHO
  404. if_false
  405.         fprintf logfile "getstr returned FALSE\r\n"
  406.     setlogic FALSE
  407.     return
  408.     end_if
  409. strcat waitforbuf str
  410. # Handle Pause Prompt
  411. compare_substr waitforbuf "HIT A KEY"
  412. if_true
  413.         fprintf logfile "received hit a key prompt\r\n"
  414.     print_remote "\r"
  415.     goto waitfor_reset
  416.     end_if
  417. # Handle ANSI Cursor Position Request
  418. compare_substr waitforbuf "[6n"
  419. if_true
  420.     print_remote "\r"
  421.     goto waitfor_reset
  422.     end_if
  423. # Return TRUE if string found
  424. compare_substr waitforbuf waitforstr
  425. if_true
  426.     setlogic TRUE
  427.     return
  428.     end_if
  429. # Return FALSE if QWK: prompt found instead
  430. compare waitforbuf "QWK: "
  431. if_true
  432.     setlogic FALSE
  433.         return
  434.         end_if
  435.  
  436. goto waitfor_nextchar
  437.  
  438.  
  439. #####################################################################
  440. # Flush (remove, do not process) any characters in the input buffer #
  441. #####################################################################
  442. :flush_input
  443. inkey
  444. if_true # Flush input buffer
  445.         goto flush_input
  446.         end_if
  447. return
  448.  
  449. ###################################################
  450. # Timeout routine (falls-through to Exit routine) #
  451. ###################################################
  452. :timeout
  453. print_local "\r\nBAJAQNET: \7Time-out!\7\r\n"
  454. fprintf logfile "BAJAQNET: Time-out\r\n"
  455.  
  456. #################
  457. # Exit routine    #
  458. #################
  459. :exit
  460. print_local "BAJAQNET: Exiting...\r\n"
  461. # Mark ending time
  462. time end
  463. time_str str end
  464. fprintf logfile "BAJAQNET: Terminated: %s\r\n" str
  465. compare connect 0
  466. if_not_equal
  467.     copy i end
  468.     sub i connect
  469.     second_str tmp i
  470.     fprintf logfile "BAJAQNET: Time online: %s\r\n" tmp
  471.     end_if
  472. hangup
  473. not _sys_status SS_DCDHIGH
  474. mswait 2000
  475. return
  476.  
  477. # End of QNET.SRC
  478.