/*======================================================================* * * * NETCALL - Program to process ExpressNET! Calls * * * *======================================================================*/ #version $50 #reserve 6 #copyright "Netcall.cmd Copyright 1995 K-Products" #address $7000 #include runtime.h #include bbs_pro.h #define MAXBUFF 3510 #define DISK2 2 #define C_MODEM 5 #define _ACK_ 6 #define _NAK_ 24 #define _EOT_ 4 byte consol = 53279; int file_modified; char callfn [40]; char buffer [MAXBUFF]; /* 26 Entries, each entry is 135 bytes long ---------------------------------------- */ char p_bbs_name [16]; /* name of this BBS */ char p_number [44]; /* number of the BBS */ byte p_baud; /* baud rate */ byte p_secs_to_wait; /* seconds to wait */ card p_usernumber; /* user # on this BBS */ char p_password [16]; /* password */ byte p_lt_date [3]; /* last tried date */ byte p_lc_date [3]; /* last connected date */ byte p_lx_date [3]; /* last transfer date */ byte p_days_to_call [7]; /* 0=sunday (0=no,1=yes)*/ byte p_begin_time; /* low time we can call */ byte p_end_time; /* end time we can call */ byte p_max_retries; /* max calls to make */ byte p_num_retries; /* number times called */ char p_inbases[32]; /* base redirection */ char p_dial_mode; /* 0=tone, 1=pulse */ char p_type; /* 253= Standard, 252 hi speed*/ char p_filler; /* fill out to 135 */ main() { byte idx, boards_left; byte rc; strcpy (callfn, "Dx:>PRO>NETWORK>CALLOUT.DAT"); callfn [2] = s_netdr; if (load_call_dataset() == 0) return; printf ("%c%e%e%e%e%e%e%e __ExpressNET! Dialer Activated__%e%e", 125); idx = 0; file_modified = 0; while (consol != 6) { /* START key breaks out */ #asm { lda #0 ;turn off attract mode sta 77 } boards_left = 0; for (idx = 0; idx < 26; ++idx) { if (consol == 6) break; get_board (idx); if (length (p_number) == 0) /* ignore null entries */ continue; datestamp(); printf("%eEntry : %s%e", p_bbs_name); printf("Status : "); if (cur_month == p_lc_date[0] && cur_day == p_lc_date[1] && cur_year == p_lc_date[2]) { printf("already connected today.%e"); continue; } if (p_days_to_call [cur_weekday] == 0) { printf("not scheduled for today.%e"); continue; } if (cur_hour < p_begin_time || cur_hour >= p_end_time) { printf("not time to call yet.%e"); continue; } if (cur_month != p_lt_date[0] || cur_day != p_lt_date[1] || cur_year != p_lt_date[2]) { p_num_retries = 0; /* reset try counter */ if (p_type == 0) p_type = 253; p_lt_date[0] = cur_month; p_lt_date[1] = cur_day; p_lt_date[2] = cur_year; put_board (idx); /* save data */ file_modified = 1; } if (p_num_retries >= p_max_retries) { printf("exhausted maximum retries.%e"); continue; } printf ("placing ExpressNET! call.%e"); ++boards_left; /* we've got one to */ ++p_num_retries; /* process... */ put_board (idx); file_modified = 1; if (connect_to_board()) { /* dial this number */ resume(); p_lc_date[0] = cur_month; /* mark last connect */ p_lc_date[1] = cur_day; p_lc_date[2] = cur_year; put_board (idx); file_modified = 1; rc = handshake(); /* attempt handshaking */ if (rc > 0) { if (rc == 2) printf("%eNo file waiting for your node..%e"); else { p_lx_date[0] = cur_month; /* mark last xfer */ p_lx_date[1] = cur_day; p_lx_date[2] = cur_year; put_board (idx); file_modified = 1; spawn_xmodem(); /* blow out to xmodem */ return; /* should never return */ } } } } if (boards_left == 0) /* we've done 'em all */ break; } printf("%eNetCALL: processing finished.%e"); if (file_modified) save_call_dataset(); else wait (2); exit_netcall(); /* to shell, rewrite SYSDATA */ } connect_to_board() { byte mstat = 747; int x, y; printf("%e%eConfig : "); close (C_MODEM); dtroff(); wait (2); baud = p_baud; config(); open_mdm(); putd (C_MODEM, 13); wait (1); putd (C_MODEM, 'A'); putd (C_MODEM, 'T'); putd (C_MODEM, 'M'); putd (C_MODEM, '0'); putd (C_MODEM, 13); wait (2); printf("done%e"); printf("Dialing: "); putd (C_MODEM, 'A'); putd (C_MODEM, 'T'); putd (C_MODEM, 'D'); if (p_dial_mode == 0) putd (C_MODEM, 'T'); else putd (C_MODEM, 'P'); for (y=1; y <= length(p_number); ++y) { putd (C_MODEM, p_number [y]); put (p_number [y]); } printf (" (#%d)%e", p_num_retries); putd (C_MODEM, 13); wait (2); close (C_MODEM); printf ("Waiting: 1"); seconds = 1; x = 99; do { if (consol == 6) seconds = p_secs_to_wait; if (x != seconds) { x = seconds; put (30); put (30); if (x < 10) put (' '); printf ("%d", x); mdmstat(); } } while (mstat & 8 == 0 && seconds < p_secs_to_wait); cr_lf(); if (seconds < p_secs_to_wait) return(1); /* connected!! */ dtroff(); wait (2); return(0); } /*==================================================================* * handshake - Attempt to handshake with the host system. * * * * Returns: 0 - unable to establish connection. * * 1 - connected, file coming. * * 2 - connected, no file available. * *==================================================================*/ handshake() { int x, y; char ch; printf ("%eHandshaking with remote system..."); seconds = 0; ch = 0; do { /* output $FD's until */ if (bytes_in()) ch = getd (C_MODEM); else { putd (C_MODEM, p_type); /*was $fd we get a NAK.. */ wait (3); } } while (ch != _NAK_ && seconds < 40); /* try 40 seconds */ if (ch != _NAK_) return (0); seconds = 0; do { if (bytes_in()) { ch = getd (C_MODEM); case (ch) { _ACK_ : return(1); /* we're on!! */ _NAK_ : send_node_info(); /* try again */ _EOT_ : return(2); /* no file for us! */ else : purge_modem(); /* got some junk */ } } } while (seconds < 45); return (0); } send_node_info() { char hs_buff [25]; /* only 20 bytes are used */ byte cksum, x; strcpy (hs_buff, p_password); /* bytes 0-15 = pword */ hs_buff [16] = s_node & $ff; hs_buff [17] = s_node >> 8; hs_buff [18] = p_usernumber & $ff; hs_buff [19] = p_usernumber >> 8; cksum = 0; for (x=0; x < 20; ++x) { putd (C_MODEM, hs_buff [x]); cksum = cksum + hs_buff [x]; } putd (C_MODEM, cksum); } purge_modem() { char ch; while (bytes_in()) ch = getd (C_MODEM); } wait (byte secs) { byte hold; hold = seconds; /* save current second counter */ seconds = 0; do { } while (seconds < secs); seconds = hold + secs; } spawn_xmodem() { byte x; save_call_dataset(); /* save callout file */ invoker = $C1; /* set invoker to RECEIVE */ for (x=0; x < 32; ++x) /* pass along the message */ parm1 [x+1] = p_inbases [x]; /* redirection flags */ parm1 [0] = 32; if (p_type == 252) chain ("NSRXFER"); if (p_type == 251) chain ("NCRXFER"); else chain ("NETMODEM"); /* and do the transfer */ } get_board (byte bn) { char *cp; int ofst; ofst = bn * 135; cp = buffer + ofst; moveblock (&p_bbs_name, cp, 135); /* each entry is 135 bytes */ } put_board (byte bn) { char *cp; int ofst; ofst = bn * 135; cp = buffer + ofst; moveblock (cp, &p_bbs_name, 135); /* each entry is 135 bytes */ } load_call_dataset() { int tbytes; byte x; MIOsuspend(); if (open (DISK2, callfn, 4, 0) != OK) { /* open input file? */ MIOresume(); printf ("Unable to open CALLOUT.DAT file!"); return (0); } tbytes = blockread (DISK2, buffer, sizeof(buffer)); if (tbytes != sizeof(buffer)) { MIOresume(); printf("Invalid CALLOUT.DAT file!"); return (0); } close (DISK2); MIOresume(); return (1); } save_call_dataset() { int tbytes; MIOsuspend(); if (open (DISK2, callfn, 12, 0) != OK) { /* open input file? */ MIOresume(); printf ("Unable to open CALLOUT.DAT file!"); return (0); } if (blockwrite (DISK2, buffer, sizeof(buffer)) != sizeof(buffer)) { MIOresume(); printf("Error writing CALLOUT.DAT file!"); return (0); } close (DISK2); MIOresume(); return (1); }