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-03-06 02:22:19 -05:00
|
|
|
|
var activeServers = Manager.Servers.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-02-23 02:06:13 -05:00
|
|
|
|
ViewBag.Title = "Web Console";
|
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-03-06 02:22:19 -05:00
|
|
|
|
var server = Manager.Servers.First(s => s.GetHashCode() == serverId);
|
2018-04-05 00:38:45 -04:00
|
|
|
|
var client = new Player()
|
|
|
|
|
{
|
|
|
|
|
ClientId = User.ClientId,
|
|
|
|
|
Level = User.Level,
|
|
|
|
|
CurrentServer = server
|
|
|
|
|
};
|
2018-04-04 15:38:34 -04:00
|
|
|
|
|
|
|
|
|
var remoteEvent = new Event(Event.GType.Say, command, client, null, server);
|
2018-02-23 02:06:13 -05:00
|
|
|
|
|
|
|
|
|
await server.ExecuteEvent(remoteEvent);
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|