public override void HandleRequest() { // NOTE: The HttpServer will handle the DbConnectException using (Database = new StatsDatabase()) { // Setup Variables int Pid = 0, MapId = 0, CustomOnly = 0; string MapName = ""; SelectQueryBuilder Query = new SelectQueryBuilder(Database); ASPResponse Response = Client.Response as ASPResponse; // 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 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 Response.WriteHeaderLine("mapid", "mapname", "time", "win", "loss", "best", "worst"); foreach (Dictionary <string, object> Map in Database.QueryReader(Query.BuildCommand())) { 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 Response.WriteHeaderLine("mapid", "name", "score", "time", "times", "kills", "deaths"); foreach (Dictionary <string, object> Map in Database.QueryReader(Query.BuildCommand())) { Response.WriteDataLine(Map["id"], Map["name"], Map["score"], Map["time"], Map["times"], Map["kills"], Map["deaths"]); } } // Send Response Response.Send(); } }
public override void HandleRequest() { // First and foremost. Make sure that we are authorized to be here! IPEndPoint RemoteIP = Client.RemoteEndPoint; ASPResponse Response = Client.Response as ASPResponse; // Make sure we have post data if (!Client.Request.HasEntityBody) { // No Post Data if (Client.Request.UserAgent == "GameSpyHTTP/1.0") { Response.WriteResponseStart(false); Response.WriteHeaderLine("response"); Response.WriteDataLine("SNAPSHOT Data NOT found!"); } else { Client.Response.StatusCode = (int)HttpStatusCode.BadRequest; } Response.Send(); return; } // Create snapshot backup file if the snapshot is valid try { // Read Snapshot using (StreamReader Reader = new StreamReader(Client.Request.InputStream)) { // Attempt to Queue the snapshot in the Processor factory string SnapshotData = Reader.ReadToEnd(); StatsManager.QueueServerSnapshot(SnapshotData, RemoteIP.Address); } // Tell the server we are good to go Response.WriteResponseStart(); Response.WriteHeaderLine("response"); Response.WriteDataLine("OK"); Response.Send(); } catch (UnauthorizedAccessException) { // Notify User Notify.Show("Snapshot Denied!", "Invalid Server IP: " + RemoteIP.Address.ToString(), AlertType.Warning); if (Client.Request.UserAgent == "GameSpyHTTP/1.0") { Response.WriteResponseStart(false); Response.WriteHeaderLine("response"); Response.WriteDataLine("Unauthorised Gameserver"); } else { Response.StatusCode = (int)HttpStatusCode.Forbidden; } Response.Send(); return; } catch (InvalidDataException E) { // Generate Exception Log HttpServer.AspStatsLog.Write("ERROR: [SnapshotPreProcess] " + E.Message); ExceptionHandler.GenerateExceptionLog(E); // Notify the user and the connection client Notify.Show("Error Processing Snapshot!", "Snapshot Data NOT Complete or Invalid!", AlertType.Warning); Response.WriteResponseStart(false); Response.WriteHeaderLine("response"); Response.WriteDataLine("SNAPSHOT Data NOT complete or invalid!"); Response.Send(); return; } catch (Exception E) { HttpServer.AspStatsLog.Write("ERROR: [SnapshotPreProcess] " + E.Message + " @ " + E.TargetSite); Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable; Response.Send(); return; } }