add kick client functionality to webfront home for issue #142
This commit is contained in:
parent
4c583e1c53
commit
88b1f08149
@ -15,7 +15,7 @@ var plugin = {
|
||||
eventParser = manager.GenerateDynamicEventParser(this.name);
|
||||
|
||||
rconParser.Configuration.StatusHeader.Pattern = 'num +score +ping +playerid +steamid +name +lastmsg +address +qport +rate *';
|
||||
rconParser.Configuration.Status.Pattern = '^ *([0-9]+) +-?([0-9]+) +((?:[A-Z]+|[0-9]+)) +((?:[a-z]|[0-9]){16,32}|(?:[a-z]|[0-9]){32}|bot[0-9]+) ([0-9+]) *(.{0,32}) +([0-9]+) +(\\d+\\.\\d+\\.\\d+.\\d+\\:-*\\d{1,5}|0+.0+:-*\\d{1,5}|loopback) +(-*[0-9]+) +([0-9]+) *$'
|
||||
rconParser.Configuration.Status.Pattern = '^ *([0-9]+) +-?([0-9]+) +((?:[A-Z]+|[0-9]+)) +((?:[a-z]|[0-9]{16,32})|bot[0-9]+) ([0-9]+) +(.{0,32}) +([0-9]+) +(\\d+\\.\\d+\\.\\d+.\\d+\\:-*\\d{1,5}|0+.0+:-*\\d{1,5}|loopback) +(-*[0-9]+) +([0-9]+) *$';
|
||||
rconParser.Configuration.Status.AddMapping(104, 6); // RConName
|
||||
rconParser.Configuration.Status.AddMapping(105, 8); // RConIPAddress
|
||||
|
||||
|
@ -329,5 +329,48 @@ namespace WebfrontCore.Controllers
|
||||
command = $"!unflag @{targetId} {reason}"
|
||||
}));
|
||||
}
|
||||
|
||||
public IActionResult KickForm(int id)
|
||||
{
|
||||
var info = new ActionInfo()
|
||||
{
|
||||
ActionButtonLabel = Localization["WEBFRONT_ACTION_KICK_NAME"],
|
||||
Name = "Kick",
|
||||
Inputs = new List<InputInfo>()
|
||||
{
|
||||
new InputInfo()
|
||||
{
|
||||
Name = "reason",
|
||||
Label = Localization["WEBFRONT_ACTION_LABEL_REASON"],
|
||||
},
|
||||
new InputInfo()
|
||||
{
|
||||
Name = "targetId",
|
||||
Type = "hidden",
|
||||
Value = id.ToString()
|
||||
}
|
||||
},
|
||||
Action = "KickAsync",
|
||||
ShouldRefresh = true
|
||||
};
|
||||
|
||||
return View("_ActionForm", info);
|
||||
}
|
||||
|
||||
public async Task<IActionResult> KickAsync(int targetId, string reason)
|
||||
{
|
||||
var client = Manager.GetActiveClients().FirstOrDefault(_client => _client.ClientId == targetId);
|
||||
|
||||
if (client == null)
|
||||
{
|
||||
return BadRequest(Localization["WEBFRONT_ACTION_KICK_DISCONNECT"]);
|
||||
}
|
||||
|
||||
return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new
|
||||
{
|
||||
serverId = client.CurrentServer.EndPoint,
|
||||
command = $"!kick {client.ClientNumber} {reason}"
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,26 +57,16 @@ namespace WebfrontCore.Controllers
|
||||
};
|
||||
|
||||
Manager.AddEvent(remoteEvent);
|
||||
List<CommandResponseInfo> response = null;
|
||||
CommandResponseInfo[] response = null;
|
||||
|
||||
try
|
||||
{
|
||||
var completedEvent = await remoteEvent.WaitAsync(Utilities.DefaultCommandTimeout, server.Manager.CancellationToken);
|
||||
// wait for the event to process
|
||||
if (!completedEvent.Failed)
|
||||
var completedEvent = await remoteEvent.WaitAsync(Utilities.DefaultCommandTimeout, server.Manager.CancellationToken);
|
||||
|
||||
if (completedEvent.FailReason == GameEvent.EventFailReason.Timeout)
|
||||
{
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
else if (completedEvent.FailReason == GameEvent.EventFailReason.Timeout)
|
||||
{
|
||||
response = new List<CommandResponseInfo>()
|
||||
response = new[]
|
||||
{
|
||||
new CommandResponseInfo()
|
||||
{
|
||||
@ -85,11 +75,22 @@ namespace WebfrontCore.Controllers
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
response = response = server.CommandResult.Where(c => c.ClientId == client.ClientId).ToArray();
|
||||
}
|
||||
|
||||
// remove the added command response
|
||||
for (int i = 0; i < response?.Length; i++)
|
||||
{
|
||||
server.CommandResult.Remove(response[i]);
|
||||
}
|
||||
}
|
||||
|
||||
catch (System.OperationCanceledException)
|
||||
{
|
||||
response = new List<CommandResponseInfo>()
|
||||
response = new[]
|
||||
{
|
||||
new CommandResponseInfo()
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
@model List<SharedLibraryCore.Dtos.CommandResponseInfo>
|
||||
@model IEnumerable<SharedLibraryCore.Dtos.CommandResponseInfo>
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
|
@ -52,10 +52,19 @@
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ViewBag.Authorized)
|
||||
{
|
||||
<div class="oi oi-circle-x text-danger mr-1 d-md-none profile-action" data-action="kick" data-action-id="@Model.Players[i].ClientId" aria-hidden="true"></div>
|
||||
}
|
||||
string levelColorClass = !ViewBag.Authorized ? "" : $"level-color-{Model.Players[i].LevelInt}";
|
||||
<a asp-controller="Client" asp-action="ProfileAsync" asp-route-id="@Model.Players[i].ClientId" class="@levelColorClass">
|
||||
<color-code value="@Model.Players[i].Name" allow="@ViewBag.EnableColorCodes"></color-code>
|
||||
</a>
|
||||
if (ViewBag.Authorized)
|
||||
{
|
||||
<div class="oi oi-circle-x text-danger ml-1 d-none d-md-inline-flex profile-action" data-action="kick" data-action-id="@Model.Players[i].ClientId" aria-hidden="true"></div>
|
||||
}
|
||||
<br />
|
||||
}
|
||||
}
|
||||
@ -68,10 +77,15 @@
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string levelColorClass = !ViewBag.Authorized ? "" : $"level-color-{Model.Players[i].LevelInt}";
|
||||
<a asp-controller="Client" asp-action="ProfileAsync" asp-route-id="@Model.Players[i].ClientId" class="@levelColorClass">
|
||||
<color-code value="@Model.Players[i].Name" allow="@ViewBag.EnableColorCodes"></color-code>
|
||||
</a>
|
||||
if (ViewBag.Authorized)
|
||||
{
|
||||
<div class="oi oi-circle-x text-danger ml-1 profile-action" data-action="kick" data-action-id="@Model.Players[i].ClientId" aria-hidden="true"></div>
|
||||
}
|
||||
<br />
|
||||
}
|
||||
}
|
||||
@ -112,8 +126,9 @@
|
||||
<span class="text-light">
|
||||
<color-code value="@Model.ChatHistory[i].Name" allow="@ViewBag.EnableColorCodes"></color-code>
|
||||
</span>
|
||||
<span> —
|
||||
<color-code value="@Model.ChatHistory[i].Message.CapClientName(48)" allow="@ViewBag.EnableColorCodes"></color-code>
|
||||
<span>
|
||||
—
|
||||
<color-code value="@Model.ChatHistory[i].Message.CapClientName(48)" allow="@ViewBag.EnableColorCodes"></color-code>
|
||||
</span><br />
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,8 @@ $(document).ready(function () {
|
||||
/*
|
||||
* handle action modal
|
||||
*/
|
||||
$('.profile-action').click(function (e) {
|
||||
$(document).off('click', '.profile-action');
|
||||
$(document).on('click', '.profile-action', function (e) {
|
||||
const actionType = $(this).data('action');
|
||||
const actionId = $(this).data('action-id');
|
||||
const actionIdKey = actionId === undefined ? '' : '?id=' + actionId;
|
||||
@ -43,7 +44,7 @@ $(document).ready(function () {
|
||||
})
|
||||
.fail(function (jqxhr, textStatus, error) {
|
||||
$('#actionModal .modal-body-content').html('');
|
||||
$('#actionModal .modal-message').text('Error — ' + error);
|
||||
$('#actionModal .modal-message').text(_localization['GLOBAL_ERROR'] + ' — ' + jqxhr.responseText);
|
||||
$('#actionModal').modal();
|
||||
$('#actionModal .modal-message').fadeIn('fast');
|
||||
});
|
||||
@ -78,10 +79,10 @@ $(document).ready(function () {
|
||||
$('#actionModal .modal-message').fadeOut('fast');
|
||||
}
|
||||
if (jqxhr.status === 401) {
|
||||
$('#actionModal .modal-message').text('Invalid login credentials');
|
||||
$('#actionModal .modal-message').text(_localization['WEBFRONT_ACTION_CREDENTIALS']);
|
||||
}
|
||||
else {
|
||||
$('#actionModal .modal-message').text('Error — ' + error);
|
||||
$('#actionModal .modal-message').text(_localization['GLOBAL_ERROR'] + ' — ' + jqxhr.responseText);
|
||||
}
|
||||
$('#actionModal .modal-message').fadeIn('fast');
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user