From 101aaa4856f800e8f20a368045e2ddc8b74d435b Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Tue, 12 Jul 2011 00:44:39 -0600 Subject: [PATCH] Added UserManager.RemoveUser(string inputUser, bool ip) --- TShockAPI/Commands.cs | 8 ++++---- TShockAPI/DB/UserManager.cs | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index bc21bd0d..5a44ea12 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -359,10 +359,10 @@ namespace TShockAPI args.Player.SendMessage("Could not add user", Color.Green); return; } - else - { - args.Player.SendMessage("Invalid syntax. Try /user help.", Color.Red); - } + args.Player.SendMessage("Invalid syntax. Try /user help.", Color.Red); + } else if (args.Parameters[0] == "del") + { + } } } diff --git a/TShockAPI/DB/UserManager.cs b/TShockAPI/DB/UserManager.cs index 1a881792..7c19ad42 100644 --- a/TShockAPI/DB/UserManager.cs +++ b/TShockAPI/DB/UserManager.cs @@ -94,6 +94,41 @@ namespace TShockAPI.DB } } + public int RemoveUser(string inputUser, bool ip) + { + try + { + using (var com = database.CreateCommand()) + { + if (ip) + { + com.CommandText = "DELETE FROM Users WHERE IP=`@ip`"; + com.AddParameter("@ip", inputUser.ToLower()); + } else + { + com.CommandText = "DELETE FROM Users WHERE Username=`@name`"; + com.AddParameter("@name", inputUser.ToLower()); + } + + using (var reader = com.ExecuteReader()) + { + if (reader.RecordsAffected > 0) + //Return code 1 (User removed) + return 1; + else + //Return code 0 (Remove failed) + return 0; + } + } + } + catch (SqliteExecutionException ex) + { + //Return code 0 (Remove failed) + Log.Error(ex.ToString()); + return 0; + } + } + /// /// Fetches the hashed password and group for a given username ///