IW4M-Admin/WebfrontCore/Controllers/ConsoleController.cs
RaidMax 4caa4655e2 abstracting rcon parsing and event parsing
changed Event to GameEvent
finally fixed the stats NaN
check ip for bans
consolidated console, profile, and logout into dropdown
make sure game is iw4 before using :^ in say
fix pm not showing from name if in web console
show time left of temban on profile
2018-04-13 01:32:30 -05:00

60 lines
1.8 KiB
C#

using Microsoft.AspNetCore.Mvc;
using SharedLibraryCore;
using SharedLibraryCore.Dtos;
using SharedLibraryCore.Objects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebfrontCore.Controllers
{
public class ConsoleController : BaseController
{
public IActionResult Index()
{
var activeServers = Manager.GetServers().Select(s => new ServerInfo()
{
Name = s.Hostname,
ID = s.GetHashCode(),
});
ViewBag.Description = "Use the IW4MAdmin web console to execute commands";
ViewBag.Title = "Web Console";
ViewBag.Keywords = "IW4MAdmin, console, execute, commands";
return View(activeServers);
}
public async Task<IActionResult> ExecuteAsync(int serverId, string command)
{
var server = Manager.GetServers().First(s => s.GetHashCode() == serverId);
var client = new Player()
{
ClientId = User.ClientId,
Level = User.Level,
CurrentServer = server,
CurrentAlias = new Alias() { Name = User.Name }
};
var remoteEvent = new GameEvent()
{
Type = GameEvent.EventType.Say,
Data = command,
Origin = client,
Owner = server
};
await server.ExecuteEvent(remoteEvent);
var 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]);
return View("_Response", response);
}
}
}