this was trying to enter Player Names in multiple rows when the IP was different - but player name is the primary key!
(also fixed position on reconnect) Remembering Position should now work correctly.
This commit is contained in:
parent
76d486778a
commit
ad56dd0741
1 changed files with 26 additions and 6 deletions
|
|
@ -44,6 +44,28 @@ namespace TShockAPI.DB
|
||||||
creator.EnsureExists(table);
|
creator.EnsureExists(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector2 CheckLeavePos(string name)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var reader = database.QueryReader("SELECT * FROM RememberedPos WHERE Name=@0", name))
|
||||||
|
{
|
||||||
|
if (reader.Read())
|
||||||
|
{
|
||||||
|
return new Vector2(reader.Get<int>("X"), reader.Get<int>("Y"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Vector2();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Vector2 GetLeavePos(string name, string IP)
|
public Vector2 GetLeavePos(string name, string IP)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -66,12 +88,11 @@ namespace TShockAPI.DB
|
||||||
|
|
||||||
public void InsertLeavePos(string name, string IP, int X, int Y)
|
public void InsertLeavePos(string name, string IP, int X, int Y)
|
||||||
{
|
{
|
||||||
if (GetLeavePos(name, IP) == Vector2.Zero)
|
if (CheckLeavePos(name) == Vector2.Zero)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
database.Query("INSERT INTO RememberedPos (Name, IP, X, Y, WorldID) VALUES (@0, @1, @2, @3, @4);", name, IP, X,
|
database.Query("INSERT INTO RememberedPos (Name, IP, X, Y, WorldID) VALUES (@0, @1, @2, @3, @4);", name, IP, X, Y , Main.worldID.ToString());
|
||||||
Y + 3, Main.worldID.ToString());
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -82,8 +103,7 @@ namespace TShockAPI.DB
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
database.Query("UPDATE RememberedPos SET X = @0, Y = @1 WHERE Name = @2 AND IP = @3 AND WorldID = @4;", X, Y + 3,
|
database.Query("UPDATE RememberedPos SET X = @0, Y = @1, IP = @2 WHERE Name = @3 AND WorldID = @4;", X, Y, IP, name, Main.worldID.ToString());
|
||||||
name, IP, Main.worldID.ToString());
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -92,4 +112,4 @@ namespace TShockAPI.DB
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue