ban/unban buttons added to profile

several css tweaks
changed administratorIPs to PrivilegedClients
added time step references to profile page
This commit is contained in:
RaidMax 2018-03-26 23:54:20 -05:00
parent 979b1f2310
commit a07ce112b0
18 changed files with 349 additions and 57 deletions

View File

@ -68,11 +68,6 @@ namespace StatsPlugin.Cheat
double avg = AverageHitOffset / (float)avgcnt;
}
/*r = distance,
x = playerX + r*cos(yaw)*cos(pitch),
y = playerY + r*sin(yaw)*cos(pitch)
z = playerZ + r*sin(360-pitch)*/
#endregion
#region SESSION_RATIOS

View File

@ -25,7 +25,7 @@ namespace IW4MAdmin
{
private List<Server> _servers;
public List<Server> Servers => _servers.OrderByDescending(s => s.ClientNum).ToList();
public List<int> AdministratorIPs { get; set; }
public Dictionary<int, int> PrivilegedClients { get; set; }
public ILogger Logger { get; private set; }
public bool Running { get; private set; }
public EventHandler<Event> ServerEventOccurred { get; private set; }
@ -54,7 +54,7 @@ namespace IW4MAdmin
ClientSvc = new ClientService();
AliasSvc = new AliasService();
PenaltySvc = new PenaltyService();
AdministratorIPs = new List<int>();
PrivilegedClients = new Dictionary<int, int>();
ServerEventOccurred += EventAPI.OnServerEventOccurred;
ConfigHandler = new BaseConfigurationHandler<ApplicationConfiguration>("IW4MAdminSettings");
}
@ -77,9 +77,21 @@ namespace IW4MAdmin
public async Task Init()
{
#region DATABASE
AdministratorIPs = (await ClientSvc.Find(c => c.Level > Player.Permission.Trusted))
.Select(c => c.IPAddress)
.ToList();
var ipList = (await ClientSvc.Find(c => c.Level > Player.Permission.Trusted))
.Select(c => new { c.IPAddress, c.ClientId });
foreach (var a in ipList)
{
try
{
PrivilegedClients.Add(a.IPAddress, a.ClientId);
}
catch (ArgumentException)
{
continue;
}
}
#endregion
#region CONFIG

View File

@ -302,7 +302,7 @@ namespace IW4MAdmin
string escapedName = Regex.Escape(E.Target.Name);
var reg = new Regex($"(\"{escapedName}\")|({escapedName})", RegexOptions.IgnoreCase);
E.Data = reg.Replace(E.Data, "", 1).Trim();
if (E.Data.Length == 0 && C.RequiredArgumentCount > 1)
{
await E.Origin.Tell($"Not enough arguments supplied!");
@ -479,8 +479,8 @@ namespace IW4MAdmin
playerCountStart = DateTime.Now;
}
if (LastMessage.TotalSeconds > Manager.GetApplicationSettings().Configuration().AutoMessagePeriod
&& BroadcastMessages.Count > 0
if (LastMessage.TotalSeconds > Manager.GetApplicationSettings().Configuration().AutoMessagePeriod
&& BroadcastMessages.Count > 0
&& ClientNum > 0)
{
await Broadcast(Utilities.ProcessMessageToken(Manager.GetMessageTokens(), BroadcastMessages[NextMessage]));
@ -658,7 +658,7 @@ namespace IW4MAdmin
LogFile = new IFile(logPath);
//#else
}
LogFile = new RemoteFile("https://raidmax.org/IW4MAdmin/getlog.php");
LogFile = new RemoteFile("https://raidmax.org/IW4MAdmin/getlog.php");
//#endif
Logger.WriteInfo($"Log file is {logPath}");
#if !DEBUG
@ -775,9 +775,13 @@ namespace IW4MAdmin
CurrentMap = Maps.Find(m => m.Name == mapname) ?? new Map() { Alias = mapname, Name = mapname };
// todo: make this more efficient
((ApplicationManager)(Manager)).AdministratorIPs = (await new GenericRepository<EFClient>().FindAsync(c => c.Level > Player.Permission.Trusted))
.Select(c => c.IPAddress)
.ToList();
((ApplicationManager)(Manager)).PrivilegedClients = new Dictionary<int, int>();
var ClientSvc = new ClientService();
var ipList = (await ClientSvc.Find(c => c.Level > Player.Permission.Trusted))
.Select(c => new { c.IPAddress, c.ClientId });
foreach (var a in ipList)
((ApplicationManager)(Manager)).PrivilegedClients.Add(a.IPAddress, a.ClientId);
}
if (E.Type == Event.GType.MapEnd)
@ -887,11 +891,10 @@ namespace IW4MAdmin
return;
}
}
#if !DEBUG
else
await Target.CurrentServer.ExecuteCommandAsync($"clientkick {Target.ClientNumber } \"^7Player Temporarily Banned: ^5{ Reason }\"");
#if DEBUG
#else
await Target.CurrentServer.RemovePlayer(Target.ClientNumber);
#endif
@ -933,8 +936,9 @@ namespace IW4MAdmin
{
// this is set only because they're still in the server.
Target.Level = Player.Permission.Banned;
#if !DEBUG
await Target.CurrentServer.ExecuteCommandAsync($"clientkick {Target.ClientNumber} \"Player Banned: ^5{Message} ^7(appeal at {Website}) ^7\"");
#if DEBUG
#else
await Target.CurrentServer.RemovePlayer(Target.ClientNumber);
#endif
}

