Merge branch 'general-devel' into user-equatable

This commit is contained in:
Ivan 2017-08-05 21:46:39 +02:00 committed by GitHub
commit a9e1d835b8
10 changed files with 108 additions and 43 deletions

View file

@ -3,7 +3,15 @@
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
* API: Added hooks for item, projectile and tile bans (@deadsurgeon42)
* API: New WorldGrassSpread hook which shold allow corruption/crimson/hallow creep config options to work (@DeathCradle)
* Fixed saving when one player is one the server and another one joins (@MarioE)
* Fixed /spawnmob not spawning negative IDs (@MarioE)
* Validated tile placement on PlaceObject; clients can no longer place frames, paintings etc with dirt blocks (@bartico6, @ProfessorXZ)
* Updated to new stat tracking system with more data so we can actually make informed software decisions (Jordan Coulam)
## TShock 4.3.24
* API: Changed `PlayerHooks` permission hook mechanisms to allow negation from hooks (@deadsurgeon42)
* Updated OpenTerraria API to 1.3.5.3 (@DeathCradle) * Updated OpenTerraria API to 1.3.5.3 (@DeathCradle)
* Updated Terraria Server API to 1.3.5.3 (@WhiteXZ, @hakusaro) * Updated Terraria Server API to 1.3.5.3 (@WhiteXZ, @hakusaro)
* Updated TShock core components to 1.3.5.3 (@hakusaro) * Updated TShock core components to 1.3.5.3 (@hakusaro)

View file

@ -1,6 +1,6 @@
<p align="center"> <p align="center">
<img src="https://tshock.co/newlogo.png" alt="TShock for Terraria"><br /> <img src="https://tshock.co/newlogo.png" alt="TShock for Terraria"><br />
<a href="https://travis-ci.org/NyxStudios/TShock"><img src="https://travis-ci.org/NyxStudios/TShock.png?branch=general-devel" alt="Build Status"></a><a href="https://ci.appveyor.com/project/hakusaro/tshock"><img src="https://ci.appveyor.com/api/projects/status/chhe61q227lqdlg1?svg=true" alt="AppVeyor Build Status"></a><br /> <a href="https://travis-ci.org/Pryaxis/TShock"><img src="https://travis-ci.org/Pryaxis/TShock.png?branch=general-devel" alt="Build Status"></a><a href="https://ci.appveyor.com/project/hakusaro/tshock"><img src="https://ci.appveyor.com/api/projects/status/chhe61q227lqdlg1?svg=true" alt="AppVeyor Build Status"></a><br />
<hr /> <hr />
</p> </p>

View file

@ -201,8 +201,9 @@ namespace TShockAPI.DB
if (ply.HasPermission(Permissions.usebanneditem)) if (ply.HasPermission(Permissions.usebanneditem))
return true; return true;
if (PlayerHooks.OnPlayerItembanPermission(ply, this)) PermissionHookResult hookResult = PlayerHooks.OnPlayerItembanPermission(ply, this);
return true; if (hookResult != PermissionHookResult.Unhandled)
return hookResult == PermissionHookResult.Granted;
var cur = ply.Group; var cur = ply.Group;
var traversed = new List<Group>(); var traversed = new List<Group>();

View file

@ -206,8 +206,9 @@ namespace TShockAPI.DB
if (ply.HasPermission(Permissions.canusebannedprojectiles)) if (ply.HasPermission(Permissions.canusebannedprojectiles))
return true; return true;
if (PlayerHooks.OnPlayerProjbanPermission(ply, this)) PermissionHookResult hookResult = PlayerHooks.OnPlayerProjbanPermission(ply, this);
return true; if (hookResult != PermissionHookResult.Unhandled)
return hookResult == PermissionHookResult.Granted;
var cur = ply.Group; var cur = ply.Group;
var traversed = new List<Group>(); var traversed = new List<Group>();

View file

@ -206,8 +206,9 @@ namespace TShockAPI.DB
if (ply.HasPermission(Permissions.canusebannedtiles)) if (ply.HasPermission(Permissions.canusebannedtiles))
return true; return true;
if (PlayerHooks.OnPlayerTilebanPermission(ply, this)) PermissionHookResult hookResult = PlayerHooks.OnPlayerTilebanPermission(ply, this);
return true; if (hookResult != PermissionHookResult.Unhandled)
return hookResult == PermissionHookResult.Granted;
var cur = ply.Group; var cur = ply.Group;
var traversed = new List<Group>(); var traversed = new List<Group>();

View file

