/// <summary> /// Creates a new instance of HttpRequest /// </summary> /// <param name="Client">The HttpClient creating this response</param> public ASPRequest(HttpListenerRequest Request, HttpClient Client) { // Create a better QueryString object QueryString = Request.QueryString.Cast<string>() .Select(s => new { Key = s, Value = Request.QueryString[s] }) .ToDictionary(p => p.Key, p => p.Value); this.Request = Request; this.Client = Client; }
/// <summary> /// Constructor /// </summary> public ASPResponse(HttpListenerResponse Response, HttpClient Client) { // Set Iternals this.Response = Response; this.Client = Client; // Start our Timer Clock = new Stopwatch(); Clock.Start(); // Create a new Response Body ResponseBody = new StringBuilder(); Transpose = ( Client.Request.QueryString.ContainsKey("transpose") && Client.Request.QueryString["transpose"] == "1" ); }
/// <summary> /// This request provides details on a particular players rank, and /// whether or not to show the user a promotion/demotion announcement /// </summary> /// <queryParam name="nick" type="string">The unique player's Name</queryParam> /// <queryParam name="ai" type="int">Defines whether the player is a bot (used by bf2server)</queryParam> /// <queryParam name="playerlist" type="int">Defines whether to list the players who's nick is similair to the Nick param</queryParam> /// <param name="Client">The HttpClient who made the request</param> public GetPlayerID(HttpClient Client) : base(Client) { }
/// <summary> /// This request takes snapshot data, and processes it into the stats database /// </summary> /// <param name="Client">The HttpClient who made the request</param> public SnapshotPost(HttpClient Client) : base(Client) { }
/// <summary> /// Handles the Http Connecting client in a new thread /// </summary> private static void HandleRequest(object Sync) { // Finish accepting the client HttpClient Client = new HttpClient(Sync as HttpListenerContext); // Update client count, and fire connection event SessionRequests++; RequestRecieved(); // Make sure our stats Database is online try { // If we arent suppossed to be running, show a 503 if (!IsRunning) throw new Exception("Server is not running"); // If database is offline, Try to re-connect if (!Database.Driver.IsConnected) { try { Database.CheckConnection(); } catch { } if (!Database.Driver.IsConnected) { string Message = "ERROR: Unable to establish database connection"; ServerLog.Write(Message); throw new Exception(Message); } } } catch { // Set service is unavialable Client.Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable; Client.Response.Send(); return; } // Make sure request method is supported if (Client.Request.HttpMethod != "GET" && Client.Request.HttpMethod != "POST" && Client.Request.HttpMethod != "HEAD") { Client.Response.StatusCode = (int)HttpStatusCode.MethodNotAllowed; Client.Response.Send(); return; } // Process Request try { // Get our requested document string Document = Client.Request.Url.AbsolutePath.ToLower(); switch (Document.Replace("/asp/", "")) { case "bf2statistics.php": new SnapshotPost(Client); break; case "createplayer.aspx": new CreatePlayer(Client); break; case "getbackendinfo.aspx": new GetBackendInfo(Client); break; case "getawardsinfo.aspx": new GetAwardsInfo(Client); break; case "getclaninfo.aspx": new GetClanInfo(Client); break; case "getleaderboard.aspx": new GetLeaderBoard(Client); break; case "getmapinfo.aspx": new GetMapInfo(Client); break; case "getplayerid.aspx": new GetPlayerID(Client); break; case "getplayerinfo.aspx": new GetPlayerInfo(Client); break; case "getrankinfo.aspx": new GetRankInfo(Client); break; case "getunlocksinfo.aspx": new GetUnlocksInfo(Client); break; case "ranknotification.aspx": new RankNotification(Client); break; case "searchforplayers.aspx": new SearchForPlayers(Client); break; case "selectunlock.aspx": new SelectUnlock(Client); break; default: Client.Response.StatusCode = (int)HttpStatusCode.NotFound; Client.Response.Send(); break; } } catch (Exception E) { ServerLog.Write("ERROR: " + E.Message); if (!Client.ResponseSent) { // Internal service error Client.Response.StatusCode = (int)HttpStatusCode.InternalServerError; Client.Response.Send(); } } finally { // Make sure a response is sent to prevent client hang if (!Client.ResponseSent) Client.Response.Send(); } }