From c85aee275303712ae3ca2aed9b4a60f8ae121b35 Mon Sep 17 00:00:00 2001 From: mysticbbs Date: Wed, 22 Feb 2012 03:41:08 -0500 Subject: [PATCH] Code cleanup --- mystic/bbs_general.pas | 125 +++++++++++++++++++++++++-------------- mystic/bbs_io.pas | 4 +- mystic/bbs_menus.pas | 8 +-- mystic/bbs_nodeinfo.pas | 51 ++++++++++------ mystic/bbs_sysopchat.pas | 37 +++++------- mystic/mystic.pas | 2 +- 6 files changed, 136 insertions(+), 91 deletions(-) diff --git a/mystic/bbs_general.pas b/mystic/bbs_general.pas index d76ff07..079db18 100644 --- a/mystic/bbs_general.pas +++ b/mystic/bbs_general.pas @@ -4,10 +4,6 @@ Unit bbs_General; Interface -// more ancient come from my teenage years lol this stuff needs to be -// sorted out / cleaned up and passed a session pointer or relocate to -// one of the classes - Uses m_Strings, m_DateTime, @@ -27,17 +23,18 @@ Procedure Add_BBS_List (Name : String); Procedure AutoSig_Edit; Procedure AutoSig_View; -Procedure List_Users (Data: String); -Procedure Last_Callers; +Procedure ShowUserList (Data: String); +Procedure ShowLastCallers; +Procedure ShowBBSHistory (LastDays: Word); +Procedure ShowOneLiners (Data: String); +Procedure ShowRandomQuote; + Procedure Add_TimeBank; Procedure Get_TimeBank; -Procedure One_Liners (Data : String); -Procedure Display_Quote; Procedure Add_Booth; Procedure Voting_Booth (Forced: Boolean; Num: Integer); -Procedure Voting_Result (Data : Integer); +Procedure Voting_Result (Data: Integer); Procedure Voting_Booth_New; -Procedure View_History (LastDays: Word); Procedure View_Directory (Data: String; ViewType: Byte); {$IFNDEF UNIX} @@ -110,10 +107,12 @@ Begin If Session.User.ThisUser.SigLength > 0 Then Begin Reset (DF, 1); Seek (DF, Session.User.ThisUser.SigOffset); + For Lines := 1 to Session.User.ThisUser.SigLength Do Begin BlockRead (DF, Session.Msgs.MsgText[Lines][0], 1); BlockRead (DF, Session.Msgs.MsgText[Lines][1], Ord(Session.Msgs.MsgText[Lines][0])); End; + Close (DF); End Else Lines := 0; @@ -122,12 +121,17 @@ Begin If Editor (Lines, 78, Config.MaxAutoSig, True, False, Str) Then Begin {$I-} Reset (DF, 1); {$I+} + If IoResult <> 0 Then ReWrite (DF, 1); + Session.User.ThisUser.SigLength := Lines; Session.User.ThisUser.SigOffset := FileSize(DF); + Seek (DF, Session.User.ThisUser.SigOffset); + For Lines := 1 to Lines Do BlockWrite (DF, Session.Msgs.MsgText[Lines][0], Length(Session.Msgs.MsgText[Lines]) + 1); + Close (DF); End; End; @@ -146,6 +150,7 @@ Begin For A := 1 to Session.User.ThisUser.SigLength Do Begin BlockRead (DF, S[0], 1); BlockRead (DF, S[1], Ord(S[0])); + Session.io.OutFullLn (S); End; @@ -154,22 +159,26 @@ Begin Session.io.OutFull (Session.GetPrompt(336)); End; -Procedure Display_Quote; +Procedure ShowRandomQuote; Var TF : Text; - TxtBuf : Array[1..1024] of Char; - Total, + TxtBuf : Array[1..2048] of Char; + Total : Integer; Count : Integer; Str : String; Begin - Assign (TF, Config.DataPath + 'quotes.dat'); - {$I-} Reset (TF); {$I+} - If IoResult <> 0 Then Exit; + Assign (TF, Config.DataPath + 'quotes.dat'); SetTextBuf (TF, TxtBuf); + {$I-} Reset (TF); {$I+} + + If IoResult <> 0 Then Exit; + Total := 0; + While Not Eof(TF) Do Begin ReadLn (TF, Str); + If Str[1] = '*' Then Inc(Total); End; @@ -182,6 +191,7 @@ Begin Total := 0; Reset (TF); + While Total <> Count Do Begin ReadLn (TF, Str); If Str[1] = '*' Then Inc(Total); @@ -191,6 +201,7 @@ Begin ReadLn (TF, Str); If Str[1] = '*' Then Break Else Session.io.OutFullLn (Str); End; + Close (TF); End; @@ -367,6 +378,7 @@ Begin 'Q' : Break; 'V' : If Session.io.GetYN(Session.GetPrompt(266), False) Then Begin BBSList.Verified := CurDateDos; + Seek (BBSFile, FilePos(BBSFile) - 1); Write (BBSFile, BBSList); End; @@ -382,16 +394,17 @@ Begin End; End; End; + Close (BBSFile); If Not Long Then Session.io.OutFullLn (Session.GetPrompt(262)); End; -Procedure List_Users (Data : String); +Procedure ShowUserList (Data: String); Var - Total : Integer; - tUser : RecUser; + Total : Integer; + TempUser : RecUser; Begin If Data = 'SEARCH' Then Begin Session.io.OutFull (Session.GetPrompt(32)); @@ -408,24 +421,24 @@ Begin Total := 0; While Not Eof(Session.User.UserFile) Do Begin - Read (Session.User.UserFile, tUser); + Read (Session.User.UserFile, TempUser); - If tUser.Flags AND UserDeleted <> 0 Then Continue; + If TempUser.Flags AND UserDeleted <> 0 Then Continue; - Session.io.PromptInfo[1] := tUser.Handle; - Session.io.PromptInfo[2] := tUser.City; - Session.io.PromptInfo[3] := DateDos2Str(tUser.LastOn, Session.User.ThisUser.DateType); - Session.io.PromptInfo[4] := tUser.Gender; - Session.io.PromptInfo[5] := strI2S(tUser.Security); - Session.io.PromptInfo[6] := tUser.Address; - Session.io.PromptInfo[7] := strI2S(DaysAgo(tUser.Birthday) DIV 365); - Session.io.PromptInfo[8] := tUser.Email; - Session.io.PromptInfo[9] := tUser.UserInfo; - Session.io.PromptInfo[10] := tUser.Optional[1]; - Session.io.PromptInfo[11] := tUser.Optional[2]; - Session.io.PromptInfo[12] := tUser.Optional[3]; + Session.io.PromptInfo[1] := TempUser.Handle; + Session.io.PromptInfo[2] := TempUser.City; + Session.io.PromptInfo[3] := DateDos2Str(TempUser.LastOn, Session.User.ThisUser.DateType); + Session.io.PromptInfo[4] := TempUser.Gender; + Session.io.PromptInfo[5] := strI2S(TempUser.Security); + Session.io.PromptInfo[6] := TempUser.Address; + Session.io.PromptInfo[7] := strI2S(DaysAgo(TempUser.Birthday) DIV 365); + Session.io.PromptInfo[8] := TempUser.Email; + Session.io.PromptInfo[9] := TempUser.UserInfo; + Session.io.PromptInfo[10] := TempUser.Optional[1]; + Session.io.PromptInfo[11] := TempUser.Optional[2]; + Session.io.PromptInfo[12] := TempUser.Optional[3]; - If (Data = '') or (Pos(Data, strUpper(tUser.Handle)) > 0) Then Begin + If (Data = '') or (Pos(Data, strUpper(TempUser.Handle)) > 0) Then Begin Session.io.OutFullLn (Session.GetPrompt(30)); Inc (Total); @@ -444,12 +457,15 @@ Begin Session.io.OutFull (Session.GetPrompt(31)); End; -Procedure Last_Callers; +Procedure ShowLastCallers; Begin Session.io.OutFullLn (Session.GetPrompt(141)); + Reset (LastOnFile); + While Not Eof(LastOnFile) Do Begin Read (LastOnFile, LastOn); + Session.io.PromptInfo[1] := LastOn.Handle; Session.io.PromptInfo[2] := strI2S(LastOn.Node); Session.io.PromptInfo[3] := LastOn.City; @@ -463,9 +479,12 @@ Begin Session.io.PromptInfo[11] := LastOn.Option1; Session.io.PromptInfo[12] := LastOn.Option2; Session.io.PromptInfo[13] := LastOn.Option3; + Session.io.OutFullLn (Session.GetPrompt(142)); End; + Close (LastOnFile); + Session.io.OutFull (Session.GetPrompt(143)); End; @@ -474,14 +493,18 @@ Var A : Integer; Begin Session.io.OutFull (Session.GetPrompt(172)); + A := strS2I(Session.io.GetInput(4, 4, 11, '')); + If A > 0 Then If (A < Session.TimeLeft - 4) Then Begin If (Session.User.Security.MaxTB > 0) and (Session.User.ThisUser.TimeBank + A > Session.User.Security.MaxTB) Then Begin Session.io.OutFullLn (Session.GetPrompt(209)); Exit; End; + Inc (Session.User.ThisUser.TimeBank, A); + Session.SetTimeLeft (Session.TimeLeft - A); End Else Session.io.OutFullLn (Session.GetPrompt(210)); @@ -492,14 +515,17 @@ Var A : Integer; Begin Session.io.OutFull (Session.GetPrompt(173)); + A := strS2I(Session.io.GetInput(4, 4, 11, '')); + If (A > 0) and (A <= Session.User.ThisUser.TimeBank) Then Begin Dec (Session.User.ThisUser.TimeBank, A); + Session.SetTimeLeft (Session.TimeLeft + A); End; End; -Procedure One_Liners (Data : String); +Procedure ShowOneLiners (Data : String); Const MaxLines : Byte = 9; MaxLen : Byte = 75; @@ -511,16 +537,20 @@ Var A : Byte; Begin A := Pos(';', Data); + If A > 0 Then Begin MaxLines := strS2I(Copy(Data, 1, A - 1)) - 1; + Delete (Data, 1, A); A := Pos(';', Data); + MaxLen := strS2I(Copy(Data, 1, A - 1)); MaxField := strS2I(Copy(Data, A + 1, Length(Data))); End; Assign (OneLineFile, Config.DataPath + 'oneliner.dat'); {$I-} Reset (OneLineFile); {$I+} + If IoResult <> 0 Then ReWrite (OneLineFile); Repeat @@ -529,17 +559,22 @@ Begin While Not Eof(OneLineFile) Do Begin Read (OneLineFile, OneLine); + Session.io.PromptInfo[1] := OneLine.Text; Session.io.PromptInfo[2] := OneLine.From; Session.io.PromptInfo[3] := OneLine.From[1]; + If Pos(' ', OneLine.From) > 0 Then Session.io.PromptInfo[3] := Session.io.PromptInfo[3] + OneLine.From[Pos(' ', OneLine.From) + 1]; + Session.io.OutFullLn (Session.GetPrompt(337)); End; If Session.io.GetYN(Session.GetPrompt(189), False) Then Begin Session.io.OutFull (Session.GetPrompt(190)); + Str := Session.io.GetInput (MaxField, MaxLen, 11, ''); + If Str <> '' Then Begin If FileSize(OneLineFile) > MaxLines Then KillRecord (OneLineFile, 1, SizeOf(OneLineRec)); @@ -800,13 +835,14 @@ Begin If Session.io.GetYN (Session.GetPrompt(248), True) Then Voting_Result(VPos); End; -Procedure View_History (LastDays: Word); +Procedure ShowBBSHistory (LastDays: Word); Var Temp : HistoryRec; Days : Word; Begin Assign (Session.HistoryFile, Config.DataPath + 'history.dat'); {$I-} Reset(Session.HistoryFile); {$I+} + If IoResult <> 0 Then Session.io.OutFullLn (Session.GetPrompt(454)) Else Begin @@ -1371,14 +1407,15 @@ Begin MessageBeep(0); - If Input.KeyPressed Then If Input.ReadKey = #0 Then Begin - Case Input.ReadKey of - #31 : OpenChat(True); - #46 : OpenChat(False); - End; + If Input.KeyPressed Then + If Input.ReadKey = #0 Then Begin + Case Input.ReadKey of + #31 : OpenChat(True); + #46 : OpenChat(False); + End; - Exit; - End; + Exit; + End; WaitMS(1000); End; diff --git a/mystic/bbs_io.pas b/mystic/bbs_io.pas index 1faef5b..ac115c6 100644 --- a/mystic/bbs_io.pas +++ b/mystic/bbs_io.pas @@ -547,7 +547,7 @@ Begin 'Q' : Case Code[2] of 'A' : LastMCIValue := TBBSCore(Core).User.ThisUser.Archive; 'L' : LastMCIValue := OutYN (TBBSCore(Core).User.ThisUser.QwkFiles); - 'O' : Display_Quote; + 'O' : ShowRandomQuote; End; 'R' : Case Code[2] of 'D' : LastMCIValue := strI2S(TBBSCore(Core).User.Security.DLRatio); @@ -1829,4 +1829,4 @@ Begin End; {$ENDIF} -End. \ No newline at end of file +End. diff --git a/mystic/bbs_menus.pas b/mystic/bbs_menus.pas index 4d6157c..a04a062 100644 --- a/mystic/bbs_menus.pas +++ b/mystic/bbs_menus.pas @@ -175,7 +175,7 @@ Begin 'S' : View_BBS_List (False, Data); End; 'G' : Case Cmd[2] of - '1' : View_History(strS2I(Data)); + '1' : ShowBBSHistory(strS2I(Data)); 'A' : View_Directory(Data, 0); 'D' : Session.io.OutFile (Data, True, 0); 'E' : Session.User.Edit_User_Settings(strS2I(Data)); @@ -192,13 +192,13 @@ Begin Session.SystemLog ('User logged off'); Halt(0); End; - 'L' : Last_Callers; + 'L' : ShowLastCallers; 'O' : Begin MenuOld := MenuName; MenuName := Data; Result := True; End; - 'N' : One_Liners (Data); + 'N' : ShowOneLiners (Data); 'P' : {$IFNDEF UNIX} PageForSysopChat (Pos('/F', strUpper(Data)) > 0) {$ENDIF}; 'R' : Begin If StackNum > 0 Then Begin @@ -226,7 +226,7 @@ Begin Result := True; End; 'T' : Session.io.OutFull (Data); - 'U' : List_Users (strUpper(Data)); + 'U' : ShowUserList (strUpper(Data)); 'X' : Result := ExecuteMPL(NIL, Data) = 2; '?' : Begin // online ANSI help system (BBSHTML) prototype diff --git a/mystic/bbs_nodeinfo.pas b/mystic/bbs_nodeinfo.pas index 7f0fc25..d7ed127 100644 --- a/mystic/bbs_nodeinfo.pas +++ b/mystic/bbs_nodeinfo.pas @@ -1,14 +1,14 @@ -Unit bbs_NodeInfo; { Multinode functions } +Unit bbs_NodeInfo; {$I M_OPS.PAS} Interface -Function Is_User_Online (Name : String) : Word; -Procedure Set_Node_Action (Action: String); +Function Is_User_Online (Name : String) : Word; Procedure Show_Whos_Online; Procedure Send_Node_Message (MsgType: Byte; Data: String; Room: Byte); Function CheckNodeMessages : Boolean; +Procedure Set_Node_Action (Action: String); Implementation @@ -19,22 +19,25 @@ Uses bbs_Core, bbs_User; -Function Is_User_Online (Name : String) : Word; +Function Is_User_Online (Name: String) : Word; Var TempChat : ChatRec; Count : Word; Begin - Is_User_Online := 0; + Result := 0; For Count := 1 to Config.INetTNNodes Do Begin Assign (ChatFile, Config.DataPath + 'chat' + strI2S(Count) + '.dat'); + {$I-} Reset(ChatFile); {$I+} + If IoResult <> 0 Then Continue; + Read (ChatFile, TempChat); Close (ChatFile); If (Count <> Session.NodeNum) and (TempChat.Active) and (TempChat.Name = Name) Then Begin - Is_User_Online := Count; + Result := Count; Exit; End; End; @@ -75,19 +78,22 @@ End; Procedure Show_Whos_Online; Var TChat : ChatRec; - A : Word; + Count : Word; Begin Session.io.OutFullLn (Session.GetPrompt(138)); - For A := 1 to Config.INetTNNodes Do Begin - Assign (ChatFile, Config.DataPath + 'chat' + strI2S(A) + '.dat'); + For Count := 1 to Config.INetTNNodes Do Begin + Assign (ChatFile, Config.DataPath + 'chat' + strI2S(Count) + '.dat'); + {$I-} Reset(ChatFile); {$I+} + If IoResult <> 0 Then Continue; + Read (ChatFile, TChat); Close (ChatFile); If TChat.Active and ((Not TChat.Invisible) or (TChat.Invisible and Session.User.Access(Config.AcsSeeInvis))) Then Begin - Session.io.PromptInfo[1] := strI2S(A); + Session.io.PromptInfo[1] := strI2S(Count); Session.io.PromptInfo[2] := TChat.Name; Session.io.PromptInfo[3] := TChat.Action; Session.io.PromptInfo[4] := TChat.Location; @@ -95,9 +101,11 @@ Begin Session.io.PromptInfo[6] := TChat.Gender; Session.io.PromptInfo[7] := strI2S(TChat.Age); Session.io.PromptInfo[8] := Session.io.OutYN(TChat.Available); + Session.io.OutFullLn (Session.GetPrompt(139)); End Else Begin - Session.io.PromptInfo[1] := strI2S(A); + Session.io.PromptInfo[1] := strI2S(Count); + Session.io.OutFullLn (Session.GetPrompt(268)); End; End; @@ -130,15 +138,15 @@ Begin C := ToNode; End Else Begin If Pos(';', Data) = 0 Then Exit; + ToNode := strS2I(Copy(Data, 1, Pos(';', Data)-1)); + Delete (Data, 1, Pos(';', Data)); + If ToNode = 0 Then Begin B := 1; C := Config.INetTNNodes; If MsgType = 3 Then MsgType := 2; -{ If Not (MsgType in [1, 4..7]) Then MsgType := 2;} -{ used line above comment now... see if that does anything } - End Else Begin B := ToNode; C := ToNode; @@ -146,12 +154,14 @@ Begin End; For A := B to C Do Begin + FileMode := 66; Assign (ChatFile, Config.DataPath + 'chat' + strI2S(A) + '.dat'); - FileMode := 66; + {$I-} Reset (ChatFile); {$I+} + If IoResult = 0 Then Begin - Read (ChatFile, Temp); + Read (ChatFile, Temp); Close (ChatFile); If (Not Temp.Active) and (ToNode > 0) Then Begin @@ -166,9 +176,11 @@ Begin If Temp.Active and (Temp.Available or Temp.InChat) Then Begin If Data = '' Then Begin - Session.io.PromptInfo[1] := Temp.Name; { TEMP NODE NAME } + Session.io.PromptInfo[1] := Temp.Name; Session.io.PromptInfo[2] := strI2S(A); + Session.io.OutFullLn (Session.GetPrompt(148)); + NodeMsg.Message := Session.io.GetInput(79, 79, 11, ''); End Else NodeMsg.Message := Data; @@ -181,9 +193,12 @@ Begin NodeMsg.Room := Room; NodeMsg.FromWho := Session.User.ThisUser.Handle; - Assign (NodeMsgFile, Config.SystemPath + 'temp' + strI2S(A) + PathChar + 'chat.tmp'); FileMode := 66; + + Assign (NodeMsgFile, Config.SystemPath + 'temp' + strI2S(A) + PathChar + 'chat.tmp'); + {$I-} Reset (NodeMsgFile); {$I+} + If IoResult <> 0 Then ReWrite(NodeMsgFile); Seek (NodeMsgFile, FileSize(NodeMsgFile)); diff --git a/mystic/bbs_sysopchat.pas b/mystic/bbs_sysopchat.pas index 677bfe5..8771edd 100644 --- a/mystic/bbs_sysopchat.pas +++ b/mystic/bbs_sysopchat.pas @@ -1,18 +1,5 @@ Unit bbs_SysOpChat; -(* some ideas for chat: - -split chat additions: - -- scroll half window instead of just the last line -- allow full arrow key movement in chat windows... - kinda like a full screen editor... -- ctrl-k brings up a command menu, which has: - OutFull file - display file - dos drop? add mini-dos internal to mystic? - -*) {$I M_OPS.PAS} Interface @@ -215,16 +202,18 @@ End; Procedure Line_Chat; Var - Ch : Char; - Str1, - Str2 : String; + Ch : Char; + Str1 : String[160]; + Str2 : String[160]; Begin - Str1 := ''; - Str2 := ''; + Str1 := ''; + Str2 := ''; + Session.io.OutFullLn (Session.GetPrompt(26)); Repeat Ch := Session.io.GetKey; + Case Ch of #27 : If Session.io.LocalInput Then Break; #13 : Begin @@ -238,13 +227,17 @@ Begin End; Else Str1 := Str1 + Ch; + Session.io.BufAddChar(Ch); + If Length(Str1) > 78 Then Begin strWrap (Str1, Str2, 78); Session.io.OutBS(Length(Str2), True); Session.io.OutRawLn (''); Session.io.OutRaw (Str2); + If Config.ChatLogging Then WriteLn (tFile, Str1); + Str1 := Str2; End; End; @@ -253,7 +246,7 @@ Begin Session.io.OutFull (Session.GetPrompt(27)); End; -Procedure OpenChat (Split : Boolean); +Procedure OpenChat (Split: Boolean); Var Image : TConsoleImageRec; Begin @@ -281,12 +274,12 @@ Begin Close (tFile); End; - Session.User.InChat := False; - Session.TimeOut := TimerSeconds; + Session.User.InChat := False; + Session.TimeOut := TimerSeconds; Session.io.RemoteRestore(Image); Update_Status_Line (StatusPtr, ''); End; -End. +End. \ No newline at end of file diff --git a/mystic/mystic.pas b/mystic/mystic.pas index a8d6402..f4a25fb 100644 --- a/mystic/mystic.pas +++ b/mystic/mystic.pas @@ -499,4 +499,4 @@ Begin Repeat Session.Menu.ExecuteMenu(True, True, False); Until False; -End. +End. \ No newline at end of file