@ -2350,6 +2350,15 @@ namespace TShockAPI
return true; return true;
} }
// This is neccessary to check in order to prevent special tiles such as
// queen bee larva, paintings etc that use this packet from being placed
// without selecting the right item.
if (type != args.TPlayer.inventory[args.TPlayer.selectedItem].createTile)
{
args.Player.SendTileSquare(x, y, 4);
return true;
}
TileObjectData tileData = TileObjectData.GetTileData(type, style, 0); TileObjectData tileData = TileObjectData.GetTileData(type, style, 0);
if (tileData == null) if (tileData == null)
return true; return true;

View file

@ -143,7 +143,7 @@ namespace TShockAPI.Hooks
/// <summary> /// <summary>
/// EventArgs used for the <see cref="PlayerHooks.PlayerPermission"/> event. /// EventArgs used for the <see cref="PlayerHooks.PlayerPermission"/> event.
/// </summary> /// </summary>
public class PlayerPermissionEventArgs : HandledEventArgs public class PlayerPermissionEventArgs
{ {
/// <summary> /// <summary>
/// The player who fired the event. /// The player who fired the event.
@ -155,6 +155,11 @@ namespace TShockAPI.Hooks
/// </summary> /// </summary>
public string Permission { get; set; } public string Permission { get; set; }
/// <summary>
/// <see cref="PermissionHookResult"/> of the hook.
/// </summary>
public PermissionHookResult Result { get; set; }
/// <summary> /// <summary>
/// Initializes a new instance of the PlayerPermissionEventArgs class. /// Initializes a new instance of the PlayerPermissionEventArgs class.
/// </summary> /// </summary>
@ -164,13 +169,14 @@ namespace TShockAPI.Hooks
{ {
Player = player; Player = player;
Permission = permission; Permission = permission;
Result = PermissionHookResult.Unhandled;
} }
} }
/// <summary> /// <summary>
/// EventArgs used for the <see cref="PlayerHooks.PlayerItembanPermission"/> event. /// EventArgs used for the <see cref="PlayerHooks.PlayerItembanPermission"/> event.
/// </summary> /// </summary>
public class PlayerItembanPermissionEventArgs : HandledEventArgs public class PlayerItembanPermissionEventArgs
{ {
/// <summary> /// <summary>
/// The player who fired the event. /// The player who fired the event.
@ -182,22 +188,28 @@ namespace TShockAPI.Hooks
/// </summary> /// </summary>
public ItemBan BannedItem { get; set; } public ItemBan BannedItem { get; set; }
/// <summary>
/// <see cref="PermissionHookResult"/> of the hook.
/// </summary>
public PermissionHookResult Result { get; set; }
/// <summary> /// <summary>
/// Initializes a new instance of the PlayerItembanPermissionEventArgs class. /// Initializes a new instance of the PlayerItembanPermissionEventArgs class.
/// </summary> /// </summary>
/// <param name="player">The player who fired the event.</param> /// <param name="player">The player who fired the event.</param>
/// <param name="permission">The permission being checked.</param> /// <param name="bannedItem">The banned item being checked.</param>
public PlayerItembanPermissionEventArgs(TSPlayer player, ItemBan bannedItem) public PlayerItembanPermissionEventArgs(TSPlayer player, ItemBan bannedItem)
{ {
Player = player; Player = player;
BannedItem = bannedItem; BannedItem = bannedItem;
Result = PermissionHookResult.Unhandled;
} }
} }
/// <summary> /// <summary>
/// EventArgs used for the <see cref="PlayerHooks.PlayerProjbanPermission"/> event. /// EventArgs used for the <see cref="PlayerHooks.PlayerProjbanPermission"/> event.
/// </summary> /// </summary>
public class PlayerProjbanPermissionEventArgs : HandledEventArgs public class PlayerProjbanPermissionEventArgs
{ {
/// <summary> /// <summary>
/// The player who fired the event. /// The player who fired the event.
@ -209,6 +221,11 @@ namespace TShockAPI.Hooks
/// </summary> /// </summary>
public ProjectileBan BannedProjectile { get; set; } public ProjectileBan BannedProjectile { get; set; }
/// <summary>
/// <see cref="PermissionHookResult"/> of the hook.
/// </summary>
public PermissionHookResult Result { get; set; }
/// <summary> /// <summary>
/// Initializes a new instance of the PlayerProjbanPermissionEventArgs class. /// Initializes a new instance of the PlayerProjbanPermissionEventArgs class.
/// </summary> /// </summary>
@ -218,13 +235,14 @@ namespace TShockAPI.Hooks
{ {
Player = player; Player = player;
BannedProjectile = checkedProjectile; BannedProjectile = checkedProjectile;
Result = PermissionHookResult.Unhandled;
} }
} }
/// <summary> /// <summary>
/// EventArgs used for the <see cref="PlayerHooks.PlayerTilebanPermission"/> event. /// EventArgs used for the <see cref="PlayerHooks.PlayerTilebanPermission"/> event.
/// </summary> /// </summary>
public class PlayerTilebanPermissionEventArgs : HandledEventArgs public class PlayerTilebanPermissionEventArgs
{ {
/// <summary> /// <summary>
/// The player who fired the event. /// The player who fired the event.
@ -236,6 +254,11 @@ namespace TShockAPI.Hooks
/// </summary> /// </summary>
public TileBan BannedTile { get; set; } public TileBan BannedTile { get; set; }
/// <summary>
/// <see cref="PermissionHookResult"/> of the hook.
/// </summary>
public PermissionHookResult Result { get; set; }
/// <summary> /// <summary>
/// Initializes a new instance of the PlayerTilebanPermissionEventArgs class. /// Initializes a new instance of the PlayerTilebanPermissionEventArgs class.
/// </summary> /// </summary>
@ -245,6 +268,7 @@ namespace TShockAPI.Hooks
{ {
Player = player; Player = player;
BannedTile = checkedTile; BannedTile = checkedTile;
Result = PermissionHookResult.Unhandled;
} }
} }
@ -439,60 +463,79 @@ namespace TShockAPI.Hooks
/// Fires the <see cref="PlayerPermission"/> event. /// Fires the <see cref="PlayerPermission"/> event.
/// </summary> /// </summary>
/// <param name="player">The player firing the event.</param> /// <param name="player">The player firing the event.</param>
/// <returns>True if the event has been handled.</returns> /// <returns>Event result if the event has been handled, otherwise <see cref="PermissionHookResult.Unhandled"/>.</returns>
public static bool OnPlayerPermission(TSPlayer player, string permission) public static PermissionHookResult OnPlayerPermission(TSPlayer player, string permission)
{ {
if (PlayerPermission == null) if (PlayerPermission == null)
return false; return PermissionHookResult.Unhandled;
var args = new PlayerPermissionEventArgs(player, permission); var args = new PlayerPermissionEventArgs(player, permission);
PlayerPermission(args); PlayerPermission(args);
return args.Handled;
return args.Result;
} }
/// <summary> /// <summary>
/// Fires the <see cref="PlayerItembanPermission"/> event. /// Fires the <see cref="PlayerItembanPermission"/> event.
/// </summary> /// </summary>
/// <param name="player">The player firing the event.</param> /// <param name="player">The player firing the event.</param>
/// <returns>True if the event has been handled.</returns> /// <returns>Event result if the event has been handled, otherwise <see cref="PermissionHookResult.Unhandled"/>.</returns>
public static bool OnPlayerItembanPermission(TSPlayer player, ItemBan bannedItem) public static PermissionHookResult OnPlayerItembanPermission(TSPlayer player, ItemBan bannedItem)
{ {
if (PlayerItembanPermission == null) if (PlayerItembanPermission == null)
return false; return PermissionHookResult.Unhandled;
var args = new PlayerItembanPermissionEventArgs(player, bannedItem); var args = new PlayerItembanPermissionEventArgs(player, bannedItem);
PlayerItembanPermission(args); PlayerItembanPermission(args);
return args.Handled;
return args.Result;
} }
/// <summary> /// <summary>
/// Fires the <see cref="PlayerProjbanPermission"/> event. /// Fires the <see cref="PlayerProjbanPermission"/> event.
/// </summary> /// </summary>
/// <param name="player">The player firing the event.</param> /// <param name="player">The player firing the event.</param>
/// <returns>True if the event has been handled.</returns> /// <returns>Event result if the event has been handled, otherwise <see cref="PermissionHookResult.Unhandled"/>.</returns>
public static bool OnPlayerProjbanPermission(TSPlayer player, ProjectileBan bannedProj) public static PermissionHookResult OnPlayerProjbanPermission(TSPlayer player, ProjectileBan bannedProj)
{ {
if (PlayerProjbanPermission == null) if (PlayerProjbanPermission == null)
return false; return PermissionHookResult.Unhandled;
var args = new PlayerProjbanPermissionEventArgs(player, bannedProj); var args = new PlayerProjbanPermissionEventArgs(player, bannedProj);
PlayerProjbanPermission(args); PlayerProjbanPermission(args);
return args.Handled;
return args.Result;
} }
/// <summary> /// <summary>
/// Fires the <see cref="PlayerTilebanPermission"/> event. /// Fires the <see cref="PlayerTilebanPermission"/> event.
/// </summary> /// </summary>
/// <param name="player">The player firing the event.</param> /// <param name="player">The player firing the event.</param>
/// <returns>True if the event has been handled.</returns> /// <returns>Event result if the event has been handled, otherwise <see cref="PermissionHookResult.Unhandled"/>.</returns>
public static bool OnPlayerTilebanPermission(TSPlayer player, TileBan bannedTile) public static PermissionHookResult OnPlayerTilebanPermission(TSPlayer player, TileBan bannedTile)
{ {
if (PlayerTilebanPermission == null) if (PlayerTilebanPermission == null)
return false; return PermissionHookResult.Unhandled;
var args = new PlayerTilebanPermissionEventArgs(player, bannedTile); var args = new PlayerTilebanPermissionEventArgs(player, bannedTile);
PlayerTilebanPermission(args); PlayerTilebanPermission(args);
return args.Handled;
return args.Result;
} }
} }
/// <summary>
/// Defines the possible outcomes of <see cref="PlayerHooks.PlayerPermission"/> handlers.
/// </summary>
public enum PermissionHookResult
{
/// <summary>Hook doesn't return a result on the permission check.</summary>
Unhandled,
/// <summary>Permission is explicitly denied by a hook.</summary>
Denied,
/// <summary>Permission is explicitly granted by a hook.</summary>
Granted
}
} }

