mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-19 03:31:29 +00:00
Cleanup code and formatting
This commit is contained in:
parent
d64aa421fe
commit
61f027b57e
13 changed files with 42 additions and 46 deletions
|
@ -47,7 +47,7 @@ namespace LBPUnion.ProjectLighthouse.Tests
|
||||||
|
|
||||||
public Task<HttpResponseMessage> AuthenticatedRequest(string endpoint, string mmAuth, HttpMethod method)
|
public Task<HttpResponseMessage> AuthenticatedRequest(string endpoint, string mmAuth, HttpMethod method)
|
||||||
{
|
{
|
||||||
using HttpRequestMessage? requestMessage = new(method, endpoint);
|
using HttpRequestMessage requestMessage = new(method, endpoint);
|
||||||
requestMessage.Headers.Add("Cookie", mmAuth);
|
requestMessage.Headers.Add("Cookie", mmAuth);
|
||||||
|
|
||||||
return this.Client.SendAsync(requestMessage);
|
return this.Client.SendAsync(requestMessage);
|
||||||
|
@ -61,7 +61,7 @@ namespace LBPUnion.ProjectLighthouse.Tests
|
||||||
|
|
||||||
public async Task<HttpResponseMessage> AuthenticatedUploadFileRequest(string endpoint, string filePath, string mmAuth)
|
public async Task<HttpResponseMessage> AuthenticatedUploadFileRequest(string endpoint, string filePath, string mmAuth)
|
||||||
{
|
{
|
||||||
using HttpRequestMessage? requestMessage = new(HttpMethod.Post, endpoint);
|
using HttpRequestMessage requestMessage = new(HttpMethod.Post, endpoint);
|
||||||
requestMessage.Headers.Add("Cookie", mmAuth);
|
requestMessage.Headers.Add("Cookie", mmAuth);
|
||||||
requestMessage.Content = new StringContent(await File.ReadAllTextAsync(filePath));
|
requestMessage.Content = new StringContent(await File.ReadAllTextAsync(filePath));
|
||||||
return await this.Client.SendAsync(requestMessage);
|
return await this.Client.SendAsync(requestMessage);
|
||||||
|
@ -69,7 +69,7 @@ namespace LBPUnion.ProjectLighthouse.Tests
|
||||||
|
|
||||||
public async Task<HttpResponseMessage> AuthenticatedUploadDataRequest(string endpoint, byte[] data, string mmAuth)
|
public async Task<HttpResponseMessage> AuthenticatedUploadDataRequest(string endpoint, byte[] data, string mmAuth)
|
||||||
{
|
{
|
||||||
using HttpRequestMessage? requestMessage = new(HttpMethod.Post, endpoint);
|
using HttpRequestMessage requestMessage = new(HttpMethod.Post, endpoint);
|
||||||
requestMessage.Headers.Add("Cookie", mmAuth);
|
requestMessage.Headers.Add("Cookie", mmAuth);
|
||||||
requestMessage.Content = new ByteArrayContent(data);
|
requestMessage.Content = new ByteArrayContent(data);
|
||||||
return await this.Client.SendAsync(requestMessage);
|
return await this.Client.SendAsync(requestMessage);
|
||||||
|
|
|
@ -24,14 +24,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
public async Task<IActionResult> Eula()
|
public async Task<IActionResult> Eula()
|
||||||
{
|
{
|
||||||
User user = await this.database.UserFromRequest(this.Request);
|
User user = await this.database.UserFromRequest(this.Request);
|
||||||
return user == null
|
return user == null ? this.StatusCode(403, "") : this.Ok(EulaHelper.PrivateInstanceNoticeOrBlank + "\n" + $"{EulaHelper.License}\n");
|
||||||
? this.StatusCode(403, "")
|
|
||||||
: this.Ok
|
|
||||||
(
|
|
||||||
EulaHelper.PrivateInstanceNoticeOrBlank +
|
|
||||||
"\n" +
|
|
||||||
$"{EulaHelper.License}\n"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("announce")]
|
[HttpGet("announce")]
|
||||||
|
|
|
@ -59,8 +59,8 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
[HttpGet("slots/mmpicks")]
|
[HttpGet("slots/mmpicks")]
|
||||||
public IActionResult TeamPickedSlots([FromQuery] int pageStart, [FromQuery] int pageSize)
|
public IActionResult TeamPickedSlots([FromQuery] int pageStart, [FromQuery] int pageSize)
|
||||||
{
|
{
|
||||||
IQueryable<Slot> slots = this.database.Slots
|
IQueryable<Slot> slots = this.database.Slots.Where
|
||||||
.Where(s => s.TeamPick)
|
(s => s.TeamPick)
|
||||||
.Include(s => s.Creator)
|
.Include(s => s.Creator)
|
||||||
.Include(s => s.Location)
|
.Include(s => s.Location)
|
||||||
.OrderByDescending(s => s.LastUpdated)
|
.OrderByDescending(s => s.LastUpdated)
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Profiles;
|
using LBPUnion.ProjectLighthouse.Types.Profiles;
|
||||||
|
@ -137,17 +138,21 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
User user = await this.database.UserFromRequest(this.Request);
|
User user = await this.database.UserFromRequest(this.Request);
|
||||||
if (user == null) return this.StatusCode(403, "");
|
if (user == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
string pinsString = await new System.IO.StreamReader(this.Request.Body).ReadToEndAsync();
|
string pinsString = await new StreamReader(this.Request.Body).ReadToEndAsync();
|
||||||
Pins pinJson = JsonSerializer.Deserialize<Pins>(pinsString);
|
Pins pinJson = JsonSerializer.Deserialize<Pins>(pinsString);
|
||||||
|
|
||||||
|
if (pinJson == null) return this.BadRequest();
|
||||||
|
|
||||||
// Sometimes the update gets called periodically as pin progress updates via playing,
|
// Sometimes the update gets called periodically as pin progress updates via playing,
|
||||||
// may not affect equipped profile pins however, so check before setting it.
|
// may not affect equipped profile pins however, so check before setting it.
|
||||||
string currentPins = user.Pins;
|
string currentPins = user.Pins;
|
||||||
string newPins = string.Join(",", pinJson.ProfilePins);
|
string newPins = string.Join(",", pinJson.ProfilePins);
|
||||||
if (!String.Equals(currentPins,newPins)) {
|
|
||||||
|
if (string.Equals(currentPins, newPins)) return this.Ok("[{\"StatusCode\":200}]");
|
||||||
|
|
||||||
user.Pins = newPins;
|
user.Pins = newPins;
|
||||||
await this.database.SaveChangesAsync();
|
await this.database.SaveChangesAsync();
|
||||||
}
|
|
||||||
return this.Ok("[{\"StatusCode\":200}]");
|
return this.Ok("[{\"StatusCode\":200}]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,8 +69,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
// Determine if file is JPEG
|
// Determine if file is JPEG
|
||||||
byte[] header = reader.ReadBytes(9);
|
byte[] header = reader.ReadBytes(9);
|
||||||
|
|
||||||
if (header[0] == 0xFF && header[1] == 0xD8 && header[2] == 0xFF && header[3] == 0xE0)
|
if (header[0] == 0xFF && header[1] == 0xD8 && header[2] == 0xFF && header[3] == 0xE0) return LbpFileType.Jpeg;
|
||||||
return LbpFileType.Jpeg;
|
|
||||||
|
|
||||||
return LbpFileType.Unknown; // Still unknown.
|
return LbpFileType.Unknown; // Still unknown.
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Kettu;
|
using Kettu;
|
||||||
|
@ -68,8 +67,7 @@ namespace LBPUnion.ProjectLighthouse
|
||||||
context.Request.EnableBuffering(); // Allows us to reset the position of Request.Body for later logging
|
context.Request.EnableBuffering(); // Allows us to reset the position of Request.Body for later logging
|
||||||
|
|
||||||
// Client digest check.
|
// Client digest check.
|
||||||
string authCookie;
|
if (!context.Request.Cookies.TryGetValue("MM_AUTH", out string authCookie)) authCookie = string.Empty;
|
||||||
if (!context.Request.Cookies.TryGetValue("MM_AUTH", out authCookie)) authCookie = string.Empty;
|
|
||||||
string digestPath = context.Request.Path;
|
string digestPath = context.Request.Path;
|
||||||
Stream body = context.Request.Body;
|
Stream body = context.Request.Body;
|
||||||
|
|
||||||
|
@ -91,7 +89,7 @@ namespace LBPUnion.ProjectLighthouse
|
||||||
}
|
}
|
||||||
|
|
||||||
// This does the same as above, but for the response stream.
|
// This does the same as above, but for the response stream.
|
||||||
using MemoryStream responseBuffer = new();
|
await using MemoryStream responseBuffer = new();
|
||||||
Stream oldResponseStream = context.Response.Body;
|
Stream oldResponseStream = context.Response.Body;
|
||||||
context.Response.Body = responseBuffer;
|
context.Response.Body = responseBuffer;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Types.Match
|
namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
{
|
{
|
||||||
|
[SuppressMessage("ReSharper", "CollectionNeverUpdated.Global")]
|
||||||
public class UpdatePlayersInRoom : IMatchData
|
public class UpdatePlayersInRoom : IMatchData
|
||||||
{
|
{
|
||||||
public List<string> Players;
|
public List<string> Players;
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Types.Profiles
|
namespace LBPUnion.ProjectLighthouse.Types.Profiles
|
||||||
{
|
{
|
||||||
public class Pins
|
public class Pins
|
||||||
{
|
{
|
||||||
[JsonPropertyName("progress")]
|
[JsonPropertyName("progress")]
|
||||||
public long[] Progress { get; set; }
|
public long[] Progress { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("awards")]
|
[JsonPropertyName("awards")]
|
||||||
public long[] Awards { get; set; }
|
public long[] Awards { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("profile_pins")]
|
[JsonPropertyName("profile_pins")]
|
||||||
public long[] ProfilePins { get; set; }
|
public long[] ProfilePins { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,6 @@ namespace LBPUnion.ProjectLighthouse.Types
|
||||||
set => this.PlayerIdCollection = string.Join(',', value);
|
set => this.PlayerIdCollection = string.Join(',', value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[XmlElement("score")]
|
[XmlElement("score")]
|
||||||
public int Points { get; set; }
|
public int Points { get; set; }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue