Unit Init;
interface
uses crt,dos,genstr,records;

Procedure Start_Init;
Procedure Read_In_Config;
implementation

procedure writeinitbox (s:string);
  begin
    pipewrite('|B0|01=|09> |11'+s+' |09<|01=');
    writeln;
  end;

Procedure Config_Error(str:string);
begin
writeinitbox(str);
halt(100);
end;

Procedure Config_Error2(str:string;dir:String);
begin
if dir[length(dir)]='\' then dec(dir[0]);
writeinitbox(str);
mkdir(dir);
end;

Procedure Read_In_Config;
Var Temp : String;
 begin
   assign(configf,'LUCID.CFG');
 {$I-}   reset(configf); {$I+}
    if ioresult<>0 then config_error('Lucid.cfg Does Not Exist, Please Configur Lucid ');
    writeinitbox('Reading In Configuration');
  {--}
   With Config do
    Begin
     Readln(ConfigF,LongName);
     Readln(ConfigF,Shortname);
     Readln(ConfigF,SysOpName);
     Readln(ConfigF,BoardPhone);
     Readln(ConfigF,RegistrationCode);
     Readln(ConfigF,NodeNumber);
     Readln(ConfigF,TotalNodes);
     Readln(ConfigF,DefaultUserNote);
     Readln(ConfigF,Temp);
     If Pos('T',Temp) <> 0 then Use_NUV := True else Use_NUV := False;
     Readln(ConfigF,Temp);
     If Pos('T',Temp) <> 0 then Use_SPW := True else Use_SPW := False;
    {----------------------- Passwords & Shit ----------------------}
     Readln(ConfigF,NUPS[1]);
     Readln(ConfigF,NUPS[2]);
     Readln(ConfigF,NUPS[3]);
     Readln(ConfigF,NUPS[4]);
     Readln(ConfigF,NUPS[5]);
     Readln(ConfigF,NUPAccess[1]);
     Readln(ConfigF,NUPAccess[2]);
     Readln(ConfigF,NUPAccess[3]);
     Readln(ConfigF,NUPAccess[4]);
     Readln(ConfigF,NUPAccess[5]);
     Readln(ConfigF,SystemPW);
     Readln(ConfigF,BadBaudPW);
     Readln(ConfigF,ShellPW);
     Readln(ConfigF,ExitPW);
     Readln(ConfigF,SysOpPW);
     Readln(ConfigF,ChatPW);
    {------------------------- Directory Shit ----------------------}
    Readln(ConfigF,Lucid_dir);
    Readln(ConfigF,Text_dir);
    Readln(ConfigF,Board_Dir);
    Readln(ConfigF,Data_Dir);
    Readln(ConfigF,Textfile_dir);
    Readln(ConfigF,Door_dir);
    Readln(ConfigF,work_dir);
    Readln(ConfigF,menu_dir);
    Readln(ConfigF,prot_dir);
    readln(configf,arch_dir);
    Readln(ConfigF,Extract_dir);
    {-------------------------- Modem Shit -------------------------}
    Readln(ConfigF,Comport);
    Readln(ConfigF,LockBaud);
    Readln(ConfigF,LowestBaud);
    Readln(ConfigF,AnswerStr);
    Readln(ConfigF,InitStr);
    Readln(ConfigF,hangup);
    Readln(ConfigF,Temp);
    If Pos('F',Temp) <> 0 then fossil:= True else
    if Pos('A',temp) <> 0 then fossil:= false else
    if pos('T',temp) <> 0 then begin;
                               loadtcpip;
                               fossil:=true;
                               telnet:=true;
                               end;
   Readln(ConfigF,Temp);
   If Pos('T',Temp) <> 0 then changepage:= True else
   if Pos('F',temp) <> 0 then changepage:= false;

   End;
  close(configf);
  writeinitbox('Done Reading Config');
end;


