public IEnumerable<PlayerInfo> FindByPattern( string pattern, int limit ) {
if( pattern == null ) throw new ArgumentNullException( "pattern" );
string regexString = "^" + RegexNonNameChars.Replace( pattern, "" ).Replace( "*", ".*" ).Replace( "?", "." ) + "$";
Regex regex = new Regex( regexString, RegexOptions.IgnoreCase );
List<PlayerInfo> result = new List<PlayerInfo>();
using( PlayerDB.GetReadLock() ) {
int total = PlayerDB.List.Count;
for( int i = 0; i < total; i++ ) {
if( regex.IsMatch( PlayerDB.List[i].Name ) ) {
result.Add( PlayerDB.List[i] );
if( result.Count >= limit ) break;
}
}
}
return result.ToArray();
}