diff --git a/TShockAPI/DB/UserManager.cs b/TShockAPI/DB/UserManager.cs
index 56fcd056..b7047a7b 100755
--- a/TShockAPI/DB/UserManager.cs
+++ b/TShockAPI/DB/UserManager.cs
@@ -314,6 +314,35 @@ namespace TShockAPI.DB
return null;
}
+ ///
+ /// GetUsersByName - Gets all users from the database with a username that starts with or contains
+ ///
+ /// String - Rough username search. "n" will match "n", "na", "nam", "name", etc
+ /// Boolean - If is not the first part of the username. If true then "name" would match "name", "username", "wordsnamewords", etc
+ /// List or null - Matching users or null if exception is thrown
+ public List GetUsersByName(string username, bool notAtStart = false)
+ {
+ try
+ {
+ List users = new List();
+ string search = notAtStart ? string.Format("%{0}%", username) : string.Format("{0}%", username);
+ using (var reader = database.QueryReader("SELECT * FROM Users WHERE Username LIKE @0",
+ search))
+ {
+ while (reader.Read())
+ {
+ users.Add(LoadUserFromResult(new User(), reader));
+ }
+ }
+ return users;
+ }
+ catch (Exception ex)
+ {
+ TShock.Log.Error(ex.ToString());
+ }
+ return null;
+ }
+
/// LoadUserFromResult - Fills out the fields of a User object with the results from a QueryResult object.
/// user - The user to add data to.
/// result - The QueryResult object to add data from.