home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
BTMTSRC3.ZIP
/
YOOHOO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-10-17
|
19KB
|
614 lines
/*--------------------------------------------------------------------------*/
/* */
/* */
/* ------------ Bit-Bucket Software, Co. */
/* \ 10001101 / Writers and Distributors of */
/* \ 011110 / Freely Available<tm> Software. */
/* \ 1011 / */
/* ------ */
/* */
/* (C) Copyright 1987-90, Bit Bucket Software Co., a Delaware Corporation. */
/* */
/* */
/* This module was written by Vince Perriello */
/* */
/* */
/* BinkleyTerm "YooHoo" Processor */
/* */
/* */
/* For complete details of the licensing restrictions, please refer */
/* to the License agreement, which is published in its entirety in */
/* the MAKEFILE and BT.C, and also contained in the file LICENSE.240. */
/* */
/* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
/* BINKLEYTERM LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
/* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
/* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT BIT BUCKET */
/* SOFTWARE CO. AT ONE OF THE ADDRESSES LISTED BELOW. IN NO EVENT */
/* SHOULD YOU PROCEED TO USE THIS FILE WITHOUT HAVING ACCEPTED THE */
/* TERMS OF THE BINKLEYTERM LICENSING AGREEMENT, OR SUCH OTHER */
/* AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO. */
/* */
/* */
/* You can contact Bit Bucket Software Co. at any one of the following */
/* addresses: */
/* */
/* Bit Bucket Software Co. FidoNet 1:104/501, 1:132/491, 1:141/491 */
/* P.O. Box 460398 AlterNet 7:491/0 */
/* Aurora, CO 80046 BBS-Net 86:2030/1 */
/* Internet f491.n132.z1.fidonet.org */
/* */
/* Please feel free to contact us at any time to share your comments about */
/* our software and/or licensing policies. */
/* */
/* */
/*--------------------------------------------------------------------------*/
#include <stdio.h>
#include <signal.h>
#include <ctype.h>
#include <conio.h>
#include <string.h>
#define WAZOO_SECTION
#define MATRIX_SECTION
#define isBITBRAIN 0x1b
#include "com.h"
#include "xfer.h"
#include "zmodem.h"
#include "keybd.h"
#include "sbuf.h"
#include "sched.h"
#include "externs.h"
#include "prototyp.h"
static int Send_Hello_Packet (int);
static int Recv_Hello_Packet (int);
/*--------------------------------------------------------------------------*/
/* YOOHOO SENDER (used when I am the CALLING system) */
/*--------------------------------------------------------------------------*/
int YooHoo_Sender (void)
{
char *sptr;
if (un_attended && fullscreen)
{
sb_move (filewin, 2, 2);
sb_puts (filewin, "YooHoo");
sb_show ();
}
else
{
set_xy ("YooHoo ");
}
/*--------------------------------------------------------------------*/
/* Clean up any mess that may be around */
/*--------------------------------------------------------------------*/
CLEAR_OUTBOUND ();
CLEAR_INBOUND ();
XON_DISABLE ();
if (!Send_Hello_Packet (1))
sptr = msgtxt[M_HE_HUNG_UP];
else
{
if (TIMED_READ (60) == YOOHOO) /* CML change 30 to 60 */
return Recv_Hello_Packet (1);
status_line ("!No YOOHOO/2U2");
sptr = IDUNNO_msg;
}
message (sptr);
return (0);
}
/*--------------------------------------------------------------------------*/
/* YOOHOO RECEIVER (Used when I am the CALLED system) */
/*--------------------------------------------------------------------------*/
int YooHoo_Receiver (void)
{
int i;
int c;
if (un_attended && fullscreen)
{
sb_move (filewin, 2, 2);
sb_puts (filewin, "YooHoo");
sb_show ();
}
else
set_xy ("YooHoo ");
/*--------------------------------------------------------------------*/
/* Clean up any mess that may be around */
/*--------------------------------------------------------------------*/
CLEAR_OUTBOUND ();
CLEAR_INBOUND ();
XON_DISABLE ();
if (!(i = Recv_Hello_Packet(0)))
return (0);
for (i = 0; (CARRIER) && (i < 15); i++) /* CML changed 10 to 15 */
{
if ((c = TIMED_READ (20)) == ENQ) /* CML changed 10 to 20 */
return Send_Hello_Packet (0) ? 1 : (b_init (), 0);
if (c > 0)
{
message (NULL);
printf ("[%x] ", c);
/* Delay one second, then try again */
big_pause(1);
CLEAR_INBOUND();
}
SENDBYTE(YOOHOO);
}
message (msgtxt[M_FUBAR_MSG]);
b_init ();
return (0);
} /* YooHoo Receiver */
/*--------------------------------------------------------------------------*/
/* SEND HELLO PACKET */
/*--------------------------------------------------------------------------*/
static int Send_Hello_Packet (Sender)
int Sender;
{
int i;
struct _Hello Hello;
byte *sptr;
long response_timer;
word crc;
word num_errs = 0;
word can_do_domain = 0;
/*--------------------------------------------------------------------*/
/* Setup HELLO structure */
/*--------------------------------------------------------------------*/
memset ((char *) &Hello, 0, sizeof (struct _Hello));
Hello.signal = 'o';
Hello.hello_version = 1;
Hello.product = isBITBRAIN;
Hello.product_maj = BINK_MAJVERSION;
Hello.product_min = BINK_MINVERSION;
strncpy (Hello.sysop, sysop, 19);
Hello.sysop[19] = '\0';
Hello.my_zone = alias[assumed].Zone;
if ((pvtnet >= 0) && (Sender) &&
((called_addr.Zone == boss_addr.Zone) || (called_addr.Zone == 0) || (boss_addr.Zone == 0)) &&
(called_addr.Net == boss_addr.Net) && (called_addr.Node == boss_addr.Node) &&
((called_addr.Domain == boss_addr.Domain) || (boss_addr.Domain == NULL) || (called_addr.Domain == NULL)))
{
Hello.my_net = boss_addr.Net;
Hello.my_node = boss_addr.Node;
Hello.my_point = alias[assumed].Node;
}
else
{
Hello.my_net = alias[assumed].Net;
Hello.my_node = alias[assumed].Node;
}
Hello.capabilities = (no_zapzed) ? 0 : (ZED_ZAPPER | ZED_ZIPPER);
Hello.capabilities |= Y_DIETIFNA;
if (lock_baud) /* CML */
{
if ((actual_baud >= janus_baud) || janus_OK)
Hello.capabilities |= DOES_IANUS;
}
else if ((btypes[baud].rate_value >= janus_baud) || janus_OK)
Hello.capabilities |= DOES_IANUS;
can_do_domain = (my_addr.Domain != NULL) ? DO_DOMAIN : 0;
if (!Sender)
{
can_do_domain = remote_capabilities & can_do_domain;
if (remote_capabilities & Hello.capabilities & DOES_IANUS)
Hello.capabilities = DOES_IANUS;
else if (remote_capabilities & Hello.capabilities & ZED_ZAPPER)
Hello.capabilities = ZED_ZAPPER;
else if (remote_capabilities & Hello.capabilities & ZED_ZIPPER)
Hello.capabilities = ZED_ZIPPER;
else
Hello.capabilities = Y_DIETIFNA;
}
strncpy (Hello.my_name, system_name, 58);
Hello.my_name[58] = '\0';
Hello.capabilities |= can_do_domain;
if (can_do_domain)
{
if (strlen (system_name) + strlen (alias[assumed].Domain) > 57)
Hello.my_name[57 - strlen (alias[assumed].Domain)] = '\0';
sptr = Hello.my_name + strlen (Hello.my_name) + 1;
strcpy (sptr, alias[assumed].Domain);
}
if (n_getpassword (&remote_addr))
strncpy (Hello.my_password, remote_password, 8);
if ((matrix_mask & TAKE_REQ) &&
((!Sender) || (on_our_nickel)))
Hello.capabilities |= WZ_FREQ;
/*--------------------------------------------------------------------*/
/* Disable handshaking and ^C/^K handling */
/*--------------------------------------------------------------------*/
XON_DISABLE ();
/*--------------------------------------------------------------------*/
/* Send the packet. */
/* Load outbound buffer quickly, and get modem busy sending. */
/*--------------------------------------------------------------------*/
xmit_packet:
SENDBYTE (0x1f);
sptr = (char *) (&Hello);
SENDCHARS (sptr, 128, 1);
/*--------------------------------------------------------------------*/
/* Calculate CRC while modem is sending its buffer */
/*--------------------------------------------------------------------*/
for (crc = i = 0; i < 128; i++)
crc = xcrc (crc, (byte) sptr[i]);
CLEAR_INBOUND ();
SENDBYTE ((unsigned char) (crc >> 8));
SENDBYTE ((unsigned char) (crc & 0xff));
/****/
//sptr = (char *) (&Hello);
//printf("\nSent:");
//for (i = 0; i < 128; i++)
// {
// if (!(i % 16))
// printf("\n");
// printf("%02x ",(unsigned char)sptr[i]);
// }
//printf("CRC = %02x %02x\n\n",(unsigned char)(crc >> 8),(unsigned char)(crc & 0xff));
//getch();
/****/
response_timer = timerset(4000);
while (!timeup(response_timer) && CARRIER)
{
if (!CHAR_AVAIL ())
{
if (got_ESC ())
{
DTR_OFF ();
sptr = msgtxt[M_KBD_MSG];
goto no_response;
}
time_release ();
continue;
}
switch (i = TIMED_READ (0))
{
case ACK:
return (1);
case '?':
message (msgtxt[M_DRATS]);
case ENQ:
if (++num_errs == 10)
{
sptr = msgtxt[M_FUBAR_MSG];
goto no_response;
}
goto xmit_packet;
default:
if (i > 0) /* Could just be line noise */
;
break;
}
time_release ();
}
if (!CARRIER)
sptr = &(msgtxt[M_NO_CARRIER][1]);
else
sptr = msgtxt[M_TIMEOUT];
no_response:
message (sptr);
return (0);
} /* Send Hello */
/*--------------------------------------------------------------------------*/
/* RECEIVE HELLO PACKET */
/*--------------------------------------------------------------------------*/
static int Recv_Hello_Packet (Sender)
int Sender;
{
int i;
int c;
int j;
struct _Hello Hello;
byte *sptr, *p;
byte num_errs = 0;
word crc;
word lsb;
word msb;
long master_timeout, hello_timeout;
char junkbuff[128];
sptr = NULL;
/*--------------------------------------------------------------------*/
/* Get the Hello structure */
/*--------------------------------------------------------------------*/
/* big_pause (1); */ /* Wait for quiet. */
if (un_attended && fullscreen)
{
sb_move (filewin, 2, 2);
sb_puts (filewin, "YooHoo/2U2");
sb_show ();
}
else
set_xy ("YooHoo/2U2 ");
SENDBYTE (ENQ); /* Let the other system know
* we heard YooHoo. */
master_timeout = timerset (12000); /* No more than 2 mins! */
watch_for_header:
while (1)
{
if (sptr)
{
message (sptr);
sptr = NULL;
}
if ((c = TIMED_READ (40)) == 0x1f) /* CML changed 20 to 40 */
break;
if (got_ESC ())
{
sptr = msgtxt[M_KBD_MSG];
goto receive_failed;
}
if (!CARRIER)
{
sptr = &(msgtxt[M_NO_CARRIER][1]);
goto receive_failed;
}
if (timeup(master_timeout))
goto timeout;
if (c >= 0) /* noise? */
{
hello_timeout = timerset (1000); /* Look for up to 10 secs */
while (((c = PEEKBYTE ()) >= 0) && (c != 0x1f) && (CARRIER))
{
if (timeup(hello_timeout))
break;
MODEM_IN (); /* Eat non-YooHoo chars */
}
if (c != 0x1f) /* If we didn't get YooHoo */
{
CLEAR_INBOUND (); /* Throw out what we have */
SENDBYTE (ENQ); /* Start over with ENQ */
}
}
} /* while */
/*receive_packet:*/
sptr = (char *) (&Hello);
hello_timeout = timerset (3000);
for (i = 0, crc = 0; i < 128; i++)
{
while (PEEKBYTE() < 0)
{
if (timeup (master_timeout) || timeup (hello_timeout))
goto timeout;
if (got_ESC ())
{
sptr = msgtxt[M_KBD_MSG];
goto receive_failed;
}
if (!CARRIER)
{
sptr = &(msgtxt[M_NO_CARRIER][1]);
goto receive_failed;
}
// time_release ();
}
c = TIMED_READ(0);
sptr[i] = (unsigned char) c;
crc = xcrc (crc, (byte) c);
}
if (!CARRIER)
{
sptr = &(msgtxt[M_NO_CARRIER][1]);
goto receive_failed;
}
if ((msb = TIMED_READ(20)) < 0) /* CML change 10 to 20 both cases */
{
sptr = msgtxt[M_SHRT_MSG];
goto hello_error;
}
if ((lsb = TIMED_READ(20)) < 0) /* CML change 10 to 20 both cases */
{
sptr = msgtxt[M_SHRT_MSG];
goto hello_error;
}
/****/
//sptr = (char *) (&Hello);
//printf("\nReceived:");
//for (i = 0; i < 128; i++)
// {
// if (!(i % 16))
// printf("\n");
// printf("%02x ",(unsigned char)sptr[i]);
// }
//printf("CRC = %02x %02x\n\n",(unsigned char)msb,(unsigned char)lsb);
//printf("Calculated CRC = %02x %02x\n\n",(unsigned char)(crc >> 8),(unsigned char)(crc & 0xff));
//getch();
/****/
if ((word)((msb << 8) | lsb) == crc)
goto process_hello;
sptr = msgtxt[M_CRC_MSG];
hello_error:
if (timeup(master_timeout))
goto timeout;
if ((num_errs++) > 10)
{
sptr = msgtxt[M_FUBAR_MSG];
goto receive_failed;
}
CLEAR_INBOUND ();
SENDBYTE ('?');
goto watch_for_header;
process_hello:
/* The idea for removing junk characters came from Holger Schurig */
/* Get rid of junk characters */
for (p = Hello.my_name; *p != '\0'; p++)
if (*p < ' ')
*p = ' ';
/* Get rid of junk characters */
for (p = Hello.sysop; *p != '\0'; p++)
if (*p < ' ')
*p = ' ';
remote_addr.Zone = Hello.my_zone;
remote_addr.Net = Hello.my_net;
remote_addr.Node = Hello.my_node;
remote_addr.Point = Hello.my_point;
if ((Hello.capabilities & DO_DOMAIN) && (my_addr.Domain != NULL))
{
remote_addr.Domain = find_domain (&(Hello.my_name[strlen (Hello.my_name) + 1]));
}
if (strlen (Hello.my_name) > 42)
Hello.my_name[42] = '\0';
Hello.sysop[19] = '\0';
remote_capabilities = (Hello.capabilities) | Y_DIETIFNA;
if (nodefind (&remote_addr, 0) && !remote_addr.Zone)
remote_addr.Zone = found_zone;
sprintf (junkbuff, "*%s (%s)",
Hello.my_name,
Full_Addr_Str (&remote_addr));
status_line (junkbuff);
if ((pvtnet >= 0) &&
((remote_addr.Zone == alias[assumed].Zone) || (remote_addr.Zone == 0)) &&
(remote_addr.Net == boss_addr.Net) && (remote_addr.Node == boss_addr.Node) &&
(remote_addr.Point > 0))
{
remote_addr.Net = pvtnet;
remote_addr.Node = Hello.my_point;
remote_addr.Point = 0;
}
log_product (Hello.product, Hello.product_maj, Hello.product_min);
if (Hello.sysop[0])
status_line (":Sysop: %s", Hello.sysop);
if (remote_addr.Point > 0)
{
remote_addr.Point = 0;
remote_addr.Node = -1;
}
if (n_getpassword (&remote_addr))
{
if (j = n_password (Hello.my_password, remote_password))
{
if ((j == 1) || ((j == 2) && (!Sender)))
{
DTR_OFF (); /* He'll never get it right */
timer (2); /* Wait two secs */
sptr = NULL; /* Already logged something */
goto receive_failed;
}
else
{
status_line (msgtxt[M_PASSWORD_OVERRIDE]);
}
}
}
CLEAR_INBOUND ();
SENDBYTE (ACK);
SENDBYTE (YOOHOO);
return (1);
timeout:
sptr = msgtxt[M_TIMEOUT];
receive_failed:
message (sptr);
b_init ();
return (0);
} /* Recv Hello */
/* END OF FILE: yoohoo.c */