public Message CreateMyInfoMessage(Node MessageTo) { Message p = new Message(network, MessageType.MyInfo); p.To = MessageTo.NodeID; TrustedNodeInfo t = network.TrustedNodes[MessageTo.NodeID]; NodeInfo nodeInfo = new NodeInfo(); nodeInfo.NodeID = network.LocalNode.NodeID; nodeInfo.NickName = network.LocalNode.NickName; nodeInfo.AvatarSize = network.LocalNode.AvatarSize; if (MessageTo.IsConnectedLocally == true || t.AllowNetworkInfo == true) { nodeInfo.DestinationInfos = Core.DestinationManager.DestinationInfos; } if (t.AllowProfile == true) { nodeInfo.RealName = network.LocalNode.RealName; nodeInfo.Email = network.LocalNode.Email; } nodeInfo.ClientName = network.LocalNode.ClientName; nodeInfo.ClientVersion = network.LocalNode.ClientVersion; if (t.AllowSharedFiles == true) { nodeInfo.Bytes = network.LocalNode.Bytes; nodeInfo.Files = network.LocalNode.Files; } List<ConnectionInfo> connections = new List<ConnectionInfo>(); List<ChatRoomInfo> rooms = new List<ChatRoomInfo>(); List<MemoInfo> memos = new List<MemoInfo>(); foreach (INodeConnection con in network.Connections) { if (con.NodeLocal != MessageTo & con.NodeRemote != MessageTo) { if (con.ConnectionState == ConnectionState.Ready | con.ConnectionState == ConnectionState.Remote) { ConnectionInfo n = new ConnectionInfo(); Node ConnectionSourceNode = con.NodeLocal; Node ConnectionDestNode = con.NodeRemote; n.SourceNodeID = ConnectionSourceNode.NodeID; n.SourceNodeNickname = ConnectionSourceNode.NickName; n.DestNodeID = ConnectionDestNode.NodeID; n.DestNodeNickname = ConnectionDestNode.NickName; connections.Add (n); } } } foreach (ChatRoom currentRoom in network.ChatRooms) { ChatRoomInfo roomInfo = new ChatRoomInfo(); roomInfo.Id = currentRoom.Id; roomInfo.Name = currentRoom.Name; roomInfo.Users = new string[currentRoom.Users.Count]; int x = 0; foreach (Node node in currentRoom.Users.Values) { roomInfo.Users[x] = node.NodeID; x ++; } rooms.Add(roomInfo); } foreach (Memo currentMemo in network.Memos) { if (Core.IsLocalNode(currentMemo.Node)) { MemoInfo info = new MemoInfo(currentMemo); memos.Add(info); } } nodeInfo.KnownConnections = connections.ToArray(); nodeInfo.KnownChatRooms = rooms.ToArray(); nodeInfo.KnownMemos = memos.ToArray(); p.Content = nodeInfo; return p; }
internal ChatRoom(Network network, ChatRoomInfo info) { this.network = network; this.id = info.Id; this.name = info.Name; }
public Message CreateHelloMessage() { Message message = new Message (network, MessageType.Hello); HelloInfo hello = new HelloInfo (); List<ConnectionInfo> connections = new List<ConnectionInfo>(); List<ChatRoomInfo> rooms = new List<ChatRoomInfo>(); List<MemoInfo> memos = new List<MemoInfo>(); foreach (INodeConnection con in network.Connections) { if (con.ConnectionState == ConnectionState.Ready | con.ConnectionState == ConnectionState.Remote) { ConnectionInfo n = new ConnectionInfo(); Node ConnectionSourceNode = con.NodeLocal; Node ConnectionDestNode = con.NodeRemote; n.SourceNodeID = ConnectionSourceNode.NodeID; n.SourceNodeNickname = ConnectionSourceNode.NickName; n.DestNodeID = ConnectionDestNode.NodeID; n.DestNodeNickname = ConnectionDestNode.NickName; connections.Add(n); } } foreach (ChatRoom currentRoom in network.ChatRooms) { ChatRoomInfo tmpRoom = new ChatRoomInfo(); tmpRoom.Id = currentRoom.Id; tmpRoom.Name = currentRoom.Name; tmpRoom.Users = new string[currentRoom.Users.Count]; int x = 0; foreach (Node node in currentRoom.Users.Values) { tmpRoom.Users[x] = node.NodeID; x ++; } rooms.Add(tmpRoom); } foreach (Memo currentMemo in network.Memos) { MemoInfo info = new MemoInfo(currentMemo); memos.Add(info); } hello.KnownConnections = connections.ToArray(); hello.KnownChatRooms = rooms.ToArray(); hello.KnownMemos = memos.ToArray(); hello.MyNickName = network.LocalNode.NickName; message.Content = hello; return message; }