home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 270.img / FORUM25C.ZIP / GETLOGIN.PAS < prev    next >
Pascal/Delphi Source File  |  1989-03-02  |  17KB  |  631 lines

  1. {$R-,S-,I-,V-,B-}
  2. {$O+}
  3.  
  4. unit getlogin;
  5.  
  6.  
  7. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  8.  
  9. interface
  10.  
  11. USES CRT,
  12.      DOS,
  13.      gentypes,
  14.      configrt,
  15.      modem,
  16.      userret,
  17.      statret,
  18.      gensubs,
  19.      subs1,
  20.      subs2,
  21.      windows,
  22.      StrLib,
  23.      mailret,
  24.      textret,
  25.      overret1,
  26.      mainr1,
  27.      mainr2;
  28.  
  29. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  30.  
  31.  
  32. Procedure getloginproc;
  33. Procedure returnfromdoor;
  34.  
  35.  
  36. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  37.  
  38. implementation
  39.  
  40. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  41.  
  42.  
  43. Procedure getloginproc;
  44. VAR isnew:boolean;
  45.  
  46. {=============================================================================}
  47.  
  48. Procedure Do_today;
  49. VAR Day,Month,Year,DayOfWeek : WORD;
  50.     Ext                      : String3;
  51.     Today_File               : String14;
  52.     Data_file                : TEXT;
  53.     No_more                  : BOOLEAN;
  54.     Found                    : BOOLEAN;
  55.     Was_born                 : BOOLEAN;
  56.     Dat                      : String80;
  57. CONST MonthStr : ARRAY[1..12] OF String3 = ('Jan','Feb','Mar','Apr','May',
  58.                                             'Jun','Jul','Aug','Sep','Oct',
  59.                                             'Nov','Dec');
  60. Function Get_born : String80;
  61. VAR Data : String80;
  62. Begin
  63.   Found := FALSE;
  64.   No_More := FALSE;
  65.   REPEAT
  66.     Readln(Data_File,Data);
  67.     If Data[1] = '*' THEN
  68.      Begin
  69.       Get_born := '';
  70.       No_More := TRUE
  71.      End
  72.     ELSE
  73.       Begin
  74.         If Copy(Data,1,5) = 'B'+ZeroStr(Month,2)+ZeroStr(Day,2) THEN
  75.           Begin
  76.             Get_Born := Data;
  77.             Found := TRUE;
  78.           End
  79.         ELSE
  80.           Begin
  81.             Found := FALSE;
  82.             Get_born := '';
  83.           End;
  84.       End;
  85.   UNTIL (No_more) Or (Found);
  86. End;
  87.  
  88. Function Get_Special : String80;
  89. VAR Data : String80;
  90. Begin
  91.   Found := FALSE;
  92.   No_More := FALSE;
  93.   REPEAT
  94.     Readln(Data_File,Data);
  95.     If Data[1] = '*' THEN
  96.      Begin
  97.       Get_special := '';
  98.       No_More := TRUE
  99.      End
  100.     ELSE
  101.       Begin
  102.         If Copy(Data,1,5) = 'S'+ZeroStr(Month,2)+ZeroStr(Day,2) THEN
  103.           Begin
  104.             Get_special := Data;
  105.             Found := TRUE;
  106.           End
  107.         ELSE
  108.           Begin
  109.             Found := FALSE;
  110.             Get_special := '';
  111.           End;
  112.       End;
  113.   If EOF(Data_file) THEN No_more := TRUE;
  114.   UNTIL (No_more) Or (Found);
  115. End;
  116.  
  117. CONST Full_month : ARRAY[1..12] OF String10 = ('January','February','March',
  118.                                                'April','May','June','July',
  119.                                                'August','September','October',
  120.                                                'November','December');
  121. CONST Week_day : ARRAY[0..6] OF String10 = ('Sunday','Monday','Tuesday',
  122.                                             'Wednesday','Thrusday','Friday',
  123.                                             'Saturday');
  124. Begin
  125.   GetDate(Year,Month,Day,DayOfWeek);
  126.   Ext := MonthStr[Month];
  127.   Today_file := ext+'.DAT';
  128.   Assign(Data_file,Today_file);
  129.   Reset(Data_file);
  130.   If IOREsult <> 0 THEN
  131.     Begin
  132.       Exit;
  133.     End;
  134.   Was_Born := FALSE;
  135.   Readln(Data_File,Dat);
  136.   Readln(Data_file,Dat);
  137.   Writeln;
  138.   WriteStr('It''s '+Week_day[DayOfWeek]+', '+Full_month[Month]+' '+
  139.             Strr(Day)+', '+Strr(year)+'.');
  140.   Writeln;
  141.   Writeln('Birthdays today: ');
  142.   Writeln;
  143.   REPEAT
  144.     Dat := Get_born;
  145.     If Dat <> '' THEN
  146.       Begin
  147.         If Dat[10] = 'C' THEN
  148.           Begin
  149.             Tab(' ',12);
  150.             Writeln(Copy(Dat,11,80));
  151.           End
  152.         ELSE
  153.           Begin
  154.             Tab(' ',3);
  155.             If Copy(Dat,6,4) <> '    ' THEN
  156.             Tab('In '+Copy(Dat,6,5),9);
  157.             Writeln(Copy(Dat,11,80));
  158.           End;
  159.       End;
  160.   UNTIL No_more;
  161.   Readln(data_file,Dat);
  162.   Writeln;
  163.   Writeln('Other events: ');
  164.   Writeln;
  165.   REPEAT
  166.     Dat := Get_special;
  167.     If Dat <> '' THEN
  168.       Begin
  169.         If Dat[10] = 'C' THEN
  170.           Begin
  171.             Tab(' ',12);
  172.             Writeln(Copy(Dat,11,80));
  173.           End
  174.         ELSE
  175.           Begin
  176.             Tab(' ',3);
  177.             If Copy(Dat,6,4) <> '    ' THEN
  178.                 Tab('In '+Copy(Dat,6,5),9);
  179.             Writeln(Copy(Dat,11,80));
  180.           End;
  181.       End;
  182.   UNTIL No_more;
  183.   Close(Data_file);
  184. End;
  185.  
  186. {=============================================================================}
  187.  
  188.   Procedure addlastcaller (n:mstr);
  189.   VAR qf:file of lastrec;
  190.       last,cnt:integer;
  191.       l:lastrec;
  192.   begin
  193.     assign (qf,'Callers');
  194.     reset (qf);
  195.     if ioresult<>0 then rewrite (qf);
  196.     last:=filesize(qf);
  197.     if last>maxlastcallers then last:=maxlastcallers;
  198.     for cnt:=last-1 downto 0 do begin
  199.       seek (qf,cnt);
  200.       read (qf,l);
  201.       seek (qf,cnt+1);
  202.       write (qf,l)
  203.     end;
  204.     with l do begin
  205.       name:=n;
  206.       when:=now;
  207.       callnum:=round(numcallers)
  208.     end;
  209.     seek (qf,0);
  210.     write (qf,l);
  211.     close (qf)
  212.   end;
  213.  
  214.   Procedure byebye (byefile:sstr);
  215.   begin
  216.     printfile (textfiledir+byefile);
  217.     unum:=-1;
  218.     disconnect
  219.   end;
  220.  
  221.   Procedure nicetry;
  222.   begin
  223.     byebye ('NiceTry')
  224.   end;
  225.  
  226.   Procedure getsystempassword;
  227.   VAR tries:integer;
  228.       b:boolean;
  229.   begin
  230.     if (length(systempassword)=0) or (autologin and local) then exit;
  231.     tries:=0;
  232.     repeat
  233.       chainstr:='';
  234.       writeln (^B'System password:');
  235.       dots:=true;
  236.       writestr ('=> *');
  237.       tries:=tries+1;
  238.       b:=match(input,systempassword)
  239.     until (tries=4) or b;
  240.     if not b then nicetry
  241.   end;
  242.  
  243.   Procedure newuser;
  244.  
  245.     Function validphone:boolean;
  246.     VAR p:integer;
  247.         k:char;
  248.     begin
  249.       validphone:=false;
  250.       p:=1;
  251.       while p<=length(input) do begin
  252.         k:=input[p];
  253.         if k in ['0'..'9']
  254.           then p:=p+1
  255.           else delete (input,p,1);
  256.       end;
  257.       if length(input)<>10 then begin
  258.         writestr ('The phone number must be 10 digits long.');
  259.         exit
  260.       end;
  261.       if (input[2] in ['2'..'9']) or (input[1] in ['0','1'])
  262.          or (input[4] in ['0','1']) then begin
  263.            writestr ('Invalid phone number.');
  264.            exit
  265.          end;
  266.       validphone:=true
  267.     end;
  268.  
  269.     Procedure getoption (c:configtype; txt:lstr; b:boolean);
  270.     const yn:array [false..true] of string[3]=('No','Yes');
  271.     begin
  272.       if hungupon then exit;
  273.       txt:=txt+' [def: '+yn[b]+'] ? *';
  274.       writestr (txt);
  275.       if length(input)<>0 then b:=yes;
  276.       if b then
  277.         urec.config:=urec.config+[c]
  278.       ELSE
  279.         urec.config := urec.config - [c]
  280.     End;
  281.  
  282.   VAR oldn      : INTEGER;
  283.       k         : CHAR;
  284.       Valid_set : SET OF CHAR;
  285.   Begin
  286.     if private then byebye ('Newuser') else begin
  287.       printfile (textfiledir+'Newuser');
  288.       unum:=0;
  289.       oldn:=0;
  290.       repeat
  291.         if oldn<>0 then unam:='';
  292.         if length(unam)=0 then begin
  293.           writestr (^B'Enter your New User Name:'^M'=> *');
  294.           unam:=input;
  295.           if pos('*',unam)>0 then begin
  296.             writestr ('Invalid user name!');
  297.             oldn:=1
  298.           end
  299.         end;
  300.         if hungupon then exit;
  301.         if length(unam)=0
  302.           then oldn:=0
  303.           else begin
  304.             writestr ('Searching for duplicate user name.');
  305.             if not validuname(unam)
  306.               then oldn:=1
  307.               else begin
  308.                 oldn := lookupuser(unam);
  309.                 if oldn<>0 then writestr(^B'Name is already in use.')
  310.               end
  311.           end
  312.       until oldn=0;
  313.       ulvl := NewUserLevel;
  314.       IF unam<>'' then
  315.         begin
  316.           unum := adduser (urec);
  317.           if unum<1 then
  318.             begin
  319.               writeln (^B'Sorry!  No room for new users right now!'^M,
  320.                          'Try again later!'^M);
  321.               hangupmodem;
  322.               exit
  323.             end;
  324.         Writeln (^B^M'You are user number ',unum,'.');
  325.         REPEAT
  326.           LastPrompt := ^B^M'Please choose a password now.'^B^M'> ';
  327.           Write(LastPrompt)
  328.         UNTIL GetPassword OR HungUpon;
  329.         With Urec DO
  330.          Begin
  331.            regularcolor := 7;
  332.            promptcolor := 7;
  333.            statcolor := 7;
  334.            inputcolor := 7;
  335.          End;
  336.         Repeat
  337.           Writestr(^M'What is your home phone number? *');
  338.         Until validphone or hungupon;
  339.         urec.phonenum:=input;
  340.         writeln;
  341.         repeat
  342.           writestr ('Can you emulate: A)NSI color, V)T52, or N)one:');
  343.           if length(input)>0
  344.             then k:=upcase(input[1])
  345.             else k:='N'
  346.         until (k in ['A','N','V']) or hungupon;
  347.         case k of
  348.           'A':urec.config:=urec.config+[ansigraphics];
  349.           'V':urec.config:=urec.config+[vt52];
  350.           'N':getoption (lowercase,'Can you display lower case',true)
  351.         end;
  352.         Valid_Set := ['1'];
  353.         URec.Config := URec.Config - [Fseditor];
  354.  
  355.         If (ANSIGraphics In Urec.Config) OR (VT52 in URec.Config) THEN
  356.           GetOption(FSeditor,'Do you want to use the full screen editor',TRUE);
  357.         getoption (moreprompts,'Should I pause after every screen',false);
  358.         repeat
  359.           writestr ('How many lines long is your screen? *');
  360.           urec.displaylen:=valu(input)
  361.         until ((urec.displaylen>20) and (urec.displaylen<44)) or hungupon;
  362.         getoption(linefeeds,'Do you need line feeds',true);
  363.         getoption(eightycols,'Do you have 80 columns',true);
  364.         if lowercase in urec.config then
  365.          getoption(asciigraphics,'Can you see IBM graphics characters',true);
  366.         GetOption(ExtClrScr,'Clear screen between posts (Extenden newscan)',
  367.                   TRUE);
  368.         IF hungupon THEN
  369.           Begin
  370.             unum := 0;
  371.             Exit;
  372.           End;
  373.         WriteUrec;
  374.         isnew := TRUE;
  375.       end
  376.     else
  377.       begin
  378.         unum:=0;
  379.         writeln (^B^M'If you aren''t a new user...')
  380.       end
  381.     end
  382.   end;
  383.  
  384.   Procedure getunum;
  385.   VAR tries,cnt:integer;
  386.       u:userrec;
  387.       enterednum:boolean;
  388.   begin
  389.     tries:=0;
  390.     repeat
  391.       Inc(tries);
  392.       if tries > MaxLoginTries then nicetry
  393.        else
  394.         begin
  395.          chainstr:='';
  396. {        writestr(^M'Enter your UserName[NEW=NEWUSER]'+^B^M+'[> *'); }
  397.          WriteStr(^M+User_name_prompt+^B^M+'[> *');
  398.          unam := input;
  399.          isnew := false;
  400.          enterednum := valu(unam)<>0;
  401.          if hungupon then
  402.            unum:=-1
  403.          else
  404.            begin
  405.              If UpString(Unam) = 'NEW' THEN
  406.               Begin
  407.                Unam := '';
  408.                Newuser
  409.               End
  410.              ELSE
  411.               Begin
  412.                unum := lookupuser(unam);
  413.                if unum=0 THEN
  414.                  Begin
  415.                    writestr('User not found');
  416.                  End
  417.                else
  418.                  IF NOT enterednum THEN
  419.                    writeln (^M'Use ',unum,' for faster logon.')
  420.              end
  421.          end
  422.       End
  423.     until (unum<>0);
  424.   end;
  425.  
  426.   Procedure getpwd;
  427.   VAR u:userrec;
  428.   begin
  429.     seek (ufile,unum);
  430.     read (ufile,u); che;
  431.     if not checkpassword(u) then begin
  432.       nicetry;
  433.       writelog (0,2,unam)
  434.     end;
  435.     writeln (^M)
  436.   end;
  437.  
  438.   Procedure inituser;
  439.   VAR asc:boolean;
  440.  
  441.     Procedure center (c:lstr; a,b:sstr);
  442.     VAR cnt:integer;
  443.         tmp:lstr;
  444.     begin
  445.       if asc then begin
  446.         a:='│';
  447.         b:=a
  448.       end;
  449.       fillchar (tmp[1],80,32);
  450.       if length(a)+length(b)+length(c)>39
  451.         then c[0]:=chr(39-length(a)-length(b));
  452.       tmp[0]:=chr((39-length(c)-length(a)-length(b)) div 2);
  453.       c:=a+tmp+c;
  454.       tmp[0]:=chr(39-length(c)-length(b));
  455.       c:=c+tmp+b;
  456.       while c[length(c)]=' ' do c[0]:=pred(c[0]);
  457.       writeln (c)
  458.     end;
  459.  
  460.   VAR m:mailrec;
  461.       cnt:integer;
  462.       tmp:lstr;
  463.   const inoutstr:array [false..true] of string[3]=('Out','In');
  464.   begin
  465.     readurec;
  466.     if ulvl=-1 then begin
  467.       byebye ('Trashcan');
  468.       exit
  469.     end;
  470.     printfile(textfiledir+'Welcom'+strr(random(numwelcomes)+1));
  471.     if requireforms and (urec.infoform<0) then infoform;
  472.     if local
  473.       then tmp:=' (Local)'
  474.       else tmp:=' at '+baudstr;
  475.     Writeln;
  476.     Writeln;
  477. {    If Local THEN
  478.       WriteStr(LongName+' running locally.')
  479.     ELSE
  480.       WriteStr(LongName+' operating at '+tmp);  }
  481.     writelog (0,1,unam+tmp);
  482.     with urec do begin
  483.       numon:=numon+1;
  484.       numcallers:=numcallers+1;
  485.       callstoday:=callstoday+1;
  486.       asc:=asciigraphics in config;
  487.       if datepart(laston)<>datepart(now) then begin
  488.         cnt:=ulvl;
  489.         if cnt<1 then cnt:=1;
  490.         if cnt>100 then cnt:=100;
  491.         timetoday:=usertime[cnt]
  492.       end;
  493.       if (timetillevent<timetoday+3) and (timetillevent<=63) then begin
  494.         writestr (^M'Due to a timed event scheduled for '+eventtime+',');
  495.         writeln ('your time today is limited to ',timetillevent-3,' mins.')
  496.       end;
  497.       write (^B^M);
  498.       if asc
  499.         then writeln ('╒══════════╡ '^S,versionnum,^N' ╞══════════╕')
  500.         else writeln ('/----------: ',versionnum,' :----------\');
  501.       center ('Welcome, '+unam+'.','\','/');
  502.       center ('Caller number: '+streal(numcallers),' \','/ ');
  503.       center ('Last caller: '+getlastcaller,' /','\ ');
  504.       center ('This is time on #'+strr(numon)+' for you.','/','\');
  505.       center ('Total time on: '+streal(totaltime)+' mins.','\','/');
  506.       if laston<>0 then
  507.         center ('Last on '+datestr(laston)+' at '+timestr(laston)+
  508.                     '.',' !','! ');
  509.       GenTypes.laston := laston;
  510.       laston:=now;
  511.       center ('Time for today: '+strr(timetoday)+' mins.',' /','\ ');
  512.       center ('Your ranking: Level '+strr(ulvl),'/','\');
  513.       center ('Sysop is: '+inoutstr[sysopisavail],'!','!');
  514.       if asc
  515.         then writeln ('╘═════════════════════════════════════╛'^B^M)
  516.         else writeln ('\-------------------------------------/'^B^M);
  517.       cnt:=getnummail(unum);
  518.       if cnt>0
  519.         then writeln (^B^G'You have ',cnt,
  520.                  ' piece',s(cnt),' of mail waiting.');
  521.       if (ulvl>=sysoplevel) then begin
  522.         if numfeedback>0 then begin
  523.           thereisare (numfeedback);
  524.           writeln('piece',s(numfeedback),' of feedback waiting.')
  525.         end;
  526.         if exist('Errlog') then
  527.            writeln (^B^G'Errors have occured!')
  528.       End;
  529.       logontime:=timer;
  530.       logofftime:=timer+timetoday;
  531.       logonunum:=unum
  532.     end;
  533.     if exist ('ad')
  534.       then writestr ('Buy this software!  Use & to read!');
  535.     addlastcaller (unam);
  536.     writeurec;
  537.     bottomline;
  538.     if wanted in urec.config then
  539.      if (sysopisavail) OR (Ulvl >= 90) then begin
  540.       writeln (^B,sysopname,' wishes to speak with you.');
  541.       writeln ('Paging.. please stand by...'^M);
  542.       for cnt:=1 to 25 do if not keyhit then summonbeep;
  543.       chatmode:=true
  544.     end;
  545.     printnews;
  546.     Writeln;
  547.     Do_today;
  548.     Writeln;
  549.     if tonext>-1 then begin
  550.       writehdr ('-%-  Message from last user  -%-');
  551.       printtext (tonext)
  552.     end;
  553.     disconnected:=false;
  554.     Writeln;
  555.     Writeln;
  556.   End;
  557.  
  558. begin
  559.   stoptimer (numminsidle);
  560.   starttimer (numminsused);
  561.   textcolor (normbotcolor);
  562.   clrscr;
  563.   fillchar (urec,sizeof(urec),0);
  564.   urec.config:=[lowercase,linefeeds,eightycols];
  565.   uselinefeeds:=true;
  566.   usecapsonly:=false;
  567.   getsystempassword;
  568.  
  569.   Urec.DisplayLen := 24;
  570.   DontStop := FALSE;
  571.  
  572.   Printfile(Textfiledir+'Prelog.');
  573.  
  574.   if autologin and local and (not carrier) then begin
  575.     unum:=lookupuser (sysopname);
  576.     if unum=0
  577.       then writeln (usr,'User ',sysopname,' not found!')
  578.       else begin
  579.         writeln (usr,'* SYSOP AUTOLOGIN *');
  580.         unum:=1;
  581.         inituser;
  582.         exit
  583.       end
  584.   end;
  585.   getunum;
  586.   if hungupon then exit;
  587.   if not isnew then getpwd;
  588.   if hungupon then exit;
  589.   inituser;
  590.   Writeln;
  591. end;
  592.  
  593.  
  594.  
  595. procedure returnfromdoor;
  596. var t:sstr;
  597. begin
  598.   if not fromdoor then exit;
  599.   readdataarea;
  600.   baudrate := valu(paramstr(2));
  601.   parity := boolean(valu(paramstr(3)));
  602.   online := baudrate<>0;
  603.   local := not online;
  604.   if baudrate=0 then baudrate:=defbaudrate;
  605.   setparam (usecom,baudrate,parity);
  606.   if unum=valu(paramstr(1)) then readurec else begin
  607.     unum:=valu(paramstr(1));
  608.     readurec;
  609.     if (unum<1) or (unum>numusers) then begin
  610.       unum:=-1;
  611.       exit
  612.     end;
  613.     logontime:=timer;
  614.     logofftime:=timer+urec.timetoday
  615.   end;
  616.   if hungupon then begin
  617.     unum:=-1;
  618.     exit
  619.   end;
  620.   fromdoor:=true;
  621.   t:=paramstr(4);
  622.   if t=''then
  623.     returnto:='P'
  624.   else
  625.     returnto:=upcase(t[1])
  626. end;
  627.  
  628.  
  629. Begin
  630. End.
  631.