home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BTMTSRC3.ZIP / YOOHOO.C < prev    next >
C/C++ Source or Header  |  1991-10-17  |  19KB  |  614 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 "YooHoo" Processor                       */
  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.  
  47. #include <stdio.h>
  48. #include <signal.h>
  49. #include <ctype.h>
  50. #include <conio.h>
  51. #include <string.h>
  52.  
  53. #define WAZOO_SECTION
  54. #define MATRIX_SECTION
  55. #define isBITBRAIN 0x1b
  56.  
  57. #include "com.h"
  58. #include "xfer.h"
  59. #include "zmodem.h"
  60. #include "keybd.h"
  61. #include "sbuf.h"
  62. #include "sched.h"
  63. #include "externs.h"
  64. #include "prototyp.h"
  65.  
  66. static int Send_Hello_Packet (int);
  67. static int Recv_Hello_Packet (int);
  68.  
  69. /*--------------------------------------------------------------------------*/
  70. /* YOOHOO SENDER    (used when I am the CALLING system)                     */
  71. /*--------------------------------------------------------------------------*/
  72. int YooHoo_Sender (void)
  73. {
  74.    char *sptr;
  75.  
  76.    if (un_attended && fullscreen)
  77.       {
  78.       sb_move (filewin, 2, 2);
  79.       sb_puts (filewin, "YooHoo");
  80.       sb_show ();
  81.       }
  82.    else
  83.       {
  84.       set_xy ("YooHoo ");
  85.       }
  86.  
  87.    /*--------------------------------------------------------------------*/
  88.    /* Clean up any mess that may be around                               */
  89.    /*--------------------------------------------------------------------*/
  90.    CLEAR_OUTBOUND ();
  91.    CLEAR_INBOUND ();
  92.    XON_DISABLE ();
  93.  
  94.    if (!Send_Hello_Packet (1))
  95.       sptr = msgtxt[M_HE_HUNG_UP];
  96.  
  97.    else
  98.       {
  99.       if (TIMED_READ (60) == YOOHOO)            /* CML change 30 to 60 */
  100.          return Recv_Hello_Packet (1);
  101.  
  102.       status_line ("!No YOOHOO/2U2");
  103.       sptr = IDUNNO_msg;
  104.       }
  105.  
  106.    message (sptr);
  107.    return (0);
  108. }
  109.  
  110. /*--------------------------------------------------------------------------*/
  111. /* YOOHOO RECEIVER  (Used when I am the CALLED system)                      */
  112. /*--------------------------------------------------------------------------*/
  113.  
  114. int YooHoo_Receiver (void)
  115. {
  116.    int i;
  117.    int c;
  118.  
  119.    if (un_attended && fullscreen)
  120.       {
  121.       sb_move (filewin, 2, 2);
  122.       sb_puts (filewin, "YooHoo");
  123.       sb_show ();
  124.       }
  125.    else
  126.       set_xy ("YooHoo ");
  127.  
  128.    /*--------------------------------------------------------------------*/
  129.    /* Clean up any mess that may be around                               */
  130.    /*--------------------------------------------------------------------*/
  131.    CLEAR_OUTBOUND ();
  132.    CLEAR_INBOUND ();
  133.    XON_DISABLE ();
  134.  
  135.    if (!(i = Recv_Hello_Packet(0)))
  136.       return (0);
  137.  
  138.    for (i = 0; (CARRIER) && (i < 15); i++)            /* CML changed 10 to 15 */
  139.       {
  140.       if ((c = TIMED_READ (20)) == ENQ)            /* CML changed 10 to 20 */
  141.          return Send_Hello_Packet (0) ? 1 : (b_init (), 0);
  142.  
  143.       if (c > 0)
  144.          {
  145.          message (NULL);
  146.          printf ("[%x] ", c);
  147.  
  148.          /* Delay one second, then try again */
  149.          big_pause(1);
  150.  
  151.          CLEAR_INBOUND();
  152.          }
  153.  
  154.       SENDBYTE(YOOHOO);
  155.       }
  156.  
  157.    message (msgtxt[M_FUBAR_MSG]);
  158.    b_init ();
  159.    return (0);
  160.  
  161. }                                                /* YooHoo Receiver */
  162.  
  163. /*--------------------------------------------------------------------------*/
  164. /* SEND HELLO PACKET                                                        */
  165. /*--------------------------------------------------------------------------*/
  166. static int Send_Hello_Packet (Sender)
  167. int Sender;
  168. {
  169.    int i;
  170.    struct _Hello Hello;
  171.    byte *sptr;
  172.    long response_timer;
  173.    word crc;
  174.    word num_errs = 0;
  175.    word can_do_domain = 0;
  176.  
  177.    /*--------------------------------------------------------------------*/
  178.    /* Setup HELLO structure                                              */
  179.    /*--------------------------------------------------------------------*/
  180.    memset ((char *) &Hello, 0, sizeof (struct _Hello));
  181.  
  182.    Hello.signal = 'o';
  183.    Hello.hello_version = 1;
  184.  
  185.    Hello.product = isBITBRAIN;
  186.    Hello.product_maj = BINK_MAJVERSION;
  187.    Hello.product_min = BINK_MINVERSION;
  188.  
  189.    strncpy (Hello.sysop, sysop, 19);
  190.    Hello.sysop[19] = '\0';
  191.  
  192.    Hello.my_zone = alias[assumed].Zone;
  193.    if ((pvtnet >= 0) && (Sender) &&
  194.        ((called_addr.Zone == boss_addr.Zone) || (called_addr.Zone == 0) || (boss_addr.Zone == 0)) &&
  195.        (called_addr.Net == boss_addr.Net) && (called_addr.Node == boss_addr.Node) &&
  196.        ((called_addr.Domain == boss_addr.Domain) || (boss_addr.Domain == NULL) || (called_addr.Domain == NULL)))
  197.       {
  198.       Hello.my_net = boss_addr.Net;
  199.       Hello.my_node = boss_addr.Node;
  200.       Hello.my_point = alias[assumed].Node;
  201.       }
  202.    else
  203.       {
  204.       Hello.my_net = alias[assumed].Net;
  205.       Hello.my_node = alias[assumed].Node;
  206.       }
  207.  
  208.    Hello.capabilities = (no_zapzed) ? 0 : (ZED_ZAPPER | ZED_ZIPPER);
  209.    Hello.capabilities |= Y_DIETIFNA;
  210.  
  211.     if (lock_baud)                /* CML */
  212.         {
  213.         if ((actual_baud >= janus_baud) || janus_OK)
  214.             Hello.capabilities |= DOES_IANUS;
  215.         }
  216.     else if ((btypes[baud].rate_value >= janus_baud) || janus_OK)
  217.              Hello.capabilities |= DOES_IANUS;
  218.  
  219.  
  220.    can_do_domain = (my_addr.Domain != NULL) ? DO_DOMAIN : 0;
  221.    if (!Sender)
  222.       {
  223.       can_do_domain = remote_capabilities & can_do_domain;
  224.       if (remote_capabilities & Hello.capabilities & DOES_IANUS)
  225.          Hello.capabilities = DOES_IANUS;
  226.       else if (remote_capabilities & Hello.capabilities & ZED_ZAPPER)
  227.          Hello.capabilities = ZED_ZAPPER;
  228.       else if (remote_capabilities & Hello.capabilities & ZED_ZIPPER)
  229.          Hello.capabilities = ZED_ZIPPER;
  230.       else
  231.          Hello.capabilities = Y_DIETIFNA;
  232.       }
  233.  
  234.    strncpy (Hello.my_name, system_name, 58);
  235.    Hello.my_name[58] = '\0';
  236.    Hello.capabilities |= can_do_domain;
  237.    if (can_do_domain)
  238.       {
  239.       if (strlen (system_name) + strlen (alias[assumed].Domain) > 57)
  240.          Hello.my_name[57 - strlen (alias[assumed].Domain)] = '\0';
  241.       sptr = Hello.my_name + strlen (Hello.my_name) + 1;
  242.       strcpy (sptr, alias[assumed].Domain);
  243.       }
  244.  
  245.    if (n_getpassword (&remote_addr))
  246.       strncpy (Hello.my_password, remote_password, 8);
  247.  
  248.    if ((matrix_mask & TAKE_REQ) &&
  249.        ((!Sender) || (on_our_nickel)))
  250.       Hello.capabilities |= WZ_FREQ;
  251.  
  252.    /*--------------------------------------------------------------------*/
  253.    /* Disable handshaking and ^C/^K handling                             */
  254.    /*--------------------------------------------------------------------*/
  255.    XON_DISABLE ();
  256.  
  257.    /*--------------------------------------------------------------------*/
  258.    /* Send the packet.                                                   */
  259.    /* Load outbound buffer quickly, and get modem busy sending.          */
  260.    /*--------------------------------------------------------------------*/
  261.  
  262. xmit_packet:
  263.  
  264.    SENDBYTE (0x1f);
  265.  
  266.    sptr = (char *) (&Hello);
  267.    SENDCHARS (sptr, 128, 1);
  268.  
  269.    /*--------------------------------------------------------------------*/
  270.    /* Calculate CRC while modem is sending its buffer                    */
  271.    /*--------------------------------------------------------------------*/
  272.    for (crc = i = 0; i < 128; i++)
  273.       crc = xcrc (crc, (byte) sptr[i]);
  274.  
  275.    CLEAR_INBOUND ();
  276.  
  277.    SENDBYTE ((unsigned char) (crc >> 8));
  278.    SENDBYTE ((unsigned char) (crc & 0xff));
  279.  
  280. /****/
  281. //sptr = (char *) (&Hello);
  282. //printf("\nSent:");
  283. //for (i = 0; i < 128; i++)
  284. //    {
  285. //    if (!(i % 16))
  286. //        printf("\n");
  287. //    printf("%02x ",(unsigned char)sptr[i]);
  288. //    }
  289. //printf("CRC = %02x %02x\n\n",(unsigned char)(crc >> 8),(unsigned char)(crc & 0xff));
  290. //getch();
  291. /****/
  292.  
  293.    response_timer = timerset(4000);
  294.  
  295.     while (!timeup(response_timer) && CARRIER)
  296.         {
  297.         if (!CHAR_AVAIL ())
  298.             {
  299.             if (got_ESC ())
  300.                 {
  301.                 DTR_OFF ();
  302.                 sptr  = msgtxt[M_KBD_MSG];
  303.                 goto no_response;
  304.                 }
  305.             time_release ();
  306.             continue;
  307.             }     
  308.  
  309.         switch (i = TIMED_READ (0))
  310.             {
  311.             case ACK:
  312.                 return (1);
  313.  
  314.             case '?':
  315.                 message (msgtxt[M_DRATS]);
  316.  
  317.             case ENQ:
  318.                 if (++num_errs == 10)
  319.                     {
  320.                     sptr = msgtxt[M_FUBAR_MSG];
  321.                     goto no_response;
  322.                     }
  323.                 goto xmit_packet;
  324.  
  325.             default:
  326.                 if (i > 0)                   /* Could just be line noise */
  327.                     ;
  328.                 break;
  329.             }
  330.         time_release ();
  331.         }
  332.  
  333.     if (!CARRIER)
  334.         sptr = &(msgtxt[M_NO_CARRIER][1]);
  335.     else
  336.         sptr  = msgtxt[M_TIMEOUT];
  337.  
  338. no_response:
  339.  
  340.     message (sptr);
  341.     return (0);
  342.     }                                                /* Send Hello */
  343.  
  344.  
  345. /*--------------------------------------------------------------------------*/
  346. /* RECEIVE HELLO PACKET                                                     */
  347. /*--------------------------------------------------------------------------*/
  348. static int Recv_Hello_Packet (Sender)
  349. int Sender;
  350. {
  351.    int i;
  352.    int c;
  353.    int j;
  354.    struct _Hello Hello;
  355.    byte *sptr, *p;
  356.    byte num_errs = 0;
  357.    word crc;
  358.    word lsb;
  359.    word msb;
  360.    long master_timeout, hello_timeout;
  361.    char junkbuff[128];
  362.  
  363.    sptr = NULL;
  364.  
  365.    /*--------------------------------------------------------------------*/
  366.    /* Get the Hello structure                                            */
  367.    /*--------------------------------------------------------------------*/
  368.  
  369. /* big_pause (1);  */                           /* Wait for quiet. */
  370.    
  371.    if (un_attended && fullscreen)
  372.       {
  373.       sb_move (filewin, 2, 2);
  374.       sb_puts (filewin, "YooHoo/2U2");
  375.       sb_show ();
  376.       }
  377.    else
  378.       set_xy ("YooHoo/2U2 ");
  379.  
  380.    SENDBYTE (ENQ);                               /* Let the other system know
  381.                                                   * we heard YooHoo. */
  382.  
  383.    master_timeout = timerset (12000);        /* No more than 2 mins! */
  384.  
  385. watch_for_header:
  386.  
  387.    while (1)
  388.       {
  389.       if (sptr)
  390.          {
  391.          message (sptr);
  392.          sptr = NULL;
  393.          }
  394.  
  395.       if ((c = TIMED_READ (40)) == 0x1f)        /* CML changed 20 to 40 */
  396.          break;
  397.  
  398.       if (got_ESC ())
  399.          {
  400.          sptr = msgtxt[M_KBD_MSG];
  401.          goto receive_failed;
  402.          }
  403.  
  404.       if (!CARRIER)
  405.          {
  406.          sptr = &(msgtxt[M_NO_CARRIER][1]);
  407.          goto receive_failed;
  408.          }
  409.  
  410.       if (timeup(master_timeout))
  411.          goto timeout;
  412.  
  413.       if (c >= 0)                               /* noise? */
  414.          {
  415.          hello_timeout = timerset (1000);       /* Look for up to 10 secs  */
  416.          while (((c = PEEKBYTE ()) >= 0) && (c != 0x1f) && (CARRIER))
  417.             {
  418.             if (timeup(hello_timeout))
  419.                break;
  420.             MODEM_IN ();                        /* Eat non-YooHoo chars    */
  421.             }
  422.  
  423.          if (c != 0x1f)                         /* If we didn't get YooHoo */
  424.             {
  425.             CLEAR_INBOUND ();                   /* Throw out what we have  */
  426.             SENDBYTE (ENQ);                     /* Start over with ENQ     */
  427.             }
  428.          }
  429.       }                         /* while */
  430.  
  431.  
  432. /*receive_packet:*/
  433.  
  434.    sptr = (char *) (&Hello);
  435.  
  436.    hello_timeout = timerset (3000);
  437.  
  438.    for (i = 0, crc = 0; i < 128; i++)
  439.       {
  440.  
  441.       while (PEEKBYTE() < 0)
  442.          {
  443.          if (timeup (master_timeout) || timeup (hello_timeout))
  444.             goto timeout;
  445.         
  446.          if (got_ESC ())
  447.             {
  448.             sptr = msgtxt[M_KBD_MSG];
  449.             goto receive_failed;
  450.             }
  451.  
  452.          if (!CARRIER)
  453.             {
  454.             sptr = &(msgtxt[M_NO_CARRIER][1]);
  455.             goto receive_failed;
  456.             }
  457.  
  458. //         time_release ();
  459.      }
  460.  
  461.       c = TIMED_READ(0);
  462.  
  463.       sptr[i] = (unsigned char) c;
  464.       crc = xcrc (crc, (byte) c);
  465.       }
  466.  
  467.    if (!CARRIER)
  468.       {
  469.       sptr = &(msgtxt[M_NO_CARRIER][1]);
  470.       goto receive_failed;
  471.       }
  472.  
  473.    if ((msb = TIMED_READ(20)) < 0)        /* CML change 10 to 20 both cases */
  474.       {
  475.       sptr = msgtxt[M_SHRT_MSG];
  476.       goto hello_error;
  477.       }
  478.  
  479.    if ((lsb = TIMED_READ(20)) < 0)        /* CML change 10 to 20 both cases */
  480.       {
  481.       sptr = msgtxt[M_SHRT_MSG];
  482.       goto hello_error;
  483.       }
  484.  
  485. /****/
  486. //sptr = (char *) (&Hello);
  487. //printf("\nReceived:");
  488. //for (i = 0; i < 128; i++)
  489. //    {
  490. //    if (!(i % 16))
  491. //        printf("\n");
  492. //    printf("%02x ",(unsigned char)sptr[i]);
  493. //    }
  494. //printf("CRC = %02x %02x\n\n",(unsigned char)msb,(unsigned char)lsb);
  495. //printf("Calculated CRC = %02x %02x\n\n",(unsigned char)(crc >> 8),(unsigned char)(crc & 0xff));
  496. //getch();
  497. /****/
  498.  
  499.    if ((word)((msb << 8) | lsb) == crc)
  500.       goto process_hello;
  501.  
  502.    sptr = msgtxt[M_CRC_MSG];
  503.  
  504. hello_error:
  505.  
  506.    if (timeup(master_timeout))
  507.       goto timeout;
  508.  
  509.    if ((num_errs++) > 10)
  510.       {
  511.       sptr = msgtxt[M_FUBAR_MSG];
  512.       goto receive_failed;
  513.       }
  514.  
  515.    CLEAR_INBOUND ();
  516.    SENDBYTE ('?');
  517.    goto watch_for_header;
  518.  
  519. process_hello:
  520.  
  521.     /* The idea for removing junk characters came from Holger Schurig */
  522.     /* Get rid of junk characters */
  523.     for (p = Hello.my_name; *p != '\0'; p++)
  524.         if (*p < ' ')
  525.             *p = ' ';
  526.  
  527.     /* Get rid of junk characters */
  528.     for (p = Hello.sysop; *p != '\0'; p++)
  529.         if (*p < ' ')
  530.             *p = ' ';
  531.  
  532.    remote_addr.Zone = Hello.my_zone;
  533.    remote_addr.Net = Hello.my_net;
  534.    remote_addr.Node = Hello.my_node;
  535.    remote_addr.Point = Hello.my_point;
  536.    if ((Hello.capabilities & DO_DOMAIN) && (my_addr.Domain != NULL))
  537.       {
  538.       remote_addr.Domain = find_domain (&(Hello.my_name[strlen (Hello.my_name) + 1]));
  539.       }
  540.  
  541.    if (strlen (Hello.my_name) > 42)
  542.       Hello.my_name[42] = '\0';
  543.  
  544.    Hello.sysop[19] = '\0';
  545.  
  546.    remote_capabilities = (Hello.capabilities) | Y_DIETIFNA;
  547.  
  548.    if (nodefind (&remote_addr, 0) && !remote_addr.Zone)
  549.       remote_addr.Zone = found_zone;
  550.  
  551.    sprintf (junkbuff, "*%s (%s)",
  552.             Hello.my_name,
  553.             Full_Addr_Str (&remote_addr));
  554.    status_line (junkbuff);
  555.  
  556.    if ((pvtnet >= 0) &&
  557.        ((remote_addr.Zone == alias[assumed].Zone) || (remote_addr.Zone == 0)) &&
  558.        (remote_addr.Net == boss_addr.Net) && (remote_addr.Node == boss_addr.Node) &&
  559.        (remote_addr.Point > 0))
  560.       {
  561.       remote_addr.Net = pvtnet;
  562.       remote_addr.Node = Hello.my_point;
  563.       remote_addr.Point = 0;
  564.       }
  565.  
  566.    log_product (Hello.product, Hello.product_maj, Hello.product_min);
  567.  
  568.    if (Hello.sysop[0])
  569.       status_line (":Sysop: %s", Hello.sysop);
  570.  
  571.    if (remote_addr.Point > 0)
  572.       {
  573.       remote_addr.Point = 0;
  574.       remote_addr.Node = -1;
  575.       }
  576.  
  577.    if (n_getpassword (&remote_addr))
  578.       {
  579.       if (j = n_password (Hello.my_password, remote_password))
  580.          {
  581.          if ((j == 1) || ((j == 2) && (!Sender)))
  582.             {
  583.             DTR_OFF ();                            /* He'll never get it right */
  584.             timer (2);                             /* Wait two secs */
  585.             sptr = NULL;                           /* Already logged something */
  586.             goto receive_failed;
  587.             }
  588.          else
  589.             {
  590.             status_line (msgtxt[M_PASSWORD_OVERRIDE]);
  591.             }
  592.          }
  593.       }
  594.  
  595.    CLEAR_INBOUND ();
  596.  
  597.    SENDBYTE (ACK);
  598.    SENDBYTE (YOOHOO);
  599.  
  600.    return (1);
  601.  
  602. timeout:
  603.  
  604.    sptr = msgtxt[M_TIMEOUT];
  605.  
  606. receive_failed:
  607.  
  608.    message (sptr);
  609.    b_init ();
  610.    return (0);
  611. }                                               /* Recv Hello */
  612.  
  613. /* END OF FILE: yoohoo.c */
  614.