2018-02-23 02:06:13 -05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore;
|
2020-07-31 21:40:03 -04:00
|
|
|
|
using SharedLibraryCore.Configuration;
|
2018-11-05 22:01:29 -05:00
|
|
|
|
using SharedLibraryCore.Database.Models;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore.Dtos;
|
2019-12-02 16:52:36 -05:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2018-02-23 02:06:13 -05:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
using Data.Models;
|
2018-02-23 02:06:13 -05:00
|
|
|
|
|
|
|
|
|
namespace WebfrontCore.Controllers
|
|
|
|
|
{
|
2018-03-06 02:22:19 -05:00
|
|
|
|
public class ConsoleController : BaseController
|
2018-02-23 02:06:13 -05:00
|
|
|
|
{
|
2020-07-31 21:40:03 -04:00
|
|
|
|
private readonly ApplicationConfiguration _appconfig;
|
|
|
|
|
|
2019-12-02 16:52:36 -05:00
|
|
|
|
public ConsoleController(IManager manager) : base(manager)
|
|
|
|
|
{
|
2020-07-31 21:40:03 -04:00
|
|
|
|
_appconfig = manager.GetApplicationSettings().Configuration();
|
2019-12-02 16:52:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
|
2021-01-08 20:21:23 -05:00
|
|
|
|
ViewBag.Description = Localization["WEFBRONT_DESCRIPTION_CONSOLE"];
|
2018-05-05 18:52:04 -04:00
|
|
|
|
ViewBag.Title = Localization["WEBFRONT_CONSOLE_TITLE"];
|
2021-01-08 20:21:23 -05:00
|
|
|
|
ViewBag.Keywords = Localization["WEBFRONT_KEYWORDS_CONSOLE"];
|
2018-03-13 17:30:22 -04:00
|
|
|
|
|
2018-02-23 02:06:13 -05:00
|
|
|
|
return View(activeServers);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
public async Task<IActionResult> Execute(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);
|
|
|
|
|
|
2022-04-19 19:43:58 -04: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,
|
2019-01-03 15:39:22 -05:00
|
|
|
|
NetworkId = Client.NetworkId,
|
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
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
var remoteEvent = new GameEvent
|
2018-04-13 02:32:30 -04:00
|
|
|
|
{
|
2018-05-10 01:34:29 -04:00
|
|
|
|
Type = GameEvent.EventType.Command,
|
2021-01-17 22:58:18 -05:00
|
|
|
|
Data = command.StartsWith(_appconfig.CommandPrefix) ||
|
|
|
|
|
command.StartsWith(_appconfig.BroadcastCommandPrefix)
|
|
|
|
|
? command
|
|
|
|
|
: $"{_appconfig.CommandPrefix}{command}",
|
2018-04-13 02:32:30 -04:00
|
|
|
|
Origin = client,
|
2018-04-14 00:51:38 -04:00
|
|
|
|
Owner = server,
|
2019-01-03 15:39:22 -05:00
|
|
|
|
IsRemote = true
|
2018-04-05 00:38:45 -04:00
|
|
|
|
};
|
2018-02-23 02:06:13 -05:00
|
|
|
|
|
2020-05-04 17:50:02 -04:00
|
|
|
|
Manager.AddEvent(remoteEvent);
|
2020-07-14 15:13:40 -04:00
|
|
|
|
CommandResponseInfo[] response = null;
|
2019-05-17 10:02:09 -04:00
|
|
|
|
|
|
|
|
|
try
|
2018-09-06 14:25:58 -04:00
|
|
|
|
{
|
2019-05-17 10:02:09 -04:00
|
|
|
|
// wait for the event to process
|
2021-01-17 22:58:18 -05:00
|
|
|
|
var completedEvent =
|
|
|
|
|
await remoteEvent.WaitAsync(Utilities.DefaultCommandTimeout, server.Manager.CancellationToken);
|
2020-07-31 21:40:03 -04:00
|
|
|
|
|
2020-07-14 15:13:40 -04:00
|
|
|
|
if (completedEvent.FailReason == GameEvent.EventFailReason.Timeout)
|
2019-05-17 10:02:09 -04:00
|
|
|
|
{
|
2020-07-14 15:13:40 -04:00
|
|
|
|
response = new[]
|
2019-05-17 10:02:09 -04:00
|
|
|
|
{
|
2019-07-21 18:14:44 -04:00
|
|
|
|
new CommandResponseInfo()
|
|
|
|
|
{
|
|
|
|
|
ClientId = client.ClientId,
|
|
|
|
|
Response = Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_COMMAND_TIMEOUT"]
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-12-01 13:17:53 -05:00
|
|
|
|
}
|
2020-07-14 15:13:40 -04:00
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-01-17 22:58:18 -05:00
|
|
|
|
response = completedEvent.Output.Select(output => new CommandResponseInfo()
|
|
|
|
|
{
|
|
|
|
|
Response = output,
|
|
|
|
|
ClientId = client.ClientId
|
|
|
|
|
}).ToArray();
|
2020-07-14 15:13:40 -04:00
|
|
|
|
}
|
2018-09-06 14:25:58 -04:00
|
|
|
|
}
|
2018-02-23 02:06:13 -05:00
|
|
|
|
|
2019-05-17 10:02:09 -04:00
|
|
|
|
catch (System.OperationCanceledException)
|
2018-09-06 14:25:58 -04:00
|
|
|
|
{
|
2020-07-14 15:13:40 -04:00
|
|
|
|
response = new[]
|
2018-09-06 14:25:58 -04:00
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
new CommandResponseInfo
|
2018-09-06 14:25:58 -04:00
|
|
|
|
{
|
|
|
|
|
ClientId = client.ClientId,
|
2019-05-17 10:02:09 -04:00
|
|
|
|
Response = Utilities.CurrentLocalization.LocalizationIndex["COMMADS_RESTART_SUCCESS"]
|
2018-09-06 14:25:58 -04:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-04-19 19:43:58 -04:00
|
|
|
|
|
|
|
|
|
return remoteEvent.Failed ? StatusCode(400, response) : Ok(response);
|
2018-02-23 02:06:13 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-19 19:43:58 -04:00
|
|
|
|
}
|