home *** CD-ROM | disk | FTP | other *** search
/ TestDrive Super Store 2.3 / TESTDRIVE_2.ISO / quickenw / connect.scr < prev    next >
Encoding:
Text File  |  1993-12-08  |  7.5 KB  |  377 lines

  1. !+N
  2. CompuServe = 1;        ! "CompuServe"
  3. !-N
  4.  
  5.  
  6. define %CR = "^M";
  7. define %FALSE = 0;
  8. define %TRUE = 1;
  9.  
  10.     dial = 0;
  11.     if %Connected = 1 goto Do_CIS_Script;
  12.     UsingModem = %FALSE;
  13.     init %Port, %BaudRate;
  14.     if %_init goto Continue_Connect;
  15.  
  16.     define %Result = 14;
  17.     goto Connect_Failure;
  18.  
  19. Continue_Connect:
  20.     Result = %Failure;
  21.     on cancel goto Cancel_Connect;
  22.  
  23. !!  DIAL the PHONE    
  24.     
  25.     gosub phone;
  26.     if Result = %Cancel goto Cancel_Connect;
  27.     if Result = %Failure goto Connect_Failure;
  28.     UsingModem = %TRUE;
  29.  
  30.  
  31. !!  Negotiate the Network and Logon
  32.  
  33. Connect_CIS:
  34.     send %CR;
  35.  
  36. Do_CIS_Script:
  37.     Result = %Failure;
  38.     gosub login;
  39.  
  40. Back_From_Login:
  41.     if Result = %Failure goto Connect_Failure;
  42.     if Result = %Cancel goto Cancel_Connect;
  43.     exit %Success;
  44.  
  45. Connect_Failure:
  46.     if %Connected = 1 goto Connect_Failure_Exit;
  47. !!    if UsingModem goto Hangup_Connect;
  48.     goto Hangup_Connect;
  49.  
  50. Connect_Failure_Exit:
  51.     reset;
  52.     exit %Failure;
  53.  
  54. Hangup_Connect:
  55.     dial = 1;
  56.     gosub phone;
  57.     reset;
  58.     exit %Failure;
  59.  
  60. Cancel_Connect:
  61.     if %Connected = 1 goto CC_1;
  62.     if UsingModem = %FALSE goto CC_1;
  63.     gosub Hangup;
  64. CC_1:
  65.     define %Result = 12;
  66.     reset;
  67.     exit %Cancel;
  68.  
  69.  
  70.  
  71. !!  SUBCOMMANDS for DIALING and HANGING UP
  72.  
  73. phone:
  74.     WaitTime = 10;
  75.  
  76.     if dial = 0 goto Do_Phone_Connect;
  77.     gosub Hangup;
  78.     return;  ! from GOSUB
  79.  
  80. Send_Modem_Cmd:
  81.     if (ModemStr = "") goto End_Modem_Cmd;
  82.  
  83.     sendm %mdm_Prefix;
  84.     send  ModemStr;        
  85.     sendm %mdm_Suffix;
  86.  
  87. End_Modem_Cmd:
  88.     return;  ! from GOSUB
  89.     
  90. Hangup:
  91.     HangupDone = %FALSE;
  92.     if UsingModem goto Send_Escape;
  93.     goto Send_Hangup;
  94.  
  95. Send_Escape:
  96.     wait until 12;
  97.     sendm %mdm_EscapeCode;
  98.     wait until 12;
  99.     wait
  100.         %mdm_Ack goto End_Escape_Wait,
  101.         "DISCONNECT" goto Hangup_Complete,
  102.         "CARRIER LOST" goto Hangup_Complete
  103.     until 10;
  104.  
  105. End_Escape_Wait:
  106.     wait until 2;
  107.  
  108. Send_Hangup:
  109.     ModemStr = %mdm_Hangup;
  110.     gosub Send_Modem_Cmd;
  111.     wait
  112.         %mdm_Ack goto Pause_And_Return,
  113.         "DISCONNECT" goto Pause_And_Return
  114.     until 20;  !! (10 is not enough for some modems to hang up)
  115.     if HangupDone goto Pause_And_Return;
  116.     HangupDone = %TRUE;
  117.     goto Send_Escape;
  118.  
  119. Pause_And_Return:
  120.     wait until 2;
  121.  
  122. Hangup_Complete:
  123.     return;
  124.  
  125. Do_Phone_Connect:
  126.     RingLimit = 5;
  127.     RingCount = 0;
  128.     UsingModem = %FALSE;
  129.     on cancel goto Phone_Cancelled;
  130.     if %DialType = 0 goto Get_Tone_Str;
  131.     DialTypeStr = %mdm_Pulse_Dial;
  132.     goto Init_Modem;
  133.  
  134. Get_Tone_Str:
  135.     DialTypeStr = %mdm_Tone_Dial;
  136.  
  137. Init_Modem:
  138.     show "Initializing Modem";
  139.     MsgStr = "Dialing " & %Phone;
  140.     ModemStr = %mdm_Reset;
  141.     gosub Send_Modem_Cmd;
  142.     wait 
  143.         %mdm_Ack goto Modem_OK,
  144.     "0"     goto Modem_OK
  145.     until 40;
  146.     gosub Hangup;
  147.     wait until 2;
  148.      
  149.     ModemStr = %mdm_Reset;
  150.     gosub Send_Modem_Cmd;
  151.     wait 
  152.         %mdm_Ack goto Modem_OK,
  153.     "0"     goto Modem_OK
  154.     until 40;
  155.     define %Result = 14;
  156.     goto Return_FailureMsg;
  157.  
  158.  
  159. Modem_OK:
  160.     wait until 2;
  161.     ModemStr = %mdm_Init;
  162.     if ModemStr <> "" goto Add_V1;
  163.         ModemStr = %mdm_Prefix;
  164. Add_V1:
  165.     ModemStr = ModemStr & "V1";
  166.     send  ModemStr;
  167.     sendm %mdm_Suffix;
  168.     wait 
  169.         %mdm_Ack goto End_Wait1
  170.     until 10;
  171.  
  172. End_Wait1:
  173.     wait until 2;
  174.  
  175. Try_Phone:
  176.     count = 0;
  177.     FailStr = "";
  178.  
  179. Dial_Phone:
  180.     if (count > %Retry) goto Phone_Failed;
  181.     show MsgStr;
  182.     ModemStr = DialTypeStr & %Phone;
  183.     gosub Send_Modem_Cmd;
  184.  
  185. Start_Phone_Loop:
  186.     wait
  187.         %mdm_Success goto Modem_Success,
  188.         %mdm_Failure goto Modem_Failure,
  189.         "No Dial" goto No_Dial_Tone,
  190.         "Dial Complete" goto Dial_Complete,
  191.         "Busy" goto Line_Busy,
  192.         "Ring" goto Remote_Ring
  193.     until 450;
  194.     define %Result = 13;
  195.     goto Return_FailureMsg;
  196.     
  197. Modem_Success:
  198.     wait until 2;
  199.     Result = %Success;
  200.     return;
  201.  
  202. Modem_Failure:
  203.  
  204. No_Dial_Tone:
  205.     define %Result = 13;
  206.     goto Return_FailureMsg;
  207.  
  208. Dial_Complete:
  209.     MsgStr = "Dialed " & %Phone & ", awaiting answer";
  210.     show MsgStr;
  211.     goto Start_Phone_Loop;
  212.         
  213. Line_Busy:
  214.     FailStr = "Number is busy";
  215.     wait until 2 * WaitTime;
  216.     send %CR;
  217.     wait
  218.         %mdm_Success goto End_Line_Busy,
  219.         %mdm_Failure goto End_Line_Busy,
  220.         "No Dial" goto End_Line_Busy,
  221.         "Dial Complete" goto End_Line_Busy,
  222.         "Busy" goto End_Line_Busy,
  223.         "Ring" goto End_Line_Busy
  224.     until 56;
  225.  
  226. End_Line_Busy:
  227.     wait until WaitTime;
  228.     goto End_Phone_Loop;
  229.  
  230. Remote_Ring:
  231.     if RingCount <= RingLimit goto Show_Ringing;
  232.  
  233.     FailStr = "No answer";
  234.     goto End_Phone_Loop;
  235.  
  236. Show_Ringing:
  237.     MsgStr = %Phone & " is ringing, awaiting answer";
  238.     show MsgStr;
  239.     goto Start_Phone_Loop;
  240.  
  241. End_Phone_Loop:
  242.     MsgStr = FailStr & ", redialing " & %Phone;
  243.     count = count + 1;
  244.     goto Dial_Phone;
  245.  
  246. Phone_Cancelled:
  247.     on cancel goto Exit_Cancel;
  248.     gosub Hangup;
  249.  
  250. Exit_Cancel:
  251.     Result = %Cancel;
  252.     define %Result = 12;
  253.     return;
  254.  
  255. Phone_Failed:
  256.     if FailStr <> "" goto Exit_Failure;
  257.     FailStr = "Dialing failed";
  258.  
  259. Exit_Failure:
  260.     define %FailureMsg = FailStr;
  261.     define %Result = 13;
  262.     Result = %Failure;
  263.     return;
  264.  
  265.  
  266. !!  NETWORK and LOGON
  267.  
  268. login:
  269.     if %Connected = 1 goto Dont_Show_Message;
  270.     show "Logging into IntelliCharge processing center";
  271.  
  272. Dont_Show_Message:
  273.     Tries = 7;
  274.     on cancel goto Return_Cancel;
  275.     FirstTry = %TRUE;
  276.     FailStr = "";
  277.     ETX = "^C";
  278.     CompuServeHost = "CPS^M";
  279.  
  280. Start_Connect:
  281.     if Tries = 0 goto CIS_Failure;
  282.     Tries = Tries - 1;
  283.  
  284. Connect_Wait:
  285.     wait
  286.         "UIC:"       goto Send_ETX,
  287.         "Host Name:" goto Send_Host_Name,
  288.         "User ID:"   goto Send_ID,
  289.         "Password:"  goto Send_Password
  290.     until 80;
  291.  
  292. Send_CR:
  293.     send %CR;
  294.     goto Start_Connect;
  295.  
  296. Send_ETX:
  297.     send ETX;
  298.     goto Connect_Wait;
  299.  
  300. Send_Host_Name:
  301.     send CompuServeHost;
  302.     goto Connect_Wait;
  303.  
  304. Send_ID:
  305.     send %UserID & %LogonParams & "/INT" & %CR;
  306.     goto Connect_Wait;
  307.  
  308. Send_Password:
  309.     send %Password & %CR;
  310.     goto Logon_Wait;
  311.  
  312. Logon_Wait:
  313.     wait
  314.     "Address ?"  goto Return_Success,
  315.         "CompuServe" goto Return_Success,
  316.         "OK"         goto Return_Success,
  317.         "^F"         goto Return_Success,
  318.         "? LOG"      goto Process_Log_Msg,
  319.     "??LOG"         goto Process_Log_Msg,
  320.         " NTW"       goto System_Unavailable,
  321.         "^[I"         goto Send_Response
  322.     until 200;
  323.     goto CIS_Failure;
  324.  
  325. Process_Log_Msg:
  326.     wait
  327.         "INE"    goto Bad_ID,
  328.     "ISX"    goto Bad_ID,
  329.     "SIL"    goto System_Unavailable,
  330.     "SIU"    goto System_Unavailable,
  331.     "SNA"    goto System_Unavailable,
  332.     "STU"    goto System_Unavailable
  333.     until 50;
  334.     goto Try_Again;
  335.  
  336. Bad_ID:
  337.     define %Result = 15;
  338.     goto Return_FailureMsg;
  339.  
  340. System_Unavailable:
  341.     define %Result = 17;
  342.     goto Return_FailureMsg;
  343.  
  344. Try_Again:
  345.     if not FirstTry goto CIS_Failure;
  346.     send ETX;
  347.     FirstTry = %FALSE;
  348.     wait
  349.         "User ID"    goto Send_ID
  350.     until 140;
  351.     goto CIS_Failure;
  352.  
  353. Send_Response:
  354. !!    sendi "#IBXQW3,AP,+";
  355.     sendi %ESCIResponse;
  356.     Result = %Success;
  357.     return;
  358.  
  359. CIS_Failure:
  360.     define %Result = 15;
  361.     goto Return_FailureMsg;
  362.  
  363. Return_FailureMsg:
  364.     define %FailureMsg = "Disconnecting";
  365.     Result = %Failure;
  366.     return;
  367.  
  368. Return_Cancel:
  369.     Result = %Cancel;
  370.     return;
  371.  
  372. Return_Success:
  373.     define %Result = 0;
  374.     Result = %Success;
  375.     return;
  376.  
  377.