View file

@ -12,23 +12,23 @@ namespace TShockAPI.Sockets
{ {
public class LinuxTcpSocket : ISocket public class LinuxTcpSocket : ISocket
{ {
private byte[] _packetBuffer = new byte[1024]; public byte[] _packetBuffer = new byte[1024];
private int _packetBufferLength; public int _packetBufferLength;
private List<object> _callbackBuffer = new List<object>(); public List<object> _callbackBuffer = new List<object>();
private int _messagesInQueue; public int _messagesInQueue;
private TcpClient _connection; public TcpClient _connection;
private TcpListener _listener; public TcpListener _listener;
private SocketConnectionAccepted _listenerCallback; public SocketConnectionAccepted _listenerCallback;
private RemoteAddress _remoteAddress; public RemoteAddress _remoteAddress;
private bool _isListening; public bool _isListening;
public int MessagesInQueue public int MessagesInQueue
{ {

View file

@ -160,10 +160,10 @@ namespace TShockAPI
{ {
if (plugins != null) if (plugins != null)
{ {
return plugins;//Return early return plugins; //Return early
} }
plugins = new PluginItem[ServerApi.Plugins.Count];//Initialize with enough room to store the ammount of plugins loaded. plugins = new PluginItem[ServerApi.Plugins.Count]; //Initialize with enough room to store the ammount of plugins loaded.
for (var i = 0; i < ServerApi.Plugins.Count; i++) for (var i = 0; i < ServerApi.Plugins.Count; i++)
{ {
var pluginItem = new PluginItem(); var pluginItem = new PluginItem();
@ -181,10 +181,10 @@ namespace TShockAPI
{ {
if (totalMem != 0) if (totalMem != 0)
{ {
return totalMem;//Return early return totalMem; //Return early
} }
if (isMono)//Set totalMem so it can be returned later if (isMono) //Set totalMem so it can be returned later
{ {
var pc = new PerformanceCounter("Mono Memory", "Total Physical Memory"); var pc = new PerformanceCounter("Mono Memory", "Total Physical Memory");
totalMem = (pc.RawValue / 1024 / 1024 / 1024); totalMem = (pc.RawValue / 1024 / 1024 / 1024);

View file

@ -1265,8 +1265,10 @@ namespace TShockAPI
/// <returns>True if the player has that permission.</returns> /// <returns>True if the player has that permission.</returns>
public bool HasPermission(string permission) public bool HasPermission(string permission)
{ {
if (PlayerHooks.OnPlayerPermission(this, permission)) PermissionHookResult hookResult = PlayerHooks.OnPlayerPermission(this, permission);
return true;
if (hookResult != PermissionHookResult.Unhandled)
return hookResult == PermissionHookResult.Granted;
if (tempGroup != null) if (tempGroup != null)
return tempGroup.HasPermission(permission); return tempGroup.HasPermission(permission);