home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRC_250.LZH / B_BBS.C < prev    next >
Text File  |  1991-09-15  |  10KB  |  277 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*               This module was written by Vince Perriello                 */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                BinkleyTerm BBS / UUCP Session Initiator                  */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.250.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  27. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  28. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  29. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  30. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /* You can contact Bit Bucket Software Co. at any one of the following      */
  34. /* addresses:                                                               */
  35. /*                                                                          */
  36. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n343.z1.fidonet.org         */
  40. /*                                                                          */
  41. /* Please feel free to contact us at any time to share your comments about  */
  42. /* our software and/or licensing policies.                                  */
  43. /*                                                                          */
  44. /*--------------------------------------------------------------------------*/
  45.  
  46. /* Include this file before any other includes or defines! */
  47.  
  48. #include "includes.h"
  49.  
  50. #ifdef Snoop
  51. #include "snserver.h"
  52. extern HSNOOP hsnoop;
  53. #endif /* Snoop */
  54.  
  55. void BBSexit ()
  56. {
  57.    int retval;
  58.    int xit = 0;
  59.    unsigned int baudrate;
  60.    char command[80];
  61.    FILE *bbsbatch;
  62.    long t1, t2;
  63.  
  64.    if (BBSnote != NULL)
  65.       {
  66.       (void) SendBanner ((char far *)"\r\n");    /* Start with newline    */
  67.       (void) SendBanner ((char far *)BBSnote);   /* Tell user we're going */
  68.       (void) SendBanner ((char far *)"\r\n");    /* End it with a newline */
  69.       }
  70.  
  71.    t1 = timerset (100);
  72.    t2 = timerset (400);
  73.  
  74.    /* Wait for output complete, 4 seconds, or carrier loss */
  75.  
  76.    while (!OUT_EMPTY () && !timeup (t2) && CARRIER)
  77.       ;
  78.  
  79.    /* Make sure we waited at least 1 second */
  80.    while (CARRIER && !timeup (t1))
  81.       ;
  82.  
  83.    /* Now if there is no carrier bag it */
  84.    if (!CARRIER)
  85.       {
  86.       status_line (MSG_TXT(M_NO_CARRIER));
  87.       return;
  88.       }
  89.  
  90.    ++hist.bbs_calls;
  91.    if (un_attended && fullscreen)
  92.       {
  93.       (void) sprintf (junk, "%d/%d", hist.bbs_calls, hist.mail_calls);
  94.       sb_move (history_hWnd, HIST_BBS_ROW, HIST_COL);
  95.       sb_puts( history_BBS, junk );
  96.       }
  97.  
  98.    if ((lock_baud && (btypes[baud].rate_value >= (unsigned)lock_baud))
  99.    || (ARQ_lock != 0))
  100.       baudrate = max_baud.rate_value;
  101.    else baudrate = cur_baud.rate_value;
  102.  
  103.    if (strnicmp (BBSopt, "batch", 5) == 0)       /* if BBS flag is "batch" */
  104.       {
  105.       (void) strcpy (command, COMFILE_PREFIX);          /* Start of batch filename*/
  106.       (void) strcat (command, "BBSBATCH");              /* Meat of Batch filename */
  107.       (void) strcat (command, COMFILE_SUFFIX);          /* End of batch filename  */
  108.  
  109.       (void) unlink (command);                          /* Delete old copies      */
  110.       if ((bbsbatch = fopen (command, "wt")) == NULL)   /* Try to open it  */
  111.          {
  112.          (void) got_error (MSG_TXT(M_OPEN_MSG), command);
  113.          return;
  114.          }
  115.       errno = 0;
  116.  
  117.       (void) fprintf (bbsbatch, "SPAWNBBS %u %u %d %d %s\n",
  118.                baudrate, cur_baud.rate_value,
  119.                   hfComHandle, time_to_next (1), mdm_reliable);
  120.  
  121.       (void) fclose (bbsbatch);
  122.       xit = 1;
  123.       }
  124.  
  125.    if ((strnicmp (BBSopt, "exit", 4) == 0) || (xit))    /* "exit" or "batch" ??   */
  126.       {
  127.       retval = (int) (baudrate / 100);
  128.       status_line (MSG_TXT(M_BBS_EXIT), retval);
  129.       if (vfossil_installed)
  130.          vfossil_close ();
  131.  
  132.       if (!share)                                /* Turn off FOSSIL,       */
  133.          MDM_DISABLE ();                         /* if need be             */
  134.       write_sched ();
  135.       exit (retval);                             /* and exit with error    */
  136.       }
  137.  
  138.    if (strnicmp (BBSopt, "spawn", 5) == 0)       /* if BBS flag is "spawn" */
  139.       {
  140.       status_line (MSG_TXT(M_BBS_SPAWN));
  141.       gotoxy (0, SB_ROWS);
  142.       (void) sprintf (command, "SPAWNBBS %u %u %d %d %s",
  143.                baudrate, cur_baud.rate_value,
  144.                   hfComHandle, time_to_next (1), mdm_reliable);
  145.       close_up ();
  146.  
  147.       /* Run the BBS */
  148.       b_spawn (command);
  149.  
  150.       come_back ();
  151.       status_line (MSG_TXT(M_BBS_RETURN));
  152.       }
  153. }
  154.  
  155. void close_up ()
  156. {
  157.    if (!share)
  158.        MDM_DISABLE ();
  159.  
  160.    vfossil_close ();
  161.  
  162.    /* Close the log file */
  163.    if (status_log != NULL)
  164.       (void) fclose (status_log);
  165. #ifdef Snoop
  166.    if (hsnoop != (HSNOOP)NULL)
  167.       snoop_close();
  168. #endif /* Snoop */
  169. }
  170.  
  171. void come_back ()
  172. {
  173. #ifdef Snoop
  174.    if (pipename[0] != '\0')
  175.       {
  176.       if (hsnoop == (HSNOOP)NULL)
  177.          snoop_open(pipename);
  178.       else
  179.          snoop_open(NULL);
  180.       }
  181. #endif /* Snoop */
  182.  
  183.    /* Re-enable ourselves */
  184.    if (Cominit (port_ptr, buftmo) != 0x1954)
  185.       {
  186.       (void) printf ("\n%s\n", MSG_TXT(M_FOSSIL_GONE));
  187.       exit (1);
  188.       }
  189.  
  190.    if (status_log != NULL)
  191.       {
  192.       if ((status_log = share_fopen (log_name, "at", DENY_WRITE)) == NULL)
  193.          {
  194.          (void) printf ("\n%s\n", MSG_TXT(M_NO_LOGFILE));
  195.          }
  196.       }
  197.  
  198.    program_baud ();
  199.    vfossil_init ();
  200.    if (fullscreen && un_attended)
  201.       {
  202.       screen_clear ();
  203.       sb_dirty ();
  204.       opening_banner ();
  205.       mailer_banner ();
  206.       sb_show ();
  207.       }
  208. }
  209.  
  210.  
  211. void UUCPexit (int n)
  212. {
  213.    unsigned int baudrate;
  214.    char command[80];
  215.    FILE *mailbatch;
  216.    long t1, t2;
  217.  
  218.    if (MAILnote != NULL)
  219.       {
  220.       (void) SendBanner ((char far *)"\r\n");    /* Start with newline */
  221.       (void) SendBanner ((char far *)MAILnote);  /* Say it's mail time */
  222.       (void) SendBanner ((char far *)"\r\n");    /* End with a newline */
  223.       }
  224.  
  225.    t1 = timerset (100);
  226.    t2 = timerset (400);
  227.  
  228.    /* Wait for output complete, 4 seconds, or carrier loss */
  229.  
  230.    while (!OUT_EMPTY () && !timeup (t2) && CARRIER)
  231.       ;
  232.  
  233.    /* Make sure we waited at least 1 second */
  234.    while (CARRIER && !timeup (t1))
  235.       ;
  236.  
  237.    /* Now if there is no carrier bag it */
  238.    if (!CARRIER)
  239.       {
  240.       status_line (MSG_TXT(M_NO_CARRIER));
  241.       return;
  242.       }
  243.  
  244.    if ((lock_baud && (btypes[baud].rate_value >= (unsigned)lock_baud))
  245.    || (ARQ_lock != 0))
  246.       baudrate = max_baud.rate_value;
  247.    else baudrate = cur_baud.rate_value;
  248.  
  249.    (void) strcpy (command, COMFILE_PREFIX);            /* Start of batch filename*/
  250.    (void) strcat (command, "MAILBAT");                 /* Meat of Batch filename */
  251.    (void) strcat (command, COMFILE_SUFFIX);            /* End of batch filename  */
  252.  
  253.    (void) unlink (command);                             /* Delete old copies */
  254.    if ((mailbatch = fopen (command, "at")) == NULL) /* Try to open it */
  255.       {
  256.       (void) got_error (MSG_TXT(M_OPEN_MSG), command);
  257.       return;
  258.       }
  259.  
  260.    (void) fprintf (mailbatch, "EXTMAIL %u %u %d %d %d %s\n",
  261.                baudrate, cur_baud.rate_value,
  262.                   hfComHandle, time_to_next (1), n, mdm_reliable);
  263.    (void) fclose (mailbatch);
  264.  
  265.    status_line (MSG_TXT(M_EXT_MAIL), n);
  266.  
  267.    if (vfossil_installed)
  268.       vfossil_close ();
  269.  
  270.    if (!share)                                   /* Turn off FOSSIL,          */
  271.       MDM_DISABLE ();                            /* if need be                */
  272.  
  273.    write_sched ();                               /* Save scheduler info       */
  274.    exit (n);                                     /* and exit with UUCP error  */
  275. }
  276. 
  277.