/// <summary> /// This request provides details of the leaderboard /// </summary> /// <queryParam name="pid" type="int">The unique player ID</queryParam> /// <queryParam name ="nick" type="string">Unique player nickname</queryParam> /// <queryParam name="type" type="string">"score", "kit", "vehicle", "weapon"</queryParam> /// <queryParam name="id" type="int|string (score)">the various fetch variables (kit ids, vehicle id's etc etc)</queryParam> /// <queryParam name="before" type="int">The number of players before</queryParam> /// <queryParam name="after" type="int">The number of players after</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 GetLeaderBoard(HttpClient Client, StatsDatabase Database) { // Set internal variables this.Response = Client.Response; this.QueryString = Client.Request.QueryString; this.Driver = Database; // We need a type! if (!QueryString.ContainsKey("type")) { Response.WriteResponseStart(false); Response.WriteHeaderLine("asof", "err"); Response.WriteDataLine(DateTime.UtcNow.ToUnixTimestamp(), "Invalid Syntax!"); Response.Send(); return; } // Setup Params if(QueryString.ContainsKey("pid")) Int32.TryParse(QueryString["pid"], out Pid); if (QueryString.ContainsKey("id")) Id = QueryString["id"]; if (QueryString.ContainsKey("before")) Int32.TryParse(QueryString["before"], out Before); if(QueryString.ContainsKey("after")) Int32.TryParse(QueryString["after"], out After); if (QueryString.ContainsKey("pos")) Int32.TryParse(QueryString["pos"], out Pos); Min = (Pos - 1) - Before; Max = After + 1; // Do our requested Task switch (QueryString["type"]) { case "score": DoScore(); break; case "risingstar": DoRisingStar(); break; case "kit": DoKit(); break; case "vehicle": DoVehicles(); break; case "weapon": DoWeapons(); break; default: //Response.HTTPStatusCode = ASPResponse.HTTPStatus.BadRequest; Response.Send(); break; } }
/// <summary> /// Creates a new instance of HttpClinet /// </summary> /// <param name="Client">The TcpClient object for this connection</param> /// <param name="Reset"> /// The ManualResetEvent object, used to stop the parent thread until the /// request is fully recieved, and a response an be created /// </param> public HttpClient(HttpListenerContext Client) { // Fill Request / Response RemoteEndPoint = Client.Request.RemoteEndPoint as IPEndPoint; Request = new HttpRequest(Client.Request, this); if (Client.Request.Url.AbsolutePath.ToLower().StartsWith("/asp/")) { Response = new ASPResponse(Client.Response, this); } else { Response = new HttpResponse(Client.Response, this); } // Add BF2Statistics Header Client.Response.AddHeader("X-Powered-By", "BF2Statistics Control Center v" + Program.Version); }
//&info=per*,cmb*,twsc,cpcp,cacp,dfcp,kila,heal,rviv,rsup,rpar,tgte,dkas,dsab,cdsc,rank,cmsc,kick,kill,deth,suic,ospm,klpm,klpr,dtpr,bksk,wdsk,bbrs,tcdr,ban,dtpm,lbtl,osaa,vrk,tsql,tsqm,tlwf,mvks,vmks,mvn*,vmr*,fkit,fmap,fveh,fwea,wtm-,wkl-,wdt-,wac-,wkd-,vtm-,vkl-,vdt-,vkd-,vkr-,atm-,awn-,alo-,abr-,ktm-,kkl-,kdt-,kkd- public GetPlayerInfo(HttpClient Client) { // Load class Variables this.Response = Client.Response; this.QueryString = Client.Request.QueryString; this.Driver = ASPServer.Database.Driver; // Setup Params if (QueryString.ContainsKey("pid")) Int32.TryParse(QueryString["pid"], out Pid); if (QueryString.ContainsKey("transpose")) Int32.TryParse(QueryString["transpose"], out Transpose); if (QueryString.ContainsKey("info")) Info = QueryString["info"].Split(',').ToList<string>(); // Make sure our required params are indeed passed if (Pid == 0 || Info.Count == 0) { Client.Response.WriteResponseStart(false); Client.Response.WriteHeaderLine("asof", "err"); Client.Response.WriteDataLine(DateTime.UtcNow.ToUnixTimestamp(), "Invalid Syntax!"); Client.Response.Send(); return; } // Get Missing keys for a standard request List<string> ReqKeys = RequiredKeys.Split(',').ToList<string>(); IEnumerable<string> Diff = from item in ReqKeys where !Info.Contains(item) select item; List<string> MissingKeys = new List<string>(Diff); // Standard BF2HQ Request if (MissingKeys.Count == 0) DoFullRequest(); // Time Info else if (QueryString["info"] == "ktm-,vtm-,wtm-,mtm-") DoTimeRequest(); // Map Info else if (QueryString["info"].StartsWith("mtm-,mwn-,mls-")) DoMapRequest(); else if (QueryString["info"].StartsWith("rank") && QueryString["info"].EndsWith("vac-")) DoServerRequest(); else Response.Send(); }
public GetUnlocksInfo(HttpClient Client) { // Load class Variables this.Response = Client.Response; this.QueryString = Client.Request.QueryString; // Earned and Available Unlocks int Earned = 0; int Available = 0; // Get player ID if (QueryString.ContainsKey("pid")) Int32.TryParse(QueryString["pid"], out Pid); // Prepare Output Response.WriteResponseStart(); Response.WriteHeaderLine("pid", "nick", "asof"); switch(MainForm.Config.ASP_UnlocksMode) { // Player Based case 0: // Make sure the player exists Rows = Driver.Query("SELECT name, score, rank, usedunlocks FROM player WHERE id=@P0", Pid); if(Rows.Count == 0) goto case 2; // No Unlocks // Start Output Response.WriteDataLine(Pid, Rows[0]["name"].ToString().Trim(), DateTime.UtcNow.ToUnixTimestamp()); // Get total number of unlocks player is allowed to have Rank = Int32.Parse(Rows[0]["rank"].ToString()); Earned = Int32.Parse(Rows[0]["usedunlocks"].ToString()); Available = GetBonusUnlocks(); // Determine total unlocks available Rows = Driver.Query("SELECT COUNT(id) AS count FROM unlocks WHERE id = @P0 AND state = 's'", Pid); int Used = Int32.Parse(Rows[0]["count"].ToString()); if (Used > 0) { // Update unlocks data Available -= Used; Driver.Execute("UPDATE player SET availunlocks = @P0, usedunlocks = @P1 WHERE id = @P2", Available, Used, Pid); } // Output more Response.WriteHeaderLine("enlisted", "officer"); Response.WriteDataLine(Available, 0); Response.WriteHeaderLine("id", "state"); // Add each unlock's state Dictionary<string, bool> Unlocks = new Dictionary<string, bool>(); Rows = Driver.Query("SELECT kit, state FROM unlocks WHERE id=@P0 ORDER BY kit ASC", Pid); foreach (Dictionary<string, object> Unlock in Rows) { // Add unlock to output if its a base unlock int Id = Int32.Parse(Unlock["kit"].ToString()); if (Id < 78) Response.WriteDataLine(Unlock["kit"], Unlock["state"]); // Add Unlock to list Unlocks.Add(Unlock["kit"].ToString(), (Unlock["state"].ToString() == "s")); } // Add SF Unlocks... We need the base class unlock unlocked first CheckUnlock(88, 22, Unlocks); CheckUnlock(99, 33, Unlocks); CheckUnlock(111, 44, Unlocks); CheckUnlock(222, 55, Unlocks); CheckUnlock(333, 66, Unlocks); CheckUnlock(444, 11, Unlocks); CheckUnlock(555, 77, Unlocks); break; // All Unlocked case 1: Response.WriteDataLine(Pid, "All_Unlocks", DateTime.UtcNow.ToUnixTimestamp()); Response.WriteHeaderLine("enlisted", "officer"); Response.WriteDataLine(0, 0); Response.WriteHeaderLine("id", "state"); for (int i = 11; i < 100; i += 11) Response.WriteDataLine(i, "s"); for (int i = 111; i < 556; i += 111) Response.WriteDataLine(i, "s"); break; // Unlocks Disabled case 2: default: Response.WriteDataLine(Pid, "No_Unlocks", DateTime.UtcNow.ToUnixTimestamp()); Response.WriteHeaderLine("enlisted", "officer"); Response.WriteDataLine(0, 0); Response.WriteHeaderLine("id", "state"); for (int i = 11; i < 100; i += 11) Response.WriteDataLine(i, "n"); for (int i = 111; i < 556; i += 111) Response.WriteDataLine(i, "n"); break; } // Send Response Response.Send(); }
/// <summary> /// This request provides details of the players unlocked weapons /// </summary> /// <queryParam name="pid" type="int">The unique player ID</queryParam> /// <queryParam name ="nick" type="string">Unique player nickname</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 GetUnlocksInfo(HttpClient Client, StatsDatabase Database) { // Load class Variables this.Response = Client.Response; this.Driver = Database; // Earned and Available Unlocks int HasUsed = 0; int Earned = 0; int Available = 0; // Get player ID if (Client.Request.QueryString.ContainsKey("pid")) Int32.TryParse(Client.Request.QueryString["pid"], out Pid); // Prepare Output Response.WriteResponseStart(); Response.WriteHeaderLine("pid", "nick", "asof"); // Our ourput changes based on the selected Unlocks config setting switch(MainForm.Config.ASP_UnlocksMode) { // Player Based - Unlocks are earned case 0: // Make sure the player exists Rows = Driver.Query("SELECT name, score, rank, availunlocks, usedunlocks FROM player WHERE id=@P0", Pid); if(Rows.Count == 0) goto case 2; // No Unlocks // Start Output Response.WriteDataLine(Pid, Rows[0]["name"].ToString().Trim(), DateTime.UtcNow.ToUnixTimestamp()); // Get total number of unlocks player is allowed to have givin his rank, and bonus unlocks Rank = Int32.Parse(Rows[0]["rank"].ToString()); HasUsed = Int32.Parse(Rows[0]["usedunlocks"].ToString()); Available = Int32.Parse(Rows[0]["availunlocks"].ToString()); Earned = GetBonusUnlocks(); // Determine total unlocks available, based on what he has earned, minus what he has used already Rows = Driver.Query("SELECT COUNT(id) AS count FROM unlocks WHERE id = @P0 AND state = 's'", Pid); int Used = Int32.Parse(Rows[0]["count"].ToString()); Earned -= Used; // Update database if the database is off if (Earned != Available || HasUsed != Used) Driver.Execute("UPDATE player SET availunlocks = @P0, usedunlocks = @P1 WHERE id = @P2", Earned, Used, Pid); // Output more Response.WriteHeaderLine("enlisted", "officer"); Response.WriteDataLine(Earned, 0); Response.WriteHeaderLine("id", "state"); // Add each unlock's state Dictionary<string, bool> Unlocks = new Dictionary<string, bool>(); Rows = Driver.Query("SELECT kit, state FROM unlocks WHERE id=@P0 ORDER BY kit ASC", Pid); if (Rows.Count == 0) { // Create Player Unlock Data StringBuilder Query = new StringBuilder("INSERT INTO unlocks VALUES "); // Normal unlocks for (int i = 11; i < 100; i += 11) { // 88 and above are Special Forces unlocks, and wont display at all if the base unlocks are not earned if (i < 78 ) Response.WriteDataLine(i, "n"); Query.AppendFormat("({0}, {1}, 'n'), ", Pid, i); } // Sf Unlocks, Dont display these because thats how Gamespy does it for (int i = 111; i < 556; i += 111) { Query.AppendFormat("({0}, {1}, 'n')", Pid, i); if (i != 555) Query.Append(", "); } // Do Insert Driver.Execute(Query.ToString()); } else { foreach (Dictionary<string, object> Unlock in Rows) { // Add unlock to output if its a base unlock int Id = Int32.Parse(Unlock["kit"].ToString()); if (Id < 78) Response.WriteDataLine(Unlock["kit"], Unlock["state"]); // Add Unlock to list Unlocks.Add(Unlock["kit"].ToString(), (Unlock["state"].ToString() == "s")); } // Add SF Unlocks... We need the base class unlock unlocked first CheckUnlock(88, 22, Unlocks); CheckUnlock(99, 33, Unlocks); CheckUnlock(111, 44, Unlocks); CheckUnlock(222, 55, Unlocks); CheckUnlock(333, 66, Unlocks); CheckUnlock(444, 11, Unlocks); CheckUnlock(555, 77, Unlocks); } break; // All Unlocked case 1: Response.WriteDataLine(Pid, "All_Unlocks", DateTime.UtcNow.ToUnixTimestamp()); Response.WriteHeaderLine("enlisted", "officer"); Response.WriteDataLine(0, 0); Response.WriteHeaderLine("id", "state"); for (int i = 11; i < 100; i += 11) Response.WriteDataLine(i, "s"); for (int i = 111; i < 556; i += 111) Response.WriteDataLine(i, "s"); break; // Unlocks Disabled case 2: default: Response.WriteDataLine(Pid, "No_Unlocks", DateTime.UtcNow.ToUnixTimestamp()); Response.WriteHeaderLine("enlisted", "officer"); Response.WriteDataLine(0, 0); Response.WriteHeaderLine("id", "state"); for (int i = 11; i < 78; i += 11) Response.WriteDataLine(i, "n"); break; } // Send Response Response.Send(); }