Procedure Check_Config;
begin
writeinitbox('Checking Configuration');
if config.longname = '' then  config_error('Configuration Error Board Name Not Set');
if config.Sysopname = '' then config_error('Configuration Error SysOp Name Not Set');
if Config.Lucid_dir = '' then config_error('Configuration Error Lucid Main Path Not Set');
if Config.Text_Dir = '' then config_error('Configuration Error Text Path Not Set');
if Config.Extract_dir = '' then config_error('Configuration Error Extract Directory Not Set');

{if not direxist(config.Lucid_dir) then config_error('Lucid Main Directory Does Not Exist');
if not direxist(config.text_dir) then config_error('Lucid Text Directory Does Not Exist');
if not direxist(config.extract_dir) then config_error('Lucid Extract Directory Does Not Exist');}

if not direxist(config.Lucid_dir)   then config_error2('Lucid Main Directory Does Not Exist',config.Lucid_dir);
if not direxist(config.text_dir)    then config_error2('Lucid Text Directory Does Not Exist',config.text_dir);
if not direxist(config.extract_dir) then config_error2('Lucid Extract Directory Does Not Exist',config.extract_dir);
killfile(config.work_dir+'\batch.dat');
If not FileExist(config.data_dir+'STAT.DAT') then

 Begin
  Stat.Today_Post  := 0;
  Stat.Today_Ups   := 0;
  Stat.Today_Dwns  := 0;
  Stat.Today_Calls := 0;
  Stat.Today_Email := 0;
  Stat.Today_Feed  := 0;
  Stat.Today_Time  := 0;
  Stat.Last_Alias  := 'Nobody';
  Stat.Last_Posts  := 0;
  Stat.Last_Ups    :=0;
  Stat.Last_Downs  :=0;
  Stat.Last_Feed   :=0;
  Stat.Last_Credits:=0;
  Stat.Last_Note   :='System Operator';
  Stat.Total_Calls :=0;
  Stat.Total_Ups   :=0;
  Stat.Total_Downs :=0;
  Stat.Total_Email :=0;
  Stat.Total_Mesgs :=0;
  Stat.Total_Files :=0;
  Stat.Total_Users :=0;
  Assign(StatF,Config.Data_Dir+'STAT.DAT');
  Rewrite(StatF);
  Write(StatF,Stat);
  Close(StatF);
 End;
writeinitbox('Done Checking Configuration');
end;

Procedure Start_Init;
var i:byte;
    x,Y:byte;
    par : string;
    ib: boolean;
    TEMP:STRING;

