home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / UTIL / WWIVE / LILO.C < prev    next >
Text File  |  1992-06-16  |  14KB  |  586 lines

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