- 404 favicon

- Try to fix chrome redirect bug
This commit is contained in:
Infi
2024-08-28 19:57:50 +02:00
parent bf446c5511
commit 6fe560d111
4 changed files with 50 additions and 14 deletions
+2 -3
View File
@@ -79,7 +79,6 @@ public class HostContext
{
IsActive = false;
IsStopping = true;
await Task.Delay(10000);
Host.Stop();
// Save our session tokens
@@ -114,9 +113,9 @@ public class HostContext
Plugin.Log.Error(args.Exception, "Webserver threw an exception.");
}
private async Task DefaultRoute(HttpContextBase ctx)
private async Task<bool> DefaultRoute(HttpContextBase ctx)
{
await ctx.Response.Send("Nothing to see here.");
return await ctx.Response.Send("Nothing to see here.");
}
private async Task CheckAuthenticationCookie(HttpContextBase ctx)
+20 -1
View File
@@ -36,10 +36,12 @@ public class RouteController
// Pre Auth
Core.Host.Routes.PreAuthentication.Static.Add(HttpMethod.GET, "/", AuthRoute, ExceptionRoute);
Core.Host.Routes.PreAuthentication.Static.Add(HttpMethod.GET, "/auth", GetAuthenticateClient, ExceptionRoute);
Core.Host.Routes.PreAuthentication.Static.Add(HttpMethod.POST, "/auth", AuthenticateClient, ExceptionRoute);
Core.Host.Routes.PreAuthentication.Static.Add(HttpMethod.GET, "/files/gfdata.gfd", GetGfdData, ExceptionRoute);
Core.Host.Routes.PreAuthentication.Static.Add(HttpMethod.GET, "/files/fonticon_ps5.tex", GetTexData, ExceptionRoute);
Core.Host.Routes.PreAuthentication.Static.Add(HttpMethod.GET, "/files/FFXIV_Lodestone_SSF.ttf", GetLodestoneFont, ExceptionRoute);
Core.Host.Routes.PreAuthentication.Static.Add(HttpMethod.GET, "/favicon.ico", GetFavicon, ExceptionRoute);
Core.Host.Routes.PreAuthentication.Parameter.Add(HttpMethod.GET, "/emote/{name}", GetEmote, ExceptionRoute);
Core.Host.Routes.PreAuthentication.Content.Add("/static", true, ExceptionRoute);
@@ -87,6 +89,12 @@ public class RouteController
await ctx.Response.Send(data);
}
private async Task GetFavicon(HttpContextBase ctx)
{
ctx.Response.StatusCode = 404;
await ctx.Response.Send();
}
private async Task GetEmote(HttpContextBase ctx)
{
var name = ctx.Request.Url.Parameters["name"] ?? "";
@@ -122,9 +130,11 @@ public class RouteController
#region PreAuthRoutes
private async Task<bool> AuthenticateClient(HttpContextBase ctx)
{
Plugin.Log.Information($"Auth requested");
var currentTick = Environment.TickCount64;
if (RateLimit.TryGetValue(ctx.Request.Source.IpAddress, out var timestamp) && timestamp > currentTick)
return await Redirect(ctx, "/", ("message", "Rate limit active."), ("retry", "12345"));
return await Redirect(ctx, "/", ("message", "Rate limit active."));
// The next request will be rate limited for 10s
RateLimit[ctx.Request.Source.IpAddress] = currentTick + 10_000;
@@ -139,6 +149,15 @@ public class RouteController
ctx.Response.Headers.Add("Set-Cookie", $"ChatTwo-token={token}");
return await Redirect(ctx, "/chat");
}
private async Task<bool> GetAuthenticateClient(HttpContextBase ctx)
{
Plugin.Log.Information($"Get was used for auth requested");
Plugin.Log.Information($"{ctx.Request.Url.Full}");
Plugin.Log.Information($"{ctx.RouteType}");
return await Redirect(ctx, "/", ("message", "Rate limit active."));
}
#endregion
#region PostAuthRoutes
+1 -1
View File
@@ -13,7 +13,7 @@
<main class="auth">
<h1>Authcode</h1>
<form action="/auth" method="POST">
<input type="password" name="authcode">
<label><input type="password" name="authcode"></label>
<button type="submit">Submit</button>
</form>
<img src="/emote/Sure">