Merge branch 'general-devel' of github.com:TShock/TShock into general-devel
This commit is contained in:
commit
c505889f79
5 changed files with 119 additions and 26 deletions
|
|
@ -137,6 +137,7 @@ namespace TShockAPI
|
|||
ChatCommands.Add(new Command("warp", UseWarp, "warp"));
|
||||
ChatCommands.Add(new Command("managewarp", SetWarp, "setwarp"));
|
||||
ChatCommands.Add(new Command("managewarp", DeleteWarp, "delwarp"));
|
||||
ChatCommands.Add(new Command("managewarp", HideWarp, "hidewarp"));
|
||||
ChatCommands.Add(new Command("managegroup", AddGroup, "addGroup"));
|
||||
ChatCommands.Add(new Command("managegroup", DeleteGroup, "delGroup"));
|
||||
ChatCommands.Add(new Command("managegroup", ModifyGroup, "modGroup"));
|
||||
|
|
@ -1217,6 +1218,31 @@ namespace TShockAPI
|
|||
args.Player.SendMessage("Invalid syntax! Proper syntax: /delwarp [name]", Color.Red);
|
||||
}
|
||||
|
||||
private static void HideWarp(CommandArgs args)
|
||||
{
|
||||
if (args.Parameters.Count > 1)
|
||||
{
|
||||
string warpName = String.Join(" ", args.Parameters);
|
||||
bool state = false;
|
||||
if (Boolean.TryParse(args.Parameters[1], out state))
|
||||
{
|
||||
if (TShock.Warps.HideWarp(args.Parameters[0], state))
|
||||
{
|
||||
if (state)
|
||||
args.Player.SendMessage("Made warp " + warpName + " private", Color.Yellow);
|
||||
else
|
||||
args.Player.SendMessage("Made warp " + warpName + " public", Color.Yellow);
|
||||
}
|
||||
else
|
||||
args.Player.SendMessage("Could not find specified warp", Color.Red);
|
||||
}
|
||||
else
|
||||
args.Player.SendMessage("Invalid syntax! Proper syntax: /hidewarp [name] <true/false>", Color.Red);
|
||||
}
|
||||
else
|
||||
args.Player.SendMessage("Invalid syntax! Proper syntax: /hidewarp [name] <true/false>", Color.Red);
|
||||
}
|
||||
|
||||
private static void UseWarp(CommandArgs args)
|
||||
{
|
||||
if (args.Parameters.Count < 1)
|
||||
|
|
@ -1245,7 +1271,7 @@ namespace TShockAPI
|
|||
page--; //Substract 1 as pages are parsed starting at 1 and not 0
|
||||
}
|
||||
|
||||
var warps = TShock.Warps.ListAllWarps(Main.worldID.ToString());
|
||||
var warps = TShock.Warps.ListAllPublicWarps(Main.worldID.ToString());
|
||||
|
||||
//Check if they are trying to access a page that doesn't exist.
|
||||
int pagecount = warps.Count / pagelimit;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
TShock, a server mod for Terraria
|
||||
Copyright (C) 2011 The TShock Team
|
||||
|
||||
|
|
@ -172,11 +172,18 @@ namespace TShockAPI.DB
|
|||
string[] SplitIDs = MergedIDs.Split(',');
|
||||
|
||||
Region r = new Region(new Rectangle(X1, Y1, width, height), name, Protected != 0, Main.worldID.ToString());
|
||||
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < SplitIDs.Length; i++)
|
||||
{
|
||||
r.AllowedIDs.Add(Convert.ToInt32(SplitIDs[i]));
|
||||
int id;
|
||||
|
||||
if (Int32.TryParse(SplitIDs[i], out id)) // if unparsable, it's not an int, so silently skip
|
||||
r.AllowedIDs.Add(id);
|
||||
else if (SplitIDs[i] == "") // Split gotcha, can return an empty string with certain conditions
|
||||
// but we only want to let the user know if it's really a nonparsable integer.
|
||||
Log.Warn("One of your UserIDs is not a usable integer: " + SplitIDs[i]);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
@ -219,7 +226,13 @@ namespace TShockAPI.DB
|
|||
{
|
||||
for (int i = 0; i < SplitIDs.Length; i++)
|
||||
{
|
||||
r.AllowedIDs[i] = Convert.ToInt32(SplitIDs[i]);
|
||||
int id;
|
||||
|
||||
if (Int32.TryParse(SplitIDs[i], out id)) // if unparsable, it's not an int, so silently skip
|
||||
r.AllowedIDs.Add(id);
|
||||
else if (SplitIDs[i] == "") // Split gotcha, can return an empty string with certain conditions
|
||||
// but we only want to let the user know if it's really a nonparsable integer.
|
||||
Log.Warn("UnitTest: One of your UserIDs is not a usable integer: " + SplitIDs[i]);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
|||
|
|
@ -38,6 +38,11 @@ namespace TShockAPI.DB
|
|||
"CREATE TABLE IF NOT EXISTS 'Warps' ('X' NUMERIC, 'Y' NUMERIC, 'WarpName' TEXT PRIMARY KEY, 'WorldID' TEXT);" :
|
||||
"CREATE TABLE IF NOT EXISTS Warps (X INT(11), Y INT(11), WarpName VARCHAR(255) PRIMARY, WorldID VARCHAR(255));";
|
||||
|
||||
if (TShock.Config.StorageType.ToLower() == "sqlite")
|
||||
db.Query("ALTER TABLE 'Warps' ADD COLUMN 'Private' TEXT");
|
||||
else
|
||||
db.Query("ALTER TABLE Warps ADD COLUMN Private VARCHAR(255)");
|
||||
|
||||
database.Query(query);
|
||||
|
||||
String file = Path.Combine(TShock.SavePath, "warps.xml");
|
||||
|
|
@ -167,7 +172,14 @@ namespace TShockAPI.DB
|
|||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
return new Warp(new Vector2(reader.Get<int>("X"), reader.Get<int>("Y")), reader.Get<string>("WarpName"), reader.Get<string>("WorldID"));
|
||||
try
|
||||
{
|
||||
return new Warp(new Vector2(reader.Get<int>("X"), reader.Get<int>("Y")), reader.Get<string>("WarpName"), reader.Get<string>("WorldID"), reader.Get<string>("Private"));
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new Warp(new Vector2(reader.Get<int>("X"), reader.Get<int>("Y")), reader.Get<string>("WarpName"), reader.Get<string>("WorldID"), "0");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -183,15 +195,25 @@ namespace TShockAPI.DB
|
|||
/// </summary>
|
||||
/// <param name="worldid">World name to get warps from</param>
|
||||
/// <returns>List of warps with only their names</returns>
|
||||
public List<Warp> ListAllWarps(string worldid)
|
||||
public List<Warp> ListAllPublicWarps(string worldid)
|
||||
{
|
||||
var warps = new List<Warp>();
|
||||
try
|
||||
{
|
||||
using (var reader = database.QueryReader("SELECT WarpName FROM Warps WHERE WorldID=@0", worldid))
|
||||
using (var reader = database.QueryReader("SELECT * FROM Warps WHERE WorldID=@0", worldid))
|
||||
{
|
||||
while (reader.Read())
|
||||
warps.Add(new Warp { WarpName = reader.Get<string>("WarpName") });
|
||||
{
|
||||
try
|
||||
{
|
||||
if (reader.Get<String>("Private") == "0" || reader.Get<String>("Private") == null)
|
||||
warps.Add(new Warp { WarpName = reader.Get<string>("WarpName") });
|
||||
}
|
||||
catch
|
||||
{
|
||||
warps.Add(new Warp { WarpName = reader.Get<string>("WarpName") });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -200,6 +222,28 @@ namespace TShockAPI.DB
|
|||
}
|
||||
return warps;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the warps names from world
|
||||
/// </summary>
|
||||
/// <param name="worldid">World name to get warps from</param>
|
||||
/// <returns>List of warps with only their names</returns>
|
||||
public bool HideWarp(string warp, bool state)
|
||||
{
|
||||
try
|
||||
{
|
||||
string query = "UPDATE Warps SET Private=@0 WHERE WarpName=@1 AND WorldID=@2";
|
||||
|
||||
database.Query(query, state ? "1" : "0", warp, Main.worldID.ToString());
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.ToString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Warp
|
||||
|
|
@ -207,12 +251,14 @@ namespace TShockAPI.DB
|
|||
public Vector2 WarpPos { get; set; }
|
||||
public string WarpName { get; set; }
|
||||
public string WorldWarpID { get; set; }
|
||||
public string Private { get; set; }
|
||||
|
||||
public Warp(Vector2 warppos, string name, string worldname)
|
||||
public Warp(Vector2 warppos, string name, string worldid, string hidden)
|
||||
{
|
||||
WarpPos = warppos;
|
||||
WarpName = name;
|
||||
WorldWarpID = worldname;
|
||||
WorldWarpID = worldid;
|
||||
Private = hidden;
|
||||
}
|
||||
|
||||
public Warp()
|
||||
|
|
@ -220,6 +266,7 @@ namespace TShockAPI.DB
|
|||
WarpPos = Vector2.Zero;
|
||||
WarpName = null;
|
||||
WorldWarpID = string.Empty;
|
||||
Private = "0";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ namespace TShockAPI
|
|||
public bool IsLoggedIn;
|
||||
public int UserID = -1;
|
||||
public bool HasBeenNaggedAboutLoggingIn;
|
||||
public bool TpLock = false;
|
||||
Player FakePlayer;
|
||||
|
||||
public bool RealPlayer
|
||||
|
|
@ -184,24 +185,29 @@ namespace TShockAPI
|
|||
|
||||
public bool Teleport(int tilex, int tiley)
|
||||
{
|
||||
InitSpawn = false;
|
||||
|
||||
SendTeleport(tilex, tiley);
|
||||
|
||||
//150 Should avoid all client crash errors
|
||||
//The error occurs when a tile trys to update which the client hasnt load yet, Clients only update tiles withen 150 blocks
|
||||
//Try 300 if it does not work (Higher number - Longer load times - Less chance of error)
|
||||
if (!SendTileSquare(tilex, tiley))
|
||||
if (!TpLock)
|
||||
{
|
||||
SendMessage("Warning, teleport failed due to being too close to the edge of the map.", Color.Red);
|
||||
return false;
|
||||
InitSpawn = false;
|
||||
|
||||
SendTeleport(tilex, tiley);
|
||||
|
||||
//150 Should avoid all client crash errors
|
||||
//The error occurs when a tile trys to update which the client hasnt load yet, Clients only update tiles withen 150 blocks
|
||||
//Try 300 if it does not work (Higher number - Longer load times - Less chance of error)
|
||||
if (!SendTileSquare(tilex, tiley))
|
||||
{
|
||||
SendMessage("Warning, teleport failed due to being too close to the edge of the map.", Color.Red);
|
||||
return false;
|
||||
}
|
||||
|
||||
Spawn();
|
||||
|
||||
SendTeleport(Main.spawnTileX, Main.spawnTileY);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Spawn();
|
||||
|
||||
SendTeleport(Main.spawnTileX, Main.spawnTileY);
|
||||
|
||||
return true;
|
||||
SendMessage("Cannot teleport due to TP Lock", Color.Red);
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Spawn()
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ using System.Security.Cryptography;
|
|||
using System.Text;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Terraria;
|
||||
using TerrariaAPI;
|
||||
|
||||
namespace TShockAPI
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue