home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / BBSING / RBBS / RBBS4102.ARK / RBBS4.C < prev    next >
Text File  |  1985-02-09  |  7KB  |  351 lines

  1. /****************************************************************
  2. * RBBS4.C                             *
  3.  
  4. Release 7: RBBS 4.1 Edit 02 - Added test for % MFLAG to disallow
  5.                   E and K commands for such users.
  6. Release 6: RBBS 4.1 Edit 01 - Allow "personal" messages everywhere
  7.                 - Added non-display of summary if already
  8.                   seen a msgfile once
  9.                 - Bypass choice list if typeahead
  10.                 - Added N command to simulate entry of "R;#+"
  11. Release 5: RBBS 4.1 Edit 00 - Names now one large field
  12.                 - Activated lstmsg for 1st 7 non-PERSONALs
  13.                 - Inserted PERSONLY conditional
  14. Release 4: RBBS 4.0 Edit 21 - if no PERSONAL msgs waiting, selects GENERAL
  15. Release 1: RBBS 4.0 Edit 18
  16.  
  17. First C version of RBBS, inspired by RBBS31
  18.  
  19. Originally designed and written by John C. Gilbert.
  20. Additional coding (mainly RBBSCIO.C) by Frank J. Wancho.
  21.  
  22. Principal Beta testing and numerous suggestions by Sigi Kluger,
  23. with additional testing and help from David Schmidt and Ron
  24. Fowler and others.
  25.  
  26. This program was originally designed to support a
  27. restricted-access, multi-user TurboDOS RCP/M system.
  28.  
  29. This source is herewith released into the public domain with the
  30. understanding that bug reports and revisions be submitted to the
  31. LAZARUS RCP/M (915-544-1432) or via DDN to WANCHO@SIMTEL20.
  32.  
  33. (See any DRI license agreement for any other disclaimers that may apply
  34. to this program.)
  35.  
  36. * Functions included in this file:
  37.  
  38. * main        calls logon, loguser, select_MSG, and maindispatch
  39.  
  40. * compuser    called by checkmsgs to check if current msg is
  41.         for this user
  42.  
  43. * maindispatch    main command dispatcher
  44.  
  45. * select_MSG    called by main and by maindispatch if F command.
  46.         Offers subject files for selection and calls
  47.                 checkmsgs
  48.  
  49. * checkmsgs    loops thru current message file, calling compuser
  50.                 on each entry.
  51.  
  52. ****************************************************************/
  53. #include    <bdscio.h>
  54. #include    "rbbs4.h"
  55.  
  56.     int    privct;
  57.     int    fflags[15];
  58.  
  59. main()
  60. {
  61.     int    userfd,msgfd;
  62.     char    rflg;
  63.     struct    _sum    s;
  64.     struct    _user    u;
  65.  
  66.     setmem(fflags,15,FALSE);
  67.     outstr(VERSION,1);
  68.     belflg = FALSE;
  69.     expert = FALSE;
  70.     rtnok = FALSE;
  71.     poke(0,0xcd);        /* Change JMP at 0 to CALL        */
  72.     rflg = peek(0x5d);    /* Get first char of command line    */
  73.     poke(0x5d,0x20);    /* Clear that first char        */
  74.     if ( (rflg == 'P') && (peek(0x5b) == 'x') )
  75.         rtnok = TRUE;    /* Set flag if a rerun            */
  76.     poke(0x5b,0x78);    /* Set flag loc for possible return    */
  77.     if (!rtnok)
  78.         bulletins();
  79.     userfd = openfile(DSK(USERS.CCC));
  80. #if    !DATETIME
  81.     get_date();
  82.     strcpy(logdate,sysdate);
  83. #endif
  84.     logon(userfd,u);
  85.     loguser(u);
  86.     crlf(1);
  87.     setptr(m,lp);
  88.     fileflag = FALSE;
  89.     msgfd = select_MSG(msgfd,1,u,s);    /* Select PERSONAL    */
  90. #if    !PERSONLY
  91.     if (!privct)                /* if none,        */
  92.     {
  93.         fileflag = TRUE;
  94.         msgfd = select_MSG(msgfd,2,u,s);/* select GENERAL    */
  95.     }
  96. #endif
  97.     maindispatch(msgfd,userfd,u,s);
  98. }
  99. /***************************************************************/
  100. compuser(ct,u,s)
  101. int    ct;
  102. struct    _user    *u;
  103. struct    _sum    *s;
  104. {
  105.     capstr(s->tnm);
  106.     if ( !strcmp(u->nm,s->tnm) || (sysop  && !strcmp("SYSOP",s->tnm)) )
  107.     {
  108.         if(!ct)
  109.         {
  110.             outstr("YOU HAVE MAIL:",1);
  111.             crlf(1);
  112.         }
  113.         dispsum(s);
  114.         return ++ct;
  115.     }
  116.     else    return ct;
  117. }
  118. /***************************************************************/
  119. maindispatch(fd,ufd,u,s)
  120. int    fd,ufd;
  121. struct    _user    *u;
  122. struct    _sum    *s;
  123. {
  124.     int    cmd;
  125.     char    cmd2[2];
  126.  
  127.     cmd = FALSE;
  128.     while(TRUE)
  129.     {
  130.         while(cmd)
  131.         {
  132.             switch(cmd)
  133.             {
  134.                 case 'E':
  135.                     if (*u->ustat == '%')
  136.                         break;
  137.                     entermsg(fd,ufd,u,s,FALSE);
  138.                     break;
  139.  
  140.                 case 'R':
  141.                     readmsgs(fd,u,s);
  142.                     break;
  143.  
  144.                 case 'S':
  145.                     summsgs(fd,u,s);
  146.                     break;
  147.  
  148.                 case 'K':
  149.                     if (*u->ustat == '%')
  150.                         break;
  151.                     killmsg(fd,u,s);
  152.                     break;
  153.  
  154.                 case 'G':
  155.                     fd = goodbye(fd,ufd,u,s);
  156.                     break;
  157.  
  158.                 case 'W':
  159.                     welcome();
  160.                     break;
  161.  
  162.                 case 'C':
  163.                     fd = gocpm(fd,ufd,u,s);
  164.                     break;
  165.  
  166. #if    !PERSONLY
  167.                 case 'F':
  168.                     if (close(fd) == ERROR)
  169.                         ioerr("Closing MSG");
  170.                     fileflag = TRUE;
  171.                     fd = select_MSG(fd,0,u,s);
  172.                     break;
  173. #endif
  174.  
  175.                 case 'U':
  176. #if    NOUCMD
  177.                     if (!sysop)
  178.                         break;
  179. #endif
  180.                     crlf(1);
  181.                     showuser(ufd,u);
  182.                     break;
  183.  
  184.                 case 'T':
  185.                     belflg = !belflg;
  186.                     break;
  187.  
  188.                 case 'X':
  189.                     expert = !expert;
  190.                     break;
  191.  
  192.                 case 'B':
  193.                     bulletins();
  194.                     break;
  195.  
  196.                 case 'P':
  197.                     chgpasswd(u,ufd);
  198.                     break;
  199.  
  200.                 case 'M':
  201.                     msg_info(msgct,TRUE);
  202. #if    !PERSONLY
  203.                     himsg(u);
  204. #endif
  205. #if    DATETIME
  206.                     crlf(1);
  207.                     tos();
  208. #endif
  209.                     break;
  210.  
  211.                 case 'N':
  212.                     strcpy(sav,"#+");
  213.                     readmsgs(fd,u,s);
  214.                     break;
  215.  
  216.                 case '?':
  217.                     help();
  218.                     break;
  219.  
  220.                 default:
  221.                     if(sysop)
  222.                     {
  223.                         crlf(1);
  224.                         lstuser();
  225.                     }
  226.                     break;
  227.             }
  228.             cmd = FALSE;
  229.         }
  230.         strcpy(tmpstr,"COMMAND: ");
  231.         if (!expert)
  232.         {
  233.             strcat(tmpstr,"C,E,");
  234. #if    !PERSONLY
  235.             strcat(tmpstr,"F,");
  236. #endif
  237.             strcat(tmpstr,"G,K,R,S,N,b,m,p,t,");
  238. #if    NOUCMD
  239.             strcat(tmpstr,"w,x (or ? for help): ");
  240. #else
  241.             strcat(tmpstr,"u,w,x (or ? for help): ");
  242. #endif
  243.         }
  244.         outstr(tmpstr,4);
  245.         instr("",cmd2,1);
  246.         cmd = toupper(*cmd2);
  247.         crlf(1);
  248.     }
  249. }
  250. /****************************************************************/
  251. select_MSG(msgfd,choice,u,s)
  252. int    msgfd,choice;
  253. struct    _user    *u;
  254. struct    _sum    *s;
  255. {
  256.     int    fd,n;
  257.     char    input[3];
  258.     char    rec[SECSIZ];
  259.     int    pflag;
  260.  
  261. #if    !PERSONLY
  262.     fd = openfile(DSK(SUBJECTS.CCC));
  263.     if (readrec(fd,0,rec,1) == ERROR)
  264.         ioerr("reading subject");
  265.     sscanf(rec,"%d",&n);
  266.     while ( (!choice) || (choice > n) )
  267.     {
  268.         if (!*sav)
  269.         {
  270.             outstr("Subjects are:",2);
  271.             displ_subj(fd,n,rec);
  272.         }
  273.         outstr("File number: ",4);
  274.         instr("",input,3);
  275.         crlf(1);
  276.         choice = atoi(input);
  277.     }
  278.     close(fd);    
  279.     if ( choice > 8)
  280.         cchoice = 0;
  281.     else
  282.         cchoice = choice - 1;
  283.     setmem(cmsgfile,9,0);
  284.     movmem(rec+8*choice,cmsgfile,8);
  285. #else
  286.     cchoice = 0;
  287.     strcpy(cmsgfile,"PERSONAL");
  288. #endif
  289.     sprintf(msgfile,"%s%s%s",DRIVE,capstr(cmsgfile),".MSG");
  290.     msgct = load_cntrl(msgct,s);
  291.     pflag = TRUE;
  292.     if ( fflags[choice])
  293.         pflag = FALSE;
  294.     msg_info(msgct,pflag);
  295.     msgfd = openfile(msgfile);
  296.     personal = !strcmp(cmsgfile,"PERSONAL");
  297.     if ( actmsg && !fflags[choice])
  298.     {
  299.         sprintf(tmpstr,"Checking the %s Messages File...",cmsgfile);
  300.         outstr(tmpstr,3);
  301.         checkmsgs(msgfd,u,s);
  302.     }
  303.     fflags[choice] = TRUE;
  304. #if    !PERSONLY
  305.     himsg(u);
  306. #endif
  307.     return msgfd;
  308. }
  309. /***************************************************************/
  310. #if    !PERSONLY
  311. himsg(u)
  312. struct    _user    *u;
  313. {
  314.     if (cchoice)
  315.     {
  316. sprintf(tmpstr,"Highest message number seen in this file is %d.",u->lstmsg[cchoice-1]);
  317.         outstr(tmpstr,2);
  318.     }
  319. }
  320. #endif
  321. /***************************************************************/
  322. checkmsgs(fd,u,s)
  323. int    fd;
  324. struct    _user    *u;
  325. struct     _sum    *s;
  326. {
  327.     int    i;
  328.  
  329.     privct = 0;
  330.     for ( i = 1; i <= msgct; i++)
  331.     {
  332.         if (mno[i])
  333.         {
  334.             readsum(fd,mndx[i],s);
  335.             privct = compuser(privct,u,s);
  336.         }
  337.     }
  338.     if (privct)
  339.     {
  340.         outstr("PLEASE READ AND KILL ",3);
  341.         sprintf(tmpstr,"TH%s MESSAGE%s",(privct==1)?"IS":"ESE",(privct==1)?".":"S.");
  342.         outstr(tmpstr,1);
  343.     }
  344.     else
  345.         outstr("No new mail for you.",1);
  346. }
  347. /***************************************************************/
  348. ice])
  349.     {
  350.         sprintf(tmpstr,"Checking the %s Messages File...",cmsgfile);
  351.         outstr(tm