1 | using System;
|
---|
2 | using System.Net;
|
---|
3 | using Platform.Steam;
|
---|
4 | using Webserver;
|
---|
5 | using Webserver.UrlHandlers;
|
---|
6 | using Webserver.WebAPI;
|
---|
7 |
|
---|
8 | namespace AllocsFixes {
|
---|
9 | public class SteamLoginApi : AbsWebAPI {
|
---|
10 | public override int DefaultPermissionLevel () => 2000;
|
---|
11 |
|
---|
12 | private const string pageBasePath = "/legacymap/index.html";
|
---|
13 |
|
---|
14 | private const string steamOpenIdVerifyUrl = "verifysteamopenid";
|
---|
15 | private const string steamLoginUrl = "loginsteam";
|
---|
16 |
|
---|
17 | public SteamLoginApi (Web _parentWeb) : base(_parentWeb) {
|
---|
18 | }
|
---|
19 |
|
---|
20 | public override void HandleRequest (RequestContext _context) {
|
---|
21 | if (_context.Request.RemoteEndPoint == null) {
|
---|
22 | WebUtils.WriteText (_context.Response, "No remote endpoint", HttpStatusCode.BadRequest);
|
---|
23 | return;
|
---|
24 | }
|
---|
25 |
|
---|
26 | string subpath = _context.RequestPath;
|
---|
27 |
|
---|
28 | string remoteEndpointString = _context.Request.RemoteEndPoint!.ToString ();
|
---|
29 |
|
---|
30 | if (subpath.StartsWith (steamOpenIdVerifyUrl)) {
|
---|
31 | if (SessionHandler.HandleSteamVerification (ParentWeb.ConnectionHandler, _context, remoteEndpointString)) {
|
---|
32 | _context.Response.Redirect (pageBasePath);
|
---|
33 | } else {
|
---|
34 | WebUtils.WriteText (_context.Response, "Login failed", HttpStatusCode.InternalServerError);
|
---|
35 | }
|
---|
36 | return;
|
---|
37 | }
|
---|
38 |
|
---|
39 | if (subpath.StartsWith ("logout")) {
|
---|
40 | SessionHandler.HandleLogout (ParentWeb.ConnectionHandler, _context, pageBasePath);
|
---|
41 | return;
|
---|
42 | }
|
---|
43 |
|
---|
44 | if (subpath.StartsWith (steamLoginUrl)) {
|
---|
45 | var absoluteUrl = _context.Request.Url.AbsolutePath;
|
---|
46 | absoluteUrl = absoluteUrl.Substring (0, absoluteUrl.Length - _context.RequestPath.Length);
|
---|
47 | SessionHandler.HandleSteamLogin (_context, $"{absoluteUrl}{steamOpenIdVerifyUrl}");
|
---|
48 | return;
|
---|
49 | }
|
---|
50 |
|
---|
51 | WebUtils.WriteText (_context.Response, "Invalid path", HttpStatusCode.BadRequest);
|
---|
52 | }
|
---|
53 |
|
---|
54 | }
|
---|
55 | }
|
---|