diff --git a/CelesteNet.Client/CelesteNetClientSettings.cs b/CelesteNet.Client/CelesteNetClientSettings.cs index 0770af2d..a7c13bc4 100644 --- a/CelesteNet.Client/CelesteNetClientSettings.cs +++ b/CelesteNet.Client/CelesteNetClientSettings.cs @@ -784,7 +784,7 @@ public TextMenu.Slider CreateMenuSlider(TextMenu menu, string dialogLabel, int m return item; } - public TextMenu.Button CreateMenuButton(TextMenu menu, string dialogLabel, Func? dialogTransform, Action onPress) + public TextMenu.Button CreateMenuButton(TextMenu menu, string dialogLabel, Func dialogTransform, Action onPress) { string label = $"modoptions_celestenetclient_{dialogLabel}".DialogClean(); TextMenu.Button item = new TextMenu.Button(dialogTransform?.Invoke(label) ?? label); @@ -792,7 +792,7 @@ public TextMenu.Button CreateMenuButton(TextMenu menu, string dialogLabel, Func< menu.Add(item); return item; } - public TextMenu.Button CreateMenuStringInput(TextMenu menu, string dialogLabel, Func? dialogTransform, int maxValueLength, Func currentValue, Action newValue) { + public TextMenu.Button CreateMenuStringInput(TextMenu menu, string dialogLabel, Func dialogTransform, int maxValueLength, Func currentValue, Action newValue) { string label = $"modoptions_celestenetclient_{dialogLabel}".DialogClean(); TextMenu.Button item = new TextMenu.Button(dialogTransform?.Invoke(label) ?? label); item.Pressed(() => { diff --git a/CelesteNet.Client/Components/CelesteNetChatComponent.cs b/CelesteNet.Client/Components/CelesteNetChatComponent.cs index 0ea53124..80f1b70a 100644 --- a/CelesteNet.Client/Components/CelesteNetChatComponent.cs +++ b/CelesteNet.Client/Components/CelesteNetChatComponent.cs @@ -65,8 +65,8 @@ public enum ChatMode { Off } - public MTexture? InputScrollUpIcon; - public MTexture? InputScrollDownIcon; + public MTexture InputScrollUpIcon; + public MTexture InputScrollDownIcon; public MTexture ArrowUpIcon => GFX.Gui["controls/directions/0x-1"]; public MTexture ArrowDownIcon => GFX.Gui["controls/directions/0x1"]; private bool activeController = false; diff --git a/CelesteNet.Client/Components/CelesteNetClientInfoComponent.cs b/CelesteNet.Client/Components/CelesteNetClientInfoComponent.cs index 22d6af86..40325739 100644 --- a/CelesteNet.Client/Components/CelesteNetClientInfoComponent.cs +++ b/CelesteNet.Client/Components/CelesteNetClientInfoComponent.cs @@ -70,7 +70,7 @@ private string ClientInfoGet(string inp) { [MethodImpl(MethodImplOptions.AggressiveInlining)] private NetworkInterface FindInternetFacingNic() { - IPAddress? addrInternet = null; + IPAddress addrInternet = null; Socket socket = new(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); try { socket.Connect("8.8.8.8", 80); diff --git a/CelesteNet.Client/Handshake.cs b/CelesteNet.Client/Handshake.cs index 3e0ee8d9..0a7b808e 100644 --- a/CelesteNet.Client/Handshake.cs +++ b/CelesteNet.Client/Handshake.cs @@ -48,8 +48,8 @@ public static class Handshake { // Read the "HTTP" response string statusLine = netStream.UnbufferedReadLine(); - string[] statusSegs = statusLine.Split(new[] { ' ' }, 3); - if (statusSegs.Length != 3) + string[] statusSegs = statusLine?.Split(new[] { ' ' }, 3); + if (statusSegs?.Length != 3) throw new InvalidDataException($"Invalid HTTP response status line: '{statusLine}'"); int statusCode = int.Parse(statusSegs[1]); diff --git a/CelesteNet.Server.FrontendModule/RCEPs/RCEPControl.cs b/CelesteNet.Server.FrontendModule/RCEPs/RCEPControl.cs index 645d02fd..95bc96a7 100644 --- a/CelesteNet.Server.FrontendModule/RCEPs/RCEPControl.cs +++ b/CelesteNet.Server.FrontendModule/RCEPs/RCEPControl.cs @@ -764,7 +764,7 @@ public static void ProcessAllAvatars(Frontend f, HttpRequestEventArgs c) { try { info = Image.Identify(data); - } catch (UnknownImageFormatException e) { + } catch (UnknownImageFormatException) { Logger.Log(LogLevel.INF, "frontend", $"Could not identify avatar: {uid}"); continue; } diff --git a/CelesteNet.Server.SqliteModule/MessagePackHelper.cs b/CelesteNet.Server.SqliteModule/MessagePackHelper.cs index 4a11ac49..388e88b9 100644 --- a/CelesteNet.Server.SqliteModule/MessagePackHelper.cs +++ b/CelesteNet.Server.SqliteModule/MessagePackHelper.cs @@ -1,12 +1,11 @@ -using Microsoft.Xna.Framework; -using System; +using System; using System.Collections.Generic; using MessagePack; using MessagePack.Formatters; using MessagePack.Resolvers; +using Microsoft.Xna.Framework; -namespace Celeste.Mod.CelesteNet.Server.Sqlite -{ +namespace Celeste.Mod.CelesteNet.Server.Sqlite { public static class MessagePackHelper { public static readonly MessagePackSerializerOptions Options = ContractlessStandardResolver.Options @@ -29,12 +28,12 @@ public class CelesteNetMessagePackResolver : IFormatterResolver { private CelesteNetMessagePackResolver() { } - public IMessagePackFormatter GetFormatter() + public IMessagePackFormatter? GetFormatter() => Cache.Formatter; private static class Cache { - public static IMessagePackFormatter Formatter; + public static IMessagePackFormatter? Formatter; static Cache() { if (Formatters.TryGetValue(typeof(T), out object? fo)) { diff --git a/CelesteNet.Server.SqliteModule/SqliteUserData.cs b/CelesteNet.Server.SqliteModule/SqliteUserData.cs index 1766f253..104ffea3 100644 --- a/CelesteNet.Server.SqliteModule/SqliteUserData.cs +++ b/CelesteNet.Server.SqliteModule/SqliteUserData.cs @@ -139,7 +139,7 @@ FROM sqlite_master { "$real", real }, { "$type", typename }, }; - return mini.Run().value; + return mini.Run().value ?? ""; } else { using MiniCommand mini = new(this) { @@ -182,7 +182,7 @@ FROM sqlite_master ", { "$name", name }, }; - return mini.Run().value; + return mini.Run().value ?? ""; } else { using MiniCommand mini = new(this) { @@ -226,7 +226,7 @@ FROM sqlite_master { "$name", name }, { "$real", real }, }; - return mini.Run().value; + return mini.Run().value ?? ""; } else { using MiniCommand mini = new(this) { @@ -401,9 +401,14 @@ FROM [{table}] { "$format", (int) DataFormat.MessagePack }, { "$length", ms.Length }, }; - (SqliteConnection con, SqliteCommand cmd) = mini.Run(out long rowid); + (SqliteConnection con, SqliteCommand cmd) = mini.Run(out long? rowid); - using SqliteBlob blob = new(con, table, "value", rowid); + if (rowid == null) { + Logger.Log(LogLevel.ERR, "sqlite", $"Save: Failed getting rowid for {table} of UID {uid}"); + return; + } + + using SqliteBlob blob = new(con, table, "value", (long) rowid); ms.CopyTo(blob); blob.Dispose(); } @@ -428,9 +433,14 @@ FROM [{table}] { "$uid", uid }, { "$length", ms.Length }, }; - (SqliteConnection con, SqliteCommand cmd) = mini.Run(out long rowid); + (SqliteConnection con, SqliteCommand cmd) = mini.Run(out long? rowid); + + if (rowid == null) { + Logger.Log(LogLevel.ERR, "sqlite", $"WriteFile: Failed getting rowid for {table} of UID {uid}"); + return; + } - using SqliteBlob blob = new(con, table, "value", rowid); + using SqliteBlob blob = new(con, table, "value", (long) rowid); ms.CopyTo(blob); blob.Dispose(); }); @@ -874,9 +884,14 @@ FROM [{table}] { "$format", (int) format }, { "$length", ms.Length }, }; - (SqliteConnection con, SqliteCommand cmd) = mini.Run(out long rowid); + (SqliteConnection con, SqliteCommand cmd) = mini.Run(out long? rowid); + + if (rowid == null) { + Logger.Log(LogLevel.ERR, "sqlite", $"InsertData: Failed getting rowid for {table} of UID {uid}"); + return; + } - using SqliteBlob blob = new(con, table, "value", rowid); + using SqliteBlob blob = new(con, table, "value", (long) rowid); ms.CopyTo(blob); blob.Dispose(); } @@ -902,9 +917,14 @@ FROM [{table}] { "$uid", uid }, { "$length", ms.Length }, }; - (SqliteConnection con, SqliteCommand cmd) = mini.Run(out long rowid); + (SqliteConnection con, SqliteCommand cmd) = mini.Run(out long? rowid); + + if (rowid == null) { + Logger.Log(LogLevel.ERR, "sqlite", $"InsertFile: Failed getting rowid for {table} of UID {uid}"); + return; + } - using SqliteBlob blob = new(con, table, "value", rowid); + using SqliteBlob blob = new(con, table, "value", (long) rowid); ms.CopyTo(blob); blob.Dispose(); } @@ -1298,14 +1318,14 @@ public void Next(MiniCommand cmd) { return (con, cmd, cmd.ExecuteNonQuery()); } - public (SqliteConnection con, SqliteCommand cmd, T value) Run() { + public (SqliteConnection con, SqliteCommand cmd, T? value) Run() { (SqliteConnection con, SqliteCommand cmd) = Prepare(); - return (con, cmd, (T) cmd.ExecuteScalar()); + return (con, cmd, (T?) cmd.ExecuteScalar()); } - public (SqliteConnection con, SqliteCommand cmd) Run(out T value) { + public (SqliteConnection con, SqliteCommand cmd) Run(out T? value) { (SqliteConnection con, SqliteCommand cmd) = Prepare(); - value = (T) cmd.ExecuteScalar(); + value = (T?) cmd.ExecuteScalar(); return (con, cmd); } diff --git a/CelesteNet.Shared/CelesteNetUtils.cs b/CelesteNet.Shared/CelesteNetUtils.cs index 09c739c0..1a3f6c45 100644 --- a/CelesteNet.Shared/CelesteNetUtils.cs +++ b/CelesteNet.Shared/CelesteNetUtils.cs @@ -238,7 +238,7 @@ public static bool IsDisconnect(this SocketException se) { } } - public static string UnbufferedReadLine(this NetworkStream netStream) { + public static string? UnbufferedReadLine(this NetworkStream netStream) { //Unbuffered "read line" implementation reading every byte one at a time //Extremely slow and inefficient, but otherwise we may gobble up binary packet bytes by accident :catresort: List lineChars = new List(); diff --git a/CelesteNet.Shared/DataTypes/DataClientInfo.cs b/CelesteNet.Shared/DataTypes/DataClientInfo.cs index d1ba5834..dea49092 100644 --- a/CelesteNet.Shared/DataTypes/DataClientInfo.cs +++ b/CelesteNet.Shared/DataTypes/DataClientInfo.cs @@ -85,7 +85,7 @@ static DataClientInfoRequest() { public uint ID = uint.MaxValue; - public string Nonce; + public string Nonce = ""; public string[] List = Dummy.EmptyArray; public string[] MapStrings = Dummy.EmptyArray;