Пример #1
0
        public ActionResult Delete()
        {
            var playerIsAdmin           = _playerAdminChecker.IsAdmin(PlayerId);
            var recordedGames           = _gameRecordingsGetter.GetRecordedGames().OrderByDescending(x => x.StartTimeSeconds);
            var deletableGameRecordings = new List <IDeletableGameRecording>();
            var bkaDatas = _bkaDataGetter.Get().ToList();

            foreach (var recordedGame in recordedGames)
            {
                var gameRecordings = _gameRecordingsGetter.Get(recordedGame.ServerName, recordedGame.StartTimeSeconds);
                foreach (var gameRecording in gameRecordings)
                {
                    var userMayDelete = playerIsAdmin || gameRecording.PlayerId.Equals(PlayerId);
                    if (userMayDelete)
                    {
                        var bkaData = bkaDatas.SingleOrDefault(x => x.PlayerId.Equals(gameRecording.PlayerId));
                        var game    = _gamesGetter.Get(recordedGame.ServerName, recordedGame.StartTimeSeconds);
                        deletableGameRecordings.Add(new DeletableGameRecording(game, gameRecording.PlayerId, bkaData));
                    }
                }
            }
            return(View(new RecordingsDeleteViewModel {
                DeletableGameRecordings = deletableGameRecordings
            }));
        }
        public ActionResult Manage()
        {
            var bkaData = _bkaDataGetter.Get(PlayerId);

            ViewData["bkaData"] = bkaData;
            return(View());
        }
Пример #3
0
        protected override string GetResponseJson(string realmName, HttpRequest request, MySqlConnection connection)
        {
            var     trackId     = request["t"];
            var     buildNumber = request["b"];
            var     playerId    = request["i"];
            var     className   = request["c"];
            decimal seconds     = 0;

            using (var command = new MySqlCommand {
                Connection = connection
            })
            {
                command.CommandText = "select min(seconds) as seconds from laps where trackid = @TrackId and buildNumber = @BuildNumber and playerid = @PlayerId and className = @ClassName;";
                command.Prepare();
                command.Parameters.AddWithValue("@TrackId", trackId);
                command.Parameters.AddWithValue("@BuildNumber", buildNumber);
                command.Parameters.AddWithValue("@PlayerId", playerId);
                command.Parameters.AddWithValue("@ClassName", className);
                var secondsResult = command.ExecuteScalar();
                if (secondsResult != null && secondsResult != DBNull.Value)
                {
                    seconds = Convert.ToDecimal(secondsResult);
                }
            }
            decimal bestSeconds       = 0;
            var     bestPlayerBkaName = string.Empty;

            using (var command = new MySqlCommand {
                Connection = connection
            })
            {
                command.CommandText = "select playerid, min(seconds) as seconds from laps where trackid = @TrackId and buildNumber = @BuildNumber and className = @ClassName group by playerid order by 2 limit 1;";
                command.Prepare();
                command.Parameters.AddWithValue("@TrackId", trackId);
                command.Parameters.AddWithValue("@BuildNumber", buildNumber);
                command.Parameters.AddWithValue("@ClassName", className);
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var bestPlayerId = reader.GetInt64("playerid");
                        var bkaData      = _bkaDataGetter.Get(bestPlayerId);
                        if (!string.IsNullOrWhiteSpace(bkaData?.Bka))
                        {
                            bestPlayerBkaName = bkaData.Bka;
                        }

                        bestSeconds = reader.GetDecimal("seconds");
                    }
                }
            }
            var result = JsonConvert.SerializeObject(new Dictionary <string, object> {
                { "success", true }, { "seconds", seconds }, { "bestSeconds", bestSeconds }, { "bestBkaName", bestPlayerBkaName }
            });

            return(result);
        }
Пример #4
0
        public ViewResult Index()
        {
            var tracks           = _tracksGetter.Get().ToList();
            var laps             = _lapsGetter.Get().ToList();
            var bkaDatas         = _bkaDataGetter.Get().ToList();
            var lapDisplayModels = _lapAdapter.AdaptForBka(laps, bkaDatas, tracks);

            return(View(new LapsIndexViewModel {
                Tracks = tracks.Where(x => laps.Any(y => y.TrackId.Equals(x.Id))), Laps = lapDisplayModels
            }));
        }
Пример #5
0
        public ActionResult Index(long?id)
        {
            if (id.HasValue)
            {
                if (id != PlayerId && !_playerAdminChecker.IsAdmin(PlayerId))
                {
                    throw new Exception("Disallowed request.");
                }
            }
            else
            {
                id = PlayerId;
            }
            var bkaData     = _bkaDataGetter.Get(id.Value);
            var bka         = bkaData != null ? bkaData.Bka : string.Empty;
            var karmaDeltas = _karmaGetter.Get("ns2", id.Value);

            return(View(new KarmaViewModel {
                PlayerId = id.Value, Bka = bka, Deltas = karmaDeltas
            }));
        }
Пример #6
0
        public ActionResult Watch(string serverName, double startTimeSeconds)
        {
            var cameraOptions  = new List <SelectListItem>();
            var gameRecordings = _gameRecordingsGetter.Get(serverName, startTimeSeconds);

            foreach (var gameRecording in gameRecordings)
            {
                var bkaData = _bkaDataGetter.Get(gameRecording.PlayerId);
                if (!string.IsNullOrWhiteSpace(bkaData?.Bka))
                {
                    var    playedGame     = _playedGamesGetter.Get("ns2", gameRecording.PlayerId).SingleOrDefault(x => x.ServerName.Equals(serverName) && x.StartTimeSeconds.Equals(startTimeSeconds));
                    string cameraTeamInfo = null;
                    if (playedGame != null)
                    {
                        if (playedGame.GameMode == "ns2")
                        {
                            var team = playedGame.MarineSeconds > playedGame.AlienSeconds ? "M" : "A";
                            var comm = playedGame.CommanderSeconds > playedGame.DurationInSeconds / 2 ? "C" : string.Empty;
                            cameraTeamInfo = $"{team}{comm}";
                        }
                    }
                    else
                    {
                        cameraTeamInfo = "S";
                    }
                    var cameraDisplay = $"{bkaData.Bka}";
                    if (!string.IsNullOrWhiteSpace(cameraTeamInfo))
                    {
                        cameraDisplay = $"{cameraDisplay} ({cameraTeamInfo})";
                    }
                    cameraOptions.Add(new SelectListItem {
                        Value = gameRecording.VideoIdentifier, Text = cameraDisplay
                    });
                }
            }
            return(View(new RecordingWatchViewModel {
                CameraOptions = cameraOptions
            }));
        }