Merge branch 'general-devel' of github.com:NyxStudios/TShock into general-devel

This commit is contained in:
Tyler Watson 2015-09-12 18:08:31 +10:00
commit 049abd9146
4 changed files with 169 additions and 99 deletions

View file

@ -119,8 +119,8 @@ namespace TShockAPI
[Description("Mediumcore players ONLY. This means softcore players cannot join.")] [Description("Mediumcore players ONLY. This means softcore players cannot join.")]
public bool MediumcoreOnly; public bool MediumcoreOnly;
[Description("Kicks a mediumcore player on death.")]
/// <summary>KickOnMediumcoreDeath - Whether or not to kick mediumcore players on death.</summary> /// <summary>KickOnMediumcoreDeath - Whether or not to kick mediumcore players on death.</summary>
[Description("Kicks a mediumcore player on death.")]
public bool KickOnMediumcoreDeath; public bool KickOnMediumcoreDeath;
/// <summary>BanOnMediumcoreDeath - Whether or not to ban mediumcore players on death.</summary> /// <summary>BanOnMediumcoreDeath - Whether or not to ban mediumcore players on death.</summary>
@ -180,6 +180,9 @@ namespace TShockAPI
[Description("Force-disable printing logs to players with the log permission.")] [Description("Force-disable printing logs to players with the log permission.")]
public bool DisableSpewLogs = true; public bool DisableSpewLogs = true;
[Description("Prevents OnSecondUpdate checks from writing to the log file")]
public bool DisableSecondUpdateLogs = false;
[Description("Valid types are \"sha512\", \"sha256\", \"md5\", append with \"-xp\" for the xp supported algorithms.")] [Description("Valid types are \"sha512\", \"sha256\", \"md5\", append with \"-xp\" for the xp supported algorithms.")]
public string HashAlgorithm = "sha512"; public string HashAlgorithm = "sha512";

View file

@ -1331,7 +1331,7 @@ namespace TShockAPI
if (max > TShock.Config.MaxHP && !args.Player.Group.HasPermission(Permissions.ignorehp)) if (max > TShock.Config.MaxHP && !args.Player.Group.HasPermission(Permissions.ignorehp))
{ {
args.Player.Disable("Maximum HP beyond limit"); args.Player.Disable("Maximum HP beyond limit", DisableFlags.WriteToLogAndConsole);
return true; return true;
} }
@ -1360,7 +1360,7 @@ namespace TShockAPI
if (max > TShock.Config.MaxMP && !args.Player.Group.HasPermission(Permissions.ignoremp)) if (max > TShock.Config.MaxMP && !args.Player.Group.HasPermission(Permissions.ignoremp))
{ {
args.Player.Disable("Maximum MP beyond limit"); args.Player.Disable("Maximum MP beyond limit", DisableFlags.WriteToLogAndConsole);
return true; return true;
} }
@ -1648,7 +1648,8 @@ namespace TShockAPI
TileID.MinecartTrack, TileID.MinecartTrack,
TileID.WeaponsRack, TileID.WeaponsRack,
TileID.ItemFrame, TileID.ItemFrame,
TileID.LunarMonolith TileID.LunarMonolith,
TileID.TargetDummy
}; };
private static bool HandleSendTileSquare(GetDataHandlerArgs args) private static bool HandleSendTileSquare(GetDataHandlerArgs args)
@ -2099,14 +2100,14 @@ namespace TShockAPI
if (args.Player.TileKillThreshold >= TShock.Config.TileKillThreshold) if (args.Player.TileKillThreshold >= TShock.Config.TileKillThreshold)
{ {
args.Player.Disable("Reached TileKill threshold."); args.Player.Disable("Reached TileKill threshold.", DisableFlags.WriteToLogAndConsole);
args.Player.SendTileSquare(tileX, tileY, 4); args.Player.SendTileSquare(tileX, tileY, 4);
return true; return true;
} }
if (args.Player.TilePlaceThreshold >= TShock.Config.TilePlaceThreshold) if (args.Player.TilePlaceThreshold >= TShock.Config.TilePlaceThreshold)
{ {
args.Player.Disable("Reached TilePlace threshold."); args.Player.Disable("Reached TilePlace threshold.", DisableFlags.WriteToLogAndConsole);
args.Player.SendTileSquare(tileX, tileY, 4); args.Player.SendTileSquare(tileX, tileY, 4);
return true; return true;
} }
@ -2214,7 +2215,7 @@ namespace TShockAPI
if (args.Player.TilePlaceThreshold >= TShock.Config.TilePlaceThreshold) if (args.Player.TilePlaceThreshold >= TShock.Config.TilePlaceThreshold)
{ {
args.Player.Disable("Reached TilePlace threshold."); args.Player.Disable("Reached TilePlace threshold.", DisableFlags.WriteToLogAndConsole);
args.Player.SendTileSquare(x, y, 4); args.Player.SendTileSquare(x, y, 4);
return true; return true;
} }
@ -2443,7 +2444,7 @@ namespace TShockAPI
if (TShock.Itembans.ItemIsBanned(itemName, args.Player)) if (TShock.Itembans.ItemIsBanned(itemName, args.Player))
{ {
control[5] = false; control[5] = false;
args.Player.Disable("using a banned item ({0})".SFormat(itemName)); args.Player.Disable("using a banned item ({0})".SFormat(itemName), DisableFlags.WriteToLogAndConsole);
args.Player.SendErrorMessage("You cannot use {0} on this server. Your actions are being ignored.", itemName); args.Player.SendErrorMessage("You cannot use {0} on this server. Your actions are being ignored.", itemName);
} }
@ -2595,7 +2596,7 @@ namespace TShockAPI
if (TShock.ProjectileBans.ProjectileIsBanned(type, args.Player)) if (TShock.ProjectileBans.ProjectileIsBanned(type, args.Player))
{ {
args.Player.Disable("Player does not have permission to create that projectile.", true); args.Player.Disable("Player does not have permission to create that projectile.", DisableFlags.WriteToLogAndConsole);
args.Player.SendErrorMessage("You do not have permission to create that projectile."); args.Player.SendErrorMessage("You do not have permission to create that projectile.");
args.Player.RemoveProjectile(ident, owner); args.Player.RemoveProjectile(ident, owner);
return true; return true;
@ -2603,7 +2604,7 @@ namespace TShockAPI
if (dmg > TShock.Config.MaxProjDamage && !args.Player.Group.HasPermission(Permissions.ignoredamagecap)) if (dmg > TShock.Config.MaxProjDamage && !args.Player.Group.HasPermission(Permissions.ignoredamagecap))
{ {
args.Player.Disable(String.Format("Projectile damage is higher than {0}.", TShock.Config.MaxProjDamage)); args.Player.Disable(String.Format("Projectile damage is higher than {0}.", TShock.Config.MaxProjDamage), DisableFlags.WriteToLogAndConsole);
args.Player.RemoveProjectile(ident, owner); args.Player.RemoveProjectile(ident, owner);
return true; return true;
} }
@ -2633,7 +2634,7 @@ namespace TShockAPI
} }
else else
{ {
args.Player.Disable(String.Format("Does not have projectile permission to update projectile. ({0})", type)); args.Player.Disable(String.Format("Does not have projectile permission to update projectile. ({0})", type), DisableFlags.WriteToLogAndConsole);
args.Player.RemoveProjectile(ident, owner); args.Player.RemoveProjectile(ident, owner);
} }
return true; return true;
@ -2641,7 +2642,7 @@ namespace TShockAPI
if (args.Player.ProjectileThreshold >= TShock.Config.ProjectileThreshold) if (args.Player.ProjectileThreshold >= TShock.Config.ProjectileThreshold)
{ {
args.Player.Disable("Reached projectile update threshold."); args.Player.Disable("Reached projectile update threshold.", DisableFlags.WriteToLogAndConsole);
args.Player.RemoveProjectile(ident, owner); args.Player.RemoveProjectile(ident, owner);
return true; return true;
} }
@ -2708,7 +2709,7 @@ namespace TShockAPI
if (TShock.CheckProjectilePermission(args.Player, index, type) && type != 102 && type != 100 && !TShock.Config.IgnoreProjKill) if (TShock.CheckProjectilePermission(args.Player, index, type) && type != 102 && type != 100 && !TShock.Config.IgnoreProjKill)
{ {
args.Player.Disable("Does not have projectile permission to kill projectile."); args.Player.Disable("Does not have projectile permission to kill projectile.", DisableFlags.WriteToLogAndConsole);
args.Player.RemoveProjectile(ident, owner); args.Player.RemoveProjectile(ident, owner);
return true; return true;
} }
@ -2810,7 +2811,7 @@ namespace TShockAPI
if (args.Player.TileLiquidThreshold >= TShock.Config.TileLiquidThreshold) if (args.Player.TileLiquidThreshold >= TShock.Config.TileLiquidThreshold)
{ {
args.Player.Disable("Reached TileLiquid threshold."); args.Player.Disable("Reached TileLiquid threshold.", DisableFlags.WriteToLogAndConsole);
args.Player.SendTileSquare(tileX, tileY, 1); args.Player.SendTileSquare(tileX, tileY, 1);
return true; return true;
} }
@ -2847,7 +2848,7 @@ namespace TShockAPI
if (type == 1 && !(bucket == 2 || bucket == 0)) if (type == 1 && !(bucket == 2 || bucket == 0))
{ {
args.Player.SendErrorMessage("You do not have permission to perform this action."); args.Player.SendErrorMessage("You do not have permission to perform this action.");
args.Player.Disable("Spreading lava without holding a lava bucket"); args.Player.Disable("Spreading lava without holding a lava bucket", DisableFlags.WriteToLogAndConsole);
args.Player.SendTileSquare(tileX, tileY, 1); args.Player.SendTileSquare(tileX, tileY, 1);
return true; return true;
} }
@ -2855,7 +2856,7 @@ namespace TShockAPI
if (type == 1 && TShock.Itembans.ItemIsBanned("Lava Bucket", args.Player)) if (type == 1 && TShock.Itembans.ItemIsBanned("Lava Bucket", args.Player))
{ {
args.Player.SendErrorMessage("You do not have permission to perform this action."); args.Player.SendErrorMessage("You do not have permission to perform this action.");
args.Player.Disable("Using banned lava bucket without permissions"); args.Player.Disable("Using banned lava bucket without permissions", DisableFlags.WriteToLogAndConsole);
args.Player.SendTileSquare(tileX, tileY, 1); args.Player.SendTileSquare(tileX, tileY, 1);
return true; return true;
} }
@ -2863,7 +2864,7 @@ namespace TShockAPI
if (type == 0 && !(bucket == 1 || bucket == 0 || bucket == 4)) if (type == 0 && !(bucket == 1 || bucket == 0 || bucket == 4))
{ {
args.Player.SendErrorMessage("You do not have permission to perform this action."); args.Player.SendErrorMessage("You do not have permission to perform this action.");
args.Player.Disable("Spreading water without holding a water bucket"); args.Player.Disable("Spreading water without holding a water bucket", DisableFlags.WriteToLogAndConsole);
args.Player.SendTileSquare(tileX, tileY, 1); args.Player.SendTileSquare(tileX, tileY, 1);
return true; return true;
} }
@ -2871,7 +2872,7 @@ namespace TShockAPI
if (type == 0 && TShock.Itembans.ItemIsBanned("Water Bucket", args.Player)) if (type == 0 && TShock.Itembans.ItemIsBanned("Water Bucket", args.Player))
{ {
args.Player.SendErrorMessage("You do not have permission to perform this action."); args.Player.SendErrorMessage("You do not have permission to perform this action.");
args.Player.Disable("Using banned water bucket without permissions"); args.Player.Disable("Using banned water bucket without permissions", DisableFlags.WriteToLogAndConsole);
args.Player.SendTileSquare(tileX, tileY, 1); args.Player.SendTileSquare(tileX, tileY, 1);
return true; return true;
} }
@ -2879,7 +2880,7 @@ namespace TShockAPI
if (type == 2 && !(bucket == 3 || bucket == 0)) if (type == 2 && !(bucket == 3 || bucket == 0))
{ {
args.Player.SendErrorMessage("You do not have permission to perform this action."); args.Player.SendErrorMessage("You do not have permission to perform this action.");
args.Player.Disable("Spreading honey without holding a honey bucket"); args.Player.Disable("Spreading honey without holding a honey bucket", DisableFlags.WriteToLogAndConsole);
args.Player.SendTileSquare(tileX, tileY, 1); args.Player.SendTileSquare(tileX, tileY, 1);
return true; return true;
} }
@ -2887,7 +2888,7 @@ namespace TShockAPI
if (type == 2 && TShock.Itembans.ItemIsBanned("Honey Bucket", args.Player)) if (type == 2 && TShock.Itembans.ItemIsBanned("Honey Bucket", args.Player))
{ {
args.Player.SendErrorMessage("You do not have permission to perform this action."); args.Player.SendErrorMessage("You do not have permission to perform this action.");
args.Player.Disable("Using banned honey bucket without permissions"); args.Player.Disable("Using banned honey bucket without permissions", DisableFlags.WriteToLogAndConsole);
args.Player.SendTileSquare(tileX, tileY, 1); args.Player.SendTileSquare(tileX, tileY, 1);
return true; return true;
} }
@ -3328,7 +3329,7 @@ namespace TShockAPI
} }
else else
{ {
args.Player.Disable(String.Format("Player damage exceeded {0}.", TShock.Config.MaxDamage)); args.Player.Disable(String.Format("Player damage exceeded {0}.", TShock.Config.MaxDamage), DisableFlags.WriteToLogAndConsole);
} }
args.Player.SendData(PacketTypes.PlayerHp, "", id); args.Player.SendData(PacketTypes.PlayerHp, "", id);
args.Player.SendData(PacketTypes.PlayerUpdate, "", id); args.Player.SendData(PacketTypes.PlayerUpdate, "", id);
@ -3394,7 +3395,7 @@ namespace TShockAPI
} }
else else
{ {
args.Player.Disable(String.Format("NPC damage exceeded {0}.", TShock.Config.MaxDamage)); args.Player.Disable(String.Format("NPC damage exceeded {0}.", TShock.Config.MaxDamage), DisableFlags.WriteToLogAndConsole);
} }
args.Player.SendData(PacketTypes.NpcUpdate, "", id); args.Player.SendData(PacketTypes.NpcUpdate, "", id);
return true; return true;

