2018-02-23 02:06:13 -05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore;
|
2018-11-05 22:01:29 -05:00
|
|
|
|
using SharedLibraryCore.Database.Models;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore.Dtos;
|
2018-02-23 02:06:13 -05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace WebfrontCore.Controllers
|
|
|
|
|
{
|
2018-03-06 02:22:19 -05:00
|
|
|
|
public class ConsoleController : BaseController
|
2018-02-23 02:06:13 -05:00
|
|
|
|
{
|
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
2018-04-08 14:48:40 -04:00
|
|
|
|
var activeServers = Manager.GetServers().Select(s => new ServerInfo()
|
2018-02-23 02:06:13 -05:00
|
|
|
|
{
|
|
|
|
|
Name = s.Hostname,
|
2018-11-27 19:31:48 -05:00
|
|
|
|
ID = s.EndPoint,
|
2018-02-23 02:06:13 -05:00
|
|
|
|
});
|
|
|
|
|
|
2018-03-13 17:30:22 -04:00
|
|
|
|
ViewBag.Description = "Use the IW4MAdmin web console to execute commands";
|
2018-05-05 18:52:04 -04:00
|
|
|
|
ViewBag.Title = Localization["WEBFRONT_CONSOLE_TITLE"];
|
2018-03-13 17:30:22 -04:00
|
|
|
|
ViewBag.Keywords = "IW4MAdmin, console, execute, commands";
|
|
|
|
|
|
2018-02-23 02:06:13 -05:00
|
|
|
|
return View(activeServers);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-27 19:31:48 -05:00
|
|
|
|
public async Task<IActionResult> ExecuteAsync(long serverId, string command)
|
2018-02-23 02:06:13 -05:00
|
|
|
|
{
|
2018-11-27 19:31:48 -05:00
|
|
|
|
var server = Manager.GetServers().First(s => s.EndPoint == serverId);
|
|
|
|
|
|
2018-11-05 22:01:29 -05:00
|
|
|
|
var client = new EFClient()
|
2018-04-05 00:38:45 -04:00
|
|
|
|
{
|
2018-04-26 02:13:04 -04:00
|
|
|
|
ClientId = Client.ClientId,
|
|
|
|
|
Level = Client.Level,
|
2018-04-13 02:32:30 -04:00
|
|
|
|
CurrentServer = server,
|
2018-12-01 13:17:53 -05:00
|
|
|
|
CurrentAlias = new EFAlias()
|
|
|
|
|
{
|
|
|
|
|
Name = Client.Name
|
|
|
|
|
}
|
2018-04-13 02:32:30 -04:00
|
|
|
|
};
|
2018-04-29 16:44:04 -04:00
|
|
|
|
|
2018-04-13 02:32:30 -04:00
|
|
|
|
var remoteEvent = new GameEvent()
|
|
|
|
|
{
|
2018-05-10 01:34:29 -04:00
|
|
|
|
Type = GameEvent.EventType.Command,
|
2018-04-13 02:32:30 -04:00
|
|
|
|
Data = command,
|
|
|
|
|
Origin = client,
|
2018-04-14 00:51:38 -04:00
|
|
|
|
Owner = server,
|
|
|
|
|
Remote = true
|
2018-04-05 00:38:45 -04:00
|
|
|
|
};
|
2018-02-23 02:06:13 -05:00
|
|
|
|
|
2018-04-26 02:13:04 -04:00
|
|
|
|
Manager.GetEventHandler().AddEvent(remoteEvent);
|
2018-09-06 14:25:58 -04:00
|
|
|
|
List<CommandResponseInfo> response;
|
2018-04-26 02:13:04 -04:00
|
|
|
|
// wait for the event to process
|
2018-10-02 13:39:08 -04:00
|
|
|
|
if (!(await remoteEvent.WaitAsync(60 * 1000)).Failed)
|
2018-09-06 14:25:58 -04:00
|
|
|
|
{
|
|
|
|
|
response = server.CommandResult.Where(c => c.ClientId == client.ClientId).ToList();
|
|
|
|
|
|
|
|
|
|
// remove the added command response
|
|
|
|
|
for (int i = 0; i < response.Count; i++)
|
2018-12-01 13:17:53 -05:00
|
|
|
|
{
|
2018-09-06 14:25:58 -04:00
|
|
|
|
server.CommandResult.Remove(response[i]);
|
2018-12-01 13:17:53 -05:00
|
|
|
|
}
|
2018-09-06 14:25:58 -04:00
|
|
|
|
}
|
2018-02-23 02:06:13 -05:00
|
|
|
|
|
2018-09-06 14:25:58 -04:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
response = new List<CommandResponseInfo>()
|
|
|
|
|
{
|
|
|
|
|
new CommandResponseInfo()
|
|
|
|
|
{
|
|
|
|
|
ClientId = client.ClientId,
|
|
|
|
|
Response = Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_COMMAND_TIMEOUT"]
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-02-23 02:06:13 -05:00
|
|
|
|
|
|
|
|
|
return View("_Response", response);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|