implement players section
This commit is contained in:
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<ChatController>()
|
||||
.WithController<PluginsController>()
|
||||
.WithController<PluginDownloadsController>())
|
||||
.WithController<PluginDownloadsController>()
|
||||
.WithController<PlayersController>())
|
||||
.WithModule(new LogsModule("/api/live/logs", true))
|
||||
.WithModule(chatModule)
|
||||
.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 PluginManager PluginManager => Torch.Managers.GetManager<PluginManager>();
|
||||
public static CommandManager? CommandManager => Torch.CurrentSession?.Managers.GetManager<CommandManager>();
|
||||
public static MultiplayerManagerDedicated? MultiplayerManager =>
|
||||
Torch.CurrentSession?.Managers.GetManager<MultiplayerManagerDedicated>();
|
||||
|
||||
public static ChatModule ChatModule = null!;
|
||||
}
|
||||
|
Reference in New Issue
Block a user