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