home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / bts314b4 / b_bbs.c < prev    next >
C/C++ Source or Header  |  1994-01-08  |  11KB  |  321 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-90, 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.240.    */
  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:132/491, 1:141/491  */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n132.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 <stdio.h>
  47. #include <signal.h>
  48. #include <ctype.h>
  49. #include <conio.h>
  50. #include <string.h>
  51. #ifndef LATTICE
  52. #include <process.h>
  53. #endif
  54. #include <stdlib.h>
  55. #include <errno.h>
  56.  
  57.  
  58. #include "bink.h"
  59. #include "msgs.h"
  60. #include "sched.h"
  61. #include "sbuf.h"
  62. #include "com.h"
  63. #include "vfossil.h"
  64.  
  65. void BBSexit( void )
  66. {
  67.    int retval;
  68.    int xit = 0;
  69.    unsigned int baudrate;
  70.    char command[80];
  71.    FILE *bbsbatch;
  72.    long t1, t2;
  73.  
  74.    if (BBSnote != NULL)
  75.       {
  76.       (void) SendBanner ("\r\n");                /* Start with newline    */
  77.       (void) SendBanner (BBSnote);               /* Tell user we're going */
  78.       (void) SendBanner ("\r\n");                /* End it with a newline */
  79.       }
  80.  
  81.    t1 = timerset (50);
  82.    t2 = timerset (400);
  83.  
  84.    /* Wait for output complete, 4 seconds, or carrier loss */
  85.  
  86.    while (!OUT_EMPTY () && !timeup (t2) && CARRIER)
  87.       ;
  88.  
  89.    /* Make sure we waited at least 1/2 second */
  90.    while (CARRIER && !timeup (t1))
  91.       ;
  92.  
  93.    /* Now if there is no carrier bag it */
  94.    if (!CARRIER)
  95.       {
  96.       status_line (msgtxt[M_NO_CARRIER]);
  97.       return;
  98.       }
  99.  
  100.    ++hist.bbs_calls;
  101.    if (un_attended && fullscreen)
  102.       {
  103.       sb_move (historywin, HIST_BBS_ROW, HIST_COL);
  104.       (void) sprintf (junk, "%d/%d/%d",
  105.           hist.bbs_calls, hist.mail_calls, hist.extmails);
  106.       sb_puts (historywin, (unsigned char *) junk);
  107.         }
  108.  
  109. #ifndef SWGNODO
  110.     /*
  111.      * It seems that we'd rather have the CONNECT baud rate rather
  112.      * than the DTE!
  113.      */
  114.    if (lock_baud && (cur_baud >= lock_baud))
  115.       baudrate = max_baud.rate_value;
  116.    else baudrate = btypes[baud].rate_value;
  117. #endif
  118.  
  119.    if (BBSopt && (strnicmp (BBSopt, "batch", 5) == 0))       /* if BBS flag is "batch" */
  120.       {
  121. #ifndef OS_2
  122.       (void) strcpy (command, "BBSBATCH.BAT");          /* Batch file name        */
  123. #else
  124.       (void) strcpy (command, "BBSBATCH.CMD");          /* Batch file name        */
  125. #endif
  126.       (void) unlink (command);                          /* Delete old copies      */
  127.       if ((bbsbatch = fopen (command, write_ascii)) == NULL)   /* Try to open it  */
  128.          {
  129.          (void) got_error (msgtxt[M_OPEN_MSG], command);
  130.          return;
  131.          }
  132.       errno = 0;
  133. #ifndef OS_2
  134.       (void) fprintf (bbsbatch, "SPAWNBBS %u %d %d %s\n",
  135.                baudrate, port_ptr + 1, time_to_next (1), mdm_reliable);
  136. #else
  137.       (void) fprintf (bbsbatch, "SPAWNBBS %u %d %d %s\n",
  138.                baudrate, hfComHandle, time_to_next (1), mdm_reliable);
  139. #endif
  140.       (void) fclose (bbsbatch);
  141.       xit = 1;
  142.       }
  143.  
  144.    if ((BBSopt && (strnicmp (BBSopt, "exit", 4) == 0)) || xit)    /* "exit" or "batch" ??   */
  145.       {
  146.       retval = (int) (baudrate / 100);
  147.       status_line (msgtxt[M_BBS_EXIT], retval);
  148.       if (vfossil_installed)
  149.          vfossil_close ();
  150.  
  151.       if (!share)                                /* Turn off FOSSIL,       */
  152.          MDM_DISABLE ();                         /* if need be             */
  153.       write_sched ();
  154.       if (reset_port) exit_port();
  155.       exit (retval);                             /* and exit with error    */
  156.       }
  157.  
  158.    if (BBSopt && (strnicmp (BBSopt, "spawn", 5) == 0))       /* if BBS flag is "spawn" */
  159.       {
  160.       status_line (msgtxt[M_BBS_SPAWN]);
  161.       gotoxy (0, SB_ROWS);
  162. #ifndef OS_2
  163.       (void) sprintf (command, "SPAWNBBS %u %d %d %s",
  164.                baudrate, port_ptr + 1, time_to_next (1), mdm_reliable);
  165. #else
  166.       (void) sprintf (command, "SPAWNBBS %u %d %d %s",
  167.                baudrate, hfComHandle, time_to_next (1), mdm_reliable);
  168. #endif
  169.       close_up ();
  170.  
  171.       /* Run the BBS */
  172.       b_spawn (command);
  173.  
  174.       come_back ();
  175.       status_line (msgtxt[M_BBS_RETURN]);
  176.       }
  177. }
  178.  
  179. void close_up( void )
  180. {
  181.    if (!share)
  182.        MDM_DISABLE ();
  183.  
  184.    vfossil_close ();
  185.  
  186. #ifdef NEW
  187.  
  188.     close_log();
  189.     
  190. #else
  191.  
  192.    /* Close the log file */
  193.    if (status_log != NULL)
  194.       (void) fclose (status_log);
  195.  
  196. #endif
  197.  
  198. #ifdef OS_2
  199. #ifdef Snoop
  200.    snoop_close();
  201. #endif /* Snoop */
  202. #endif /* OS_2  */
  203. }
  204.  
  205. void come_back( void )
  206. {
  207. #ifdef OS_2
  208. #ifdef Snoop
  209.    snoop_open(NULL);
  210. #endif /* Snoop */
  211. #endif /* OS_2  */
  212.  
  213.    /* Re-enable ourselves */
  214.    if (Cominit (port_ptr) != 0x1954)
  215.       {
  216.       (void) printf ("\n%s\n", msgtxt[M_FOSSIL_GONE]);
  217.       if (reset_port) exit_port();
  218.       exit (1);
  219.       }
  220.  
  221. #ifdef NEW
  222.  
  223.     open_log();
  224.  
  225. #else
  226.  
  227.    if (status_log != NULL)
  228.       {
  229.       if ((status_log = fopen (log_name, append_ascii)) == NULL)
  230.          {
  231.          (void) printf ("\n%s\n", msgtxt[M_NO_LOGFILE]);
  232.          }
  233.       }
  234.  
  235. #endif
  236.  
  237.    MDM_ENABLE (lock_baud && (btypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : btypes[baud].rate_mask);
  238.    vfossil_init ();
  239.    if (fullscreen && un_attended)
  240.       {
  241.       screen_clear ();
  242.       sb_dirty ();
  243.       opening_banner ();
  244.       mailer_banner ();
  245.       sb_show ();
  246.       }
  247. }
  248.  
  249.  
  250. void UUCPexit (int n)    /* UUCP Errorlevel value */
  251. {
  252.    unsigned int baudrate;
  253.    char command[80];
  254.    FILE *mailbatch;
  255.    long t1, t2;
  256.  
  257.    if (MAILnote != NULL)
  258.       {
  259.       (void) SendBanner ("\r\n");                /* Start with newline */
  260.       (void) SendBanner (MAILnote);              /* Say it's mail time */
  261.       (void) SendBanner ("\r\n");                /* End with a newline */
  262.       }
  263.  
  264.    t1 = timerset (50);
  265.    t2 = timerset (400);
  266.  
  267.    /* Wait for output complete, 4 seconds, or carrier loss */
  268.  
  269.    while (!OUT_EMPTY () && !timeup (t2) && CARRIER)
  270.       ;
  271.  
  272.    /* Make sure we waited at least 1/2 second */
  273.    while (CARRIER && !timeup (t1))
  274.       ;
  275.  
  276.    /* Now if there is no carrier bag it */
  277.    if (!CARRIER)
  278.       {
  279.       status_line (msgtxt[M_NO_CARRIER]);
  280.       return;
  281.       }
  282.  
  283.  
  284.    if (lock_baud && (cur_baud >= lock_baud))
  285.       baudrate = max_baud.rate_value;
  286.    else baudrate = btypes[baud].rate_value;
  287.  
  288. #ifndef OS_2
  289.   (void) strcpy (command, "MAILBAT.BAT");              /* Batch file name   */
  290. #else
  291.   (void) strcpy (command, "MAILBAT.CMD");              /* Batch file name   */
  292. #endif
  293.    (void) unlink (command);                             /* Delete old copies */
  294.    if ((mailbatch = fopen (command, append_ascii)) == NULL) /* Try to open it */
  295.       {
  296.       (void) got_error (msgtxt[M_OPEN_MSG], command);
  297.       return;
  298.       }
  299. #ifndef OS_2
  300.    (void) fprintf (mailbatch, "EXTMAIL %u %d %d %d %s\n",
  301.             baudrate, port_ptr + 1, time_to_next (1), n, mdm_reliable);
  302. #else
  303.    (void) fprintf (mailbatch, "EXTMAIL %u %d %d %d %s\n",
  304.             baudrate, hfComHandle, time_to_next (1), n, mdm_reliable);
  305. #endif
  306.    (void) fclose (mailbatch);
  307.  
  308.    status_line (msgtxt[M_EXT_MAIL], n);
  309.     hist.extmails++;                                /* Increment extern count */
  310.  
  311.    if (vfossil_installed)
  312.       vfossil_close ();
  313.  
  314.    if (!share)                                   /* Turn off FOSSIL,          */
  315.       MDM_DISABLE ();                            /* if need be                */
  316.  
  317.    write_sched ();                               /* Save scheduler info       */
  318.    if (reset_port) exit_port();
  319.    exit (n);                                     /* and exit with UUCP error  */
  320. }
  321.