mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-08 21:08:39 +00:00
Implement property dependency injection for the website (#806)
* Remove most non DI usages of DbContext * Optimize website queries and refactor startup to use top level statements * Remove unused functions in UserEntity and SlotEntity * Optimize LBP1 LevelTags
This commit is contained in:
parent
727dd4e903
commit
e43397ac6a
47 changed files with 333 additions and 430 deletions
|
@ -98,17 +98,22 @@ public class MatchController : ControllerBase
|
|||
case FindBestRoom diveInData when MatchHelper.UserLocations.Count > 1:
|
||||
#endif
|
||||
{
|
||||
FindBestRoomResponse? response = RoomHelper.FindBestRoom
|
||||
(user, token.GameVersion, diveInData.RoomSlot, token.Platform, token.UserLocation);
|
||||
FindBestRoomResponse? response = RoomHelper.FindBestRoom(this.database,
|
||||
user,
|
||||
token.GameVersion,
|
||||
diveInData.RoomSlot,
|
||||
token.Platform,
|
||||
token.UserLocation);
|
||||
|
||||
if (response == null) return this.NotFound();
|
||||
|
||||
string serialized = JsonSerializer.Serialize(response, typeof(FindBestRoomResponse));
|
||||
foreach (Player player in response.Players) MatchHelper.AddUserRecentlyDivedIn(user.UserId, player.User.UserId);
|
||||
foreach (Player player in response.Players)
|
||||
MatchHelper.AddUserRecentlyDivedIn(user.UserId, player.User.UserId);
|
||||
|
||||
return this.Ok($"[{{\"StatusCode\":200}},{serialized}]");
|
||||
}
|
||||
case CreateRoom createRoom when MatchHelper.UserLocations.Count >= 1:
|
||||
case CreateRoom createRoom when !MatchHelper.UserLocations.IsEmpty:
|
||||
{
|
||||
List<int> users = new();
|
||||
foreach (string playerUsername in createRoom.Players)
|
||||
|
@ -139,9 +144,8 @@ public class MatchController : ControllerBase
|
|||
}
|
||||
|
||||
room.PlayerIds = users.Select(u => u.UserId).ToList();
|
||||
await RoomHelper.CleanupRooms(null, room);
|
||||
await RoomHelper.CleanupRooms(this.database, null, room);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,17 +34,17 @@ public class PhotosController : ControllerBase
|
|||
[HttpPost("uploadPhoto")]
|
||||
public async Task<IActionResult> UploadPhoto()
|
||||
{
|
||||
UserEntity? user = await this.database.UserFromGameToken(this.GetToken());
|
||||
if (user == null) return this.Forbid();
|
||||
GameTokenEntity token = this.GetToken();
|
||||
|
||||
if (user.GetUploadedPhotoCount(this.database) >= ServerConfiguration.Instance.UserGeneratedContentLimits.PhotosQuota) return this.BadRequest();
|
||||
int photoCount = await this.database.Photos.CountAsync(p => p.CreatorId == token.UserId);
|
||||
if (photoCount >= ServerConfiguration.Instance.UserGeneratedContentLimits.PhotosQuota) return this.BadRequest();
|
||||
|
||||
GamePhoto? photo = await this.DeserializeBody<GamePhoto>();
|
||||
if (photo == null) return this.BadRequest();
|
||||
|
||||
foreach (PhotoEntity p in this.database.Photos.Where(p => p.CreatorId == user.UserId))
|
||||
foreach (PhotoEntity p in this.database.Photos.Where(p => p.CreatorId == token.UserId))
|
||||
{
|
||||
if (p.LargeHash == photo.LargeHash) return this.Ok(); // photo already uplaoded
|
||||
if (p.LargeHash == photo.LargeHash) return this.Ok(); // photo already uploaded
|
||||
if (p.MediumHash == photo.MediumHash) return this.Ok();
|
||||
if (p.SmallHash == photo.SmallHash) return this.Ok();
|
||||
if (p.PlanHash == photo.PlanHash) return this.Ok();
|
||||
|
@ -52,8 +52,7 @@ public class PhotosController : ControllerBase
|
|||
|
||||
PhotoEntity photoEntity = new()
|
||||
{
|
||||
CreatorId = user.UserId,
|
||||
Creator = user,
|
||||
CreatorId = token.UserId,
|
||||
SmallHash = photo.SmallHash,
|
||||
MediumHash = photo.MediumHash,
|
||||
LargeHash = photo.LargeHash,
|
||||
|
@ -145,12 +144,14 @@ public class PhotosController : ControllerBase
|
|||
|
||||
await this.database.SaveChangesAsync();
|
||||
|
||||
string username = await this.database.UsernameFromGameToken(token);
|
||||
|
||||
await WebhookHelper.SendWebhook
|
||||
(
|
||||
new EmbedBuilder
|
||||
{
|
||||
Title = "New photo uploaded!",
|
||||
Description = $"{user.Username} uploaded a new photo.",
|
||||
Description = $"{username} uploaded a new photo.",
|
||||
ImageUrl = $"{ServerConfiguration.Instance.ExternalUrl}/gameAssets/{photo.LargeHash}",
|
||||
Color = WebhookHelper.GetEmbedColor(),
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
|||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
using LBPUnion.ProjectLighthouse.Types.Filter;
|
||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
using LBPUnion.ProjectLighthouse.Types.Matchmaking.Rooms;
|
||||
using LBPUnion.ProjectLighthouse.Types.Misc;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Types.Users;
|
||||
|
|
|
@ -1,36 +1,22 @@
|
|||
using LBPUnion.ProjectLighthouse;
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Logging.Loggers.AspNet;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Startup;
|
||||
using LBPUnion.ProjectLighthouse.Types.Misc;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer;
|
||||
await StartupTasks.Run(ServerType.GameServer);
|
||||
|
||||
public static class Program
|
||||
IHostBuilder builder = Host.CreateDefaultBuilder();
|
||||
builder.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
StartupTasks.Run(args, ServerType.GameServer);
|
||||
webBuilder.UseStartup<GameServerStartup>();
|
||||
webBuilder.UseUrls(ServerConfiguration.Instance.GameApiListenUrl);
|
||||
});
|
||||
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
builder.ConfigureLogging(logging =>
|
||||
{
|
||||
logging.ClearProviders();
|
||||
logging.AddProvider(new AspNetToLighthouseLoggerProvider());
|
||||
});
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args)
|
||||
=> Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults
|
||||
(
|
||||
webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<GameServerStartup>();
|
||||
webBuilder.UseUrls(ServerConfiguration.Instance.GameApiListenUrl);
|
||||
}
|
||||
)
|
||||
.ConfigureLogging
|
||||
(
|
||||
logging =>
|
||||
{
|
||||
logging.ClearProviders();
|
||||
logging.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, AspNetToLighthouseLoggerProvider>());
|
||||
}
|
||||
);
|
||||
}
|
||||
await builder.Build().RunAsync();
|
|
@ -113,6 +113,5 @@ public class GameServerStartup
|
|||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints => endpoints.MapControllers());
|
||||
app.UseEndpoints(endpoints => endpoints.MapRazorPages());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue