Merge pull request #1801 from Pryaxis/h/betterlogs

Improve logging of anticheat/antihack checks
This commit is contained in:
Chris 2020-05-20 15:40:39 +09:30 committed by GitHub
commit 1ae88c9339
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 93 additions and 16 deletions

View file

@ -3,6 +3,7 @@
This is the rolling changelog for TShock for Terraria. Use past tense when adding new entries; sign your name off when you add or change something. This should primarily be things like user changes, not necessarily codebase changes unless it's really relevant or large. This is the rolling changelog for TShock for Terraria. Use past tense when adding new entries; sign your name off when you add or change something. This should primarily be things like user changes, not necessarily codebase changes unless it's really relevant or large.
## Upcoming changes ## Upcoming changes
* Debug logging now provides ConsoleDebug and ILog has been updated to support the concept of debug logs. Debug logs are now controlled by `config.json` instead of by preprocessor debug flag. (@hakusaro)
* Removed `/confuse` command and Terraria player data resync from @Zidonuke. (@hakusaro) * Removed `/confuse` command and Terraria player data resync from @Zidonuke. (@hakusaro)
## TShock 4.4.0 (Pre-release 3) ## TShock 4.4.0 (Pre-release 3)

View file

@ -69,11 +69,12 @@ namespace TShockAPI
GetDataHandlers.PlayerDamage += OnPlayerDamage; GetDataHandlers.PlayerDamage += OnPlayerDamage;
GetDataHandlers.KillMe += OnKillMe; GetDataHandlers.KillMe += OnKillMe;
} }
internal void OnGetSection(object sender, GetDataHandlers.GetSectionEventArgs args) internal void OnGetSection(object sender, GetDataHandlers.GetSectionEventArgs args)
{ {
if (args.Player.RequestedSection) if (args.Player.RequestedSection)
{ {
TShock.Log.ConsoleDebug("Bouncer / OnGetSection rejected GetSection packet from {0}", args.Player.Name);
args.Handled = true; args.Handled = true;
return; return;
} }
@ -81,6 +82,7 @@ namespace TShockAPI
if (String.IsNullOrEmpty(args.Player.Name)) if (String.IsNullOrEmpty(args.Player.Name))
{ {
TShock.Log.ConsoleDebug("Bouncer / OnGetSection rejected empty player name.");
args.Player.Kick("Your client sent a blank character name.", true, true); args.Player.Kick("Your client sent a blank character name.", true, true);
args.Handled = true; args.Handled = true;
return; return;
@ -106,18 +108,21 @@ namespace TShockAPI
if (pos.X < 0 || pos.Y < 0 || pos.X >= Main.maxTilesX * 16 - 16 || pos.Y >= Main.maxTilesY * 16 - 16) if (pos.X < 0 || pos.Y < 0 || pos.X >= Main.maxTilesX * 16 - 16 || pos.Y >= Main.maxTilesY * 16 - 16)
{ {
TShock.Log.ConsoleDebug("Bouncer / OnPlayerUpdate rejected from (position check) {0}", args.Player.Name);
args.Handled = true; args.Handled = true;
return; return;
} }
if (item < 0 || item >= args.Player.TPlayer.inventory.Length) if (item < 0 || item >= args.Player.TPlayer.inventory.Length)
{ {
TShock.Log.ConsoleDebug("Bouncer / OnPlayerUpdate rejected from (inventory length) {0}", args.Player.Name);
args.Handled = true; args.Handled = true;
return; return;
} }
if (args.Player.LastNetPosition == Vector2.Zero) if (args.Player.LastNetPosition == Vector2.Zero)
{ {
TShock.Log.ConsoleDebug("Bouncer / OnPlayerUpdate rejected from (last network position) {0}", args.Player.Name);
args.Handled = true; args.Handled = true;
return; return;
} }
@ -161,9 +166,11 @@ namespace TShockAPI
{ {
args.Player.Spawn(); args.Player.Spawn();
} }
TShock.Log.ConsoleDebug("Bouncer / OnPlayerUpdate rejected from (??) {0}", args.Player.Name);
args.Handled = true; args.Handled = true;
return; return;
} }
TShock.Log.ConsoleDebug("Bouncer / OnPlayerUpdate rejected from (below ??) {0}", args.Player.Name);
args.Handled = true; args.Handled = true;
return; return;
} }
@ -171,6 +178,7 @@ namespace TShockAPI
// Corpses don't move // Corpses don't move
if (args.Player.Dead) if (args.Player.Dead)
{ {
TShock.Log.ConsoleDebug("Bouncer / OnPlayerUpdate rejected from (corpses don't move) {0}", args.Player.Name);
args.Handled = true; args.Handled = true;
return; return;
} }
@ -196,6 +204,7 @@ namespace TShockAPI
{ {
if (editData < 0) if (editData < 0)
{ {
TShock.Log.ConsoleDebug("Bouncer / OnTileEdit rejected from (editData check) {0}", args.Player.Name);
args.Player.SendTileSquare(tileX, tileY, 4); args.Player.SendTileSquare(tileX, tileY, 4);
args.Handled = true; args.Handled = true;
return; return;
@ -203,6 +212,7 @@ namespace TShockAPI
if (!TShock.Utils.TilePlacementValid(tileX, tileY)) if (!TShock.Utils.TilePlacementValid(tileX, tileY))
{ {
TShock.Log.ConsoleDebug("Bouncer / OnTileEdit rejected from (tile placement valid) {0}", args.Player.Name);
args.Player.SendTileSquare(tileX, tileY, 1); args.Player.SendTileSquare(tileX, tileY, 1);
args.Handled = true; args.Handled = true;
return; return;
@ -210,12 +220,14 @@ namespace TShockAPI
if (action == EditAction.KillTile && Main.tile[tileX, tileY].type == TileID.MagicalIceBlock) if (action == EditAction.KillTile && Main.tile[tileX, tileY].type == TileID.MagicalIceBlock)
{ {
TShock.Log.ConsoleDebug("Bouncer / OnTileEdit super accepted from (ice block) {0}", args.Player.Name);
args.Handled = false; args.Handled = false;
return; return;
} }
if (args.Player.Dead && TShock.Config.PreventDeadModification) if (args.Player.Dead && TShock.Config.PreventDeadModification)
{ {
TShock.Log.ConsoleDebug("Bouncer / OnTileEdit rejected from (pdm) {0}", args.Player.Name);
args.Player.SendTileSquare(tileX, tileY, 4); args.Player.SendTileSquare(tileX, tileY, 4);
args.Handled = true; args.Handled = true;
return; return;
@ -229,6 +241,7 @@ namespace TShockAPI
{ {
if (TShock.TileBans.TileIsBanned(editData, args.Player)) if (TShock.TileBans.TileIsBanned(editData, args.Player))
{ {
TShock.Log.ConsoleDebug("Bouncer / OnTileEdit rejected from (tb) {0}", args.Player.Name);
args.Player.SendTileSquare(tileX, tileY, 1); args.Player.SendTileSquare(tileX, tileY, 1);
args.Player.SendErrorMessage("You do not have permission to place this tile."); args.Player.SendErrorMessage("You do not have permission to place this tile.");
args.Handled = true; args.Handled = true;
@ -243,6 +256,7 @@ namespace TShockAPI
// If the tile is an axe tile and they aren't selecting an axe, they're hacking. // If the tile is an axe tile and they aren't selecting an axe, they're hacking.
if (Main.tileAxe[tile.type] && ((args.Player.TPlayer.mount.Type != 8 && selectedItem.axe == 0) && !ItemID.Sets.Explosives[selectedItem.netID] && args.Player.RecentFuse == 0)) if (Main.tileAxe[tile.type] && ((args.Player.TPlayer.mount.Type != 8 && selectedItem.axe == 0) && !ItemID.Sets.Explosives[selectedItem.netID] && args.Player.RecentFuse == 0))
{ {
TShock.Log.ConsoleDebug("Bouncer / OnTileEdit rejected from (axe) {0}", args.Player.Name);
args.Player.SendTileSquare(tileX, tileY, 4); args.Player.SendTileSquare(tileX, tileY, 4);
args.Handled = true; args.Handled = true;
return; return;
@ -250,6 +264,7 @@ namespace TShockAPI
// If the tile is a hammer tile and they aren't selecting a hammer, they're hacking. // If the tile is a hammer tile and they aren't selecting a hammer, they're hacking.
else if (Main.tileHammer[tile.type] && ((args.Player.TPlayer.mount.Type != 8 && selectedItem.hammer == 0) && !ItemID.Sets.Explosives[selectedItem.netID] && args.Player.RecentFuse == 0)) else if (Main.tileHammer[tile.type] && ((args.Player.TPlayer.mount.Type != 8 && selectedItem.hammer == 0) && !ItemID.Sets.Explosives[selectedItem.netID] && args.Player.RecentFuse == 0))
{ {
TShock.Log.ConsoleDebug("Bouncer / OnTileEdit rejected from (hammer) {0}", args.Player.Name);
args.Player.SendTileSquare(tileX, tileY, 4); args.Player.SendTileSquare(tileX, tileY, 4);
args.Handled = true; args.Handled = true;
return; return;
@ -259,6 +274,7 @@ namespace TShockAPI
else if (tile.type != TileID.ItemFrame else if (tile.type != TileID.ItemFrame
&& !Main.tileAxe[tile.type] && !Main.tileHammer[tile.type] && tile.wall == 0 && args.Player.TPlayer.mount.Type != 8 && selectedItem.pick == 0 && !ItemID.Sets.Explosives[selectedItem.netID] && args.Player.RecentFuse == 0) && !Main.tileAxe[tile.type] && !Main.tileHammer[tile.type] && tile.wall == 0 && args.Player.TPlayer.mount.Type != 8 && selectedItem.pick == 0 && !ItemID.Sets.Explosives[selectedItem.netID] && args.Player.RecentFuse == 0)
{ {
TShock.Log.ConsoleDebug("Bouncer / OnTileEdit rejected from (pick) {0}", args.Player.Name);
args.Player.SendTileSquare(tileX, tileY, 4); args.Player.SendTileSquare(tileX, tileY, 4);
args.Handled = true; args.Handled = true;
return; return;
@ -269,6 +285,7 @@ namespace TShockAPI
// If they aren't selecting a hammer, they could be hacking. // If they aren't selecting a hammer, they could be hacking.
if (selectedItem.hammer == 0 && !ItemID.Sets.Explosives[selectedItem.netID] && args.Player.RecentFuse == 0 && selectedItem.createWall == 0) if (selectedItem.hammer == 0 && !ItemID.Sets.Explosives[selectedItem.netID] && args.Player.RecentFuse == 0 && selectedItem.createWall == 0)
{ {
TShock.Log.ConsoleDebug("Bouncer / OnTileEdit rejected from (hammer2) {0}", args.Player.Name);
args.Player.SendTileSquare(tileX, tileY, 1); args.Player.SendTileSquare(tileX, tileY, 1);
args.Handled = true; args.Handled = true;
return; return;
@ -284,6 +301,7 @@ namespace TShockAPI
(MaxPlaceStyles.ContainsKey(editData) && style > MaxPlaceStyles[editData]) && (MaxPlaceStyles.ContainsKey(editData) && style > MaxPlaceStyles[editData]) &&
(ExtraneousPlaceStyles.ContainsKey(editData) && style > ExtraneousPlaceStyles[editData])) (ExtraneousPlaceStyles.ContainsKey(editData) && style > ExtraneousPlaceStyles[editData]))
{ {
TShock.Log.ConsoleDebug("Bouncer / OnTileEdit rejected from (ms1) {0}", args.Player.Name);
args.Player.SendTileSquare(tileX, tileY, 4); args.Player.SendTileSquare(tileX, tileY, 4);
args.Handled = true; args.Handled = true;
return; return;
@ -294,6 +312,8 @@ namespace TShockAPI
(editData != (action == EditAction.PlaceTile ? selectedItem.createTile : selectedItem.createWall) && (editData != (action == EditAction.PlaceTile ? selectedItem.createTile : selectedItem.createWall) &&
!(ropeCoilPlacements.ContainsKey(selectedItem.netID) && editData == ropeCoilPlacements[selectedItem.netID]))) !(ropeCoilPlacements.ContainsKey(selectedItem.netID) && editData == ropeCoilPlacements[selectedItem.netID])))
{ {
TShock.Log.ConsoleDebug("Bouncer / OnTileEdit rejected from (ms2) {0}", args.Player.Name);
args.Player.SendTileSquare(tileX, tileY, 4); args.Player.SendTileSquare(tileX, tileY, 4);
args.Handled = true; args.Handled = true;
return; return;
@ -301,12 +321,14 @@ namespace TShockAPI
if (editData >= (action == EditAction.PlaceTile ? Main.maxTileSets : Main.maxWallTypes)) if (editData >= (action == EditAction.PlaceTile ? Main.maxTileSets : Main.maxWallTypes))
{ {
TShock.Log.ConsoleDebug("Bouncer / OnTileEdit rejected from (ms3) {0}", args.Player.Name);
args.Player.SendTileSquare(tileX, tileY, 4); args.Player.SendTileSquare(tileX, tileY, 4);
args.Handled = true; args.Handled = true;
return; return;
} }
if (action == EditAction.PlaceTile && (editData == TileID.PiggyBank || editData == TileID.Safes) && Main.ServerSideCharacter) if (action == EditAction.PlaceTile && (editData == TileID.PiggyBank || editData == TileID.Safes) && Main.ServerSideCharacter)
{ {
TShock.Log.ConsoleDebug("Bouncer / OnTileEdit rejected from (sscprotect) {0}", args.Player.Name);
args.Player.SendErrorMessage("You cannot place this tile because server side characters are enabled."); args.Player.SendErrorMessage("You cannot place this tile because server side characters are enabled.");
args.Player.SendTileSquare(tileX, tileY, 3); args.Player.SendTileSquare(tileX, tileY, 3);
args.Handled = true; args.Handled = true;
@ -316,6 +338,7 @@ namespace TShockAPI
{ {
if (TShock.Utils.HasWorldReachedMaxChests()) if (TShock.Utils.HasWorldReachedMaxChests())
{ {
TShock.Log.ConsoleDebug("Bouncer / OnTileEdit rejected from (chestcap) {0}", args.Player.Name);
args.Player.SendErrorMessage("The world's chest limit has been reached - unable to place more."); args.Player.SendErrorMessage("The world's chest limit has been reached - unable to place more.");
args.Player.SendTileSquare(tileX, tileY, 3); args.Player.SendTileSquare(tileX, tileY, 3);
args.Handled = true; args.Handled = true;
@ -324,6 +347,7 @@ namespace TShockAPI
if ((TShock.Utils.TilePlacementValid(tileX, tileY + 1) && Main.tile[tileX, tileY + 1].type == TileID.Boulder) || if ((TShock.Utils.TilePlacementValid(tileX, tileY + 1) && Main.tile[tileX, tileY + 1].type == TileID.Boulder) ||
(TShock.Utils.TilePlacementValid(tileX + 1, tileY + 1) && Main.tile[tileX + 1, tileY + 1].type == TileID.Boulder)) (TShock.Utils.TilePlacementValid(tileX + 1, tileY + 1) && Main.tile[tileX + 1, tileY + 1].type == TileID.Boulder))
{ {
TShock.Log.ConsoleDebug("Bouncer / OnTileEdit rejected from (validplacement) {0}", args.Player.Name);
args.Player.SendTileSquare(tileX, tileY, 3); args.Player.SendTileSquare(tileX, tileY, 3);
args.Handled = true; args.Handled = true;
return; return;

View file

@ -520,6 +520,9 @@ namespace TShockAPI
[Description("Whether or not to show backup auto save messages.")] [Description("Whether or not to show backup auto save messages.")]
public bool ShowBackupAutosaveMessages = true; public bool ShowBackupAutosaveMessages = true;
[Description("Whether or not the server should output debug level messages related to system operation.")]
public bool DebugLogs = false;
/// <summary> /// <summary>
/// Reads a configuration file from a given path /// Reads a configuration file from a given path
/// </summary> /// </summary>

View file

@ -2101,6 +2101,7 @@ namespace TShockAPI
{ {
if (args.Player == null || args.TPlayer == null || args.Data == null) if (args.Player == null || args.TPlayer == null || args.Data == null)
{ {
TShock.Log.ConsoleDebug("GetDataHandlers / OnPlayerUpdate rejected from null player.");
return true; return true;
} }

View file

@ -123,13 +123,25 @@ namespace TShockAPI
void Write(string message, TraceLevel level); void Write(string message, TraceLevel level);
/// <summary> /// <summary>
/// Writes a debug string to the log file. Only works if the DEBUG preprocessor conditional is set. /// Writes a debug string to the log file and console. Only works if the DebugLogs config option is set to true.
/// </summary>
/// <param name="message">The message to be written.</param>
void ConsoleDebug(string message);
/// <summary>
/// Writes a debug string to the log file. Only works if the DebugLogs config option is set to true.
/// </summary>
/// <param name="message">The message to be written.</param>
void ConsoleDebug(string message, params object[] args);
/// <summary>
/// Writes a debug string to the log file. Only works if the DebugLogs config option is set to true.
/// </summary> /// </summary>
/// <param name="message">The message to be written.</param> /// <param name="message">The message to be written.</param>
void Debug(string message); void Debug(string message);
/// <summary> /// <summary>
/// Writes a debug string to the log file. Only works if the DEBUG preprocessor conditional is set. /// Writes a debug string to the log file. Only works if the DebugLogs config option is set to true.
/// </summary> /// </summary>
/// <param name="format">The format of the message to be written.</param> /// <param name="format">The format of the message to be written.</param>
/// <param name="args">The format arguments.</param> /// <param name="args">The format arguments.</param>

View file

@ -205,15 +205,34 @@ namespace TShockAPI
ConsoleInfo(string.Format(format, args)); ConsoleInfo(string.Format(format, args));
} }
/// <summary>
/// Writes a debug string to the log file. Also outputs to the console. Requires config TShock.DebugLogs to be true.
/// </summary>
/// <param name="message">The message to be written.</param>
public void ConsoleDebug(string message)
{
Console.WriteLine("Debug: " + message);
Write(message, TraceLevel.Verbose);
}
/// <summary>
/// Writes a debug string to the log file. Also outputs to the console. Requires config TShock.DebugLogs to be true.
/// </summary>
/// <param name="format">The format of the message to be written.</param>
/// <param name="args">The format arguments.</param>
public void ConsoleDebug(string format, params object[] args)
{
ConsoleDebug(string.Format(format, args));
}
/// <summary> /// <summary>
/// Writes a debug string to the log file. /// Writes a debug string to the log file.
/// </summary> /// </summary>
/// <param name="message">The message to be written.</param> /// <param name="message">The message to be written.</param>
public void Debug(string message) public void Debug(string message)
{ {
#if DEBUG if (TShock.Config.DebugLogs)
Write(message, TraceLevel.Verbose); Write(message, TraceLevel.Verbose);
#endif
} }
/// <summary> /// <summary>
@ -223,9 +242,8 @@ namespace TShockAPI
/// <param name="args">The format arguments.</param> /// <param name="args">The format arguments.</param>
public void Debug(string format, params object[] args) public void Debug(string format, params object[] args)
{ {
#if DEBUG if (TShock.Config.DebugLogs)
Debug(string.Format(format, args)); Debug(string.Format(format, args));
#endif
} }
public void Write(string message, TraceLevel level) public void Write(string message, TraceLevel level)

View file

@ -1487,7 +1487,7 @@ namespace TShockAPI
PacketTypes type = e.MsgID; PacketTypes type = e.MsgID;
Debug.WriteLine("Recv: {0:X}: {2} ({1:XX})", e.Msg.whoAmI, (byte)type, type); Log.ConsoleDebug("Recv: {0:X}: {2} ({1:XX})", e.Msg.whoAmI, (byte)type, type);
var player = Players[e.Msg.whoAmI]; var player = Players[e.Msg.whoAmI];
if (player == null || !player.ConnectionAlive) if (player == null || !player.ConnectionAlive)

View file

@ -172,15 +172,34 @@ namespace TShockAPI
ConsoleInfo(string.Format(format, args)); ConsoleInfo(string.Format(format, args));
} }
/// <summary>
/// Writes a debug string to the log file. Also outputs to the console. Requires config TShock.DebugLogs to be true.
/// </summary>
/// <param name="message">The message to be written.</param>
public void ConsoleDebug(string message)
{
Console.WriteLine("Debug: " + message);
Write(message, TraceLevel.Verbose);
}
/// <summary>
/// Writes a debug string to the log file. Also outputs to the console. Requires config TShock.DebugLogs to be true.
/// </summary>
/// <param name="format">The format of the message to be written.</param>
/// <param name="args">The format arguments.</param>
public void ConsoleDebug(string format, params object[] args)
{
ConsoleDebug(string.Format(format, args));
}
/// <summary> /// <summary>
/// Writes a debug string to the log file. /// Writes a debug string to the log file.
/// </summary> /// </summary>
/// <param name="message">The message to be written.</param> /// <param name="message">The message to be written.</param>
public void Debug(string message) public void Debug(string message)
{ {
#if DEBUG if (TShock.Config.DebugLogs)
Write(message, TraceLevel.Verbose); Write(message, TraceLevel.Verbose);
#endif
} }
/// <summary> /// <summary>
@ -190,9 +209,8 @@ namespace TShockAPI
/// <param name="args">The format arguments.</param> /// <param name="args">The format arguments.</param>
public void Debug(string format, params object[] args) public void Debug(string format, params object[] args)
{ {
#if DEBUG if (TShock.Config.DebugLogs)
Debug(string.Format(format, args)); Debug(string.Format(format, args));
#endif
} }
/// <summary> /// <summary>