ReSharper redundant code cleanup
This commit is contained in:
parent
fd51214146
commit
1147788154
21 changed files with 148 additions and 150 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue