add kick client functionality to webfront home for issue #142

This commit is contained in:
RaidMax
2020-07-14 14:13:40 -05:00
parent 4c583e1c53
commit 88b1f08149
6 changed files with 84 additions and 24 deletions

View File

@ -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}"
}));
}
}
}

View File

@ -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()
{