private void AddUserToChat(NetworkPacket netPacket, string defaultChat, User user) { Chat activeChat = chatList.Find(chat => chat.ChatName.Equals(defaultChat)); if (activeChat != null) { /* * Add user to defaultChat */ activeChat.AddUser(user); /* * Create GetChatUserList request for defaultChat */ RequestGetChatUserList requestGetChatUserList = new RequestGetChatUserList(-1, defaultChat, activeChat.GetUserChatInfoList()); Console.WriteLine("Send getChatUserList update to {0} users {1} / {2}", activeChat.GetUserList().Count, activeChat.GetUserChatInfoList().Count, requestGetChatUserList.UserChatInfoList.Count); NetworkPacket sendPacket = new NetworkPacket(netPacket.WorkSocket, requestGetChatUserList.Serialize()); /* * Notify every user in chat of the newcomer's arrival */ activeChat.GetUserList().ForEach(userInChat => { Console.WriteLine("Send message packet to {0}", userInChat.Username); AsyncSendPacket(sendPacket, userInChat); }); Console.WriteLine("Send getChatUserList update to {0} users3", activeChat.GetUserList().Count); } }
private void GetChatUserList(NetworkPacket netPacket) { RequestGetChatUserList requestGetChatUserList = new RequestGetChatUserList(); requestGetChatUserList.Deserialize(netPacket.Message.ToArray()); Console.WriteLine("GetChatUserList - ChatName: {0}", requestGetChatUserList.ChatName); Chat activeChat = chatList.Find(chat => chat.ChatName.Equals(requestGetChatUserList.ChatName)); if (activeChat != null) { requestGetChatUserList.UserChatInfoList = activeChat.GetUserChatInfoList(); } NetworkPacket sendPacket = new NetworkPacket( netPacket.WorkSocket, requestGetChatUserList.Serialize()); int result = networkManager.Send(sendPacket); }