View File

@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using SharedLibrary;
using WebfrontCore.ViewModels;
namespace WebfrontCore.Controllers
{
public class ActionController : BaseController
{
public IActionResult BanForm()
{
var info = new ActionInfo()
{
ActionButtonLabel = "Ban",
Name = "Ban",
Inputs = new List<InputInfo>()
{
new InputInfo()
{
Name = "Reason",
Placeholder = ""
}
},
Action = "BanAsync"
};
return View("_ActionForm", info);
}
public async Task<IActionResult> BanAsync(int targetId, string Reason)
{
var server = Manager.GetServers().First();
return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new
{
serverId = server.GetHashCode(),
command = $"!ban @{targetId} {Reason}"
}));
}
public IActionResult UnbanForm()
{
var info = new ActionInfo()
{
ActionButtonLabel = "Unban",
Name = "Unban",
Inputs = new List<InputInfo>()
{
new InputInfo()
{
Name = "Reason",
Placeholder = ""
}
},
Action = "UnbanAsync"
};
return View("_ActionForm", info);
}
public async Task<IActionResult> UnbanAsync(int targetId, string Reason)
{
var server = Manager.GetServers().First();
return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new
{
serverId = server.GetHashCode(),
command = $"!unban @{targetId} {Reason}"
}));
}
}
}

View File

@ -2,11 +2,8 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using SharedLibrary;
using SharedLibrary.Interfaces;
using System;
using SharedLibrary.Database.Models;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebfrontCore.Controllers
{
@ -14,19 +11,36 @@ namespace WebfrontCore.Controllers
{
protected ApplicationManager Manager;
protected bool Authorized { get; private set; }
protected EFClient User { get; private set; }
public override void OnActionExecuting(ActionExecutingContext context)
{
Manager = IW4MAdmin.Program.ServerManager;
Authorized = context.HttpContext.Connection.RemoteIpAddress.ToString() == "127.0.0.1" ||
Manager.AdministratorIPs.Contains(context.HttpContext.Connection.RemoteIpAddress.ToString().ConvertToIP());
User = new EFClient()
{
ClientId = -1
};
try
{
User.ClientId = Manager.PrivilegedClients[context.HttpContext.Connection.RemoteIpAddress.ToString().ConvertToIP()];
}
catch (KeyNotFoundException)
{
}
Authorized = context.HttpContext.Connection.RemoteIpAddress.ToString() == "127.0.0.1" ||
User.ClientId >= 0;
ViewBag.Authorized = Authorized;
ViewBag.Url = Startup.Configuration["Web:Address"];
string inviteLink = Manager.GetApplicationSettings().Configuration().DiscordInviteCode;
if (inviteLink != null)
ViewBag.DiscordLink = inviteLink.Contains("https") ? inviteLink : $"https://discordapp.com/invite/{inviteLink}";
else
ViewBag.DiscorLink = "";
ViewBag.DiscordLink = "";
base.OnActionExecuting(context);
}
}

View File

@ -41,7 +41,7 @@ namespace WebfrontCore.Controllers
IPAddress = intIP
};
#else
var origin = (await Manager.GetClientService().GetUnique(0)).AsPlayer();
var origin = (await Manager.GetClientService().GetUnique(0)).AsPlayer();
#endif
var server = Manager.Servers.First(s => s.GetHashCode() == serverId);

