private void welcomeNewUser(User newUser) { TextMessage welcomeMessage = new TextMessage($"Welcome, {newUser.Name}", ServerDTO.AdminData, (UserData)newUser.Data); ServerDTO.Serializer.Serialize(newUser.nwStream, welcomeMessage); ContactsMessage newContactsDBMessage = new ContactsMessage(ServerDTO.ContactsDB, ServerDTO.AdminData, ServerDTO.AdminData); _messageSender.SendToAllClients(newContactsDBMessage); TextMessage userJoinedChatMessage = new TextMessage($"{newUser.Name} joined the chat!", ServerDTO.AdminData, ServerDTO.AdminData); _messageSender.SendToAllClients(userJoinedChatMessage); }
private void removeUserFromMembersDB(TcpClient client) { User removedUser = _serverDTO.MembersDB.RemoveUser(client); UserData removedUserData = (UserData)removedUser.Data; removeUserFromContactsDB(removedUserData); if (removedUser != null) { TextMessage userLeftChatMessage = new TextMessage($"{removedUser.Name} has left the chat!", _serverDTO.AdminData, _serverDTO.AdminData); _messageSender.SendToAllClients(userLeftChatMessage); ContactsMessage contactsUpdateMessage = new ContactsMessage(_serverDTO.ContactsDB, _serverDTO.AdminData, _serverDTO.AdminData); _messageSender.SendToAllClients(contactsUpdateMessage); // ToDo: move to a function with indicative name } }