View file

@ -31,6 +31,30 @@ using Timer = System.Timers.Timer;
namespace TShockAPI namespace TShockAPI
{ {
/// <summary>
/// Bitflags used with the <see cref="Disable(string, DisableFlags)"></see> method
/// </summary>
[Flags]
public enum DisableFlags
{
/// <summary>
/// Disable the player and leave no messages
/// </summary>
None,
/// <summary>
/// Write the Disable message to the console
/// </summary>
WriteToConsole,
/// <summary>
/// Write the Disable message to the log
/// </summary>
WriteToLog,
/// <summary>
/// Equivalent to WriteToConsole | WriteToLog
/// </summary>
WriteToLogAndConsole
}
public class TSPlayer public class TSPlayer
{ {
/// <summary> /// <summary>
@ -794,7 +818,25 @@ namespace TShockAPI
/// </summary> /// </summary>
/// <param name="reason">The reason why the player was disabled.</param> /// <param name="reason">The reason why the player was disabled.</param>
/// <param name="displayConsole">Whether or not to log this event to the console.</param> /// <param name="displayConsole">Whether or not to log this event to the console.</param>
[Obsolete("Use Disable(string, DisableFlags)")]
public virtual void Disable(string reason = "", bool displayConsole = true) public virtual void Disable(string reason = "", bool displayConsole = true)
{
if (displayConsole)
{
Disable(reason, DisableFlags.WriteToConsole);
}
else
{
Disable(reason, DisableFlags.WriteToLog);
}
}
/// <summary>
/// Disables the player for the given <paramref name="reason"/>
/// </summary>
/// <param name="reason">The reason why the player was disabled.</param>
/// <param name="flags">Flags to dictate where this event is logged to.</param>
public virtual void Disable(string reason = "", DisableFlags flags = DisableFlags.WriteToLog)
{ {
LastThreat = DateTime.UtcNow; LastThreat = DateTime.UtcNow;
SetBuff(BuffID.Frozen, 330, true); SetBuff(BuffID.Frozen, 330, true);
@ -810,14 +852,18 @@ namespace TShockAPI
{ {
if ((DateTime.UtcNow - LastDisableNotification).TotalMilliseconds > 5000) if ((DateTime.UtcNow - LastDisableNotification).TotalMilliseconds > 5000)
{ {
if (displayConsole) if (flags.HasFlag(DisableFlags.WriteToConsole))
{
if (flags.HasFlag(DisableFlags.WriteToLog))
{ {
TShock.Log.ConsoleInfo("Player {0} has been disabled for {1}.", Name, reason); TShock.Log.ConsoleInfo("Player {0} has been disabled for {1}.", Name, reason);
} }
else else
{ {
TShock.Log.Info("Player {0} has been disabled for {1}.", Name, reason); Server.SendInfoMessage("Player {0} has been disabled for {1}.", Name, reason);
} }
}
LastDisableNotification = DateTime.UtcNow; LastDisableNotification = DateTime.UtcNow;
} }
} }

View file

@ -854,6 +854,8 @@ namespace TShockAPI
/// <summary>OnSecondUpdate - Called effectively every second for all time based checks.</summary> /// <summary>OnSecondUpdate - Called effectively every second for all time based checks.</summary>
private void OnSecondUpdate() private void OnSecondUpdate()
{ {
DisableFlags flags = Config.DisableSecondUpdateLogs ? DisableFlags.WriteToConsole : DisableFlags.WriteToLogAndConsole;
if (Config.ForceTime != "normal") if (Config.ForceTime != "normal")
{ {
switch (Config.ForceTime) switch (Config.ForceTime)
@ -875,7 +877,7 @@ namespace TShockAPI
{ {
if (player.TileKillThreshold >= Config.TileKillThreshold) if (player.TileKillThreshold >= Config.TileKillThreshold)
{ {
player.Disable("Reached TileKill threshold."); player.Disable("Reached TileKill threshold.", flags);
TSPlayer.Server.RevertTiles(player.TilesDestroyed); TSPlayer.Server.RevertTiles(player.TilesDestroyed);
player.TilesDestroyed.Clear(); player.TilesDestroyed.Clear();
} }
@ -891,7 +893,7 @@ namespace TShockAPI
{ {
if (player.TilePlaceThreshold >= Config.TilePlaceThreshold) if (player.TilePlaceThreshold >= Config.TilePlaceThreshold)
{ {
player.Disable("Reached TilePlace threshold"); player.Disable("Reached TilePlace threshold", flags);
TSPlayer.Server.RevertTiles(player.TilesCreated); TSPlayer.Server.RevertTiles(player.TilesCreated);
player.TilesCreated.Clear(); player.TilesCreated.Clear();
} }
@ -932,7 +934,7 @@ namespace TShockAPI
if (player.TileLiquidThreshold >= Config.TileLiquidThreshold) if (player.TileLiquidThreshold >= Config.TileLiquidThreshold)
{ {
player.Disable("Reached TileLiquid threshold"); player.Disable("Reached TileLiquid threshold", flags);
} }
if (player.TileLiquidThreshold > 0) if (player.TileLiquidThreshold > 0)
{ {
@ -941,7 +943,7 @@ namespace TShockAPI
if (player.ProjectileThreshold >= Config.ProjectileThreshold) if (player.ProjectileThreshold >= Config.ProjectileThreshold)
{ {
player.Disable("Reached projectile threshold"); player.Disable("Reached projectile threshold", flags);
} }
if (player.ProjectileThreshold > 0) if (player.ProjectileThreshold > 0)
{ {
@ -950,7 +952,7 @@ namespace TShockAPI
if (player.PaintThreshold >= Config.TilePaintThreshold) if (player.PaintThreshold >= Config.TilePaintThreshold)
{ {
player.Disable("Reached paint threshold"); player.Disable("Reached paint threshold", flags);
} }
if (player.PaintThreshold > 0) if (player.PaintThreshold > 0)
{ {
@ -961,6 +963,21 @@ namespace TShockAPI
{ {
player.Spawn(); player.Spawn();
} }
if (Main.ServerSideCharacter && !player.IsLoggedIn)
{
if (CheckIgnores(player))
{
player.Disable("not being logged in while SSC is enabled", flags);
}
else if (Itembans.ItemIsBanned(player.TPlayer.inventory[player.TPlayer.selectedItem].name, player))
{
player.Disable($"holding banned item: {player.TPlayer.inventory[player.TPlayer.selectedItem].name}", flags);
player.SendErrorMessage($"You are holding a banned item: {player.TPlayer.inventory[player.TPlayer.selectedItem].name}");
}
}
else if (!Main.ServerSideCharacter || (Main.ServerSideCharacter && player.IsLoggedIn))
{
string check = "none"; string check = "none";
foreach (Item item in player.TPlayer.inventory) foreach (Item item in player.TPlayer.inventory)
{ {
@ -1028,13 +1045,16 @@ namespace TShockAPI
} }
} }
player.IgnoreActionsForDisabledArmor = check; player.IgnoreActionsForDisabledArmor = check;
if (CheckIgnores(player)) if (CheckIgnores(player))
{ {
player.Disable("check ignores failed in OnSecondUpdate()", false); player.Disable("check ignores failed in OnSecondUpdate()", flags);
} }
else if (Itembans.ItemIsBanned(player.TPlayer.inventory[player.TPlayer.selectedItem].name, player)) else if (Itembans.ItemIsBanned(player.TPlayer.inventory[player.TPlayer.selectedItem].name, player))
{ {
player.SetBuff(23, 120); //Cursed player.Disable($"holding banned item: {player.TPlayer.inventory[player.TPlayer.selectedItem].name}", flags);
player.SendErrorMessage($"You are holding a banned item: {player.TPlayer.inventory[player.TPlayer.selectedItem].name}");
}
} }
var oldRegion = player.CurrentRegion; var oldRegion = player.CurrentRegion;
@ -1044,12 +1064,12 @@ namespace TShockAPI
{ {
if (oldRegion != null) if (oldRegion != null)
{ {
Hooks.RegionHooks.OnRegionLeft(player, oldRegion); RegionHooks.OnRegionLeft(player, oldRegion);
} }
if (player.CurrentRegion != null) if (player.CurrentRegion != null)
{ {
Hooks.RegionHooks.OnRegionEntered(player, player.CurrentRegion); RegionHooks.OnRegionEntered(player, player.CurrentRegion);
} }
} }
} }