mysticbbs/mystic/bbs_common.pas

299 lines
8.5 KiB
ObjectPascal
Raw Normal View History

2012-02-13 16:50:48 -08:00
Unit bbs_Common;
{$I M_OPS.PAS}
Interface
Uses
{$IFDEF WINDOWS}
m_io_Base,
m_io_Sockets,
{$ENDIF}
2012-02-13 16:50:48 -08:00
{$IFDEF UNIX}
Unix,
{$ENDIF}
m_Types,
m_Strings,
m_Output,
m_Input,
m_DateTime,
m_FileIO,
2013-08-29 03:04:20 -07:00
BBS_Records;
2012-02-13 16:50:48 -08:00
// This unit is very old (like 1994) and its functions need to be phased out
// This is the stuff that hasn't been worked into a class somewhere or
// replace with MDL/FP RTL functions
Const
WinConsoleTitle = mysSoftwareID + ' Node ';
DateTypeStr : Array[1..4] of String[8] = ('MM/DD/YY', 'DD/MM/YY', 'YY/DD/MM', 'Ask ');
2012-02-13 16:50:48 -08:00
2013-03-13 20:56:42 -07:00
Function DrawAccessFlags (Var Flags: AccessFlagType) : String;
Procedure KillRecord (Var dFile; RecNum: LongInt; RecSize: Word);
Procedure AddRecord (var dFile; RecNum: LongInt; RecSize: Word);
Function Bool_Search (Mask: String; Str: String) : Boolean;
Function ShellDOS (ExecPath: String; Command: String) : LongInt;
2012-02-13 16:50:48 -08:00
{$IFNDEF UNIX}
Procedure UpdateStatusLine (Mode: Byte; Str: String);
Procedure ProcessSysopCommand (Cmd: Char);
2012-02-13 16:50:48 -08:00
{$ENDIF}
Implementation
Uses
DOS,
bbs_Core,
2013-08-29 03:04:20 -07:00
BBS_DataBase,
2012-02-13 16:50:48 -08:00
{$IFNDEF UNIX}
bbs_SysOpChat,
{$ENDIF}
bbs_cfg_UserEdit,
bbs_General,
MPL_Execute;
2013-03-13 20:56:42 -07:00
Function DrawAccessFlags (Var Flags: AccessFlagType) : String;
Var
Ch : Char;
Begin
Result := '';
For Ch := 'A' to 'Z' Do
If Ord(Ch) - 64 in Flags Then
Result := Result + Ch
Else
Result := Result + '-';
End;
2012-02-13 16:50:48 -08:00
Procedure AddRecord (var dFile; RecNum: LongInt; RecSize: Word);
Var
F : File Absolute dFile;
A : LongInt;
Buffer : Pointer;
Begin
If (RecNum < 1) or (RecNum > FileSize(F) + 1) Then Exit;
GetMem (Buffer, RecSize);
Dec (RecNum);
For A := FileSize(F) - 1 DownTo RecNum Do Begin
Seek (F, A);
BlockRead (F, Buffer^, 1);
BlockWrite (F, Buffer^, 1);
End;
Seek (F, RecNum);
FreeMem (Buffer, RecSize);
End;
Procedure KillRecord (var dFile; RecNum: LongInt; RecSize: Word);
Var
F : File Absolute dFile;
Count : LongInt;
Buffer : Pointer;
Begin
If (RecNum < 1) or (RecNum > FileSize(F)) Then Exit;
GetMem (Buffer, RecSize);
Dec (RecNum);
For Count := RecNum to FileSize(F) - 2 Do Begin
Seek (F, Count + 1);
BlockRead (F, Buffer^, 1);
Seek (F, Count);
BlockWrite (F, Buffer^, 1);
End;
Seek (F, FileSize(F) - 1);
Truncate (F);
FreeMem (Buffer, RecSize);
End;
Function Bool_Search (Mask: String; Str: String) : Boolean;
{ place holder for this functionality someday... need to pass in a buffer }
{ to search }
Begin
Bool_Search := True;
2012-06-30 17:23:39 -07:00
2012-02-13 16:50:48 -08:00
If Mask = '' Then Exit;
2012-06-30 17:23:39 -07:00
2012-02-13 16:50:48 -08:00
Bool_Search := Pos(strUpper(Mask), strUpper(Str)) > 0;
End;
Function ShellDOS (ExecPath: String; Command: String) : LongInt;
Begin
2013-05-06 10:19:01 -07:00
Session.SystemLog('DEBUG: In ShellOS for: (' + ExecPath + ') ' + Command);
2012-08-05 22:53:52 -07:00
Session.io.BufFlush;
2012-02-13 16:50:48 -08:00
{$IFDEF WINDOWS}
2012-06-30 17:23:39 -07:00
ExecInheritsHandles := True;
2012-02-13 16:50:48 -08:00
{$ENDIF}
If Session.User.UserNum <> -1 Then Begin
Reset (Session.User.UserFile);
Seek (Session.User.UserFile, Session.User.UserNum - 1);
Write (Session.User.UserFile, Session.User.ThisUser);
Close (Session.User.UserFile);
End;
{$IFNDEF UNIX}
2013-09-16 13:31:39 -07:00
Console.SetWindow (1, 1, 80, 25, False);
Console.TextAttr := 7;
Console.ClearScreen;
2012-02-13 16:50:48 -08:00
{$ENDIF}
{$IFDEF UNIX}
2013-09-16 13:31:39 -07:00
Console.SetRawMode(False);
2012-02-13 16:50:48 -08:00
{$ENDIF}
2013-05-06 10:19:01 -07:00
If ExecPath <> '' Then Begin
Session.SystemLog('DEBUG: ShellOS changing DIR to: ' + ExecPath);
DirChange(ExecPath);
End;
2012-02-13 16:50:48 -08:00
{$IFDEF UNIX}
Result := Shell (Command);
2012-02-13 16:50:48 -08:00
{$ENDIF}
{$IFDEF WINDOWS}
If Command <> '' Then Command := '/C' + Command;
2013-05-06 10:19:01 -07:00
Session.SystemLog('DEBUG: ShellOS EXEC' + GetEnv('COMSPEC') + ' ' + Command);
2012-02-13 16:50:48 -08:00
Exec (GetEnv('COMSPEC'), Command);
Result := DosExitCode;
2013-05-06 10:19:01 -07:00
Session.SystemLog('DEBUG: ShellOS returned: ' + strI2S(Result));
2012-02-13 16:50:48 -08:00
{$ENDIF}
{$IFDEF UNIX}
2013-09-16 13:31:39 -07:00
Console.SetRawMode(True);
2012-02-13 16:50:48 -08:00
{$ENDIF}
2012-02-22 02:51:16 -08:00
{$IFDEF WINDOWS}
2013-09-16 13:31:39 -07:00
Console.SetWindowTitle (WinConsoleTitle + strI2S(Session.NodeNum));
2012-02-13 16:50:48 -08:00
{$ENDIF}
DirChange(bbsCfg.SystemPath);
2012-02-13 16:50:48 -08:00
If Session.User.UserNum <> -1 Then Begin
Reset (Session.User.UserFile);
Seek (Session.User.UserFile, Session.User.UserNum - 1);
Read (Session.User.UserFile, Session.User.ThisUser);
Close (Session.User.UserFile);
End;
2013-05-20 02:35:04 -07:00
// Reset (Session.PromptFile);
2012-02-13 16:50:48 -08:00
{$IFNDEF UNIX}
2013-09-16 13:31:39 -07:00
If Console.Active Then
Session.io.LocalScreenEnable
Else
Session.io.LocalScreenDisable;
2012-02-13 16:50:48 -08:00
{$ENDIF}
2012-06-30 17:23:39 -07:00
Session.TimeOut := TimerSeconds;
2012-02-13 16:50:48 -08:00
End;
{$IFNDEF UNIX}
Procedure UpdateStatusLine (Mode: Byte; Str: String);
2012-02-13 16:50:48 -08:00
Begin
If Not bbsCfg.UseStatusBar Then Exit;
2012-02-13 16:50:48 -08:00
2013-09-16 13:31:39 -07:00
Console.SetWindow (1, 1, 80, 25, False);
2012-02-13 16:50:48 -08:00
Case Mode of
2013-09-16 13:31:39 -07:00
0 : Console.WriteXY (1, 25, bbsCfg.StatusColor3, strPadC(Str, 80, ' '));
2012-02-13 16:50:48 -08:00
1 : Begin
2013-09-16 13:31:39 -07:00
Console.WriteXY ( 1, 25, bbsCfg.StatusColor1, ' Alias ' + strRep(' ', 35) + 'Age SecLevel TimeLeft ');
Console.WriteXY ( 8, 25, bbsCfg.StatusColor2, Session.User.ThisUser.Handle + ' #' + strI2S(Session.User.ThisUser.PermIdx));
Console.WriteXY (47, 25, bbsCfg.StatusColor2, Session.User.ThisUser.Gender + '/' + strI2S(DaysAgo(Session.User.ThisUser.Birthday, 1) DIV 365));
Console.WriteXY (62, 25, bbsCfg.StatusColor2, strI2S(Session.User.ThisUser.Security));
Console.WriteXY (76, 25, bbsCfg.StatusColor2, strI2S(Session.TimeLeft));
2012-02-13 16:50:48 -08:00
End;
2 : Begin
2013-09-16 13:31:39 -07:00
Console.WriteXY ( 1, 25, bbsCfg.StatusColor1, ' Email ' + strRep(' ', 35) + ' Location ' + strRep(' ', 27) + ' ');
Console.WriteXY ( 8, 25, bbsCfg.StatusColor2, strPadR(Session.User.ThisUser.Email, 36, ' '));
Console.WriteXY (53, 25, bbsCfg.StatusColor2, strPadR(Session.User.ThisUser.City, 27, ' '));
2012-02-13 16:50:48 -08:00
End;
3 : Begin
2013-09-16 13:31:39 -07:00
Console.WriteXY ( 1, 25, bbsCfg.StatusColor1, ' IP ' + strRep(' ', 19) + ' Host ' + strRep(' ', 49) + ' ');
Console.WriteXY ( 5, 25, bbsCfg.StatusColor2, Session.UserIPInfo);
Console.WriteXY (31, 25, bbsCfg.StatusColor2, strPadR(Session.UserHostInfo, 49, ' '));
2012-02-13 16:50:48 -08:00
End;
4 : Begin
2013-09-16 13:31:39 -07:00
Console.WriteXY ( 1, 25, bbsCfg.StatusColor1, ' Flags 1 ' + strRep(' ', 35) + ' Flags 2 ');
Console.WriteXY (10, 25, bbsCfg.StatusColor2, DrawAccessFlags(Session.User.ThisUser.AF1));
Console.WriteXY (54, 25, bbsCfg.StatusColor2, DrawAccessFlags(Session.User.ThisUser.AF2));
2012-02-13 16:50:48 -08:00
End;
2013-09-16 13:31:39 -07:00
5 : Console.WriteXY (1, 25, bbsCfg.StatusColor3, ' ALTS/C Chat ALTE Edit ALTH Hangup ALT+/- Time ALTB Info ALTT Bar ALTV Screen ');
2012-02-13 16:50:48 -08:00
End;
2013-09-16 13:31:39 -07:00
Console.SetWindow (1, 1, 80, 24, False);
2012-02-13 16:50:48 -08:00
End;
Procedure ProcessSysopCommand (Cmd: Char);
2012-02-13 16:50:48 -08:00
Begin
2013-09-16 13:31:39 -07:00
If Not Console.Active And (Cmd <> #47) Then Exit;
2012-02-13 16:50:48 -08:00
Case Cmd of
2012-03-17 11:11:50 -07:00
{E} #18 : If (Not Session.InUserEdit) and (Session.User.UserNum <> -1) Then
Configuration_LocalUserEdit;
2012-02-13 16:50:48 -08:00
{T} #20 : Begin
bbsCfg.UseStatusBar := Not bbsCfg.UseStatusBar;
2012-02-13 16:50:48 -08:00
If Not bbsCfg.UseStatusBar Then Begin
2013-09-16 13:31:39 -07:00
Console.WriteXY (1, 25, 0, strRep(' ', 80));
Console.SetWindow (1, 1, 80, 25, False);
2012-02-13 16:50:48 -08:00
End Else
2013-09-16 13:31:39 -07:00
UpdateStatusLine (Session.StatusPtr, '');
2012-02-13 16:50:48 -08:00
End;
{S} #31 : If Not Session.User.InChat Then OpenChat(True);
{H} #35 : Begin
Session.SystemLog('SysOp hungup on user.');
Halt(0);
End;
{C} #46 : If Not Session.User.InChat Then OpenChat(False);
2013-09-16 13:31:39 -07:00
{V} #47 : If Console.Active Then
2012-02-13 16:50:48 -08:00
Session.io.LocalScreenDisable
Else
Session.io.LocalScreenEnable;
{B} #48 : Begin
2013-09-16 13:31:39 -07:00
If Session.StatusPtr < 5 Then
Inc (Session.StatusPtr)
2012-02-13 16:50:48 -08:00
Else
2013-09-16 13:31:39 -07:00
Session.StatusPtr := 1;
2012-02-13 16:50:48 -08:00
2013-09-16 13:31:39 -07:00
UpdateStatusLine (Session.StatusPtr, '');
2012-02-13 16:50:48 -08:00
End;
#59..
#62 : Begin
Session.io.InMacroStr := bbsCfg.SysopMacro[Ord(Cmd) - 58];
2012-02-13 16:50:48 -08:00
If Session.io.InMacroStr[1] = '!' Then
ExecuteMPL (NIL, Copy(Session.io.InMacroStr, 2, 255))
Else Begin
Session.io.InMacroPos := 1;
Session.io.InMacro := Session.io.InMacroStr <> '';
End;
End;
{+} #130: If Session.TimeLeft > 1 Then Begin
Session.SetTimeLeft(Session.TimeLeft-1);
2013-09-16 13:31:39 -07:00
UpdateStatusLine(Session.StatusPtr, '');
2012-02-13 16:50:48 -08:00
End;
{-} #131: If Session.TimeLeft < 999 Then Begin
Session.SetTimeLeft(Session.TimeLeft+1);
2013-09-16 13:31:39 -07:00
UpdateStatusLine(Session.StatusPtr, '');
2012-02-13 16:50:48 -08:00
End;
End;
End;
{$ENDIF}
End.