home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / BBS / WWMAIL42.ZIP / USERREC.C < prev    next >
Text File  |  1992-08-12  |  10KB  |  276 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <fcntl.h>
  4. #include <string.h>
  5. #include <dos.h>
  6. #include <process.h>
  7. #include <sys\stat.h>
  8. #include <time.h>
  9. #include <ctype.h>
  10. #include <io.h>
  11. #include <conio.h>
  12. #include <dir.h>
  13. #include <alloc.h>
  14.  
  15. #include    "vardec.h"  /* yours */
  16. #include    "userrec.h" /* mine  */
  17.  
  18. extern  configrec     syscfg;         /* holds info from config.dat */
  19. extern  mailu         u,              /* holds mailu */
  20.                       temp;           /* this one changes as program runs */
  21. extern  int           local,          /* flag for local usage */
  22.                       ansi,           /* flag for ansi usage */
  23.                       nowrite,        /* write user files ? */
  24.                       logoff,         /* should the door logoff */
  25.                       batch,          /* batch mode enabled ? */
  26.                       max_subs;       /* either 32 or 64 */
  27.         userrec       user;           /* the DEADLY userrec */
  28.                         
  29. extern void delmail(int);
  30. extern void realmain(int argc, char *argv[]);
  31. extern short cd_to(char *);
  32. extern void print_ansi(char *);
  33. extern void print(int, char *);
  34. extern void carrier_dropped(char *);
  35.  
  36. /* set-up the stack */
  37. unsigned _stklen = 64000;
  38.  
  39. /*===================================================================*/
  40. void numsubs(void)
  41. {
  42.         /* distinguish between 32 and 64 subs for WWIV4.21a+ */
  43.         
  44.         if (syscfg.userreclen == sizeof(userrec))
  45.                 max_subs = MAX_SUBS;
  46.         else
  47.                 max_subs = 32;
  48.  
  49. }
  50. /*===================================================================*/
  51. void convert_to(void)
  52. {
  53.         /* transfers your userrec info into my mailu structure */
  54.         int i;
  55.         
  56.         strcpy(u.name, user.name);
  57.         u.screenlines     = user.screenlines;
  58.         u.sl              = user.sl;
  59.         u.dsl             = user.dsl;
  60.         u.waiting         = user.waiting;
  61.         u.age             = user.age;
  62.         u.ar              = user.ar;
  63.         u.dar             = user.dar;
  64.         u.restrict        = user.restrict;
  65.         u.msgpost         = user.msgpost;
  66.         u.posttoday       = user.posttoday;
  67.         u.daten           = user.daten;
  68.         u.postnet         = user.postnet;
  69.  
  70.         for (i = 0; i < 33; i++)        
  71.                 u.qscnptr[i]  = user.qscnptr[i];
  72.  
  73.         if (max_subs > 32)
  74.                 for (i = 0; i < (max_subs - 32); i++)
  75.                         u.qscnptr2[i] =  user.qscnptr2[i];
  76.  
  77.         /* make copy into change structure */
  78.         temp = u;
  79.  
  80. }
  81. /*===================================================================*/
  82. void convert_from(void)
  83. {
  84.         /* transfers my mailu info to your userrec structure */
  85.         /* BTW: WWIVMail/QWK only updates these fields, so the entire
  86.            userrec doesn't need to be updated */
  87.         int i;
  88.         
  89.         user.waiting         = temp.waiting;
  90.         user.msgpost         = temp.msgpost,
  91.         user.posttoday       = temp.posttoday;
  92.         user.postnet         = temp.postnet;
  93.  
  94.         /* restore original qscn sub tags */
  95.         for (i = 0; i < 33; i++)        
  96.                 user.qscnptr[i]  = temp.qscnptr[i];
  97.         if (max_subs > 32)
  98.                 for (i = 0; i < (max_subs - 32); i++)
  99.                         user.qscnptr2[i] =  temp.qscnptr2[i];
  100.  
  101.         /* put changes into stadard mailu */
  102.         u = temp;
  103. }
  104. /*===================================================================*/
  105. void read_user_info(int *user_num, char *cur_baud, char *com_speed)
  106. {
  107.         /* opens user file and chain.txt to get info for userrec */
  108.  
  109.         long pos;
  110.         int userfile, advance;
  111.         char line[80];
  112.         FILE *chain;
  113.  
  114.         /* local mode */
  115.         if(local){
  116.                 /* local batch mode => ANSI and SYSOP */
  117.                 if (batch) {
  118.                         ansi = 1;
  119.                         *user_num = 1;
  120.                 } else {
  121.                         printf("\n");
  122.                         printf("Please Enter User Number:");
  123.                         gets(line);
  124.                         *user_num = (int)atoi(line);
  125.                         printf("Do You Have Local ANSI ? (Y/N)");
  126.                         gets(line);
  127.                         /* turn on/off ansi graphic output */
  128.                         if(strcmp(strupr(line),"Y") == 0)
  129.                         ansi = 1;
  130.                         else
  131.                         ansi = 0;
  132.                 }
  133.                 strcpy(cur_baud, "KB");
  134.                 strcpy(com_speed, "0");
  135.         /* remote user */
  136.         } else {
  137.                 if (batch) {
  138.                         *user_num = 1;
  139.                         ansi = 1;
  140.                 } else {
  141.                         /* line 1 of chain.txt has user number */
  142.                         chain = fopen("chain.txt", "r");
  143.                         fgets(line,80,chain);
  144.                         *user_num = (int)atoi(line);
  145.                 
  146.                         /* skip on down to ansi support line */
  147.                         for(advance = 1; advance < 14; advance++)
  148.                                 fgets(line, 80, chain);
  149.                         ansi = atoi(line);
  150.  
  151.                         /* skip on down to current baud rate */
  152.                         for(advance = 1; advance < 7; advance++)
  153.                                 fgets(line, 80, chain);
  154.                         strcpy(cur_baud, "");
  155.                         strncat(cur_baud, line, strlen(line) - 1);
  156.  
  157.                         /* skip on down to current com_speed */
  158.                         for(advance = 1; advance < 12; advance++)
  159.                                 fgets(line, 80, chain);
  160.                         strcpy(com_speed, "");
  161.                         strncat(com_speed, line, strlen(line) - 1);
  162.  
  163.                         fclose(chain);
  164.                 }
  165.         }
  166.  
  167.         /* actually open the user file */
  168.         sprintf(line, "%sUSER.LST", syscfg.datadir);
  169.         userfile = open(line, O_RDWR | O_BINARY);
  170.         pos = (syscfg.userreclen * (long)*user_num);
  171.         if (lseek(userfile, pos, SEEK_SET) != -1L) {
  172.                 if (read(userfile, (void *)&user, syscfg.userreclen) > 0) {
  173.                         convert_to();
  174.                 } else
  175.                         *user_num = 0;
  176.         }
  177.  
  178.         /* 0 = fail upon return */
  179.         close(userfile);
  180. }
  181. /*===================================================================*/
  182. void write_user(int user_num, char *main_dir, int clean)
  183. {
  184.         /* Open the user file and update the last read pointers */
  185.  
  186.         int userfile;
  187.         long pos;
  188.         char s[81];
  189.  
  190.         cd_to(main_dir);
  191.  
  192.         /* Deletes E-Mail and Updates Pointers */
  193.         print_ansi(normal);
  194.         if ((nowrite == 0) && clean) {
  195.                 delmail(user_num);
  196.         }
  197.         convert_from();
  198.         sprintf(s,"%sUSER.LST",syscfg.datadir);
  199.         userfile = open(s,O_RDWR | O_BINARY);
  200.         if (userfile > 0) {
  201.                 pos = (syscfg.userreclen * (long)user_num);
  202.                 lseek(userfile, pos, SEEK_SET);
  203.                 if (nowrite == 0)
  204.                         write(userfile, (void *)&user, syscfg.userreclen);
  205.                 close(userfile);
  206.         }
  207.         cd_to(syscfg.tempdir);
  208.         if (logoff)
  209.                 carrier_dropped(main_dir);
  210.  
  211. }
  212. /*===================================================================*/
  213. void user_ssm(int un)
  214. {
  215.         /* tells a user that he/she has one more piece of
  216.            short message to read */
  217.  
  218.         char s[80];
  219.         int userfile;
  220.         unsigned long pos;
  221.         userrec tempuser;
  222.         
  223.         sprintf(s, "%sUSER.LST", syscfg.datadir);
  224.         userfile = open(s, O_RDWR | O_BINARY);
  225.         if (userfile > 0) {
  226.                 pos = (long)(syscfg.userreclen * un);
  227.                 lseek(userfile, pos, SEEK_SET);
  228.                 read(userfile, (void *)&tempuser, syscfg.userreclen);
  229.                 if (nowrite == 0) {
  230.                         lseek(userfile, pos, SEEK_SET);
  231.                         tempuser.sysstatus |= sysstatus_smw;
  232.                         write(userfile, (void *)&tempuser, syscfg.userreclen);
  233.                 }
  234.                 close(userfile);
  235.         }
  236. }
  237. /*===================================================================*/
  238. void user_import(int un, int user_num)
  239. {
  240.         /* tells a user (local) that he/she has one more piece of
  241.            e-mail to read */
  242.            
  243.         char s[80];
  244.         int userfile;
  245.         unsigned long pos;
  246.         userrec tempuser;
  247.         
  248.         sprintf(s, "%sUSER.LST", syscfg.datadir);
  249.         userfile = open(s, O_RDWR | O_BINARY);
  250.         if (userfile > 0) {
  251.                 pos = (long)(syscfg.userreclen * un);
  252.                 lseek(userfile, pos, SEEK_SET);
  253.                 read(userfile, (void *)&tempuser, syscfg.userreclen);
  254.                 lseek(userfile, pos, SEEK_SET);
  255.                 if (nowrite == 0) {
  256.                         tempuser.waiting++;
  257.                         write(userfile, (void *)&tempuser, syscfg.userreclen);
  258.                         if (un == user_num)
  259.                                 temp.waiting++;
  260.                 }
  261.                 close(userfile);
  262.         }
  263. }
  264. /*===================================================================*/
  265. main(int argc, char *argv[])
  266. {
  267.         /* this is a stub for the REAL main() routine. However, since
  268.        you are linking this to my .LIB, you have to have the main()..
  269.        or at least it's easier if you do. */
  270.  
  271.        realmain(argc, argv);
  272. }
  273. /*===================================================================*/
  274.  
  275.  
  276.