add configurable command and broadcast command prefix for issue #149
This commit is contained in:
@ -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}"
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@ -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[]
|
||||
|
@ -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;
|
||||
|
@ -26,7 +26,7 @@
|
||||
<td>@command.Alias</td>
|
||||
<td>@command.Description</td>
|
||||
<td>@command.RequiresTarget</td>
|
||||
<td>!@command.Syntax.Split('!')[1]</td>
|
||||
<td>@ViewBag.CommandPrefix@command.Syntax.Split(@ViewBag.CommandPrefix)[1]</td>
|
||||
<td>@command.Permission.ToLocalizedLevelName()</td>
|
||||
</tr>
|
||||
}
|
||||
@ -62,7 +62,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td scope="row" class="bg-primary">@loc["WEBFRONT_HELP_COMMAND_DESC_SYNTAX"]</td>
|
||||
<td class="bg-dark text-light">!@command.Syntax.Split('!')[1]</td>
|
||||
<td class="bg-dark text-light">@ViewBag.CommandPrefix@command.Syntax.Split(@ViewBag.CommandPrefix)[1]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td scope="row" class="bg-primary" style="border-bottom: #222 1px solid;">@loc["WEBFRONT_HELP_COMMAND_DESC_REQUIRED_LEVEL"]</td>
|
||||
|
@ -6,10 +6,6 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
if (command[0] !== '!') {
|
||||
$('#console_command_response').text(_localization['WEBFRONT_CONSOLE_COMMAND']).addClass('text-danger');
|
||||
return false;
|
||||
}
|
||||
showLoader();
|
||||
$.get('/Console/ExecuteAsync', { serverId: serverId, command: command })
|
||||
.done(function (response) {
|
||||
|
Reference in New Issue
Block a user