home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1996 October / PCO_10.ISO / filesbbs / bsrc_260.arj / SRC.ZIP / b_bbs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-31  |  10.3 KB  |  352 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-96, Bit Bucket Software Co.              */
  11. /*                                                                          */
  12. /*                This module was written by Vince Perriello                */
  13. /*                                                                          */
  14. /*                 BinkleyTerm BBS / UUCP Session Initiator                 */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*    For complete  details  of the licensing restrictions, please refer    */
  18. /*    to the License  agreement,  which  is published in its entirety in    */
  19. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.260.    */
  20. /*                                                                          */
  21. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  22. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  23. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  24. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  25. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  26. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  27. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  28. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  29. /*                                                                          */
  30. /*                                                                          */
  31. /* You can contact Bit Bucket Software Co. at any one of the following      */
  32. /* addresses:                                                               */
  33. /*                                                                          */
  34. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  35. /* P.O. Box 460398                AlterNet 7:42/1491                        */
  36. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  37. /*                                Internet f491.n343.z1.fidonet.org         */
  38. /*                                                                          */
  39. /* Please feel free to contact us at any time to share your comments about  */
  40. /* our software and/or licensing policies.                                  */
  41. /*                                                                          */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. /* Include this file before any other includes or defines! */
  45.  
  46. #include "includes.h"
  47.  
  48. #ifdef Snoop
  49. #include "snserver.h"
  50. extern HSNOOP hsnoop;
  51.  
  52. #endif                            /* Snoop */
  53.  
  54. void
  55. BBSexit ()
  56. {
  57.     long retval;
  58.     int xit = 0;
  59.     unsigned long 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.         time_release ();
  78.  
  79.     /* Make sure we waited at least 1 second */
  80.     while (CARRIER && !timeup (t1))
  81.         time_release ();
  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 (historywin, HIST_BBS_ROW, HIST_COL);
  95.         sb_puts (historywin, junk);
  96.     }
  97.  
  98.     if ((lock_baud && (pbtypes[baud].rate_value >= lock_baud))
  99.         || (ARQ_lock != 0))
  100.         baudrate = max_baud.rate_value;
  101.     else
  102.         baudrate = cur_baud.rate_value;
  103.  
  104.     if (strnicmp (BBSopt, "batch", 5) == 0)        /* if BBS flag is "batch"   */
  105.     {
  106.         (void) strcpy (command, COMFILE_PREFIX);/* Start of batch filename  */
  107.         (void) strcat (command, "BBSBATCH");    /* Meat of Batch filename   */
  108.         (void) strcat (command, COMFILE_SUFFIX);/* End of batch filename    */
  109.  
  110.         (void) unlink (command);                /* Delete old copies        */
  111.  
  112.         /* Try to open the file */
  113.  
  114.         if ((bbsbatch = fopen (command, write_ascii)) == NULL)
  115.         {
  116.             (void) got_error (MSG_TXT (M_OPEN_MSG), command);
  117.             return;
  118.         }
  119.         errno = 0;
  120.  
  121.         (void) fprintf (bbsbatch, "SPAWNBBS %lu %lu %lu %d %s\n",
  122.             baudrate, cur_baud.rate_value,
  123.             (unsigned long) hfComHandle, time_to_next (1), mdm_reliable);
  124.  
  125.         (void) fclose (bbsbatch);
  126.         xit = 1;
  127.     }
  128.  
  129. #ifdef BINKLEY_SOUNDS
  130.     Make_Sound (fnBBSSound);
  131. #endif
  132.  
  133.     if ((strnicmp (BBSopt, "exit", 4) == 0) || (xit))    /* "exit" or "batch"?  */
  134.     {
  135.         retval = baudrate / 100L;
  136.         status_line (MSG_TXT (M_BBS_EXIT), (int) retval);
  137.         if (vfossil_installed)
  138.             vfossil_close ();
  139.  
  140.         if (!share)                /* Turn off FOSSIL,         */
  141.             MDM_DISABLE ();        /* if need be               */
  142.         write_sched ();
  143.         exit ((int) retval);    /* and exit with error      */
  144.     }
  145.  
  146.     else if (strnicmp (BBSopt, "spawn", 5) == 0)    /* if BBS flag is "spawn"   */
  147.     {
  148.         status_line (MSG_TXT (M_BBS_SPAWN));
  149.         gotoxy (0, SB_ROWS);
  150.         (void) sprintf (command, "SPAWNBBS %lu %lu %lu %d %s",
  151.             baudrate, cur_baud.rate_value,
  152.             (unsigned long) hfComHandle, time_to_next (1), mdm_reliable);
  153.         close_up ();
  154.  
  155.         /* Run the BBS */
  156.  
  157.         b_spawn (command);
  158.  
  159.         come_back ();
  160.         status_line (MSG_TXT (M_BBS_RETURN));
  161.     }
  162. }
  163.  
  164. void
  165. close_up ()
  166. {
  167.     if (!share)
  168.         MDM_DISABLE ();
  169. #if defined(OS_2) | defined(_WIN32)
  170.     else
  171.         ComPause (hcModem);
  172. #endif
  173.  
  174.     vfossil_close ();
  175.  
  176.     /* Close the log file */
  177.  
  178.     if (status_log != NULL)
  179.         (void) fclose (status_log);
  180.  
  181. #ifdef Snoop
  182.     if (hsnoop != (HSNOOP) 0L)
  183.         snoop_close ();
  184. #endif                            /* Snoop */
  185.  
  186.     if (cost_log != NULL)
  187.         (void) fclose (cost_log);
  188.  
  189. #ifdef SET_CONMODE
  190.     setmode (fileno (stdin), O_TEXT);
  191.     setmode (fileno (stdout), O_TEXT);
  192. #endif
  193. }
  194.  
  195. void
  196. come_back ()
  197. {
  198. #ifdef Snoop
  199.     if (pipename[0] != '\0')
  200.     {
  201.         if (hsnoop == (HSNOOP) 0L)
  202.             snoop_open (pipename);
  203.         else
  204.             snoop_open (NULL);
  205.     }
  206. #endif                            /* Snoop */
  207.  
  208.     /* Re-enable ourselves */
  209.     if (Cominit (port_ptr, buftmo) != 0x1954)
  210.     {
  211.         (void) printf ("\n%s\n", MSG_TXT (M_FOSSIL_GONE));
  212.         exit (1);
  213.     }
  214.  
  215. #if defined(OS_2) | defined(_WIN32)
  216.     ComResume (hcModem);
  217. #endif
  218.  
  219.     if (status_log != NULL)
  220.     {
  221.         if ((status_log = share_fopen (log_name, append_ascii, DENY_WRITE)) == NULL)
  222.         {
  223.             (void) printf ("\n%s\n", MSG_TXT (M_NO_LOGFILE));
  224.             status_log = NULL;
  225.         }
  226.     }
  227.  
  228.     if (cost_log != NULL)
  229.     {
  230.         if ((cost_log = share_fopen (cost_log_name, append_ascii, DENY_WRITE)) == NULL)
  231.         {
  232.             (void) printf ("\n%s\n", MSG_TXT (M_NO_COSTFILE));
  233.             cost_log = NULL;
  234.         }
  235.     }
  236.     program_baud ();
  237.     vfossil_init ();
  238.  
  239. #ifdef SET_CONMODE
  240.     setmode (fileno (stdin), O_BINARY);
  241.     setmode (fileno (stdout), O_BINARY);
  242. #endif
  243.  
  244.     if (fullscreen && un_attended)
  245.     {
  246.         vfossil_cursor (0);
  247.         screen_clear ();
  248.         sb_dirty ();
  249.         opening_banner ();
  250.         mailer_banner ();
  251.         sb_show ();
  252.     }
  253. }
  254.  
  255. void
  256. UUCPexit (int n, int fCheckCarrier)
  257. {
  258.     unsigned long baudrate;
  259.     char command[80];
  260.     FILE *mailbatch;
  261.     long t1, t2;
  262.  
  263.     /* We check carrier for all applications where we would want to send
  264.        MAILnote. Good thing. SendBanner is highly sensitive to carrier. */
  265.  
  266.     if (MAILnote != NULL && fCheckCarrier)
  267.     {
  268.         (void) SendBanner ((char far *) "\r\n");    /* Start with newline   */
  269.         (void) SendBanner ((char far *) MAILnote);    /* Say it's mail time   */
  270.         (void) SendBanner ((char far *) "\r\n");    /* End with a newline   */
  271.     }
  272.  
  273.     t1 = timerset (100);
  274.     t2 = timerset (400);
  275.  
  276.     /* Wait for output complete, 4 seconds, or carrier loss */
  277.  
  278.     while (!OUT_EMPTY () && !timeup (t2) && (!fCheckCarrier || CARRIER))
  279.         time_release ();
  280.  
  281.     /* Make sure we waited at least 1 second */
  282.  
  283.     while ((!fCheckCarrier || CARRIER) && !timeup (t1))
  284.         time_release ();
  285.  
  286.     /* Now if there is no carrier bag it */
  287.  
  288.     if (fCheckCarrier && !CARRIER)
  289.     {
  290.         status_line (MSG_TXT (M_NO_CARRIER));
  291.         return;
  292.     }
  293.  
  294.     if ((lock_baud && (pbtypes[baud].rate_value >= lock_baud))
  295.         || (ARQ_lock != 0))
  296.         baudrate = max_baud.rate_value;
  297.     else
  298.         baudrate = cur_baud.rate_value;
  299.  
  300. #ifdef BINKLEY_SOUNDS
  301.     Make_Sound (fnEXTSound);
  302. #endif
  303.  
  304.     if (EXTopt != NULL && strnicmp (EXTopt, "spawn", 5) == 0)    /* opt="spawn" */
  305.     {
  306.         status_line (MSG_TXT (M_EXT_SPAWN));
  307.         gotoxy (0, SB_ROWS);
  308.         (void) sprintf (command, "EXTMAIL %lu %lu %lu %d %d %s",
  309.             baudrate, cur_baud.rate_value,
  310.             (unsigned long) hfComHandle, time_to_next (1), n, mdm_reliable);
  311.         close_up ();
  312.  
  313.         /* Run the External Program */
  314.  
  315.         b_spawn (command);
  316.  
  317.         come_back ();
  318.         status_line (MSG_TXT (M_EXT_RETURN));
  319.         return;
  320.     }
  321.  
  322.     (void) strcpy (command, COMFILE_PREFIX);    /* Start of batch filename  */
  323.     (void) strcat (command, "MAILBAT");            /* Meat of Batch filename   */
  324.     (void) strcat (command, COMFILE_SUFFIX);    /* End of batch filename    */
  325.  
  326.     (void) unlink (command);    /* Delete old copies    */
  327.  
  328.     /* Try to open the file */
  329.  
  330.     if ((mailbatch = fopen (command, append_ascii)) == NULL)
  331.     {
  332.         (void) got_error (MSG_TXT (M_OPEN_MSG), command);
  333.         return;
  334.     }
  335.  
  336.     (void) fprintf (mailbatch, "EXTMAIL %lu %lu %lu %d %d %s\n",
  337.         baudrate, cur_baud.rate_value,
  338.         (unsigned long) hfComHandle, time_to_next (1), n, mdm_reliable);
  339.     (void) fclose (mailbatch);
  340.  
  341.     status_line (MSG_TXT (M_EXT_MAIL), n);
  342.  
  343.     if (vfossil_installed)
  344.         vfossil_close ();
  345.  
  346.     if (!share)                    /* Turn off FOSSIL,         */
  347.         MDM_DISABLE ();            /* if need be               */
  348.  
  349.     write_sched ();                /* Save scheduler info      */
  350.     exit (n);                    /* and exit with UUCP error */
  351. }
  352.