home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC / SRC15B67.ZIP / NETWORK.CPP < prev    next >
C/C++ Source or Header  |  1997-11-17  |  47KB  |  1,894 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdarg.h>
  5. #include <dos.h>
  6. #include <fcntl.h>
  7. #include <sys/stat.h>
  8. #include <ctype.h>
  9. #include <mem.h>
  10. #include <conio.h>
  11. #include <io.h>
  12. #include <share.h>
  13. #include <errno.h>
  14. #include <malloc.h>
  15. #include <alloc.h>
  16. #include <dir.h>
  17. #include <time.h>
  18. #include <process.h>
  19. #include <direct.h>
  20. #include "vardec.h"
  21. #include "net.h"
  22. #include "version.h"
  23. #include "retcode.h"
  24.  
  25. #define SIZE_OF_EMULATOR 415
  26. #define FILL_CHAR 0xFF
  27.  
  28. #define NUL '\0'
  29. #define LAST(s) s[strlen(s)-1]
  30.  
  31. #define SHARE_LEVEL 10
  32. #define WAIT_TIME 10
  33. #define TRIES 100
  34.  
  35. #define MT_DESQVIEW 0x01
  36. #define MT_WINDOWS  0x02
  37. #define MT_OS2      0x04
  38. #define MT_NB       0x40
  39.  
  40. #define VIDEO 0x10
  41.  
  42. #define INI_NETWORK   0x01
  43. #define INI_GENERAL   0x02
  44. #define INI_NEWS      0x04
  45.  
  46. char *version = "Freeware PPP Project Net Packet Engine " VERSION " (" __DATE__ ")";
  47. char *author = "Contact Frank Reid at edare@ix.netcom.com or 1@8213.WWIVnet for support";
  48.  
  49. char *strings[] = {
  50.     "Unable to create",
  51.     "Unable to read",
  52.     "Unknown error",
  53.     "Unable to write CONTACT.NET!",
  54.     "Unable to write NET.LOG!",
  55.     0L,
  56. };
  57.  
  58. typedef struct {
  59.   unsigned short sysnum;
  60.   char address[60];
  61. } net_address_rec;
  62.  
  63. configrec syscfg;
  64. configoverrec syscfgovr;
  65. net_networks_rec netcfg;
  66. net_system_list_rec *netsys;
  67.  
  68. int multitasker = 0, ini_section = 0, num_addr;
  69. char wwiv_net_no[20], maindir[MAXPATH];
  70. char net_name[16], net_data[MAXPATH];
  71. unsigned short net_sysnum;
  72. int num_sys_list, net_num, net_num_max, netnum;
  73. int lsl_loaded;
  74.  
  75. char SMTPHOST[40], POPHOST[40], NEWSHOST[40], POPNAME[20], POPPASS[20];
  76. char IPADDR[18], NETMASK[18], FWDNAME[20], FWDDOM[40], TIMEHOST[40];
  77. char DNS[16], SDNS[16], DOMAIN[40], GATEWAY[16], temp_dir[MAXPATH];
  78. unsigned int KEEPSENT = 0, ALLMAIL = 1, CLEANUP = 0, MOREINFO = 0;
  79. unsigned int TIMEOUT = 60, SOCK_DELAY = 30, INACTIVE = 60;
  80. unsigned int ONECALL = 0, PURGE = 1;
  81. int instance;
  82.  
  83. char *xenviron[20];
  84.  
  85. void init_stack_count(void)
  86. {
  87.   char far *sp;
  88.   extern  unsigned __brklvl;
  89.     
  90.   sp = (char *)MK_FP(_SS, _SP - 1 );
  91.   while( sp > (char far *) SIZE_OF_EMULATOR )  {
  92.      *sp = FILL_CHAR;
  93.      sp--;
  94.   }
  95.   return;
  96. }
  97.  
  98. void stack_count( void )
  99. {
  100.   unsigned count= 0;
  101.   char far *sp;
  102.   
  103.   sp = (char *)MK_FP( _SS, SIZE_OF_EMULATOR+1);
  104.   if (_SP >  SIZE_OF_EMULATOR) {
  105.     while (sp < MK_FP(_SS,_SP)) {
  106.       if (*sp != (char) FILL_CHAR)
  107.         break;
  108.       count++;
  109.       sp++;
  110.     }
  111.   }
  112.   if (MOREINFO)
  113.     fprintf(stderr, "\n ! Stack not used = %u bytes\n" , count);
  114.   return;
  115. }
  116.  
  117. void dv_pause(void)
  118. {
  119.   __emit__(0xb8, 0x1a, 0x10, 0xcd, 0x15);
  120.   __emit__(0xb8, 0x00, 0x10, 0xcd, 0x15);
  121.   __emit__(0xb8, 0x25, 0x10, 0xcd, 0x15);
  122. }
  123.  
  124. void win_pause(void)
  125. {
  126.   __emit__(0x55, 0xb8, 0x80, 0x16, 0xcd, 0x2f, 0x5d);
  127. }
  128.  
  129. int get_dos_version(void)
  130. {
  131.   _AX = 0x3000;
  132.   geninterrupt(0x21);
  133.   if (_AX % 256 >= 10) {
  134.     multitasker |= MT_OS2;
  135.   }
  136.   return (_AX);
  137. }
  138.  
  139. int get_dv_version(void)
  140. {
  141.   int v;
  142.  
  143.   if (multitasker & MT_OS2)
  144.     return 0;
  145.   _AX = 0x2b01;
  146.   _CX = 0x4445;
  147.   _DX = 0x5351;
  148.   geninterrupt(0x21);
  149.   if (_AL == 0xff) {
  150.     return 0;
  151.   } else {
  152.     v = _BX;
  153.     multitasker |= MT_DESQVIEW;
  154.     return v;
  155.   }
  156. }
  157.  
  158. int get_win_version(void)
  159. {
  160.   int v = 0;
  161.  
  162.   __emit__(0x55, 0x06, 0x53);
  163.   _AX = 0x352f;
  164.   geninterrupt(0x21);
  165.   _AX = _ES;
  166.   if (_AX | _BX) {
  167.     _AX = 0x1600;
  168.     geninterrupt(0x2f);
  169.     v = _AX;
  170.     if (v % 256 <= 1)
  171.       v = 0;
  172.   }
  173.   __emit__(0x5b, 0x07, 0x5d);
  174.   if (v != 0)
  175.     multitasker |= MT_WINDOWS;
  176.   return (v);
  177. }
  178.  
  179. int get_nb_version(void)
  180. {
  181.   _AX = 0;
  182.   geninterrupt(0x2A);
  183.   return (_AH);
  184. }
  185.  
  186. void detect_multitask(void)
  187. {
  188.   get_dos_version();
  189.   get_win_version();
  190.   get_dv_version();
  191.   if (multitasker < 2)
  192.     if (get_nb_version())
  193.       multitasker = MT_NB;
  194. }
  195.  
  196. void giveup_timeslice(void)
  197. {
  198.   if (multitasker) {
  199.     switch (multitasker) {
  200.  case 1:
  201.  case 3:
  202.         dv_pause();
  203.         break;
  204.       case 2:
  205.       case 4:
  206.       case 5:
  207.       case 6:
  208.       case 7:
  209.         win_pause();
  210.         break;
  211.       default:
  212.         break;
  213.     }
  214.   }
  215. }
  216.  
  217. char *stripspace(char *str)
  218. {
  219.   char *obuf, *nbuf;
  220.  
  221.   if (str) {
  222.     for (obuf = str, nbuf = str; *obuf; ++obuf) {
  223.       if (!isspace(*obuf))
  224.         *nbuf++ = *obuf;
  225.     }
  226.     *nbuf = NULL;
  227.   }
  228.   return (str);
  229. }
  230.  
  231. int sh_write(int handle, void *buffer, unsigned long len)
  232. {
  233.   if (handle == -1) {
  234.     return (-1);
  235.   }
  236.   return (write(handle, buffer, (unsigned) len));
  237. }
  238.  
  239. int sh_open(char *path, int file_access, unsigned fmode)
  240. {
  241.   int handle, count, share;
  242.   char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
  243.  
  244.   if ((file_access & O_RDWR) || (file_access & O_WRONLY) || (fmode & S_IWRITE)) {
  245.     share = SH_DENYRW;
  246.   } else {
  247.     share = SH_DENYWR;
  248.   }
  249.   handle = open(path, file_access | share, fmode);
  250.   if (handle < 0) {
  251.     count = 1;
  252.     fnsplit(path, drive, dir, file, ext);
  253.     if (access(path, 0) != -1) {
  254.       delay(WAIT_TIME);
  255.       handle = open(path, file_access | share, fmode);
  256.       while (((handle < 0) && (errno == EACCES)) && (count < TRIES)) {
  257.         if (count % 2)
  258.           delay(WAIT_TIME);
  259.         else
  260.           giveup_timeslice();
  261.         count++;
  262.         handle = open(path, file_access | share, fmode);
  263.       }
  264.     }
  265.   }
  266.   return (handle);
  267. }
  268.  
  269. int sh_open1(char *path, int access)
  270. {
  271.   unsigned fmode;
  272.  
  273.   fmode = 0;
  274.   if ((access & O_RDWR) || (access & O_WRONLY))
  275.     fmode |= S_IWRITE;
  276.   if ((access & O_RDWR) || (access & O_RDONLY))
  277.     fmode |= S_IREAD;
  278.   return (sh_open(path, access, fmode));
  279. }
  280.  
  281. int sh_close(int f)
  282. {
  283.   if (f != -1)
  284.     close(f);
  285.   return (-1);
  286. }
  287.  
  288. int sh_read(int handle, void *buf, unsigned len)
  289. {
  290.   if (handle == -1) {
  291.     return (-1);
  292.   }
  293.   return (read(handle, buf, len));
  294. }
  295.  
  296. long sh_lseek(int handle, long offset, int fromwhere)
  297. {
  298.   if (handle == -1) {
  299.     return (-1L);
  300.   }
  301.   return (lseek(handle, offset, fromwhere));
  302. }
  303.  
  304. FILE *fsh_open(char *path, char *fmode)
  305. {
  306.   FILE *f;
  307.   int count, share, md, fd;
  308.   char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
  309.  
  310.   share = SH_DENYWR;
  311.   md = 0;
  312.   if (((char *) _fstrchr(fmode, 'w')) != NULL) {
  313.     share = SH_DENYRD;
  314.     md = O_RDWR | O_CREAT | O_TRUNC;
  315.   } else
  316.     if (((char *) _fstrchr(fmode, 'a')) != NULL) {
  317.     share = SH_DENYRD;
  318.     md = O_RDWR | O_CREAT;
  319.   } else {
  320.     md = O_RDONLY;
  321.   }
  322.   if (((char *) _fstrchr(fmode, 'b')) != NULL) {
  323.     md |= O_BINARY;
  324.   }
  325.   if (((char *) _fstrchr(fmode, '+')) != NULL) {
  326.     md &= ~O_RDONLY;
  327.     md |= O_RDWR;
  328.     share = SH_DENYRD;
  329.   }
  330.   fd = open(path, md | share, S_IREAD | S_IWRITE);
  331.   if (fd < 0) {
  332.     count = 1;
  333.     fnsplit(path, drive, dir, file, ext);
  334.     if ((access(path, 0)) != -1) {
  335.       delay(WAIT_TIME);
  336.       fd = open(path, md | share, S_IREAD | S_IWRITE);
  337.       while (((fd < 0) && (errno == EACCES)) && (count < TRIES)) {
  338.         delay(WAIT_TIME);
  339.         count++;
  340.         fd = open(path, md | share, S_IREAD | S_IWRITE);
  341.       }
  342.     }
  343.   }
  344.   if (fd > 0) {
  345.     if (((char *) _fstrchr(fmode, 'a')) != NULL)
  346.       sh_lseek(fd, 0L, SEEK_END);
  347.     f = fdopen(fd, fmode);
  348.     if (!f) {
  349.       close(fd);
  350.     }
  351.   } else
  352.     f = NULL;
  353.   return (f);
  354. }
  355.  
  356. void output(char *fmt, ...)
  357. {
  358.   va_list v;
  359.   char s[255];
  360.  
  361.   va_start(v, fmt);
  362.   vsprintf(s, fmt, v);
  363.   va_end(v);
  364.   fputs(s, stderr);
  365. }
  366.  
  367.  
  368. void backline(void)
  369. {
  370.   int i;
  371.  
  372.   output(" ");
  373.   for (i = wherex(); i > 0; i--)
  374.     output("\b \b");
  375. }
  376.  
  377.  
  378. int do_spawn(char *cl)
  379. {
  380.   int i, i1, l;
  381.   char *ss1, *ss[10];
  382.  
  383.   ss1 = _fstrdup(cl);
  384.   ss[0] = ss1;
  385.   i = 1;
  386.   l = strlen(ss1);
  387.   for (i1 = 1; i1 < l; i1++)
  388.     if (ss1[i1] == 32) {
  389.       ss1[i1] = 0;
  390.       ss[i++] = &(ss1[i1 + 1]);
  391.     }
  392.   ss[i] = NULL;
  393.   if (MOREINFO)
  394.     output("\nAvailable memory %ld bytes.\n", farcoreleft());
  395.   i = (spawnvpe(P_WAIT, ss[0], ss, xenviron) & 0x00ff);
  396.   if (ss1 != NULL)
  397.     farfree(ss1);
  398.   return (i);
  399. }
  400.  
  401. #ifndef PACKET
  402. void unload_klos(void)
  403. {
  404.   char s[101];
  405.  
  406.   sprintf(s, "%s\\IPSTUB U", maindir);
  407.   do_spawn(s);
  408.   sprintf(s, "%s\\PPP U", maindir);
  409.   do_spawn(s);
  410.   if (!lsl_loaded) {
  411.     sprintf(s, "%s\\LSL U", maindir);
  412.     do_spawn(s);
  413.   }
  414. }
  415. #endif
  416.  
  417. void cd_to(char *s)
  418. {
  419.   char *s1;
  420.   int i, db;
  421.  
  422.   s1 = s;
  423.   i = strlen(s1) - 1;
  424.   db = (s1[i] == '\\');
  425.   if (i == 0)
  426.     db = 0;
  427.   if ((i == 2) && (s1[1] == ':'))
  428.     db = 0;
  429.   if (db)
  430.     s1[i] = 0;
  431.   chdir(s1);
  432.   if (s[1] == ':')
  433.     setdisk(s[0] - 'A');
  434. }
  435.  
  436. void get_dir(char *s, int be)
  437. {
  438.   strcpy(s, "X:\\");
  439.   s[0] = 'A' + getdisk();
  440.   getcurdir(0, s + 3);
  441.   if (be) {
  442.     if (s[strlen(s) - 1] != '\\')
  443.       strcat(s, "\\");
  444.   }
  445. }
  446.  
  447. unsigned char *trimstr1(unsigned char *s)
  448. {
  449.   int i;
  450.   static char *whitespace = " \r\n\t";
  451.  
  452.   i = strlen(s);
  453.   if (i) {
  454.     while ((i > 0) && (_fstrchr(whitespace, s[i - 1])))
  455.       --i;
  456.     while ((i > 0) && (_fstrchr(whitespace, *s))) {
  457.       memmove(s, s + 1, --i);
  458.     }
  459.     s[i] = NUL;
  460.   }
  461.   return (s);
  462. }
  463.  
  464. char *make_abs_path(unsigned char *checkdir)
  465. {
  466.   char newdir[121];
  467.  
  468.   if ((strlen(checkdir) < 3) || (checkdir[1] != ':') || (checkdir[2] != '\\')) {
  469.     cd_to(maindir);
  470.     cd_to(checkdir);
  471.     if (LAST(checkdir) == '\\')
  472.       get_dir(newdir, 1);
  473.     else
  474.       get_dir(newdir, 0);
  475.     cd_to(maindir);
  476.     strcpy(checkdir, newdir);
  477.   }
  478.   return checkdir;
  479. }
  480.  
  481. int exist(char *s)
  482. {
  483.   int i;
  484.   struct ffblk ff;
  485.  
  486.   i = findfirst(s, &ff, FA_HIDDEN);
  487.   if (i)
  488.     return 0;
  489.   else
  490.     return 1;
  491. }
  492.  
  493. void set_net_num(int n)
  494. {
  495.   char s[121];
  496.   int f;
  497.  
  498.   sprintf(s, "%sNETWORKS.DAT", syscfg.datadir);
  499.   f = sh_open1(s, O_RDONLY | O_BINARY);
  500.   if (f < 0)
  501.     return;
  502.   lseek(f, ((long) (n)) * sizeof(net_networks_rec), SEEK_SET);
  503.   sh_read(f, &netcfg, sizeof(net_networks_rec));
  504.   close(f);
  505.   net_num = n;
  506.   net_sysnum = netcfg.sysnum;
  507.   strcpy(net_name, netcfg.name);
  508.   strcpy(net_data, make_abs_path(netcfg.dir));
  509.   if (LAST(net_data) != '\\')
  510.     strcat(net_data, "\\");
  511.   sprintf(wwiv_net_no, "WWIV_NET=%d", net_num);
  512. }
  513.  
  514. int make_path(char *s)
  515. {
  516.   unsigned int i;
  517.   char drive, current_path[MAXPATH], current_drive, *p, *flp;
  518.   union REGS r;
  519.  
  520.   p = flp = strdup(s);
  521.   _getdcwd(0, current_path, MAXPATH);
  522.   current_drive = *current_path - '@';
  523.   if (LAST(s) == '\\')
  524.     LAST(s) = 0;
  525.   if (p[1] == ':') {
  526.     drive = toupper(p[0]) - 'A' + 1;
  527.     if ((_osmajor == 3 && _osminor >= 1) || (_osmajor > 3)) {
  528.       r.x.ax = 0x4409;
  529.       r.h.bl = drive;
  530.       int86(0x21, &r, &r);
  531.       if (r.x.cflag)
  532.         return -3;
  533.     }
  534.     if (_chdrive(drive)) {
  535.       chdir(current_path);
  536.       _dos_setdrive(current_drive, &i);
  537.       return -2;
  538.     }
  539.     p += 2;
  540.   }
  541.   if (*p == '\\') {
  542.     chdir("\\");
  543.     p++;
  544.   }
  545.   for (; (p = strtok(p, "\\")) != 0; p = 0) {
  546.     if (chdir(p)) {
  547.       if (mkdir(p)) {
  548.         chdir(current_path);
  549.         _dos_setdrive(current_drive, &i);
  550.         return -1;
  551.       }
  552.       chdir(p);
  553.     }
  554.   }
  555.   chdir(current_path);
  556.   if (flp)
  557.     free(flp);
  558.   return 0;
  559. }
  560.  
  561. void process_mail(void)
  562. {
  563.   char s[121];
  564.  
  565.   output("\n ■ Network clean-up... please wait... ");
  566.   sprintf(s, "%s\\FLINK.EXE", maindir);
  567.   if (exist(s))
  568.     do_spawn(s);
  569.   sprintf(s, "%s\\LINKER.EXE", maindir);
  570.   if (exist(s))
  571.     do_spawn(s);
  572.   output("done.");
  573. }
  574.  
  575. int valid_system(unsigned int ts)
  576. {
  577.   int i;
  578.  
  579.   for (i = 0; i < num_sys_list; i++) {
  580.     if (netsys[i].sysnum == ts) {
  581.       if (netsys[i].numhops == 1)
  582.         return (1);
  583.       else
  584.         return (0);
  585.     }
  586.   }
  587.   return (0);
  588. }
  589.  
  590. int create_contact_ppp(void)
  591. {
  592.   char *ss, fn[101], s[81];
  593.   unsigned short node;
  594.   int curfile, i;
  595.   net_address_rec curaddr;
  596.   FILE *fp, *fc;
  597.  
  598.   sprintf(fn, "%sCONTACT.PPP", net_data);
  599.   if ((fc = fsh_open(fn, "wb+")) == NULL) {
  600.     output("\n ■ %s %s!\n", strings[0], fn);
  601.     return (1);
  602.   }
  603.   curfile = 1;
  604.   num_addr = 0;
  605.   do {
  606.     sprintf(fn, "%sADDRESS.%d", net_data, curfile);
  607.     if ((fp = fsh_open(fn, "rt")) == NULL)
  608.       curfile = -1;
  609.     while ((curfile > 0) && (fgets(s, 80, fp) != NULL)) {
  610.       if (s[0] != '@')
  611.         continue;
  612.       ss = strtok(s, " \t\r");
  613.       node = atoi(&ss[1]);
  614.       if (node) {
  615.         ss = strtok(NULL, " \t\r");
  616.         trimstr1(ss);
  617.         curaddr.sysnum = node;
  618.         strcpy(curaddr.address, ss);
  619.         if (ss[0]) {
  620.           fwrite(&curaddr, sizeof(net_address_rec), 1, fc);
  621.           ++num_addr;
  622.         }
  623.       }
  624.     }
  625.     if (fp != NULL)
  626.       fclose(fp);
  627.     ++curfile;
  628.   } while (curfile > 0);
  629.   fseek(fc, 0L, SEEK_SET);
  630.   sprintf(fn, "%sADDRESS.0", net_data);
  631.   if ((fp = fsh_open(fn, "rt")) == NULL) {
  632.     if (fc != NULL)
  633.       fclose(fc);
  634.     return(0);
  635.   }
  636.   while (fgets(s, 80, fp) != NULL) {
  637.     if (s[0] != '@')
  638.       continue;
  639.     ss = strtok(s, " \t\r");
  640.     node = atoi(&ss[1]);
  641.     do {
  642.       ss = strtok(NULL, " \t\r");
  643.       switch (ss[0]) {
  644.         case '-':
  645.           for (i = 0; i < num_addr; i++) {
  646.             fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  647.             fread(&curaddr, sizeof(net_address_rec), 1, fc);
  648.             if (node == curaddr.sysnum) {
  649.               curaddr.sysnum = 0;
  650.               fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  651.               fwrite(&curaddr, sizeof(net_address_rec), 1, fc);
  652.             }
  653.           }
  654.           break;
  655.       }
  656.     } while (ss);
  657.   }
  658.   if (fp != NULL)
  659.     fclose(fp);
  660.   if (fc != NULL)
  661.     fclose(fc);
  662.   return (0);
  663. }
  664.  
  665. void good_addr(char *address, unsigned short sn)
  666. {
  667.   char fn[101];
  668.   int i;
  669.   net_address_rec curaddr;
  670.   FILE *fc;
  671.  
  672.   address[0] = 0;
  673.   sprintf(fn, "%sCONTACT.PPP", net_data);
  674.   if ((fc = fsh_open(fn, "rb+")) == NULL) {
  675.     output("\n ■ %s %s!\n", strings[1], fn);
  676.     return;
  677.   }
  678.   for (i=0; ((i < num_addr) && (!address[0])); i++) {
  679.     fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  680.     fread(&curaddr, sizeof(net_address_rec), 1, fc);
  681.     if (sn == curaddr.sysnum)
  682.       strcpy(address, curaddr.address);
  683.   }
  684.   if (fc != NULL)
  685.     fclose(fc);
  686. }
  687.  
  688. int copyfile(char *infn, char *outfn)
  689. {
  690.   int f1, f2, i;
  691.   char *b;
  692.   struct ftime ft;
  693.  
  694.   if ((strcmp(infn, outfn) != 0) && (exist(infn)) && (!exist(outfn))) {
  695.     if ((b = (char *) farmalloc(16400)) == NULL)
  696.       return 0;
  697.     f1 = sh_open1(infn, O_RDONLY | O_BINARY);
  698.     if (!f1) {
  699.       farfree(b);
  700.       b = NULL;
  701.       return 0;
  702.     }
  703.     getftime(f1, &ft);
  704.     f2 = sh_open(outfn, O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  705.     if (!f2) {
  706.       farfree(b);
  707.       b = NULL;
  708.       f1 = sh_close(f1);
  709.       return 0;
  710.     }
  711.     i = sh_read(f1, (char *)b, 16384);
  712.     while (i > 0) {
  713.       sh_write(f2, (char *)b, i);
  714.       i = sh_read(f1, (char *)b, 16384);
  715.     }
  716.     f1 = sh_close(f1);
  717.     setftime(f2, &ft);
  718.     f2 = sh_close(f2);
  719.     farfree(b);
  720.     b = NULL;
  721.   }
  722.   return 1;
  723. }
  724.  
  725. void do_exit(int exitlevel)
  726. {
  727.   delay(2000);
  728.   exit(2 - exitlevel);
  729. }
  730.  
  731. int uu(char *fn, char *pktname, char *dest)
  732. {
  733.   int ok;
  734.   char s[121], s1[121], s2[81];
  735.   FILE *fp;
  736.  
  737.   sprintf(s, "%sMQUEUE\\%s.UUE", net_data, pktname);
  738.   if ((fp = fsh_open(s, "wt")) == NULL) {
  739.     output("\n ■ %s %s!", strings[0], s);
  740.     do_exit(EXIT_FAILURE);
  741.   } else {
  742.     sprintf(s2, "from: %s@%s\n", POPNAME, DOMAIN);
  743.     fprintf(fp, s2);
  744.     sprintf(s2, "to: %s\n", dest);
  745.     fprintf(fp, s2);
  746.     sprintf(s2, "subject: @%s NET PACKET : %s.UUE\n\n", net_name, pktname);
  747.     fprintf(fp, s2);
  748.   }
  749.   if (fp != NULL)
  750.     fclose(fp);
  751.   sprintf(s1, "%s\\UU.EXE -encode %s %s", maindir, fn, s);
  752.   ok = do_spawn(s1);
  753.   return ok;
  754. }
  755.  
  756. int update_contact(unsigned short sy, unsigned long sb, unsigned long rb)
  757. {
  758.   char s[101];
  759.   int i, i1, f;
  760.   long cur_time, l;
  761.  
  762.   sprintf(s, "%sCONTACT.NET", net_data);
  763.   f = sh_open1(s, O_RDONLY | O_BINARY);
  764.   if (f >= 0) {
  765.     l = filelength(f);
  766.     netcfg.num_ncn = (int) (l / sizeof(net_contact_rec));
  767.     if ((netcfg.ncn = (net_contact_rec *) farmalloc((netcfg.num_ncn + 2) *
  768.                                         sizeof(net_contact_rec))) == NULL) {
  769.       f = sh_close(f);
  770.       return 1;
  771.     }
  772.     sh_lseek(f, 0L, SEEK_SET);
  773.     sh_read(f, (void *) netcfg.ncn, netcfg.num_ncn * sizeof(net_contact_rec));
  774.     f = sh_close(f);
  775.   }
  776.   for (i = 0; i < netcfg.num_ncn; i++)
  777.     if (netcfg.ncn[i].systemnumber == sy)
  778.       i1 = i;
  779.   time(&cur_time);
  780.   netcfg.ncn[i1].lasttry = cur_time;
  781.   ++netcfg.ncn[i1].numcontacts;
  782.   if (!netcfg.ncn[i1].firstcontact)
  783.     netcfg.ncn[i1].firstcontact = cur_time;
  784.   netcfg.ncn[i1].lastcontact = cur_time;
  785.   netcfg.ncn[i1].lastcontactsent = cur_time;
  786.   netcfg.ncn[i1].bytes_sent += sb;
  787.   if (rb)
  788.     netcfg.ncn[i1].bytes_received += rb;
  789.   netcfg.ncn[i1].bytes_waiting = 0L;
  790.   sprintf(s, "%sS%hd.net", net_data, sy);
  791.   if (!exist(s))
  792.     sprintf(s, "%sZ%hd.net", net_data, sy);
  793.   f = sh_open1(s, O_RDONLY | O_BINARY);
  794.   if (f > 0) {
  795.     netcfg.ncn[i1].bytes_waiting += filelength(f);
  796.     close(f);
  797.   }
  798.   sprintf(s, "%sCONTACT.NET", net_data);
  799.   f = sh_open1(s, O_RDWR | O_CREAT | O_BINARY);
  800.   if (f > 0) {
  801.     sh_lseek(f, 0L, SEEK_SET);
  802.     sh_write(f, (void *) netcfg.ncn, netcfg.num_ncn * sizeof(net_contact_rec));
  803.     f = sh_close(f);
  804.   }
  805.   if (netcfg.ncn)
  806.     farfree(netcfg.ncn);
  807.   return 0;
  808. }
  809.  
  810.  
  811. int update_contacts(unsigned short sy, unsigned long sb, unsigned long rb)
  812. {
  813.   int i, i1, rc;
  814.   char fn[101];
  815.   net_address_rec curaddr;
  816.   FILE *fc;
  817.  
  818.   rc = 0;
  819.   sprintf(fn, "%sCONTACT.PPP", net_data);
  820.   if ((fc = fsh_open(fn, "rb+")) == NULL) {
  821.     output("\n ■ %s %s!\n", strings[1], fn);
  822.     rc = 1;
  823.     return (rc);
  824.   }
  825.   for (i = 0; i < num_addr; i++) {
  826.     fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  827.     fread(&curaddr, sizeof(net_address_rec), 1, fc);
  828.     if (curaddr.sysnum != 0) {
  829.       if (curaddr.sysnum == sy)
  830.         i1 = update_contact(curaddr.sysnum, sb, rb);
  831.       else
  832.         i1 = update_contact(curaddr.sysnum, 0, 0);
  833.       if (i1)
  834.         rc = 1;
  835.     }
  836.   }
  837.   if (fc != NULL)
  838.     fclose(fc);
  839.   return (rc);
  840. }
  841.  
  842. int uu_packets(void)
  843. {
  844.   char pktname[21], s[121], s1[121], s2[121], s3[121], temp[121];
  845.   int found, sz, f, f1, i;
  846.   unsigned long sbytes, basename;
  847.   net_address_rec curaddr;
  848.   FILE *fc;
  849.  
  850.   num_sys_list = 0;
  851.   found = 0;
  852.   basename = time(NULL);
  853.   sprintf(s, "%sBBSDATA.NET", net_data);
  854.   f = sh_open1(s, O_RDONLY | O_BINARY);
  855.   if (f > 0) {
  856.     num_sys_list = (int) (filelength(f) / sizeof(net_system_list_rec));
  857.     if ((netsys = (net_system_list_rec *) farmalloc((num_sys_list + 2) *
  858.                                     sizeof(net_system_list_rec))) == NULL) {
  859.       output("\n ■ Unable to allocate %d bytes of memory for BBSDATA.NET",
  860.               (int) (num_sys_list + 2) * sizeof(net_system_list_rec));
  861.       f = sh_close(f);
  862.       return 0;
  863.     }
  864.     sh_lseek(f, 0L, SEEK_SET);
  865.     sh_read(f, (void *) netsys, num_sys_list * sizeof(net_system_list_rec));
  866.     f = sh_close(f);
  867.   } else
  868.     return 0;
  869.  
  870.   sprintf(s1, "%sCONTACT.PPP", net_data);
  871.   if ((fc = fsh_open(s1, "rb+")) == NULL) {
  872.     output("\n ■ %s %s!\n", strings[1], s1);
  873.     farfree(netsys);
  874.     return 0;
  875.   }
  876.   for (i=0; i < num_addr; i++) {
  877.     fseek(fc, (long) i * sizeof(net_address_rec), SEEK_SET);
  878.     fread(&curaddr, sizeof(net_address_rec), 1, fc);
  879.     if ((valid_system(curaddr.sysnum)) && (curaddr.sysnum != 32767)) {
  880.       sprintf(s1, "%sS%hd.NET", net_data, curaddr.sysnum);
  881.       if (exist(s1)) {
  882.         sz = 0;
  883.         found = 1;
  884.       } else {
  885.         sprintf(s1, "%sZ%hd.NET", net_data, curaddr.sysnum);
  886.         if (exist(s1)) {
  887.           sz = 1;
  888.           found = 1;
  889.         } else
  890.           continue;
  891.       }
  892.       do {
  893.         sprintf(pktname, "%8.8lx", ++basename);
  894.         sprintf(temp, "%sMQUEUE\\%s.UUE", net_data, pktname);
  895.       } while (exist(temp));
  896.       backline();
  897.       output("\r ■ Encoding %s%hd.NET as %s.UUE -",
  898.               sz ? "Z" : "S", curaddr.sysnum, strupr(pktname));
  899.       if ((uu(s1, pktname, curaddr.address)) != EXIT_SUCCESS) {
  900.         output("\n ■ %s %sMQUEUE\\%s.UUE", strings[0], net_data, pktname);
  901.         if (fc != NULL)
  902.           fclose(fc);
  903.         farfree(netsys);
  904.         do_exit(EXIT_FAILURE);
  905.       } else {
  906.         if (KEEPSENT) {
  907.           sprintf(s3, "%sMQUEUE\\%s.UUE", net_data, pktname);
  908.           sprintf(s2, "%sSENT\\%s.SNT", net_data, pktname);
  909.           f1 = sh_open1(s3, O_RDONLY | O_BINARY);
  910.           if (f1 > 0) {
  911.             sbytes = filelength(f1);
  912.             f = sh_close(f1);
  913.           }
  914.           if (!copyfile(s3, s2))
  915.             output("\n ■ %s %s%hd.NET", strings[0], sz ? "Z" : "S", curaddr.sysnum);
  916.         }
  917.         unlink(s1);
  918.         update_contact(curaddr.sysnum, sbytes, 0);
  919.       }
  920.     }
  921.   }
  922.   if (fc != NULL)
  923.     fclose(fc);
  924.   farfree(netsys);
  925.   return found;
  926. }
  927.  
  928. int purge_sent(void)
  929. {
  930.   char s[121];
  931.   int f1, howmany = 0;
  932.   long age;
  933.   struct ffblk ff;
  934.   struct stat fileinfo;
  935.  
  936.   sprintf(s, "%sSENT\\*.*", net_data);
  937.   f1 = findfirst(s, &ff, 0);
  938.   while (f1 == 0) {
  939.     sprintf(s, "%sSENT\\%s", net_data, ff.ff_name);
  940.     if (stat(s, &fileinfo) == 0) {
  941.       age = (time(NULL) - fileinfo.st_atime);
  942.       if (age > (86400L * KEEPSENT)) {
  943.         ++howmany;
  944.         unlink(s);
  945.       }
  946.     }
  947.     f1 = findnext(&ff);
  948.   }
  949.   return howmany;
  950. }
  951.  
  952. int parse_net_ini(void)
  953. {
  954.   char cursect;
  955.   char line[121], *ss;
  956.   FILE *fp;
  957.  
  958.   if ((fp = fsh_open("NET.INI", "rt")) == NULL)
  959.     return (0);
  960.   while (fgets(line, 80, fp)) {
  961.     stripspace(line);
  962.     ss = NULL;
  963.     ss = strtok(line, "=");
  964.     if (ss)
  965.       ss = strtok(NULL, "\n");
  966.     if ((line[0] == ';') || (line[0] == '\n') || (strlen(line) == 0))
  967.       continue;
  968.     if ((strnicmp(line, "[FILENET]", 9) == 0) ||
  969.         (strnicmp(line, "[PPPNET]", 8) == 0)) {
  970.       cursect = INI_NETWORK;
  971.       ini_section |= INI_NETWORK;
  972.       continue;
  973.     }
  974.     if (strnicmp(line, "[GENERAL]", 9) == 0) {
  975.       cursect = INI_GENERAL;
  976.       ini_section |= INI_GENERAL;
  977.       continue;
  978.     }
  979.     if (strnicmp(line, "[NEWS]", 6) == 0) {
  980.       cursect = INI_NEWS;
  981.       ini_section |= INI_NEWS;
  982.       continue;
  983.     }
  984.     if (cursect & INI_NETWORK) {
  985.       if (strnicmp(line, "TIMEHOST", 8) == 0) {
  986.         if (ss)
  987.           strcpy(TIMEHOST, ss);
  988.         continue;
  989.       }
  990.       if (strnicmp(line, "SMTPHOST", 8) == 0) {
  991.         if (ss)
  992.           strcpy(SMTPHOST, ss);
  993.         continue;
  994.       }
  995.       if (strnicmp(line, "POPHOST", 7) == 0) {
  996.         if (ss)
  997.           strcpy(POPHOST, ss);
  998.         continue;
  999.       }
  1000.       if (strnicmp(line, "POPNAME", 7) == 0) {
  1001.         if (ss)
  1002.           strcpy(POPNAME, ss);
  1003.         continue;
  1004.       }
  1005.       if (strnicmp(line, "POPPASS", 7) == 0) {
  1006.         if (ss)
  1007.           strcpy(POPPASS, ss);
  1008.         continue;
  1009.       }
  1010.     }
  1011.     if (cursect & INI_GENERAL) {
  1012.       if (strnicmp(line, "TIMEOUT", 7) == 0) {
  1013.         if (atoi(ss))
  1014.           TIMEOUT = atoi(ss);
  1015.         continue;
  1016.       }
  1017.       if (strnicmp(line, "SOCK_DELAY", 10) == 0) {
  1018.         if (atoi(ss))
  1019.           SOCK_DELAY = atoi(ss);
  1020.         continue;
  1021.       }
  1022.       if ((strnicmp(line, "INACTIVE", 8) == 0) || (strnicmp(line, "SOCK_INACTIVE", 13) == 0)) {
  1023.         if (atoi(ss))
  1024.           INACTIVE = atoi(ss);
  1025.         continue;
  1026.       }
  1027.       if (strnicmp(line, "KEEPSENT", 8) == 0) {
  1028.         if (atoi(ss))
  1029.           KEEPSENT = atoi(ss);
  1030.         continue;
  1031.       }
  1032.       if (strnicmp(line, "PURGE", 5) == 0) {
  1033.         if (toupper(ss[0]) == 'N')
  1034.           PURGE = 0;
  1035.         continue;
  1036.       }
  1037.       if (strnicmp(line, "ALLMAIL", 7) == 0) {
  1038.         if (toupper(ss[0]) == 'N')
  1039.           ALLMAIL = 0;
  1040.         continue;
  1041.       }
  1042.       if (strnicmp(line, "ONECALL", 7) == 0) {
  1043.         if (toupper(ss[0]) == 'Y')
  1044.           ONECALL = 1;
  1045.         continue;
  1046.       }
  1047.       if (strnicmp(line, "MOREINFO", 8) == 0) {
  1048.         if (toupper(ss[0]) == 'Y')
  1049.           MOREINFO = 1;
  1050.         continue;
  1051.       }
  1052.       if (strnicmp(line, "CLEANUP", 7) == 0) {
  1053.         if (toupper(ss[0]) == 'Y')
  1054.           CLEANUP = 1;
  1055.         continue;
  1056.       }
  1057.       if (strnicmp(line, "IPADDR", 6) == 0) {
  1058.         if ((ss) && (ss[0] != '0'))
  1059.           strcpy(IPADDR, ss);
  1060.         continue;
  1061.       }
  1062.       if (strnicmp(line, "NETMASK", 7) == 0) {
  1063.         if (ss)
  1064.           strcpy(NETMASK, ss);
  1065.         continue;
  1066.       }
  1067.       if (strnicmp(line, "DNS", 3) == 0) {
  1068.         if (ss)
  1069.           strcpy(DNS, ss);
  1070.         continue;
  1071.       }
  1072.       if (strnicmp(line, "SDNS", 3) == 0) {
  1073.         if (ss)
  1074.           strcpy(SDNS, ss);
  1075.         continue;
  1076.       }
  1077.       if (strnicmp(line, "DOMAIN", 6) == 0) {
  1078.         if (ss)
  1079.           strcpy(DOMAIN, ss);
  1080.         continue;
  1081.       }
  1082.       if (strnicmp(line, "FWDNAME", 7) == 0) {
  1083.         if (ss)
  1084.           strcpy(FWDNAME, ss);
  1085.         continue;
  1086.       }
  1087.       if (strnicmp(line, "FWDDOM", 6) == 0) {
  1088.         if (ss)
  1089.           strcpy(FWDDOM, ss);
  1090.         continue;
  1091.       }
  1092.       if (strnicmp(line, "GATEWAY", 7) == 0) {
  1093.         if ((ss) && (ss[0] != '0'))
  1094.           strcpy(GATEWAY, ss);
  1095.         continue;
  1096.       }
  1097.     }
  1098.     if (cursect & INI_NEWS) {
  1099.       if (strnicmp(line, "NEWSHOST", 8) == 0) {
  1100.         if (ss)
  1101.           strcpy(NEWSHOST, ss);
  1102.         continue;
  1103.       }
  1104.     }
  1105.   }
  1106.   if (!FWDNAME[0])
  1107.     strcpy(FWDNAME, POPNAME);
  1108.   if (!FWDDOM[0])
  1109.     strcpy(FWDDOM, DOMAIN);
  1110.   if (fp != NULL)
  1111.     fclose(fp);
  1112.   return (1);
  1113. }
  1114.  
  1115. #define MAX_LEN 12288
  1116.  
  1117. int open_netlog(char *fn)
  1118. {
  1119.   int f, count = 0;
  1120.  
  1121.   do {
  1122.     f = open(fn, O_RDWR | O_BINARY | SH_DENYRW | O_CREAT, S_IREAD | S_IWRITE);
  1123.   } while ((f < 0) && (errno == EACCES) && (count++ < 500));
  1124.  
  1125.   return(f);
  1126. }
  1127.  
  1128.  
  1129. int write_netlog(int sn, long sent, long recd, char *tmused)
  1130. {
  1131.   int f;
  1132.   char *ss, s[101], s1[81], s2[81], fn[121];
  1133.   long l;
  1134.   struct tm *time_now;
  1135.   time_t some;
  1136.  
  1137.   time(&some);
  1138.   time_now = localtime(&some);
  1139.   strftime(s1, 35, "%m/%d/%y %H:%M:%S", time_now);
  1140.  
  1141.   ss = (char *) farmalloc(MAX_LEN+1024L);
  1142.   if (ss == NULL) {
  1143.     output("\n ■ Insufficient memory to update NET.LOG!");
  1144.     return 1;
  1145.   }
  1146.  
  1147.   if ((sent) || (recd)) {
  1148.     if ((recd) && (!sent))
  1149.       sprintf(s2, "       , R:%4ldk,", recd);
  1150.     else {
  1151.       if ((recd) && (sent))
  1152.         sprintf(s2, "S:%4ldk, R:%4ldk,", sent, recd);
  1153.       else
  1154.         sprintf(s2, "S:%4ldk,         ", sent);
  1155.     }
  1156.   } else
  1157.     strcpy(s2, "                 ");
  1158.   sprintf(s, "%s To %5d, %s         %5s min  %s\r\n", s1, sn, s2,
  1159.             tmused, net_name);
  1160.  
  1161.   strcpy(ss, s);
  1162.  
  1163.   sprintf(fn, "%sNET.LOG", syscfg.gfilesdir);
  1164.   f = open_netlog(fn);
  1165.   sh_lseek(f, 0L, SEEK_SET);
  1166.   l = (long) (sh_read(f, (void *)(&(ss[strlen(s)])), MAX_LEN) + strlen(s));
  1167.   while ((l > 0L) && (ss[(int)l] != '\n'))
  1168.     --l;
  1169.   sh_lseek(f, 0L, SEEK_SET);
  1170.   write(f, (void *) ss, (int)l + 1);
  1171.   chsize(f, l + 1);
  1172.   if (ss) {
  1173.     farfree(ss);
  1174.     ss = NULL;
  1175.   }
  1176.   sh_close(f);
  1177.   return 0;
  1178. }
  1179.  
  1180. void read_networks(void)
  1181. {
  1182.   int f;
  1183.   char s[121];
  1184.  
  1185.   sprintf(s, "%sNETWORKS.DAT", syscfg.datadir);
  1186.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1187.   net_num_max = 0;
  1188.   if (f > 0) {
  1189.     net_num_max = (int) (filelength(f) / sizeof(net_networks_rec));
  1190.     f = sh_close(f);
  1191.   }
  1192. }
  1193.  
  1194. void init(void)
  1195. {
  1196.   char s[81], s1[81], *ss;
  1197.   int i, i1, dv, f;
  1198.   struct tm *time_now;
  1199.   time_t some;
  1200.  
  1201.   output("\n%s\n%s\n\n", version, author);
  1202.   get_dir(maindir, 0);
  1203.   ss = getenv("WWIV_INSTANCE");
  1204.   if (ss) {
  1205.     instance = atoi(ss);
  1206.     if ((instance <= 0) || (instance > 999)) {
  1207.       output("\n ■ WWIV_INSTANCE can only be 1..999!");
  1208.       instance = 1;
  1209.     }
  1210.   } else {
  1211.     instance = 1;
  1212.   }
  1213.  
  1214.   detect_multitask();
  1215.  
  1216.   switch (multitasker) {
  1217.     case 1:
  1218.       dv = get_dv_version();
  1219.       sprintf(s1, "DesqView %d.%02d", dv / 256, dv % 256);
  1220.       break;
  1221.     case 2:
  1222.       dv = get_win_version();
  1223.       if (dv == 4)
  1224.         strcpy(s1, "Windows 95");
  1225.       else
  1226.         sprintf(s1, "Windows %d.%02d", dv % 256, dv / 256);
  1227.       break;
  1228.     case 3:
  1229.       dv = get_dv_version();
  1230.       sprintf(s1, "Windows and DesqView %d.%02d", dv / 256, dv % 256);
  1231.       break;
  1232.     case 4:
  1233.     case 5:
  1234.     case 6:
  1235.     case 7:
  1236.       if ((_osmajor / 10 == 2) && (_osminor >= 30))
  1237.         strcpy(s1, "OS/2 Warp");
  1238.       else
  1239.         sprintf(s1, "OS/2 %d.%2.2d", _osmajor / 10, _osminor);
  1240.       break;
  1241.     case 8:
  1242.       sprintf(s1, "NETBIOS network");
  1243.       multitasker = 1;
  1244.       break;
  1245.     default:
  1246.       strcpy(s1, "DOS");
  1247.       break;
  1248.   }
  1249.   strcpy(s, "CONFIG.DAT");
  1250.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1251.   if (f < 0) {
  1252.     output("\n ■ %s NOT FOUND.", s);
  1253.     return;
  1254.   }
  1255.   sh_read(f, (void *) (&syscfg), sizeof(configrec));
  1256.   f = sh_close(f);
  1257.   output(" ■ Running under %s on instance %d ", s1, instance);
  1258.   time(&some);
  1259.   time_now = localtime(&some);
  1260.   strftime(s, 80, "at %I:%M%p, %d %b %y", time_now);
  1261.   printf(s);
  1262.   strcpy(s, "CONFIG.OVR");
  1263.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1264.   if (f < 0) {
  1265.     output("\n ■ %s NOT FOUND.", s);
  1266.     return;
  1267.   }
  1268.   sh_lseek(f, (instance - 1) * sizeof(configoverrec), SEEK_SET);
  1269.   sh_read(f, &syscfgovr, sizeof(configoverrec));
  1270.   f = sh_close(f);
  1271.   sprintf(s, "%sINSTANCE.DAT", syscfg.datadir);
  1272.   if (!exist(s)) {
  1273.     output("\n ■ %s NOT FOUND.", s);
  1274.     return;
  1275.   }
  1276.   read_networks();
  1277.   i = i1 = 0;
  1278.   while ((environ[i] != NULL) && (i < 20)) {
  1279.     xenviron[i1++] = environ[i];
  1280.     ++i;
  1281.   }
  1282.   xenviron[i1] = NULL;
  1283. }
  1284.  
  1285. long getfctime(char *s)
  1286. {
  1287.   struct stat statbuf;
  1288.  
  1289.   if (stat(s, &statbuf) < 0)
  1290.     return (0L);
  1291.   else
  1292.     return (statbuf.st_atime);
  1293. }
  1294.  
  1295. int process_bbsdata(void)
  1296. {
  1297.   char s[101];
  1298.   unsigned long bbslist_ctime, connect_ctime, callout_ctime, bbsdata_ctime;
  1299.   int tf, n, net3;
  1300.  
  1301.   net3 = 0;
  1302.   sprintf(s, "%sBBSLIST.NET", net_data);
  1303.   bbslist_ctime = getfctime(s);
  1304.   sprintf(s, "%sCONNECT.NET", net_data);
  1305.   connect_ctime = getfctime(s);
  1306.   sprintf(s, "%sCALLOUT.NET", net_data);
  1307.   callout_ctime = getfctime(s);
  1308.   sprintf(s, "%sBBSDATA.NET", net_data);
  1309.   bbsdata_ctime = getfctime(s);
  1310.   sprintf(s, "%sBBSLIST.UPD", net_data);
  1311.   bbslist_ctime = getfctime(s);
  1312.   sprintf(s, "%sCONNECT.UPD", net_data);
  1313.   connect_ctime = getfctime(s);
  1314.  
  1315.   n = 0;
  1316.   tf = ((bbslist_ctime > bbsdata_ctime) || (connect_ctime > bbsdata_ctime));
  1317.   if (tf)
  1318.     n = 1;
  1319.   tf = (tf || (callout_ctime > bbsdata_ctime));
  1320.   if (tf) {
  1321.     sprintf(s, "NETWORK3 .%d", netnum);
  1322.     if (n) {
  1323.       sprintf(s, "NETWORK3 .%d Y", netnum);
  1324.       net3 = 1;
  1325.     }
  1326.     do_spawn(s);
  1327.   }
  1328.   return (net3);
  1329. }
  1330.  
  1331. void do_it(char *cl)
  1332. {
  1333.   int i, i1, l;
  1334.   char *s, *ss[30];
  1335.  
  1336.   s = strdup(cl);
  1337.   ss[0] = s;
  1338.   i = 1;
  1339.   l = strlen(s);
  1340.   for (i1 = 1; i1 < l; i1++)
  1341.     if (s[i1] == 32) {
  1342.       s[i1] = 0;
  1343.       ss[i++] = &(s[i1 + 1]);
  1344.     }
  1345.   ss[i] = NULL;
  1346.   execvpe(ss[0], ss, xenviron);
  1347. }
  1348.  
  1349. int create_wattcp_cfg(void)
  1350. {
  1351.   char s[MAXPATH], s1[41];
  1352.   FILE *fp;
  1353.  
  1354.   sprintf(s, "%s\\WATTCP.CFG", maindir);
  1355.   if ((fp = fsh_open(s, "wt")) == NULL) {
  1356.     output("\n ■ %s %s!", strings[0], s);
  1357.     return 1;
  1358.   }
  1359.   fseek(fp, 0L, SEEK_SET);
  1360.   sprintf(s, "my_ip=%s\n", IPADDR);
  1361.   fprintf(fp, s);
  1362.   fprintf(fp, "netmask=%s\n", NETMASK);
  1363.   fprintf(fp, "nameserver=%s\n", DNS);
  1364.   if (*SDNS)
  1365.     fprintf(fp, "nameserver=%s\n", SDNS);
  1366.   if (GATEWAY[0] == 0) {
  1367.     strcpy(s1, IPADDR);
  1368.     while (LAST(s1) != '.')
  1369.       LAST(s1) = 0;
  1370.     strcat(s1, "1");
  1371.     strcpy(GATEWAY, s1);
  1372.   }
  1373.   sprintf(s, "gateway=%s\n", GATEWAY);
  1374.   fprintf(fp, s);
  1375.   fprintf(fp, "domains=\"%s\"\n", DOMAIN);
  1376.   fprintf(fp, "hostname=\"%s\"\n", POPNAME);
  1377.   fprintf(fp, "sockdelay=%d\n", SOCK_DELAY);
  1378.   fprintf(fp, "inactive=%d\n", INACTIVE);
  1379.   if (fp != NULL)
  1380.     fclose(fp);
  1381.   return 0;
  1382. }
  1383.  
  1384. int check_for_lsl(void)
  1385. {
  1386.   union REGS r;
  1387.   struct SREGS s;
  1388.   char *intstr;
  1389.  
  1390.   for (r.h.ah = 0xc0; r.h.ah != 0; r.h.ah++) {
  1391.     r.h.al = 0;
  1392.     int86x(0x2f, &r, &r, &s);
  1393.     if (r.h.al == 0xff) {
  1394.       intstr = (char *) MK_FP(s.es, r.x.si);
  1395.       if (strncmp(intstr, "LINKSUP$", 8) == 0)
  1396.         return 1;
  1397.     }
  1398.   }
  1399.   return 0;
  1400. }
  1401.  
  1402. #ifndef PACKET
  1403. void klos_ppp(void)
  1404. {
  1405.   char s[121], fn[MAXPATH], *ss;
  1406.   int i;
  1407.   FILE *fp;
  1408.  
  1409.   lsl_loaded = check_for_lsl();
  1410.   if (!lsl_loaded) {
  1411.     sprintf(s, "%s\\LSL.COM", maindir);
  1412.     if (exist(s)) {
  1413.       if (MOREINFO)
  1414.         output("\n ■ Loading Link Support Layer and ");
  1415.       do_spawn(s);
  1416.     } else {
  1417.       output("\n ■ LSL.COM not in BBS main directory!");
  1418.       do_exit(EXIT_FAILURE);
  1419.     }
  1420.   } else {
  1421.     if (MOREINFO)
  1422.       output("\n ■ LSL already in memory - loading ");
  1423.   }
  1424.   sprintf(s, "%s\\PPP.EXE", maindir);
  1425.   if (exist(s)) {
  1426.     if (MOREINFO)
  1427.       output("PPP packet driver.");
  1428.     do_spawn(s);
  1429.   } else {
  1430.     output("\n ■ %s\\PPP.EXE not found!", maindir);
  1431.     do_exit(EXIT_FAILURE);
  1432.   }
  1433.   while (kbhit())
  1434.     getch();
  1435.   sprintf(s, "%s\\PPPSTATE.EXE", maindir);
  1436.   if (exist(s)) {
  1437.     output("\n ■ Dialing %s... timeout %d seconds... ", DOMAIN, TIMEOUT);
  1438.     delay(2000);
  1439.     sprintf(s, "%s\\PPPSTATE.EXE WAIT=%d IP", maindir, TIMEOUT);
  1440.     i = do_spawn(s);
  1441.     switch (i) {
  1442.       case 0:
  1443.         output(" connected!");
  1444.         break;
  1445.       case 1:
  1446.         output("\n ■ Unable to establish connection... aborting");
  1447.         sprintf(s, "%s\\PPP U", maindir);
  1448.         do_spawn(s);
  1449.         if (!lsl_loaded) {
  1450.           sprintf(s, "%s\\LSL U", maindir);
  1451.           do_spawn(s);
  1452.         }
  1453.         do_exit(EXIT_FAILURE);
  1454.       case 2:
  1455.         output("\n ■ Unable to find PPP layer... aborting");
  1456.         if (!lsl_loaded) {
  1457.           sprintf(s, "%s\\LSL U", maindir);
  1458.           do_spawn(s);
  1459.         }
  1460.         do_exit(EXIT_FAILURE);
  1461.       default:
  1462.         output("\n ■ %s PPPState #%d... aborting", strings[2], i);
  1463.         sprintf(s, "%s\\PPP U", maindir);
  1464.         do_spawn(s);
  1465.         if (!lsl_loaded) {
  1466.           sprintf(s, "%s\\LSL U", maindir);
  1467.           do_spawn(s);
  1468.         }
  1469.         do_exit(EXIT_FAILURE);
  1470.     }
  1471.   } else {
  1472.     output("\n ■ %s\\PPPSTATE.EXE not found!", maindir);
  1473.     do_exit(EXIT_FAILURE);
  1474.   }
  1475.   if (!IPADDR[0]) {
  1476.     sprintf(s, "%s\\PPPWAT.EXE", maindir);
  1477.     if (exist(s)) {
  1478.       do_spawn(s);
  1479.     } else {
  1480.       output("\n ■ %s\\PPPWAT.EXE not found!", maindir);
  1481.       unload_klos();
  1482.       do_exit(EXIT_FAILURE);
  1483.     }
  1484.     sprintf(fn, "%s\\WATTCP.CFG", maindir);
  1485.     if ((fp = fsh_open(fn, "rt")) == NULL) {
  1486.       output("\n ■ %s %s\\WATTCP.CFG... aborting!", strings[1], maindir);
  1487.       unload_klos();
  1488.       do_exit(EXIT_FAILURE);
  1489.     } else {
  1490.       while (fgets(s, 100, fp) != NULL) {
  1491.         if (strnicmp(s, "my_ip", 5) == 0) {
  1492.           ss = strtok(s, "=");
  1493.           ss = strtok(NULL, "\r");
  1494.           trimstr1(ss);
  1495.           strcpy(IPADDR, ss);
  1496.           break;
  1497.         }
  1498.       }
  1499.     }
  1500.     if (fp != NULL)
  1501.       fclose(fp);
  1502.   }
  1503.   if (IPADDR) {
  1504.     output("\n ■ IP address set to %s... ", IPADDR);
  1505.     if (create_wattcp_cfg()) {
  1506.       unload_klos();
  1507.       do_exit(EXIT_FAILURE);
  1508.     }
  1509.   } else {
  1510.     output("\n ■ Could not find IP Address... aborting!");
  1511.     unload_klos();
  1512.     do_exit(EXIT_FAILURE);
  1513.   }
  1514.   sprintf(s, "%s\\IPSTUB.EXE", maindir);
  1515.   if (exist(s)) {
  1516.     do_spawn(s);
  1517.   } else {
  1518.     output("\n ■ %s\\IPSTUB.EXE not found!", maindir);
  1519.     do_exit(EXIT_FAILURE);
  1520.   }
  1521.   output("establishing socket     ");
  1522.   for (i = 3; i >= 0; i--) {
  1523.     output("\b\b\b\b%d...", i);
  1524.     delay(1000);
  1525.   }
  1526.   output("\b\b\b\b\b... ready!");
  1527. }
  1528. #endif
  1529.  
  1530. int main(int argc, char *argv[])
  1531. {
  1532.   int i, ok, news, totf, send, f1;
  1533.   unsigned short sy;
  1534.   char *ss, s[121], s1[MAXPATH], destaddr[121], temp[121];
  1535.   char ttotal[21];
  1536.   clock_t starttime, mailtime, newstime;
  1537.   static unsigned long dspace, sentbytes, recdbytes, rnewsbytes, snewsbytes;
  1538.   FILE *fp;
  1539.   struct ffblk ff;
  1540.   struct diskfree_t df;
  1541.  
  1542.   init_stack_count();
  1543.   init();
  1544.   news = 0;
  1545.   num_addr = 0;
  1546.   ss = argv[argc - 1];
  1547.   ok = 0;
  1548.   if (_fstrstr((char *) ss, ".") != NULL) {
  1549.     if (atoi(&ss[1]) < net_num_max) {
  1550.       netnum = atoi(&ss[1]);
  1551.       ok = 1;
  1552.     }
  1553.   } else {
  1554.     ss = (getenv("WWIV_NET"));
  1555.     netnum = atoi(ss);
  1556.     if (netnum < net_num_max)
  1557.       ok = 1;
  1558.   }
  1559.   if (!ok) {
  1560.     strcpy(s, "WWIV_NET.DAT");
  1561.     if ((fp = fsh_open(s, "rb")) != NULL) {
  1562.       fgets(s, 3, fp);
  1563.       netnum = atoi(s);
  1564.       if (fp != NULL)
  1565.         fclose(fp);
  1566.       if (netnum < net_num_max)
  1567.         ok = 1;
  1568.     }
  1569.   }
  1570.   ss = argv[1];
  1571.   if (strncmpi(ss, "/N", 2))
  1572.     ok = 0;
  1573.   set_net_num(netnum);
  1574.   sprintf(s, "%sADDRESS.1", net_data);
  1575.   if (!exist(s))
  1576.     ok = 0;
  1577.   if (ok) {
  1578.     *SMTPHOST = *POPHOST = *NEWSHOST = *TIMEHOST = *POPNAME = *POPPASS = 0;
  1579.     *IPADDR = *NETMASK = *DNS = *SDNS = *DOMAIN = *GATEWAY = *FWDNAME = *FWDDOM = 0;
  1580.     if (parse_net_ini()) {
  1581.       set_net_num(netnum);
  1582.       if (ini_section & INI_NETWORK) {
  1583.         if (!(ini_section & INI_GENERAL)) {
  1584.           output("\n ■ [GENERAL] tag missing from NET.INI!");
  1585.           ok = 0;
  1586.         }
  1587.       } else {
  1588.         ok = 0;
  1589.         output("\n ■ [FILENET] tag missing from NET.INI!");
  1590.       }
  1591.     } else {
  1592.       output("\n ■ %s NET.INI!", strings[1]);
  1593.       ok = 0;
  1594.     }
  1595.   }
  1596.  
  1597.   if (ok)
  1598.     if (create_contact_ppp())
  1599.       ok = 0;
  1600.  
  1601.   if (ok) {
  1602.     output("\n ■ Memory available : %ld bytes -", coreleft());
  1603.     if (net_data[1] == ':')
  1604.       i = net_data[0];
  1605.     else
  1606.       i = maindir[0];
  1607.     i = toupper(i) - 'A' + 1;
  1608.     _dos_getdiskfree(i, &df);
  1609.     dspace = (long)df.avail_clusters * (long)df.bytes_per_sector *
  1610.             (long)df.sectors_per_cluster;
  1611.     if (dspace < 1024000L) {
  1612.       output("\n ■ Only %luK available on drive %c:... aborting!",
  1613.               dspace, i + '@');
  1614.       do_exit(EXIT_FAILURE);
  1615.     } else
  1616.       output(" Disk space : %c:%luM", i + '@', (dspace/1024000L));
  1617.  
  1618.     set_net_num(netnum);
  1619.     ss = argv[1];
  1620.     sy = atoi(&ss[2]);
  1621.     destaddr[0] = 0;
  1622.     if (sy != 32767)
  1623.       good_addr(destaddr, sy);
  1624.  
  1625.     if ((destaddr[0] == 0) && (sy != 32767)) {
  1626.       output("\n ■ Using direct dial for @%hd.%s\n\n", sy, net_name);
  1627.       ok = 0;
  1628.     } else {
  1629.       ok = 1;
  1630.       if (sy == 32767) {
  1631.         if (ini_section & INI_NEWS)
  1632.           output("\n ■ Initiating newsgroup session...");
  1633.         else {
  1634.           output("\n ■ [NEWS] missing from NET.INI!");
  1635.           do_exit(EXIT_FAILURE);
  1636.         }
  1637.       }
  1638.     }
  1639.   }
  1640.   if (ok) {
  1641.     if (!MOREINFO)
  1642.       freopen(NULL, "w", stdout);
  1643.     if (CLEANUP)
  1644.       process_mail();
  1645.     set_net_num(netnum);
  1646.     sprintf(s, "%sSPOOL", net_data);
  1647.     if ((make_path(s)) < 0) {
  1648.       output("\n ■ %s \"%s\"", strings[0], s);
  1649.       do_exit(EXIT_FAILURE);
  1650.     }
  1651.     sprintf(s, "%sMQUEUE", net_data);
  1652.     if ((make_path(s)) < 0) {
  1653.       output("\n ■ %s \"%s\"", strings[0], s);
  1654.       do_exit(EXIT_FAILURE);
  1655.     }
  1656.     sprintf(s, "%sOUTBOUND", net_data);
  1657.     if ((make_path(s)) < 0) {
  1658.       output("\n ■ %s \"%s\"", strings[0], s);
  1659.       do_exit(EXIT_FAILURE);
  1660.     }
  1661.     sprintf(s, "%sINBOUND", net_data);
  1662.     if ((make_path(s)) < 0) {
  1663.       output("\n ■ %s \"%s\"", strings[0], s);
  1664.       do_exit(EXIT_FAILURE);
  1665.     }
  1666.     sprintf(s, "%sSENT", net_data);
  1667.     if ((make_path(s)) < 0) {
  1668.       output("\n ■ %s \"%s\"", strings[0], s);
  1669.       do_exit(EXIT_FAILURE);
  1670.     }
  1671.     if (PURGE) {
  1672.       if ((KEEPSENT) && (sy != 32767)) {
  1673.         output("\n ■ Purging sent packets older than %d day%s...", KEEPSENT,
  1674.                 KEEPSENT == 1 ? "" : "s");
  1675.         i = purge_sent();
  1676.         output(" %d packet%s deleted.", i, i == 1 ? "" : "s");
  1677.       }
  1678.     }
  1679.     sprintf(s, "%sCHECKNET", net_data);
  1680.     if ((make_path(s)) < 0) {
  1681.       output("\n ■ %s \"%s\"", strings[0], s);
  1682.       do_exit(EXIT_FAILURE);
  1683.     }
  1684.     send = 1;
  1685.  
  1686.     cd_to(maindir);
  1687.     sprintf(s, "%s\\EXP.EXE", maindir);
  1688.     if (!exist(s)) {
  1689.       output("\n ■ EXP.EXE not found!");
  1690.     } else {
  1691.       sprintf(s, "%sS32767.NET", net_data);
  1692.       sprintf(s1, "%sSPOOL\\UNK*.*", net_data);
  1693.       if ((exist(s)) || (exist(s1))) {
  1694.         sprintf(s, "EXP.EXE S32767.NET %s %hu %s %s %s",
  1695.                 net_data, net_sysnum, FWDNAME, FWDDOM, net_name);
  1696.         if (do_spawn(s))
  1697.           output("\n ■ %s during export.", strings[2]);
  1698.       } else {
  1699.         if (MOREINFO)
  1700.           output("\n ■ No Internet mail or newsgroup articles to export.");
  1701.       }
  1702.     }
  1703.  
  1704.     cd_to(maindir);
  1705.     if ((sy != 32767) || (ONECALL)) {
  1706.       output("\n ■ Preparing outbound packets...");
  1707.       if (!uu_packets()) {
  1708.         sprintf(s, "%sMQUEUE\\*.*", net_data);
  1709.         if (findfirst(s, &ff, 0) == 0) {
  1710.           output(" already in MQUEUE to be sent.");
  1711.         } else {
  1712.           output(" no mail or packets to send.");
  1713.           send = 0;
  1714.         }
  1715.       } else {
  1716.         backline();
  1717.         output(" ■ All packets prepared for transfer.");
  1718.       }
  1719.     }
  1720.     sprintf(s, "%sNET%d.CFG", net_data, instance);
  1721.     if (exist(s)) {
  1722.       sprintf(s1, "%s\\NET.CFG", maindir);
  1723.       unlink(s1);
  1724.       if (!copyfile(s, s1))
  1725.         output("\n ■ %s %s from %s.", strings[0], s1, s);
  1726.     }
  1727.  
  1728.     starttime = clock();
  1729.     sentbytes = recdbytes = snewsbytes = rnewsbytes = 0L;
  1730.  
  1731.     cd_to(maindir);
  1732.  
  1733. #ifndef PACKET
  1734.     klos_ppp();
  1735. #endif
  1736.  
  1737.     sprintf(temp_dir, "%sINBOUND\\", net_data);
  1738.  
  1739.     ok = 0;
  1740.     if ((send) && ((sy != 32767) || (ONECALL))) {
  1741.       totf = 0;
  1742.       sentbytes = 0L;
  1743.       sprintf(temp, "%sMQUEUE\\*.*", net_data);
  1744.       f1 = findfirst(temp, &ff, FA_ARCH);
  1745.       while (f1 == 0) {
  1746.         ok = 1;
  1747.         ++totf;
  1748.         sentbytes += ff.ff_fsize;
  1749.         f1 = findnext(&ff);
  1750.       }
  1751.       sprintf(s1, "%sMQUEUE\\", net_data);
  1752.       sprintf(s, "%s\\POP -send %s %s %s %d", maindir, SMTPHOST, DOMAIN, s1, MOREINFO);
  1753.       do_spawn(s);
  1754.       f1 = findfirst(temp, &ff, FA_ARCH);
  1755.       while (f1 == 0) {
  1756.         --totf;
  1757.         sentbytes -= ff.ff_fsize;
  1758.         f1 = findnext(&ff);
  1759.       }
  1760.       if (ok) {
  1761.         backline();
  1762.         output(" ■ Outbound mail transfer completed : %d message%s (%ldK).",
  1763.               totf, totf == 1 ? "" : "s", ((sentbytes + 1023) / 1024));
  1764.       }
  1765.     }
  1766.     if ((sy != 32767) || (ONECALL)) {
  1767.       sprintf(s, "%s\\POP -receive %s %s %s %s %d %s %d", maindir, POPHOST, POPNAME, POPPASS,
  1768.               temp_dir, ALLMAIL, DOMAIN, MOREINFO);
  1769.       output("\n ■ Checking %s for mail... ", POPHOST);
  1770.       sprintf(s1, "%s*.*", temp_dir);
  1771.       if ((do_spawn(s) == EXIT_SUCCESS) || (exist(s1))) {
  1772.         sprintf(temp, "%s*.*", temp_dir);
  1773.         f1 = findfirst(temp, &ff, FA_ARCH);
  1774.         i = 0;
  1775.         while (f1 == 0) {
  1776.           if ((strncmp(ff.ff_name, "BAD", 3) != 0) && (strncmp(ff.ff_name, "SPM", 3) != 0) &&
  1777.                 (ff.ff_fsize)) {
  1778.             recdbytes += ff.ff_fsize;
  1779.             sprintf(s1, "%s%s", temp_dir, ff.ff_name);
  1780.             sprintf(temp, "%s\\UU.EXE -decode %s %s %s", maindir, ff.ff_name,
  1781.                     temp_dir, net_data);
  1782.             if (!do_spawn(temp))
  1783.               unlink(s1);
  1784.           }
  1785.           f1 = findnext(&ff);
  1786.         }
  1787.       } else
  1788.         output("\n ■ No network packets to process");
  1789.  
  1790.     }
  1791.     sprintf(s, "%sSPOOL\\UNK*.*", net_data);
  1792.     if (exist(s)) {
  1793.       sprintf(s, "EXP.EXE S32767.NET %s %hu %s %s %s",
  1794.               net_data, net_sysnum, FWDNAME, FWDDOM, net_name);
  1795.       if (do_spawn(s))
  1796.         output("\n ■ %s during export", strings[2]);
  1797.     }
  1798.     mailtime = clock() - starttime;
  1799.     if ((sy == 32767) || (ONECALL)) {
  1800.       news = 1;
  1801.       starttime = clock();
  1802.       set_net_num(netnum);
  1803.       sprintf(temp, "%sOUTBOUND\\*.*", net_data);
  1804.       f1 = findfirst(temp, &ff, FA_ARCH);
  1805.       while (f1 == 0) {
  1806.         snewsbytes += ff.ff_fsize;
  1807.         f1 = findnext(&ff);
  1808.       }
  1809.       cd_to(maindir);
  1810.       strcpy(s1, net_data);
  1811.       if (LAST(s1) == '\\')
  1812.         LAST(s1) = 0;
  1813.       sprintf(s, "%s\\NEWS.EXE %s %s %hu", maindir, s1, NEWSHOST, net_sysnum);
  1814.       ok = 1;
  1815.       do_spawn(s);
  1816.       set_net_num(netnum);
  1817.       sprintf(temp, "%sP0*.*", net_data);
  1818.       f1 = findfirst(temp, &ff, 0);
  1819.       while (f1 == 0) {
  1820.         rnewsbytes += ff.ff_fsize;
  1821.         f1 = findnext(&ff);
  1822.       }
  1823.     }
  1824.   } else {
  1825.     output("\n");
  1826.     set_net_num(netnum);
  1827.     strcpy(s, "NETWORK0.EXE");
  1828.     for (i = 1; i < argc; i++) {
  1829.       strcat(s, " ");
  1830.       strcat(s, argv[i]);
  1831.     }
  1832.     s[strlen(s) + 1] = '\0';
  1833.     do_it(s);
  1834.     exit(EXIT_SUCCESS);
  1835.   }
  1836.  
  1837.   sprintf(s1, "%s\\NTIME.EXE", maindir);
  1838.   if ((exist(s1)) && (*TIMEHOST)) {
  1839.     output("\n ■ Checking %s...  ", TIMEHOST);
  1840.     sprintf(s, "%s %s", s1, TIMEHOST);
  1841.     do_spawn(s);
  1842.   }
  1843.  
  1844. #ifndef PACKET
  1845.   unload_klos();
  1846. #endif
  1847.  
  1848.   output("\n ■ Updating network connection records...");
  1849.  
  1850.   if ((sy != 32767) || ((sy == 32767) && (ONECALL))) {
  1851.     recdbytes = ((recdbytes + 1023) / 1024);
  1852.     sentbytes = ((sentbytes + 1023) / 1024);
  1853.     if (mailtime)
  1854.       sprintf(ttotal, "%3.1f", (mailtime / CLK_TCK / 60));
  1855.     else
  1856.       strcpy(ttotal, "0.1");
  1857.     if (update_contacts(sy, sentbytes, recdbytes))
  1858.       output("\n ■ %s", strings[3]);
  1859.     if (write_netlog(sy, sentbytes, recdbytes, ttotal))
  1860.       output("\n ■ %s", strings[4]);
  1861.   }
  1862.  
  1863.   if (news) {
  1864.     if ((newstime = clock()) == (clock_t) -1)
  1865.       output("\n ■ NEWS time invalid.");
  1866.     else {
  1867.       newstime -= starttime;
  1868.       if (newstime)
  1869.         sprintf(ttotal, "%3.1f", (newstime / CLK_TCK / 60));
  1870.       else
  1871.         strcpy(ttotal, "0.1");
  1872.       rnewsbytes = ((rnewsbytes + 1023) / 1024);
  1873.       if (rnewsbytes > 9999L)
  1874.         rnewsbytes = 9999L;
  1875.       snewsbytes = ((snewsbytes + 1023) / 1024);
  1876.       if (update_contact(32767, snewsbytes, rnewsbytes))
  1877.         output("\n ■ %s", strings[3]);
  1878.       if (write_netlog(32767, snewsbytes, rnewsbytes, ttotal))
  1879.         output("\n ■ %s", strings[4]);
  1880.     }
  1881.   }
  1882.  
  1883.   if (CLEANUP) {
  1884.     process_mail();
  1885.     set_net_num(netnum);
  1886.     process_bbsdata();
  1887.   }
  1888.   cd_to(maindir);
  1889.   set_net_num(netnum);
  1890.   output("\n ■ %s completed!\n\n", version);
  1891.   stack_count();
  1892.   return 0;
  1893. }
  1894.