Added UserManager.RemoveUser(string inputUser, bool ip)

This commit is contained in:
Lucas Nicodemus 2011-07-12 00:44:39 -06:00
parent b629c6e48f
commit 101aaa4856
2 changed files with 39 additions and 4 deletions

View file

@ -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")
{
}
}
}

View file

@ -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;
}
}
/// <summary>
/// Fetches the hashed password and group for a given username
/// </summary>