private static async Task OnRequest(object sender, SessionEventArgs e) { //check if the request is to something that interests us string url = e.WebSession.Request.Url; if (!url.Contains("ppy.sh")) { return; } if (url == "https://c.ppy.sh/") { if (e.WebSession.Request.GetAllHeaders().Any(a => a.Name == "osu-token")) { byte[] bodyOriginal = await e.GetRequestBody(); List <BanchoPacket> plist = BanchoSerializer.DeserializePackets(bodyOriginal).ToList(); foreach (IHopePlugin plugin in Manager.Plugins) { try { plugin.OnBanchoRequest(ref plist); } catch (Exception exception) { Debug.WriteLine($"Exception occured in plugin {plugin.GetMetadata().Name} OnBanchoRequest: " + exception); } } byte[] bodySerialized = BanchoSerializer.Serialize(plist); await e.SetRequestBody(bodySerialized); #if DEBUG && NO_PLUGINS bool equal = true; if (bodyOriginal.Length == bodySerialized.Length) { if (bodyOriginal.Where((t, i) => t != bodySerialized[i]).Any()) { equal = false; } } else { equal = false; } if (!equal) { File.WriteAllBytes("orig", bodyOriginal); File.WriteAllBytes("gen", bodySerialized); Debugger.Break(); } #endif } else { //login request, don't modify this for now Debug.WriteLine("Not parsing login request."); } } }
private static async Task OnResponse(object sender, SessionEventArgs e) { string url = e.WebSession.Request.Url; if (!url.Contains("ppy.sh")) { return; } if (url == "https://c.ppy.sh/") { //normal request byte[] bodyOriginal = await e.GetResponseBody(); List <BanchoPacket> plist = BanchoSerializer.DeserializePackets(bodyOriginal).ToList(); foreach (IHopePlugin plugin in Manager.Plugins) { try { plugin.OnBanchoResponse(ref plist); } catch (Exception exception) { Debug.WriteLine($"Exception occured in plugin {plugin.GetMetadata().Name} OnBanchoRequest: " + exception); } } byte[] bodySerialized = BanchoSerializer.Serialize(plist); await e.SetResponseBody(bodySerialized); #if DEBUG && NO_PLUGINS bool equal = true; if (bodyOriginal.Length == bodySerialized.Length) { if (bodyOriginal.Where((t, i) => t != bodySerialized[i]).Any()) { equal = false; } } else { equal = false; } if (!equal) { File.WriteAllBytes("orig", bodyOriginal); File.WriteAllBytes("gen", bodySerialized); Debugger.Break(); } #endif } }