Tweaked around with the region code a lot.

Databases will need to be rebuilt past this build.
This commit is contained in:
Lucas Nicodemus 2011-07-14 01:47:57 -06:00
parent c4efc96303
commit 5b79212b8f
6 changed files with 55 additions and 82 deletions

View file

@ -1443,7 +1443,7 @@ namespace TShockAPI
int.TryParse(args.Parameters[1], out page); int.TryParse(args.Parameters[1], out page);
var sb = new StringBuilder(); var sb = new StringBuilder();
List<RegionStore> Regions = TShock.Regions.ListAllRegions(); List<Region> Regions = TShock.Regions.ListAllRegions();
if (Regions.Count > (15 * (page - 1))) if (Regions.Count > (15 * (page - 1)))
{ {

View file

@ -35,6 +35,8 @@ namespace TShockAPI.DB
{ {
public static List<Region> Regions = new List<Region>(); public static List<Region> Regions = new List<Region>();
public Region[] RegionArray;
private IDbConnection database; private IDbConnection database;
public RegionManager(IDbConnection db) public RegionManager(IDbConnection db)
@ -45,15 +47,54 @@ namespace TShockAPI.DB
{ {
if (TShock.Config.StorageType.ToLower() == "sqlite") if (TShock.Config.StorageType.ToLower() == "sqlite")
com.CommandText = com.CommandText =
"CREATE TABLE IF NOT EXISTS 'Regions' ('X1' NUMERIC, 'Y1' NUMERIC, 'X2' NUMERIC, 'Y2' NUMERIC, 'RegionName' TEXT PRIMARY KEY, 'WorldID' TEXT, 'UserIds' TEXT, 'Protected' NUMERIC);"; "CREATE TABLE IF NOT EXISTS 'Regions' ('X1' NUMERIC, 'Y1' NUMERIC, 'height' NUMERIC, 'width' NUMERIC, 'RegionName' TEXT PRIMARY KEY, 'WorldID' TEXT, 'UserIds' TEXT, 'Protected' NUMERIC);";
else if (TShock.Config.StorageType.ToLower() == "mysql") else if (TShock.Config.StorageType.ToLower() == "mysql")
com.CommandText = com.CommandText =
"CREATE TABLE IF NOT EXISTS Regions (X1 INT(11), Y1 INT(11), X2 INT(11), Y2 INT(11), RegionName VARCHAR(255) PRIMARY, WorldID VARCHAR(255), UserIds VARCHAR(255), Protected INT(1));"; "CREATE TABLE IF NOT EXISTS Regions (X1 INT(11), Y1 INT(11), height INT(11), width INT(11), RegionName VARCHAR(255) PRIMARY, WorldID VARCHAR(255), UserIds VARCHAR(255), Protected INT(1));";
com.ExecuteNonQuery(); com.ExecuteNonQuery();
} }
} }
public void ReloadAllRegions()
{
try
{
using (var com = database.CreateCommand())
{
com.CommandText = "SELECT * FROM Regions WHERE WorldID=@worldid";
com.AddParameter("@worldid", Main.worldID.ToString());
using (var reader = com.ExecuteReader())
{
int regionCount = reader.RecordsAffected;
RegionArray = new Region[regionCount];
int iterationCounter = 0;
while (reader.Read())
{
int X1 = reader.Get<int>("X1");
int Y1 = reader.Get<int>("Y1");
int height = reader.Get<int>("height");
int width = reader.Get<int>("width");
int Protected = reader.Get<int>("Protected");
string MergedIDs = DbExt.Get<string>(reader, "UserIds");
string name = DbExt.Get<string>(reader, "RegionName");
string[] SplitIDs = MergedIDs.Split(',');
Region r = new Region(new Rectangle(X1, Y1, width, height), name, Protected, Main.worldID.ToString());
RegionArray[iterationCounter] = r;
iterationCounter++;
}
reader.Close();
}
}
}
catch (Exception ex)
{
Log.Error(ex.ToString());
}
}
public bool AddRegion(int tx, int ty, int width, int height, string regionname, string worldid) public bool AddRegion(int tx, int ty, int width, int height, string regionname, string worldid)
{ {
try try
@ -141,17 +182,17 @@ namespace TShockAPI.DB
{ {
int X1 = reader.Get<int>("X1"); int X1 = reader.Get<int>("X1");
int Y1 = reader.Get<int>("Y1"); int Y1 = reader.Get<int>("Y1");
int X2 = reader.Get<int>("X2"); int height = reader.Get<int>("height");
int Y2 = reader.Get<int>("Y2"); int width = reader.Get<int>("width");
int Protected = reader.Get<int>("Protected"); int Protected = reader.Get<int>("Protected");
string MergedIDs = DbExt.Get<string>(reader, "UserIds"); string MergedIDs = DbExt.Get<string>(reader, "UserIds");
string[] SplitIDs = MergedIDs.Split(','); string[] SplitIDs = MergedIDs.Split(',');
if (X >= X1 && if (X >= X1 &&
X <= X2 && X <= height &&
Y >= Y1 && Y >= Y1 &&
Y <= Y2 && Y <= width &&
Protected == 1) Protected == 1)
{ {
if (!SplitIDs.Contains(user.ID.ToString())) if (!SplitIDs.Contains(user.ID.ToString()))
@ -237,7 +278,7 @@ namespace TShockAPI.DB
using (var reader = com.ExecuteReader()) using (var reader = com.ExecuteReader())
{ {
while (reader.Read()) while (reader.Read())
Regions.Add(new Region(new Rectangle(reader.Get<int>("X1"), reader.Get<int>("Y1"), reader.Get<int>("X2"), reader.Get<int>("Y2")), reader.Get<string>("RegionName"), reader.Get<int>("Protected"), reader.Get<string>("WorldID"))); Regions.Add(new Region(new Rectangle(reader.Get<int>("X1"), reader.Get<int>("Y1"), reader.Get<int>("height"), reader.Get<int>("width")), reader.Get<string>("RegionName"), reader.Get<int>("Protected"), reader.Get<string>("WorldID")));
reader.Close(); reader.Close();
} }
} }
@ -256,14 +297,14 @@ namespace TShockAPI.DB
public string RegionName { get; set; } public string RegionName { get; set; }
public int DisableBuild { get; set; } public int DisableBuild { get; set; }
public string RegionWorldID { get; set; } public string RegionWorldID { get; set; }
public string RegionAllowedIDs { get; set; } public string[] RegionAllowedIDs { get; set; }
public Region(Rectangle region, string name, int disablebuild, string worldname) public Region(Rectangle region, string name, int disablebuild, string RegionWorldIDz)
{ {
RegionArea = region; RegionArea = region;
RegionName = name; RegionName = name;
DisableBuild = disablebuild; DisableBuild = disablebuild;
RegionWorldID = worldname; RegionWorldID = RegionWorldIDz;
} }
public Region() public Region()

View file

@ -35,5 +35,5 @@ using System.Runtime.InteropServices;
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.3.4.0713")] [assembly: AssemblyVersion("2.3.4.0714")]
[assembly: AssemblyFileVersion("2.3.4.0713")] [assembly: AssemblyFileVersion("2.3.4.0714")]

View file

@ -1,67 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TShockAPI.DB;
namespace TShockAPI
{
class RegionStore
{
public int X1;
public int X2;
public int Y1;
public int Y2;
public int IsProtected;
public string[] UserIDs;
public RegionStore(string tX1, string tX2, string tY1, string tY2, int tIsProtected, string[] tUserIDs)
{
X1 = Convert.ToInt32(tX1);
X2 = Convert.ToInt32(tX2);
Y1 = Convert.ToInt32(tY1);
Y2 = Convert.ToInt32(tY2);
IsProtected = tIsProtected;
UserIDs = tUserIDs;
}
public RegionStore(int tX1, int tX2, int tY1, int tY2, int tIsProtected, string[] tUserIDs)
{
X1 = Convert.ToInt32(tX1);
X2 = Convert.ToInt32(tX2);
Y1 = Convert.ToInt32(tY1);
Y2 = Convert.ToInt32(tY2);
IsProtected = tIsProtected;
UserIDs = tUserIDs;
}
public RegionStore(string tX1, string tX2, string tY1, string tY2)
{
X1 = Convert.ToInt32(tX1);
X2 = Convert.ToInt32(tX2);
Y1 = Convert.ToInt32(tY1);
Y2 = Convert.ToInt32(tY2);
}
public RegionStore(int tX1, int tX2, int tY1, int tY2)
{
X1 = Convert.ToInt32(tX1);
X2 = Convert.ToInt32(tX2);
Y1 = Convert.ToInt32(tY1);
Y2 = Convert.ToInt32(tY2);
}
public bool InProtectedArea(int x, int y, User user)
{
if (x >= X1 &&
x <= X2 &&
y >= Y1 &&
y <= Y2 &&
IsProtected == 1)
{
if (!UserIDs.Contains(user.ID.ToString()))
return true;
}
return false;
}
}
}

View file

@ -100,7 +100,6 @@
<Compile Include="Net\WorldInfoMsg.cs" /> <Compile Include="Net\WorldInfoMsg.cs" />
<Compile Include="DB\RegionManager.cs" /> <Compile Include="DB\RegionManager.cs" />
<Compile Include="RconHandler.cs" /> <Compile Include="RconHandler.cs" />
<Compile Include="RegionStore.cs" />
<Compile Include="RememberPosManager.cs" /> <Compile Include="RememberPosManager.cs" />
<Compile Include="Resources.Designer.cs"> <Compile Include="Resources.Designer.cs">
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>

View file

@ -501,7 +501,7 @@ namespace TShockAPI
using (var sha = new SHA512CryptoServiceProvider()) using (var sha = new SHA512CryptoServiceProvider())
{ {
var bytes = sha.ComputeHash(Encoding.ASCII.GetBytes(password)); var bytes = sha.ComputeHash(Encoding.ASCII.GetBytes(password));
return bytes.Aggregate("", (s, b) => s + b.ToString("X2")); return bytes.Aggregate("", (s, b) => s + b.ToString("height"));
} }
} }