Added RevertKillTile to TSServerPlayer
This commit is contained in:
parent
90474920cd
commit
ea0c091355
3 changed files with 77 additions and 75 deletions
|
|
@ -53,24 +53,6 @@ namespace TShockAPI
|
|||
_logWriter = new StreamWriter(filename, !clear);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal method which writes a message directly to the log file.
|
||||
/// </summary>
|
||||
private static void Write(String message, LogLevel level)
|
||||
{
|
||||
if (!MayWriteType(level))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string caller = "TShock";
|
||||
|
||||
_logWriter.WriteLine(string.Format("{0} - {1}: {2}: {3}",
|
||||
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
|
||||
caller, level.ToString().ToUpper(), message));
|
||||
_logWriter.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the log level contains the specified flag.
|
||||
/// </summary>
|
||||
|
|
@ -124,5 +106,23 @@ namespace TShockAPI
|
|||
{
|
||||
Write(message, LogLevel.Debug);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal method which writes a message directly to the log file.
|
||||
/// </summary>
|
||||
private static void Write(String message, LogLevel level)
|
||||
{
|
||||
if (!MayWriteType(level))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string caller = "TShock";
|
||||
|
||||
_logWriter.WriteLine(string.Format("{0} - {1}: {2}: {3}",
|
||||
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
|
||||
caller, level.ToString().ToUpper(), message));
|
||||
_logWriter.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -27,8 +27,8 @@ namespace TShockAPI
|
|||
{
|
||||
public static readonly TSServerPlayer Server = new TSServerPlayer();
|
||||
public static readonly TSPlayer All = new TSPlayer("All");
|
||||
public uint TileThreshold { get; set; }
|
||||
public Dictionary<Vector2, Tile> TilesDestroyed { get; set; }
|
||||
public int TileThreshold { get; set; }
|
||||
public Dictionary<Vector2, Tile> TilesDestroyed { get; protected set; }
|
||||
public bool SyncHP { get; set; }
|
||||
public bool SyncMP { get; set; }
|
||||
public Group Group { get; set; }
|
||||
|
|
@ -42,6 +42,13 @@ namespace TShockAPI
|
|||
{
|
||||
get { return RealPlayer ? Netplay.serverSock[Index].active && !Netplay.serverSock[Index].kill : false; }
|
||||
}
|
||||
public string IP
|
||||
{
|
||||
get
|
||||
{
|
||||
return RealPlayer ? Tools.GetRealIP(Netplay.serverSock[Index].tcpClient.Client.RemoteEndPoint.ToString()) : "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Terraria Player
|
||||
/// </summary>
|
||||
|
|
@ -50,13 +57,6 @@ namespace TShockAPI
|
|||
{
|
||||
get { return TPlayer.name; }
|
||||
}
|
||||
public string IP
|
||||
{
|
||||
get
|
||||
{
|
||||
return RealPlayer ? Tools.GetRealIP(Netplay.serverSock[Index].tcpClient.Client.RemoteEndPoint.ToString()) : "";
|
||||
}
|
||||
}
|
||||
public bool Active
|
||||
{
|
||||
get { return TPlayer.active; }
|
||||
|
|
@ -93,12 +93,15 @@ namespace TShockAPI
|
|||
get
|
||||
{
|
||||
bool flag = false;
|
||||
for (int i = 0; i < 40; i++)
|
||||
if (RealPlayer)
|
||||
{
|
||||
if (!TPlayer.inventory[i].active)
|
||||
for (int i = 0; i < 40; i++)
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
if (!TPlayer.inventory[i].active)
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
|
|
@ -123,17 +126,11 @@ namespace TShockAPI
|
|||
|
||||
public virtual void Disconnect(string reason)
|
||||
{
|
||||
if (Index == -1)
|
||||
return;
|
||||
|
||||
NetMessage.SendData((int)PacketTypes.Disconnect, Index, -1, reason, 0x0, 0f, 0f, 0f);
|
||||
}
|
||||
|
||||
public virtual void SendTileSquare(int x, int y, int size = 10)
|
||||
{
|
||||
if (Index == -1)
|
||||
return;
|
||||
|
||||
NetMessage.SendData((int)PacketTypes.TileSendSquare, Index, -1, "", size, (float)(x - (size / 2)), (float)(y - (size / 2)), 0f);
|
||||
}
|
||||
|
||||
|
|
@ -167,17 +164,11 @@ namespace TShockAPI
|
|||
|
||||
public virtual void DamagePlayer(int damage)
|
||||
{
|
||||
if (Index == -1)
|
||||
return;
|
||||
|
||||
NetMessage.SendData((int)PacketTypes.PlayerDamage, -1, -1, "", Index, ((new Random()).Next(-1, 1)), damage, (float)0);
|
||||
}
|
||||
|
||||
public virtual void SetPvP(bool pvp)
|
||||
{
|
||||
if (Index == -1)
|
||||
return;
|
||||
|
||||
if (TPlayer.hostile != pvp)
|
||||
{
|
||||
TPlayer.hostile = pvp;
|
||||
|
|
@ -242,5 +233,21 @@ namespace TShockAPI
|
|||
Main.npc[npcid].StrikeNPC(damage, knockBack, hitDirection);
|
||||
NetMessage.SendData((int)PacketTypes.NPCStrike, -1, -1, "", npcid, damage, knockBack, hitDirection);
|
||||
}
|
||||
|
||||
public void RevertKillTile(Dictionary<Vector2, Tile> destroyedTiles)
|
||||
{
|
||||
// Update Main.Tile first so that when tile sqaure is sent it is correct
|
||||
foreach (KeyValuePair<Vector2, Tile> entry in destroyedTiles)
|
||||
{
|
||||
Main.tile[(int)entry.Key.X, (int)entry.Key.Y] = 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 (Vector2 coords in destroyedTiles.Keys)
|
||||
{
|
||||
TSPlayer.All.SendTileSquare((int)coords.X, (int)coords.Y, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -31,14 +31,12 @@ namespace TShockAPI
|
|||
[APIVersion(1, 3)]
|
||||
public class TShock : TerrariaPlugin
|
||||
{
|
||||
public static TSPlayer[] Players = new TSPlayer[Main.maxPlayers];
|
||||
public static readonly Version VersionNum = new Version(2, 1, 0, 6);
|
||||
public static readonly string VersionCodename = "Forgot to increase the version.";
|
||||
|
||||
public static readonly string SavePath = "tshock";
|
||||
|
||||
public static readonly Version VersionNum = new Version(2, 1, 0, 6);
|
||||
|
||||
public static readonly string VersionCodename = "Forgot to increase the version.";
|
||||
|
||||
public static TSPlayer[] Players = new TSPlayer[Main.maxPlayers];
|
||||
public static BanManager Bans = new BanManager(Path.Combine(SavePath, "bans.txt"));
|
||||
|
||||
public override Version Version
|
||||
|
|
@ -187,9 +185,7 @@ namespace TShockAPI
|
|||
{
|
||||
if (Tools.HandleTntUser(player, "Kill tile abuse detected."))
|
||||
{
|
||||
RevertKillTile(player);
|
||||
player.TileThreshold = 0;
|
||||
player.TilesDestroyed.Clear();
|
||||
TSPlayer.Server.RevertKillTile(player.TilesDestroyed);
|
||||
}
|
||||
else if (player.TileThreshold > 0)
|
||||
{
|
||||
|
|
@ -201,6 +197,7 @@ namespace TShockAPI
|
|||
else if (player.TileThreshold > 0)
|
||||
{
|
||||
player.TileThreshold = 0;
|
||||
player.TilesDestroyed.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -214,8 +211,7 @@ namespace TShockAPI
|
|||
var player = new TSPlayer(ply);
|
||||
player.Group = Tools.GetGroupForIP(player.IP);
|
||||
|
||||
if (Tools.ActivePlayers() + 1 > ConfigurationManager.MaxSlots &&
|
||||
!player.Group.HasPermission("reservedslot"))
|
||||
if (Tools.ActivePlayers() + 1 > ConfigurationManager.MaxSlots && !player.Group.HasPermission("reservedslot"))
|
||||
{
|
||||
Tools.ForceKick(player, "Server is full");
|
||||
handler.Handled = true;
|
||||
|
|
@ -336,21 +332,33 @@ namespace TShockAPI
|
|||
TSPlayer player = Players[e.Msg.whoAmI];
|
||||
|
||||
if (!player.ConnectionAlive)
|
||||
{
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Main.verboseNetplay)
|
||||
Debug.WriteLine("{0:X} ({2}): {3} ({1:XX})", player.Index, (byte) type, player.TPlayer.dead ? "dead " : "alive", type.ToString());
|
||||
Debug.WriteLine("{0:X} ({2}): {3} ({1:XX})", player.Index, (byte)type, player.TPlayer.dead ? "dead " : "alive", type.ToString());
|
||||
|
||||
using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
|
||||
// Stop accepting updates from player as this player is going to be kicked/banned during OnUpdate (different thread so can produce race conditions)
|
||||
if (player.TileThreshold >= 20 && !player.Group.HasPermission("ignoregriefdetection"))
|
||||
{
|
||||
try
|
||||
Log.Debug("Rejecting " + type + " from " + player.Name + " as this player is about to be kicked");
|
||||
e.Handled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length))
|
||||
{
|
||||
if (GetDataHandlers.HandlerGetData(type, player, data))
|
||||
e.Handled = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.ToString());
|
||||
try
|
||||
{
|
||||
if (GetDataHandlers.HandlerGetData(type, player, data))
|
||||
e.Handled = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -478,19 +486,6 @@ namespace TShockAPI
|
|||
return true;
|
||||
}
|
||||
|
||||
public static void RevertKillTile(TSPlayer player)
|
||||
{
|
||||
Tile[] tiles = new Tile[player.TilesDestroyed.Count];
|
||||
player.TilesDestroyed.Values.CopyTo(tiles, 0);
|
||||
Vector2[] positions = new Vector2[player.TilesDestroyed.Count];
|
||||
player.TilesDestroyed.Keys.CopyTo(positions, 0);
|
||||
for (int i = (player.TilesDestroyed.Count - 1); i >= 0; i--)
|
||||
{
|
||||
Main.tile[(int)positions[i].X, (int)positions[i].Y] = tiles[i];
|
||||
NetMessage.SendData(17, -1, -1, "", 1, positions[i].X, positions[i].Y, (float)0);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool HackedHealth(TSPlayer player)
|
||||
{
|
||||
return (player.TPlayer.statManaMax > 200) ||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue