Skip to content

Commit

Permalink
Merge pull request #95 from Controllerdestiny/main
Browse files Browse the repository at this point in the history
更新: ServerTools 插件尝试修复Rest Ban指令
  • Loading branch information
Controllerdestiny authored May 5, 2024
2 parents cf5c464 + 0006701 commit ab937eb
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
26 changes: 24 additions & 2 deletions ServerTools/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Terraria;
using MonoMod.RuntimeDetour;
using Terraria;
using Terraria.GameContent.Creative;
using TerrariaApi.Server;
using TShockAPI;
Expand Down Expand Up @@ -29,9 +30,11 @@ public partial class Plugin : TerrariaPlugin

public event Action<EventArgs>? Timer;

public static Hook CmdHook;

public Plugin(Main game) : base(game)
{

}

public override void Initialize()
Expand Down Expand Up @@ -70,6 +73,8 @@ public override void Initialize()
GeneralHooks.ReloadEvent += (_) => LoadConfig();
#endregion

CmdHook = new Hook(typeof(Commands).GetMethod(nameof(Commands.HandleCommand)), CommandHook);

#region RestAPI
TShock.RestApi.Register("/deathrank", DeadRank);
TShock.RestApi.Register("/onlineDuration", Queryduration);
Expand All @@ -78,6 +83,23 @@ public override void Initialize()
HandleCommandLine(Environment.GetCommandLineArgs());
}

public static bool CommandHook(TSPlayer ply, string cmd)
{
CmdHook.Undo();
if (ply.GetType() == typeof(TSRestPlayer))
{
ply.Account = new()
{
Name = ply.Name,
Group = ply.Group.Name,
ID = ply.Index
};
}
var status = Commands.HandleCommand(ply, cmd);
CmdHook.Apply();
return status;
}

private void OnPlayerSpawn(object? sender, GetDataHandlers.SpawnEventArgs e)
{
if(e.Player != null)
Expand Down
56 changes: 56 additions & 0 deletions ServerTools/RestPlayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TShockAPI;

namespace ServerTools
{
public class RestPlayer : TSPlayer
{
internal List<string> CommandOutput = new List<string>();

public RestPlayer(string playerName, Group playerGroup) : base(playerName)
{
Group = playerGroup;
AwaitingResponse = new Dictionary<string, Action<object>>();
}

public override void SendMessage(string msg, Color color)
{
SendMessage(msg, color.R, color.G, color.B);
}

public override void SendMessage(string msg, byte red, byte green, byte blue)
{
this.CommandOutput.Add(msg);
}

public override void SendInfoMessage(string msg)
{
SendMessage(msg, Color.Yellow);
}

public override void SendSuccessMessage(string msg)
{
SendMessage(msg, Color.Green);
}

public override void SendWarningMessage(string msg)
{
SendMessage(msg, Color.OrangeRed);
}

public override void SendErrorMessage(string msg)
{
SendMessage(msg, Color.Red);
}

public List<string> GetCommandOutput()
{
return this.CommandOutput;
}
}
}

0 comments on commit ab937eb

Please sign in to comment.