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