home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 270.img / FORUM25C.ZIP / CHATSTUF.PAS < prev    next >
Pascal/Delphi Source File  |  1989-01-20  |  11KB  |  462 lines

  1. {$R-,S-,I-,D-,V-,B-,N-,L- }
  2. {$O+}
  3.  
  4. unit chatstuf;
  5.  
  6.  
  7. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  8.  
  9. INTERFACE
  10.  
  11. Uses Overlay,
  12.      crt,
  13.      gentypes,
  14.      gensubs,
  15.      subs1,
  16.      userret,
  17.      flags,
  18.      mainr1,
  19.      modem,
  20.      windows,
  21.      statret,
  22.      Shell,
  23.      configrt;
  24.  
  25. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  26.  
  27. Function specialcommand:boolean;
  28. Procedure specialseries;
  29. Procedure chat;
  30.  
  31. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  32.  
  33. implementation
  34.  
  35. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  36.  
  37. Function specialcommand:boolean;
  38.  
  39.   Procedure getnewtime;
  40.   VAR q:sstr;
  41.       n:integer;
  42.   begin
  43.     n:=timeleft;
  44.     writeln (usr,'The user has ',n,' minutes left.');
  45.     write (usr,'New time left for today? ');
  46.     readline (q);
  47.     if length(q)>0 then begin
  48.       urec.timetoday:=urec.timetoday+(valu(q)-n);
  49.       writeurec;
  50.       writeln ('You have been granted ',timeleft,' minutes for today.')
  51.     end
  52.   end;
  53.  
  54.   Procedure getnewlevel;
  55.   VAR q:sstr;
  56.       n:integer;
  57.   begin
  58.     writeln (usr,'Current level: ',ulvl);
  59.     write (usr,'New level [-1 to trash]: ');
  60.     readline (q);
  61.     if length (q)>0 then begin
  62.      n:=valu(q);
  63.      ulvl:=n;
  64.      urec.level:=n;
  65.      writeurec;
  66.      writeln ('You have been granted level ',n,' access.');
  67.      if n=-1 then writeln ('That means you''ve been thrown off this system.')
  68.     end
  69.   end;
  70.  
  71.   Procedure getnewaccess;
  72.   VAR q,bname:sstr;
  73.       bn:integer;
  74.       ac:accesstype;
  75.       wasopen:boolean;
  76.       k:char;
  77.  
  78.     Function inputaccess (q:sstr):accesstype;
  79.     begin
  80.       inputaccess:=invalid;
  81.       if length(q)=0 then exit;
  82.       case upcase(q[1]) of
  83.         'L':inputaccess:=letin;
  84.         'B':inputaccess:=bylevel;
  85.         'K':inputaccess:=keepout
  86.       end
  87.     end;
  88.  
  89.     Procedure getallaccess;
  90.  
  91.       Procedure setallaccess (ac:accesstype);
  92.       VAR cnt:integer;
  93.       begin
  94.         setalluserflags (urec,ac);
  95.         writeln ('Your access to all sub-boards: ',accessstr[ac]);
  96.         writeurec
  97.       end;
  98.  
  99.     begin
  100.       write (usr,'Grant ALL access ([B]y level, [L]et in, [K]eep out, or CR): ');
  101.       readline (q);
  102.       ac:=inputaccess(q);
  103.       if ac<>invalid then setallaccess(ac)
  104.     end;
  105.  
  106.   VAR bd:boardrec;
  107.   begin
  108.     write (usr,'Which board for which to change access [*=all]: ');
  109.     readline (bname);
  110.     if length(bname)=0 then exit;
  111.     if bname='*' then
  112.       begin
  113.         getallaccess;
  114.         exit
  115.       end;
  116.     opentempbdfile;
  117.     bn:=searchboard(bname);
  118.     if bn=-1 then
  119.       begin
  120.         closetempbdfile;
  121.         writeln (usr,'No such board!  Press any key..');
  122.         k:=bioskey;
  123.         exit
  124.       end;
  125.     writeln (usr,'Board ',bname,'... Current access: ',
  126.       accessstr[getuseraccflag(urec,bn)]);
  127.     write (usr,'Grant access ([B]y level, [L]et in, [K]eep out, or CR: ');
  128.     readline (q);
  129.     ac:=inputaccess(q);
  130.     if ac=invalid then begin
  131.       closetempbdfile;
  132.       exit
  133.     end;
  134.     setuseraccflag (urec,bn,ac);
  135.     writeurec;
  136.     closetempbdfile;
  137.     writeln ('New access for board ',bname,': ',accessstr[ac])
  138.   end;
  139.  
  140.   Procedure hangupyn;
  141.   VAR q:sstr;
  142.   begin
  143.     write (usr,'Hang up on him (Y/N)? ');
  144.     readline (q);
  145.     if length(q)>0 then if upcase(q[1])='Y' then
  146.       begin
  147.         writeln ('*** System going down ***    '^M^M);
  148.         hangup;
  149.         forcehangup:=true;
  150.         specialcommand:=true
  151.       end
  152.   end;
  153.  
  154.   Procedure getnewname;
  155.   VAR m:mstr;
  156.       n:integer;
  157.       t:string[1];
  158.   begin
  159.     writeln (usr,'Current name: ',unam);
  160.     write (usr,'New name: ');
  161.     readline (m);
  162.     if length(m)<>0 then begin
  163.       if not validuname(m) then begin
  164.         writeln (usr,'Invalid name!');
  165.         exit
  166.       end;
  167.       n:=lookupuser(m);
  168.       if n<>0 then begin
  169.         write (usr,'Name already exists!  Are you sure? ');
  170.         buflen:=1;
  171.         readline (t);
  172.         if upcase(t[1])<>'Y' then exit
  173.       end;
  174.       unam:=m;
  175.       urec.handle:=m;
  176.       writeurec;
  177.       writeln ('Your name is changed to ',unam,'.')
  178.     end
  179.   end;
  180.  
  181.   Procedure getnewpassword;
  182.   VAR m:mstr;
  183.   begin
  184.     writeln (usr,'Current password: ',urec.password);
  185.     write (usr,'New password: ');
  186.     readline (m);
  187.     if length(m)<>0 then begin
  188.       urec.password:=m;
  189.       writeurec;
  190.       writeln ('Your password has been changed.')
  191.     end
  192.   end;
  193.  
  194.   Procedure getnewud;
  195.   VAR m:mstr;
  196.  
  197.     Procedure getnewud1 (VAR i:integer; q:sstr);
  198.     begin
  199.       if length(m)>1
  200.         then i:=valu(copy(m,2,255))
  201.         else begin
  202.           writeln (usr,'New file transfer '+q+'? ');
  203.           readline (m);
  204.           if length(m)=0
  205.             then exit
  206.             else i:=valu(m)
  207.         end;
  208.       writeln ('New file transfer ',q,': ',i);
  209.       writeurec
  210.     end;
  211.  
  212.   begin
  213.     writeln (usr,'Current upload L)evel:  ',urec.udlevel);
  214.     writeln (usr,'Current upload P)oints: ',urec.udpoints);
  215.     write (usr,'Enter L, P, or CR for neither: ');
  216.     readline (m);
  217.     if length(m)>0 then begin
  218.       case upcase(m[1]) of
  219.         'L':getnewud1 (urec.udlevel,'level');
  220.         'P':getnewud1 (urec.udpoints,'points')
  221.       end
  222.     end
  223.   end;
  224.  
  225.   Procedure snoopmode;
  226.   begin
  227.     writeln (usr,'All I/O to the modem is locked.');
  228.     modeminlock:=true;
  229.     setoutlock (true)
  230.   end;
  231.  
  232.   Procedure unsnoop;
  233.   begin
  234.     writeln (usr,'I/O to the modem is re-enabled.');
  235.     modeminlock:=false;
  236.     setoutlock (false)
  237.   end;
  238.  
  239.   Procedure Gotodos;
  240.   VAR ReturnCode : INTEGER;
  241.   Begin
  242.     Writeln ('The sysop has dropped into DOS; please wait...');
  243.     Window (1,1,80,25);
  244.  
  245.  {   gotoxy (1,25);
  246.     Writeln (usr,^M^J^J^J);
  247.     Updateuserstats (false);
  248.     Writereturnbat;
  249.     Ensureclosed;
  250.     Halt (4)   }
  251.  
  252.     ClrScr;
  253.     ReturnCode := Dos_Exec('',FALSE,FALSE);
  254.     Writeln(USR,'Return: ',Returncode);
  255.   End;
  256.  
  257.   Procedure getsysopaccess;
  258.   const sysopstr:array [false..true] of string[6]=('Normal','Sysop');
  259.         sectionnames:array [udsysop..databasesysop] of string[20]=
  260.           ('File transfer','Bulletin section','Voting booths',
  261.            'E-mail section','Doors','Main menu','Databases');
  262.   VAR cnt:configtype;
  263.       x:string[10];
  264.       n,mx:integer;
  265.       v:boolean;
  266.   begin
  267.     repeat
  268.       clrscr;
  269.       mx:=1;
  270.       for cnt:=udsysop to databasesysop do begin
  271.         write (usr,mx:3,'. ',sectionnames[cnt]);
  272.         mx:=mx+1;
  273.         gotoxy (25,wherey);
  274.         writeln (usr,sysopstr[cnt in urec.config])
  275.       end;
  276.       write (usr,^M^J'Number to toggle [CR to exit]: ');
  277.       buflen:=1;
  278.       readline (x);
  279.       n:=valu(x);
  280.       v:=(n>0) and (n<mx);
  281.       if v then begin
  282.         cnt:=configtype(ord(udsysop)+n-1);
  283.         if cnt in urec.config
  284.           then
  285.             begin
  286.               urec.config:=urec.config-[cnt];
  287.               x:='denied'
  288.             end
  289.           else
  290.             begin
  291.               urec.config:=urec.config+[cnt];
  292.               x:='granted'
  293.             end;
  294.         writeln ('You have been ',x,' sysop priveleges for the ',
  295.                  sectionnames[cnt],'.')
  296.       end
  297.     until not v;
  298.     writeurec
  299.   end;
  300.  
  301. VAR scom:sstr;
  302.     k:char;
  303. begin
  304.   writeln (^B^M'One moment please...');
  305.   splitscreen (12);
  306.   top;
  307.   clrscr;
  308.   specialcommand:=false;
  309.   writeln (usr,'Special commands:');
  310.   writeln (usr,'N)ame, P)assword, L)evel, T)ime left, B)oard access, H)ang up, U)UD section,');
  311.   writeln (usr,'Y)Sysop access, S)noop, Z)unsnoop, D)OS, Q)uit');
  312.   write (usr,'---> ');
  313.   readline (scom);
  314.   clearbreak;
  315.   k:=' ';
  316.   if length(scom)>0 then begin
  317.     k:=upcase(scom[1]);
  318.     case k of
  319.       'L' : getnewlevel;
  320.       'B' : getnewaccess;
  321.       'H' : hangupyn;
  322.       'N' : getnewname;
  323.       'P' : getnewpassword;
  324.       'L' : getnewlevel;
  325.       'T' : getnewtime;
  326.       'U' : getnewud;
  327.       'S' : snoopmode;
  328.       'Z' : unsnoop;
  329.       'Y' : getsysopaccess;
  330.       'D' : gotodos;
  331.     End
  332.   End;
  333.   bottomline;
  334.   specialcommand:=k in ['Q','S','Z'];
  335.   unsplit
  336. end;
  337.  
  338. Procedure specialseries;
  339. begin
  340.   repeat until specialcommand
  341. end;
  342.  
  343. Procedure chat;
  344. VAR k:char;
  345.     cnt,displaywid:integer;
  346.     quit,carrierloss,fromkbd:boolean;
  347.     linebuffer:lstr;
  348.     l:byte absolute linebuffer;
  349.     curcolor:byte;
  350.  
  351.   Procedure instruct;
  352.   begin
  353.     splitscreen (3);
  354.     top;
  355.     clrscr;
  356.     write (usr,'Now in chat mode.  Press <F1> to leave or <F2> for commands.');
  357.     bottom
  358.   end;
  359.  
  360.   Procedure wordwrap;
  361.   VAR cnt,wl:integer;
  362.       ww:lstr;
  363.   begin
  364.     ww:='';
  365.     cnt:=displaywid;
  366.     while (cnt>0) and (linebuffer[cnt]<>' ') do cnt:=cnt-1;
  367.     if cnt=0 then ww:=k else begin
  368.       ww:=copy(linebuffer,cnt+1,255);
  369.       wl:=length(ww)-1;
  370.       if wl>0 then begin
  371.         for cnt:=1 to wl do write (^H);
  372.         for cnt:=1 to wl do write (' ')
  373.       end
  374.     end;
  375.     writeln;
  376.     ansicolor (curcolor);
  377.     write (ww);
  378.     linebuffer:=ww
  379.   end;
  380.  
  381.   Procedure typedchar (k:char);
  382.   VAR ec:byte;
  383.   begin
  384.     l:=l+1;
  385.     linebuffer[l]:=k;
  386.     if fromkbd then ec:=urec.regularcolor else ec:=urec.inputcolor;
  387.     if curcolor<>ec then begin
  388.       curcolor:=ec;
  389.       ansicolor (curcolor)
  390.     end;
  391.     if l=displaywid then wordwrap else write(k)
  392.   end;
  393.  
  394. VAR Ch : CHAR;
  395. begin
  396.   While Keypressed DO
  397.     Ch := ReadKey;
  398.   Writeln(^M);
  399.   carrierloss := false;
  400.   chatmode := false;
  401.   InChat := TRUE;
  402.   writeln(^B);
  403.   if (wanted in urec.config) AND (Ulvl < 90)  then begin
  404.     specialmsg ('(No longer wanted)');
  405.     urec.config:=urec.config-[wanted];
  406.     writeurec;
  407.   end;
  408.   if eightycols in urec.config then displaywid:=80 else displaywid:=40;
  409.   if length(chatreason)>0 then specialmsg ('(Chat reason: '+chatreason+')');
  410.   chatreason:='';
  411.   clearbreak;
  412.   nobreak := TRUE;
  413.   Writeln (sysopname,' is here.'^M);
  414.   instruct;
  415.   quit:=false;
  416.   l:=0;
  417.   curcolor:=urec.regularcolor;
  418.   repeat
  419.     linecount:=0;
  420.     if (not carrierloss) and (not carrier) then begin
  421.       carrierloss:=true;
  422.       writeln (^M'No one''s here to chat with!'^M)
  423.     end;
  424.     repeat until keyhit or (carrier and (numchars>0));
  425.     fromkbd:=keyhit;
  426.     ingetstr:=true;
  427.     read(directin,k);
  428.     if k=#127 then k:=#8;
  429.     Quit := NOT Inchat;
  430.     case ord(k) of
  431.       8:if l>0 then begin
  432.           write (k+' '+k);
  433.           l:=l-1
  434.         end;
  435.       0:;
  436.       13:begin
  437.            writeln;
  438.            bottomline;
  439.            l:=0
  440.          end;
  441.       32..126:typedchar (k);
  442.       1..31:if fromkbd and carrier then sendchar(k)
  443.     end
  444.   until quit;
  445.   UnSplit;
  446.   ClearBreak;
  447. {  Writeln(^M);    }
  448. End;
  449.  
  450. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  451.  
  452. {initialization}
  453.  
  454. {/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\}
  455.  
  456.  
  457. Begin
  458.   Chat_proc := Chat;
  459.   Command_proc := Specialseries;
  460.   InChat := FALSE;
  461. End.
  462.