implement players section
This commit is contained in:
21
TorchRemote.Models/Responses/PlayerResponse.cs
Normal file
21
TorchRemote.Models/Responses/PlayerResponse.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
namespace TorchRemote.Models.Responses;
|
||||||
|
|
||||||
|
public record PlayerResponse(ulong ClientId, string Name, PlayerPromoteLevel PromoteLevel);
|
||||||
|
|
||||||
|
public enum PlayerPromoteLevel
|
||||||
|
{
|
||||||
|
/// <summary>Normal players</summary>
|
||||||
|
None,
|
||||||
|
/// <summary>Can edit scripts when the scripter role is enabled</summary>
|
||||||
|
Scripter,
|
||||||
|
/// <summary>
|
||||||
|
/// Can kick and ban players, has access to 'Show All Players' option in Admin Tools menu
|
||||||
|
/// </summary>
|
||||||
|
Moderator,
|
||||||
|
/// <summary>Has access to Space Master tools</summary>
|
||||||
|
SpaceMaster,
|
||||||
|
/// <summary>Has access to Admin tools</summary>
|
||||||
|
Admin,
|
||||||
|
/// <summary>Admins listed in server config, cannot be demoted</summary>
|
||||||
|
Owner,
|
||||||
|
}
|
53
TorchRemote.Plugin/Controllers/PlayersController.cs
Normal file
53
TorchRemote.Plugin/Controllers/PlayersController.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
using EmbedIO;
|
||||||
|
using EmbedIO.Routing;
|
||||||
|
using EmbedIO.WebApi;
|
||||||
|
using Sandbox.Engine.Multiplayer;
|
||||||
|
using Sandbox.Game.Multiplayer;
|
||||||
|
using TorchRemote.Models.Responses;
|
||||||
|
using TorchRemote.Plugin.Utils;
|
||||||
|
|
||||||
|
namespace TorchRemote.Plugin.Controllers;
|
||||||
|
|
||||||
|
public class PlayersController : WebApiController
|
||||||
|
{
|
||||||
|
private const string RootPath = "/players";
|
||||||
|
|
||||||
|
[Route(HttpVerbs.Get, RootPath)]
|
||||||
|
public Task<IEnumerable<PlayerResponse>> Get()
|
||||||
|
{
|
||||||
|
return Statics.Torch.InvokeAsync(() => Sync.Players.GetOnlinePlayers()
|
||||||
|
.Select(b => new PlayerResponse(b.Id.SteamId, b.DisplayName,
|
||||||
|
(PlayerPromoteLevel)Statics.MultiplayerManager!
|
||||||
|
.GetUserPromoteLevel(b.Id.SteamId))));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Route(HttpVerbs.Post, $"{RootPath}/{{id}}/kick")]
|
||||||
|
public Task Kick(ulong id, [QueryField] bool cooldown = true)
|
||||||
|
{
|
||||||
|
return Statics.Torch.InvokeAsync(() => MyMultiplayer.Static.KickClient(id, true, cooldown));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Route(HttpVerbs.Post, $"{RootPath}/{{id}}/ban")]
|
||||||
|
public void Ban(ulong id)
|
||||||
|
{
|
||||||
|
Statics.MultiplayerManager!.BanPlayer(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Route(HttpVerbs.Post, $"{RootPath}/{{id}}/disconnect")]
|
||||||
|
public Task Disconnect(ulong id)
|
||||||
|
{
|
||||||
|
return Statics.Torch.InvokeAsync(() => MyMultiplayer.Static.DisconnectClient(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Route(HttpVerbs.Post, $"{RootPath}/{{id}}/promote")]
|
||||||
|
public void Promote(ulong id)
|
||||||
|
{
|
||||||
|
Statics.MultiplayerManager!.PromoteUser(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Route(HttpVerbs.Post, $"{RootPath}/{{id}}/demote")]
|
||||||
|
public void Demote(ulong id)
|
||||||
|
{
|
||||||
|
Statics.MultiplayerManager!.DemoteUser(id);
|
||||||
|
}
|
||||||
|
}
|
@@ -60,7 +60,8 @@ public class ApiServerManager : Manager
|
|||||||
.WithController<WorldsController>()
|
.WithController<WorldsController>()
|
||||||
.WithController<ChatController>()
|
.WithController<ChatController>()
|
||||||
.WithController<PluginsController>()
|
.WithController<PluginsController>()
|
||||||
.WithController<PluginDownloadsController>())
|
.WithController<PluginDownloadsController>()
|
||||||
|
.WithController<PlayersController>())
|
||||||
.WithModule(new LogsModule("/api/live/logs", true))
|
.WithModule(new LogsModule("/api/live/logs", true))
|
||||||
.WithModule(chatModule)
|
.WithModule(chatModule)
|
||||||
.WithBearerToken("/api", new SymmetricSecurityKey(Convert.FromBase64String(_config.SecurityKey)), new BasicAuthorizationServerProvider());
|
.WithBearerToken("/api", new SymmetricSecurityKey(Convert.FromBase64String(_config.SecurityKey)), new BasicAuthorizationServerProvider());
|
||||||
|
@@ -21,6 +21,8 @@ internal static class Statics
|
|||||||
public static InstanceManager InstanceManager => Torch.Managers.GetManager<InstanceManager>();
|
public static InstanceManager InstanceManager => Torch.Managers.GetManager<InstanceManager>();
|
||||||
public static PluginManager PluginManager => Torch.Managers.GetManager<PluginManager>();
|
public static PluginManager PluginManager => Torch.Managers.GetManager<PluginManager>();
|
||||||
public static CommandManager? CommandManager => Torch.CurrentSession?.Managers.GetManager<CommandManager>();
|
public static CommandManager? CommandManager => Torch.CurrentSession?.Managers.GetManager<CommandManager>();
|
||||||
|
public static MultiplayerManagerDedicated? MultiplayerManager =>
|
||||||
|
Torch.CurrentSession?.Managers.GetManager<MultiplayerManagerDedicated>();
|
||||||
|
|
||||||
public static ChatModule ChatModule = null!;
|
public static ChatModule ChatModule = null!;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user