Merging old release back into the release branch.
Merge branch 'general-devel' Conflicts: TShockAPI/Properties/AssemblyInfo.cs
This commit is contained in:
commit
36092d4aa8
38 changed files with 7493 additions and 338 deletions
|
|
@ -36,6 +36,7 @@ namespace TShockDBEditor
|
|||
CommandList.Add("kill");
|
||||
CommandList.Add("butcher");
|
||||
CommandList.Add("item");
|
||||
CommandList.Add("clearitems");
|
||||
CommandList.Add("heal");
|
||||
CommandList.Add("whisper");
|
||||
CommandList.Add("annoy");
|
||||
|
|
|
|||
BIN
HttpBins/HttpServer.dll
Normal file
BIN
HttpBins/HttpServer.dll
Normal file
Binary file not shown.
BIN
HttpBins/HttpServer.pdb
Normal file
BIN
HttpBins/HttpServer.pdb
Normal file
Binary file not shown.
6183
HttpBins/HttpServer.xml
Normal file
6183
HttpBins/HttpServer.xml
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
TShock, a server mod for Terraria
|
||||
Copyright (C) 2011 The TShock Team
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
|
@ -36,7 +36,7 @@ namespace TShockAPI
|
|||
public string Message { get; private set; }
|
||||
public TSPlayer Player { get; private set; }
|
||||
/// <summary>
|
||||
/// Parameters passed to the arguement. Does not include the command name.
|
||||
/// Parameters passed to the arguement. Does not include the command name.
|
||||
/// IE '/kick "jerk face"' will only have 1 argument
|
||||
/// </summary>
|
||||
public List<string> Parameters { get; private set; }
|
||||
|
|
@ -137,6 +137,7 @@ namespace TShockAPI
|
|||
add(Permissions.tp, Spawn, "spawn");
|
||||
add(Permissions.tp, TP, "tp");
|
||||
add(Permissions.tphere, TPHere, "tphere");
|
||||
add(Permissions.tphere, SendWarp, "sendwarp", "sw");
|
||||
add(Permissions.warp, UseWarp, "warp");
|
||||
add(Permissions.managewarp, SetWarp, "setwarp");
|
||||
add(Permissions.managewarp, DeleteWarp, "delwarp");
|
||||
|
|
@ -151,6 +152,7 @@ namespace TShockAPI
|
|||
add(Permissions.cfg, ShowConfiguration, "showconfig");
|
||||
add(Permissions.cfg, ServerPassword, "serverpassword");
|
||||
add(Permissions.cfg, Save, "save");
|
||||
add(Permissions.cfg, Settle, "settle");
|
||||
add(Permissions.cfg, MaxSpawns, "maxspawns");
|
||||
add(Permissions.cfg, SpawnRate, "spawnrate");
|
||||
add(Permissions.time, Time, "time");
|
||||
|
|
@ -164,6 +166,7 @@ namespace TShockAPI
|
|||
add(null, AuthToken, "auth");
|
||||
add(null, ThirdPerson, "me");
|
||||
add(null, PartyChat, "p");
|
||||
add(null, Motd, "motd");
|
||||
add(null, Rules, "rules");
|
||||
add(Permissions.logs, DisplayLogs, "displaylogs");
|
||||
ChatCommands.Add(new Command(PasswordUser, "password") { DoLog = false });
|
||||
|
|
@ -181,6 +184,7 @@ namespace TShockAPI
|
|||
add(Permissions.butcher, Butcher, "butcher");
|
||||
add(Permissions.item, Item, "item", "i");
|
||||
add(Permissions.item, Give, "give");
|
||||
add(Permissions.clearitems, ClearItems, "clearitems");
|
||||
add(Permissions.heal, Heal, "heal");
|
||||
add(Permissions.buff, Buff, "buff");
|
||||
add(Permissions.buffplayer, GBuff, "gbuff", "buffplayer");
|
||||
|
|
@ -350,7 +354,6 @@ namespace TShockAPI
|
|||
|
||||
private static void PasswordUser(CommandArgs args)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
if (args.Player.IsLoggedIn && args.Parameters.Count == 2)
|
||||
|
|
@ -430,6 +433,13 @@ namespace TShockAPI
|
|||
// return;
|
||||
//}
|
||||
|
||||
// This guy needs to be here so that people don't get exceptions when they type /user
|
||||
if (args.Parameters.Count < 1)
|
||||
{
|
||||
args.Player.SendMessage("Invalid user syntax. Try /user help.", Color.Red);
|
||||
return;
|
||||
}
|
||||
|
||||
string subcmd = args.Parameters[0];
|
||||
|
||||
// Add requires a username:password pair/ip address and a group specified.
|
||||
|
|
@ -899,7 +909,6 @@ namespace TShockAPI
|
|||
Tools.ForceKickAll("Server shutting down for update!");
|
||||
WorldGen.saveWorld();
|
||||
Netplay.disconnect = true;
|
||||
|
||||
}
|
||||
|
||||
#endregion Server Maintenence Commands
|
||||
|
|
@ -918,7 +927,7 @@ namespace TShockAPI
|
|||
int penis57 = Main.rand.Next(Main.maxTilesX - 50) + 100;
|
||||
penis57 *= 0x10;
|
||||
int penis58 = Main.rand.Next((int)(Main.maxTilesY * 0.05)) * 0x10;
|
||||
PointF vector = new PointF(penis57, penis58);
|
||||
Vector2 vector = new Vector2(penis57, penis58);
|
||||
float speedX = Main.rand.Next(-100, 0x65);
|
||||
float speedY = Main.rand.Next(200) + 100;
|
||||
float penis61 = (float)Math.Sqrt(((speedX * speedX) + (speedY * speedY)));
|
||||
|
|
@ -1202,6 +1211,42 @@ namespace TShockAPI
|
|||
}
|
||||
}
|
||||
|
||||
private static void SendWarp(CommandArgs args)
|
||||
{
|
||||
if (args.Parameters.Count < 2)
|
||||
{
|
||||
args.Player.SendMessage("Invalid syntax! Proper syntax: /sendwarp [player] [warpname]", Color.Red);
|
||||
return;
|
||||
}
|
||||
|
||||
var foundplr = Tools.FindPlayer(args.Parameters[0]);
|
||||
if (foundplr.Count == 0)
|
||||
{
|
||||
args.Player.SendMessage("Invalid player!", Color.Red);
|
||||
return;
|
||||
}
|
||||
else if (foundplr.Count > 1)
|
||||
{
|
||||
args.Player.SendMessage(string.Format("More than one ({0}) player matched!", args.Parameters.Count), Color.Red);
|
||||
return;
|
||||
}
|
||||
string warpName = String.Join(" ", args.Parameters[1]);
|
||||
var warp = TShock.Warps.FindWarp(warpName);
|
||||
var plr = foundplr[0];
|
||||
if (warp.WarpPos != Vector2.Zero)
|
||||
{
|
||||
if (plr.Teleport((int)warp.WarpPos.X, (int)warp.WarpPos.Y + 3))
|
||||
{
|
||||
plr.SendMessage(string.Format("{0} Warped you to {1}", args.Player.Name, warpName), Color.Yellow);
|
||||
args.Player.SendMessage(string.Format("You warped {0} to {1}.", plr.Name, warpName), Color.Yellow);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
args.Player.SendMessage("Specified warp not found", Color.Red);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetWarp(CommandArgs args)
|
||||
{
|
||||
if (args.Parameters.Count > 0)
|
||||
|
|
@ -1327,7 +1372,7 @@ namespace TShockAPI
|
|||
{
|
||||
string warpName = String.Join(" ", args.Parameters);
|
||||
var warp = TShock.Warps.FindWarp(warpName);
|
||||
if (warp.WarpPos != PointF.Empty)
|
||||
if (warp.WarpPos != Vector2.Zero)
|
||||
{
|
||||
if (args.Player.Teleport((int)warp.WarpPos.X, (int)warp.WarpPos.Y + 3))
|
||||
args.Player.SendMessage("Warped to " + warpName, Color.Yellow);
|
||||
|
|
@ -1337,7 +1382,6 @@ namespace TShockAPI
|
|||
args.Player.SendMessage("Specified warp not found", Color.Red);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion Teleport Commands
|
||||
|
|
@ -1538,9 +1582,21 @@ namespace TShockAPI
|
|||
SaveWorld.Start();
|
||||
}
|
||||
|
||||
private static void MaxSpawns(CommandArgs args)
|
||||
private static void Settle(CommandArgs args)
|
||||
{
|
||||
|
||||
if (Liquid.panicMode)
|
||||
{
|
||||
args.Player.SendMessage("Liquid is already settling!", Color.Red);
|
||||
return;
|
||||
}
|
||||
Liquid.StartPanic();
|
||||
Tools.Broadcast("Settling all liquids...");
|
||||
|
||||
}
|
||||
|
||||
private static void MaxSpawns(CommandArgs args)
|
||||
{
|
||||
if (args.Parameters.Count != 1)
|
||||
{
|
||||
args.Player.SendMessage("Invalid syntax! Proper syntax: /maxspawns <maxspawns>", Color.Red);
|
||||
|
|
@ -1688,7 +1744,6 @@ namespace TShockAPI
|
|||
}
|
||||
switch (cmd)
|
||||
{
|
||||
|
||||
case "name":
|
||||
{
|
||||
{
|
||||
|
|
@ -1697,7 +1752,6 @@ namespace TShockAPI
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case "set":
|
||||
{
|
||||
int choice = 0;
|
||||
|
|
@ -1718,7 +1772,7 @@ namespace TShockAPI
|
|||
{
|
||||
if (args.Parameters.Count > 1)
|
||||
{
|
||||
if (!args.Player.TempPoints.Any(p => p == PointF.Empty))
|
||||
if (!args.Player.TempPoints.Any(p => p == Point.Zero))
|
||||
{
|
||||
string regionName = String.Join(" ", args.Parameters.GetRange(1, args.Parameters.Count - 1));
|
||||
var x = Math.Min(args.Player.TempPoints[0].X, args.Player.TempPoints[1].X);
|
||||
|
|
@ -1728,8 +1782,8 @@ namespace TShockAPI
|
|||
|
||||
if (TShock.Regions.AddRegion(x, y, width, height, regionName, Main.worldID.ToString()))
|
||||
{
|
||||
args.Player.TempPoints[0] = Point.Empty;
|
||||
args.Player.TempPoints[1] = Point.Empty;
|
||||
args.Player.TempPoints[0] = Point.Zero;
|
||||
args.Player.TempPoints[1] = Point.Zero;
|
||||
args.Player.SendMessage("Set region " + regionName, Color.Yellow);
|
||||
}
|
||||
else
|
||||
|
|
@ -1788,8 +1842,8 @@ namespace TShockAPI
|
|||
}
|
||||
case "clear":
|
||||
{
|
||||
args.Player.TempPoints[0] = Point.Empty;
|
||||
args.Player.TempPoints[1] = Point.Empty;
|
||||
args.Player.TempPoints[0] = Point.Zero;
|
||||
args.Player.TempPoints[1] = Point.Zero;
|
||||
args.Player.SendMessage("Cleared temp area", Color.Yellow);
|
||||
args.Player.AwaitingTempPoint = 0;
|
||||
break;
|
||||
|
|
@ -1950,6 +2004,62 @@ namespace TShockAPI
|
|||
args.Player.SendMessage("Invalid syntax! Proper syntax: /region info [name]", Color.Red);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case "resize":
|
||||
case "expand":
|
||||
{
|
||||
if (args.Parameters.Count == 4)
|
||||
{
|
||||
int direction;
|
||||
switch (args.Parameters[3])
|
||||
{
|
||||
case "u":
|
||||
case "up":
|
||||
{
|
||||
direction = 0;
|
||||
break;
|
||||
}
|
||||
case "r":
|
||||
case "right":
|
||||
{
|
||||
direction = 1;
|
||||
break;
|
||||
}
|
||||
case "d":
|
||||
case "down":
|
||||
{
|
||||
direction = 2;
|
||||
break;
|
||||
}
|
||||
case "l":
|
||||
case "left":
|
||||
{
|
||||
direction = 3;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
direction = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int addAmount;
|
||||
int.TryParse(args.Parameters[2], out addAmount);
|
||||
if (TShock.Regions.resizeRegion(args.Parameters[1], addAmount, direction))
|
||||
{
|
||||
args.Player.SendMessage("Region Resized Successfully!", Color.Yellow);
|
||||
TShock.Regions.ReloadAllRegions();
|
||||
}
|
||||
else
|
||||
{
|
||||
args.Player.SendMessage("Invalid syntax! Proper syntax: /region resize [regionname] [u/d/l/r] [amount]", Color.Red);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
args.Player.SendMessage("Invalid syntax! Proper syntax: /region resize [regionname] [u/d/l/r] [amount]1", Color.Red);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "help":
|
||||
|
|
@ -1960,10 +2070,10 @@ namespace TShockAPI
|
|||
args.Player.SendMessage("/region name (provides region name)", Color.Yellow);
|
||||
args.Player.SendMessage("/region delete [name] /region clear (temporary region)", Color.Yellow);
|
||||
args.Player.SendMessage("/region allow [name] [regionname]", Color.Yellow);
|
||||
args.Player.SendMessage("/region resize [regionname] [u/d/l/r] [amount]", Color.Yellow);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion World Protection Commands
|
||||
|
|
@ -2117,6 +2227,11 @@ namespace TShockAPI
|
|||
args.Player.SendMessage("You are not in a party!", 255, 240, 20);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Motd(CommandArgs args)
|
||||
{
|
||||
Tools.ShowFileToUser(args.Player, "motd.txt");
|
||||
}
|
||||
|
||||
private static void Rules(CommandArgs args)
|
||||
{
|
||||
|
|
@ -2185,6 +2300,7 @@ namespace TShockAPI
|
|||
(new Thread(ply.Whoopie)).Start(annoy);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion General Commands
|
||||
|
||||
#region Cheat Commands
|
||||
|
|
@ -2359,6 +2475,50 @@ namespace TShockAPI
|
|||
}
|
||||
}
|
||||
|
||||
public static void ClearItems(CommandArgs args)
|
||||
{
|
||||
|
||||
int radius = 50;
|
||||
if (args.Parameters.Count > 0)
|
||||
{
|
||||
|
||||
if (args.Parameters[0].ToLower() == "all")
|
||||
{
|
||||
|
||||
radius = Int32.MaxValue / 16;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
radius = Convert.ToInt32(args.Parameters[0]);
|
||||
|
||||
}
|
||||
catch (Exception) { args.Player.SendMessage("Please either enter the keyword \"all\", or the block radius you wish to delete all items from.", Color.Red); return; }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
int count = 0;
|
||||
for (int i = 0; i < 200; i++)
|
||||
{
|
||||
|
||||
if ((Math.Sqrt(Math.Pow(Main.item[i].position.X - args.Player.X, 2) + Math.Pow(Main.item[i].position.Y - args.Player.Y, 2)) < radius * 16) && (Main.item[i].active))
|
||||
{
|
||||
|
||||
Main.item[i].active = false;
|
||||
NetMessage.SendData(0x15, -1, -1, "", i, 0f, 0f, 0f, 0);
|
||||
count++;
|
||||
}
|
||||
|
||||
}
|
||||
args.Player.SendMessage("All " + count.ToString() + " items within a radius of " + radius.ToString() + " have been deleted.");
|
||||
|
||||
}
|
||||
|
||||
private static void Heal(CommandArgs args)
|
||||
{
|
||||
TSPlayer playerToHeal;
|
||||
|
|
@ -2563,8 +2723,10 @@ namespace TShockAPI
|
|||
args.Player.SendMessage("Unknown plant!", Color.Red);
|
||||
return;
|
||||
}
|
||||
args.Player.SendMessage("You have grown a " + name, Color.Green);
|
||||
args.Player.SendTileSquare(x, y);
|
||||
args.Player.SendMessage("Tried to grow a " + name, Color.Green);
|
||||
}
|
||||
|
||||
#endregion Cheat Comamnds
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -187,6 +187,18 @@ namespace TShockAPI
|
|||
[Description("This will announce a player's location on join")]
|
||||
public bool EnableGeoIP = false;
|
||||
|
||||
[Description("This will turn on a token requirement for the /status API endpoint.")]
|
||||
public bool EnableTokenEndpointAuthentication = false;
|
||||
|
||||
[Description("This is used when the API endpoint /status is queried.")]
|
||||
public string ServerNickname = "TShock Server";
|
||||
|
||||
[Description("Enable/Disable the rest api.")]
|
||||
public bool RestApiEnabled = false;
|
||||
|
||||
[Description("This is the port which the rest api will listen on.")]
|
||||
public int RestApiPort = 7878;
|
||||
|
||||
public static ConfigFile Read(string path)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
|
|
|
|||
|
|
@ -154,8 +154,10 @@ namespace TShockAPI.DB
|
|||
permissions.AddRange(group.permissions.Where(s => !permissions.Contains(s)));
|
||||
|
||||
if (database.Query("UPDATE GroupList SET Commands=@0 WHERE GroupName=@1", String.Join(",", permissions), name) != 0)
|
||||
{
|
||||
message = "Group " + name + " has been modified successfully.";
|
||||
|
||||
group.SetPermission( permissions );
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
|
|
@ -168,11 +170,13 @@ namespace TShockAPI.DB
|
|||
var group = Tools.GetGroup(name);
|
||||
|
||||
//Only get permissions that exist in the group.
|
||||
var newperms = permissions.Where(s => group.permissions.Contains(s));
|
||||
var newperms = group.permissions.Except( permissions );
|
||||
|
||||
if (database.Query("UPDATE GroupList SET Commands=@0 WHERE GroupName=@1", String.Join(",", newperms), name) != 0)
|
||||
{
|
||||
message = "Group " + name + " has been modified successfully.";
|
||||
|
||||
group.SetPermission( newperms.ToList() );
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Drawing;
|
||||
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
|
|
@ -378,6 +378,68 @@ namespace TShockAPI.DB
|
|||
{
|
||||
return MergedIDs.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
}
|
||||
|
||||
public bool resizeRegion(string regionName, int addAmount, int direction)
|
||||
{
|
||||
//0 = up
|
||||
//1 = right
|
||||
//2 = down
|
||||
//3 = left
|
||||
int X = 0;
|
||||
int Y = 0;
|
||||
int height = 0;
|
||||
int width = 0;
|
||||
try
|
||||
{
|
||||
using (var reader = database.QueryReader("SELECT X1, Y1, height, width FROM Regions WHERE RegionName=@0 AND WorldID=@1", regionName, Main.worldID.ToString()))
|
||||
{
|
||||
if (reader.Read())
|
||||
X = reader.Get<int>("X1");
|
||||
width = reader.Get<int>("width");
|
||||
Y = reader.Get<int>("Y1");
|
||||
height = reader.Get<int>("height");
|
||||
}
|
||||
if (!(direction == 0))
|
||||
{
|
||||
if (!(direction == 1))
|
||||
{
|
||||
if (!(direction == 2))
|
||||
{
|
||||
if (!(direction == 3))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
X -= addAmount;
|
||||
width += addAmount;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
height += addAmount;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
width += addAmount;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Y -= addAmount;
|
||||
height += addAmount;
|
||||
}
|
||||
int q = database.Query("UPDATE Regions SET X1 = @0, Y1 = @1, width = @2, height = @3 WHERE RegionName = @4 AND WorldID=@5", X, Y, width, height, regionName, Main.worldID.ToString());
|
||||
if (q > 0)
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.ToString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool RemoveUser(string regionName, string userName)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
|
||||
using MySql.Data.MySqlClient;
|
||||
using Terraria;
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ namespace TShockAPI.DB
|
|||
creator.EnsureExists(table);
|
||||
}
|
||||
|
||||
public PointF GetLeavePos(string name, string IP)
|
||||
public Vector2 GetLeavePos(string name, string IP)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -51,7 +51,7 @@ namespace TShockAPI.DB
|
|||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
return new PointF(reader.Get<int>("X"), reader.Get<int>("Y"));
|
||||
return new Vector2(reader.Get<int>("X"), reader.Get<int>("Y"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -60,12 +60,12 @@ namespace TShockAPI.DB
|
|||
Log.Error(ex.ToString());
|
||||
}
|
||||
|
||||
return new PointF();
|
||||
return new Vector2();
|
||||
}
|
||||
|
||||
public void InsertLeavePos(string name, string IP, int X, int Y)
|
||||
{
|
||||
if (GetLeavePos(name, IP) == PointF.Empty)
|
||||
if (GetLeavePos(name, IP) == Vector2.Zero)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
|
@ -173,11 +173,11 @@ namespace TShockAPI.DB
|
|||
{
|
||||
try
|
||||
{
|
||||
return new Warp(new PointF(reader.Get<int>("X"), reader.Get<int>("Y")), reader.Get<string>("WarpName"), reader.Get<string>("WorldID"), reader.Get<string>("Private"));
|
||||
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 PointF(reader.Get<int>("X"), reader.Get<int>("Y")), reader.Get<string>("WarpName"), reader.Get<string>("WorldID"), "0");
|
||||
return new Warp(new Vector2(reader.Get<int>("X"), reader.Get<int>("Y")), reader.Get<string>("WarpName"), reader.Get<string>("WorldID"), "0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -247,12 +247,12 @@ namespace TShockAPI.DB
|
|||
|
||||
public class Warp
|
||||
{
|
||||
public PointF WarpPos { get; set; }
|
||||
public Vector2 WarpPos { get; set; }
|
||||
public string WarpName { get; set; }
|
||||
public string WorldWarpID { get; set; }
|
||||
public string Private { get; set; }
|
||||
|
||||
public Warp(PointF warppos, string name, string worldid, string hidden)
|
||||
public Warp(Vector2 warppos, string name, string worldid, string hidden)
|
||||
{
|
||||
WarpPos = warppos;
|
||||
WarpName = name;
|
||||
|
|
@ -262,7 +262,7 @@ namespace TShockAPI.DB
|
|||
|
||||
public Warp()
|
||||
{
|
||||
WarpPos = PointF.Empty;
|
||||
WarpPos = Vector2.Zero;
|
||||
WarpName = null;
|
||||
WorldWarpID = string.Empty;
|
||||
Private = "0";
|
||||
|
|
|
|||
|
|
@ -52,6 +52,20 @@ namespace TShockAPI.DB
|
|||
}
|
||||
}
|
||||
|
||||
public static QueryResult QueryReaderDict(this IDbConnection olddb, string query, Dictionary<string, object> values)
|
||||
{
|
||||
var db = olddb.CloneEx();
|
||||
db.Open();
|
||||
using (var com = db.CreateCommand())
|
||||
{
|
||||
com.CommandText = query;
|
||||
foreach(var kv in values)
|
||||
com.AddParameter("@" + kv.Key, kv.Value);
|
||||
|
||||
return new QueryResult(db, com.ExecuteReader());
|
||||
}
|
||||
}
|
||||
|
||||
public static IDbDataParameter AddParameter(this IDbCommand command, string name, object data)
|
||||
{
|
||||
var parm = command.CreateParameter();
|
||||
|
|
@ -157,10 +171,14 @@ namespace TShockAPI.DB
|
|||
|
||||
public bool Read()
|
||||
{
|
||||
if (Reader == null)
|
||||
return false;
|
||||
return Reader.Read();
|
||||
}
|
||||
public T Get<T>(string column)
|
||||
{
|
||||
if (Reader == null)
|
||||
return default(T);
|
||||
return Reader.Get<T>(Reader.GetOrdinal(column));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,13 +18,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Terraria;
|
||||
using TerrariaAPI;
|
||||
|
||||
using TShockAPI.Net;
|
||||
using XNAHelpers;
|
||||
using System.IO.Streams;
|
||||
|
||||
namespace TShockAPI
|
||||
{
|
||||
|
|
@ -349,6 +349,13 @@ namespace TShockAPI
|
|||
args.Player.SendTileSquare(x, y);
|
||||
return true;
|
||||
}
|
||||
if (type == 1 && tiletype == 21 && Tools.MaxChests())
|
||||
{
|
||||
args.Player.SendMessage("Reached world's max chest limit, unable to place more!", Color.Red);
|
||||
Log.Info("Reached world's chest limit, unable to place more.");
|
||||
args.Player.SendTileSquare(x, y);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!args.Player.Group.HasPermission(Permissions.editspawn) && !TShock.Regions.CanBuild(x, y, args.Player) && TShock.Regions.InArea(x, y))
|
||||
{
|
||||
|
|
@ -393,9 +400,9 @@ namespace TShockAPI
|
|||
if (type == 0 && BlacklistTiles[Main.tile[x, y].type] && args.Player.Active)
|
||||
{
|
||||
args.Player.TileThreshold++;
|
||||
var coords = new PointF(x, y);
|
||||
var coords = new Vector2(x, y);
|
||||
if (!args.Player.TilesDestroyed.ContainsKey(coords))
|
||||
args.Player.TilesDestroyed.Add(coords, Main.tile[x, y]);
|
||||
args.Player.TilesDestroyed.Add(coords, Main.tile[x, y].Data);
|
||||
}
|
||||
|
||||
if ((DateTime.UtcNow - args.Player.LastExplosive).TotalMilliseconds < 1000)
|
||||
|
|
@ -480,12 +487,18 @@ namespace TShockAPI
|
|||
return true;
|
||||
}
|
||||
|
||||
if (type == 23 && (vely == 0f || velx == 0f)) //float.IsNaN((float)Math.Sqrt((double)(velx * velx + vely * vely))))
|
||||
if (type == 23)
|
||||
{
|
||||
Tools.HandleGriefer(args.Player, TShock.Config.ProjectileAbuseReason);
|
||||
return true;
|
||||
if (velx == 0f && vely == 0f && dmg == 99)
|
||||
{
|
||||
Tools.HandleGriefer(args.Player, TShock.Config.ProjectileAbuseReason);
|
||||
return true;
|
||||
}
|
||||
else if (velx == 0f || vely == 0f)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (type == 29 || type == 28 || type == 37)
|
||||
{
|
||||
Log.Debug(string.Format("Explosive(PlyXY:{0}_{1}, Type:{2})", args.Player.TileX, args.Player.TileY, type));
|
||||
|
|
|
|||
|
|
@ -73,6 +73,14 @@ namespace TShockAPI
|
|||
{
|
||||
permissions.Add(permission);
|
||||
}
|
||||
public void SetPermission( List<string> permission)
|
||||
{
|
||||
permissions.Clear();
|
||||
foreach( string s in permission )
|
||||
{
|
||||
permissions.Add( s );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SuperAdminGroup : Group
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Streams;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using TerrariaAPI;
|
||||
using XNAHelpers;
|
||||
|
||||
using System.IO.Streams;
|
||||
|
||||
namespace TShockAPI.Net
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.IO.Streams;
|
||||
using System.Text;
|
||||
using TerrariaAPI;
|
||||
using XNAHelpers;
|
||||
|
||||
namespace TShockAPI.Net
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
using System;
|
||||
using System.IO;
|
||||
using Terraria;
|
||||
using XNAHelpers;
|
||||
using System.IO.Streams;
|
||||
|
||||
namespace TShockAPI.Net
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using TerrariaAPI;
|
||||
using XNAHelpers;
|
||||
using System.IO;
|
||||
using System.IO.Streams;
|
||||
|
||||
namespace TShockAPI.Net
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using TerrariaAPI;
|
||||
using XNAHelpers;
|
||||
|
||||
using System.IO.Streams;
|
||||
|
||||
namespace TShockAPI.Net
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ using System.IO;
|
|||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using Terraria;
|
||||
using TerrariaAPI;
|
||||
using TerrariaAPI.Hooks;
|
||||
|
||||
using Hooks;
|
||||
|
||||
namespace TShockAPI
|
||||
{
|
||||
|
|
|
|||
|
|
@ -123,6 +123,9 @@ namespace TShockAPI
|
|||
[Description("User can spawn items")]
|
||||
public static readonly string item;
|
||||
|
||||
[Description("User can clear item drops.")]
|
||||
public static readonly string clearitems;
|
||||
|
||||
[Description("")]
|
||||
public static readonly string heal;
|
||||
|
||||
|
|
|
|||
|
|
@ -36,5 +36,5 @@ using System.Runtime.InteropServices;
|
|||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
|
||||
[assembly: AssemblyVersion("3.3.0.0905")]
|
||||
[assembly: AssemblyFileVersion("3.3.0.0905")]
|
||||
[assembly: AssemblyVersion("3.3.4.0926")]
|
||||
[assembly: AssemblyFileVersion("3.3.4.0926")]
|
||||
|
|
@ -24,7 +24,7 @@ using System.Net.Sockets;
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
using Terraria;
|
||||
using XNAHelpers;
|
||||
using System.IO.Streams;
|
||||
|
||||
namespace TShockAPI
|
||||
{
|
||||
|
|
@ -38,13 +38,30 @@ namespace TShockAPI
|
|||
public static string Response = "";
|
||||
private static bool Started;
|
||||
private static UdpClient listener;
|
||||
private static Thread startThread;
|
||||
private static Thread heartbeat;
|
||||
private static Thread listen;
|
||||
|
||||
public static void ShutdownAllThreads()
|
||||
{
|
||||
if (Started)
|
||||
{
|
||||
startThread.Abort();
|
||||
heartbeat.Abort();
|
||||
listen.Abort();
|
||||
Started = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void StartThread()
|
||||
{
|
||||
if (!Started)
|
||||
{
|
||||
(new Thread(Start)).Start();
|
||||
(new Thread(SendHeartbeat)).Start();
|
||||
startThread = new Thread(Start);
|
||||
startThread.Start();
|
||||
|
||||
heartbeat = new Thread(SendHeartbeat);
|
||||
heartbeat.Start();
|
||||
}
|
||||
Started = true;
|
||||
}
|
||||
|
|
@ -57,7 +74,7 @@ namespace TShockAPI
|
|||
Console.WriteLine(string.Format("RconHandler is running at UDP port {0} and password is {1}",
|
||||
ListenPort,
|
||||
Password));
|
||||
Thread listen = new Thread(Listener);
|
||||
listen = new Thread(Listener);
|
||||
listen.Start();
|
||||
while (true)
|
||||
{
|
||||
|
|
@ -161,8 +178,8 @@ namespace TShockAPI
|
|||
}
|
||||
else
|
||||
{
|
||||
response = "Bad rconpassword.\n";
|
||||
Log.ConsoleInfo("Bad rconpassword from " + EP);
|
||||
response = "Bad rcon password.\n";
|
||||
Log.ConsoleInfo("Bad rcon password from " + EP);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -170,7 +187,7 @@ namespace TShockAPI
|
|||
}
|
||||
else
|
||||
{
|
||||
response = "No rconpassword set on the server.\n";
|
||||
response = "No rcon password set on the server.\n";
|
||||
Log.Info("No password for rcon set");
|
||||
}
|
||||
}
|
||||
|
|
@ -328,7 +345,7 @@ namespace TShockAPI
|
|||
{
|
||||
if ((DateTime.UtcNow - LastHeartbeat).Seconds >= 30)
|
||||
{
|
||||
var packet = ConstructPacket("heartbeat TERRARIA", false);
|
||||
var packet = ConstructPacket("heartbeat TerrariaShock", false);
|
||||
if (listener == null)
|
||||
try
|
||||
{
|
||||
|
|
|
|||
141
TShockAPI/Rest/Rest.cs
Normal file
141
TShockAPI/Rest/Rest.cs
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using HttpServer;
|
||||
using HttpServer.Headers;
|
||||
using Newtonsoft.Json;
|
||||
using HttpListener = HttpServer.HttpListener;
|
||||
|
||||
namespace Rests
|
||||
{
|
||||
/// <summary>
|
||||
/// Rest command delegate
|
||||
/// </summary>
|
||||
/// <param name="parameters">Parameters in the url</param>
|
||||
/// <param name="verbs">{x} in urltemplate</param>
|
||||
/// <returns>Response object or null to not handle request</returns>
|
||||
public delegate object RestCommandD(RestVerbs verbs, IParameterCollection parameters);
|
||||
public class Rest : IDisposable
|
||||
{
|
||||
readonly List<RestCommand> commands = new List<RestCommand>();
|
||||
HttpListener listener;
|
||||
public IPAddress Ip { get; set; }
|
||||
public int Port { get; set; }
|
||||
|
||||
public Rest(IPAddress ip, int port)
|
||||
{
|
||||
Ip = ip;
|
||||
Port = port;
|
||||
}
|
||||
public virtual void Start()
|
||||
{
|
||||
if (listener == null)
|
||||
{
|
||||
listener = HttpListener.Create(Ip, Port);
|
||||
listener.RequestReceived += OnRequest;
|
||||
listener.Start(int.MaxValue);
|
||||
}
|
||||
}
|
||||
public void Start(IPAddress ip, int port)
|
||||
{
|
||||
Ip = ip;
|
||||
Port = port;
|
||||
Start();
|
||||
}
|
||||
public virtual void Stop()
|
||||
{
|
||||
listener.Stop();
|
||||
}
|
||||
|
||||
public void Register(string path, RestCommandD callback)
|
||||
{
|
||||
AddCommand(new RestCommand(path, callback));
|
||||
}
|
||||
|
||||
public void Register(RestCommand com)
|
||||
{
|
||||
AddCommand(com);
|
||||
}
|
||||
|
||||
protected void AddCommand(RestCommand com)
|
||||
{
|
||||
commands.Add(com);
|
||||
}
|
||||
|
||||
protected virtual void OnRequest(object sender, RequestEventArgs e)
|
||||
{
|
||||
var obj = ProcessRequest(sender, e);
|
||||
if (obj == null)
|
||||
throw new NullReferenceException("obj");
|
||||
|
||||
var str = JsonConvert.SerializeObject(obj, Formatting.Indented);
|
||||
e.Response.Connection.Type = ConnectionType.Close;
|
||||
e.Response.Body.Write(Encoding.ASCII.GetBytes(str), 0, str.Length);
|
||||
e.Response.Status = HttpStatusCode.OK;
|
||||
return;
|
||||
}
|
||||
|
||||
protected virtual object ProcessRequest(object sender, RequestEventArgs e)
|
||||
{
|
||||
var uri = e.Request.Uri.AbsolutePath;
|
||||
uri = uri.TrimEnd('/');
|
||||
|
||||
foreach (var com in commands)
|
||||
{
|
||||
var verbs = new RestVerbs();
|
||||
if (com.HasVerbs)
|
||||
{
|
||||
var match = Regex.Match(uri, com.UriVerbMatch);
|
||||
if (!match.Success)
|
||||
continue;
|
||||
if ((match.Groups.Count - 1) != com.UriVerbs.Length)
|
||||
continue;
|
||||
|
||||
for (int i = 0; i < com.UriVerbs.Length; i++)
|
||||
verbs.Add(com.UriVerbs[i], match.Groups[i + 1].Value);
|
||||
}
|
||||
else if (com.UriTemplate.ToLower() != uri.ToLower())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var obj = ExecuteCommand(com, verbs, e.Request.Parameters);
|
||||
if (obj != null)
|
||||
return obj;
|
||||
|
||||
}
|
||||
return new Dictionary<string, string> { { "status", "404" }, { "error", "Specified API endpoint doesn't exist. Refer to the documentation for a list of valid endpoints." } };
|
||||
}
|
||||
|
||||
protected virtual object ExecuteCommand(RestCommand cmd, RestVerbs verbs, IParameterCollection parms)
|
||||
{
|
||||
return cmd.Callback(verbs, parms);
|
||||
}
|
||||
|
||||
#region Dispose
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (listener != null)
|
||||
{
|
||||
listener.Stop();
|
||||
listener = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
~Rest()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
47
TShockAPI/Rest/RestCommand.cs
Normal file
47
TShockAPI/Rest/RestCommand.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Rests
|
||||
{
|
||||
public class RestCommand
|
||||
{
|
||||
public string Name { get; protected set; }
|
||||
public string UriTemplate { get; protected set; }
|
||||
public string UriVerbMatch { get; protected set; }
|
||||
public string[] UriVerbs { get; protected set; }
|
||||
public RestCommandD Callback { get; protected set; }
|
||||
public bool RequiresToken { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="name">Used for identification</param>
|
||||
/// <param name="uritemplate">Url template</param>
|
||||
/// <param name="callback">Rest Command callback</param>
|
||||
public RestCommand(string name, string uritemplate, RestCommandD callback)
|
||||
{
|
||||
Name = name;
|
||||
UriTemplate = uritemplate;
|
||||
UriVerbMatch = string.Format("^{0}$", string.Join("([^/]*)", Regex.Split(uritemplate, "\\{[^\\{\\}]*\\}")));
|
||||
var matches = Regex.Matches(uritemplate, "\\{([^\\{\\}]*)\\}");
|
||||
UriVerbs = (from Match match in matches select match.Groups[1].Value).ToArray();
|
||||
Callback = callback;
|
||||
RequiresToken = true;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="uritemplate">Url template</param>
|
||||
/// <param name="callback">Rest Command callback</param>
|
||||
public RestCommand(string uritemplate, RestCommandD callback)
|
||||
: this(string.Empty, uritemplate, callback)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public bool HasVerbs
|
||||
{
|
||||
get { return UriVerbs.Length > 0; }
|
||||
}
|
||||
}
|
||||
}
|
||||
448
TShockAPI/Rest/RestManager.cs
Normal file
448
TShockAPI/Rest/RestManager.cs
Normal file
|
|
@ -0,0 +1,448 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using HttpServer;
|
||||
using Rests;
|
||||
using Terraria;
|
||||
|
||||
namespace TShockAPI
|
||||
{
|
||||
|
||||
public class RestManager
|
||||
{
|
||||
private Rest Rest;
|
||||
public RestManager(Rest rest)
|
||||
{
|
||||
Rest = rest;
|
||||
}
|
||||
|
||||
public void RegisterRestfulCommands()
|
||||
{
|
||||
Rest.Register(new RestCommand("/status", Status) { RequiresToken = false });
|
||||
Rest.Register(new RestCommand("/tokentest", TokenTest) { RequiresToken = true });
|
||||
|
||||
Rest.Register(new RestCommand("/users/read/{user}/info", UserInfo) { RequiresToken = true });
|
||||
Rest.Register(new RestCommand("/users/destroy/{user}", UserDestroy) { RequiresToken = true });
|
||||
Rest.Register(new RestCommand("/users/update/{user}", UserUpdate) { RequiresToken = true });
|
||||
|
||||
Rest.Register(new RestCommand("/bans/create", BanCreate) { RequiresToken = true });
|
||||
Rest.Register(new RestCommand("/bans/read/{user}/info", BanInfo) { RequiresToken = true });
|
||||
Rest.Register(new RestCommand("/bans/destroy/{user}", BanDestroy) { RequiresToken = true });
|
||||
|
||||
|
||||
Rest.Register(new RestCommand("/lists/players", UserList) { RequiresToken = true });
|
||||
|
||||
Rest.Register(new RestCommand("/world/read", WorldRead) { RequiresToken = true });
|
||||
Rest.Register(new RestCommand("/world/meteor", WorldMeteor) { RequiresToken = true });
|
||||
Rest.Register(new RestCommand("/world/bloodmoon/{bool}", WorldBloodmoon) { RequiresToken = true });
|
||||
|
||||
Rest.Register(new RestCommand("/players/read/{player}", PlayerRead) { RequiresToken = true });
|
||||
Rest.Register(new RestCommand("/players/{player}/kick", PlayerKick) { RequiresToken = true });
|
||||
Rest.Register(new RestCommand("/players/{player}/ban", PlayerBan) { RequiresToken = true });
|
||||
//RegisterExamples();
|
||||
}
|
||||
|
||||
#region RestMethods
|
||||
|
||||
object TokenTest(RestVerbs verbs, IParameterCollection parameters)
|
||||
{
|
||||
return new Dictionary<string, string> { { "status", "200" }, { "response", "Token is valid and was passed through correctly." } };
|
||||
}
|
||||
|
||||
object Status(RestVerbs verbs, IParameterCollection parameters)
|
||||
{
|
||||
if (TShock.Config.EnableTokenEndpointAuthentication)
|
||||
return new RestObject("403") { Error = "Server settings require a token for this API call." };
|
||||
|
||||
var activeplayers = Main.player.Where(p => p != null && p.active).ToList();
|
||||
string currentPlayers = string.Join(", ", activeplayers.Select(p => p.name));
|
||||
|
||||
var ret = new RestObject("200");
|
||||
ret["name"] = TShock.Config.ServerNickname;
|
||||
ret["port"] = Convert.ToString(TShock.Config.ServerPort);
|
||||
ret["playercount"] = Convert.ToString(activeplayers.Count());
|
||||
ret["players"] = currentPlayers;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RestUserMethods
|
||||
|
||||
object UserList(RestVerbs verbs, IParameterCollection parameters)
|
||||
{
|
||||
var activeplayers = Main.player.Where(p => p != null && p.active).ToList();
|
||||
string currentPlayers = string.Join(", ", activeplayers.Select(p => p.name));
|
||||
var ret = new RestObject("200");
|
||||
ret["players"] = currentPlayers;
|
||||
return ret;
|
||||
}
|
||||
|
||||
object UserUpdate(RestVerbs verbs, IParameterCollection parameters)
|
||||
{
|
||||
var returnBlock = new Dictionary<string, string>();
|
||||
var password = parameters["password"];
|
||||
var group = parameters["group"];
|
||||
|
||||
if (group == null && password == null)
|
||||
{
|
||||
returnBlock.Add("status", "400");
|
||||
returnBlock.Add("error", "No parameters were passed.");
|
||||
return returnBlock;
|
||||
}
|
||||
|
||||
var user = TShock.Users.GetUserByName(verbs["user"]);
|
||||
if (user == null)
|
||||
{
|
||||
returnBlock.Add("status", "400");
|
||||
returnBlock.Add("error", "The specefied user doesn't exist.");
|
||||
return returnBlock;
|
||||
}
|
||||
|
||||
if (password != null)
|
||||
{
|
||||
TShock.Users.SetUserPassword(user, password);
|
||||
returnBlock.Add("password-response", "Password updated successfully.");
|
||||
}
|
||||
|
||||
if (group != null)
|
||||
{
|
||||
TShock.Users.SetUserGroup(user, group);
|
||||
returnBlock.Add("group-response", "Group updated successfully.");
|
||||
}
|
||||
|
||||
returnBlock.Add("status", "200");
|
||||
return returnBlock;
|
||||
}
|
||||
|
||||
object UserDestroy(RestVerbs verbs, IParameterCollection parameters)
|
||||
{
|
||||
var user = TShock.Users.GetUserByName(verbs["user"]);
|
||||
if (user == null)
|
||||
{
|
||||
return new Dictionary<string, string> { { "status", "400" }, { "error", "The specified user account does not exist." } };
|
||||
}
|
||||
var returnBlock = new Dictionary<string, string>();
|
||||
try
|
||||
{
|
||||
TShock.Users.RemoveUser(user);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
returnBlock.Add("status", "400");
|
||||
returnBlock.Add("error", "The specified user was unable to be removed.");
|
||||
return returnBlock;
|
||||
}
|
||||
returnBlock.Add("status", "200");
|
||||
returnBlock.Add("response", "User deleted successfully.");
|
||||
return returnBlock;
|
||||
}
|
||||
|
||||
object UserInfo(RestVerbs verbs, IParameterCollection parameters)
|
||||
{
|
||||
var user = TShock.Users.GetUserByName(verbs["user"]);
|
||||
if (user == null)
|
||||
{
|
||||
return new Dictionary<string, string> { { "status", "400" }, { "error", "The specified user account does not exist." } };
|
||||
}
|
||||
|
||||
var returnBlock = new Dictionary<string, string>();
|
||||
returnBlock.Add("status", "200");
|
||||
returnBlock.Add("group", user.Group);
|
||||
returnBlock.Add("id", user.ID.ToString());
|
||||
return returnBlock;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RestBanMethods
|
||||
|
||||
object BanCreate(RestVerbs verbs, IParameterCollection parameters)
|
||||
{
|
||||
var returnBlock = new Dictionary<string, string>();
|
||||
var ip = parameters["ip"];
|
||||
var name = parameters["name"];
|
||||
var reason = parameters["reason"];
|
||||
|
||||
if (ip == null && name == null)
|
||||
{
|
||||
returnBlock.Add("status", "400");
|
||||
returnBlock.Add("error", "Required parameters were missing from this API endpoint.");
|
||||
return returnBlock;
|
||||
}
|
||||
|
||||
if (ip == null)
|
||||
{
|
||||
ip = "";
|
||||
}
|
||||
|
||||
if (name == null)
|
||||
{
|
||||
name = "";
|
||||
}
|
||||
|
||||
if (reason == null)
|
||||
{
|
||||
reason = "";
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
TShock.Bans.AddBan(ip, name, reason);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
returnBlock.Add("status", "400");
|
||||
returnBlock.Add("error", "The specified ban was unable to be created.");
|
||||
return returnBlock;
|
||||
}
|
||||
returnBlock.Add("status", "200");
|
||||
returnBlock.Add("response", "Ban created successfully.");
|
||||
return returnBlock;
|
||||
}
|
||||
|
||||
object BanDestroy(RestVerbs verbs, IParameterCollection parameters)
|
||||
{
|
||||
var returnBlock = new Dictionary<string, string>();
|
||||
|
||||
var type = parameters["type"];
|
||||
if (type == null)
|
||||
{
|
||||
returnBlock.Add("Error", "Invalid Type");
|
||||
return returnBlock;
|
||||
}
|
||||
|
||||
var ban = new DB.Ban();
|
||||
if (type == "ip") ban = TShock.Bans.GetBanByIp(verbs["user"]);
|
||||
else if (type == "name") ban = TShock.Bans.GetBanByName(verbs["user"]);
|
||||
else
|
||||
{
|
||||
returnBlock.Add("Error", "Invalid Type");
|
||||
return returnBlock;
|
||||
}
|
||||
|
||||
if (ban == null)
|
||||
{
|
||||
return new Dictionary<string, string> { { "status", "400" }, { "error", "The specified ban does not exist." } };
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
TShock.Bans.RemoveBan(ban.IP);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
returnBlock.Add("status", "400");
|
||||
returnBlock.Add("error", "The specified ban was unable to be removed.");
|
||||
return returnBlock;
|
||||
}
|
||||
returnBlock.Add("status", "200");
|
||||
returnBlock.Add("response", "Ban deleted successfully.");
|
||||
return returnBlock;
|
||||
}
|
||||
|
||||
object BanInfo(RestVerbs verbs, IParameterCollection parameters)
|
||||
{
|
||||
var returnBlock = new Dictionary<string, string>();
|
||||
|
||||
var type = parameters["type"];
|
||||
if (type == null)
|
||||
{
|
||||
returnBlock.Add("Error", "Invalid Type");
|
||||
return returnBlock;
|
||||
}
|
||||
|
||||
var ban = new DB.Ban();
|
||||
if (type == "ip") ban = TShock.Bans.GetBanByIp(verbs["user"]);
|
||||
else if (type == "name") ban = TShock.Bans.GetBanByName(verbs["user"]);
|
||||
else
|
||||
{
|
||||
returnBlock.Add("Error", "Invalid Type");
|
||||
return returnBlock;
|
||||
}
|
||||
|
||||
if (ban == null)
|
||||
{
|
||||
return new Dictionary<string, string> { { "status", "400" }, { "error", "The specified ban does not exist." } };
|
||||
}
|
||||
|
||||
returnBlock.Add("status", "200");
|
||||
returnBlock.Add("name", ban.Name);
|
||||
returnBlock.Add("ip", ban.IP);
|
||||
returnBlock.Add("reason", ban.Reason);
|
||||
return returnBlock;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RestWorldMethods
|
||||
object WorldRead(RestVerbs verbs, IParameterCollection parameters)
|
||||
{
|
||||
var returnBlock = new Dictionary<string, object>();
|
||||
returnBlock.Add("status", "200");
|
||||
returnBlock.Add("name", Main.worldName);
|
||||
returnBlock.Add("size", Main.maxTilesX + "*" + Main.maxTilesY);
|
||||
returnBlock.Add("time", Main.time);
|
||||
returnBlock.Add("daytime", Main.dayTime);
|
||||
returnBlock.Add("bloodmoon", Main.bloodMoon);
|
||||
returnBlock.Add("invasionsize", Main.invasionSize);
|
||||
return returnBlock;
|
||||
}
|
||||
|
||||
object WorldMeteor(RestVerbs verbs, IParameterCollection parameters)
|
||||
{
|
||||
WorldGen.dropMeteor();
|
||||
var returnBlock = new Dictionary<string, string>();
|
||||
returnBlock.Add("status", "200");
|
||||
returnBlock.Add("response", "Meteor has been spawned.");
|
||||
return returnBlock;
|
||||
}
|
||||
|
||||
object WorldBloodmoon(RestVerbs verbs, IParameterCollection parameters)
|
||||
{
|
||||
var returnBlock = new Dictionary<string, string>();
|
||||
var bloodmoonVerb = verbs["bool"];
|
||||
bool bloodmoon;
|
||||
if (bloodmoonVerb == null)
|
||||
{
|
||||
returnBlock.Add("status", "400");
|
||||
returnBlock.Add("error", "No parameter was passed.");
|
||||
return returnBlock;
|
||||
}
|
||||
if (!bool.TryParse(bloodmoonVerb, out bloodmoon))
|
||||
{
|
||||
returnBlock.Add("status", "400");
|
||||
returnBlock.Add("error", "Unable to parse parameter.");
|
||||
return returnBlock;
|
||||
}
|
||||
Main.bloodMoon = bloodmoon;
|
||||
returnBlock.Add("status", "200");
|
||||
returnBlock.Add("response", "Blood Moon has been set to " + bloodmoon.ToString());
|
||||
return returnBlock;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region RestPlayerMethods
|
||||
object PlayerRead(RestVerbs verbs, IParameterCollection parameters)
|
||||
{
|
||||
var returnBlock = new Dictionary<string, object>();
|
||||
var playerParam = parameters["player"];
|
||||
var found = Tools.FindPlayer(playerParam.ToString());
|
||||
if (found.Count == 0)
|
||||
{
|
||||
returnBlock.Add("status", "400");
|
||||
returnBlock.Add("error", "Name " + playerParam.ToString() + " was not found");
|
||||
}
|
||||
else if (found.Count > 1)
|
||||
{
|
||||
returnBlock.Add("status", "400");
|
||||
returnBlock.Add("error", "Name " + playerParam.ToString() + " matches " + playerParam.Count().ToString() + " players");
|
||||
}
|
||||
else if (found.Count == 1)
|
||||
{
|
||||
var player = found[0];
|
||||
returnBlock.Add("status", "200");
|
||||
returnBlock.Add("nickname", player.Name);
|
||||
returnBlock.Add("username", player.UserAccountName == null ? "" : player.UserAccountName);
|
||||
returnBlock.Add("ip", player.IP);
|
||||
returnBlock.Add("group", player.Group.Name);
|
||||
returnBlock.Add("position", player.TileX.ToString() + "," + player.TileY.ToString());
|
||||
var activeItems = player.TPlayer.inventory.Where(p => p.active).ToList();
|
||||
returnBlock.Add("inventory", string.Join(", ", activeItems.Select(p => p.name)));
|
||||
returnBlock.Add("buffs", string.Join(", ", player.TPlayer.buffType));
|
||||
}
|
||||
return returnBlock;
|
||||
}
|
||||
object PlayerKick(RestVerbs verbs, IParameterCollection parameters)
|
||||
{
|
||||
var returnBlock = new Dictionary<string, object>();
|
||||
var playerParam = parameters["player"];
|
||||
var found = Tools.FindPlayer(playerParam.ToString());
|
||||
var reason = verbs["reason"];
|
||||
if (found.Count == 0)
|
||||
{
|
||||
returnBlock.Add("status", "400");
|
||||
returnBlock.Add("error", "Name " + playerParam.ToString() + " was not found");
|
||||
}
|
||||
else if (found.Count > 1)
|
||||
{
|
||||
returnBlock.Add("status", "400");
|
||||
returnBlock.Add("error", "Name " + playerParam.ToString() + " matches " + playerParam.Count().ToString() + " players");
|
||||
}
|
||||
else if (found.Count == 1)
|
||||
{
|
||||
var player = found[0];
|
||||
Tools.ForceKick(player, reason == null ? "Kicked via web" : reason.ToString());
|
||||
returnBlock.Add("status", "200");
|
||||
returnBlock.Add("response", "Player " + player.Name + " was kicked");
|
||||
}
|
||||
return returnBlock;
|
||||
}
|
||||
object PlayerBan(RestVerbs verbs, IParameterCollection parameters)
|
||||
{
|
||||
var returnBlock = new Dictionary<string, object>();
|
||||
var playerParam = parameters["player"];
|
||||
var found = Tools.FindPlayer(playerParam.ToString());
|
||||
var reason = verbs["reason"];
|
||||
if (found.Count == 0)
|
||||
{
|
||||
returnBlock.Add("status", "400");
|
||||
returnBlock.Add("error", "Name " + playerParam.ToString() + " was not found");
|
||||
}
|
||||
else if (found.Count > 1)
|
||||
{
|
||||
returnBlock.Add("status", "400");
|
||||
returnBlock.Add("error", "Name " + playerParam.ToString() + " matches " + playerParam.Count().ToString() + " players");
|
||||
}
|
||||
else if (found.Count == 1)
|
||||
{
|
||||
var player = found[0];
|
||||
TShock.Bans.AddBan(player.IP, player.Name, reason == null ? "Banned via web" : reason.ToString());
|
||||
Tools.ForceKick(player, reason == null ? "Banned via web" : reason.ToString());
|
||||
returnBlock.Add("status", "200");
|
||||
returnBlock.Add("response", "Player " + player.Name + " was banned");
|
||||
}
|
||||
return returnBlock;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region RestExampleMethods
|
||||
|
||||
public void RegisterExamples()
|
||||
{
|
||||
Rest.Register(new RestCommand("/HelloWorld/name/{username}", UserTest) { RequiresToken = false });
|
||||
Rest.Register(new RestCommand("/wizard/{username}", Wizard) { RequiresToken = false });
|
||||
}
|
||||
|
||||
//The Wizard example, for demonstrating the response convention:
|
||||
object Wizard(RestVerbs verbs, IParameterCollection parameters)
|
||||
{
|
||||
var returnBack = new Dictionary<string, string>();
|
||||
returnBack.Add("status", "200"); //Keep this in everything, 200 = ok, etc. Standard http status codes.
|
||||
returnBack.Add("error", "(If this failed, you would have a different status code and provide the error object.)"); //And only include this if the status isn't 200 or a failure
|
||||
returnBack.Add("Verified Wizard", "You're a wizard, " + verbs["username"]); //Outline any api calls and possible responses in some form of documentation somewhere
|
||||
return returnBack;
|
||||
}
|
||||
|
||||
//http://127.0.0.1:8080/HelloWorld/name/{username}?type=status
|
||||
object UserTest(RestVerbs verbs, IParameterCollection parameters)
|
||||
{
|
||||
var ret = new Dictionary<string, string>();
|
||||
var type = parameters["type"];
|
||||
if (type == null)
|
||||
{
|
||||
ret.Add("Error", "Invalid Type");
|
||||
return ret;
|
||||
}
|
||||
if (type == "status")
|
||||
{
|
||||
ret.Add("Users", "Info here");
|
||||
return ret;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
63
TShockAPI/Rest/RestObject.cs
Normal file
63
TShockAPI/Rest/RestObject.cs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Rests
|
||||
{
|
||||
[Serializable]
|
||||
public class RestObject : Dictionary<string, object>
|
||||
{
|
||||
public string Status
|
||||
{
|
||||
get { return this["status"] as string; }
|
||||
set { this["status"] = value; }
|
||||
}
|
||||
public string Error
|
||||
{
|
||||
get { return this["error"] as string; }
|
||||
set { this["error"] = value; }
|
||||
}
|
||||
public string Response
|
||||
{
|
||||
get { return this["response"] as string; }
|
||||
set { this["response"] = value; }
|
||||
}
|
||||
|
||||
public RestObject(string status)
|
||||
{
|
||||
Status = status;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets value safely, if it does not exist, return null. Sets/Adds value safely, if null it will remove.
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns>Returns null if key does not exist.</returns>
|
||||
public new object this[string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
object ret;
|
||||
if (TryGetValue(key, out ret))
|
||||
return ret;
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!ContainsKey(key))
|
||||
{
|
||||
if (value == null)
|
||||
return;
|
||||
Add(key, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value != null)
|
||||
base[key] = value;
|
||||
else
|
||||
Remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
42
TShockAPI/Rest/RestVerbs.cs
Normal file
42
TShockAPI/Rest/RestVerbs.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Rests
|
||||
{
|
||||
[Serializable]
|
||||
public class RestVerbs : Dictionary<string, string>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets value safely, if it does not exist, return null. Sets/Adds value safely, if null it will remove.
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns>Returns null if key does not exist.</returns>
|
||||
public new string this[string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
string ret;
|
||||
if (TryGetValue(key, out ret))
|
||||
return ret;
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!ContainsKey(key))
|
||||
{
|
||||
if (value == null)
|
||||
return;
|
||||
Add(key, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value != null)
|
||||
base[key] = value;
|
||||
else
|
||||
Remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
91
TShockAPI/Rest/SecureRest.cs
Normal file
91
TShockAPI/Rest/SecureRest.cs
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using HttpServer;
|
||||
using TShockAPI;
|
||||
|
||||
namespace Rests
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="username">Username to verify</param>
|
||||
/// <param name="password">Password to verify</param>
|
||||
/// <returns>Returning a restobject with a null error means a successful verification.</returns>
|
||||
public delegate RestObject VerifyD(string username, string password);
|
||||
public class SecureRest : Rest
|
||||
{
|
||||
public Dictionary<string, object> Tokens { get; protected set; }
|
||||
public event VerifyD Verify;
|
||||
public SecureRest(IPAddress ip, int port)
|
||||
: base(ip, port)
|
||||
{
|
||||
Tokens = new Dictionary<string, object>();
|
||||
Register(new RestCommand("/token/create/{username}/{password}", NewToken) { RequiresToken = false });
|
||||
Register(new RestCommand("/token/destroy/{token}", DestroyToken) { RequiresToken = true });
|
||||
}
|
||||
|
||||
object DestroyToken(RestVerbs verbs, IParameterCollection parameters)
|
||||
{
|
||||
var token = verbs["token"];
|
||||
try
|
||||
{
|
||||
Tokens.Remove(token);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return new Dictionary<string, string> { { "status", "400" }, { "error", "The specified token queued for destruction failed to be deleted." } };
|
||||
}
|
||||
return new Dictionary<string, string> { { "status", "200" }, { "response", "Requested token was successfully destroyed." } };
|
||||
}
|
||||
|
||||
object NewToken(RestVerbs verbs, IParameterCollection parameters)
|
||||
{
|
||||
var user = verbs["username"];
|
||||
var pass = verbs["password"];
|
||||
|
||||
RestObject obj = null;
|
||||
if (Verify != null)
|
||||
obj = Verify(user, pass);
|
||||
|
||||
if (obj == null)
|
||||
obj = new RestObject("401") { Error = "Invalid username/password combination provided. Please re-submit your query with a correct pair." };
|
||||
|
||||
if (obj.Error != null)
|
||||
return obj;
|
||||
|
||||
string hash;
|
||||
var rand = new Random();
|
||||
var randbytes = new byte[32];
|
||||
do
|
||||
{
|
||||
rand.NextBytes(randbytes);
|
||||
hash = randbytes.Aggregate("", (s, b) => s + b.ToString("X2"));
|
||||
} while (Tokens.ContainsKey(hash));
|
||||
|
||||
Tokens.Add(hash, user);
|
||||
|
||||
obj["token"] = hash;
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected override object ExecuteCommand(RestCommand cmd, RestVerbs verbs, IParameterCollection parms)
|
||||
{
|
||||
if (cmd.RequiresToken)
|
||||
{
|
||||
var strtoken = parms["token"];
|
||||
if (strtoken == null)
|
||||
return new Dictionary<string, string> { { "status", "401" }, { "error", "Not authorized. The specified API endpoint requires a token." } };
|
||||
|
||||
object token;
|
||||
if (!Tokens.TryGetValue(strtoken, out token))
|
||||
return new Dictionary<string, string> { { "status", "403" }, { "error", "Not authorized. The specified API endpoint requires a token, but the provided token was not valid." } };
|
||||
}
|
||||
return base.ExecuteCommand(cmd, verbs, parms);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -17,13 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using Terraria;
|
||||
using TerrariaAPI;
|
||||
|
||||
using TShockAPI.Net;
|
||||
using XNAHelpers;
|
||||
|
||||
namespace TShockAPI
|
||||
{
|
||||
|
|
@ -32,7 +31,7 @@ namespace TShockAPI
|
|||
public static readonly TSServerPlayer Server = new TSServerPlayer();
|
||||
public static readonly TSPlayer All = new TSPlayer("All");
|
||||
public int TileThreshold { get; set; }
|
||||
public Dictionary<PointF, Tile> TilesDestroyed { get; protected set; }
|
||||
public Dictionary<Vector2, TileData> TilesDestroyed { get; protected set; }
|
||||
public bool SyncHP { get; set; }
|
||||
public bool SyncMP { get; set; }
|
||||
public Group Group { get; set; }
|
||||
|
|
@ -46,10 +45,10 @@ namespace TShockAPI
|
|||
public DateTime LastTileChangeNotify { get; set; }
|
||||
public bool InitSpawn;
|
||||
public bool DisplayLogs = true;
|
||||
public PointF oldSpawn = PointF.Empty;
|
||||
public Vector2 oldSpawn = Vector2.Zero;
|
||||
public TSPlayer LastWhisper;
|
||||
public int LoginAttempts { get; set; }
|
||||
public PointF TeleportCoords = new PointF(-1, -1);
|
||||
public Vector2 TeleportCoords = new Vector2(-1, -1);
|
||||
public string UserAccountName { get; set; }
|
||||
public bool HasBeenSpammedWithBuildMessage;
|
||||
public bool IsLoggedIn;
|
||||
|
|
@ -69,7 +68,7 @@ namespace TShockAPI
|
|||
}
|
||||
public bool ConnectionAlive
|
||||
{
|
||||
get { return RealPlayer ? Netplay.serverSock[Index] != null && Netplay.serverSock[Index].active && !Netplay.serverSock[Index].kill : false; }
|
||||
get { return RealPlayer && (Netplay.serverSock[Index] != null && Netplay.serverSock[Index].active && !Netplay.serverSock[Index].kill); }
|
||||
}
|
||||
public string IP
|
||||
{
|
||||
|
|
@ -145,14 +144,14 @@ namespace TShockAPI
|
|||
|
||||
public TSPlayer(int index)
|
||||
{
|
||||
TilesDestroyed = new Dictionary<PointF, Tile>();
|
||||
TilesDestroyed = new Dictionary<Vector2, TileData>();
|
||||
Index = index;
|
||||
Group = new Group("null");
|
||||
}
|
||||
|
||||
protected TSPlayer(String playerName)
|
||||
{
|
||||
TilesDestroyed = new Dictionary<PointF, Tile>();
|
||||
TilesDestroyed = new Dictionary<Vector2, TileData>();
|
||||
Index = -1;
|
||||
FakePlayer = new Player { name = playerName, whoAmi = -1 };
|
||||
Group = new Group("null");
|
||||
|
|
@ -213,7 +212,7 @@ namespace TShockAPI
|
|||
//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, 150))
|
||||
if (!SendTileSquare(tilex, tiley))
|
||||
{
|
||||
InitSpawn = true;
|
||||
SendWorldInfo(Main.spawnTileX, Main.spawnTileY, false);
|
||||
|
|
@ -225,6 +224,9 @@ namespace TShockAPI
|
|||
|
||||
SendWorldInfo(Main.spawnTileX, Main.spawnTileY, false);
|
||||
|
||||
TPlayer.position.X = tilex;
|
||||
TPlayer.position.Y = tiley;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -406,17 +408,17 @@ namespace TShockAPI
|
|||
NetMessage.SendData((int)PacketTypes.NpcStrike, -1, -1, "", npcid, damage, knockBack, hitDirection);
|
||||
}
|
||||
|
||||
public void RevertKillTile(Dictionary<PointF, Tile> destroyedTiles)
|
||||
public void RevertKillTile(Dictionary<Vector2, TileData> destroyedTiles)
|
||||
{
|
||||
// Update Main.Tile first so that when tile sqaure is sent it is correct
|
||||
foreach (KeyValuePair<PointF, Tile> entry in destroyedTiles)
|
||||
foreach (KeyValuePair<Vector2, TileData> entry in destroyedTiles)
|
||||
{
|
||||
Main.tile[(int)entry.Key.X, (int)entry.Key.Y] = entry.Value;
|
||||
Main.tile[(int)entry.Key.X, (int)entry.Key.Y].Data = entry.Value;
|
||||
Log.Debug(string.Format("Reverted DestroyedTile(TileXY:{0}_{1}, Type:{2})",
|
||||
entry.Key.X, entry.Key.Y, Main.tile[(int)entry.Key.X, (int)entry.Key.Y].type));
|
||||
}
|
||||
// Send all players updated tile sqaures
|
||||
foreach (PointF coords in destroyedTiles.Keys)
|
||||
foreach (Vector2 coords in destroyedTiles.Keys)
|
||||
{
|
||||
All.SendTileSquare((int)coords.X, (int)coords.Y, 3);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,17 +29,15 @@ using System.Collections.Generic;
|
|||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Community.CsharpSqlite.SQLiteClient;
|
||||
using Hooks;
|
||||
using MySql.Data.MySqlClient;
|
||||
using Rests;
|
||||
using Terraria;
|
||||
using TerrariaAPI;
|
||||
using TerrariaAPI.Hooks;
|
||||
using TShockAPI.DB;
|
||||
using TShockAPI.Net;
|
||||
|
||||
|
|
@ -49,7 +47,7 @@ namespace TShockAPI
|
|||
public class TShock : TerrariaPlugin
|
||||
{
|
||||
public static readonly Version VersionNum = Assembly.GetExecutingAssembly().GetName().Version;
|
||||
public static readonly string VersionCodename = "And believe me, we are still alive.";
|
||||
public static readonly string VersionCodename = "Try the new slim model.";
|
||||
|
||||
public static string SavePath = "tshock";
|
||||
|
||||
|
|
@ -67,6 +65,8 @@ namespace TShockAPI
|
|||
public static bool OverridePort;
|
||||
public static PacketBufferer PacketBuffer;
|
||||
public static MaxMind.GeoIPCountry Geo;
|
||||
public static SecureRest RestApi;
|
||||
public static RestManager RestManager;
|
||||
|
||||
/// <summary>
|
||||
/// Called after TShock is initialized. Useful for plugins that needs hooks before tshock but also depend on tshock being loaded.
|
||||
|
|
@ -142,7 +142,7 @@ namespace TShockAPI
|
|||
var hostport = Config.MySqlHost.Split(':');
|
||||
DB = new MySqlConnection();
|
||||
DB.ConnectionString =
|
||||
String.Format("Server='{0}'; Port='{1}'; Database='{2}'; Uid='{3}'; Pwd='{4}';",
|
||||
String.Format("Server={0}; Port={1}; Database={2}; Uid={3}; Pwd={4};",
|
||||
hostport[0],
|
||||
hostport.Length > 1 ? hostport[1] : "3306",
|
||||
Config.MySqlDbName,
|
||||
|
|
@ -172,8 +172,15 @@ namespace TShockAPI
|
|||
Regions = new RegionManager(DB);
|
||||
Itembans = new ItemManager(DB);
|
||||
RememberedPos = new RemeberedPosManager(DB);
|
||||
if (Config.EnableGeoIP)
|
||||
Geo = new MaxMind.GeoIPCountry(Path.Combine(SavePath, "GeoIP.dat"));
|
||||
RestApi = new SecureRest(Netplay.serverListenIP, 8080);
|
||||
RestApi.Verify += RestApi_Verify;
|
||||
RestApi.Port = Config.RestApiPort;
|
||||
RestManager = new RestManager(RestApi);
|
||||
RestManager.RegisterRestfulCommands();
|
||||
|
||||
var geoippath = Path.Combine(SavePath, "GeoIP.dat");
|
||||
if (Config.EnableGeoIP && File.Exists(geoippath))
|
||||
Geo = new MaxMind.GeoIPCountry(geoippath);
|
||||
|
||||
Log.ConsoleInfo(string.Format("TShock Version {0} ({1}) now running.", Version, VersionCodename));
|
||||
|
||||
|
|
@ -209,23 +216,50 @@ namespace TShockAPI
|
|||
}
|
||||
}
|
||||
|
||||
public override void DeInitialize()
|
||||
RestObject RestApi_Verify(string username, string password)
|
||||
{
|
||||
GameHooks.PostInitialize -= OnPostInit;
|
||||
GameHooks.Update -= OnUpdate;
|
||||
ServerHooks.Join -= OnJoin;
|
||||
ServerHooks.Leave -= OnLeave;
|
||||
ServerHooks.Chat -= OnChat;
|
||||
ServerHooks.Command -= ServerHooks_OnCommand;
|
||||
NetHooks.GetData -= OnGetData;
|
||||
NetHooks.SendData -= NetHooks_SendData;
|
||||
NetHooks.GreetPlayer -= OnGreetPlayer;
|
||||
NpcHooks.StrikeNpc -= NpcHooks_OnStrikeNpc;
|
||||
if (File.Exists(Path.Combine(SavePath, "tshock.pid")))
|
||||
var userAccount = TShock.Users.GetUserByName(username);
|
||||
if (userAccount == null)
|
||||
{
|
||||
Console.WriteLine("Thanks for using TShock! Process ID file is now being destroyed.");
|
||||
File.Delete(Path.Combine(SavePath, "tshock.pid"));
|
||||
return new RestObject("401") { Error = "Invalid username/password combination provided. Please re-submit your query with a correct pair." };
|
||||
}
|
||||
|
||||
if (Tools.HashPassword(password).ToUpper() != userAccount.Password.ToUpper())
|
||||
{
|
||||
return new RestObject("401") { Error = "Invalid username/password combination provided. Please re-submit your query with a correct pair." };
|
||||
}
|
||||
|
||||
if (!Tools.GetGroup(userAccount.Group).HasPermission("api") && userAccount.Group != "superadmin")
|
||||
{
|
||||
return new RestObject("403") { Error = "Although your account was successfully found and identified, your account lacks the permission required to use the API. (api)" };
|
||||
}
|
||||
|
||||
return new RestObject("200") { Response = "Successful login" }; //Maybe return some user info too?
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
GameHooks.PostInitialize -= OnPostInit;
|
||||
GameHooks.Update -= OnUpdate;
|
||||
ServerHooks.Join -= OnJoin;
|
||||
ServerHooks.Leave -= OnLeave;
|
||||
ServerHooks.Chat -= OnChat;
|
||||
ServerHooks.Command -= ServerHooks_OnCommand;
|
||||
NetHooks.GetData -= OnGetData;
|
||||
NetHooks.SendData -= NetHooks_SendData;
|
||||
NetHooks.GreetPlayer -= OnGreetPlayer;
|
||||
NpcHooks.StrikeNpc -= NpcHooks_OnStrikeNpc;
|
||||
if (File.Exists(Path.Combine(SavePath, "tshock.pid")))
|
||||
{
|
||||
Console.WriteLine("Thanks for using TShock! Process ID file is now being destroyed.");
|
||||
File.Delete(Path.Combine(SavePath, "tshock.pid"));
|
||||
}
|
||||
RestApi.Dispose();
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -352,6 +386,8 @@ namespace TShockAPI
|
|||
AuthToken = 0;
|
||||
}
|
||||
Regions.ReloadAllRegions();
|
||||
if (Config.RestApiEnabled)
|
||||
RestApi.Start();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -624,7 +660,7 @@ namespace TShockAPI
|
|||
NetMessage.SendData((int)PacketTypes.TimeSet, -1, -1, "", 0, 0, Main.sunModY, Main.moonModY);
|
||||
NetMessage.syncPlayers();
|
||||
|
||||
if (Config.EnableGeoIP)
|
||||
if (Config.EnableGeoIP && Geo != null)
|
||||
{
|
||||
var code = Geo.TryGetCountryCode(IPAddress.Parse(player.IP));
|
||||
player.Country = code == null ? "N/A" : MaxMind.GeoIPCountry.GetCountryNameByCode(code);
|
||||
|
|
@ -813,11 +849,11 @@ namespace TShockAPI
|
|||
|
||||
public static bool CheckSpawn(int x, int y)
|
||||
{
|
||||
PointF tile = new PointF(x, y);
|
||||
PointF spawn = new PointF(Main.spawnTileX, Main.spawnTileY);
|
||||
Vector2 tile = new Vector2(x, y);
|
||||
Vector2 spawn = new Vector2(Main.spawnTileX, Main.spawnTileY);
|
||||
return Distance(spawn, tile) <= Config.SpawnProtectionRadius;
|
||||
}
|
||||
public static float Distance(PointF value1, PointF value2)
|
||||
public static float Distance(Vector2 value1, Vector2 value2)
|
||||
{
|
||||
float num2 = value1.X - value2.X;
|
||||
float num = value1.Y - value2.Y;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\..\serverplugins\</OutputPath>
|
||||
<OutputPath>..\..\..\Downloads\TShock 3.3.4.924\ServerPlugins\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
|
|
@ -52,6 +52,9 @@
|
|||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\SqlBins\Community.CsharpSqlite.SQLiteClient.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="HttpServer">
|
||||
<HintPath>..\HttpBins\HttpServer.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MySql.Data, Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\SqlBins\MySql.Data.dll</HintPath>
|
||||
|
|
@ -67,7 +70,6 @@
|
|||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
|
|
@ -79,10 +81,6 @@
|
|||
<HintPath>..\TerrariaServerBins\TerrariaServer.exe</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="TerrariaServerAPI, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\TerrariaServerBins\TerrariaServerAPI.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BackupManager.cs" />
|
||||
|
|
@ -121,6 +119,12 @@
|
|||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Rest\Rest.cs" />
|
||||
<Compile Include="Rest\RestCommand.cs" />
|
||||
<Compile Include="Rest\RestManager.cs" />
|
||||
<Compile Include="Rest\RestObject.cs" />
|
||||
<Compile Include="Rest\RestVerbs.cs" />
|
||||
<Compile Include="Rest\SecureRest.cs" />
|
||||
<Compile Include="Tools.cs" />
|
||||
<Compile Include="TShock.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
|
@ -177,7 +181,7 @@
|
|||
</PropertyGroup>
|
||||
<ProjectExtensions>
|
||||
<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>
|
||||
</ProjectExtensions>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
TShock, a server mod for Terraria
|
||||
Copyright (C) 2011 The TShock Team
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
|
@ -25,7 +25,7 @@ using System.Net.Sockets;
|
|||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Terraria;
|
||||
using TerrariaAPI;
|
||||
|
||||
|
||||
namespace TShockAPI
|
||||
{
|
||||
|
|
@ -127,7 +127,6 @@ namespace TShockAPI
|
|||
TSPlayer.All.SendMessage(msg, red, green, blue);
|
||||
TSPlayer.Server.SendMessage(msg, red, green, blue);
|
||||
Log.Info(string.Format("Broadcast: {0}", msg));
|
||||
|
||||
}
|
||||
|
||||
public static void Broadcast(string msg, Color color)
|
||||
|
|
@ -429,7 +428,7 @@ namespace TShockAPI
|
|||
|
||||
private static bool HandleBadPlayer(TSPlayer player, string overridePermission, bool ban, bool kick, string reason)
|
||||
{
|
||||
if (!player.Group.HasPermission(overridePermission))
|
||||
if (!player.Group.HasPermission(overridePermission) || !(player.Group.Name == "superadmin"))
|
||||
{
|
||||
if (ban)
|
||||
{
|
||||
|
|
@ -535,23 +534,33 @@ namespace TShockAPI
|
|||
/// <summary>
|
||||
/// Returns a Sha256 string for a given string
|
||||
/// </summary>
|
||||
/// <param name="password">string password</param>
|
||||
/// <param name="bytes">bytes to hash</param>
|
||||
/// <returns>string sha256</returns>
|
||||
public static string HashPassword(string password)
|
||||
public static string HashPassword(byte[] bytes)
|
||||
{
|
||||
if (string.IsNullOrEmpty(password) || password == "non-existant password")
|
||||
return "non-existant password";
|
||||
|
||||
if (bytes == null)
|
||||
throw new NullReferenceException("bytes");
|
||||
Func<HashAlgorithm> func;
|
||||
if (!HashTypes.TryGetValue(HashAlgo.ToLower(), out func))
|
||||
throw new NotSupportedException("Hashing algorithm {0} is not supported".SFormat(HashAlgo.ToLower()));
|
||||
|
||||
using (var hash = func())
|
||||
{
|
||||
var bytes = hash.ComputeHash(Encoding.ASCII.GetBytes(password));
|
||||
return bytes.Aggregate("", (s, b) => s + b.ToString("X2"));
|
||||
var ret = hash.ComputeHash(bytes);
|
||||
return ret.Aggregate("", (s, b) => s + b.ToString("X2"));
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a Sha256 string for a given string
|
||||
/// </summary>
|
||||
/// <param name="bytes">bytes to hash</param>
|
||||
/// <returns>string sha256</returns>
|
||||
public static string HashPassword(string password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(password) || password == "non-existant password")
|
||||
return "non-existant password";
|
||||
return HashPassword(Encoding.UTF8.GetBytes(password));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the string contains any unprintable characters
|
||||
|
|
@ -582,4 +591,4 @@ namespace TShockAPI
|
|||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using Newtonsoft.Json;
|
||||
|
|
|
|||
|
|
@ -1,202 +0,0 @@
|
|||
/*
|
||||
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;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Xml;
|
||||
using Terraria;
|
||||
|
||||
namespace TShockAPI
|
||||
{
|
||||
class WarpsManager
|
||||
{
|
||||
public static List<Warp> Warps = new List<Warp>();
|
||||
|
||||
public static bool AddWarp(int x, int y, string name, string worldname)
|
||||
{
|
||||
foreach (Warp nametest in Warps)
|
||||
{
|
||||
if (name.ToLower() == nametest.WarpName.ToLower())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Warps.Add(new Warp(new Vector2(x, y), name, worldname));
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool DeleteWarp(string name)
|
||||
{
|
||||
foreach (Warp nametest in Warps)
|
||||
{
|
||||
if (name.ToLower() == nametest.WarpName.ToLower() && nametest.WorldWarpName == Main.worldName)
|
||||
{
|
||||
Warps.Remove(nametest);
|
||||
WriteSettings();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Vector2 FindWarp(string name)
|
||||
{
|
||||
foreach (Warp nametest in Warps)
|
||||
{
|
||||
if (name.ToLower() == nametest.WarpName.ToLower() && nametest.WorldWarpName == Main.worldName)
|
||||
{
|
||||
return nametest.WarpPos;
|
||||
}
|
||||
}
|
||||
return Vector2.Zero;
|
||||
}
|
||||
|
||||
public static void WriteSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
|
||||
xmlWriterSettings.Indent = true;
|
||||
xmlWriterSettings.NewLineChars = Environment.NewLine;
|
||||
|
||||
using (XmlWriter settingsw = XmlWriter.Create(FileTools.WarpsPath, xmlWriterSettings))
|
||||
{
|
||||
settingsw.WriteStartDocument();
|
||||
settingsw.WriteStartElement("Warps");
|
||||
|
||||
foreach (Warp warp in Warps)
|
||||
{
|
||||
settingsw.WriteStartElement("Warp");
|
||||
settingsw.WriteElementString("WarpName", warp.WarpName);
|
||||
settingsw.WriteElementString("X", warp.WarpPos.X.ToString());
|
||||
settingsw.WriteElementString("Y", warp.WarpPos.Y.ToString());
|
||||
settingsw.WriteElementString("WorldName", warp.WorldWarpName);
|
||||
settingsw.WriteEndElement();
|
||||
}
|
||||
|
||||
settingsw.WriteEndElement();
|
||||
settingsw.WriteEndDocument();
|
||||
}
|
||||
Log.Info("Wrote Warps");
|
||||
}
|
||||
catch
|
||||
{
|
||||
Log.Info("Could not write Warps");
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReadAllSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
|
||||
xmlReaderSettings.IgnoreWhitespace = true;
|
||||
|
||||
using (XmlReader settingr = XmlReader.Create(FileTools.WarpsPath, xmlReaderSettings))
|
||||
{
|
||||
while (settingr.Read())
|
||||
{
|
||||
if (settingr.IsStartElement())
|
||||
{
|
||||
switch (settingr.Name)
|
||||
{
|
||||
case "Warps":
|
||||
{
|
||||
break;
|
||||
}
|
||||
case "Warp":
|
||||
{
|
||||
if (settingr.Read())
|
||||
{
|
||||
string name = string.Empty;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
string worldname = string.Empty;
|
||||
|
||||
settingr.Read();
|
||||
if (settingr.Value != "" || settingr.Value != null)
|
||||
name = settingr.Value;
|
||||
else
|
||||
Log.Warn("Warp name is empty, This warp will not work");
|
||||
|
||||
settingr.Read();
|
||||
settingr.Read();
|
||||
settingr.Read();
|
||||
if (settingr.Value != "" || settingr.Value != null)
|
||||
Int32.TryParse(settingr.Value, out x);
|
||||
else
|
||||
Log.Warn("x for warp " + name + " is empty");
|
||||
|
||||
settingr.Read();
|
||||
settingr.Read();
|
||||
settingr.Read();
|
||||
if (settingr.Value != "" || settingr.Value != null)
|
||||
Int32.TryParse(settingr.Value, out y);
|
||||
else
|
||||
Log.Warn("y for warp " + name + " is empty");
|
||||
|
||||
settingr.Read();
|
||||
settingr.Read();
|
||||
settingr.Read();
|
||||
if (settingr.Value != "" || settingr.Value != null)
|
||||
worldname = settingr.Value;
|
||||
else
|
||||
Log.Warn("Worldname for warp " + name + " is empty");
|
||||
|
||||
AddWarp(x, y, name, worldname);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.Info("Read Warps");
|
||||
}
|
||||
catch
|
||||
{
|
||||
Log.Info("Could not read Warps");
|
||||
WriteSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Warp
|
||||
{
|
||||
public Vector2 WarpPos { get; set; }
|
||||
public string WarpName { get; set; }
|
||||
public string WorldWarpName { get; set; }
|
||||
|
||||
public Warp(Vector2 warppos, string name, string worldname)
|
||||
{
|
||||
WarpPos = warppos;
|
||||
WarpName = name;
|
||||
WorldWarpName = worldname;
|
||||
}
|
||||
|
||||
public Warp()
|
||||
{
|
||||
WarpPos = Vector2.Zero;
|
||||
WarpName = null;
|
||||
WorldWarpName = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
|
@ -93,8 +92,6 @@ namespace UnitTests
|
|||
/**
|
||||
* For now, this test is useless. Need to implement user groups so we can alter Canbuild permission.
|
||||
*/
|
||||
TSPlayer t = new TSPlayer(0);
|
||||
Assert.IsFalse( manager.CanBuild( 100,100,t) );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
|
|
|||
|
|
@ -67,10 +67,10 @@
|
|||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="TerrariaServerAPI, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<Reference Include="TerrariaServer, Version=0.0.0.0, Culture=neutral, processorArchitecture=x86">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\TerrariaServerBins\TerrariaServerAPI.dll</HintPath>
|
||||
<ExecutableExtension>.exe</ExecutableExtension>
|
||||
<HintPath>..\TerrariaServerBins\TerrariaServer.exe</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue