1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-13 00:28:10 -05:00

update interactions to allow building custom forms

This commit is contained in:
RaidMax
2022-10-12 21:06:18 -05:00
parent 2e5747af97
commit 8502ae47aa
14 changed files with 191 additions and 118 deletions

View File

@ -1,22 +1,19 @@
using Microsoft.AspNetCore.Mvc;
using SharedLibraryCore;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Dtos;
using SharedLibraryCore.Interfaces;
using System.Linq;
using System.Threading.Tasks;
using Data.Models;
namespace WebfrontCore.Controllers
{
public class ConsoleController : BaseController
{
private readonly ApplicationConfiguration _appconfig;
private readonly IRemoteCommandService _remoteCommandService;
public ConsoleController(IManager manager) : base(manager)
public ConsoleController(IManager manager, IRemoteCommandService remoteCommandService) : base(manager)
{
_appconfig = manager.GetApplicationSettings().Configuration();
_remoteCommandService = remoteCommandService;
}
public IActionResult Index()
@ -37,75 +34,8 @@ namespace WebfrontCore.Controllers
public async Task<IActionResult> Execute(long serverId, string command)
{
var server = Manager.GetServers().First(s => s.EndPoint == serverId);
var client = new EFClient
{
ClientId = Client.ClientId,
Level = Client.Level,
NetworkId = Client.NetworkId,
CurrentServer = server,
CurrentAlias = new EFAlias()
{
Name = Client.Name
}
};
var remoteEvent = new GameEvent
{
Type = GameEvent.EventType.Command,
Data = command.StartsWith(_appconfig.CommandPrefix) ||
command.StartsWith(_appconfig.BroadcastCommandPrefix)
? command
: $"{_appconfig.CommandPrefix}{command}",
Origin = client,
Owner = server,
IsRemote = true
};
Manager.AddEvent(remoteEvent);
CommandResponseInfo[] response = null;
try
{
// wait for the event to process
var completedEvent =
await remoteEvent.WaitAsync(Utilities.DefaultCommandTimeout, server.Manager.CancellationToken);
if (completedEvent.FailReason == GameEvent.EventFailReason.Timeout)
{
response = new[]
{
new CommandResponseInfo()
{
ClientId = client.ClientId,
Response = Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_COMMAND_TIMEOUT"]
}
};
}
else
{
response = completedEvent.Output.Select(output => new CommandResponseInfo()
{
Response = output,
ClientId = client.ClientId
}).ToArray();
}
}
catch (System.OperationCanceledException)
{
response = new[]
{
new CommandResponseInfo
{
ClientId = client.ClientId,
Response = Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_RESTART_SUCCESS"]
}
};
}
return remoteEvent.Failed ? StatusCode(400, response) : Ok(response);
var response = await _remoteCommandService.Execute(Client.ClientId, null, command, Enumerable.Empty<string>(), server);
return response.Any() ? StatusCode(400, response) : Ok(response);
}
}
}