Add new REST endpoint:
- /v2/server/rawcmd Takes parameters: - cmd Commands have to start with /, some commands aren't written properly, and may not return any more output than a status code.
This commit is contained in:
parent
f04b9d7a6d
commit
b8e4dffd74
4 changed files with 74 additions and 27 deletions
|
|
@ -40,8 +40,8 @@ namespace TShockAPI
|
||||||
private int[] Compressed = new int[52];
|
private int[] Compressed = new int[52];
|
||||||
|
|
||||||
#if DEBUG_NET
|
#if DEBUG_NET
|
||||||
Command dump;
|
Command dump;
|
||||||
Command flush;
|
Command flush;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public PacketBufferer()
|
public PacketBufferer()
|
||||||
|
|
@ -51,10 +51,10 @@ namespace TShockAPI
|
||||||
buffers[i] = new PacketBuffer();
|
buffers[i] = new PacketBuffer();
|
||||||
|
|
||||||
#if DEBUG_NET
|
#if DEBUG_NET
|
||||||
dump = new Command("superadmin", Dump, "netdump");
|
dump = new Command("superadmin", Dump, "netdump");
|
||||||
flush = new Command("superadmin", Flush, "netflush");
|
flush = new Command("superadmin", Flush, "netflush");
|
||||||
Commands.ChatCommands.Add(dump);
|
Commands.ChatCommands.Add(dump);
|
||||||
Commands.ChatCommands.Add(flush);
|
Commands.ChatCommands.Add(flush);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
NetHooks.SendBytes += ServerHooks_SendBytes;
|
NetHooks.SendBytes += ServerHooks_SendBytes;
|
||||||
|
|
@ -78,8 +78,8 @@ namespace TShockAPI
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
#if DEBUG_NET
|
#if DEBUG_NET
|
||||||
Commands.ChatCommands.Remove(dump);
|
Commands.ChatCommands.Remove(dump);
|
||||||
Commands.ChatCommands.Remove(flush);
|
Commands.ChatCommands.Remove(flush);
|
||||||
#endif
|
#endif
|
||||||
NetHooks.SendBytes -= ServerHooks_SendBytes;
|
NetHooks.SendBytes -= ServerHooks_SendBytes;
|
||||||
ServerHooks.SocketReset -= ServerHooks_SocketReset;
|
ServerHooks.SocketReset -= ServerHooks_SocketReset;
|
||||||
|
|
@ -94,7 +94,7 @@ namespace TShockAPI
|
||||||
for (int i = 1; i < Bytes.Length; i++)
|
for (int i = 1; i < Bytes.Length; i++)
|
||||||
{
|
{
|
||||||
sb.AppendLine("{0,-25}{1,-25}{2,-25}{3}".SFormat(Enum.GetName(typeof (PacketTypes), i) + ":", Packets[i], Bytes[i],
|
sb.AppendLine("{0,-25}{1,-25}{2,-25}{3}".SFormat(Enum.GetName(typeof (PacketTypes), i) + ":", Packets[i], Bytes[i],
|
||||||
Compressed[i]));
|
Compressed[i]));
|
||||||
}
|
}
|
||||||
File.WriteAllText(Path.Combine(TShock.SavePath, "dmp.txt"), sb.ToString());
|
File.WriteAllText(Path.Combine(TShock.SavePath, "dmp.txt"), sb.ToString());
|
||||||
}
|
}
|
||||||
|
|
@ -167,12 +167,12 @@ namespace TShockAPI
|
||||||
lock (buffers[socket.whoAmI])
|
lock (buffers[socket.whoAmI])
|
||||||
{
|
{
|
||||||
#if DEBUG_NET
|
#if DEBUG_NET
|
||||||
int size = (count - offset);
|
int size = (count - offset);
|
||||||
var pt = buffer[offset + 4];
|
var pt = buffer[offset + 4];
|
||||||
|
|
||||||
Packets[pt]++;
|
Packets[pt]++;
|
||||||
Bytes[pt] += size;
|
Bytes[pt] += size;
|
||||||
Compressed[pt] += Compress(buffer, offset, count);
|
Compressed[pt] += Compress(buffer, offset, count);
|
||||||
#endif
|
#endif
|
||||||
using (var ms = new MemoryStream(buffer, offset, count))
|
using (var ms = new MemoryStream(buffer, offset, count))
|
||||||
{
|
{
|
||||||
|
|
@ -213,17 +213,17 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG_NET
|
#if DEBUG_NET
|
||||||
static int Compress(byte[] buffer, int offset, int count)
|
static int Compress(byte[] buffer, int offset, int count)
|
||||||
{
|
{
|
||||||
using (var ms = new MemoryStream())
|
using (var ms = new MemoryStream())
|
||||||
{
|
{
|
||||||
using (var gzip = new GZipStream(ms, CompressionMode.Compress, true))
|
using (var gzip = new GZipStream(ms, CompressionMode.Compress, true))
|
||||||
{
|
{
|
||||||
gzip.Write(buffer, offset, count);
|
gzip.Write(buffer, offset, count);
|
||||||
}
|
}
|
||||||
return (int)ms.Length;
|
return (int)ms.Length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,5 +48,5 @@ using System.Runtime.InteropServices;
|
||||||
// Build Number
|
// Build Number
|
||||||
// MMdd of the build
|
// MMdd of the build
|
||||||
|
|
||||||
[assembly: AssemblyVersion("3.4.2.0101")]
|
[assembly: AssemblyVersion("3.4.2.0102")]
|
||||||
[assembly: AssemblyFileVersion("3.4.2.0101")]
|
[assembly: AssemblyFileVersion("3.4.2.0102")]
|
||||||
|
|
@ -64,6 +64,7 @@ namespace TShockAPI
|
||||||
|
|
||||||
Rest.Register(new RestCommand("/v2/server/broadcast", Broadcast) { RequiresToken = true});
|
Rest.Register(new RestCommand("/v2/server/broadcast", Broadcast) { RequiresToken = true});
|
||||||
Rest.Register(new RestCommand("/v2/server/off", Off) {RequiresToken = true});
|
Rest.Register(new RestCommand("/v2/server/off", Off) {RequiresToken = true});
|
||||||
|
Rest.Register(new RestCommand("/v2/server/rawcmd", ServerCommand) {RequiresToken = true});
|
||||||
|
|
||||||
#region Deprecated Endpoints
|
#region Deprecated Endpoints
|
||||||
Rest.Register(new RestCommand("/bans/read/{user}/info", BanInfo) { RequiresToken = true });
|
Rest.Register(new RestCommand("/bans/read/{user}/info", BanInfo) { RequiresToken = true });
|
||||||
|
|
@ -82,6 +83,22 @@ namespace TShockAPI
|
||||||
|
|
||||||
#region RestServerMethods
|
#region RestServerMethods
|
||||||
|
|
||||||
|
private object ServerCommand(RestVerbs verbs, IParameterCollection parameters)
|
||||||
|
{
|
||||||
|
if (parameters["cmd"] != null && parameters["cmd"].Trim() != "")
|
||||||
|
{
|
||||||
|
TSRESTPlayer tr = new TSRESTPlayer();
|
||||||
|
RestObject ro = new RestObject("200");
|
||||||
|
Commands.HandleCommand(tr, parameters["cmd"]);
|
||||||
|
foreach (string s in tr.GetCommandOutput())
|
||||||
|
{
|
||||||
|
ro.Add("response", s);
|
||||||
|
}
|
||||||
|
return ro;
|
||||||
|
}
|
||||||
|
return new RestObject("500")["response"] = "Invalid cmd parameter passed to REST. Cowardly not running a blank command.";
|
||||||
|
}
|
||||||
|
|
||||||
private object Off(RestVerbs verbs, IParameterCollection parameters)
|
private object Off(RestVerbs verbs, IParameterCollection parameters)
|
||||||
{
|
{
|
||||||
bool confirm;
|
bool confirm;
|
||||||
|
|
|
||||||
|
|
@ -405,6 +405,36 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class TSRestPlayer : TSServerPlayer
|
||||||
|
{
|
||||||
|
internal List<string> CommandReturn = new List<string>();
|
||||||
|
|
||||||
|
public TSRestPlayer()
|
||||||
|
{
|
||||||
|
Group = new SuperAdminGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SendMessage(string msg)
|
||||||
|
{
|
||||||
|
SendMessage(msg, 0, 255, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
CommandReturn.Add(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<string> GetCommandOutput()
|
||||||
|
{
|
||||||
|
return CommandReturn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class TSServerPlayer : TSPlayer
|
public class TSServerPlayer : TSPlayer
|
||||||
{
|
{
|
||||||
public TSServerPlayer()
|
public TSServerPlayer()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue