public void recievePacketSessions(PacketSessions sessionsPacket) { Sessions = sessionsPacket.sessions; Console.WriteLine("sessions added to the list!"); }
public void receivePacketRequestSessions(PacketRequestSessions sessionsPacket) { List<Session> sessions = new List<Session>(); //loop through the files in de dir (CHECKED) string[] files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory); Console.WriteLine(files); int id = 0; foreach (string file in files) { if (file.Contains(".session") && (file.Contains(sessionsPacket.username) || sessionsPacket.username == "monitor")) { //file belongs to the user var fil2e = File.Open(file, FileMode.Open); //read the data BinaryFormatter formatter = new BinaryFormatter(); Session session = (Session)formatter.Deserialize(fil2e); //get id from the filename session.ID = id; id++; //add sessions to the list sessions.Add(session); //close fil2e.Close(); } } PacketSessions packetSessions = new PacketSessions(sessions); if (sessionsPacket.username == "monitor") { _server.sendPackToMonitor(packetSessions); } else { _server.sendPacketToClient(packetSessions, sessionsPacket.id); } }