View File

@ -15,8 +15,18 @@ namespace WebfrontCore.ViewComponents
int ip = HttpContext.Connection.RemoteIpAddress
.ToString().ConvertToIP();
bool authed = IW4MAdmin.ApplicationManager.GetInstance()
.AdministratorIPs.Contains(ip);
bool authed = false;
try
{
var a = IW4MAdmin.ApplicationManager.GetInstance()
.PrivilegedClients[HttpContext.Connection.RemoteIpAddress.ToString().ConvertToIP()];
}
catch (KeyNotFoundException)
{
}
var penalties = await IW4MAdmin.ApplicationManager.GetInstance().GetPenaltyService().GetRecentPenalties(15, offset);
var penaltiesDto = penalties.Select(p => new PenaltyInfo()

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebfrontCore.ViewModels
{
public class ActionInfo
{
public string Name { get; set; }
public List<InputInfo> Inputs { get; set; }
public string ActionButtonLabel { get; set; }
public string Action { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebfrontCore.ViewModels
{
public class InputInfo
{
public string Name { get; set; }
public string Placeholder { get; set; }
public string Type { get; set; }
public string Value { get; set; }
}
}

View File

@ -0,0 +1,22 @@
@model WebfrontCore.ViewModels.ActionInfo
@{
Layout = null;
}
<form class="action-form" action="/Action/@Model.Action">
<div class="input-group mb-3">
@foreach (var input in Model.Inputs)
{
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon-@input.Name">@input.Name</span>
</div>
{
string inputType = input.Type ?? "text";
string value = input.Value ?? "";
<input type="@inputType" name="@input.Name" value="@value" class="form-control" placeholder="@input.Placeholder" aria-label="@input.Name" aria-describedby="basic-addon-@input.Name">
}
}
</div>
<button type="submit" class="btn btn-block btn-primary">@Model.ActionButtonLabel</button>
</form>

View File

@ -26,12 +26,12 @@
if (Model.Level == SharedLibrary.Objects.Player.Permission.User.ToString())
{
<span id="profile_action_ban_btn" class="oi oi-ban text-danger" title="ban" aria-hidden="true"></span>
<span id="profile_action_ban_btn" class="profile-action oi oi-ban text-danger" title="Ban Client" data-action="ban" aria-hidden="true"></span>
}
if (Model.Level == SharedLibrary.Objects.Player.Permission.Banned.ToString())
{
<span id="profile_action_unban_btn" class="iconic iconic-carriage-return text-success" title="carriage return" aria-hidden="true"></span>
<span id="profile_action_unban_btn" class="profile-action oi oi-action-undo text-success" title="carriage return" data-action="unban" aria-hidden="true"></span>
}
}
}
@ -85,6 +85,10 @@
</div>
</div>
@section targetid {
<input type="hidden" name="targetId" value="@Model.ClientId" />
}
@section scripts {
<script>
const clientInfo = {};

View File

@ -61,6 +61,30 @@
</div>
</div>
<!-- Action Modal -->
<div class="modal fade" id="actionModal" tabindex="-1" role="dialog" aria-labelledby="actionModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content bg-dark">
<div class="modal-header">
<h5 class="modal-title" id="actionModalLabel">IW4MAdmin</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true" class="text-danger">&times;</span>
</button>
</div>
<div class="modal-body">
</div>
<!--<div class="modal-footer">
<button type="button" class="btn btn-primary">Action</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
</div>-->
</div>
</div>
</div>
<div id="target_id">
@RenderSection("targetid", required: false);
</div>
<!-- End Action Modal -->
<div class="container pt-0 pb-4 pl-4 pr-4">
@RenderBody()
<footer></footer>

View File

@ -75,4 +75,20 @@ a.link-inverse:hover {
border-color: $primary;
border-left: 0;
border-right: 0;
}
.close {
text-shadow: none !important;
}
.modal-footer {
border-top-color: $orange;
}
.modal-header {
border-bottom-color: $orange;
}
form * {
border-radius: 0 !important;
}

View File

@ -70,10 +70,6 @@
color: white;
}
.profile-meta-entry {
}
.penalties-color-kick,
.penalties-color-unban {
color: rgba(116, 147, 99, 1);
@ -101,22 +97,20 @@
#profile_aliases_btn {
position: relative;
top: auto;
margin-top: 0.7em;
top: -2px;
font-size: 0.5em;
color: rgb(0, 122, 204);
cursor: pointer;
}
#profile_aliases_btn:hover {
color: white;
opacity: 0.75;
cursor: pointer;
}
#profile_aliases {
position: relative;
display: none;
}
#profile_avatar {
@ -141,19 +135,26 @@
border-bottom: 2px rgb(0, 122, 204) solid;
}
.profile-event-timestep {
font-size: 1.25rem;
}
#profile_level > span.level {
color: rgba(236, 130, 222, 0.69);
font-weight: bold;
font-weight: bold;
}
#profile_wrapper {
border-bottom: 2px rgb(0, 122, 204) solid;
}
#profile_name {
.profile-action {
font-size: 0.5em;
padding-left: 0.25em;
cursor: pointer;
top: -2px !important;
}
#profile_info > .text-muted {
.profile-action:hover{
opacity: 0.75;
}

