private void ShowRankingType(MvcRoute Route)
        {
            // Create our model
            RankingsTypeModel Model = new RankingsTypeModel(Client);
            Model.UrlName = Route.Action;
            string CacheName = $"rankings_{Route.Action}_1";

            // Parse our country and page filters based on URL
            // Url formats:
            // - scoreType/country/pageNumber
            // - scoreType/pageNumber
            if (Route.Params.Length == 1)
            {
                if (Int32.TryParse(Route.Params[0], out Model.CurrentPage))
                {
                    // Just a page number provided
                    CacheName = $"rankings_{Route.Action}_{Model.CurrentPage}";
                }
                else if (Route.Params[0].Length == 2)
                {
                    // Just a country code provided, default to page 1
                    Model.Country = Route.Params[0];
                    CacheName = $"rankings_{Route.Action}_{Model.Country}_1";
                }
            }
            else if (Route.Params.Length == 2 && Int32.TryParse(Route.Params[1], out Model.CurrentPage))
            {
                if (Route.Params[0].Length == 2) // Check valid country code
                {
                    Model.Country = Route.Params[0];
                    CacheName = $"rankings_{Route.Action}_{Model.Country}_{Model.CurrentPage}";
                }
                else
                    CacheName = $"rankings_{Route.Action}_{Model.CurrentPage}";
            }

            // Check the cache file
            if (!base.CacheFileExpired(CacheName, 30))
            {
                base.SendCachedResponse(CacheName);
                return;
            }

            // NOTE: The HttpServer will handle the DbConnectException
            using (StatsDatabase Database = new StatsDatabase())
            {
                // Get our DISTINCT country list from our player pool
                SelectQueryBuilder builder = new SelectQueryBuilder(Database);
                builder.SelectColumn("country");
                builder.Distinct = true;
                builder.SelectFromTable("player");
                builder.AddWhere("country", Comparison.NotEqualTo, "xx");
                foreach (var Row in builder.ExecuteQuery())
                    Model.CountryList.Add(Row["country"].ToString());

                // Start building our player query
                builder = new SelectQueryBuilder(Database);
                builder.SelectCount();
                builder.SelectFromTable("player");
                WhereClause Where = builder.AddWhere("score", Comparison.GreaterOrEquals, 1);

                // Add country filter
                if (Model.Country.Length == 2)
                    Where.AddClause(LogicOperator.And, "country", Comparison.Equals, Model.Country);

                // Hpd additional Where
                if (Route.Action.Equals("hpd", StringComparison.InvariantCultureIgnoreCase))
                    Where.AddClause(LogicOperator.And, "time", Comparison.GreaterOrEquals, 3600);

                // Get our total records
                Model.TotalRecords = builder.ExecuteScalar<int>();
                Model.TotalPages = 1 + (Model.TotalRecords / PlayersPerPage);
                Model.ScoreHeader = GetHeaderName(Route.Action);

                // Now, Build Query that will select the players, not just the count
                bool isDecimal = false;
                FinishQuery(Route.Action, builder, out isDecimal);

                // Get our players, limiting to 50 and starting by page
                builder.Limit(PlayersPerPage, (Model.CurrentPage * PlayersPerPage) - PlayersPerPage);
                var Rows = builder.ExecuteQuery();

                // Initialize records based on records returned from Database
                Model.Records = new List<RankingsTypeModel.PlayerRow>(Rows.Count);
                foreach (Dictionary<string, object> Player in Rows)
                {
                    Model.Records.Add(new RankingsTypeModel.PlayerRow()
                    {
                        Pid = Int32.Parse(Player["pid"].ToString()),
                        Name = Player["name"].ToString(),
                        Rank = Int32.Parse(Player["rank"].ToString()),
                        Country = Player["country"].ToString(),
                        Time = Int32.Parse(Player["time"].ToString()),
                        ScorePerMin = Double.Parse(Player["spm"].ToString()),
                        KillDeathRatio = Double.Parse(Player["kdr"].ToString()),
                        WinLossRatio = Double.Parse(Player["wlr"].ToString()),
                        ScoreValue = (isDecimal)
                            ? String.Format(CultureInfo.InvariantCulture, "{0:n4}", Player["value"])
                            : String.Format(CultureInfo.InvariantCulture, "{0:n0}", Player["value"])
                    });
                }
            }

            // Send response
            base.SendTemplateResponse("rankings_type", typeof(RankingsTypeModel), Model, CacheName);
        }
        public override void HandleRequest()
        {
            // Setup Params
            if (!Request.QueryString.ContainsKey("nick"))
            {
                Response.WriteResponseStart(false);
                Response.WriteHeaderLine("asof", "err");
                Response.WriteDataLine(DateTime.UtcNow.ToUnixTimestamp(), "Invalid Syntax!");
                Response.Send();
                return;
            }

            // NOTE: The HttpServer will handle the DbConnectException
            using (Database = new StatsDatabase())
            {
                // Setup local vars
                int i = 0;
                string Nick = Request.QueryString["nick"];
                string Sort = (Request.QueryString.ContainsKey("sort")) ? Request.QueryString["sort"] : "a";
                string Where = (Request.QueryString.ContainsKey("where")) ? Request.QueryString["where"] : "a";

                // Timestamp Header
                Response.WriteResponseStart();
                Response.WriteHeaderLine("asof");
                Response.WriteDataLine(DateTime.UtcNow.ToUnixTimestamp());

                // Build our query builder
                SelectQueryBuilder builder = new SelectQueryBuilder(Database);
                builder.SelectColumns("id", "name", "score");
                builder.SelectFromTable("player");
                builder.Limit(20);

                // Where statement for our query
                switch (Where.ToLowerInvariant())
                {
                    default:
                    case "a": // Any
                        builder.AddWhere("name", Comparison.Like, "%" + Nick + "%");
                        break;
                    case "b": // Begins With
                        builder.AddWhere("name", Comparison.Like, "%" + Nick);
                        break;
                    case "e": // Ends With
                        builder.AddWhere("name", Comparison.Like, Nick + "%");
                        break;
                    case "x": // Exactly
                        builder.AddWhere("name", Comparison.Equals, Nick);
                        break;
                }

                // Add sorting (a = ascending, r = reverse (descending))
                if (Sort.Equals("r", StringComparison.InvariantCultureIgnoreCase))
                    builder.AddOrderBy("name", Sorting.Descending);
                else
                    builder.AddOrderBy("name", Sorting.Ascending);

                // Output status
                Response.WriteHeaderLine("n", "pid", "nick", "score");
                foreach (Dictionary<string, object> Player in builder.ExecuteQuery())
                {
                    Response.WriteDataLine(++i, Player["id"], Player["name"].ToString().Trim(), Player["score"]);
                }

                // Send Response
                Response.Send();
            }
        }