mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
refactor: convert == null / != null to is null / is not null in 31 files
Replace old-style null comparisons with modern C# pattern matching syntax across Commands, Protocol, Mapping, ChatBots, Physics, Inventory, Logger, CommandHandler, Scripting, Crypto, and other modules. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
446c6e7739
commit
c7bc25aa17
31 changed files with 77 additions and 77 deletions
|
|
@ -251,7 +251,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
/// <returns>Net read thread ID</returns>
|
||||
public int GetNetMainThreadId()
|
||||
{
|
||||
return netRead != null ? netRead.Item1.ManagedThreadId : -1;
|
||||
return netRead is not null ? netRead.Item1.ManagedThreadId : -1;
|
||||
}
|
||||
|
||||
public bool SendCookieResponse(string name, byte[]? data)
|
||||
|
|
@ -268,7 +268,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
{
|
||||
try
|
||||
{
|
||||
if (netRead != null)
|
||||
if (netRead is not null)
|
||||
{
|
||||
netRead.Item2.Cancel();
|
||||
c.Close();
|
||||
|
|
@ -556,7 +556,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
string serverHash = CryptoHandler.GetServerHash(serverIDhash, serverPublicKey, secretKey);
|
||||
|
||||
bool needCheckSession = true;
|
||||
if (session.ServerPublicKey != null && session.SessionPreCheckTask != null
|
||||
if (session.ServerPublicKey is not null && session.SessionPreCheckTask is not null
|
||||
&& serverIDhash == session.ServerIDhash && Enumerable.SequenceEqual(serverPublicKey, session.ServerPublicKey))
|
||||
{
|
||||
session.SessionPreCheckTask.Wait();
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
|
||||
private readonly ForgeInfo? forgeInfo;
|
||||
private FMLHandshakeClientState fmlHandshakeState = FMLHandshakeClientState.START;
|
||||
private bool ForgeEnabled() { return forgeInfo != null; }
|
||||
private bool ForgeEnabled() { return forgeInfo is not null; }
|
||||
|
||||
/// <summary>
|
||||
/// Initialize a new Forge protocol handler
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
/// <remarks>Silently dropped connection can only be detected by attempting to read/write data</remarks>
|
||||
public bool IsConnected()
|
||||
{
|
||||
return c.Client != null && c.Connected;
|
||||
return c.Client is not null && c.Connected;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ namespace MinecraftClient.Protocol.Message
|
|||
|
||||
public LastSeenMessageList.AcknowledgedMessage? ToLastSeenMessageEntry()
|
||||
{
|
||||
return signature != null ? new LastSeenMessageList.AcknowledgedMessage(senderUUID, signature, true) : null;
|
||||
return signature is not null ? new LastSeenMessageList.AcknowledgedMessage(senderUUID, signature, true) : null;
|
||||
}
|
||||
|
||||
public bool LacksSender()
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ namespace MinecraftClient.Protocol.Message
|
|||
}
|
||||
}
|
||||
|
||||
if (lastEntry != null && messageCount < acknowledgedMessages.Length)
|
||||
if (lastEntry is not null && messageCount < acknowledgedMessages.Length)
|
||||
acknowledgedMessages[messageCount++] = lastEntry;
|
||||
|
||||
LastSeenMessageList.AcknowledgedMessage[] msgList = new LastSeenMessageList.AcknowledgedMessage[messageCount];
|
||||
|
|
@ -120,7 +120,7 @@ namespace MinecraftClient.Protocol.Message
|
|||
{
|
||||
// net.minecraft.network.message.LastSeenMessagesCollector#add(net.minecraft.network.message.MessageSignatureData, boolean)
|
||||
// net.minecraft.network.message.LastSeenMessagesCollector#add(net.minecraft.network.message.AcknowledgedMessage)
|
||||
if (lastEntry != null && entry.signature.SequenceEqual(lastEntry.signature))
|
||||
if (lastEntry is not null && entry.signature.SequenceEqual(lastEntry.signature))
|
||||
return false;
|
||||
lastEntry = entry;
|
||||
|
||||
|
|
@ -143,7 +143,7 @@ namespace MinecraftClient.Protocol.Message
|
|||
{
|
||||
int k = (nextIndex + j) % acknowledgedMessages.Length;
|
||||
AcknowledgedMessage? acknowledgedMessage = acknowledgedMessages[k];
|
||||
if (acknowledgedMessage == null)
|
||||
if (acknowledgedMessage is null)
|
||||
continue;
|
||||
bitset[j / 8] |= (byte)(1 << (j % 8)); // bitSet.set(j, true);
|
||||
objectList.Add(acknowledgedMessage);
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ namespace MinecraftClient.Protocol.ProfileKey
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
int code = response == null ? 0 : response.StatusCode;
|
||||
int code = response is null ? 0 : response.StatusCode;
|
||||
ConsoleIO.WriteLineFormatted("§cFetch authlib-injector metadata failed: HttpCode = " + code + ", Error = " + e.Message);
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLineFormatted("§c" + e.StackTrace);
|
||||
|
|
@ -93,12 +93,12 @@ namespace MinecraftClient.Protocol.ProfileKey
|
|||
}
|
||||
|
||||
var json = Json.ParseJson(response.Body);
|
||||
if (json?["keyPair"]?["publicKey"] == null
|
||||
|| json["keyPair"]?["privateKey"] == null
|
||||
|| json["publicKeySignature"] == null
|
||||
|| json["publicKeySignatureV2"] == null
|
||||
|| json["expiresAt"] == null
|
||||
|| json["refreshedAfter"] == null)
|
||||
if (json?["keyPair"]?["publicKey"] is null
|
||||
|| json["keyPair"]?["privateKey"] is null
|
||||
|| json["publicKeySignature"] is null
|
||||
|| json["publicKeySignatureV2"] is null
|
||||
|| json["expiresAt"] is null
|
||||
|| json["refreshedAfter"] is null)
|
||||
{
|
||||
throw new InvalidOperationException("Certificate endpoint returned an unexpected payload.");
|
||||
}
|
||||
|
|
@ -115,7 +115,7 @@ namespace MinecraftClient.Protocol.ProfileKey
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
int code = response == null ? 0 : response.StatusCode;
|
||||
int code = response is null ? 0 : response.StatusCode;
|
||||
ConsoleIO.WriteLineFormatted("§cFetch profile key failed: HttpCode = " + code + ", Error = " + e.Message);
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLineFormatted("§c" + e.StackTrace);
|
||||
|
|
@ -209,7 +209,7 @@ namespace MinecraftClient.Protocol.ProfileKey
|
|||
{
|
||||
List<byte> data = new();
|
||||
|
||||
if (precedingSignature != null)
|
||||
if (precedingSignature is not null)
|
||||
data.AddRange(precedingSignature);
|
||||
|
||||
data.AddRange(sender.ToBigEndianBytes());
|
||||
|
|
|
|||
|
|
@ -73,11 +73,11 @@ namespace MinecraftClient.Protocol.ProfileKey
|
|||
{
|
||||
List<string> datas = new();
|
||||
datas.Add(Convert.ToBase64String(PublicKey.Key));
|
||||
if (PublicKey.Signature == null)
|
||||
if (PublicKey.Signature is null)
|
||||
datas.Add(string.Empty);
|
||||
else
|
||||
datas.Add(Convert.ToBase64String(PublicKey.Signature));
|
||||
if (PublicKey.SignatureV2 == null)
|
||||
if (PublicKey.SignatureV2 is null)
|
||||
datas.Add(string.Empty);
|
||||
else
|
||||
datas.Add(Convert.ToBase64String(PublicKey.SignatureV2));
|
||||
|
|
|
|||
|
|
@ -25,10 +25,10 @@ namespace MinecraftClient.Protocol.ProfileKey
|
|||
if (!string.IsNullOrEmpty(sigV2))
|
||||
SignatureV2 = Convert.FromBase64String(sigV2!);
|
||||
|
||||
if (SignatureV2 == null || SignatureV2.Length == 0)
|
||||
if (SignatureV2 is null || SignatureV2.Length == 0)
|
||||
SignatureV2 = Signature;
|
||||
|
||||
if (Signature == null || Signature.Length == 0)
|
||||
if (Signature is null || Signature.Length == 0)
|
||||
Signature = SignatureV2;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ namespace MinecraftClient.Protocol.Session
|
|||
|
||||
public bool SessionPreCheck(LoginType type)
|
||||
{
|
||||
if (ID == string.Empty || PlayerID == String.Empty || ServerPublicKey == null)
|
||||
if (ID == string.Empty || PlayerID == String.Empty || ServerPublicKey is null)
|
||||
return false;
|
||||
Crypto.CryptoHandler.ClientAESPrivateKey ??= Crypto.CryptoHandler.GenerateAESPrivateKey();
|
||||
string serverHash = Crypto.CryptoHandler.GetServerHash(ServerIDhash, ServerPublicKey, Crypto.CryptoHandler.ClientAESPrivateKey);
|
||||
|
|
@ -57,7 +57,7 @@ namespace MinecraftClient.Protocol.Session
|
|||
public override string ToString()
|
||||
{
|
||||
return String.Join(",", ID, PlayerName, PlayerID, ClientID, RefreshToken, ServerIDhash,
|
||||
(ServerPublicKey == null) ? String.Empty : Convert.ToBase64String(ServerPublicKey));
|
||||
(ServerPublicKey is null) ? String.Empty : Convert.ToBase64String(ServerPublicKey));
|
||||
}
|
||||
|
||||
public static SessionToken FromString(string tokenString)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue