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)
|
|
|
|
|
{
|
2019-08-23 19:34:31 -04:00
|
|
|
|
serverId = StatManager.GetIdForServer(server);
|
2019-02-26 22:25:27 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
2019-04-23 18:27:20 -04:00
|
|
|
|
Time = message.TimeSent,
|
|
|
|
|
ServerGame = message.Server.GameName ?? Server.Game.IW4
|
2018-06-05 17:31:36 -04:00
|
|
|
|
};
|
|
|
|
|
|
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();
|
|
|
|
|
|
2019-04-23 18:27:20 -04:00
|
|
|
|
foreach (var message in messages)
|
|
|
|
|
{
|
|
|
|
|
if (message.Message.IsQuickMessage())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var quickMessages = Manager.GetApplicationSettings().Configuration()
|
|
|
|
|
.QuickMessages
|
|
|
|
|
.First(_qm => _qm.Game == message.ServerGame);
|
|
|
|
|
message.Message = quickMessages.Messages[message.Message.Substring(1)];
|
|
|
|
|
message.IsQuickMessage = true;
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-05 17:31:36 -04:00
|
|
|
|
return View("_MessageContext", messages);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2018-09-04 22:07:34 -04:00
|
|
|
|
[Authorize]
|
2019-08-06 14:36:37 -04:00
|
|
|
|
public async Task<IActionResult> GetAutomatedPenaltyInfoAsync(int penaltyId)
|
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
|
|
|
|
{
|
2019-08-06 14:36:37 -04:00
|
|
|
|
var penalty = await ctx.Penalties
|
|
|
|
|
.Select(_penalty => new { _penalty.OffenderId, _penalty.PenaltyId, _penalty.When, _penalty.AutomatedOffense })
|
|
|
|
|
.FirstOrDefaultAsync(_penalty => _penalty.PenaltyId == penaltyId);
|
2019-03-31 20:56:31 -04:00
|
|
|
|
|
2019-08-06 14:36:37 -04:00
|
|
|
|
var iqSnapshotInfo = ctx.Set<Models.EFACSnapshot>()
|
|
|
|
|
.Where(s => s.ClientId == penalty.OffenderId)
|
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)
|
2019-09-09 18:40:04 -04:00
|
|
|
|
.ThenInclude(_angles => _angles.Vector)
|
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
|
2019-08-06 14:36:37 -04:00
|
|
|
|
var sql = iqSnapshotInfo.ToSql();
|
2019-03-31 20:56:31 -04:00
|
|
|
|
#endif
|
2019-08-06 14:36:37 -04:00
|
|
|
|
var penaltyInfo = await iqSnapshotInfo.ToListAsync();
|
2019-03-31 20:56:31 -04:00
|
|
|
|
|
2019-08-06 14:36:37 -04:00
|
|
|
|
if (penaltyInfo.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
return View("_PenaltyInfo", penaltyInfo);
|
|
|
|
|
}
|
2018-06-05 17:31:36 -04:00
|
|
|
|
|
2019-08-06 14:36:37 -04:00
|
|
|
|
// we want to show anything related to the automated offense
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return View("_MessageContext", new[]
|
|
|
|
|
{
|
|
|
|
|
new ChatInfo()
|
|
|
|
|
{
|
|
|
|
|
ClientId = penalty.OffenderId,
|
|
|
|
|
Message = penalty.AutomatedOffense,
|
|
|
|
|
Time = penalty.When
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-06-05 17:31:36 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-28 21:30:31 -04:00
|
|
|
|
}
|
|
|
|
|
}
|