2018-02-23 02:06:13 -05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Dtos;
|
|
|
|
|
using SharedLibraryCore.Objects;
|
2018-02-23 02:06:13 -05:00
|
|
|
|
using System;
|
|
|
|
|
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,
|
|
|
|
|
ID = s.GetHashCode(),
|
|
|
|
|
});
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> ExecuteAsync(int serverId, string command)
|
|
|
|
|
{
|
2018-04-08 14:48:40 -04:00
|
|
|
|
var server = Manager.GetServers().First(s => s.GetHashCode() == serverId);
|
2018-04-05 00:38:45 -04:00
|
|
|
|
var client = new Player()
|
|
|
|
|
{
|
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-04-28 21:11:13 -04:00
|
|
|
|
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);
|
|
|
|
|
// wait for the event to process
|
2018-05-10 01:34:29 -04:00
|
|
|
|
await Task.Run(() => remoteEvent.OnProcessed.Wait(5000));
|
2018-04-04 15:38:34 -04:00
|
|
|
|
var response = server.CommandResult.Where(c => c.ClientId == client.ClientId).ToList();
|
2018-02-23 02:06:13 -05:00
|
|
|
|
|
|
|
|
|
// remove the added command response
|
|
|
|
|
for (int i = 0; i < response.Count; i++)
|
|
|
|
|
server.CommandResult.Remove(response[i]);
|
|
|
|
|
|
|
|
|
|
return View("_Response", response);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|