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