2012-02-13 15:23:40 -08:00
|
|
|
Unit BBS_Core;
|
|
|
|
|
|
|
|
{$I M_OPS.PAS}
|
|
|
|
|
|
|
|
Interface
|
|
|
|
|
|
|
|
Uses
|
|
|
|
m_FileIO,
|
|
|
|
m_Strings,
|
|
|
|
m_DateTime,
|
|
|
|
m_Socket_Class,
|
|
|
|
BBS_Common,
|
|
|
|
BBS_IO,
|
|
|
|
BBS_MsgBase,
|
|
|
|
BBS_User,
|
|
|
|
BBS_FileBase,
|
|
|
|
BBS_Menus,
|
|
|
|
MPL_Execute;
|
|
|
|
|
2012-03-08 13:38:44 -08:00
|
|
|
Const
|
|
|
|
mysMessageThreshold = 3;
|
|
|
|
|
2012-02-13 15:23:40 -08:00
|
|
|
Type
|
|
|
|
TBBSCore = Class
|
|
|
|
User : TBBSUser;
|
|
|
|
Msgs : TMsgBase;
|
|
|
|
FileBase : TFileBase;
|
2012-07-23 20:01:52 -07:00
|
|
|
Menu : TMenuEngine;
|
2012-02-13 15:23:40 -08:00
|
|
|
IO : TBBSIO;
|
|
|
|
Client : TSocketClass;
|
|
|
|
EventFile : File of EventRec;
|
2012-06-30 17:23:39 -07:00
|
|
|
ThemeFile : File of RecTheme;
|
|
|
|
VoteFile : File of VoteRec;
|
|
|
|
Vote : VoteRec;
|
2012-02-13 15:23:40 -08:00
|
|
|
CommHandle : LongInt;
|
|
|
|
ShutDown : Boolean;
|
|
|
|
TempPath : String;
|
|
|
|
Event : EventRec;
|
|
|
|
NextEvent : EventRec;
|
2012-06-30 17:23:39 -07:00
|
|
|
Theme : RecTheme;
|
2012-02-13 15:23:40 -08:00
|
|
|
LocalMode : Boolean;
|
|
|
|
Baud : LongInt;
|
|
|
|
ExitLevel : Byte;
|
|
|
|
EventWarn : Boolean;
|
|
|
|
EventExit : Boolean;
|
|
|
|
EventRunAfter : Boolean;
|
|
|
|
NodeNum : Byte;
|
|
|
|
TimerStart : Integer;
|
|
|
|
TimerEnd : Integer;
|
|
|
|
LastTimeLeft : Integer;
|
|
|
|
TimeOut : LongInt;
|
|
|
|
UserHostInfo : String[50];
|
|
|
|
UserIPInfo : String[15];
|
|
|
|
CheckTimeOut : Boolean;
|
|
|
|
TimeOffset : Word;
|
|
|
|
TimeSaved : Word;
|
|
|
|
TimerOn : Boolean;
|
|
|
|
TimeChecked : Boolean;
|
|
|
|
ConfigMode : Boolean;
|
|
|
|
InUserEdit : Boolean;
|
2012-03-08 13:38:44 -08:00
|
|
|
AllowMessages : Boolean;
|
|
|
|
InMessage : Boolean;
|
|
|
|
MessageCheck : Byte;
|
2012-03-02 18:25:37 -08:00
|
|
|
HistoryFile : File of RecHistory;
|
2012-02-13 15:23:40 -08:00
|
|
|
HistoryEmails : Word;
|
|
|
|
HistoryPosts : Word;
|
|
|
|
HistoryDLs : Word;
|
|
|
|
HistoryDLKB : LongInt;
|
|
|
|
HistoryULs : Word;
|
|
|
|
HistoryULKB : LongInt;
|
2012-03-02 17:28:22 -08:00
|
|
|
PromptFile : File of RecPrompt;
|
|
|
|
Prompt : RecPrompt;
|
2012-02-13 15:23:40 -08:00
|
|
|
|
|
|
|
Constructor Create;
|
|
|
|
Destructor Destroy; Override;
|
|
|
|
|
|
|
|
Procedure UpdateHistory;
|
|
|
|
Procedure FindNextEvent;
|
|
|
|
Function GetPrompt (N : Word) : String;
|
|
|
|
Procedure SystemLog (Str: String);
|
|
|
|
Function MinutesUntilEvent (ExecTime: Integer): Integer;
|
|
|
|
Procedure SetTimeLeft (Mins: Integer);
|
|
|
|
Function ElapsedTime : Integer;
|
|
|
|
Function TimeLeft : Integer;
|
|
|
|
Function LoadThemeData (Str: String) : Boolean;
|
|
|
|
End;
|
|
|
|
|
|
|
|
Var
|
|
|
|
Session : TBBSCore;
|
|
|
|
|
|
|
|
Implementation
|
|
|
|
|
|
|
|
Constructor TBBSCore.Create;
|
|
|
|
Begin
|
|
|
|
Inherited Create;
|
|
|
|
|
|
|
|
HistoryEmails := 0;
|
|
|
|
HistoryPosts := 0;
|
|
|
|
HistoryDLs := 0;
|
|
|
|
HistoryDLKB := 0;
|
|
|
|
HistoryULs := 0;
|
|
|
|
HistoryULKB := 0;
|
|
|
|
ShutDown := False;
|
|
|
|
CommHandle := -1;
|
|
|
|
LocalMode := False;
|
|
|
|
Baud := -1;
|
|
|
|
ExitLevel := 0;
|
|
|
|
EventWarn := False;
|
|
|
|
EventExit := False;
|
|
|
|
EventRunAfter := False;
|
|
|
|
NodeNum := 1;
|
|
|
|
UserHostInfo := '';
|
|
|
|
UserIPInfo := '';
|
|
|
|
CheckTimeOut := True;
|
|
|
|
TimeOffset := 0;
|
|
|
|
TimeSaved := 0;
|
|
|
|
TimerOn := False;
|
|
|
|
TimeChecked := False;
|
|
|
|
ConfigMode := False;
|
|
|
|
InUserEdit := False;
|
2012-03-08 13:38:44 -08:00
|
|
|
AllowMessages := True;
|
|
|
|
InMessage := False;
|
|
|
|
MessageCheck := mysMessageThreshold;
|
2012-02-13 15:23:40 -08:00
|
|
|
|
|
|
|
{$IFDEF WINDOWS}
|
|
|
|
Client := TSocketClass.Create;
|
|
|
|
Client.FTelnetServer := True;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
User := TBBSUser.Create(Pointer(Self));
|
|
|
|
IO := TBBSIO.Create(Pointer(Self));
|
|
|
|
Msgs := TMsgBase.Create(Pointer(Self));
|
|
|
|
FileBase := TFileBase.Create(Pointer(Self));
|
2012-07-23 20:01:52 -07:00
|
|
|
Menu := TMenuEngine.Create(Pointer(Self));
|
2012-02-13 15:23:40 -08:00
|
|
|
End;
|
|
|
|
|
|
|
|
Destructor TBBSCore.Destroy;
|
|
|
|
Begin
|
|
|
|
Msgs.Free;
|
|
|
|
FileBase.Free;
|
|
|
|
Menu.Free;
|
|
|
|
User.Free;
|
|
|
|
IO.Free;
|
|
|
|
|
|
|
|
Close (PromptFile);
|
|
|
|
|
|
|
|
{$IFDEF WINDOWS}
|
|
|
|
Client.Free;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
Inherited Destroy;
|
|
|
|
End;
|
|
|
|
|
|
|
|
Procedure TBBSCore.UpdateHistory;
|
|
|
|
Var
|
2012-03-02 18:25:37 -08:00
|
|
|
History : RecHistory;
|
2012-02-13 15:23:40 -08:00
|
|
|
Begin
|
2012-07-19 18:12:19 -07:00
|
|
|
If User.ThisUser.Flags AND UserNoHistory = 0 Then Exit;
|
|
|
|
|
2012-02-13 15:23:40 -08:00
|
|
|
Assign (HistoryFile, Config.DataPath + 'history.dat');
|
2012-07-19 18:12:19 -07:00
|
|
|
ioReset (HistoryFile, SizeOf(RecHistory), fmRWDN);
|
2012-02-13 15:23:40 -08:00
|
|
|
|
2012-03-02 18:25:37 -08:00
|
|
|
If IoResult <> 0 Then ioReWrite(HistoryFile, SizeOf(RecHistory), fmRWDW);
|
2012-02-13 15:23:40 -08:00
|
|
|
|
|
|
|
History.Date := CurDateDos;
|
|
|
|
|
|
|
|
While Not Eof(HistoryFile) Do Begin
|
|
|
|
ioRead (HistoryFile, History);
|
2012-07-19 18:12:19 -07:00
|
|
|
|
2012-02-13 15:23:40 -08:00
|
|
|
If DateDos2Str(History.Date, 1) = DateDos2Str(CurDateDos, 1) Then Begin
|
|
|
|
ioSeek (HistoryFile, FilePos(HistoryFile) - 1);
|
|
|
|
Break;
|
|
|
|
End;
|
|
|
|
End;
|
|
|
|
|
|
|
|
If Eof(HistoryFile) Then Begin
|
|
|
|
FillChar(History, SizeOf(History), 0);
|
|
|
|
History.Date := CurDateDos;
|
|
|
|
End;
|
|
|
|
|
|
|
|
Inc (History.Emails, HistoryEmails);
|
|
|
|
Inc (History.Posts, HistoryPosts);
|
|
|
|
Inc (History.Downloads, HistoryDLs);
|
|
|
|
Inc (History.Uploads, HistoryULs);
|
|
|
|
Inc (History.DownloadKB, HistoryDLKB);
|
|
|
|
Inc (History.UploadKB, HistoryULKB);
|
|
|
|
|
2012-07-19 18:12:19 -07:00
|
|
|
If Not LocalMode And (User.ThisUser.Flags AND UserNoLastCall = 0) Then
|
|
|
|
Inc (History.Calls, 1);
|
|
|
|
|
2012-02-13 15:23:40 -08:00
|
|
|
If User.ThisUser.Calls = 1 Then Inc (History.NewUsers, 1);
|
|
|
|
|
|
|
|
ioWrite (HistoryFile, History);
|
|
|
|
Close (HistoryFile);
|
|
|
|
End;
|
|
|
|
|
|
|
|
Procedure TBBSCore.FindNextEvent;
|
|
|
|
Var
|
|
|
|
MinCheck : Integer;
|
|
|
|
Begin
|
|
|
|
NextEvent.Active := False;
|
|
|
|
|
|
|
|
MinCheck := -1;
|
|
|
|
|
|
|
|
Assign (EventFile, Config.DataPath + 'events.dat');
|
|
|
|
ioReset (EventFile, SizeOf(EventRec), fmRWDN);
|
|
|
|
|
|
|
|
If IoResult <> 0 Then ioReWrite (EventFile, SizeOf(EventRec), fmRWDN);
|
|
|
|
|
|
|
|
While Not Eof(EventFile) Do Begin
|
|
|
|
ioRead (EventFile, Event);
|
|
|
|
|
|
|
|
If MinCheck = -1 Then Begin
|
|
|
|
If Event.Active and ((Event.Node = 0) or (Event.Node = NodeNum)) Then begin
|
|
|
|
MinCheck := MinutesUntilEvent(Event.ExecTime);
|
|
|
|
NextEvent := Event;
|
|
|
|
End;
|
|
|
|
End Else
|
|
|
|
If (Event.Active) and ((Event.Node = 0) or (Event.Node = NodeNum)) and (MinutesUntilEvent(Event.ExecTime) < MinCheck) Then Begin
|
|
|
|
MinCheck := MinutesUntilEvent(Event.ExecTime);
|
|
|
|
NextEvent := Event;
|
|
|
|
End;
|
|
|
|
End;
|
|
|
|
|
|
|
|
Close (EventFile);
|
|
|
|
End;
|
|
|
|
|
|
|
|
Function TBBSCore.GetPrompt (N : Word) : String;
|
|
|
|
Begin
|
2012-03-10 00:54:29 -08:00
|
|
|
{$I-}
|
2012-02-13 15:23:40 -08:00
|
|
|
Seek (PromptFile, N);
|
|
|
|
Read (PromptFile, Prompt);
|
2012-03-10 00:54:29 -08:00
|
|
|
{$I+}
|
|
|
|
|
|
|
|
If IoResult <> 0 Then Begin
|
2012-04-17 15:34:27 -07:00
|
|
|
FileMode := 66;
|
|
|
|
|
2012-03-13 19:32:12 -07:00
|
|
|
{$I-}
|
2012-07-12 18:23:27 -07:00
|
|
|
Assign (PromptFile, Config.DataPath + Theme.FileName + '.thm');
|
|
|
|
Reset (PromptFile);
|
|
|
|
Seek (PromptFile, N);
|
|
|
|
Read (PromptFile, Prompt);
|
2012-03-13 19:32:12 -07:00
|
|
|
{$I+}
|
|
|
|
|
|
|
|
If IoResult <> 0 Then Begin
|
|
|
|
io.OutFull ('|CR|12Error reading prompt ' + strI2S(N) + '|DE|DE');
|
|
|
|
SystemLog ('Error reading prompt ' + strI2S(N));
|
|
|
|
Halt (1);
|
|
|
|
End;
|
2012-03-10 00:54:29 -08:00
|
|
|
End;
|
2012-02-13 15:23:40 -08:00
|
|
|
|
|
|
|
If Prompt[1] = '@' Then Begin
|
|
|
|
io.OutFile (Copy(Prompt, 2, Length(Prompt)), True, 0);
|
|
|
|
Prompt := '';
|
|
|
|
End Else
|
|
|
|
If Prompt[1] = '!' Then Begin
|
|
|
|
ExecuteMPL (NIL, Copy(Prompt, 2, Length(Prompt)));
|
|
|
|
Prompt := '';
|
|
|
|
End;
|
|
|
|
|
|
|
|
Result := Prompt;
|
|
|
|
End;
|
|
|
|
|
|
|
|
Procedure TBBSCore.SystemLog (Str: String);
|
|
|
|
Var
|
|
|
|
tLOG : Text;
|
|
|
|
Begin
|
|
|
|
Assign (tLOG, Config.LogsPath + 'sysop.' + strI2S(NodeNum));
|
|
|
|
{$I-} Append(tLOG); {$I+}
|
|
|
|
If IoResult <> 0 Then ReWrite (tLOG);
|
|
|
|
|
|
|
|
If Str = '-' Then
|
2012-02-27 06:30:13 -08:00
|
|
|
WriteLn (tLOG, strRep('-', 40))
|
2012-02-13 15:23:40 -08:00
|
|
|
Else
|
|
|
|
WriteLn (tLOG, DateDos2Str(CurDateDos, 1) + ' ' + TimeDos2Str(CurDateDos, False) + ' ' + Str);
|
|
|
|
|
|
|
|
Close (tLOG);
|
|
|
|
End;
|
|
|
|
|
|
|
|
Function TBBSCore.MinutesUntilEvent (ExecTime: Integer): Integer;
|
|
|
|
Begin {exits if 0 mins}
|
|
|
|
If ExecTime > TimerMinutes Then Result := ExecTime - TimerMinutes Else
|
|
|
|
If TimerMinutes > ExecTime Then Result := 1440 - TimerMinutes + ExecTime Else
|
|
|
|
If NextEvent.Active Then Begin
|
|
|
|
If DateDos2Str(NextEvent.LastRan, 1) = DateDos2Str(CurDateDos, 1) Then Begin
|
|
|
|
Result := 1440; {if it was already ran...}
|
|
|
|
Exit;
|
|
|
|
End;
|
|
|
|
If NextEvent.Forced Then Begin
|
|
|
|
EventExit := True;
|
|
|
|
{$IFDEF UNIX}
|
|
|
|
io.OutFullLn (GetPrompt(137));
|
|
|
|
SystemLog ('User disconnected for system event');
|
|
|
|
{$ELSE}
|
|
|
|
If Not LocalMode Then begin
|
|
|
|
io.OutFullLn (GetPrompt(137));
|
|
|
|
SystemLog('User disconnected for system event');
|
|
|
|
End;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
SystemLog('Event: ' + NextEvent.Name);
|
|
|
|
|
|
|
|
Halt (NextEvent.ErrLevel);
|
|
|
|
End Else
|
|
|
|
EventRunAfter := True;
|
|
|
|
End;
|
|
|
|
End;
|
|
|
|
|
|
|
|
Procedure TBBSCore.SetTimeLeft (Mins: Integer);
|
|
|
|
Begin
|
|
|
|
TimerStart := TimerMinutes;
|
|
|
|
TimerEnd := TimerStart + Mins;
|
|
|
|
TimerOn := True;
|
|
|
|
End;
|
|
|
|
|
|
|
|
Function TBBSCore.ElapsedTime : Integer;
|
|
|
|
Begin
|
|
|
|
If TimerStart > TimerMinutes Then Begin
|
|
|
|
Dec (TimerStart, 1440);
|
|
|
|
Dec (TimerEnd, 1440);
|
|
|
|
End;
|
|
|
|
|
|
|
|
ElapsedTime := TimerMinutes - TimerStart;
|
|
|
|
End;
|
|
|
|
|
|
|
|
Function TBBSCore.TimeLeft : Integer;
|
|
|
|
Begin
|
|
|
|
If Not TimerOn Then Begin
|
|
|
|
TimeLeft := 0;
|
|
|
|
Exit;
|
|
|
|
End;
|
|
|
|
|
|
|
|
If TimerStart > TimerMinutes Then Begin
|
|
|
|
Dec (TimerStart, 1440);
|
|
|
|
Dec (TimerEnd, 1440);
|
|
|
|
|
|
|
|
SetTimeLeft (User.Security.Time);
|
|
|
|
End;
|
|
|
|
|
|
|
|
TimeLeft := TimerEnd - TimerMinutes;
|
|
|
|
End;
|
|
|
|
|
|
|
|
Function TBBSCore.LoadThemeData (Str: String) : Boolean;
|
|
|
|
Begin
|
|
|
|
Result := False;
|
|
|
|
|
2012-06-30 17:23:39 -07:00
|
|
|
Reset (ThemeFile);
|
2012-02-13 15:23:40 -08:00
|
|
|
|
2012-06-30 17:23:39 -07:00
|
|
|
While Not Eof(ThemeFile) Do Begin
|
|
|
|
Read (ThemeFile, Theme);
|
2012-03-10 00:54:29 -08:00
|
|
|
|
2012-02-13 15:23:40 -08:00
|
|
|
{$IFDEF FS_SENSITIVE}
|
2012-06-30 18:22:09 -07:00
|
|
|
If Theme.FileName = Str Then Begin
|
2012-02-13 15:23:40 -08:00
|
|
|
{$ELSE}
|
2012-06-30 17:23:39 -07:00
|
|
|
If strUpper(Theme.FileName) = strUpper(Str) Then Begin
|
2012-02-13 15:23:40 -08:00
|
|
|
{$ENDIF}
|
2012-06-30 17:23:39 -07:00
|
|
|
If Not FileExist(Config.DataPath + Theme.FileName + '.thm') Then Break;
|
2012-02-13 15:23:40 -08:00
|
|
|
|
|
|
|
{$I-} Close (PromptFile); {$I+}
|
|
|
|
|
|
|
|
If IoResult <> 0 Then;
|
|
|
|
|
2012-06-30 17:23:39 -07:00
|
|
|
Assign (PromptFile, Config.DataPath + Theme.FileName + '.thm');
|
2012-02-13 15:23:40 -08:00
|
|
|
|
2012-03-10 00:54:29 -08:00
|
|
|
Result := ioReset(PromptFile, SizeOf(RecPrompt), fmRWDN);
|
|
|
|
|
2012-02-13 15:23:40 -08:00
|
|
|
Break;
|
|
|
|
End;
|
|
|
|
End;
|
|
|
|
|
2012-06-30 17:23:39 -07:00
|
|
|
Close (ThemeFile);
|
2012-02-13 15:23:40 -08:00
|
|
|
End;
|
|
|
|
|
|
|
|
End.
|