View File

@ -22,7 +22,7 @@ $(document).ready(function () {
count++;
return false;
}
count++
count++;
}
});
@ -68,12 +68,44 @@ $(document).ready(function () {
});
/*
* handle action modal
*/
$('.profile-action').click(function (e) {
const actionType = $(this).data('action');
$.get('/Action/' + actionType + 'Form')
.done(function (response) {
$('#actionModal .modal-body').html(response);
$('#actionModal').modal();
})
.fail(function (jqxhr, textStatus, error) {
$('#actionModal .modal-body').html('<span class="text-danger">' + error + '</span>');
$('#actionModal').modal();
});
});
/*
* handle action submit
*/
$(document).on('submit', '.action-form', function (e) {
e.preventDefault();
$(this).append($('#target_id input'));
const data = $(this).serialize();
$.get($(this).attr('action') + '/?' + data)
.done(function (response) {
$('#actionModal .modal-body').html(response);
$('#actionModal').modal();
})
.fail(function (jqxhr, textStatus, error) {
$('#actionModal .modal-body').html('<span class="text-danger">Error' + error + '</span>');
});
});
});
function penaltyToName(penaltyName) {
switch (penaltyName) {
case "Flag":
return "Flagged"
return "Flagged";
case "Warning":
return "Warned";
case "Report":
@ -89,15 +121,56 @@ function penaltyToName(penaltyName) {
}
}
function shouldIncludePlural(num) {
return num > 1 ? 's' : '';
}
let mostRecentDate = 0;
let currentStepAmount = 0;
let lastStep = "";
function timeStep(stepDifference) {
let hours = (stepDifference / (1000 * 60 * 60));
let days = (stepDifference / (1000 * 60 * 60 * 24));
let weeks = (stepDifference / (1000 * 60 * 60 * 24 * 7));
if (Math.round(weeks) > Math.round(currentStepAmount / 24 * 7)) {
currentStepAmount = Math.round(weeks);
return `${currentStepAmount} week${shouldIncludePlural(currentStepAmount)} ago`;
}
if (Math.round(days) > Math.round(currentStepAmount / 24)) {
currentStepAmount = Math.round(days);
return `${currentStepAmount} day${shouldIncludePlural(currentStepAmount)} ago`;
}
if (Math.round(hours) > currentStepAmount) {
currentStepAmount = Math.round(hours);
return `${currentStepAmount} hour${shouldIncludePlural(currentStepAmount)} ago`;
}
}
function loadMeta(meta) {
let eventString = '';
const metaDate = Date.parse(meta.when);
if (mostRecentDate === 0) {
mostRecentDate = metaDate;
}
const step = timeStep(new Date().getTime() - metaDate);
if (step !== lastStep) {
$('#profile_events').append('<span class="p2 text-white profile-event-timestep"><span class="text-primary">&mdash;</span> ' + step + '</span>');
lastStep = step;
}
// it's a penalty
if (meta.class.includes("Penalty")) {
if (meta.value.punisherId !== clientInfo.clientId) {
eventString = `<div><span class="penalties-color-${meta.value.type.toLowerCase()}">${penaltyToName(meta.value.type)}</span> by <span class="text-highlight"> <a class="link-inverse" href="${meta.value.punisherId}">${meta.value.punisherName}</a></span > for <span style="color: white; ">${meta.value.offense}</span> ${meta.whenString} ago </div>`;
eventString = `<div><span class="penalties-color-${meta.value.type.toLowerCase()}">${penaltyToName(meta.value.type)}</span> by <span class="text-highlight"> <a class="link-inverse" href="${meta.value.punisherId}">${meta.value.punisherName}</a></span > for <span style="color: white; ">${meta.value.offense}</span></div>`;
}
else {
eventString = `<div><span class="penalties-color-${meta.value.type.toLowerCase()}">${penaltyToName(meta.value.type)} </span> <span class="text-highlight"><a class="link-inverse" href="${meta.value.offenderId}"> ${meta.value.offenderName}</a></span > for <span style="color: white; ">${meta.value.offense}</span> ${meta.whenString} ago </div>`;
eventString = `<div><span class="penalties-color-${meta.value.type.toLowerCase()}">${penaltyToName(meta.value.type)} </span> <span class="text-highlight"><a class="link-inverse" href="${meta.value.offenderId}"> ${meta.value.offenderName}</a></span > for <span style="color: white; ">${meta.value.offense}</span></div>`;
}
}
// it's a message

View File

@ -22,7 +22,7 @@
lineThickness: 0,
tickThickness: 0,
margin: 0,
valueFormatString: " ",
valueFormatString: " "
},
axisY: {
gridThickness: 0,
@ -31,19 +31,19 @@
minimum: 0,
margin: 0,
valueFormatString: " ",
labelMaxWidth: 0,
labelMaxWidth: 0
},
legend: {
maxWidth: 0,
maxHeight: 0,
dockInsidePlotArea: true,
dockInsidePlotArea: true
},
data: [{
showInLegend: false,
type: "splineArea",
color: "rgba(0, 122, 204, 0.432)",
markerSize: 0,
dataPoints: playerHistory,
dataPoints: playerHistory
}]
});
//////////////////////////////////////
@ -63,9 +63,9 @@ $(window).resize(function () {
$('.server-history-row').each(function (index) {
let serverId = $(this).data('serverid');
charts[serverId].options.width = $('.server-header').first().width();
charts[serverId].render()
charts[serverId].render();
});
})
});
function refreshClientActivity() {
$('.server-history-row').each(function (index) {

View File

@ -6085,3 +6085,15 @@ a.link-inverse:hover {
border-left: 0;
border-right: 0; }
.close {
text-shadow: none !important; }
.modal-footer {
border-top-color: #fd7e14; }
.modal-header {
border-bottom-color: #fd7e14; }
form * {
border-radius: 0 !important; }

File diff suppressed because one or more lines are too long