public NetworkState(HelloInfo info) { this.knownConnections = info.KnownConnections; this.knownChatRooms = info.KnownChatRooms; this.knownMemos = info.KnownMemos; }
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; }
internal void ProcessHelloMessage(Node messageFrom, HelloInfo hello) { messageFrom.NickName = hello.MyNickName; network.AppendNetworkState (new NetworkState(hello)); }