/// <summary> /// This request provides details on a particular players map info /// </summary> /// <queryParam name="pid" type="int">The unique player ID</queryParam> /// <queryParam name="mapid" type="int">The unique map ID</queryParam> /// <queryParam name="customonly" type="int">Defines whether to only display custom maps</queryParam> /// <queryParam name="mapname" type="string">The unique map's name</queryParam> /// <param name="Client">The HttpClient who made the request</param> /// <param name="Driver">The Stats Database Driver. Connection errors are handled in the calling object</param> public GetMapInfo(HttpClient Client, StatsDatabase Driver) { // Setup Variables int Pid = 0, MapId = 0, CustomOnly = 0; string MapName = ""; SelectQueryBuilder Query = new SelectQueryBuilder(Driver); // Setup QueryString Params if (Client.Request.QueryString.ContainsKey("pid")) Int32.TryParse(Client.Request.QueryString["pid"], out Pid); if (Client.Request.QueryString.ContainsKey("mapid")) Int32.TryParse(Client.Request.QueryString["mapid"], out MapId); if (Client.Request.QueryString.ContainsKey("customonly")) Int32.TryParse(Client.Request.QueryString["customonly"], out CustomOnly); if (Client.Request.QueryString.ContainsKey("mapname")) MapName = Client.Request.QueryString["mapname"].Trim(); // Prepare Response Client.Response.WriteResponseStart(); // Is this a Player Map Request? if (Pid != 0) { // Build our query statement Query.SelectFromTable("maps"); Query.SelectColumns("maps.*", "mapinfo.name AS mapname"); Query.AddJoin(JoinType.InnerJoin, "mapinfo", "id", Comparison.Equals, "maps", "mapid"); Query.AddWhere("maps.id", Comparison.Equals, Pid); Query.AddOrderBy("mapid", Sorting.Ascending); // Execute the reader, and add each map to the output Client.Response.WriteHeaderLine("mapid", "mapname", "time", "win", "loss", "best", "worst"); foreach (Dictionary<string, object> Map in Driver.QueryReader(Query.BuildCommand())) Client.Response.WriteDataLine(Map["mapid"], Map["mapname"], Map["time"], Map["win"], Map["loss"], Map["best"], Map["worst"]); } else { // Build our query statement Query.SelectFromTable("mapinfo"); Query.SelectColumns("id", "name", "score", "time", "times", "kills", "deaths"); Query.AddOrderBy("id", Sorting.Ascending); // Select our where statement if (MapId > 0) Query.AddWhere("id", Comparison.Equals, MapId); else if (!String.IsNullOrEmpty(MapName)) Query.AddWhere("name", Comparison.Equals, MapName); else if (CustomOnly == 1) Query.AddWhere("id", Comparison.GreaterOrEquals, 700); // Execute the reader, and add each map to the output Client.Response.WriteHeaderLine("mapid", "name", "score", "time", "times", "kills", "deaths"); foreach (Dictionary<string, object> Map in Driver.QueryReader(Query.BuildCommand())) Client.Response.WriteDataLine(Map["id"], Map["name"], Map["score"], Map["time"], Map["times"], Map["kills"], Map["deaths"]); } // Send Response Client.Response.Send(); }
/// <summary> /// This method is used to fetch an array of columns we need in our detailed rankings /// page. It also returns in 2 out variables additional data we need to adjust our query /// </summary> /// <param name="action">The Action from our MvcRoute</param> /// <param name="valueIsDecimal">Indicates to the calling method if the Type of return "value" is a decimal</param> private void FinishQuery(string action, SelectQueryBuilder builder, out bool valueIsDecimal) { // Generate our list of columns List<string> Cols = new List<string>() { "player.id AS pid", "name", "rank", "time", "country", "score / (time * 1.0 / 60) AS spm", "(wins * 1.0 / losses) AS wlr", "(kills * 1.0 / deaths) AS kdr", }; // Value Type valueIsDecimal = false; // Additional function switch (action.ToLowerInvariant()) { case "score": Cols.Add("score AS value"); break; case "spm": Cols.Add("score / (time * 1.0 / 60) AS value"); valueIsDecimal = true; break; case "wlr": Cols.Add("(wins * 1.0 / losses) AS value"); valueIsDecimal = true; break; case "kdr": Cols.Add("(kills * 1.0 / deaths) AS value"); valueIsDecimal = true; break; case "knife_kdr": Cols.Add("(weapons.knifekills * 1.0 / weapons.knifedeaths) AS value"); builder.AddJoin(JoinType.InnerJoin, "weapons", "id", Comparison.Equals, "player", "id"); valueIsDecimal = true; break; case "sniper_acc": Cols.Add("(weapons.hit4 * 1.0 / weapons.fired4) AS value"); valueIsDecimal = true; builder.AddJoin(JoinType.InnerJoin, "weapons", "id", Comparison.Equals, "player", "id"); break; case "brs": Cols.Add("rndscore AS value"); break; case "fc": Cols.Add("captures AS value"); break; case "fw": Cols.Add("(captureassists + captures + neutralizes + defends) AS value"); break; case "btw": Cols.Add("teamscore AS value"); break; case "hpd": // Hours Per Day // Timeframe: ((Last Online timstamp - Joined Timestamp) / 1 day (86400 seconds)) Gets the timespan of days played // Divide Timeframe by: hours played (seconds played (`time` column) / 1 hr (3600 seconds)) Cols.Add("(time / 3600.0) / ((lastonline - joined) / 86400.0) AS value"); valueIsDecimal = true; break; case "command": Cols.Add("cmdscore AS value"); break; case "rcmds": Cols.Add("COALESCE((cmdscore * 1.0 / (cmdtime / 60)), 0.0) AS value"); valueIsDecimal = true; break; } builder.SelectColumns(Cols.ToArray()); //builder.WhereStatement.Add("value", Comparison.GreaterThan, 0); builder.AddOrderBy("value", Sorting.Descending); }