2019-02-26 22:25:27 -05:00
|
|
|
|
using IW4MAdmin.Plugins.Stats.Helpers;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2018-06-05 17:31:36 -04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2018-05-28 21:30:31 -04:00
|
|
|
|
using SharedLibraryCore;
|
2019-02-25 20:36:10 -05:00
|
|
|
|
using SharedLibraryCore.Dtos;
|
2018-05-28 21:30:31 -04:00
|
|
|
|
using System;
|
2018-06-05 17:31:36 -04:00
|
|
|
|
using System.Linq;
|
2018-05-28 21:30:31 -04:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using WebfrontCore.Controllers;
|
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin.Plugins.Stats.Web.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class StatsController : BaseController
|
|
|
|
|
{
|
|
|
|
|
[HttpGet]
|
2019-02-26 22:25:27 -05:00
|
|
|
|
public IActionResult TopPlayersAsync()
|
2018-05-28 21:30:31 -04:00
|
|
|
|
{
|
2019-03-24 22:34:20 -04:00
|
|
|
|
ViewBag.Title = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_STATS_INDEX_TITLE"];
|
|
|
|
|
ViewBag.Description = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_STATS_INDEX_DESC"];
|
2019-02-27 21:13:15 -05:00
|
|
|
|
ViewBag.Servers = Manager.GetServers().Select(_server => new ServerInfo() { Name = _server.Hostname, ID = _server.EndPoint });
|
2018-05-28 21:30:31 -04:00
|
|
|
|
|
2019-02-26 22:25:27 -05:00
|
|
|
|
return View("Index");
|
2018-05-28 21:30:31 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2019-02-26 22:25:27 -05:00
|
|
|
|
public async Task<IActionResult> GetTopPlayersAsync(int count, int offset, long? serverId = null)
|
2018-05-28 21:30:31 -04:00
|
|
|
|
{
|
2019-02-26 22:25:27 -05:00
|
|
|
|
// this prevents empty results when we really want aggregate
|
|
|
|
|
if (serverId == 0)
|
|
|
|
|
{
|
|
|
|
|
serverId = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var server = Manager.GetServers().FirstOrDefault(_server => _server.EndPoint == serverId);
|
|
|
|
|
|
|
|
|
|
if (server != null)
|
|
|
|
|
{
|
|
|
|
|
serverId = await StatManager.GetIdForServer(server);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var results = await Plugin.Manager.GetTopStats(offset, count, serverId);
|
|
|
|
|
|
|
|
|
|
// this returns an empty result so we know to stale the loader
|
|
|
|
|
if (results.Count == 0 && offset > 0)
|
|
|
|
|
{
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return View("Components/TopPlayers/_List", results);
|
|
|
|
|
}
|
2018-05-28 21:30:31 -04:00
|
|
|
|
}
|
2018-06-05 17:31:36 -04:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2019-04-08 21:31:32 -04:00
|
|
|
|
public async Task<IActionResult> GetMessageAsync(int serverId, long when)
|
2018-06-05 17:31:36 -04:00
|
|
|
|
{
|
2019-04-08 21:31:32 -04:00
|
|
|
|
var whenTime = DateTime.FromFileTimeUtc(when);
|
|
|
|
|
var whenUpper = whenTime.AddMinutes(5);
|
|
|
|
|
var whenLower = whenTime.AddMinutes(-5);
|
2018-06-05 17:31:36 -04:00
|
|
|
|
|
2018-09-04 22:07:34 -04:00
|
|
|
|
using (var ctx = new SharedLibraryCore.Database.DatabaseContext(true))
|
2018-06-05 17:31:36 -04:00
|
|
|
|
{
|
|
|
|
|
var iqMessages = from message in ctx.Set<Models.EFClientMessage>()
|
|
|
|
|
where message.ServerId == serverId
|
|
|
|
|
where message.TimeSent >= whenLower
|
|
|
|
|
where message.TimeSent <= whenUpper
|
2019-02-26 22:25:27 -05:00
|
|
|
|
select new ChatInfo()
|
2018-06-05 17:31:36 -04:00
|
|
|
|
{
|
2018-09-16 16:34:16 -04:00
|
|
|
|
ClientId = message.ClientId,
|
2018-06-05 17:31:36 -04:00
|
|
|
|
Message = message.Message,
|
|
|
|
|
Name = message.Client.CurrentAlias.Name,
|
|
|
|
|
Time = message.TimeSent
|
|
|
|
|
};
|
|
|
|
|
|
2018-09-16 16:34:16 -04:00
|
|
|
|
#if DEBUG == true
|
|
|
|
|
var messagesSql = iqMessages.ToSql();
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-06-05 17:31:36 -04:00
|
|
|
|
var messages = await iqMessages.ToListAsync();
|
|
|
|
|
|
|
|
|
|
return View("_MessageContext", messages);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2018-09-04 22:07:34 -04:00
|
|
|
|
[Authorize]
|
2018-06-05 17:31:36 -04:00
|
|
|
|
public async Task<IActionResult> GetAutomatedPenaltyInfoAsync(int clientId)
|
|
|
|
|
{
|
2018-09-04 22:07:34 -04:00
|
|
|
|
using (var ctx = new SharedLibraryCore.Database.DatabaseContext(true))
|
2018-06-05 17:31:36 -04:00
|
|
|
|
{
|
2019-03-31 20:56:31 -04:00
|
|
|
|
int linkId = await ctx.Clients
|
|
|
|
|
.Where(_client => _client.ClientId == clientId)
|
|
|
|
|
.Select(_client => _client.AliasLinkId)
|
|
|
|
|
.FirstOrDefaultAsync();
|
|
|
|
|
|
|
|
|
|
var clientIds = await ctx.Clients.Where(_client => _client.AliasLinkId == linkId)
|
|
|
|
|
.Select(_client => _client.ClientId)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
var iqPenaltyInfo = ctx.Set<Models.EFACSnapshot>()
|
|
|
|
|
.Where(s => clientIds.Contains(s.ClientId))
|
2018-06-05 17:31:36 -04:00
|
|
|
|
.Include(s => s.LastStrainAngle)
|
|
|
|
|
.Include(s => s.HitOrigin)
|
|
|
|
|
.Include(s => s.HitDestination)
|
|
|
|
|
.Include(s => s.CurrentViewAngle)
|
|
|
|
|
.Include(s => s.PredictedViewAngles)
|
2018-09-04 22:07:34 -04:00
|
|
|
|
.OrderBy(s => s.When)
|
2019-03-31 20:56:31 -04:00
|
|
|
|
.ThenBy(s => s.Hits);
|
|
|
|
|
|
|
|
|
|
#if DEBUG == true
|
|
|
|
|
var sql = iqPenaltyInfo.ToSql();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
var penaltyInfo = await iqPenaltyInfo.ToListAsync();
|
2018-06-05 17:31:36 -04:00
|
|
|
|
|
2018-09-04 22:07:34 -04:00
|
|
|
|
return View("_PenaltyInfo", penaltyInfo);
|
2018-06-05 17:31:36 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-28 21:30:31 -04:00
|
|
|
|
}
|
|
|
|
|
}
|