Implemented permissions for lua and some commands to work with it.
TSHOCKPLUGINS-4 is completed.
This commit is contained in:
parent
15d9a2aa8c
commit
d28fef8e1e
3 changed files with 83 additions and 20 deletions
|
|
@ -208,6 +208,9 @@ namespace TShockAPI
|
|||
add(Permissions.cfg, ServerInfo, "stats");
|
||||
add(Permissions.converthardmode, ConvertCorruption, "convertcorruption");
|
||||
add(Permissions.converthardmode, ConvertHallow, "converthallow");
|
||||
add(Permissions.runlua, RunLuaFile, "luarun");
|
||||
add(Permissions.runlua, RunLuaString, "lua");
|
||||
add(Permissions.runlua, ReloadLua, "luareload");
|
||||
}
|
||||
|
||||
public static bool HandleCommand(TSPlayer player, string text)
|
||||
|
|
@ -325,6 +328,41 @@ namespace TShockAPI
|
|||
return c == ' ' || c == '\t' || c == '\n';
|
||||
}
|
||||
|
||||
#region Lua Commands
|
||||
|
||||
public static void ReloadLua(CommandArgs args)
|
||||
{
|
||||
TShock.LuaLoader.LoadServerAutoruns();
|
||||
args.Player.SendMessage("Lua reloaded.");
|
||||
}
|
||||
|
||||
public static void RunLuaString(CommandArgs args)
|
||||
{
|
||||
|
||||
if (args.Parameters.Count < 1)
|
||||
{
|
||||
args.Player.SendMessage("Syntax: /lua <lua>");
|
||||
return;
|
||||
}
|
||||
|
||||
string lua = "";
|
||||
foreach (string s in args.Parameters)
|
||||
{
|
||||
lua += s;
|
||||
}
|
||||
}
|
||||
|
||||
public static void RunLuaFile(CommandArgs args)
|
||||
{
|
||||
if (args.Parameters.Count != 1)
|
||||
{
|
||||
args.Player.SendMessage("Syntax: /luarun <file>");
|
||||
return;
|
||||
}
|
||||
TShock.LuaLoader.RunLuaFile(args.Parameters[0]);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Account commands
|
||||
|
||||
public static void AttemptLogin(CommandArgs args)
|
||||
|
|
@ -1246,19 +1284,19 @@ namespace TShockAPI
|
|||
}
|
||||
}
|
||||
|
||||
private static void StartHardMode(CommandArgs args)
|
||||
{
|
||||
if (!TShock.Config.DisableHardmode)
|
||||
WorldGen.StartHardmode();
|
||||
else
|
||||
args.Player.SendMessage("Hardmode is disabled via config", Color.Red);
|
||||
}
|
||||
private static void StartHardMode(CommandArgs args)
|
||||
{
|
||||
if (!TShock.Config.DisableHardmode)
|
||||
WorldGen.StartHardmode();
|
||||
else
|
||||
args.Player.SendMessage("Hardmode is disabled via config", Color.Red);
|
||||
}
|
||||
|
||||
private static void DisableHardMode(CommandArgs args)
|
||||
{
|
||||
Main.hardMode = false;
|
||||
args.Player.SendMessage("Hardmode is now disabled", Color.Green);
|
||||
}
|
||||
private static void DisableHardMode(CommandArgs args)
|
||||
{
|
||||
Main.hardMode = false;
|
||||
args.Player.SendMessage("Hardmode is now disabled", Color.Green);
|
||||
}
|
||||
|
||||
private static void ConvertCorruption(CommandArgs args)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using LuaInterface;
|
||||
|
||||
namespace TShockAPI.LuaSystem
|
||||
|
|
@ -36,14 +37,7 @@ namespace TShockAPI.LuaSystem
|
|||
foreach (string s in Directory.GetFiles(LuaAutorunPath))
|
||||
{
|
||||
SendLuaDebugMsg("Loading: " + s);
|
||||
try
|
||||
{
|
||||
Lua.DoFile(s);
|
||||
}
|
||||
catch (LuaException e)
|
||||
{
|
||||
SendLuaDebugMsg(e.Message);
|
||||
}
|
||||
RunLuaFile(s);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
@ -53,6 +47,30 @@ namespace TShockAPI.LuaSystem
|
|||
}
|
||||
}
|
||||
|
||||
public void RunLuaString(string s)
|
||||
{
|
||||
try
|
||||
{
|
||||
Lua.DoString(s);
|
||||
}
|
||||
catch (LuaException e)
|
||||
{
|
||||
SendLuaDebugMsg(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public void RunLuaFile(string s)
|
||||
{
|
||||
try
|
||||
{
|
||||
Lua.DoFile(s);
|
||||
}
|
||||
catch (LuaException e)
|
||||
{
|
||||
SendLuaDebugMsg(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public void SendLuaDebugMsg(string s)
|
||||
{
|
||||
ConsoleColor previousColor = Console.ForegroundColor;
|
||||
|
|
@ -66,6 +84,11 @@ namespace TShockAPI.LuaSystem
|
|||
LuaFunctions LuaFuncs = new LuaFunctions();
|
||||
Lua.RegisterFunction("Print", LuaFuncs, LuaFuncs.GetType().GetMethod("Print"));
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
SendLuaDebugMsg("Lua 5.1 shutting down. Terminating all Lua threads.");
|
||||
}
|
||||
}
|
||||
|
||||
public class LuaFunctions
|
||||
|
|
|
|||
|
|
@ -149,6 +149,8 @@ namespace TShockAPI
|
|||
[Description("Allow unrestricted Send Tile Square usage, for client side world editing")] public static readonly
|
||||
string allowclientsideworldedit;
|
||||
|
||||
[Description("User can execute Lua files from the hard disk and run Lua strings.")] public static readonly string
|
||||
runlua;
|
||||
|
||||
static Permissions()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue