From 555c79bf4370fe6f995800539e1cd7780cee83f5 Mon Sep 17 00:00:00 2001 From: Greg Edwards Date: Mon, 15 Sep 2014 15:08:56 -0400 Subject: [PATCH] WIP of Tetris DS gamestats server --- Sample/Global.asax.cs | 37 ++++++++++++++++++++++++++++++++++- Sample/Sample.csproj | 11 ++++++++++- Sample/tetrisds/store.ashx | 1 + Sample/tetrisds/store.ashx.cs | 26 ++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 Sample/tetrisds/store.ashx create mode 100644 Sample/tetrisds/store.ashx.cs diff --git a/Sample/Global.asax.cs b/Sample/Global.asax.cs index 1ea52d1..3d25b71 100644 --- a/Sample/Global.asax.cs +++ b/Sample/Global.asax.cs @@ -12,5 +12,40 @@ namespace Sample protected void Application_Start(object sender, EventArgs e) { } + + void Application_BeginRequest(object sender, EventArgs e) + { + String pathInfo, query; + String targetUrl = RewriteUrl(Request.Url.PathAndQuery, out pathInfo, out query); + + if (targetUrl != null) + { + Context.RewritePath(targetUrl, pathInfo, query, false); + } + } + + public static String RewriteUrl(String url, out String pathInfo, out String query) + { + int q = url.IndexOf('?'); + String path; + pathInfo = ""; + + if (q < 0) + { + path = url; + query = ""; + } + else + { + path = url.Substring(0, q); + query = url.Substring(q + 1); + } + + // Since our handler is not ASP classic, we must rewrite .asp in + // the URL so control will be transferred to it. + if (path.Length < 4) return null; + if (path.Substring(path.Length - 4).ToLowerInvariant() != ".asp") return null; + return path.Substring(0, path.Length - 4) + ".ashx"; + } } -} \ No newline at end of file +} diff --git a/Sample/Sample.csproj b/Sample/Sample.csproj index cfd8abb..9946435 100644 --- a/Sample/Sample.csproj +++ b/Sample/Sample.csproj @@ -57,6 +57,7 @@ + Web.config @@ -73,10 +74,18 @@ Global.asax + + store.ashx + - + + + + {2d667f5b-f10d-44e2-93f6-dd555d9ee7df} + GamestatsBase + 10.0 diff --git a/Sample/tetrisds/store.ashx b/Sample/tetrisds/store.ashx new file mode 100644 index 0000000..cc23750 --- /dev/null +++ b/Sample/tetrisds/store.ashx @@ -0,0 +1 @@ +<%@ WebHandler Language="C#" CodeBehind="store.ashx.cs" Class="Sample.tetrisds.store" %> diff --git a/Sample/tetrisds/store.ashx.cs b/Sample/tetrisds/store.ashx.cs new file mode 100644 index 0000000..1fd8b67 --- /dev/null +++ b/Sample/tetrisds/store.ashx.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using GamestatsBase; + +namespace Sample.tetrisds +{ + /// + /// Summary description for store + /// + public class store : GamestatsHandler + { + public store() : base("Wo3vqrDoL56sAdveYeC1", 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, "tetrisds", GamestatsRequestVersions.Version1, GamestatsResponseVersions.Version1) + { + + } + + public override void ProcessGamestatsRequest(byte[] request, System.IO.MemoryStream response, string url, int pid, HttpContext context, GamestatsSession session) + { + byte[] nameBytes = FromUrlSafeBase64String(context.Request.QueryString["name"]); + + + } + } +}