Fix serverside "list" command

This commit is contained in:
Gabriel Tofvesson 2018-05-15 23:37:09 +02:00
parent 9755f06120
commit 1a04a0b2cb
2 changed files with 13 additions and 18 deletions

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Client.ConsoleForms;
using Client.ConsoleForms.Graphics;

View File

@ -317,28 +317,18 @@ namespace Server
public User[] Users(Predicate<User> p)
{
List<User> l = new List<User>();
// Get changed users
foreach (var entry in changeList)
if (p(entry))
l.Add(entry);
// Get loaded users
foreach(var entry in loadedUsers)
if (!l.Contains(entry) && p(entry))
l.Add(entry);
/*
using (var reader = XmlReader.Create(DatabaseName))
{
if (!Traverse(reader, MasterEntry)) return null;
while (((reader.NodeType==XmlNodeType.Element && reader.Name.Equals("User")) || SkipSpaces(reader)) && reader.NodeType != XmlNodeType.EndElement)
{
if (reader.NodeType == XmlNodeType.EndElement) break;
User e = User.Parse(ReadEntry(reader), this);
if (e!=null && !l.Contains(e = FromEncoded(e)) && p(e)) l.Add(e);
}
}
*/
// Get from database
using (var reader = XmlReader.Create(DatabaseName))
{
if (!Traverse(reader, MasterEntry)) return null;
@ -355,6 +345,15 @@ namespace Server
}
}
// Remove users scheduled for eviction
foreach(var user in toRemove)
for(int i = l.Count - 1; i>=0; --i)
if (l[i].Name.Equals(user.Name))
{
l.RemoveAt(i);
i = -1;
}
return l.ToArray();
}