2018-02-21 20:29:23 -05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-10-07 22:34:30 -04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore;
|
2018-10-07 22:34:30 -04:00
|
|
|
|
using SharedLibraryCore.Database;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore.Database.Models;
|
|
|
|
|
using SharedLibraryCore.Dtos;
|
|
|
|
|
using SharedLibraryCore.Services;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using WebfrontCore.ViewComponents;
|
2019-03-31 20:56:31 -04:00
|
|
|
|
using static SharedLibraryCore.Objects.Penalty;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
|
|
|
|
|
namespace WebfrontCore.Controllers
|
|
|
|
|
{
|
2018-03-06 02:22:19 -05:00
|
|
|
|
public class PenaltyController : BaseController
|
2018-02-21 20:29:23 -05:00
|
|
|
|
{
|
2019-03-31 20:56:31 -04:00
|
|
|
|
public IActionResult List(PenaltyType showOnly = PenaltyType.Any)
|
2018-02-21 20:29:23 -05:00
|
|
|
|
{
|
2018-03-13 17:30:22 -04:00
|
|
|
|
ViewBag.Description = "List of all the recent penalties (bans, kicks, warnings) on IW4MAdmin";
|
2018-05-05 18:52:04 -04:00
|
|
|
|
ViewBag.Title = Localization["WEBFRONT_PENALTY_TITLE"];
|
2018-03-13 17:30:22 -04:00
|
|
|
|
ViewBag.Keywords = "IW4MAdmin, penalties, ban, kick, warns";
|
|
|
|
|
|
2019-05-02 23:33:38 -04:00
|
|
|
|
return View(showOnly);
|
2018-02-21 20:29:23 -05:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-31 20:56:31 -04:00
|
|
|
|
public async Task<IActionResult> ListAsync(int offset = 0, PenaltyType showOnly = PenaltyType.Any)
|
2018-02-21 20:29:23 -05:00
|
|
|
|
{
|
2018-05-04 00:22:10 -04:00
|
|
|
|
return await Task.FromResult(View("_List", new ViewModels.PenaltyFilterInfo()
|
|
|
|
|
{
|
|
|
|
|
Offset = offset,
|
2019-03-31 20:56:31 -04:00
|
|
|
|
ShowOnly = showOnly
|
2018-05-04 00:22:10 -04:00
|
|
|
|
}));
|
2018-02-21 20:29:23 -05:00
|
|
|
|
}
|
2018-03-13 17:30:22 -04:00
|
|
|
|
|
2019-03-24 22:34:20 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// retrieves all permanent bans ordered by ban date
|
|
|
|
|
/// if request is authorized, it will include the client's ip address.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2018-03-13 17:30:22 -04:00
|
|
|
|
public async Task<IActionResult> PublicAsync()
|
|
|
|
|
{
|
2019-03-24 22:34:20 -04:00
|
|
|
|
IList<PenaltyInfo> penalties;
|
2018-10-07 22:34:30 -04:00
|
|
|
|
|
|
|
|
|
using (var ctx = new DatabaseContext(disableTracking: true))
|
|
|
|
|
{
|
2019-03-24 22:34:20 -04:00
|
|
|
|
// todo: this seems like it's pulling unnecessary info from LINQ to entities.
|
|
|
|
|
var iqPenalties = ctx.Penalties
|
2019-03-27 20:40:26 -04:00
|
|
|
|
.AsNoTracking()
|
2019-03-31 20:56:31 -04:00
|
|
|
|
.Where(p => p.Type == PenaltyType.Ban && p.Active)
|
2019-03-24 22:34:20 -04:00
|
|
|
|
.OrderByDescending(_penalty => _penalty.When)
|
|
|
|
|
.Select(p => new PenaltyInfo()
|
|
|
|
|
{
|
|
|
|
|
Id = p.PenaltyId,
|
|
|
|
|
OffenderId = p.OffenderId,
|
2019-03-27 20:40:26 -04:00
|
|
|
|
OffenderName = p.Offender.CurrentAlias.Name,
|
|
|
|
|
OffenderNetworkId = (ulong)p.Offender.NetworkId,
|
|
|
|
|
OffenderIPAddress = Authorized ? p.Offender.CurrentAlias.IPAddress.ConvertIPtoString() : null,
|
2019-03-24 22:34:20 -04:00
|
|
|
|
Offense = p.Offense,
|
|
|
|
|
PunisherId = p.PunisherId,
|
2019-03-27 20:40:26 -04:00
|
|
|
|
PunisherNetworkId = (ulong)p.Punisher.NetworkId,
|
|
|
|
|
PunisherName = p.Punisher.CurrentAlias.Name,
|
|
|
|
|
PunisherIPAddress = Authorized ? p.Punisher.CurrentAlias.IPAddress.ConvertIPtoString() : null,
|
2019-03-31 20:56:31 -04:00
|
|
|
|
TimePunished = p.When,
|
2019-03-27 20:40:26 -04:00
|
|
|
|
AutomatedOffense = Authorized ? p.AutomatedOffense : null,
|
2019-03-24 22:34:20 -04:00
|
|
|
|
});
|
|
|
|
|
#if DEBUG == true
|
|
|
|
|
var querySql = iqPenalties.ToSql();
|
|
|
|
|
#endif
|
2018-03-13 17:30:22 -04:00
|
|
|
|
|
2019-03-24 22:34:20 -04:00
|
|
|
|
penalties = await iqPenalties.ToListAsync();
|
|
|
|
|
}
|
2018-03-13 17:30:22 -04:00
|
|
|
|
|
2019-03-24 22:34:20 -04:00
|
|
|
|
return Json(penalties);
|
2018-03-13 17:30:22 -04:00
|
|
|
|
}
|
2018-02-21 20:29:23 -05:00
|
|
|
|
}
|
|
|
|
|
}
|