Fix all compiler warnings

This commit is contained in:
jvyden 2022-05-15 00:36:44 -04:00
commit b9a310ef90
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
9 changed files with 27 additions and 31 deletions

View file

@ -73,7 +73,7 @@ public class GameServerStartup
async (context, next) =>
{
// Client digest check.
if (!context.Request.Cookies.TryGetValue("MM_AUTH", out string authCookie)) authCookie = string.Empty;
if (!context.Request.Cookies.TryGetValue("MM_AUTH", out string? authCookie) || authCookie == null) authCookie = string.Empty;
string digestPath = context.Request.Path;
Stream body = context.Request.Body;

View file

@ -41,7 +41,8 @@
HttpUtility.HtmlDecode(comment.getComment(), messageWriter);
string decodedMessage = messageWriter.ToString();
string url = Url.RouteUrl(ViewContext.RouteData.Values);
string? url = Url.RouteUrl(ViewContext.RouteData.Values);
if (url == null) continue;
int rating = comment.ThumbsUp - comment.ThumbsDown;

View file

@ -5,24 +5,17 @@
@model LBPUnion.ProjectLighthouse.Types.Levels.Slot
@{
User user = (User)ViewData["User"];
User user = (User)ViewData["User"]!;
await using Database database = new();
string slotName = string.IsNullOrEmpty(Model.Name) ? "Unnamed Level" : Model.Name;
bool isMobile = (bool?)ViewData["IsMobile"] ?? false;
bool isQueued = false;
bool isHearted = false;
bool isQueued = await database.QueuedLevels.FirstOrDefaultAsync(h => h.SlotId == Model.SlotId && h.UserId == user.UserId) != null;
bool isHearted = await database.HeartedLevels.FirstOrDefaultAsync(h => h.SlotId == Model.SlotId && h.UserId == user.UserId) != null;
if (user != null)
{
isQueued = await database.QueuedLevels.FirstOrDefaultAsync(h => h.SlotId == Model.SlotId && h.UserId == user.UserId) != null;
isHearted = await database.HeartedLevels.FirstOrDefaultAsync(h => h.SlotId == Model.SlotId && h.UserId == user.UserId) != null;
}
string callbackUrl = (string)ViewData["CallbackUrl"];
string callbackUrl = (string)ViewData["CallbackUrl"]!;
bool showLink = (bool?)ViewData["ShowLink"] ?? false;
string iconHash = Model.IconHash;

View file

@ -26,10 +26,10 @@
@if (Model.PageNumber != 0)
{
<a href="/photos/@(Model.PageNumber - 1)@(Model.SearchValue.Length == 0 ? "" : "?name=" + Model.SearchValue)">Previous Page</a>
<a href="/photos/@(Model.PageNumber - 1)@(Model.SearchValue?.Length == 0 ? "" : "?name=" + Model.SearchValue)">Previous Page</a>
}
@(Model.PageNumber + 1) / @(Model.PageAmount)
@if (Model.PageNumber < Model.PageAmount - 1)
{
<a href="/photos/@(Model.PageNumber + 1)@(Model.SearchValue.Length == 0 ? "" : "?name=" + Model.SearchValue)">Next Page</a>
<a href="/photos/@(Model.PageNumber + 1)@(Model.SearchValue?.Length == 0 ? "" : "?name=" + Model.SearchValue)">Next Page</a>
}

View file

@ -15,7 +15,7 @@ public class RegisterForm : BaseLayout
public RegisterForm(Database database) : base(database)
{}
public string Error { get; private set; }
public string? Error { get; private set; }
[UsedImplicitly]
[SuppressMessage("ReSharper", "SpecifyStringComparison")]
@ -54,7 +54,7 @@ public class RegisterForm : BaseLayout
}
if (ServerConfiguration.Instance.Mail.MailEnabled &&
await this.Database.Users.FirstOrDefaultAsync(u => u.EmailAddress.ToLower() == emailAddress.ToLower()) != null)
await this.Database.Users.FirstOrDefaultAsync(u => u.EmailAddress != null && u.EmailAddress.ToLower() == emailAddress.ToLower()) != null)
{
this.Error = "The email address you've chosen is already taken.";
return this.Page();

View file

@ -10,8 +10,8 @@
Layout = "Layouts/BaseLayout";
Model.ShowTitleInPage = false;
Model.Title = Model.Slot.Name;
Model.Description = Model.Slot.Description;
Model.Title = Model.Slot?.Name ?? "";
Model.Description = Model.Slot?.Description ?? "";
bool isMobile = this.Request.IsMobile();
}
@ -22,7 +22,7 @@
"User", Model.User
},
{
"CallbackUrl", $"~/slot/{Model.Slot.SlotId}"
"CallbackUrl", $"~/slot/{Model.Slot?.SlotId}"
},
{
"ShowLink", false
@ -37,14 +37,15 @@
<div class="eight wide column">
<div class="ui blue segment">
<h2>Description</h2>
<p>@HttpUtility.HtmlDecode(string.IsNullOrEmpty(Model.Slot.Description) ? "This level has no description." : Model.Slot.Description)</p>
<p>@HttpUtility.HtmlDecode(string.IsNullOrEmpty(Model.Slot?.Description) ? "This level has no description." : Model.Slot.Description)</p>
</div>
</div>
<div class="eight wide column">
<div class="ui red segment">
<h2>Tags</h2>
@{
string[] authorLabels = Model.Slot.AuthorLabels.Split(",");
string[] authorLabels = Model.Slot?.AuthorLabels.Split(",") ?? new string[]
{};
if (authorLabels.Length == 1) // ..?? ok c#
{
<p>This level has no tags.</p>
@ -86,13 +87,13 @@
@for(int i = 0; i < Model.Reviews.Count; i++)
{
Review review = Model.Reviews[i];
string faceHash = review.Thumb switch {
string faceHash = (review.Thumb switch {
-1 => review.Reviewer?.BooHash,
0 => review.Reviewer?.MehHash,
1 => review.Reviewer?.YayHash,
_ => throw new ArgumentOutOfRangeException(),
};
}) ?? "";
if (string.IsNullOrWhiteSpace(faceHash))
{
@ -168,7 +169,7 @@
<div class="ui yellow segment">
<h2>Admin Options</h2>
@if (Model.Slot.TeamPick)
@if (Model.Slot?.TeamPick ?? false)
{
<a href="/admin/slot/@Model.Slot.SlotId/removeTeamPick">
<div class="ui pink button">
@ -179,7 +180,7 @@
}
else
{
<a href="/admin/slot/@Model.Slot.SlotId/teamPick">
<a href="/admin/slot/@Model.Slot?.SlotId/teamPick">
<div class="ui pink button">
<i class="ribbon icon"></i>
<span>Team Pick</span>
@ -187,7 +188,7 @@
</a>
}
<a href="/admin/slot/@Model.Slot.SlotId/delete">
<a href="/admin/slot/@Model.Slot?.SlotId/delete">
<div class="ui red button">
<i class="trash icon"></i>
<span>Delete</span>

View file

@ -42,10 +42,10 @@
@if (Model.PageNumber != 0)
{
<a href="/slots/@(Model.PageNumber - 1)@(Model.SearchValue.Length == 0 ? "" : "?name=" + Model.SearchValue)">Previous Page</a>
<a href="/slots/@(Model.PageNumber - 1)@(Model.SearchValue?.Length == 0 ? "" : "?name=" + Model.SearchValue)">Previous Page</a>
}
@(Model.PageNumber + 1) / @(Model.PageAmount)
@if (Model.PageNumber < Model.PageAmount - 1)
{
<a href="/slots/@(Model.PageNumber + 1)@(Model.SearchValue.Length == 0 ? "" : "?name=" + Model.SearchValue)">Next Page</a>
<a href="/slots/@(Model.PageNumber + 1)@(Model.SearchValue?.Length == 0 ? "" : "?name=" + Model.SearchValue)">Next Page</a>
}

View file

@ -36,10 +36,10 @@
@if (Model.PageNumber != 0)
{
<a href="/users/@(Model.PageNumber - 1)@(Model.SearchValue.Length == 0 ? "" : "?name=" + Model.SearchValue)">Previous Page</a>
<a href="/users/@(Model.PageNumber - 1)@(Model.SearchValue?.Length == 0 ? "" : "?name=" + Model.SearchValue)">Previous Page</a>
}
@(Model.PageNumber + 1) / @(Model.PageAmount)
@if (Model.PageNumber < Model.PageAmount - 1)
{
<a href="/users/@(Model.PageNumber + 1)@(Model.SearchValue.Length == 0 ? "" : "?name=" + Model.SearchValue)">Next Page</a>
<a href="/users/@(Model.PageNumber + 1)@(Model.SearchValue?.Length == 0 ? "" : "?name=" + Model.SearchValue)">Next Page</a>
}

View file

@ -44,6 +44,7 @@ public class DebugWarmupLifetime : IHostLifetime
ServerType.GameApi => ServerConfiguration.Instance.GameApiListenUrl,
ServerType.Website => ServerConfiguration.Instance.WebsiteListenUrl,
ServerType.Api => ServerConfiguration.Instance.ApiListenUrl,
_ => throw new ArgumentOutOfRangeException(),
};
url = url.Replace("0.0.0.0", "127.0.0.1");