Moved BanManager/WarpsManager
Added UserManager (empty)
This commit is contained in:
parent
d3cdb1095a
commit
6d531283fc
6 changed files with 208 additions and 176 deletions
|
|
@ -26,6 +26,7 @@ using System.Net;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Terraria;
|
using Terraria;
|
||||||
|
using TShockAPI.DB;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
|
|
@ -956,16 +957,16 @@ namespace TShockAPI
|
||||||
if (args.Parameters.Count > 1)
|
if (args.Parameters.Count > 1)
|
||||||
int.TryParse(args.Parameters[1], out page);
|
int.TryParse(args.Parameters[1], out page);
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
if (WarpManager.Warps.Count > (15 * (page - 1)))
|
if (TShock.Warps.Warps.Count > (15 * (page - 1)))
|
||||||
{
|
{
|
||||||
for (int j = (15 * (page - 1)); j < (15 * page); j++)
|
for (int j = (15 * (page - 1)); j < (15 * page); j++)
|
||||||
{
|
{
|
||||||
if (WarpManager.Warps[j].WorldWarpName == Main.worldName)
|
if (TShock.Warps.Warps[j].WorldWarpName == Main.worldName)
|
||||||
{
|
{
|
||||||
if (sb.Length != 0)
|
if (sb.Length != 0)
|
||||||
sb.Append(", ");
|
sb.Append(", ");
|
||||||
sb.Append("/").Append(WarpManager.Warps[j].WarpName);
|
sb.Append("/").Append(TShock.Warps.Warps[j].WarpName);
|
||||||
if (j == WarpManager.Warps.Count - 1)
|
if (j == TShock.Warps.Warps.Count - 1)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage(sb.ToString(), Color.Yellow);
|
args.Player.SendMessage(sb.ToString(), Color.Yellow);
|
||||||
break;
|
break;
|
||||||
|
|
@ -978,7 +979,7 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (WarpManager.Warps.Count > (15 * page))
|
if (TShock.Warps.Warps.Count > (15 * page))
|
||||||
{
|
{
|
||||||
args.Player.SendMessage(string.Format("Type /warp list {0} for more warps.", (page + 1)), Color.Yellow);
|
args.Player.SendMessage(string.Format("Type /warp list {0} for more warps.", (page + 1)), Color.Yellow);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,167 +1,167 @@
|
||||||
/*
|
/*
|
||||||
TShock, a server mod for Terraria
|
TShock, a server mod for Terraria
|
||||||
Copyright (C) 2011 The TShock Team
|
Copyright (C) 2011 The TShock Team
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Community.CsharpSqlite.SQLiteClient;
|
using Community.CsharpSqlite.SQLiteClient;
|
||||||
using TShockAPI.DB;
|
using TShockAPI.DB;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI.DB
|
||||||
{
|
{
|
||||||
public class BanManager
|
public class BanManager
|
||||||
{
|
{
|
||||||
private IDbConnection database;
|
private IDbConnection database;
|
||||||
|
|
||||||
public BanManager(IDbConnection db)
|
public BanManager(IDbConnection db)
|
||||||
{
|
{
|
||||||
database = db;
|
database = db;
|
||||||
|
|
||||||
using (var com = database.CreateCommand())
|
using (var com = database.CreateCommand())
|
||||||
{
|
{
|
||||||
com.CommandText =
|
com.CommandText =
|
||||||
"CREATE TABLE IF NOT EXISTS \"Bans\" (\"IP\" VARCHAR(15) NOT NULL UNIQUE , \"Name\" VARCHAR(32) NOT NULL , \"Reason\" VARCHAR(255) NOT NULL );";
|
"CREATE TABLE IF NOT EXISTS \"Bans\" (\"IP\" VARCHAR(15) NOT NULL UNIQUE , \"Name\" VARCHAR(32) NOT NULL , \"Reason\" VARCHAR(255) NOT NULL );";
|
||||||
com.ExecuteNonQuery();
|
com.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ban GetBanByIp(string ip)
|
public Ban GetBanByIp(string ip)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var com = database.CreateCommand())
|
using (var com = database.CreateCommand())
|
||||||
{
|
{
|
||||||
com.CommandText = "SELECT * FROM Bans WHERE IP=@ip";
|
com.CommandText = "SELECT * FROM Bans WHERE IP=@ip";
|
||||||
com.AddParameter("@ip", ip);
|
com.AddParameter("@ip", ip);
|
||||||
using (var reader = com.ExecuteReader())
|
using (var reader = com.ExecuteReader())
|
||||||
{
|
{
|
||||||
if (reader.Read())
|
if (reader.Read())
|
||||||
return new Ban((string)reader["IP"], (string)reader["Name"], (string)reader["Reason"]);
|
return new Ban((string)reader["IP"], (string)reader["Name"], (string)reader["Reason"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SqliteExecutionException ex)
|
catch (SqliteExecutionException ex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ban GetBanByName(string name, bool casesensitive = true)
|
public Ban GetBanByName(string name, bool casesensitive = true)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var com = database.CreateCommand())
|
using (var com = database.CreateCommand())
|
||||||
{
|
{
|
||||||
var namecol = casesensitive ? "Name" : "UPPER(Name)";
|
var namecol = casesensitive ? "Name" : "UPPER(Name)";
|
||||||
if (!casesensitive)
|
if (!casesensitive)
|
||||||
name = name.ToUpper();
|
name = name.ToUpper();
|
||||||
com.CommandText = "SELECT * FROM Bans WHERE " + namecol + "=@name";
|
com.CommandText = "SELECT * FROM Bans WHERE " + namecol + "=@name";
|
||||||
com.AddParameter("@name", name);
|
com.AddParameter("@name", name);
|
||||||
using (var reader = com.ExecuteReader())
|
using (var reader = com.ExecuteReader())
|
||||||
{
|
{
|
||||||
if (reader.Read())
|
if (reader.Read())
|
||||||
return new Ban((string)reader["IP"], (string)reader["Name"], (string)reader["Reason"]);
|
return new Ban((string)reader["IP"], (string)reader["Name"], (string)reader["Reason"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SqliteExecutionException ex)
|
catch (SqliteExecutionException ex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AddBan(string ip, string name = "", string reason = "")
|
public bool AddBan(string ip, string name = "", string reason = "")
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var com = database.CreateCommand())
|
using (var com = database.CreateCommand())
|
||||||
{
|
{
|
||||||
com.CommandText = "INSERT INTO Bans (IP, Name, Reason) VALUES (@ip, @name, @reason)";
|
com.CommandText = "INSERT INTO Bans (IP, Name, Reason) VALUES (@ip, @name, @reason)";
|
||||||
com.AddParameter("@ip", ip);
|
com.AddParameter("@ip", ip);
|
||||||
com.AddParameter("@name", name);
|
com.AddParameter("@name", name);
|
||||||
com.AddParameter("@reason", reason);
|
com.AddParameter("@reason", reason);
|
||||||
com.ExecuteNonQuery();
|
com.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (SqliteExecutionException ex)
|
catch (SqliteExecutionException ex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool RemoveBan(string ip)
|
public bool RemoveBan(string ip)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var com = database.CreateCommand())
|
using (var com = database.CreateCommand())
|
||||||
{
|
{
|
||||||
com.CommandText = "DELETE FROM Bans WHERE IP=@ip";
|
com.CommandText = "DELETE FROM Bans WHERE IP=@ip";
|
||||||
com.AddParameter("@ip", ip);
|
com.AddParameter("@ip", ip);
|
||||||
com.ExecuteNonQuery();
|
com.ExecuteNonQuery();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SqliteExecutionException ex)
|
catch (SqliteExecutionException ex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public bool ClearBans()
|
public bool ClearBans()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var com = database.CreateCommand())
|
using (var com = database.CreateCommand())
|
||||||
{
|
{
|
||||||
com.CommandText = "DELETE FROM Bans";
|
com.CommandText = "DELETE FROM Bans";
|
||||||
com.ExecuteNonQuery();
|
com.ExecuteNonQuery();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SqliteExecutionException ex)
|
catch (SqliteExecutionException ex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Ban
|
public class Ban
|
||||||
{
|
{
|
||||||
public string IP { get; set; }
|
public string IP { get; set; }
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
public string Reason { get; set; }
|
public string Reason { get; set; }
|
||||||
|
|
||||||
public Ban(string ip, string name, string reason)
|
public Ban(string ip, string name, string reason)
|
||||||
{
|
{
|
||||||
IP = ip;
|
IP = ip;
|
||||||
Name = name;
|
Name = name;
|
||||||
Reason = reason;
|
Reason = reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ban()
|
public Ban()
|
||||||
{
|
{
|
||||||
IP = string.Empty;
|
IP = string.Empty;
|
||||||
Name = string.Empty;
|
Name = string.Empty;
|
||||||
Reason = string.Empty;
|
Reason = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
29
TShockAPI/DB/UserManager.cs
Normal file
29
TShockAPI/DB/UserManager.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
TShock, a server mod for Terraria
|
||||||
|
Copyright (C) 2011 The TShock Team
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
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.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace TShockAPI.DB
|
||||||
|
{
|
||||||
|
public class UserManager
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -28,13 +28,13 @@ using System.Xml;
|
||||||
using Terraria;
|
using Terraria;
|
||||||
using TShockAPI.DB;
|
using TShockAPI.DB;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI.DB
|
||||||
{
|
{
|
||||||
public class WarpManager
|
public class WarpManager
|
||||||
{
|
{
|
||||||
private IDbConnection database;
|
private IDbConnection database;
|
||||||
|
|
||||||
public static List<Warp> Warps = new List<Warp>();
|
public List<Warp> Warps = new List<Warp>();
|
||||||
|
|
||||||
public WarpManager(IDbConnection db)
|
public WarpManager(IDbConnection db)
|
||||||
{
|
{
|
||||||
|
|
@ -30,6 +30,7 @@ using Terraria;
|
||||||
using TerrariaAPI;
|
using TerrariaAPI;
|
||||||
using TerrariaAPI.Hooks;
|
using TerrariaAPI.Hooks;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using TShockAPI.DB;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -76,8 +76,9 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="BackupManager.cs" />
|
<Compile Include="BackupManager.cs" />
|
||||||
<Compile Include="BanManager.cs" />
|
<Compile Include="DB\BanManager.cs" />
|
||||||
<Compile Include="DB\DbExt.cs" />
|
<Compile Include="DB\DbExt.cs" />
|
||||||
|
<Compile Include="DB\UserManager.cs" />
|
||||||
<Compile Include="IPackable.cs" />
|
<Compile Include="IPackable.cs" />
|
||||||
<Compile Include="ItemManager.cs" />
|
<Compile Include="ItemManager.cs" />
|
||||||
<Compile Include="Commands.cs" />
|
<Compile Include="Commands.cs" />
|
||||||
|
|
@ -99,7 +100,7 @@
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="TSPlayer.cs" />
|
<Compile Include="TSPlayer.cs" />
|
||||||
<Compile Include="UpdateManager.cs" />
|
<Compile Include="UpdateManager.cs" />
|
||||||
<Compile Include="WarpsManager.cs" />
|
<Compile Include="DB\WarpsManager.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="config\groups.txt" />
|
<None Include="config\groups.txt" />
|
||||||
|
|
@ -150,7 +151,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ProjectExtensions>
|
<ProjectExtensions>
|
||||||
<VisualStudio>
|
<VisualStudio>
|
||||||
<UserProperties BuildVersion_IncrementBeforeBuild="False" BuildVersion_StartDate="2011/6/17" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_BuildAction="Both" BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" />
|
<UserProperties BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" BuildVersion_BuildAction="Both" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_StartDate="2011/6/17" BuildVersion_IncrementBeforeBuild="False" />
|
||||||
</VisualStudio>
|
</VisualStudio>
|
||||||
</ProjectExtensions>
|
</ProjectExtensions>
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue