mysticbbs/mystic/bbs_nodeinfo.pas

296 lines
8.0 KiB
ObjectPascal
Raw Normal View History

2012-02-22 00:41:08 -08:00
Unit bbs_NodeInfo;
2012-02-13 16:50:48 -08:00
{$I M_OPS.PAS}
Interface
2012-03-10 00:58:11 -08:00
Uses
bbs_Common;
Function GetChatRecord (Node: Byte; Var Chat: ChatRec) : Boolean;
Function IsUserOnline (UserName: String) : Word;
2012-08-21 09:23:47 -07:00
Procedure WhosOnline;
2012-02-13 16:50:48 -08:00
Procedure Send_Node_Message (MsgType: Byte; Data: String; Room: Byte);
Function CheckNodeMessages : Boolean;
2012-02-22 00:41:08 -08:00
Procedure Set_Node_Action (Action: String);
2012-02-13 16:50:48 -08:00
Implementation
Uses
m_Types,
2012-02-13 16:50:48 -08:00
m_DateTime,
m_Strings,
m_FileIO,
2012-02-13 16:50:48 -08:00
bbs_Core,
bbs_User,
bbs_UserChat;
2012-02-13 16:50:48 -08:00
2012-03-10 00:58:11 -08:00
Function GetChatRecord (Node: Byte; Var Chat: ChatRec) : Boolean;
Begin
Result := False;
Assign (ChatFile, Config.DataPath + 'chat' + strI2S(Node) + '.dat');
If Not ioReset(ChatFile, SizeOf(ChatFile), fmRWDN) Then Exit;
Read (ChatFile, Chat);
Close (ChatFile);
Result := True;
End;
Function IsUserOnline (UserName: String) : Word;
2012-02-13 16:50:48 -08:00
Var
TempChat : ChatRec;
Count : Word;
Begin
2012-02-22 00:41:08 -08:00
Result := 0;
2012-02-13 16:50:48 -08:00
For Count := 1 to Config.INetTNNodes Do Begin
2012-03-10 00:58:11 -08:00
If GetChatRecord(Count, TempChat) Then
If (Count <> Session.NodeNum) and (TempChat.Active) and (TempChat.Name = UserName) Then Begin
Result := Count;
Exit;
End;
2012-02-13 16:50:48 -08:00
End;
End;
Procedure Set_Node_Action (Action: String);
Begin
Assign (ChatFile, Config.DataPath + 'chat' + strI2S(Session.NodeNum) + '.dat');
ReWrite (ChatFile);
If Action <> '' Then Begin
Chat.Active := True;
Chat.Name := Session.User.ThisUser.Handle;
Chat.Location := Session.User.ThisUser.City;
Chat.Action := Action;
Chat.Gender := Session.User.ThisUser.Gender;
2012-09-25 16:20:59 -07:00
Chat.Age := DaysAgo(Session.User.ThisUser.Birthday, 1) DIV 365;
2012-02-13 16:50:48 -08:00
If Session.LocalMode Then
Chat.Baud := 'LOCAL' {++lang}
Else
Chat.Baud := 'TELNET'; {++lang}
End Else Begin
Chat.Active := False;
Chat.Invisible := False;
Chat.Available := False;
Chat.Age := 0;
Chat.Gender := '?';
End;
Write (ChatFile, Chat);
Close (ChatFile);
2012-02-22 02:51:16 -08:00
{$IFDEF WINDOWS}
2012-03-10 00:58:11 -08:00
Screen.SetWindowTitle (WinConsoleTitle + strI2S(Session.NodeNum) + ' - ' + Session.User.ThisUser.Handle + ' - ' + strStripPipe(Action));
2012-02-13 16:50:48 -08:00
{$ENDIF}
End;
2012-08-21 09:23:47 -07:00
Procedure WhosOnline;
2012-02-13 16:50:48 -08:00
Var
TChat : ChatRec;
2012-02-22 00:41:08 -08:00
Count : Word;
2012-02-13 16:50:48 -08:00
Begin
Session.io.OutFullLn (Session.GetPrompt(138));
2012-02-22 00:41:08 -08:00
For Count := 1 to Config.INetTNNodes Do Begin
Session.io.PromptInfo[1] := strI2S(Count);
2012-08-21 09:23:47 -07:00
If Not GetChatRecord (Count, TChat) Then Begin
Session.io.OutFullLn (Session.GetPrompt(268));
Continue;
End;
2012-02-22 00:41:08 -08:00
2012-02-13 16:50:48 -08:00
If TChat.Active and ((Not TChat.Invisible) or (TChat.Invisible and Session.User.Access(Config.AcsSeeInvis))) Then Begin
Session.io.PromptInfo[2] := TChat.Name;
Session.io.PromptInfo[3] := TChat.Action;
Session.io.PromptInfo[4] := TChat.Location;
Session.io.PromptInfo[5] := TChat.Baud;
Session.io.PromptInfo[6] := TChat.Gender;
Session.io.PromptInfo[7] := strI2S(TChat.Age);
Session.io.PromptInfo[8] := Session.io.OutYN(TChat.Available);
2012-02-22 00:41:08 -08:00
2012-02-13 16:50:48 -08:00
Session.io.OutFullLn (Session.GetPrompt(139));
End Else
2012-02-13 16:50:48 -08:00
Session.io.OutFullLn (Session.GetPrompt(268));
End;
Session.io.OutFull (Session.GetPrompt(140));
End;
Procedure Send_Node_Message (MsgType: Byte; Data: String; Room: Byte);
Var
ToNode : Byte;
A, B, C : Byte;
Temp : ChatRec;
2012-03-10 00:58:11 -08:00
NodeMsgFile : File of NodeMsgRec;
NodeMsg : NodeMsgRec;
SkipCurrent : Boolean = False;
2012-02-13 16:50:48 -08:00
Begin
If Data = '' Then Begin
Repeat
Session.io.OutFull (Session.GetPrompt(146));
2013-02-26 04:45:01 -08:00
Case Session.io.OneKeyRange('?Q', 1, Config.INetTNNodes) of
#00 : Break;
'?' : WhosOnline;
'Q' : Break;
End;
2012-02-13 16:50:48 -08:00
Until False;
2013-02-26 04:45:01 -08:00
ToNode := Session.io.RangeValue;
2012-02-13 16:50:48 -08:00
If (ToNode < 0) or (ToNode > Config.INetTNNodes) Then Begin
2012-02-13 16:50:48 -08:00
Session.io.OutFullLn (Session.GetPrompt(147));
Exit;
End;
B := ToNode;
C := ToNode;
End Else Begin
If Pos(';', Data) = 0 Then Exit;
2012-02-22 00:41:08 -08:00
2012-02-13 16:50:48 -08:00
ToNode := strS2I(Copy(Data, 1, Pos(';', Data)-1));
2012-02-22 00:41:08 -08:00
2012-02-13 16:50:48 -08:00
Delete (Data, 1, Pos(';', Data));
2012-02-22 00:41:08 -08:00
2012-02-13 16:50:48 -08:00
If ToNode = 0 Then Begin
B := 1;
C := Config.INetTNNodes;
If MsgType = 3 Then Begin
MsgType := 2;
SkipCurrent := True;
End;
2012-02-13 16:50:48 -08:00
End Else Begin
B := ToNode;
C := ToNode;
End;
End;
For A := B to C Do Begin
If (A = Session.NodeNum) and SkipCurrent Then Continue;
2012-03-10 00:58:11 -08:00
If GetChatRecord(A, Temp) Then Begin
2012-02-13 16:50:48 -08:00
If (Not Temp.Active) and (ToNode > 0) Then Begin
Session.io.OutFullLn (Session.GetPrompt(147));
Exit;
End;
If (Not Temp.Available) and not (MsgType in [1, 4..7]) and (ToNode > 0) Then Begin
Session.io.OutFullLn (Session.GetPrompt(395));
Exit;
End;
If Temp.Active and (Temp.Available or Temp.InChat) Then Begin
If Data = '' Then Begin
2012-02-22 00:41:08 -08:00
Session.io.PromptInfo[1] := Temp.Name;
2012-02-13 16:50:48 -08:00
Session.io.PromptInfo[2] := strI2S(A);
2012-02-22 00:41:08 -08:00
2012-02-13 16:50:48 -08:00
Session.io.OutFullLn (Session.GetPrompt(148));
2012-02-22 00:41:08 -08:00
2012-02-13 16:50:48 -08:00
NodeMsg.Message := Session.io.GetInput(79, 79, 11, '');
End Else
NodeMsg.Message := Data;
If NodeMsg.Message = '' Then Exit;
NodeMsg.FromNode := Session.NodeNum;
NodeMsg.ToWho := Temp.Name;
NodeMsg.MsgType := MsgType;
NodeMsg.Room := Room;
NodeMsg.FromWho := Session.User.ThisUser.Handle;
FileMode := 66;
2012-02-22 00:41:08 -08:00
Assign (NodeMsgFile, Config.SystemPath + 'temp' + strI2S(A) + PathChar + 'chat.tmp');
If Not ioReset (NodeMsgFile, SizeOf(NodeMsg), fmReadWrite + fmDenyAll) Then
ioReWrite(NodeMsgFile, SizeOf(NodeMsg), fmReadWrite + fmDenyAll);
2012-02-13 16:50:48 -08:00
Seek (NodeMsgFile, FileSize(NodeMsgFile));
Write (NodeMsgFile, NodeMsg);
Close (NodeMsgFile);
End;
End;
End;
2012-02-13 16:50:48 -08:00
End;
Function CheckNodeMessages : Boolean;
Var
2012-03-13 23:22:52 -07:00
Str : String;
Image : TConsoleImageRec;
Msg : NodeMsgRec;
MsgFile : File of NodeMsgRec;
SplitChat : Boolean;
Begin
2012-08-21 09:23:47 -07:00
Result := False;
2012-03-10 00:58:11 -08:00
Assign (MsgFile, Session.TempPath + 'chat.tmp');
2012-03-10 00:58:11 -08:00
If Not ioReset(MsgFile, SizeOf(Msg), fmReadWrite + fmDenyAll) Then
Exit;
2012-03-10 00:58:11 -08:00
If FileSize(MsgFile) = 0 Then Begin
Close (MsgFile);
Exit;
End;
Session.InMessage := True;
CheckNodeMessages := True;
2012-03-10 00:58:11 -08:00
Read (MsgFile, Msg);
KillRecord (MsgFile, 1, SizeOf(Msg));
Close (MsgFile);
Screen.GetScreenImage (1, 1, 79, 24, Image);
2012-03-10 00:58:11 -08:00
Session.io.PromptInfo[1] := Msg.FromWho;
Session.io.PromptInfo[2] := strI2S(Msg.FromNode);
Session.io.PromptInfo[3] := Msg.Message;
2012-03-13 23:22:52 -07:00
SplitChat := (strS2I(Msg.Message) > 0) and (Session.io.Graphics > 0);
2012-03-10 00:58:11 -08:00
Case Msg.MsgType of
2 : Begin
2012-03-10 00:58:11 -08:00
Session.io.OutFullLn (Session.GetPrompt(179) + Msg.Message);
Session.io.OutFullLn (Session.GetPrompt(180));
End;
3 : Begin
2012-03-10 00:58:11 -08:00
Session.io.OutFullLn (Session.GetPrompt(144) + '|CR' + Msg.Message);
Session.io.OutFull (Session.GetPrompt(145));
End;
2012-03-13 23:22:52 -07:00
8 : If Session.io.GetYN(Session.GetPrompt(485), True) Then Begin
Send_Node_Message (10, strI2S(Msg.FromNode) + ';' + strI2S(Session.io.Graphics), 0);
OpenUserChat(SplitChat, False, Msg.FromNode);
End;
9 : Begin
2012-03-13 23:22:52 -07:00
Send_Node_Message (10, strI2S(Msg.FromNode) + ';' + strI2S(Session.io.Graphics), 0);
OpenUserChat(SplitChat, True, Msg.FromNode);
End;
2012-03-13 23:22:52 -07:00
10: OpenUserChat(SplitChat, False, Msg.FromNode);
2012-08-21 09:23:47 -07:00
11: Begin
Session.Pipe.CreatePipe;
Session.Pipe.WaitForPipe(300);
End;
12: If Session.Pipe.Connected Then Session.Pipe.Disconnect;
13: Halt(0);
End;
2012-03-10 00:58:11 -08:00
If Result And (Msg.MsgType = 3) Then
If Session.io.OneKey(#13 + 'R', True) = 'R' Then Begin
Session.io.OutFullLn(Session.GetPrompt(360));
Str := Session.io.GetInput(79, 79, 11, '');
If Str <> '' Then Send_Node_Message(3, Session.io.PromptInfo[2] + ';' + Str, 0);
End;
Session.io.RemoteRestore(Image);
Session.InMessage := False;
End;
2013-02-26 04:45:01 -08:00
End.