Begin
 textattr:=7;
 clrscr;
 hidecursor;
 Pipewrite('|B0|01(|09Initializing Lucid BBS Software v.1 by Judge Dredd|01)');
 pipewrite('|B0|01 ÄÄÄÄ-ÄÄÄ-Ä -   Ä     -   -    ');
 hidecursor;
 crt.gotoxy(1,3);
 read_in_config;
 check_config;
 delay(100);
 Assign(StatF,Config.Data_Dir+'STAT.DAT');
 Reset(StatF);
 Read(StatF,Stat);
 Close(StatF);
 writeinitbox('Opening COM'+Strr(Config.Comport)+' at '+Strr(Config.LockBaud)+' B.P.S');
 par:=uppercase(paramstr(1));
 usefossil:=config.fossil;
 comport  :=config.comport;
 baud     :=config.lockbaud;
 ib:=true;
 {else comport:=0;}
    IF pos('EXIT',PAR)>0 THEN BEGIN
                            X:=pos('EXIT',PAR);
                            DELETE(PAR,X,5);
                            {EXITIT:=TRUE;}
                            END;
    IF pos('LOCAL',PAR)>0 THEN BEGIN
                            X:=pos('LOCAL',PAR);
                            DELETE(PAR,X,6);
                            COMPORT:=0;
                            END ELSE ib:=Comm_Init(baud,comport);
    IF pos('LOGON',PAR)>0 THEN BEGIN
                            X:=pos('LOGON',PAR);
                            DELETE(PAR,X,6);
                            {AUTOLOGON:=TRUE;}
                            END;
    IF pos('BAUD',PAR)>0 THEN BEGIN
                            x:=pos('BAUD',PAR);
                            inc(x,5);
                            TEMP:='';
                            FOR y:=x TO LENGTH(PAR) DO
                            IF PAR[y]<>' ' THEN
                               BEGIN
                               TEMP:=TEMP+PAR[y];
                               END ELSE y:=LENGTH(PAR);
                            {BAUDR:=temp;}
{                            baud:=true;}
                            END;


 if ib=false then begin
                  writeinitbox('Modem Setup Error. For local run LOCAL as first param');
                  halt(233);
                  end;
 writeinitbox('Done Setting Up Modem');
 { This sets up basic mcis codes in bbs }
 writeinitbox('Setting Up MCI Codes');
 FILLCHAR(BASICMCI,SIZEOF(BASICMCI),#0);
 for x:=1 to 30 do basicmci[x].useproc:=false;
 BASICMCI[1].MCI:='~PA';
 BASICMCI[1].USEPROC:=TRUE;
 BASICMCI[1].ACTION:=Animated_HoldScreen;
 BASICMCI[2].MCI:='~CS';
 BASICMCI[2].USEPROC:=TRUE;
 BASICMCI[2].ACTION:=ANSICLR;
 BASICMCI[3].MCI:='~TT';
 BASICMCI[3].USEPROC:=TRUE;
 BASICMCI[3].ACTION:=WRITETIME;
 BASICMCI[4].MCI:='~TD';
 BASICMCI[4].USEPROC:=TRUE;
 BASICMCI[4].ACTION:=WRITEDATE;
 BASICMCI[5].MCI:='%CB';
 BASICMCI[5].STR := 'Local';
 BASICMCI[6].MCI:='%CS';
 BASICMCI[6].STR := 'None';

 BASICMCI[7].MCI :='|N1';
 BASICMCI[8].MCI :='|N2';
 BASICMCI[9].MCI :='|N3';
 BASICMCI[10].MCI:='|N4';
 BASICMCI[11].MCI:='|N5';
 BASICMCI[12].MCI:='|N6';
 BASICMCI[13].MCI:='|N7';
 BASICMCI[14].MCI:='|N8';
 BASICMCI[15].MCI:='|N9';

 BASICMCI[16].MCI:='%UN';
 BASICMCI[16].ACTION:=UPDATEMCIS;
 BASICMCI[16].USEPROC:=TRUE;
 BASICMCI[17].MCI:='%TL';
 BASICMCI[17].ACTION:=UPDATEMCIS;
 BASICMCI[17].USEPROC:=TRUE;
 BASICMCI[18].MCI:='%PC';
 BASICMCI[18].ACTION:=UPDATEMCIS;
 BASICMCI[18].USEPROC:=TRUE;
 BASICMCI[19].MCI:='%ML';
 BASICMCI[19].ACTION:=UPDATEMCIS;
 BASICMCI[19].USEPROC:=TRUE;
 BASICMCI[20].MCI:='%FL';
 BASICMCI[20].ACTION:=UPDATEMCIS;
 BASICMCI[20].USEPROC:=TRUE;
 BASICMCI[21].MCI:='%UL';
 BASICMCI[21].ACTION:=UPDATEMCIS;
 BASICMCI[21].USEPROC:=TRUE;
 BASICMCI[22].MCI:='%DL';
 BASICMCI[22].ACTION:=UPDATEMCIS;
 BASICMCI[22].USEPROC:=TRUE;
 BASICMCI[23].mci:='|PP';
 basicmci[23].STR:='';

 BASICMCI[24].mci:='|HD';
 basicmci[24].action:=togglehidden;
 basicmci[24].useproc:=true;

 BASICMCI[25].mci:='|NO';
 basicmci[25].action:=toggleabort;
 basicmci[25].useproc:=true;

 writeinitbox('Done Setting Up MCI Codes');
 buflen:=255;
 enter:=false;
 if swap=true then begin
                   writeinitbox('Starting Swap');
                   end;
end;

begin
end.

