ReSharper redundant code cleanup

This commit is contained in:
Lucas Nicodemus 2011-12-30 14:32:05 -07:00
parent fd51214146
commit 1147788154
21 changed files with 148 additions and 150 deletions

View file

@ -15,10 +15,11 @@ 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.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Net;
@ -26,7 +27,6 @@ using System.Text;
using System.Threading;
using Terraria;
using TShockAPI.DB;
using Region = TShockAPI.DB.Region;
namespace TShockAPI
{
@ -641,12 +641,12 @@ namespace TShockAPI
#region Stupid commands
public static void ServerInfo(CommandArgs args)
{
args.Player.SendMessage("Memory usage: " + System.Diagnostics.Process.GetCurrentProcess().WorkingSet64);
args.Player.SendMessage("Allocated memory: " + System.Diagnostics.Process.GetCurrentProcess().VirtualMemorySize64);
args.Player.SendMessage("Total processor time: " + System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime);
args.Player.SendMessage("Ver: " + System.Environment.OSVersion);
args.Player.SendMessage("Proc count: " + System.Environment.ProcessorCount);
args.Player.SendMessage("Machine name: " + System.Environment.MachineName);
args.Player.SendMessage("Memory usage: " + Process.GetCurrentProcess().WorkingSet64);
args.Player.SendMessage("Allocated memory: " + Process.GetCurrentProcess().VirtualMemorySize64);
args.Player.SendMessage("Total processor time: " + Process.GetCurrentProcess().TotalProcessorTime);
args.Player.SendMessage("Ver: " + Environment.OSVersion);
args.Player.SendMessage("Proc count: " + Environment.ProcessorCount);
args.Player.SendMessage("Machine name: " + Environment.MachineName);
}
#endregion
@ -938,7 +938,7 @@ namespace TShockAPI
ThreadPool.QueueUserWorkItem(UpdateManager.CheckUpdate);
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
private static void UpdateNow(CommandArgs args)
{
Process TServer = Process.GetCurrentProcess();
@ -1103,7 +1103,7 @@ namespace TShockAPI
private static void WoF(CommandArgs args)
{
if (Main.wof >= 0 || (args.Player.Y / 16f < (float)(Main.maxTilesY - 205)))
if (Main.wof >= 0 || (args.Player.Y / 16f < (Main.maxTilesY - 205)))
{
args.Player.SendMessage("Can't spawn Wall of Flesh!", Color.Red);
return;
@ -2855,7 +2855,7 @@ namespace TShockAPI
count++;
}
}
args.Player.SendMessage("All " + count.ToString() + " items within a radius of " + radius.ToString() + " have been deleted.");
args.Player.SendMessage("All " + count + " items within a radius of " + radius + " have been deleted.");
}

View file

@ -142,16 +142,16 @@ namespace TShockAPI
public bool SaveWorldOnCrash = true;
[Description("This will announce a player's location on join")]
public bool EnableGeoIP = false;
public bool EnableGeoIP;
[Description("This will turn on a token requirement for the /status API endpoint.")]
public bool EnableTokenEndpointAuthentication = false;
public bool EnableTokenEndpointAuthentication;
[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;
public bool RestApiEnabled;
[Description("This is the port which the rest api will listen on.")]
public int RestApiPort = 7878;
@ -160,7 +160,7 @@ namespace TShockAPI
public bool DisableTombstones = true;
[Description("Displays a player's IP on join to everyone who has the log permission")]
public bool DisplayIPToAdmins = false;
public bool DisplayIPToAdmins;
[Description("Some tiles are 'fixed' by not letting TShock handle them. Disabling this may break certain asthetic tiles.")]
public bool EnableInsecureTileFixes = true;
@ -169,22 +169,22 @@ namespace TShockAPI
public bool KickProxyUsers = true;
[Description("Disables hardmode, can't never be activated. Overrides /starthardmode")]
public bool DisableHardmode = false;
public bool DisableHardmode;
[Description("Disables Dungeon Guardian from being spawned by player packets, this will instead force a respawn")]
public bool DisableDungeonGuardian = false;
public bool DisableDungeonGuardian;
[Description("Enable Server Side Inventory checks, EXPERIMENTAL")]
public bool ServerSideInventory = false;
public bool ServerSideInventory;
[Description("Disables reporting of playercount to the stat system.")]
public bool DisablePlayerCountReporting = false;
public bool DisablePlayerCountReporting;
[Description("Disables clown bomb projectiles from spawning")]
public bool DisableClownBombs = false;
public bool DisableClownBombs;
[Description("Disables snow ball projectiles from spawning")]
public bool DisableSnowBalls = false;
public bool DisableSnowBalls;
[Description("Change ingame chat format, {0} = Group Name, {1} = Group Prefix, {2} = Player Name, {3} = Group Suffix, {4} = Chat Message")]
public string ChatFormat = "{1}{2}{3}: {4}";
@ -205,10 +205,10 @@ namespace TShockAPI
public int ProjectileThreshold = 50;
[Description("Require all players to register or login before being allowed to play.")]
public bool RequireLogin = false;
public bool RequireLogin;
[Description("Disables Invisibility potions from being used in PvP (Note, they can use them on the client, but the effect isn't sent to the rest of the server)")]
public bool DisableInvisPvP = false;
public bool DisableInvisPvP;
[Description("The maximum distance players disabled for various reasons can move from")]
public int MaxRangeForDisabled = 10;
@ -217,13 +217,13 @@ namespace TShockAPI
public string ServerPassword = "";
[Description("Protect chests with region and build permissions")]
public bool RegionProtectChests = false;
public bool RegionProtectChests;
[Description("Disable users from being able to login with account password when joining")]
public bool DisableLoginBeforeJoin = false;
public bool DisableLoginBeforeJoin;
[Description("Allows users to register any username with /register")]
public bool AllowRegisterAnyUsername = false;
public bool AllowRegisterAnyUsername;
public static ConfigFile Read(string path)
{

View file

@ -57,7 +57,7 @@ namespace TShockAPI.DB
int count = 0;
foreach (SqlValue where in wheres)
{
sbwheres.Append(where.Name + "=" + where.Value.ToString());
sbwheres.Append(where.Name + "=" + where.Value);
if (count != wheres.Count - 1)
sbwheres.Append(" AND ");
count++;
@ -74,7 +74,7 @@ namespace TShockAPI.DB
int count = 0;
foreach (SqlValue value in values)
{
sbvalues.Append(value.Name + "=" + value.Value.ToString());
sbvalues.Append(value.Name + "=" + value.Value);
if (count != values.Count - 1)
sbvalues.Append(",");
count++;
@ -82,7 +82,7 @@ namespace TShockAPI.DB
count = 0;
foreach (SqlValue where in wheres)
{
sbwheres.Append(where.Name + "=" + where.Value.ToString());
sbwheres.Append(where.Name + "=" + where.Value);
if (count != wheres.Count - 1)
sbwheres.Append(" AND ");
count++;
@ -124,7 +124,7 @@ namespace TShockAPI.DB
foreach (SqlValue where in wheres)
{
sbwheres.Append(where.Name + "=" + where.Value.ToString());
sbwheres.Append(where.Name + "=" + where.Value);
if (count != wheres.Count - 1)
sbwheres.Append(" AND ");
count++;
@ -186,7 +186,7 @@ namespace TShockAPI.DB
int count = 0;
foreach (SqlValue where in wheres)
{
sbwheres.Append(where.Name + "=" + where.Value.ToString());
sbwheres.Append(where.Name + "=" + where.Value);
if (count != wheres.Count - 1)
sbwheres.Append(" AND ");
count++;
@ -203,7 +203,7 @@ namespace TShockAPI.DB
int count = 0;
foreach (SqlValue value in values)
{
sbvalues.Append(value.Name + "=" + value.Value.ToString());
sbvalues.Append(value.Name + "=" + value.Value);
if (count != values.Count - 1)
sbvalues.Append("AND");
count++;
@ -211,7 +211,7 @@ namespace TShockAPI.DB
count = 0;
foreach (SqlValue where in wheres)
{
sbwheres.Append(where.Name + "=" + where.Value.ToString());
sbwheres.Append(where.Name + "=" + where.Value);
if (count != wheres.Count - 1)
sbwheres.Append(" AND ");
count++;
@ -254,7 +254,7 @@ namespace TShockAPI.DB
foreach (SqlValue where in wheres)
{
sbwheres.Append(where.Name + "=" + where.Value.ToString());
sbwheres.Append(where.Name + "=" + where.Value);
if (count != wheres.Count - 1)
sbwheres.Append(" AND ");
count++;

View file

@ -20,7 +20,6 @@ using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Xml;

View file

@ -18,7 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Data;
using MySql.Data.MySqlClient;
using Terraria;

View file

@ -1,5 +1,5 @@
using System.Data;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Data;
namespace TShockAPI.DB
{

View file

@ -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.Diagnostics.CodeAnalysis;
using System.IO;
using System.Xml;
using MySql.Data.MySqlClient;
@ -31,7 +31,7 @@ namespace TShockAPI.DB
{
private IDbConnection database;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
public WarpManager(IDbConnection db)
{
database = db;

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics.CodeAnalysis;
namespace TShockAPI.DB
{
@ -14,7 +15,7 @@ namespace TShockAPI.DB
/// <param name="query">Query string with parameters as @0, @1, etc.</param>
/// <param name="args">Parameters to be put in the query</param>
/// <returns>Rows affected by query</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities")]
[SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities")]
public static int Query(this IDbConnection olddb, string query, params object[] args)
{
using (var db = olddb.CloneEx())
@ -37,7 +38,7 @@ namespace TShockAPI.DB
/// <param name="query">Query string with parameters as @0, @1, etc.</param>
/// <param name="args">Parameters to be put in the query</param>
/// <returns>Query result as IDataReader</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities")]
[SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities")]
public static QueryResult QueryReader(this IDbConnection olddb, string query, params object[] args)
{
var db = olddb.CloneEx();
@ -92,8 +93,8 @@ namespace TShockAPI.DB
return SqlType.Unknown;
}
static readonly Dictionary<Type, Func<IDataReader, int, object>> ReadFuncs = new Dictionary<Type, Func<IDataReader, int, object>>()
{
static readonly Dictionary<Type, Func<IDataReader, int, object>> ReadFuncs = new Dictionary<Type, Func<IDataReader, int, object>>
{
{typeof(bool), (s, i) => s.GetBoolean(i)},
{typeof(byte), (s, i) => s.GetByte(i)},
{typeof(Int16), (s, i) => s.GetInt16(i)},

View file

@ -20,6 +20,7 @@
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
// This code is based on MaxMind's original C# code, which was ported from Java.
// This version is very simplified and does not support a majority of features for speed.
@ -141,7 +142,7 @@ namespace MaxMind
public GeoIPCountry(string filename)
{
FileStream fs = new FileStream(filename, FileMode.Open);
_geodata = (Stream)fs;
_geodata = fs;
_close = true;
}
@ -192,7 +193,7 @@ namespace MaxMind
// Converts an IPv4 address into a long, for reading from geo database
long AddressToLong(IPAddress ip)
{
if (ip.AddressFamily != System.Net.Sockets.AddressFamily.InterNetwork)
if (ip.AddressFamily != AddressFamily.InterNetwork)
throw new InvalidOperationException("IP address is not IPv4");
long num = 0;

View file

@ -15,15 +15,14 @@ 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.IO;
using System.IO.Streams;
using System.Text;
using Terraria;
using TShockAPI.Net;
using System.IO.Streams;
namespace TShockAPI
{
@ -121,8 +120,8 @@ namespace TShockAPI
int plr = args.Data.ReadInt8();
int slot = args.Data.ReadInt8();
int stack = args.Data.ReadInt8();
short prefix = (short) args.Data.ReadInt8();
int type = (int) args.Data.ReadInt16();
short prefix = args.Data.ReadInt8();
int type = args.Data.ReadInt16();
if (plr != args.Player.Index)
{

View file

@ -1,4 +1,5 @@
using System;
using System.IO;
using System.IO.Streams;
namespace TShockAPI.Net
@ -9,7 +10,7 @@ namespace TShockAPI.Net
{
get { throw new NotImplementedException("Msg ID not implemented"); }
}
public void PackFull(System.IO.Stream stream)
public void PackFull(Stream stream)
{
long start = stream.Position;
stream.WriteInt32(1);
@ -21,12 +22,12 @@ namespace TShockAPI.Net
stream.Position = end;
}
public virtual void Unpack(System.IO.Stream stream)
public virtual void Unpack(Stream stream)
{
throw new NotImplementedException();
}
public virtual void Pack(System.IO.Stream stream)
public virtual void Pack(Stream stream)
{
throw new NotImplementedException();
}

View file

@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.IO;
using Terraria;
using System.IO.Streams;
using Terraria;
namespace TShockAPI.Net
{

View file

@ -18,9 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.IO;
using System.Text;
using System.IO.Streams;
using System.Text;
namespace TShockAPI.Net
{

View file

@ -4,9 +4,8 @@ using System.ComponentModel;
using System.IO;
using System.Net.Sockets;
using System.Text;
using Terraria;
using Hooks;
using Terraria;
namespace TShockAPI
{

View file

@ -19,12 +19,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Streams;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using Terraria;
using System.IO.Streams;
namespace TShockAPI
{

View file

@ -4,6 +4,7 @@ using System.Linq;
using HttpServer;
using Rests;
using Terraria;
using TShockAPI.DB;
namespace TShockAPI
{
@ -213,7 +214,7 @@ namespace TShockAPI
return returnBlock;
}
var ban = new DB.Ban();
var ban = new Ban();
if (type == "ip") ban = TShock.Bans.GetBanByIp(verbs["user"]);
else if (type == "name") ban = TShock.Bans.GetBanByName(verbs["user"]);
else
@ -253,7 +254,7 @@ namespace TShockAPI
return returnBlock;
}
var ban = new DB.Ban();
var ban = new Ban();
if (type == "ip") ban = TShock.Bans.GetBanByIp(verbs["user"]);
else if (type == "name") ban = TShock.Bans.GetBanByName(verbs["user"]);
else
@ -318,7 +319,7 @@ namespace TShockAPI
}
Main.bloodMoon = bloodmoon;
returnBlock.Add("status", "200");
returnBlock.Add("response", "Blood Moon has been set to " + bloodmoon.ToString());
returnBlock.Add("response", "Blood Moon has been set to " + bloodmoon);
return returnBlock;
}
#endregion
@ -328,16 +329,16 @@ namespace TShockAPI
{
var returnBlock = new Dictionary<string, object>();
var playerParam = parameters["player"];
var found = TShock.Utils.FindPlayer(playerParam.ToString());
var found = TShock.Utils.FindPlayer(playerParam);
if (found.Count == 0)
{
returnBlock.Add("status", "400");
returnBlock.Add("error", "Name " + playerParam.ToString() + " was not found");
returnBlock.Add("error", "Name " + playerParam + " was not found");
}
else if (found.Count > 1)
{
returnBlock.Add("status", "400");
returnBlock.Add("error", "Name " + playerParam.ToString() + " matches " + playerParam.Count().ToString() + " players");
returnBlock.Add("error", "Name " + playerParam + " matches " + playerParam.Count() + " players");
}
else if (found.Count == 1)
{
@ -347,7 +348,7 @@ namespace TShockAPI
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());
returnBlock.Add("position", player.TileX + "," + player.TileY);
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));
@ -358,22 +359,22 @@ namespace TShockAPI
{
var returnBlock = new Dictionary<string, object>();
var playerParam = parameters["player"];
var found = TShock.Utils.FindPlayer(playerParam.ToString());
var found = TShock.Utils.FindPlayer(playerParam);
var reason = verbs["reason"];
if (found.Count == 0)
{
returnBlock.Add("status", "400");
returnBlock.Add("error", "Name " + playerParam.ToString() + " was not found");
returnBlock.Add("error", "Name " + playerParam + " was not found");
}
else if (found.Count > 1)
{
returnBlock.Add("status", "400");
returnBlock.Add("error", "Name " + playerParam.ToString() + " matches " + playerParam.Count().ToString() + " players");
returnBlock.Add("error", "Name " + playerParam + " matches " + playerParam.Count() + " players");
}
else if (found.Count == 1)
{
var player = found[0];
TShock.Utils.ForceKick(player, reason == null ? "Kicked via web" : reason.ToString());
TShock.Utils.ForceKick(player, reason == null ? "Kicked via web" : reason);
returnBlock.Add("status", "200");
returnBlock.Add("response", "Player " + player.Name + " was kicked");
}
@ -383,23 +384,23 @@ namespace TShockAPI
{
var returnBlock = new Dictionary<string, object>();
var playerParam = parameters["player"];
var found = TShock.Utils.FindPlayer(playerParam.ToString());
var found = TShock.Utils.FindPlayer(playerParam);
var reason = verbs["reason"];
if (found.Count == 0)
{
returnBlock.Add("status", "400");
returnBlock.Add("error", "Name " + playerParam.ToString() + " was not found");
returnBlock.Add("error", "Name " + playerParam + " was not found");
}
else if (found.Count > 1)
{
returnBlock.Add("status", "400");
returnBlock.Add("error", "Name " + playerParam.ToString() + " matches " + playerParam.Count().ToString() + " players");
returnBlock.Add("error", "Name " + playerParam + " matches " + playerParam.Count() + " players");
}
else if (found.Count == 1)
{
var player = found[0];
TShock.Bans.AddBan(player.IP, player.Name, reason == null ? "Banned via web" : reason.ToString());
TShock.Utils.ForceKick(player, reason == null ? "Banned via web" : reason.ToString());
TShock.Bans.AddBan(player.IP, player.Name, reason == null ? "Banned via web" : reason);
TShock.Utils.ForceKick(player, reason == null ? "Banned via web" : reason);
returnBlock.Add("status", "200");
returnBlock.Add("response", "Player " + player.Name + " was banned");
}

View file

@ -57,11 +57,11 @@ namespace TShockAPI
string response;
if (TShock.Config.DisablePlayerCountReporting)
{
response = client.DownloadString("http://tshock.co/tickto.php?do=log&fp=" + fp + "&ver=" + TShock.VersionNum + "&os=" + System.Environment.OSVersion.ToString() + "&mono=" + Main.runningMono + "&port=" + Netplay.serverPort + "&plcount=0");
response = client.DownloadString("http://tshock.co/tickto.php?do=log&fp=" + fp + "&ver=" + TShock.VersionNum + "&os=" + Environment.OSVersion + "&mono=" + Main.runningMono + "&port=" + Netplay.serverPort + "&plcount=0");
}
else
{
response = client.DownloadString("http://tshock.co/tickto.php?do=log&fp=" + fp + "&ver=" + TShock.VersionNum + "&os=" + System.Environment.OSVersion.ToString() + "&mono=" + Main.runningMono + "&port=" + Netplay.serverPort + "&plcount=" + TShock.Utils.ActivePlayers());
response = client.DownloadString("http://tshock.co/tickto.php?do=log&fp=" + fp + "&ver=" + TShock.VersionNum + "&os=" + Environment.OSVersion + "&mono=" + Main.runningMono + "&port=" + Netplay.serverPort + "&plcount=" + TShock.Utils.ActivePlayers());
}
Log.ConsoleInfo("Stat Tracker: " + response + "\n");
}

View file

@ -15,13 +15,12 @@ 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.IO;
using System.Threading;
using Terraria;
using TShockAPI.Net;
namespace TShockAPI
@ -60,21 +59,21 @@ namespace TShockAPI
public int UserID = -1;
public bool HasBeenNaggedAboutLoggingIn;
public bool TPAllow = true;
public bool mute = false;
public bool TpLock = false;
public bool mute;
public bool TpLock;
Player FakePlayer;
public bool RequestedSection = false;
public bool RequestedSection;
public DateTime LastDeath { get; set; }
public bool Dead = false;
public bool Dead;
public string Country = "??";
public int Difficulty;
private string CacheIP;
public string IgnoreActionsForInventory = "none";
public string IgnoreActionsForCheating = "none";
public string IgnoreActionsForDisabledArmor = "none";
public bool IgnoreActionsForClearingTrashCan = false;
public bool IgnoreActionsForClearingTrashCan;
public PlayerData PlayerData;
public bool RequiresPassword = false;
public bool RequiresPassword;
public bool RealPlayer
{
@ -266,8 +265,8 @@ namespace TShockAPI
{
using (var ms = new MemoryStream())
{
var msg = new SpawnMsg()
{
var msg = new SpawnMsg
{
PlayerIndex = (byte)Index,
TileX = tilex,
TileY = tiley
@ -281,8 +280,8 @@ namespace TShockAPI
{
using (var ms = new MemoryStream())
{
var msg = new ProjectileRemoveMsg()
{
var msg = new ProjectileRemoveMsg
{
Index = (short)index,
Owner = (byte)owner
};
@ -296,7 +295,7 @@ namespace TShockAPI
try
{
int num = (size - 1) / 2;
SendData(PacketTypes.TileSendSquare, "", size, (float)(x - num), (float)(y - num));
SendData(PacketTypes.TileSendSquare, "", size, (x - num), (y - num));
return true;
}
catch (Exception ex)
@ -372,7 +371,7 @@ namespace TShockAPI
if ((DateTime.UtcNow - LastThreat).TotalMilliseconds < 5000 && !bypass)
return;
SendData(PacketTypes.PlayerAddBuff, number: Index, number2: (float)type, number3: (float)time);
SendData(PacketTypes.PlayerAddBuff, number: Index, number2: type, number3: time);
}
//Todo: Separate this into a few functions. SendTo, SendToAll, etc
@ -476,7 +475,7 @@ namespace TShockAPI
public NetItem[] inventory = new NetItem[NetItem.maxNetInventory];
public int maxHealth = 100;
//public int maxMana = 100;
public bool exists = false;
public bool exists;
public PlayerData(TSPlayer player)
{
@ -571,14 +570,14 @@ namespace TShockAPI
public class NetItem
{
public static int maxNetInventory = 59;
public int netID = 0;
public int stack = 0;
public int prefix = 0;
public int netID;
public int stack;
public int prefix;
public static string ToString(NetItem[] inventory)
{
string inventoryString = "";
for (int i = 0; i < NetItem.maxNetInventory; i++)
for (int i = 0; i < maxNetInventory; i++)
{
if (i != 0)
inventoryString += "~";
@ -598,9 +597,9 @@ namespace TShockAPI
public static NetItem[] Parse(string data)
{
NetItem[] inventory = new NetItem[NetItem.maxNetInventory];
NetItem[] inventory = new NetItem[maxNetInventory];
int i;
for (i = 0; i < NetItem.maxNetInventory; i++)
for (i = 0; i < maxNetInventory; i++)
{
inventory[i] = new NetItem();
}

View file

@ -17,8 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* TShock wouldn't be possible without:
* Github
* Microsoft Visual Studio 2010
* Adrenic
* Microsoft Visual Studio 2011
* And you, for your continued support and devotion to the evolution of TShock
* Kerplunc Gaming
* TerrariaGSP
@ -29,12 +28,14 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Net;
using System.Reflection;
using System.Threading;
using Mono.Data.Sqlite;
using Hooks;
using MaxMind;
using Mono.Data.Sqlite;
using MySql.Data.MySqlClient;
using Rests;
using Terraria;
@ -65,7 +66,7 @@ namespace TShockAPI
public static IDbConnection DB;
public static bool OverridePort;
public static PacketBufferer PacketBuffer;
public static MaxMind.GeoIPCountry Geo;
public static GeoIPCountry Geo;
public static SecureRest RestApi;
public static RestManager RestManager;
public static Utils Utils = new Utils();
@ -105,7 +106,7 @@ namespace TShockAPI
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")]
[SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")]
public override void Initialize()
{
HandleCommandLine(Environment.GetCommandLineArgs());
@ -185,7 +186,7 @@ namespace TShockAPI
var geoippath = Path.Combine(SavePath, "GeoIP.dat");
if (Config.EnableGeoIP && File.Exists(geoippath))
Geo = new MaxMind.GeoIPCountry(geoippath);
Geo = new GeoIPCountry(geoippath);
Console.Title = string.Format("TerrariaShock Version {0} ({1})", Version, VersionCodename);
Log.ConsoleInfo(string.Format("TerrariaShock Version {0} ({1}) now running.", Version, VersionCodename));
@ -230,18 +231,18 @@ namespace TShockAPI
RestObject RestApi_Verify(string username, string password)
{
var userAccount = TShock.Users.GetUserByName(username);
var userAccount = Users.GetUserByName(username);
if (userAccount == null)
{
return new RestObject("401") { Error = "Invalid username/password combination provided. Please re-submit your query with a correct pair." };
}
if (TShock.Utils.HashPassword(password).ToUpper() != userAccount.Password.ToUpper())
if (Utils.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 (!TShock.Utils.GetGroup(userAccount.Group).HasPermission("api") && userAccount.Group != "superadmin")
if (!Utils.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)" };
}
@ -249,7 +250,7 @@ namespace TShockAPI
return new RestObject("200") { Response = "Successful login" }; //Maybe return some user info too?
}
protected override void Dispose(bool disposing)
protected override void Dispose(bool disposing)
{
if (disposing)
{
@ -453,12 +454,12 @@ namespace TShockAPI
if ((DateTime.UtcNow - LastSave).TotalMinutes >= 15)
{
foreach (TSPlayer player in TShock.Players)
foreach (TSPlayer player in Players)
{
// prevent null point exceptions
if (player != null && player.IsLoggedIn)
{
TShock.InventoryDB.InsertPlayerData(player);
InventoryDB.InsertPlayerData(player);
}
}
LastSave = DateTime.UtcNow;
@ -543,7 +544,7 @@ namespace TShockAPI
check = "none";
foreach (Item item in player.TPlayer.armor)
{
if (!player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned(item.name, player))
if (!player.Group.HasPermission(Permissions.usebanneditem) && Itembans.ItemIsBanned(item.name, player))
{
player.SetBuff(30, 120); //Bleeding
player.SetBuff(36, 120); //Broken Armor
@ -557,7 +558,7 @@ namespace TShockAPI
player.SetBuff(32, 120); //Slow
player.SetBuff(23, 120); //Cursed
}
else if(!player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned(player.TPlayer.inventory[player.TPlayer.selectedItem].name, player))
else if(!player.Group.HasPermission(Permissions.usebanneditem) && Itembans.ItemIsBanned(player.TPlayer.inventory[player.TPlayer.selectedItem].name, player))
{
player.SetBuff(23, 120); //Cursed
}
@ -578,9 +579,9 @@ namespace TShockAPI
player.Group = Users.GetGroupForIP(player.IP);
}
if (TShock.Utils.ActivePlayers() + 1 > Config.MaxSlots + 20)
if (Utils.ActivePlayers() + 1 > Config.MaxSlots + 20)
{
TShock.Utils.ForceKick(player, Config.ServerFullNoReservedReason);
Utils.ForceKick(player, Config.ServerFullNoReservedReason);
handler.Handled = true;
return;
}
@ -592,27 +593,27 @@ namespace TShockAPI
if (ban != null)
{
TShock.Utils.ForceKick(player, string.Format("You are banned: {0}", ban.Reason));
Utils.ForceKick(player, string.Format("You are banned: {0}", ban.Reason));
handler.Handled = true;
return;
}
if (!FileTools.OnWhitelist(player.IP))
{
TShock.Utils.ForceKick(player, "Not on whitelist.");
Utils.ForceKick(player, "Not on whitelist.");
handler.Handled = true;
return;
}
if (TShock.Geo != null)
if (Geo != null)
{
var code = TShock.Geo.TryGetCountryCode(IPAddress.Parse(player.IP));
player.Country = code == null ? "N/A" : MaxMind.GeoIPCountry.GetCountryNameByCode(code);
var code = Geo.TryGetCountryCode(IPAddress.Parse(player.IP));
player.Country = code == null ? "N/A" : GeoIPCountry.GetCountryNameByCode(code);
if (code == "A1")
{
if (TShock.Config.KickProxyUsers)
if (Config.KickProxyUsers)
{
TShock.Utils.ForceKick(player, "Proxies are not allowed");
Utils.ForceKick(player, "Proxies are not allowed");
handler.Handled = true;
return;
}
@ -637,7 +638,7 @@ namespace TShockAPI
if (ban != null)
{
TShock.Utils.ForceKick(player, string.Format("You are banned: {0}", ban.Reason));
Utils.ForceKick(player, string.Format("You are banned: {0}", ban.Reason));
handler.Handled = true;
return;
}
@ -650,7 +651,7 @@ namespace TShockAPI
if (tsplr != null && tsplr.ReceivedInfo)
{
TShock.Utils.Broadcast(tsplr.Name + " has left", Color.Yellow);
Utils.Broadcast(tsplr.Name + " has left", Color.Yellow);
Log.Info(string.Format("{0} left.", tsplr.Name));
if (tsplr.IsLoggedIn)
@ -678,7 +679,7 @@ namespace TShockAPI
return;
}
if (!TShock.Utils.ValidString(text))
if (!Utils.ValidString(text))
{
e.Handled = true;
return;
@ -698,7 +699,7 @@ namespace TShockAPI
}
else if (!tsplr.mute)
{
TShock.Utils.Broadcast(String.Format(TShock.Config.ChatFormat, tsplr.Group.Name, tsplr.Group.Prefix, tsplr.Name, tsplr.Group.Suffix, text), tsplr.Group.R, tsplr.Group.G, tsplr.Group.B);
Utils.Broadcast(String.Format(Config.ChatFormat, tsplr.Group.Name, tsplr.Group.Prefix, tsplr.Name, tsplr.Group.Suffix, text), tsplr.Group.R, tsplr.Group.G, tsplr.Group.B);
e.Handled = true;
}
else if (tsplr.mute)
@ -815,7 +816,7 @@ namespace TShockAPI
return;
}
TShock.Utils.ShowFileToUser(player, "motd.txt");
Utils.ShowFileToUser(player, "motd.txt");
if (Config.PvPMode == "always" && !player.TPlayer.hostile)
{
@ -879,7 +880,7 @@ namespace TShockAPI
void OnNpcSetDefaults(SetDefaultsEventArgs<NPC, int> e)
{
if (TShock.Itembans.ItemIsBanned(e.Object.name, null) )
if (Itembans.ItemIsBanned(e.Object.name, null) )
{
e.Object.SetDefaults(0);
}
@ -959,8 +960,8 @@ namespace TShockAPI
private void OnSaveWorld(bool resettime, HandledEventArgs e)
{
TShock.Utils.Broadcast("Saving world. Momentary lag might result from this.", Color.Red);
Thread SaveWorld = new Thread(TShock.Utils.SaveWorld);
Utils.Broadcast("Saving world. Momentary lag might result from this.", Color.Red);
Thread SaveWorld = new Thread(Utils.SaveWorld);
SaveWorld.Start();
e.Handled = true;
}
@ -984,7 +985,7 @@ namespace TShockAPI
}
else
{
Main.invasionSize = 100 + (Config.InvasionMultiplier * TShock.Utils.ActivePlayers());
Main.invasionSize = 100 + (Config.InvasionMultiplier * Utils.ActivePlayers());
}
Main.invasionWarn = 0;
@ -1010,22 +1011,22 @@ namespace TShockAPI
switch (random)
{
case 0:
TShock.Utils.Broadcast(string.Format("You call that a lot? {0} goblins killed!", KillCount));
Utils.Broadcast(string.Format("You call that a lot? {0} goblins killed!", KillCount));
break;
case 1:
TShock.Utils.Broadcast(string.Format("Fatality! {0} goblins killed!", KillCount));
Utils.Broadcast(string.Format("Fatality! {0} goblins killed!", KillCount));
break;
case 2:
TShock.Utils.Broadcast(string.Format("Number of 'noobs' killed to date: {0}", KillCount));
Utils.Broadcast(string.Format("Number of 'noobs' killed to date: {0}", KillCount));
break;
case 3:
TShock.Utils.Broadcast(string.Format("Duke Nukem would be proud. {0} goblins killed.", KillCount));
Utils.Broadcast(string.Format("Duke Nukem would be proud. {0} goblins killed.", KillCount));
break;
case 4:
TShock.Utils.Broadcast(string.Format("You call that a lot? {0} goblins killed!", KillCount));
Utils.Broadcast(string.Format("You call that a lot? {0} goblins killed!", KillCount));
break;
case 5:
TShock.Utils.Broadcast(string.Format("{0} copies of Call of Duty smashed.", KillCount));
Utils.Broadcast(string.Format("{0} copies of Call of Duty smashed.", KillCount));
break;
}
}
@ -1038,12 +1039,12 @@ namespace TShockAPI
return true;
}
if (type == 17 && !player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned("Dirt Rod", player)) //Dirt Rod Projectile
if (type == 17 && !player.Group.HasPermission(Permissions.usebanneditem) && Itembans.ItemIsBanned("Dirt Rod", player)) //Dirt Rod Projectile
{
return true;
}
if ((type == 42 || type == 65 || type == 68) && !player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned("Sandgun", player)) //Sandgun Projectiles
if ((type == 42 || type == 65 || type == 68) && !player.Group.HasPermission(Permissions.usebanneditem) && Itembans.ItemIsBanned("Sandgun", player)) //Sandgun Projectiles
{
return true;
}
@ -1051,7 +1052,7 @@ namespace TShockAPI
Projectile proj = new Projectile();
proj.SetDefaults(type);
if (!player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned(proj.name, player))
if (!player.Group.HasPermission(Permissions.usebanneditem) && Itembans.ItemIsBanned(proj.name, player))
{
return true;
}
@ -1066,7 +1067,7 @@ namespace TShockAPI
public static bool CheckRangePermission(TSPlayer player, int x, int y, int range = 32)
{
if (TShock.Config.RangeChecks && ((Math.Abs(player.TileX - x) > 32) || (Math.Abs(player.TileY - y) > 32)))
if (Config.RangeChecks && ((Math.Abs(player.TileX - x) > 32) || (Math.Abs(player.TileY - y) > 32)))
{
return true;
}
@ -1080,12 +1081,12 @@ namespace TShockAPI
player.SendMessage("You do not have permission to build!", Color.Red);
return true;
}
if (!player.Group.HasPermission(Permissions.editspawn) && !TShock.Regions.CanBuild(tileX, tileY, player) && TShock.Regions.InArea(tileX, tileY))
if (!player.Group.HasPermission(Permissions.editspawn) && !Regions.CanBuild(tileX, tileY, player) && Regions.InArea(tileX, tileY))
{
player.SendMessage("Region protected from changes.", Color.Red);
return true;
}
if (TShock.Config.DisableBuild)
if (Config.DisableBuild)
{
if (!player.Group.HasPermission(Permissions.editspawn))
{
@ -1093,11 +1094,11 @@ namespace TShockAPI
return true;
}
}
if (TShock.Config.SpawnProtection)
if (Config.SpawnProtection)
{
if (!player.Group.HasPermission(Permissions.editspawn))
{
var flag = TShock.CheckSpawn(tileX, tileY);
var flag = CheckSpawn(tileX, tileY);
if (flag)
{
player.SendMessage("Spawn protected from changes.", Color.Red);
@ -1119,7 +1120,7 @@ namespace TShockAPI
float num2 = value1.X - value2.X;
float num = value1.Y - value2.Y;
float num3 = (num2 * num2) + (num * num);
return (float)Math.Sqrt((double)num3);
return (float)Math.Sqrt(num3);
}
public static bool HackedHealth(TSPlayer player)
@ -1300,7 +1301,7 @@ namespace TShockAPI
RconHandler.Password = file.RconPassword;
RconHandler.ListenPort = file.RconPort;
TShock.Utils.HashAlgo = file.HashAlgorithm;
Utils.HashAlgo = file.HashAlgorithm;
}
}
}

View file

@ -15,9 +15,9 @@ 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.Net;
using System.Threading;
using Newtonsoft.Json;

View file

@ -15,9 +15,9 @@ 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.IO;
using System.Linq;
using System.Net;
@ -26,7 +26,6 @@ using System.Security.Cryptography;
using System.Text;
using Terraria;
namespace TShockAPI
{
public class Utils