Merge remote-tracking branch 'remotes/origin/general-devel'
Conflicts: TShockAPI/Commands.cs TShockAPI/DB/GroupManager.cs TShockAPI/DB/RegionManager.cs TShockAPI/Properties/AssemblyInfo.cs Terraria.sln
This commit is contained in:
commit
5c59ebf71a
18 changed files with 660 additions and 15 deletions
|
|
@ -37,7 +37,6 @@ namespace TShockAPI.DB
|
|||
AddGroup("default", "canwater,canlava,warp,canbuild");
|
||||
AddGroup("vip", "default,canwater,canlava,warp,canbuild,reservedslot");
|
||||
|
||||
|
||||
String file = Path.Combine(TShock.SavePath, "groups.txt");
|
||||
if (File.Exists(file))
|
||||
{
|
||||
|
|
@ -124,6 +123,96 @@ namespace TShockAPI.DB
|
|||
return false;
|
||||
}
|
||||
|
||||
public String addGroup(String name, String permissions)
|
||||
{
|
||||
String message = "";
|
||||
if( GroupExists( name ) )
|
||||
return "Error: Group already exists. Use /modGroup to change permissions.";
|
||||
using (var com = database.CreateCommand())
|
||||
{
|
||||
if (TShock.Config.StorageType.ToLower() == "sqlite")
|
||||
com.CommandText = "INSERT OR IGNORE INTO GroupList (GroupName, Commands, OrderBy) VALUES (@groupname, @commands, @order);";
|
||||
else if (TShock.Config.StorageType.ToLower() == "mysql")
|
||||
com.CommandText = "INSERT IGNORE INTO GroupList SET GroupName=@groupname, Commands=@commands, OrderBy=@order;";
|
||||
com.AddParameter("@groupname", name);
|
||||
com.AddParameter("@commands", permissions);
|
||||
com.AddParameter("@order", "0");
|
||||
if (com.ExecuteNonQuery() == 1)
|
||||
message = "Group " + name + " has been created successfully.";
|
||||
Group g = new Group(name);
|
||||
g.permissions.Add(permissions);
|
||||
groups.Add(g);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public String delGroup(String name)
|
||||
{
|
||||
String message = "";
|
||||
if (!GroupExists(name))
|
||||
return "Error: Group doesn't exists.";
|
||||
using (var com = database.CreateCommand())
|
||||
{
|
||||
com.CommandText = "Delete FROM GroupList WHERE GroupName=@groupname;";
|
||||
com.AddParameter("@groupname", name);
|
||||
if (com.ExecuteNonQuery() == 1)
|
||||
message = "Group " + name + " has been deleted successfully.";
|
||||
groups.Remove(Tools.GetGroup(name));
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public String addPermission(String name, List<String> permissions)
|
||||
{
|
||||
String message = "";
|
||||
if (!GroupExists(name))
|
||||
return "Error: Group doesn't exists.";
|
||||
using (var com = database.CreateCommand())
|
||||
{
|
||||
Group g = Tools.GetGroup(name);
|
||||
List<String> perm = g.permissions;
|
||||
foreach (String p in permissions)
|
||||
{
|
||||
if (!perm.Contains(p))
|
||||
{
|
||||
if (perm.Count > 0 && perm[0].Equals(""))
|
||||
perm[0] = p;
|
||||
else
|
||||
g.permissions.Add(p);
|
||||
}
|
||||
}
|
||||
com.CommandText = "UPDATE GroupList SET Commands=@perm WHERE GroupName=@name;";
|
||||
com.AddParameter("@perm", String.Join(",", perm));
|
||||
com.AddParameter("@name", name);
|
||||
if (com.ExecuteNonQuery() == 1)
|
||||
message = "Group " + name + " has been modified successfully.";
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public String delPermission(String name, List<String> permissions)
|
||||
{
|
||||
String message = "";
|
||||
if (!GroupExists(name))
|
||||
return "Error: Group doesn't exists.";
|
||||
using (var com = database.CreateCommand())
|
||||
{
|
||||
Group g = Tools.GetGroup(name);
|
||||
List<String> perm = g.permissions;
|
||||
foreach (String p in permissions)
|
||||
{
|
||||
if (perm.Contains(p))
|
||||
g.permissions.Remove(p);
|
||||
}
|
||||
com.CommandText = "UPDATE GroupList SET Commands=@perm WHERE GroupName=@name;";
|
||||
com.AddParameter("@perm", String.Join(",", perm));
|
||||
com.AddParameter("@name", name);
|
||||
if (com.ExecuteNonQuery() == 1)
|
||||
message = "Group " + name + " has been modified successfully.";
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public void LoadPermisions()
|
||||
{
|
||||
groups = new List<Group>();
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ namespace TShockAPI.DB
|
|||
String line;
|
||||
while ((line = sr.ReadLine()) != null)
|
||||
{
|
||||
if (!line.Equals("") && !line.Substring( 0, 1 ).Equals("#") )
|
||||
if (!line.Equals("") && !line.Substring(0, 1).Equals("#"))
|
||||
{
|
||||
if (TShock.Config.StorageType.ToLower() == "sqlite")
|
||||
com.CommandText = "INSERT OR IGNORE INTO 'ItemBans' (ItemName) VALUES (@name);";
|
||||
|
|
@ -44,8 +44,8 @@ namespace TShockAPI.DB
|
|||
com.CommandText = "INSERT IGNORE INTO ItemBans SET ItemName=@name;";
|
||||
|
||||
int id = 0;
|
||||
int.TryParse(line, out id );
|
||||
com.AddParameter("@name", Tools.GetItemById( id ).name );
|
||||
int.TryParse(line, out id);
|
||||
com.AddParameter("@name", Tools.GetItemById(id).name);
|
||||
com.ExecuteNonQuery();
|
||||
com.Parameters.Clear();
|
||||
}
|
||||
|
|
@ -60,19 +60,25 @@ namespace TShockAPI.DB
|
|||
File.Delete(file2);
|
||||
File.Move(file, file2);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateItemBans();
|
||||
}
|
||||
|
||||
public void UpdateItemBans()
|
||||
{
|
||||
ItemBans.Clear();
|
||||
using (var com = database.CreateCommand())
|
||||
{
|
||||
com.CommandText = "SELECT * FROM ItemBans";
|
||||
|
||||
using (var reader = com.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
while (reader!=null&&reader.Read())
|
||||
ItemBans.Add(reader.Get<string>("ItemName"));
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddNewBan(string itemname = "")
|
||||
{
|
||||
try
|
||||
|
|
@ -82,6 +88,8 @@ namespace TShockAPI.DB
|
|||
com.CommandText = "INSERT INTO ItemBans (ItemName) VALUES (@itemname);";
|
||||
com.AddParameter("@itemname", Tools.GetItemByName(itemname)[0].name);
|
||||
com.ExecuteNonQuery();
|
||||
if( !ItemIsBanned( itemname ) )
|
||||
ItemBans.Add(itemname);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -92,13 +100,16 @@ namespace TShockAPI.DB
|
|||
|
||||
public void RemoveBan(string itemname)
|
||||
{
|
||||
if (!ItemIsBanned(itemname))
|
||||
return;
|
||||
try
|
||||
{
|
||||
using (var com = database.CreateCommand())
|
||||
{
|
||||
com.CommandText = "DELETE FROM ItemBans WHERE ItemName=@itemname;";
|
||||
com.CommandText = "Delete FROM 'ItemBans' WHERE ItemName=@itemname;";
|
||||
com.AddParameter("@itemname", Tools.GetItemByName(itemname)[0].name);
|
||||
com.ExecuteNonQuery();
|
||||
ItemBans.Remove(itemname);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
|
|
@ -201,7 +201,6 @@ namespace TShockAPI.DB
|
|||
File.Delete(file2);
|
||||
//File.Move(file, file2);
|
||||
}
|
||||
|
||||
if (updates > 0)
|
||||
ReloadAllRegions();
|
||||
}
|
||||
|
|
@ -249,7 +248,7 @@ namespace TShockAPI.DB
|
|||
int Protected = reader.Get<int>("Protected");
|
||||
string MergedIDs = DbExt.Get<string>(reader, "UserIds");
|
||||
string name = DbExt.Get<string>(reader, "RegionName");
|
||||
|
||||
System.Console.WriteLine(MergedIDs);
|
||||
string[] SplitIDs = MergedIDs.Split(',');
|
||||
|
||||
Region r = new Region(new Rectangle(X1, Y1, width, height), name, Protected, Main.worldID.ToString());
|
||||
|
|
@ -262,6 +261,7 @@ namespace TShockAPI.DB
|
|||
{
|
||||
break;
|
||||
}
|
||||
//System.Console.WriteLine(SplitIDs[i]);
|
||||
r.RegionAllowedIDs[i] = Convert.ToInt32(SplitIDs[i]);
|
||||
}
|
||||
}
|
||||
|
|
@ -303,7 +303,7 @@ namespace TShockAPI.DB
|
|||
com.AddParameter("@protected", 1);
|
||||
if (com.ExecuteNonQuery() > 0)
|
||||
{
|
||||
ReloadAllRegions();
|
||||
Regions.Add(new Region(new Rectangle(tx, ty, width, height), regionname, 0, worldid));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue