Added /lists/bans REST endpoint - Returns a JSON list of bans

This commit is contained in:
Lucas Nicodemus 2012-02-09 22:20:36 -07:00
parent 5cdd537ebd
commit 454403d495
2 changed files with 32 additions and 0 deletions

View file

@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using MySql.Data.MySqlClient;
@ -67,6 +68,28 @@ throw new Exception("Could not find a database library (probably Sqlite3.dll)");
return null;
}
public List<Ban> GetBans()
{
List<Ban> banlist = new List<Ban>();
try
{
using (var reader = database.QueryReader("SELECT * FROM Bans"))
{
while (reader.Read())
{
banlist.Add(new Ban(reader.Get<string>("IP"), reader.Get<string>("Name"), reader.Get<string>("Reason")));
}
return banlist;
}
}
catch (Exception ex)
{
Log.Error(ex.ToString());
Console.WriteLine(ex.StackTrace);
}
return null;
}
public Ban GetBanByName(string name, bool casesensitive = true)
{
if (!TShock.Config.EnableBanOnUsernames)

View file

@ -48,6 +48,7 @@ namespace TShockAPI
Rest.Register(new RestCommand("/v2/bans/read", BanInfoV2) { RequiresToken = true });
Rest.Register(new RestCommand("/v2/bans/destroy", BanDestroyV2) { RequiresToken = true });
Rest.Register(new RestCommand("/lists/bans", BanListIPs) { RequiresToken = true });
Rest.Register(new RestCommand("/lists/players", PlayerList) {RequiresToken = true});
Rest.Register(new RestCommand("/world/read", WorldRead) {RequiresToken = true});
@ -252,6 +253,14 @@ namespace TShockAPI
#region RestBanMethods
private object BanListIPs(RestVerbs verbs, IParameterCollection parameters)
{
RestObject returnItem = new RestObject("200");
returnItem.Add("bans", TShock.Bans.GetBans());
return returnItem;
}
private object BanCreate(RestVerbs verbs, IParameterCollection parameters)
{
var returnBlock = new Dictionary<string, string>();