From 4daa9add13cc0b8f786c0c46ec0037041ef018d3 Mon Sep 17 00:00:00 2001 From: stevenh Date: Mon, 13 Feb 2012 19:16:20 +0000 Subject: [PATCH] Added GetUsers method mirroring GetBans to enable RestAPI to provide a full users list as well as an active one --- TShockAPI/DB/UserManager.cs | 41 +++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/TShockAPI/DB/UserManager.cs b/TShockAPI/DB/UserManager.cs index 29944e18..7ea6c63a 100644 --- a/TShockAPI/DB/UserManager.cs +++ b/TShockAPI/DB/UserManager.cs @@ -18,6 +18,7 @@ along with this program. If not, see . using System; using System.Data; using System.IO; +using System.Collections.Generic; using MySql.Data.MySqlClient; namespace TShockAPI.DB @@ -256,14 +257,7 @@ namespace TShockAPI.DB using (var reader = result) { if (reader.Read()) - { - user.ID = reader.Get("ID"); - user.Group = reader.Get("Usergroup"); - user.Password = reader.Get("Password"); - user.Name = reader.Get("Username"); - user.Address = reader.Get("IP"); - return user; - } + return LoadUserFromResult(user, result); } } catch (Exception ex) @@ -272,6 +266,37 @@ namespace TShockAPI.DB } throw new UserNotExistException(string.IsNullOrEmpty(user.Address) ? user.Name : user.Address); } + + public List GetUsers() + { + try + { + List users = new List(); + using (var reader = database.QueryReader("SELECT * FROM Users")) + { + while (reader.Read()) + { + users.Add(LoadUserFromResult(new User(), reader)); + } + return users; + } + } + catch (Exception ex) + { + Log.Error(ex.ToString()); + } + return null; + } + + private User LoadUserFromResult(User user, QueryResult result) + { + user.ID = result.Get("ID"); + user.Group = result.Get("Usergroup"); + user.Password = result.Get("Password"); + user.Name = result.Get("Username"); + user.Address = result.Get("IP"); + return user; + } } public class User