Exemplo n.º 1
0
        public async Task <IActionResult> GetAutomatedPenaltyInfoAsync(int clientId)
        {
            using (var ctx = new SharedLibraryCore.Database.DatabaseContext(true))
            {
                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))
                                    .Include(s => s.LastStrainAngle)
                                    .Include(s => s.HitOrigin)
                                    .Include(s => s.HitDestination)
                                    .Include(s => s.CurrentViewAngle)
                                    .Include(s => s.PredictedViewAngles)
                                    .OrderBy(s => s.When)
                                    .ThenBy(s => s.Hits);

#if DEBUG == true
                var sql = iqPenaltyInfo.ToSql();
#endif

                var penaltyInfo = await iqPenaltyInfo.ToListAsync();

                return(View("_PenaltyInfo", penaltyInfo));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetAutomatedPenaltyInfoAsync(int penaltyId)
        {
            using (var ctx = new SharedLibraryCore.Database.DatabaseContext(true))
            {
                var penalty = await ctx.Penalties
                              .Select(_penalty => new { _penalty.OffenderId, _penalty.PenaltyId, _penalty.When, _penalty.AutomatedOffense })
                              .FirstOrDefaultAsync(_penalty => _penalty.PenaltyId == penaltyId);

                if (penalty == null)
                {
                    return(NotFound());
                }

                // todo: this can be optimized
                var iqSnapshotInfo = ctx.Set <Stats.Models.EFACSnapshot>()
                                     .Where(s => s.ClientId == penalty.OffenderId)
                                     .Include(s => s.LastStrainAngle)
                                     .Include(s => s.HitOrigin)
                                     .Include(s => s.HitDestination)
                                     .Include(s => s.CurrentViewAngle)
                                     .Include(s => s.PredictedViewAngles)
                                     .ThenInclude(_angles => _angles.Vector)
                                     .OrderBy(s => s.When)
                                     .ThenBy(s => s.Hits);

                var penaltyInfo = await iqSnapshotInfo.ToListAsync();

                if (penaltyInfo.Count > 0)
                {
                    return(View("_PenaltyInfo", penaltyInfo));
                }

                // 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
                        }
                    }));
                }
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetMessageAsync(int serverId, long when)
        {
            var whenTime  = DateTime.FromFileTimeUtc(when);
            var whenUpper = whenTime.AddMinutes(5);
            var whenLower = whenTime.AddMinutes(-5);

            using (var ctx = new SharedLibraryCore.Database.DatabaseContext(true))
            {
                var iqMessages = from message in ctx.Set <Models.EFClientMessage>()
                                 where message.ServerId == serverId
                                 where message.TimeSent >= whenLower
                                 where message.TimeSent <= whenUpper
                                 select new ChatInfo()
                {
                    ClientId   = message.ClientId,
                    Message    = message.Message,
                    Name       = message.Client.CurrentAlias.Name,
                    Time       = message.TimeSent,
                    ServerGame = message.Server.GameName ?? Server.Game.IW4
                };

#if DEBUG == true
                var messagesSql = iqMessages.ToSql();
#endif
                var messages = await iqMessages.ToListAsync();

                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 { }
                    }
                }

                return(View("_MessageContext", messages));
            }
        }