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