home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 276.img / FORUM21S.ZIP / MYLOGIN.PAS < prev    next >
Pascal/Delphi Source File  |  1988-09-27  |  12KB  |  429 lines

  1. {$R-,S-,I-,D-,T-,F-,V-,B-,N-,L+ }
  2. {$M 65500,0,0 }
  3.  
  4. unit getlogin;
  5.  
  6. interface
  7.  
  8. uses crt,
  9.      gentypes,configrt,modem,userret,statret,gensubs,subs1,subs2,windows,
  10.      mailret,textret,overret1,mainr1,mainr2;
  11.  
  12. procedure getloginproc;
  13. procedure returnfromdoor;
  14.  
  15. implementation
  16.  
  17. procedure getloginproc;
  18. var isnew:boolean;
  19.  
  20.   procedure addlastcaller (n:mstr);
  21.   var qf:file of lastrec;
  22.       last,cnt:integer;
  23.       l:lastrec;
  24.   begin
  25.     assign (qf,'Callers');
  26.     reset (qf);
  27.     if ioresult<>0 then rewrite (qf);
  28.     last:=filesize(qf);
  29.     if last>maxlastcallers then last:=maxlastcallers;
  30.     for cnt:=last-1 downto 0 do begin
  31.       seek (qf,cnt);
  32.       read (qf,l);
  33.       seek (qf,cnt+1);
  34.       write (qf,l)
  35.     end;
  36.     with l do begin
  37.       name:=n;
  38.       when:=now;
  39.       callnum:=round(numcallers)
  40.     end;
  41.     seek (qf,0);
  42.     write (qf,l);
  43.     close (qf)
  44.   end;
  45.  
  46.   procedure byebye (byefile:sstr);
  47.   begin
  48.     printfile (textfiledir+byefile);
  49.     unum:=-1;
  50.     disconnect
  51.   end;
  52.  
  53.   procedure nicetry;
  54.   begin
  55.     byebye ('NiceTry')
  56.   end;
  57.  
  58.   procedure getsystempassword;
  59.   var tries:integer;
  60.       b:boolean;
  61.   begin
  62.     tries:=0;
  63.     writeln(^B'              DDT/6');
  64.     writeln;
  65.     writeln(^B'    Kelv''s answering machine.   ');
  66.     writeln(^B' Leave your name and number and ');
  67.     writeln(^B' I''ll try to get back to you as ');
  68.     writeln(^B' soon as I can.  If it''s urgent ');
  69.     writeln(^B' put an (*) after your name.    ');
  70.     writeln(^B' ------------------------------ ');
  71.     repeat
  72.       chainstr:='';
  73.       writeln (^B'Entry:');
  74.       dots:=true;
  75.       writestr ('=> *');
  76.       tries:=tries+1;
  77.       b:=match(input,systempassword)
  78.     until (tries=4) or b;
  79.     if not b then nicetry
  80.   end;
  81.  
  82.   procedure newuser;
  83.  
  84.     function validphone:boolean;
  85.     var p:integer;
  86.         k:char;
  87.     begin
  88.       validphone:=false;
  89.       p:=1;
  90.       while p<=length(input) do begin
  91.         k:=input[p];
  92.         if k in ['0'..'9']
  93.           then p:=p+1
  94.           else delete (input,p,1);
  95.       end;
  96.       if length(input)<>10 then begin
  97.         writestr ('The phone number must be 10 digits long.');
  98.         exit
  99.       end;
  100.       if (input[2] in ['2'..'9']) or (input[1] in ['0','1'])
  101.          or (input[4] in ['0','1']) then begin
  102.            writestr ('Invalid phone number.');
  103.            exit
  104.          end;
  105.       validphone:=true
  106.     end;
  107.  
  108.     procedure getoption (c:configtype; txt:lstr; b:boolean);
  109.     const yn:array [false..true] of string[3]=('No','Yes');
  110.     begin
  111.       if hungupon then exit;
  112.       txt:=txt+' [def: '+yn[b]+'] ? *';
  113.       writestr (txt);
  114.       if length(input)<>0 then b:=yes;
  115.       if b
  116.         then urec.config:=urec.config+[c]
  117.         else urec.config:=urec.config-[c]
  118.     end;
  119.  
  120.   var oldn:integer;
  121.       k:char;
  122.   begin
  123.     if private then byebye ('Newuser') else begin
  124.       printfile (textfiledir+'Newuser');
  125.       unum:=0;
  126.       oldn:=0;
  127.       repeat
  128.         if oldn<>0 then unam:='';
  129.         if length(unam)=0 then begin
  130.           writestr (^B'Enter your name:'^M'=> *');
  131.           unam:=input;
  132.           if pos('*',unam)>0 then begin
  133.             writestr ('Invalid user name!');
  134.             oldn:=1
  135.           end
  136.         end;
  137.         if hungupon then exit;
  138.         if length(unam)=0
  139.           then oldn:=0
  140.           else begin
  141.             writestr ('Hold on a sec..');
  142.             if not validuname(unam)
  143.               then oldn:=1
  144.               else begin
  145.                 oldn:=lookupuser(unam);
  146.                 if oldn<>0 then writestr (^B'Sorry!  That name is in use!')
  147.               end
  148.           end
  149.       until oldn=0;
  150.       ulvl:=1;
  151.       if unam<>'' then begin
  152.         unum:=adduser (urec);
  153.         if unum<1 then begin
  154.           writeln (^B'Sorry!  No room for new users right now!'^M,
  155.                    'Try again later!'^M);
  156.           hangupmodem;
  157.           exit
  158.         end;
  159.         writeln (^B^M'You are user number ',unum,'.');
  160.         repeat
  161.           lastprompt:=^B^M'Please choose a password now.'^B^M'> ';
  162.           write (lastprompt)
  163.         until getpassword or hungupon;
  164.         with urec do begin
  165.           regularcolor:=7;
  166.           promptcolor:=7;
  167.           statcolor:=7;
  168.           inputcolor:=7
  169.         end;
  170.         repeat
  171.           writestr (^M'What is your home phone number? *');
  172.         until validphone or hungupon;
  173.         urec.phonenum:=input;
  174.         writeln;
  175.         repeat
  176.           writestr ('Can you emulate: A)NSI color, V)T52, or N)one:');
  177.           if length(input)>0
  178.             then k:=upcase(input[1])
  179.             else k:='N'
  180.         until (k in ['A','N','V']) or hungupon;
  181.         case k of
  182.           'A':urec.config:=urec.config+[ansigraphics];
  183.           'V':urec.config:=urec.config+[vt52];
  184.           'N':getoption (lowercase,'Can you display lower case',true)
  185.         end;
  186.         if k in ['A','V']
  187.           then getoption (fseditor,
  188.                   'Do you want to use the full-screen editor',true)
  189.           else urec.config:=urec.config-[fseditor];
  190.         getoption (moreprompts,'Should I pause after every screen',false);
  191.         repeat
  192.           writestr ('How many lines long is your screen? *');
  193.           urec.displaylen:=valu(input)
  194.         until ((urec.displaylen>20) and (urec.displaylen<44)) or hungupon;
  195.         getoption (linefeeds,'Do you need line feeds',true);
  196.         getoption (eightycols,'Do you have 80 columns',true);
  197.         if lowercase in urec.config then
  198.          getoption (asciigraphics,'Can you see IBM graphics characters',true);
  199.         if hungupon then begin
  200.           unum:=0;
  201.           exit
  202.         end;
  203.         writeurec;
  204.         isnew:=true
  205.       end else begin
  206.         unum:=0;
  207.         writeln (^B^M'If you aren''t a new user...')
  208.       end
  209.     end
  210.   end;
  211.  
  212.   procedure getunum;
  213.   var tries,cnt:integer;
  214.       u:userrec;
  215.       enterednum:boolean;
  216.   begin
  217.     tries:=0;
  218.     repeat
  219.       tries:=tries+1;
  220.       if tries>3 then nicetry else begin
  221.         chainstr:='';
  222.         writestr
  223.           (^M'Enter your full name.'+^B^M+'=> *');
  224.         unam:=input;
  225.         isnew:=false;
  226.         enterednum:=valu(unam)<>0;
  227.         if hungupon then unum:=-1 else
  228.           if length(unam)=0
  229.             then newuser
  230.             else begin
  231.               unum:=lookupuser (unam);
  232.               if unum=0
  233.                 then
  234.                   begin
  235.                     writestr ('Not found!  Are you new? *');
  236.                     if yes then newuser
  237.                   end
  238.                 else if not enterednum
  239.                   then writeln (^M'Use ',unum,' for faster logon.')
  240.             end
  241.       end
  242.     until unum<>0
  243.   end;
  244.  
  245.   procedure getpwd;
  246.   var u:userrec;
  247.   begin
  248.     seek (ufile,unum);
  249.     read (ufile,u); che;
  250.     if not checkpassword(u) then begin
  251.       nicetry;
  252.       writelog (0,2,unam)
  253.     end;
  254.     writeln (^M)
  255.   end;
  256.  
  257.   procedure inituser;
  258.   var asc:boolean;
  259.  
  260.     procedure center (c:lstr; a,b:sstr);
  261.     var cnt:integer;
  262.         tmp:lstr;
  263.     begin
  264.       if asc then begin
  265.         a:='│';
  266.         b:=a
  267.       end;
  268.       fillchar (tmp[1],80,32);
  269.       if length(a)+length(b)+length(c)>39
  270.         then c[0]:=chr(39-length(a)-length(b));
  271.       tmp[0]:=chr((39-length(c)-length(a)-length(b)) div 2);
  272.       c:=a+tmp+c;
  273.       tmp[0]:=chr(39-length(c)-length(b));
  274.       c:=c+tmp+b;
  275.       while c[length(c)]=' ' do c[0]:=pred(c[0]);
  276.       writeln (c)
  277.     end;
  278.  
  279.   var m:mailrec;
  280.       cnt:integer;
  281.       tmp:lstr;
  282.   const inoutstr:array [false..true] of string[3]=('Out','In');
  283.   begin
  284.     readurec;
  285.     if ulvl=-1 then begin
  286.       byebye ('Trashcan');
  287.       exit
  288.     end;
  289.     if requireforms and (urec.infoform<0) then infoform;
  290.     writestr ('O.K. you''re on!'^M);
  291.     if local
  292.       then tmp:=' (Local)'
  293.       else tmp:=' at '+baudstr;
  294.     writelog (0,1,unam+tmp);
  295.     with urec do begin
  296.       numon:=numon+1;
  297.       numcallers:=numcallers+1;
  298.       callstoday:=callstoday+1;
  299.       asc:=asciigraphics in config;
  300.       if datepart(laston)<>datepart(now) then begin
  301.         cnt:=ulvl;
  302.         if cnt<1 then cnt:=1;
  303.         if cnt>100 then cnt:=100;
  304.         timetoday:=usertime[cnt]
  305.       end;
  306.       if (timetillevent<timetoday+3) and (timetillevent<=63) then begin
  307.         writestr (^M'Due to a timed event scheduled for '+eventtime+',');
  308.         writeln ('your time today is limited to ',timetillevent-3,' mins.')
  309.       end;
  310.       write (^B^M);
  311.       if asc
  312.         then writeln ('╒══════════╡ '^S,versionnum,^N' ╞══════════╕')
  313.         else writeln ('/----------: ',versionnum,' :----------\');
  314.       center ('Welcome, '+unam+'.','\','/');
  315.       center ('Caller number: '+streal(numcallers),' \','/ ');
  316.       center ('Last caller: '+getlastcaller,' /','\ ');
  317.       center ('This is time on #'+strr(numon)+' for you.','/','\');
  318.       center ('Total time on: '+streal(totaltime)+' mins.','\','/');
  319.       if laston<>0 then
  320.         center ('Last on '+datestr(laston)+' at '+timestr(laston)+
  321.                     '.',' !','! ');
  322.       subs1.laston:=laston;
  323.       laston:=now;
  324.       center ('Time for today: '+strr(timetoday)+' mins.',' /','\ ');
  325.       center ('Your ranking: Level '+strr(ulvl),'/','\');
  326.       center ('Sysop is: '+inoutstr[sysopisavail],'!','!');
  327.       if asc
  328.         then writeln ('╘═════════════════════════════════════╛'^B^M)
  329.         else writeln ('\-------------------------------------/'^B^M);
  330.       cnt:=getnummail(unum);
  331.       if cnt>0
  332.         then writeln (^B^G'You have ',cnt,
  333.                  ' piece',s(cnt),' of mail waiting!  Use [E] to read.');
  334.       if (ulvl>=sysoplevel) then begin
  335.         if numfeedback>0 then begin
  336.           thereisare (numfeedback);
  337.           writeln ('piece',s(cnt),' of feedback waiting!  Use [%,F] to read.')
  338.         end;
  339.         if exist ('Errlog')
  340.           then writeln (^B^G'Errors have occured!  Use [%,E] to read.')
  341.       end;
  342.       logontime:=timer;
  343.       logofftime:=timer+timetoday;
  344.       logonunum:=unum
  345.     end;
  346.     if exist ('ad')
  347.       then writestr ('Buy this software!  Use & to read!');
  348.     addlastcaller (unam);
  349.     writeurec;
  350.     bottomline;
  351.     if wanted in urec.config then if sysopisavail then begin
  352.       writeln (^B,sysopname,' wishes to speak with you.');
  353.       writeln ('Paging.. please stand by...'^M);
  354.       for cnt:=1 to 25 do if not keyhit then summonbeep;
  355.       chatmode:=true
  356.     end;
  357.     printnews;
  358.     if tonext>-1 then begin
  359.       writehdr ('Message from last user');
  360.       printtext (tonext)
  361.     end;
  362.     disconnected:=false
  363.   end;
  364.  
  365. begin
  366.   stoptimer (numminsidle);
  367.   starttimer (numminsused);
  368.   textcolor (normbotcolor);
  369.   clrscr;
  370.   initwinds;
  371.   fillchar (urec,sizeof(urec),0);
  372.   urec.config:=[lowercase,linefeeds,eightycols];
  373.   uselinefeeds:=true;
  374.   usecapsonly:=false;
  375.   getsystempassword;
  376.   printfile (textfiledir+'Welcome.'+strr(random(numwelcomes)+1));
  377.   if autologin and local and (not carrier) then begin
  378.     unum:=lookupuser (sysopname);
  379.     if unum=0
  380.       then writeln (usr,'User ',sysopname,' not found!')
  381.       else begin
  382.         writeln (usr,'* SYSOP AUTOLOGIN *');
  383.         unum:=1;
  384.         inituser;
  385.         exit
  386.       end
  387.   end;
  388.   getunum;
  389.   if hungupon then exit;
  390.   if not isnew then getpwd;
  391.   if hungupon then exit;
  392.   inituser
  393. end;
  394.  
  395. procedure returnfromdoor;
  396. var t:sstr;
  397. begin
  398.   if not fromdoor then exit;
  399.   readdataarea;
  400.   baudrate:=valu(paramstr(2));
  401.   parity:=boolean(valu(paramstr(3)));
  402.   online:=baudrate<>0;
  403.   local:=not online;
  404.   if baudrate=0 then baudrate:=defbaudrate;
  405.   setparam (usecom,baudrate,parity);
  406.   if unum=valu(paramstr(1)) then readurec else begin
  407.     unum:=valu(paramstr(1));
  408.     readurec;
  409.     if (unum<1) or (unum>numusers) then begin
  410.       unum:=-1;
  411.       exit
  412.     end;
  413.     logontime:=timer;
  414.     logofftime:=timer+urec.timetoday
  415.   end;
  416.   if hungupon then begin
  417.     unum:=-1;
  418.     exit
  419.   end;
  420.   fromdoor:=true;
  421.   t:=paramstr(4);
  422.   if t=''
  423.     then returnto:='D'
  424.     else returnto:=upcase(t[1])
  425. end;
  426.  
  427. begin
  428. end.
  429.