From 379523d4592f5494054e6a3265872cc55d1f362a Mon Sep 17 00:00:00 2001 From: mysticbbs Date: Sun, 23 Sep 2012 15:09:39 -0400 Subject: [PATCH] Now uses DataWaiting to help prevent named pipe blocking --- mystic/nodespy.pas | 57 ++++++++++++++++++++++++--------------- mystic/nodespy_common.pas | 45 +++++++++++++++++++++++++++++-- 2 files changed, 78 insertions(+), 24 deletions(-) diff --git a/mystic/nodespy.pas b/mystic/nodespy.pas index 5b045c2..4cb0891 100644 --- a/mystic/nodespy.pas +++ b/mystic/nodespy.pas @@ -396,13 +396,6 @@ Var End; Begin - GetChatRecord(Node, Chat); - - If Not Chat.Active Then Begin - ShowMsgBox(0, 'Node ' + strI2S(Node) + ' is not in use'); - Exit; - End; - ShowMsgBox (3, 'Requesting snoop session for node ' + strI2S(Node)); SendNodeMessage(Node, 11); @@ -427,12 +420,14 @@ Begin Update := TimerSet(UpdateNode); While Pipe.Connected Do Begin - Pipe.ReadFromPipe(Buffer, SizeOf(Buffer), BufRead); + If Pipe.DataWaiting Then Begin + Pipe.ReadFromPipe(Buffer, SizeOf(Buffer), BufRead); - If BufRead = 0 Then - WaitMS(200) - Else - Term.ProcessBuf(Buffer, BufRead); + If BufRead <= 0 Then + WaitMS(200) + Else + Term.ProcessBuf(Buffer, BufRead); + End; If Keyboard.KeyPressed Then Case Keyboard.ReadKey of @@ -444,6 +439,7 @@ Begin #45 : Break; #46 : DoUserChat(Node); End; + #27 : Break; End; If TimerUp(Update) Then Begin @@ -715,22 +711,39 @@ Begin End; End; #13 : Begin - SnoopNode(NodeInfo[CurNode]^.Node); - FullReDraw; + GetChatRecord(NodeInfo[CurNode]^.Node, Chat); + + If Not Chat.Active Then Begin + ShowMsgBox(0, 'Node ' + strI2S(NodeInfo[CurNode]^.Node) + ' is not in use'); + Continue; + End; + + Case GetCommandOption(8, 'S-Snoop|C-User Chat|K-Kick User|G-Kill Ghost|') of + 'S' : Begin + SnoopNode(NodeInfo[CurNode]^.Node); + FullReDraw; + End; + 'G' : If ShowMsgBox(1, 'Kill Ghost on Node ' + strI2S(NodeInfo[CurNode]^.Node)) Then Begin + FileErase(Config.DataPath + 'chat' + strI2S(NodeInfo[CurNode]^.Node) + '.dat'); + + UpdateOnlineStatus; + DrawNodes; + + NodeTimer := TimerSet(UpdateNode); + End; + 'K' : If ShowMsgBox(1, 'Kick this user?') Then + SendNodeMessage(NodeInfo[CurNode]^.Node, 13); + 'C' : Begin + DoUserChat(NodeInfo[CurNode]^.Node); + FullReDraw; + End; + End; End; #32 : Begin Terminal; FullReDraw; End; #27 : Break; - 'G' : If ShowMsgBox(1, 'Kill Ghost on Node ' + strI2S(NodeInfo[CurNode]^.Node)) Then Begin - FileErase(Config.DataPath + 'chat' + strI2S(NodeInfo[CurNode]^.Node) + '.dat'); - - UpdateOnlineStatus; - DrawNodes; - - NodeTimer := TimerSet(UpdateNode); - End; End; If TimerUp(NodeTimer) Then Begin diff --git a/mystic/nodespy_common.pas b/mystic/nodespy_common.pas index 257e571..8a708e1 100644 --- a/mystic/nodespy_common.pas +++ b/mystic/nodespy_common.pas @@ -10,10 +10,12 @@ Uses m_Output, m_Term_Ansi, m_MenuBox, + m_MenuForm, m_MenuInput; -Function ShowMsgBox (BoxType: Byte; Str: String) : Boolean; -Function GetStr (Header, Text, Def: String; Len, MaxLen: Byte) : String; +Function ShowMsgBox (BoxType: Byte; Str: String) : Boolean; +Function GetStr (Header, Text, Def: String; Len, MaxLen: Byte) : String; +Function GetCommandOption (StartY: Byte; CmdStr: String) : Char; {$I RECORDS.PAS} @@ -153,4 +155,43 @@ Begin Result := Str; End; +Function GetCommandOption (StartY: Byte; CmdStr: String) : Char; +Var + Box : TMenuBox; + Form : TMenuForm; + Count : Byte; + Cmds : Byte; + CmdData : Array[1..10] of Record + Key : Char; + Desc : String[18]; + End; +Begin + Cmds := 0; + + While Pos('|', CmdStr) > 0 Do Begin + Inc (Cmds); + + CmdData[Cmds].Key := CmdStr[1]; + CmdData[Cmds].Desc := Copy(CmdStr, 3, Pos('|', CmdStr) - 3); + + Delete (CmdStr, 1, Pos('|', Cmdstr)); + End; + + Box := TMenuBox.Create(Screen); + Form := TMenuForm.Create(Screen); + + Form.HelpSize := 0; + + Box.Open (30, StartY, 51, StartY + Cmds + 1); + + For Count := 1 to Cmds Do + Form.AddNone (CmdData[Count].Key, ' ' + CmdData[Count].Key + ' ' + CmdData[Count].Desc, 31, StartY + Count, 20, ''); + + Result := Form.Execute; + + Form.Free; + Box.Close; + Box.Free; +End; + End.