add configurable command and broadcast command prefix for issue #149

This commit is contained in:
RaidMax
2020-07-31 20:40:03 -05:00
parent 6155493181
commit 04a95aa58a
27 changed files with 403 additions and 61 deletions

View File

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SharedLibraryCore;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Interfaces;
using WebfrontCore.ViewModels;
using static SharedLibraryCore.Database.Models.EFClient;
@ -13,9 +14,11 @@ namespace WebfrontCore.Controllers
{
public class ActionController : BaseController
{
private readonly ApplicationConfiguration _appConfig;
public ActionController(IManager manager) : base(manager)
{
_appConfig = manager.GetApplicationSettings().Configuration();
}
public IActionResult BanForm()
@ -80,8 +83,8 @@ namespace WebfrontCore.Controllers
}
string command = Duration == 6 ?
$"!ban @{targetId} {Reason}" :
$"!tempban @{targetId} {duration} {Reason}";
$"{_appConfig.CommandPrefix}ban @{targetId} {Reason}" :
$"{_appConfig.CommandPrefix}tempban @{targetId} {duration} {Reason}";
var server = Manager.GetServers().First();
@ -120,7 +123,7 @@ namespace WebfrontCore.Controllers
return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new
{
serverId = server.EndPoint,
command = $"!unban @{targetId} {Reason}"
command = $"{_appConfig.CommandPrefix}unban @{targetId} {Reason}"
}));
}
@ -189,7 +192,7 @@ namespace WebfrontCore.Controllers
return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new
{
serverId = server.EndPoint,
command = $"!setlevel @{targetId} {level}"
command = $"{_appConfig.CommandPrefix}setlevel @{targetId} {level}"
}));
}
@ -256,7 +259,7 @@ namespace WebfrontCore.Controllers
return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new
{
serverId = server.EndPoint,
command = $"!say {message}"
command = $"{_appConfig.CommandPrefix}say {message}"
}));
}
@ -294,7 +297,7 @@ namespace WebfrontCore.Controllers
return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new
{
serverId = server.EndPoint,
command = $"!flag @{targetId} {reason}"
command = $"{_appConfig.CommandPrefix}flag @{targetId} {reason}"
}));
}
@ -326,7 +329,7 @@ namespace WebfrontCore.Controllers
return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new
{
serverId = server.EndPoint,
command = $"!unflag @{targetId} {reason}"
command = $"{_appConfig.CommandPrefix}unflag @{targetId} {reason}"
}));
}
@ -369,7 +372,7 @@ namespace WebfrontCore.Controllers
return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new
{
serverId = client.CurrentServer.EndPoint,
command = $"!kick {client.ClientNumber} {reason}"
command = $"{_appConfig.CommandPrefix}kick {client.ClientNumber} {reason}"
}));
}
}

View File

@ -1,9 +1,9 @@
using Microsoft.AspNetCore.Mvc;
using SharedLibraryCore;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Dtos;
using SharedLibraryCore.Interfaces;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@ -11,9 +11,11 @@ namespace WebfrontCore.Controllers
{
public class ConsoleController : BaseController
{
private readonly ApplicationConfiguration _appconfig;
public ConsoleController(IManager manager) : base(manager)
{
_appconfig = manager.GetApplicationSettings().Configuration();
}
public IActionResult Index()
@ -50,7 +52,8 @@ namespace WebfrontCore.Controllers
var remoteEvent = new GameEvent()
{
Type = GameEvent.EventType.Command,
Data = command,
Data = command.StartsWith(_appconfig.CommandPrefix) || command.StartsWith(_appconfig.BroadcastCommandPrefix) ?
command : $"{_appconfig.CommandPrefix}{command}",
Origin = client,
Owner = server,
IsRemote = true
@ -63,7 +66,7 @@ namespace WebfrontCore.Controllers
{
// wait for the event to process
var completedEvent = await remoteEvent.WaitAsync(Utilities.DefaultCommandTimeout, server.Manager.CancellationToken);
if (completedEvent.FailReason == GameEvent.EventFailReason.Timeout)
{
response = new[]

View File

@ -61,6 +61,7 @@ namespace WebfrontCore.Controllers
{
ViewBag.IsFluid = true;
ViewBag.Title = Localization["WEBFRONT_NAV_HELP"];
ViewBag.CommandPrefix = Manager.GetApplicationSettings().Configuration().CommandPrefix;
// we don't need to the name of the shared library assembly
var excludedAssembly = typeof(BaseController).Assembly;