Merge branch 'general-devel' into net9-upgrade

This commit is contained in:
Luke 2025-01-29 22:03:08 +10:00
commit 3e08982e73
7 changed files with 174 additions and 19 deletions

View file

@ -148,24 +148,29 @@ namespace TShockAPI
Permissions = new List<string>();
}
public bool Run(string msg, bool silent, TSPlayer ply, List<string> parms)
public bool Run(CommandArgs args)
{
if (!CanRun(ply))
if (!CanRun(args.Player))
return false;
try
{
CommandDelegate(new CommandArgs(msg, silent, ply, parms));
CommandDelegate(args);
}
catch (Exception e)
{
ply.SendErrorMessage(GetString("Command failed, check logs for more details."));
args.Player.SendErrorMessage(GetString("Command failed, check logs for more details."));
TShock.Log.Error(e.ToString());
}
return true;
}
public bool Run(string msg, bool silent, TSPlayer ply, List<string> parms)
{
return Run(new CommandArgs(msg, silent, ply, parms));
}
public bool Run(string msg, TSPlayer ply, List<string> parms)
{
return Run(msg, false, ply, parms);
@ -704,7 +709,12 @@ namespace TShockAPI
TShock.Utils.SendLogs(GetString("{0} executed: {1}{2}.", player.Name, silent ? SilentSpecifier : Specifier, cmdText), Color.PaleVioletRed, player);
else
TShock.Utils.SendLogs(GetString("{0} executed (args omitted): {1}{2}.", player.Name, silent ? SilentSpecifier : Specifier, cmdName), Color.PaleVioletRed, player);
cmd.Run(cmdText, silent, player, args);
CommandArgs arguments = new CommandArgs(cmdText, silent, player, args);
bool handled = PlayerHooks.OnPrePlayerCommand(cmd, ref arguments);
if (!handled)
cmd.Run(arguments);
PlayerHooks.OnPostPlayerCommand(cmd, arguments, handled);
}
}
return true;

View file

@ -4445,6 +4445,11 @@ namespace TShockAPI
return true;
}
// Don't modify the player data if it isn't there.
// This is the case whilst the player is connecting, as we receive the SyncLoadout packet before the ContinueConnecting2 packet.
if (args.Player.PlayerData == null)
return false;
// The client does not sync slot changes when changing loadouts, it only tells the server the loadout index changed,
// and the server will replicate the changes the client did. This means that PlayerData.StoreSlot is never called, so we need to
// swap around the PlayerData items ourself.

View file

@ -20,6 +20,8 @@ using System;
using System.Linq;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
namespace TShockAPI
{
/// <summary>
@ -52,17 +54,17 @@ namespace TShockAPI
/// <summary>
/// The group that this group inherits permissions from.
/// </summary>
public Group Parent { get; set; }
public virtual Group Parent { get; set; }
/// <summary>
/// The chat prefix for this group.
/// </summary>
public string Prefix { get; set; }
public virtual string Prefix { get; set; }
/// <summary>
/// The chat suffix for this group.
/// </summary>
public string Suffix { get; set; }
public virtual string Suffix { get; set; }
/// <summary>
/// The name of the parent, not particularly sure why this is here.
@ -164,6 +166,20 @@ namespace TShockAPI
/// </summary>
public byte B = 255;
/// <summary>
/// Simplifies work with the <see cref="R"/>, <see cref="G"/>, <see cref="B"/> properties.
/// </summary>
public virtual Color Color
{
get => new Color(R, G, B);
set
{
R = value.R;
G = value.G;
B = value.B;
}
}
/// <summary>
/// The default group attributed to unregistered users.
/// </summary>
@ -242,7 +258,7 @@ namespace TShockAPI
/// Adds a permission to the list of negated permissions.
/// </summary>
/// <param name="permission">The permission to negate.</param>
public void NegatePermission(string permission)
public virtual void NegatePermission(string permission)
{
// Avoid duplicates
if (!negatedpermissions.Contains(permission))
@ -256,7 +272,7 @@ namespace TShockAPI
/// Adds a permission to the list of permissions.
/// </summary>
/// <param name="permission">The permission to add.</param>
public void AddPermission(string permission)
public virtual void AddPermission(string permission)
{
if (permission.StartsWith("!"))
{
@ -276,7 +292,7 @@ namespace TShockAPI
/// will parse "!permission" and add it to the negated permissions.
/// </summary>
/// <param name="permission">The new list of permissions to associate with the group.</param>
public void SetPermission(List<string> permission)
public virtual void SetPermission(List<string> permission)
{
permissions.Clear();
negatedpermissions.Clear();
@ -288,7 +304,7 @@ namespace TShockAPI
/// where "!permission" will remove a negated permission.
/// </summary>
/// <param name="permission"></param>
public void RemovePermission(string permission)
public virtual void RemovePermission(string permission)
{
if (permission.StartsWith("!"))
{
@ -302,7 +318,7 @@ namespace TShockAPI
/// Assigns all fields of this instance to another.
/// </summary>
/// <param name="otherGroup">The other instance.</param>
public void AssignTo(Group otherGroup)
public virtual void AssignTo(Group otherGroup)
{
otherGroup.Name = Name;
otherGroup.Parent = Parent;

View file

@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using TShockAPI.DB;
@ -119,6 +120,49 @@ namespace TShockAPI.Hooks
public string CommandPrefix { get; set; }
}
/// <summary>
/// EventArgs used for the <see cref="PlayerHooks.PrePlayerCommand"/> event.
/// </summary>
public class PrePlayerCommandEventArgs : HandledEventArgs
{
/// <summary>
/// The command entered by the player.
/// </summary>
public Command Command { get; }
/// <summary>
/// Command arguments.
/// </summary>
public CommandArgs Arguments { get; set; }
public PrePlayerCommandEventArgs(Command command, CommandArgs args)
{
Command = command;
Arguments = args;
}
}
/// <summary>
/// EventArgs used for the <see cref="PlayerHooks.PostPlayerCommand"/> event.
/// </summary>
public class PostPlayerCommandEventArgs : HandledEventArgs
{
/// <summary>
/// The command entered by the player.
/// </summary>
public Command Command { get; }
/// <summary>
/// Command arguments.
/// </summary>
public CommandArgs Arguments { get; }
public PostPlayerCommandEventArgs(Command command, CommandArgs arguments, bool handled)
{
Command = command;
Arguments = arguments;
Handled = handled;
}
}
/// <summary>
/// EventArgs used for the <see cref="PlayerHooks.PlayerChat"/> event.
/// </summary>
@ -343,6 +387,26 @@ namespace TShockAPI.Hooks
/// </summary>
public static event PlayerCommandD PlayerCommand;
/// <summary>
/// The delegate of the <see cref="PrePlayerCommand"/> event.
/// </summary>
/// <param name="e">The EventArgs for this event.</param>
public delegate void PrePlayerCommandD(PrePlayerCommandEventArgs e);
/// <summary>
/// Fired before a command is run.
/// </summary>
public static event PrePlayerCommandD PrePlayerCommand;
/// <summary>
/// The delegate of the <see cref="PostPlayerCommand"/> event.
/// </summary>
/// <param name="e">The EventArgs for this event.</param>
public delegate void PostPlayerCommandD(PostPlayerCommandEventArgs e);
/// <summary>
/// Fired after a command is run.
/// </summary>
public static event PostPlayerCommandD PostPlayerCommand;
/// <summary>
/// The delegate of the <see cref="PlayerChat"/> event.
/// </summary>
@ -449,6 +513,40 @@ namespace TShockAPI.Hooks
return playerCommandEventArgs.Handled;
}
/// <summary>
/// Fires the <see cref="PrePlayerCommand"/> event.
/// </summary>
/// <param name="cmd">Command to be executed</param>
/// <param name="arguments">Command arguments</param>
/// <returns>True if the event has been handled.</returns>
public static bool OnPrePlayerCommand(Command cmd, ref CommandArgs arguments)
{
if (PrePlayerCommand == null)
return false;
PrePlayerCommandEventArgs args = new PrePlayerCommandEventArgs(cmd, arguments);
PrePlayerCommand(args);
arguments = args.Arguments;
return args.Handled;
}
/// <summary>
/// Fires the <see cref="PostPlayerCommand"/> event.
/// </summary>
/// <param name="cmd">Executed command.</param>
/// <param name="arguments">Command arguments.</param>
/// <param name="handled">Is the command executed.</param>
public static void OnPostPlayerCommand(Command cmd, CommandArgs arguments, bool handled)
{
if (PostPlayerCommand == null)
return;
PostPlayerCommandEventArgs args = new PostPlayerCommandEventArgs(cmd, arguments, handled);
PostPlayerCommand(args);
}
/// <summary>
/// Fires the <see cref="PlayerPreLogin"/> event.
/// </summary>

View file

@ -1149,11 +1149,15 @@ namespace TShockAPI
/// <param name="empty">If the server is empty; determines if we should use Utils.GetActivePlayerCount() for player count or 0.</param>
internal void SetConsoleTitle(bool empty)
{
if (ShouldSkipTitle)
return;
Console.Title = GetString("{0}{1}/{2} on {3} @ {4}:{5} (TShock for Terraria v{6})",
!string.IsNullOrWhiteSpace(TShock.Config.Settings.ServerName) ? TShock.Config.Settings.ServerName + " - " : "",
empty ? 0 : GetActivePlayerCount(),
TShock.Config.Settings.MaxSlots, Main.worldName, Netplay.ServerIP.ToString(), Netplay.ListenPort, TShock.VersionNum);
}
// Some terminals doesn't supports XTerm escape sequences for setting the title
private static bool ShouldSkipTitle = !System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows) && !(Environment.GetEnvironmentVariable("TERM")?.Contains("xterm") ?? false);
/// <summary>Determines the distance between two vectors.</summary>
/// <param name="value1">The first vector location.</param>