Unit UserStuf;

Interface
 Function  LoadUserInfo(Alias : String) : Boolean; (* False if Not Exist *)
 Procedure WriteToLog(S : String);
 Procedure Apply;
 Function  writeuserInfo(XX:LONGINT) : Boolean; (* False if Not Exist *)
 function  finduser(s:String;saveit:boolean):longint;
 Procedure UserList;
 Function  Getansimode : Boolean;  { Tests for Ansi, True if Ansi }
 Function  Allowed_Baud : Boolean; { Tests BaudRate, True if > lowbaud }
 Function  GetUser : Boolean;      { Asks for Name/Password, True if Login }

Implementation

Uses Dos,Crt,Records,GenStr,IO,protcomm,timeing,barinfo,menu;

Function GetUser : Boolean;
Var Answer    : String[50];
Begin
 Infobar(CurrentBar,'');
 Fillchar(User,SizeOf(User),#0);
 User.Time := 10;
 Infobar(CurrentBar,'');
 GOXY(BASICMCI[7].X,BASICMCI[7].Y);
 buflen:=30;
 sreadln(answer);
 If LoadUserInfo(Answer)=false then
  Begin
   passwordit:=false;
   GetUser := False;
   Fillchar(User,SizeOf(User),#0);
   user.time:=10;
   timeleft:=10;
   Exit;
  End;
 Infobar(CurrentBar,'');
 GOXY(BASICMCI[8].X,BASICMCI[8].Y);
 hide:=true;
 sreadln(Answer);
 hide:=false;
 GetUser := (uppercase(Answer) = uppercase(User.Password));
 If uppercase(Answer) <> uppercase(User.Password) then begin
 passwordit:=false;
 Fillchar(User,SizeOf(User),#0);
 end;
 User.Time := 6;
 InfoBar(CurrentBar,'');
End;

Function Getansimode : Boolean;
var T : String[80];
begin
 AnsiClr;
 print(showstring(22));
 Awrite(#27);
 Delay(30);Awrite('[');
 Delay(30);Awrite('6');
 Delay(30);Awrite('n');
 Delay(4000);
 T := '';
 While dataavailable do T := T + Chr(GetChar);
 GetansiMode := Pos('2;1R',T) > 0;
 wleng:=255;
End;

Function Allowed_Baud : Boolean;
var baudpass : string[30];
    X : Byte;
Begin
 Allowed_Baud := True;
 If Localon then Exit;
 If Connectbaud < Config.LowestBaud then Allowed_Baud := False;
 If Allowed_Baud then Exit;
 Swrite('Lockout Baud Password:');
 hide:=true;
 sreadln(baudpass);
 hide:=false;
 For X := 1 to Length(Baudpass) do Baudpass[X] := Upcase(Baudpass[X]);
 For X := 1 to Length(Config.BadbaudPW) do Baudpass[X] := Upcase(config.badBaudpw[X]);
 If baudpass = Config.BadBaudPw then
  Begin
   Allowed_baud:=true;
   Exit;
  End;
 swriteln('Sorry Wrong Password!');
 Allowed_Baud := False;
End;

Procedure UserList;
Var Uzer : UserRec;
    UFile : File of UserRec;
    TFile : Text;
    X : Word;
    usermci:mcis;

Begin
 Assign(UFile,CONFIG.DATA_DIR+'USER.DAT');
{$I-} Reset(UFile); {$I+}
 IF IORESULT<>0 THEN EXIT;
 fillchar(usermci,sizeof(usermci),#0);

 usermci[1].mci:='~ID';
 usermci[2].mci:='~UN';
 usermci[3].mci:='~LO';
 usermci[4].mci:='~SX';
 usermci[5].mci:='~UC';
 usermci[6].mci:='~SL';

 printfile(Config.Textfile_Dir+'userl.top',basicmci,false);
 For X := 1 to Filesize(UFile) do
  Begin
  Read(UFile,Uzer);
  USERMCI[1].STR:=strr(X);
  usermci[2].str:=uzer.alias;
  usermci[3].str:=uzer.location;
  usermci[4].str:=uzer.sex;
  usermci[5].str:=strr(uzer.calls);
  usermci[6].str:=strr(uzer.mainlev);

  printfile(Config.Textfile_Dir+'userl.mid',USERMCI,false);
  End;
  printfile(Config.Textfile_Dir+'userl.bot',basicmci,false);
  Close(UFile);
End;

Function UserExist(handle : String) : Boolean;
Begin
 Fillchar(User,Sizeof(User),#0);
 UserExist := LoadUserInfo(Handle);
 Fillchar(User,Sizeof(User),#0);
                   user.time:=10;
                   user.timeperday:=10;
                   timeleft:=10;

End;


Function LoadUserInfo(Alias : String) : Boolean; (* False if Not Exist *)
Var X : Word;
Begin
 Assign(UserF,Config.Data_Dir+'USER.DAT');
 {$I-} Reset(UserF); {$I+}
 if ioresult<>0 then rewrite(userf);
 LoadUserInfo := False;
 if valu(alias) IN [1..FILESIZE(USERF)] then
                       begin
                       SEEK(USERF,VALU(ALIAS)-1);
                       READ(USERF,USER);
                       LOADUSERINFO:=TRUE;
                       Close(UserF);
                       EXIT;
                       end;

 For X := 1 to FileSize(UserF) do
  Begin
   Seek(UserF,X-1);
   Read(UserF,User);
   If (uppercase(alias)=uppercase(User.Alias)) or (uppercase(alias) = uppercase(User.RealName)) then
    Begin
     LoadUserInfo := True;
     Close(UserF);
     Exit;
    End;
  End;
 Close(UserF);
End;

function finduser(s:String;saveit:boolean):longint;
Var X : Word;
    tempu:userrec;
Begin
 Assign(UserF,Config.Data_Dir+'USER.DAT');
 {$I-} Reset(UserF); {$I+}
 if ioresult<>0 then rewrite(userf);

 For X := 1 to FileSize(UserF) do
  Begin
   Seek(UserF,X-1);
   Read(UserF,tempu);
   If (uppercase(s)=uppercase(tempu.Alias)) or (uppercase(s) = uppercase(tempu.RealName)) then
    Begin
     finduser:=x-1;
     Close(UserF);
     if saveit=true then user:=tempu;
     Exit;
    End;
  End;
 Close(UserF);
     if saveit=true then user:=tempu;
End;


Function writeuserInfo(XX:LONGINT) : Boolean; (* False if Not Exist *)
Var X : Word;
    G : USERREC;
Begin
 Assign(UserF,Config.Data_Dir+'USER.DAT');
 {$i-} reset(userf); {$i+}
 if ioresult<>0 then rewrite(userf);
 SEEK(USERF,XX);
 WRITE(USERF,USER);
 CLOSE(USERF);
End;

Procedure WriteToLog(S : String);
Var Year,Month,Day,DOW : Word;
    Hour,Minute,Second,MSec : Word;
    LogFile : Text;
Begin
 GetDate(Year,Month,Day,DOW);
 GetTime(Hour,Minute,Second,MSec);
 Assign(LogFile,Config.Data_Dir+'SLOG_'+Strr(Config.NodeNumber)+'.'+Strr(DOW));
 {$I-} Append(LogFile); {$I+}
 If IOResult <> 0 then Rewrite(LogFile);
 Write(LogFile,'-<'+Strr(Month)+'-'+Strr(Day)+'-'+Strr(Year)+'   '+Strr(Hour)+':'+Strr(Minute)+'>- ');
 Writeln(LogFile,S);
 Close(LogFile);
End;


Procedure Apply;

Function CheckExit : Boolean;
Begin
 print(showstring(9));{p_AbortApp);}
 CheckExit := AnsiYn('|15|17 Yes ','|16|07 Yes ','|15|17 No ','|16|07 No ',false);
End;

Var TempInput : String[50];
    X : Word;
   TmpUser : UserRec;
Label AskHandle,AskName,AskPasswd;
Begin
{ Fillchar(User,SizeOf(User),#0);}
                   user.time:=10;
                   user.timeperday:=10;
                   timeleft:=10;
 { Get Handle }
 AskHandle:
 print(showstring(10));{ap_EnterHandle);}
 tempinput:='';
 sreadln(tempinput);
 If Length(TempInput) < 2 then
  Begin
  If CheckExit then Exit else goto AskHandle;
  End;

 print(showstring(11));{ap_CheckHandle);}

 If UserExist(TempInput) then
  Begin
   print(showstring(12));{Ap_HandleBad);}
   Goto AskHandle;
  End;

 User.Alias := TempInput;
 { Get Real Name Name }
 AskName:
 print(showstring(13));{ap_EnterName);}
 sreadln(tempinput);
 If Length(TempInput) < 2 then
  Begin
   If CheckExit then Exit else goto AskName;
  End;
 If (Pos(' ',TempInput) = 0) or (TempInput = ' ') then
  Begin
   print(showstring(14));{Ap_NameBad);}
   Goto AskName;
  End;
 User.RealName := TempInput;
 print(showstring(15));{Ap_PhoneNumber);}
 SPhoneInput(TempInput);
 User.Phone := TempInput;
 print(showstring(16));{ap_UserNote);}
 sreadln(tempinput);
 User.UserNote := TempInput;
 AskPasswd:
 Fillchar(User.Password,SizeOf(User.Password),#0);
 print(showstring(17));{ap_Password);}
 buflen:=30;
 sreadln(tempinput);
 If (TempInput = '') then Goto AskPasswd;
 User.Password := TempInput;
 print(showstring(19));{Ap_ReenterPw);}
 buflen:=30;
 sreadln(tempinput);
 If (TempInput <> User.Password) then
  Begin
   print(showstring(18));{ap_PWBad);}
   Goto AskPasswd;
  End;
 print(showstring(20));{Ap_Xpert);}
 User.XPerMode := AnsiYn('|15|17 Yes ','|16|07 Yes ','|15|17 No ','|16|07 No ',false);
 println('');
 print(showstring(21));{Ap_FSE);}
 User.FSE := AnsiYn('|15|17 Yes ','|16|07 Yes ','|15|17 No ','|16|07 No ',true);
 println('');
 print(showstring(22));{Ap_Ansi);}
 User.Ansi := AnsiYn('|15|17 Yes ','|16|07 Yes ','|15|17 No ','|16|07 No ',true);
 println('');
 print('|B0|09Scr Length [24]: ');
 tempinput:='24';
 buflen:=2;
 editline(tempinput);
 user.scrln:=valu(tempinput);
 print(showstring(23));{Ap_Filing);}
 println('');
 user.MainLev     := 1;
 user.FileLev     := 1;
 user.Flags       := '                          ';
 user.SysOpNote   := 'New User';
 user.AllowPage   := True;
 user.UserLog     := False;
 user.LogUser     := False;
 user.PCR         := 0;
 user.UDRatio     := 0;
 user.Credits     := 5000;
 user.Uploads     := 0;
 user.Downloads   := 0;
 user.BytesUp     := 0;
 user.BytesDown   := 0;
 user.Posts       := 0;
 user.Calls       := 0;
 user.CallsPerDay := 1000;
 user.prompt      := 1;
 user.LastCall    := 0;
 user.TimePerDay  := 10;
 user.Time        := 10;
 Assign(UserF,Config.Data_Dir+'USER.DAT');
 {$I-} Reset(UserF); {$I+}
 If IOResult <> 0 then Rewrite(UserF);
     seek(userf,filesize(userf));
     Write(UserF,User);
     Close(UserF);
 print(showstring(24));{Ap_Note);}
 print(showstring(25));{Ap_CallbackLater);}
 Fillchar(TmpUser,SizeOf(TmpUser),#0);
End;
End.
