home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / W / DEVBBS.ZIP / LILO.C < prev    next >
Text File  |  1992-08-15  |  13KB  |  539 lines

  1. /*****************************************************************************
  2.  
  3.                 WWIV Version 4
  4.                     Copyright (C) 1988-1991 by Wayne Bell
  5.  
  6. *****************************************************************************/
  7.  
  8. #include "vars.h"
  9. #pragma hdrstop
  10.  
  11. int check_ansi()
  12. {
  13.   long l;
  14.   char ch;
  15.  
  16.   while (comhit())
  17.     get1c();
  18.   pr1("\x1b[6n");
  19.   l=timer1()+36;
  20.   if (modem_flag & flag_ec)
  21.     l += 18;
  22.   while ((timer1()<l) && (!hangup)) {
  23.     checkhangup();
  24.     ch=get1c();
  25.     if (ch=='\x1b')
  26.       return(1);
  27.     if (ch=='N')
  28.       return(-1);
  29.   }
  30.   return(0);
  31. }
  32.  
  33. void getuser()
  34. {
  35.   char s[81],s2[81],s3[81],*ss;
  36.   int ok,count,net_only,ans;
  37.   long l;
  38.   FILE *f;
  39.  
  40.   thisuser.sysstatus &= (~sysstatus_ansi);
  41.   net_only=1;
  42.   if (syscfg.netlowtime!= syscfg.nethightime) {
  43.     if (syscfg.nethightime>syscfg.netlowtime) {
  44.       if ((timer()<=(syscfg.netlowtime*60.0)) || (timer()>=(syscfg.nethightime*60.0)))
  45.         net_only=0;
  46.     } else {
  47.       if ((timer()<=(syscfg.netlowtime*60.0)) && (timer()>=(syscfg.nethightime*60.0)))
  48.         net_only=0;
  49.     }
  50.   } else
  51.     net_only=0;
  52.   count=0;
  53.   ok=0;
  54.   checkit=1;
  55.   okmacro=0;
  56.   actsl=syscfg.newusersl;
  57.   if ((!net_only) && (incom)) {
  58.     sprintf(s,"%sWELCOME.ANS",syscfg.gfilesdir);
  59.     if (exist(s)) {
  60.       nl();
  61. #ifdef OLD
  62.       outstr("Can you support ANSI graphics? ");
  63.       thisuser.sysstatus=0;
  64.       ans=yn();
  65. #else
  66.       ans=check_ansi();
  67. #endif
  68.       if (ans>0)
  69.         printfile("welcome.ans");
  70.       else if (ans==0)
  71.     printfile("welcome.msg");
  72.     } else
  73.       printfile("welcome.msg");
  74.   }
  75.   makeansi(0x07, s, 1);
  76.   outs(s);
  77.   do {
  78.     nl();
  79.     if (net_only) {
  80.       pl("This time is reserved for net-mail ONLY.");
  81.       pl("Please try calling back again later.");
  82.     } else
  83.       pl("Enter number or name or 'NEW'");
  84.     outstr("NN: "); /* DON'T change the NN: prompt. */
  85.     input(s,30);
  86.     usernum=finduser(s);
  87.     if ((net_only) && (usernum!=-2))
  88.       usernum=0;
  89.     if (usernum>0) {
  90.       read_user(usernum,&thisuser);
  91.       actsl = syscfg.newusersl;
  92.       topscreen();
  93.       ok=1;
  94.       outstr("1PW7: ");
  95.       echo=0;
  96.       input(s,8);
  97.       if (strcmp(s,thisuser.pw)!=0)
  98.         ok=0;
  99.       if ((syscfg.sysconfig & sysconfig_free_phone)==0) {
  100.     outstr("1PH7: e■■■-■■■-");
  101.     echo=0;
  102.     input(s2,4);
  103.     if (strcmp(s2,&thisuser.phone[8])!=0) {
  104.       ok=0;
  105.       if ((strlen(s2)==4) && (s2[3]=='-')) {
  106.         nl();
  107.         pl("6!! Enter the LAST 4 DIGITS of your phone number ONLY !!");
  108.         nl();
  109.           }
  110.         }
  111.       }
  112.       if ((thisuser.sl==255) && (incom) && (ok)) {
  113.     outstr("6SY: ");
  114.         echo=0;
  115.         input(s,20);
  116.         if (strcmp(s,syscfg.systempw)!=0)
  117.           ok=0;
  118.       }
  119.       echo=1;
  120.       if (ok) {
  121.         reset_act_sl();
  122.         changedsl();
  123.       } else {
  124.         ++thisuser.illegal;
  125.         write_user(usernum,&thisuser);
  126.         close_user();
  127.         nl();
  128.         pl("\7ILLEGAL LOGON\7");
  129.         nl();
  130.         sprintf(s3,"### ILLEGAL LOGON for %s (%s) (PW=%s)",
  131.                 nam(&thisuser,usernum),
  132.                 ctim(timer()),
  133.                 s);
  134.         sl1(0,s3);
  135.     usernum=0;
  136.       }
  137.     } else
  138.       if (usernum==-1) {
  139.         newuser();
  140.         ok=1;
  141.       } else
  142.         if (usernum==0) {
  143.       if (net_only)
  144.         nl();
  145.       else
  146.         pl("6Unknown user.");
  147.     } else
  148.       if ((usernum==-2) || (usernum==-3) || (usernum==-4)) {
  149.         if (incom) {
  150.           save_status();
  151.           time(&l);
  152.           s2[0]=0;
  153.           switch(usernum) {
  154.         case -2:
  155.           sprintf(s2,"NETWORK /B%u /T%ld /F%u",modem_speed,l,modem_flag);
  156.           run_external1(s2);
  157.           break;
  158.         case -3:
  159.           sprintf(s2,"REMOTE /B%u /F%u",modem_speed,modem_flag);
  160.           run_external1(s2);
  161.           break;
  162.         case -4:
  163.           s[8]=0;
  164.           if (s[0]) {
  165.             sprintf(s2,"%s /B%u /F%u",s,modem_speed,modem_flag);
  166.             sprintf(s3,"%sREMOTES.DAT",syscfg.datadir);
  167.             f=fopen(s3,"r");
  168.             if (f) {
  169.               ok=0;
  170.               while ((!ok) && (fgets(s3,80,f))) {
  171.             ss=strchr(s3,'\n');
  172.             if (ss)
  173.               *ss=0;
  174.             if (stricmp(s3,s)==0)
  175.               ok=1;
  176.               }
  177.               fclose(f);
  178.               if (ok) {
  179.             run_external1(s2);
  180.               }
  181.             }
  182.           }
  183.           break;
  184.           }
  185.           get_status();
  186.           hangup=1;
  187.           dtr(0);
  188.           global_xx=0;
  189.           wait(1.0);
  190.           dtr(1);
  191.           wait(0.1);
  192.           cleanup_net();
  193.               imodem(0);
  194.         }
  195.         hangup=1;
  196.           }
  197.  
  198.   } while ((!hangup) && (!ok) && (++count<3));
  199.   if (count==3)
  200.     hangup=1;
  201.   checkit=0;
  202.   okmacro=1;
  203.   if ((!hangup) && (usernum>0) && (thisuser.restrict & restrict_logon) &&
  204.     (strcmp(date(),thisuser.laston)==0) && (thisuser.ontoday>0)) {
  205.     nl();
  206.     pl("1Sorry, you can only logon once per day.");
  207.     nl();
  208.     hangup=1;
  209.   }
  210. }
  211.  
  212. void logon()
  213. {
  214.   char s[255],s1[81],s2[81],*ss;
  215.   int i,i1,f;
  216.   long len,pos;
  217.   char s3[31],l[4][81];
  218.  
  219.   if (usernum<1) {
  220.     hangup=1;
  221.     return;
  222.   }
  223.  
  224.   if (live_user) {
  225.     ansic(0);
  226.     outchr(12);
  227.   }
  228.   if (strcmp(date(),status.date1)!=0) {
  229.     if (live_user) {
  230.       nl();
  231.       pl("6Now doing daily maintenance.");
  232.       nl();
  233.     }
  234.     beginday();
  235.   }
  236.   if (incom && live_user) {
  237.     i=printfile("LOGON");
  238.     if ((!i) && (!(thisuser.sysstatus & sysstatus_pause_on_page)))
  239.       pausescr();
  240.   }
  241.  
  242.   strcpy(xdate,date());
  243.   if (strcmp(xdate,thisuser.laston)==0)
  244.     ++thisuser.ontoday;
  245.   else {
  246.     thisuser.ontoday=1;
  247.     thisuser.timeontoday=0.0;
  248.     thisuser.extratime=0.0;
  249.     thisuser.posttoday=0;
  250.     thisuser.etoday=0;
  251.     thisuser.fsenttoday1=0;
  252.   }
  253.   ++thisuser.logons;
  254.   cursub=0;
  255.   msgreadlogon=0;
  256.   if (udir[0].subnum==0)
  257.     curdir=1;
  258.   else
  259.     curdir=0;
  260.   curdloads=0;
  261.   if (actsl!=255) {
  262.     ++status.callernum1;
  263.     ++status.callstoday;
  264.   }
  265.   sprintf(s,"%ld: %s %s %s   %s - %d",
  266.        status.callernum1,
  267.        nam(&thisuser,usernum),
  268.        times(),
  269.        date(),
  270.        curspeed,
  271.        thisuser.ontoday);
  272.  
  273.   sprintf(s2,"%sLASTON.TXT",syscfg.gfilesdir);
  274.   ss=get_file(s2,&len);
  275.   pos=0;
  276.   if (ss!=NULL) {
  277.     if (!cs())
  278.       for (i=0; i<4; i++)
  279.     copy_line(s1,ss,&pos,len);
  280.     i=1;
  281.     do {
  282.       copy_line(s1,ss,&pos,len);
  283.       if ((s1[0]) && live_user) {
  284.     if (i) {
  285.       i=0;
  286.       nl();
  287.       nl();
  288.       pl("7Last few callers: ");
  289.       nl();
  290.     }
  291.     pl(s1);
  292.       }
  293.     } while (pos<len);
  294.   }
  295.   if ((actsl!=255) || (incom)) {
  296.     sl1(0,"");
  297.     sl1(0,s);
  298.     sl1(1,"");
  299.     sprintf(s,"1%ld > f%-20s   e%-20s   f%s 7- e%d\r\n",
  300.       status.callernum1,
  301.       nam(&thisuser,usernum),
  302.       thisuser.citstate,
  303.       curspeed,
  304.       thisuser.ontoday);
  305.     sprintf(s1,"%sUSER.LOG",syscfg.gfilesdir);
  306.     f=open(s1,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  307.     lseek(f,0L,SEEK_END);
  308.     i=strlen(s);
  309.     if (actsl!=255) {
  310.       write(f,(void *)s,i);
  311.       close(f);
  312.       f=open(s2,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  313.       pos=0;
  314.       copy_line(s1,ss,&pos,len);
  315.       for (i=1; i<8; i++) {
  316.         copy_line(s1,ss,&pos,len);
  317.         strcat(s1,"\r\n");
  318.         write(f,(void *)s1,strlen(s1));
  319.       }
  320.       write(f,(void *)s,strlen(s));
  321.       close(f);
  322.     } else
  323.       close(f);
  324.   }
  325.   if (ss!=NULL)
  326.     farfree(ss);
  327.   if (live_user)
  328.     read_automessage();
  329.   if (live_user)
  330.     read_bbsadd();
  331.   timeon=timer();
  332.   useron=1;
  333.   if (live_user)
  334.     topscreen();
  335.   if ((syscfg.logon_c[0]) && live_user) {
  336.     nl();
  337.     stuff_in(s,syscfg.logon_c,create_chain_file("CHAIN.TXT"),"","","","");
  338.     full_external(s,0,1);
  339.     nl();
  340.     nl();
  341.   }
  342.   if (live_user) {
  343.     nl();
  344.     npr("                  7 Name           6: 1%s\r\n",nam(&thisuser,usernum));
  345.     npr("                  7 Time allowed on6: 1%d\r\n", (int) ((nsl()+30)/60.0));
  346.     npr("                   7Illegal logons 6: 1%d\r\n",thisuser.illegal);
  347.     npr("                   7Mail waiting   6: 1%d\r\n",thisuser.waiting);
  348.     if (thisuser.ontoday==1)
  349.       npr("                   7Last on        6: 1%s\r\n",thisuser.laston);
  350.     else
  351.       npr("                   7Times on today 6: 1%d\r\n",thisuser.ontoday);
  352.     if (sysop2())
  353.       npr("                   7Sysop is       6: 1Watching your every move!\r\n");
  354.     else
  355.       npr("                   7Sysop is       6: 1Out Llama tipping!\r\n");
  356.  
  357.  
  358. /****************************************************************************/
  359. /*
  360.  * Do NOT remove or modify this part of the code.  If the registration number
  361.  * (or an indicator that it is unregistered) is not printed out, it will
  362.  * be plainly obvious that this is a 'pirated' version of the source code.
  363.  */
  364.     if (syscfg.wwiv_reg_number)
  365.       sprintf(s,"(Reg #%ld)",syscfg.wwiv_reg_number);
  366.     else
  367.       strcpy(s,"(Unregistered)");
  368.     sprintf(s1,"                   7System is      6: 1%s   %s",VERSION_NUMBER,s);
  369.     pl(s1);
  370. /****************************************************************************/
  371.     if (syscfg.systemnumber)
  372.       npr("                   7NuclearArms6NET : 1@%u   (net%u)\r\n",syscfg.systemnumber,
  373.     status.net_version);
  374.     nl();
  375.     if (thisuser.forwardusr) {
  376.       if (thisuser.forwardsys) {
  377.         if (!next_system(thisuser.forwardsys)) {
  378.           thisuser.forwardusr=0;
  379.           thisuser.forwardsys=0;
  380.           strcpy(s1,"Forwarded to unknown system; forwarding reset.");
  381.         } else {
  382.           sprintf(s1,"Forwarding mail to #%u @%u.",
  383.               thisuser.forwardusr,thisuser.forwardsys);
  384.         }
  385.       } else {
  386.         sprintf(s1,"Forwarding mail to user #%u.",thisuser.forwardusr);
  387.       }
  388.       pl(s1);
  389.       nl();
  390.     }
  391.     fsenttoday=0;
  392.     if (thisuser.year) {
  393.       s[0]=years_old(thisuser.month,thisuser.day,thisuser.year);
  394.       if (thisuser.age!=s[0]) {
  395.     thisuser.age=s[0];
  396.     topscreen();
  397.       }
  398.     } else {
  399.       nl();
  400.       pl("Please enter the following information:");
  401.       do {
  402.         nl();
  403.         input_age(&thisuser);
  404.         sprintf(s,"%02d/%02d/%02d",(int) thisuser.month,
  405.                                 (int) thisuser.day,
  406.                                 (int) thisuser.year);
  407.         nl();
  408.         npr("Birthdate: %s.  Correct? ",s);
  409.         if (!yn())
  410.           thisuser.year=0;
  411.       } while ((!hangup) && (thisuser.year==0));
  412.       topscreen();
  413.       nl();
  414.     }
  415.     rsm(usernum,&thisuser);
  416.     if (thisuser.waiting) {
  417.       prt(5,"eRead your mail now? ");
  418.       if (ny())
  419.     readmail();
  420.     }
  421.   }
  422.   nscandate=thisuser.daten;
  423.   batchtime=0.0;
  424.   numbatchdl=numbatch=0;
  425.   i1=0;
  426.   for (i=0; i<20; i++) {
  427.     if (questused[i])
  428.       if (thisuser.votes[i]==0)
  429.     i1=1;
  430.   }
  431.   if (restrict_vote & thisuser.restrict)
  432.     i1=0;
  433.   if (actsl<=10)
  434.     i1=0;
  435.   if (i1 && live_user) {
  436.     nl();
  437.     prt(3,"fYou haven't voted yet.");
  438.     nl();
  439.     pausescr();
  440.     vote();
  441.     nl();
  442.     nl();
  443.   }
  444.   save_status();
  445.   create_chain_file("CHAIN.TXT");
  446.   prt(1,"Scan for New Messagese?");
  447.   if (ny())
  448.     nscan(0);
  449. }
  450.  
  451. void logoff()
  452. {
  453.   long l;
  454.   int f,r,w,t,i;
  455.   char s[81];
  456.   mailrec m;
  457.   shortmsgrec sm;
  458.   double ton;
  459.  
  460.   dtr(0);
  461.   hangup=1;
  462.   if (usernum<1)
  463.     return;
  464.   thisuser.lastrate=modem_speed;
  465.   strcpy(thisuser.laston,xdate);
  466.   thisuser.illegal=0;
  467.   if ((timer()-timeon)<-30.0)
  468.     timeon-=24.0*3600.0;
  469.   ton=timer()-timeon;
  470.   thisuser.timeon += ton;
  471.   thisuser.timeontoday += (ton-extratimecall);
  472.   status.activetoday += (int) (ton/60.0);
  473.   save_status();
  474.   time(&l);
  475.   thisuser.daten=l;
  476.   close_user();
  477.   write_user(usernum,&thisuser);
  478.   close_user();
  479.   sprintf(s,"Read: %u   Time on: %u",msgreadlogon,
  480.         (int)((timer()-timeon)/60.0));
  481.   if ((incom) || (actsl!=255))
  482.     sl1(0,s);
  483.   if (mailcheck) {
  484.     sprintf(s,"%sEMAIL.DAT",syscfg.datadir);
  485.     f=open(s,O_BINARY | O_RDWR);
  486.     if (f!=-1) {
  487.       t=(int) (filelength(f)/sizeof(mailrec));
  488.       r=0;
  489.       w=0;
  490.       while (r<t) {
  491.         lseek(f,(long)(sizeof(mailrec)) * (long)(r),SEEK_SET);
  492.         read(f,(void *)&m,sizeof(mailrec));
  493.         if ((m.tosys!=0) || (m.touser!=0)) {
  494.           if (r!=w) {
  495.             lseek(f,(long)(sizeof(mailrec)) * (long)(w),SEEK_SET);
  496.             write(f,(void *)&m,sizeof(mailrec));
  497.           }
  498.           ++w;
  499.         }
  500.         ++r;
  501.       }
  502.       chsize(f,(long)(sizeof(mailrec)) * (long)(w));
  503.       close(f);
  504.     }
  505.   }
  506.   if (smwcheck) {
  507.     sprintf(s,"%sSMW.DAT",syscfg.datadir);
  508.     f=open(s,O_BINARY | O_RDWR);
  509.     if (f!=-1) {
  510.       t=(int) (filelength(f)/sizeof(shortmsgrec));
  511.       r=0;
  512.       w=0;
  513.       while (r<t) {
  514.         lseek(f,(long)(sizeof(shortmsgrec)) * (long)(r),SEEK_SET);
  515.         read(f,(void *)&sm,sizeof(shortmsgrec));
  516.         if ((sm.tosys!=0) || (sm.touser!=0)) {
  517.           if (r!=w) {
  518.             lseek(f,(long)(sizeof(shortmsgrec)) * (long)(w),SEEK_SET);
  519.             write(f,(void *)&sm,sizeof(shortmsgrec));
  520.           }
  521.           ++w;
  522.         }
  523.         ++r;
  524.       }
  525.       chsize(f,(long)(sizeof(shortmsgrec)) * (long)(w));
  526.       close(f);
  527.     }
  528.   }
  529.   remove_from_temp("*.*", syscfg.tempdir, 0);
  530.   remove_from_temp("*.*", syscfg.batchdir, 0);
  531.   if (numbatch && (numbatch != numbatchdl)) {
  532.     for (i=0; i<numbatch; i++) {
  533.       if (!batch[i].sending) {
  534.         didnt_upload(i);
  535.       }
  536.     }
  537.   }
  538. }
  539.