home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug184.arc / ROS34.LBR / ROSINI.IZC / ROSINI.INC
Text File  |  1979-12-31  |  17KB  |  529 lines

  1. { ROSINI.INC - Remote Operating System initialization/shutdown routines }
  2.  
  3. overlay procedure login;
  4. { Log user into system }
  5.   var
  6.     continue: boolean;
  7.     key: StrName;
  8.  
  9.   procedure get_new_user(var continue: boolean);
  10.   { Get new user information }
  11.     var
  12.       i: integer;
  13.     begin
  14.       continue := FALSE;
  15.       Writeln(USR);
  16.       Writeln(USR, 'Name not found.');
  17.       list('A');
  18.       Writeln(USR);
  19.       continue := ask('Are you a new user');
  20.       if continue
  21.         then with user_rec do
  22.           begin
  23.             get_case;
  24.             get_nulls;
  25.             cy := prompt('From what CITY are you calling', len_ad, 'E');
  26.             st := prompt(' STATE [2 letter abbreviation]', len_st, 'ES');
  27.             Writeln(USR);
  28.             Writeln(USR, 'You are ', fn, ' ', ln, ' from ', cy, ', ', st, '.');
  29.             Writeln(USR);
  30.             continue := ask('Is that correct');
  31.             if continue
  32.               then
  33.                 begin
  34.                   get_new_password;
  35.                   used := 0;
  36.                   ad := '';
  37.                   ph := '';
  38.                   if fn = 'SYSOP'
  39.                     then access := 255
  40.                     else access := def_acc;
  41.                   limit := def_time;
  42.                   help_level := 3;
  43.                   columns := def_chars;
  44.                   lines := def_lines;
  45.                   for i := 0 to 5 do
  46.                     laston[i] := 0;
  47.                   time_today := 0;
  48.                   time_total := 0;
  49.                   lasthi := 0;
  50.                   upload := 0;
  51.                   download := 0;
  52.  
  53.                   key := pad(ln, len_ln) + pad(fn, len_fn);
  54.                   AddRec(DatF, user_loc, user_rec);
  55.                   AddKey(IdxF, user_loc, key);
  56.                   log(9, '');
  57.                   list('I');
  58.                   pause
  59.                 end
  60.           end
  61.     end;
  62.  
  63.   procedure init_user;
  64.   { Initialize user }
  65.     var
  66.       str: StrTAD;
  67.     begin
  68.       if local_online
  69.         then log(2, 'Local')
  70.         else log(2, intstr(rate, 3) + ' bps');
  71.       Seek(logr_file, 0);
  72.       Read(logr_file, logr_rec);
  73.       logr_rec.user := succ(logr_rec.user);
  74.       Seek(logr_file, 0);
  75.       Write(logr_file, logr_rec);
  76.  
  77.       GetTAD(login_t);
  78.       if (login_t[3] <> user_rec.laston[3]) or
  79.          (login_t[4] <> user_rec.laston[4]) or
  80.          (login_t[5] <> user_rec.laston[5]) then user_rec.time_today := 0;
  81.  
  82.       if user_rec.access < 10               { Hang up on twit }
  83.         then remote_online := FALSE
  84.         else
  85.           begin
  86.             str := FormTAD(login_t);
  87.             Writeln(USR);
  88.             Writeln(USR, 'Login             : ', str);
  89.             Writeln(USR);
  90.             Writeln(USR, 'Caller number     : ', logr_rec.user);
  91.             Writeln(USR, 'Access time today : ', user_rec.time_today);
  92.             Writeln(USR, 'Access time total : ', user_rec.time_total);
  93.             str := FormTAD(user_rec.laston);
  94.             Writeln(USR, 'Last on system    : ', str);
  95.             Writeln(USR, 'Last high message : ', user_rec.lasthi)
  96.           end
  97.     end;
  98.  
  99.   begin { login }
  100.     Writeln(USR, version);
  101.     list('W');
  102.     repeat
  103.       get_name(user_rec.fn, user_rec.ln);
  104.       timeout := 300;                       { Now allow five minutes }
  105.       key := pad(user_rec.ln, len_ln) + pad(user_rec.fn, len_fn);
  106.       FindKey(IdxF, user_loc, key);
  107.       if OK
  108.         then
  109.           begin
  110.             GetRec(DatF, user_loc, user_rec);
  111.             get_old_password('  Password', valid_pw);
  112.             if not valid_pw
  113.               then list('P');
  114.             continue := TRUE
  115.           end
  116.         else
  117.           begin
  118.             valid_pw := TRUE;
  119.             get_new_user(continue)
  120.           end
  121.     until (not online) or continue;
  122.     in_use := valid_pw;
  123.     connected := continue;
  124.     if online and in_use
  125.       then init_user
  126.   end;
  127.  
  128. overlay procedure wrapup;
  129. { Disconnect, update and close all files}
  130.   var
  131.     i, j, time_on, time_left: integer;
  132.     t: tad_array;
  133.   begin
  134.     Write(USR, 'Adios, call again...');
  135.     mdhangup;
  136.     if valid_pw                             { Don't update files if user not initialized }
  137.       then
  138.         begin
  139.           timer(time_on, time_left);
  140.           user_rec.time_today := user_rec.time_today + time_on;
  141.           user_rec.time_total := user_rec.time_total + time_on;
  142.           GetTAD(t);
  143.           user_rec.laston := t;
  144.  
  145.           PutRec(DatF, user_loc, user_rec);
  146.  
  147.           log(3, '');
  148.  
  149.           i := login_t[1];
  150.           j := login_t[2];
  151.           while j <> t[2] do
  152.             begin
  153.               stat_rec.busy_per_hour[j] := stat_rec.busy_per_hour[j] + 60 - i;
  154.               i := 0;
  155.               j := succ(j) mod 24
  156.             end;
  157.           stat_rec.busy_per_hour[j] := stat_rec.busy_per_hour[j] + t[1] - i;
  158.  
  159.           seek(stat_file, 0);
  160.           Write(stat_file, stat_rec)
  161.         end;
  162.     CloseFile(DatF);
  163.     CloseIndex(IdxF);
  164.     Close(logr_file);
  165.     Close(stat_file);
  166.     Close(nwin_file);
  167.     Close(summ_file);
  168.     Close(mesg_file)
  169.   end;
  170.  
  171. overlay procedure setup;
  172. { Initialize variables and open files }
  173.   var
  174.     i: integer;
  175.     t: tad_array;
  176.   begin
  177.     fini             := FALSE;
  178.  
  179.     connected        := FALSE;              { Assume no connection }
  180.     local_online     := FALSE;
  181.     local_copy       := TRUE;
  182.     printer_copy     := FALSE;              { Sysop can turn on printer }
  183.     remote_online    := FALSE;
  184.     remote_copy      := FALSE;
  185.  
  186.     mode             := message_mode;       { Start system in message mode }
  187.     st_switch        := TRUE;               { Default file size display - in 'k' }
  188.     new_dir          := FALSE;              { Reset directory flag }
  189.     up_down_display  := TRUE;               { Show up/downloads for files mode }
  190.     extra_time       := 0;                  { None until upload complete }
  191.  
  192.     op_chat          := FALSE;              { Operator chat not initiated }
  193.  
  194.     user_rec.nulls      := 2;               { 2 nulls until recognition }
  195.     user_rec.shift_lock := TRUE;            { Upper case only to start }
  196.     user_rec.noisy      := FALSE;           { Prompt bell initially off }
  197.     user_rec.columns    := def_chars;
  198.     user_rec.lines      := def_lines;
  199.  
  200.     macro            := 'L/R/PAYSG';
  201.     macro_ptr        := 0;
  202.  
  203.     timeout := 60;                          { Allow one minute for input }
  204.  
  205.     InitIndex;                              { Get files ready for use }
  206.  
  207.     OpenFile(DatF, user_data + ext, SizeOf(user_rec));
  208.     if OK
  209.       then OpenIndex(IdxF, user_indx + ext, len_ln + len_fn, 0);
  210.     if not OK
  211.       then
  212.         begin
  213.           Write(BEL, 'User files not found.  Creating ', user_data, ext);
  214.           MakeFile(DatF, user_data + ext, SizeOf(user_rec));
  215.           Write(', ', user_indx, ext);
  216.           MakeIndex(IdxF, user_indx + ext, len_ln + len_fn, 0);
  217.           Writeln
  218.         end;
  219.  
  220.     {$I-} Reset(logr_file) {$I+};
  221.     if IOresult <> 0
  222.       then
  223.         begin
  224.           Write(BEL, 'Log file not found.  Creating ', logr_name, ext);
  225.           Rewrite(logr_file);
  226.           logr_rec.user := 0;
  227.           Write(logr_file, logr_rec);
  228.           Writeln
  229.         end;
  230.  
  231.     {$I-} Reset(summ_file) {$I+};
  232.     OK := (IOresult = 0);
  233.     if OK
  234.       then
  235.         begin
  236.           {$I-} Reset(mesg_file) {$I+};
  237.           OK := (IOresult = 0)
  238.         end;
  239.     if not OK
  240.       then
  241.         begin
  242.           Write(BEL, 'Message files not found.  Creating ', summ_name, ext);
  243.           Rewrite(summ_file);
  244.           summ_rec.num := 0;
  245.           Write(summ_file, summ_rec);
  246.           Write(', ', mesg_name, ext);
  247.           Rewrite(mesg_file);
  248.           Writeln
  249.         end;
  250.  
  251.     {$I-} Reset(stat_file) {$I+};
  252.     if IOresult = 0
  253.       then read(stat_file, stat_rec)
  254.       else
  255.         begin
  256.           Write(BEL, 'Statistics file not found.  Creating ', stat_name, ext);
  257.           Rewrite(stat_file);
  258.           GetTAD(stat_rec.date);
  259.           for i := 0 to 23 do
  260.             stat_rec.busy_per_hour[i]  := 0;
  261.           for i := 0 to 6 do
  262.             stat_rec.busy_per_day[i]  := 0;
  263.           Writeln
  264.         end;
  265.  
  266.     {$I-} Reset(nwin_file) {$I+};
  267.     if IOresult <> 0
  268.       then
  269.         begin
  270.           Write(BEL, 'Newin file not found.  Creating ', nwin_name, ext);
  271.           Rewrite(nwin_file);
  272.           Writeln
  273.         end;
  274.  
  275.     if cold
  276.       then
  277.         begin
  278.           log(0, '');
  279.           cold := FALSE
  280.         end
  281.   end;
  282.  
  283. overlay procedure wait_for_user;
  284. { Wait for call or console interrupt }
  285.   var
  286.     ch: char;
  287.     count: integer;
  288.   begin
  289.     ClrScr;
  290.     if delay_down
  291.       then
  292.         begin
  293.           putstat('Waiting for delayed shutdown acknowledgement...');
  294.           mdbusy                            { Make modem busy }
  295.         end
  296.       else
  297.         begin
  298.           putstat(version + ' as of ' + ver_date + '.  Copyright (c) 1985 by Steve Fox.');
  299.           mdinit                            { Get modem ready }
  300.         end;
  301.     count := 0;
  302.     repeat
  303.       count := succ(count);
  304.       if count > 8000
  305.         then
  306.           begin
  307.             putstat('');
  308.             GotoXY(succ(Random(79)), succ(Random(23)));
  309.             count := 0
  310.           end;
  311.       if delay_down
  312.         then Write(BEL);
  313.       ch := GetChar;
  314.       if ch = ETX
  315.         then
  316.           begin
  317.             putstat('Busy modem? ');
  318.             read(KBD, ch);
  319.             if UpCase(ch) = 'Y'
  320.               then mdbusy
  321.               else mdhangup;
  322.             putstat('ROS completing...');
  323.             log(1, '');
  324.             CloseFile(DatF);
  325.             CloseIndex(IdxF);
  326.             Close(sysm_file);
  327.             Close(summ_file);
  328.             Close(mesg_file);
  329.             Close(logr_file);
  330.             Close(stat_file);
  331.             Close(nwin_file);
  332.             fini := TRUE
  333.           end
  334.       else if ch = CR
  335.         then
  336.           begin
  337.             putstat('Local use requested');
  338.             mdbusy;
  339.             rate := 1200;                   { Pretend we're running at 1200 bps }
  340.             local_online := TRUE
  341.           end
  342.       else if mdring
  343.         then
  344.           begin
  345.             putstat('Ring detected');
  346.             mdans;
  347.             remote_online := ch_carck;
  348.             remote_copy   := remote_online;
  349.             if remote_online
  350.               then putstat('Connect at ' + intstr(rate, 3) + ' bps')
  351.           end
  352.     until fini or local_online or remote_online;
  353.     delay_down := FALSE
  354.   end;
  355.  
  356. overlay procedure cold_start;
  357. { One-time initialization routine }
  358.   var
  359.     b: byte;
  360.     SDrive: char;
  361.     i, BufferPtr, remaining, SUser, SAccs: integer;
  362.     SysmThis, SysmLast: SysmPtr;
  363.     SectThis, SectLast: SectPtr;
  364.     AreaThis, AreaLast: AreaPtr;
  365.     SName: Str10;
  366.     SDesc: StrPr;
  367.     sect_file: text;
  368.     sysm_text: file;
  369.  
  370.   procedure build_sysm;
  371.   { Build SYSMSG.BB# file }
  372.     begin
  373.       {$I-} Close(sysm_file) {$I+};         { Shouldn't erase an open file }
  374.       i := IOresult;                        { Ignore any errors }
  375.       Rewrite(sysm_file);
  376.       Assign(sysm_text, sysm_name + '.TXT');
  377.       {$I-} Reset(sysm_text) {$I+};
  378.       if IOresult = 0
  379.         then
  380.           begin
  381.             Write('  Creating ', sysm_name, ext);
  382.             BufferPtr := maxint;
  383.             remaining := FileSize(sysm_text);
  384.             b := $7F and getc(sysm_text, BufferPtr, remaining);
  385.             sysm_rec := '';
  386.             while b <> 26 do
  387.               begin
  388.                 if b = 10
  389.                   then
  390.                     begin
  391.                       Write(sysm_file, sysm_rec);
  392.                       sysm_rec := ''
  393.                     end
  394.                   else if b >= 32
  395.                     then sysm_rec := sysm_rec + char(b);
  396.                   b := $7F and getc(sysm_text, BufferPtr, remaining)
  397.               end;
  398.             Close(sysm_text);
  399.             Close(sysm_file);
  400.             Reset(sysm_file)
  401.           end
  402.         else
  403.           begin
  404.             Writeln;
  405.             Write('System message text file not found.  ', sysm_name, ext, ' will be empty.')
  406.           end;
  407.       Writeln
  408.     end;
  409.  
  410.   begin
  411.     cold        := TRUE;
  412.  
  413.     audit_on    := FALSE;                   { No audit file initially }
  414.     delay_down  := FALSE;                   { Don't shut down yet }
  415.     in_library  := FALSE;                   { Start in non-library mode }
  416.  
  417.     SysmBase    := nil;                     { Start with empty system message, }
  418.     SectBase    := nil;                     {   section, }
  419.     AreaBase    := nil;                     {   message area, }
  420.     MesgBase    := nil;                     {   message, }
  421.     DirBase     := nil;                     {   directory, }
  422.     LibBase     := nil;                     {   and library lists }
  423.  
  424.     UsrOutPtr   := addr(putchar);           { Initialize output driver }
  425.  
  426.     HomDrv      := BDOS(getdrive);          { Assume system files are }
  427.     HomUsr      := BDOS(getseluser, $FF);   {   in the startup area }
  428.  
  429.     Assign(sysm_file, sysm_name + ext);
  430.     Assign(summ_file, summ_name + ext);
  431.     Assign(mesg_file, mesg_name + ext);
  432.     Assign(logr_file, logr_name + ext);
  433.     Assign(sect_file, sect_name + ext);
  434.     Assign(stat_file, stat_name + ext);
  435.     Assign(nwin_file, nwin_name + ext);
  436.  
  437.     {$I-} Reset(sysm_file) {$I+};           { Try to open system message file }
  438.     if IOresult <> 0
  439.       then
  440.         begin
  441.           Write('Cannot open ', sysm_name + ext, '.');
  442.           build_sysm
  443.         end;
  444.  
  445.     {$I-} read(sysm_file, sysm_rec) {$I+};  { Try to read file }
  446.     if IOresult <> 0
  447.       then
  448.         begin
  449.           Write('Cannot read ', sysm_name + ext, '.');
  450.           build_sysm;
  451.           seek(sysm_file, 0);
  452.           {$I-} read(sysm_file, sysm_rec) {$I+};
  453.           if IOresult <> 0
  454.             then
  455.               begin
  456.                 Writeln('Still cannot read ', sysm_name + ext, '.');
  457.                 Writeln('Unable to continue.');
  458.                 halt
  459.               end
  460.         end;
  461.  
  462.     i := 0;
  463.     while not EOF(sysm_file) do
  464.       begin
  465.         if sysm_rec[1] = ':'
  466.           then
  467.             begin
  468.               new(SysmThis);
  469.               if SysmBase = nil
  470.                 then SysmBase := SysmThis
  471.                 else SysmLast^.next := SysmThis;
  472.               SysmLast := SysmThis;
  473.               SysmLast^.key := sysm_rec[2];
  474.               SysmLast^.loc := i;
  475.               SysmLast^.next := nil
  476.             end;
  477.         read(sysm_file, sysm_rec);
  478.         i := succ(i)
  479.       end;
  480.  
  481.     RcvDrv := 0;                            { Default to A0: for uploads }
  482.     RcvUsr := 0;
  483.     {$I-} Reset(sect_file) {$I+};           { Build file and message section lists }
  484.     OK := (IOresult = 0);
  485.     if OK
  486.       then
  487.         begin
  488.           while not EOF(sect_file) do
  489.             begin
  490.               readln(sect_file, SDrive, SUser, SAccs, SName, SDesc);
  491.               if SDrive = ' '
  492.                 then
  493.                   begin
  494.                     new(AreaThis);
  495.                     if AreaBase = nil
  496.                       then AreaBase := AreaThis
  497.                       else AreaLast^.next := AreaThis;
  498.                     AreaLast := AreaThis;
  499.                     AreaLast^.Area := SUser;
  500.                     AreaLast^.AreaAccs := SAccs;
  501.                     AreaLast^.AreaName := trim(SName);
  502.                     AreaLast^.AreaDesc := trim(SDesc);
  503.                     AreaLast^.next := nil
  504.                   end
  505.               else if SDrive <> ' '
  506.                 then
  507.                   begin
  508.                     new(SectThis);
  509.                     if SectBase = nil
  510.                       then SectBase := SectThis
  511.                       else SectLast^.next := SectThis;
  512.                     SectLast := SectThis;
  513.                     SectLast^.SectDrive := ord(SDrive) - ord('A');
  514.                     SectLast^.SectUser := SUser;
  515.                     SectLast^.SectAccs := SAccs;
  516.                     SectLast^.SectName := trim(SName);
  517.                     SectLast^.SectDesc := trim(SDesc);
  518.                     SectLast^.next := nil
  519.                   end
  520.             end;
  521.           Close(sect_file);
  522.           FindSect('NEWIN', RcvDrv, RcvUsr, OK);
  523.           if not OK
  524.             then Writeln(BEL, 'NEWIN section not found.');
  525.         end
  526.       else Writeln(BEL, 'Section file not found.');
  527.   end;
  528.  
  529.