mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
Modernize null-check patterns in Protocol18.cs
Replace '== null' with 'is null' and '!= null' with 'is not null' for all 25 null comparisons in the file, following modern C# pattern matching conventions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
cf34db526b
commit
902e944cbb
1 changed files with 25 additions and 25 deletions
|
|
@ -133,7 +133,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
pForge = new Protocol18Forge(forgeInfo, protocolVersion, dataTypes, this, handler);
|
pForge = new Protocol18Forge(forgeInfo, protocolVersion, dataTypes, this, handler);
|
||||||
pTerrain = new Protocol18Terrain(protocolVersion, dataTypes, handler);
|
pTerrain = new Protocol18Terrain(protocolVersion, dataTypes, handler);
|
||||||
packetPalette = new PacketTypeHandler(protocolVersion, forgeInfo != null).GetTypeHandler();
|
packetPalette = new PacketTypeHandler(protocolVersion, forgeInfo is not null).GetTypeHandler();
|
||||||
log = handler.GetLogger();
|
log = handler.GetLogger();
|
||||||
randomGen = RandomNumberGenerator.Create();
|
randomGen = RandomNumberGenerator.Create();
|
||||||
lastSeenMessagesCollector = protocolVersion >= MC_1_19_3_Version ? new(20) : new(5);
|
lastSeenMessagesCollector = protocolVersion >= MC_1_19_3_Version ? new(20) : new(5);
|
||||||
|
|
@ -524,7 +524,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
else if (isDimension)
|
else if (isDimension)
|
||||||
{
|
{
|
||||||
dimensionIdMap!.Add(i, entryId);
|
dimensionIdMap!.Add(i, entryId);
|
||||||
if (nbtData != null && handler.GetTerrainEnabled())
|
if (nbtData is not null && handler.GetTerrainEnabled())
|
||||||
World.StoreOneDimension(entryId, nbtData);
|
World.StoreOneDimension(entryId, nbtData);
|
||||||
}
|
}
|
||||||
else if (isAttribute)
|
else if (isAttribute)
|
||||||
|
|
@ -984,7 +984,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var player = handler.GetPlayerInfo(senderUuid);
|
var player = handler.GetPlayerInfo(senderUuid);
|
||||||
verifyResult = player != null && player.VerifyMessage(signedChat, timestamp, salt,
|
verifyResult = player is not null && player.VerifyMessage(signedChat, timestamp, salt,
|
||||||
ref messageSignature);
|
ref messageSignature);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1043,7 +1043,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
var messageTypeEnum =
|
var messageTypeEnum =
|
||||||
ChatParser.ChatId2Type!.GetValueOrDefault(chatTypeId, ChatParser.MessageType.CHAT);
|
ChatParser.ChatId2Type!.GetValueOrDefault(chatTypeId, ChatParser.MessageType.CHAT);
|
||||||
|
|
||||||
if (targetName != null &&
|
if (targetName is not null &&
|
||||||
(messageTypeEnum == ChatParser.MessageType.TEAM_MSG_COMMAND_INCOMING ||
|
(messageTypeEnum == ChatParser.MessageType.TEAM_MSG_COMMAND_INCOMING ||
|
||||||
messageTypeEnum == ChatParser.MessageType.TEAM_MSG_COMMAND_OUTGOING))
|
messageTypeEnum == ChatParser.MessageType.TEAM_MSG_COMMAND_OUTGOING))
|
||||||
senderTeamName = Json.ParseJson(targetName)!["with"]![0]!
|
senderTeamName = Json.ParseJson(targetName)!["with"]![0]!
|
||||||
|
|
@ -1052,7 +1052,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
if (string.IsNullOrWhiteSpace(senderDisplayName))
|
if (string.IsNullOrWhiteSpace(senderDisplayName))
|
||||||
{
|
{
|
||||||
var player = handler.GetPlayerInfo(senderUuid);
|
var player = handler.GetPlayerInfo(senderUuid);
|
||||||
if (player != null && (player.DisplayName != null || player is { Name: not null }) &&
|
if (player is not null && (player.DisplayName is not null || player is { Name: not null }) &&
|
||||||
string.IsNullOrWhiteSpace(senderDisplayName))
|
string.IsNullOrWhiteSpace(senderDisplayName))
|
||||||
{
|
{
|
||||||
senderDisplayName = ChatParser.ParseText(player.DisplayName ?? player.Name);
|
senderDisplayName = ChatParser.ParseText(player.DisplayName ?? player.Name);
|
||||||
|
|
@ -1071,7 +1071,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var player = handler.GetPlayerInfo(senderUuid);
|
var player = handler.GetPlayerInfo(senderUuid);
|
||||||
if (player == null || !player.IsMessageChainLegal())
|
if (player is null || !player.IsMessageChainLegal())
|
||||||
verifyResult = false;
|
verifyResult = false;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -1158,7 +1158,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
if (string.IsNullOrWhiteSpace(senderDisplayName))
|
if (string.IsNullOrWhiteSpace(senderDisplayName))
|
||||||
{
|
{
|
||||||
var player = handler.GetPlayerInfo(senderUuid);
|
var player = handler.GetPlayerInfo(senderUuid);
|
||||||
if (player != null && (player.DisplayName != null || player.Name != null) &&
|
if (player is not null && (player.DisplayName is not null || player.Name is not null) &&
|
||||||
string.IsNullOrWhiteSpace(senderDisplayName))
|
string.IsNullOrWhiteSpace(senderDisplayName))
|
||||||
{
|
{
|
||||||
senderDisplayName = player.DisplayName ?? player.Name;
|
senderDisplayName = player.DisplayName ?? player.Name;
|
||||||
|
|
@ -1170,7 +1170,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
}
|
}
|
||||||
|
|
||||||
bool verifyResult;
|
bool verifyResult;
|
||||||
if (!isOnlineMode || messageSignature == null)
|
if (!isOnlineMode || messageSignature is null)
|
||||||
verifyResult = false;
|
verifyResult = false;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -1179,7 +1179,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var player = handler.GetPlayerInfo(senderUuid);
|
var player = handler.GetPlayerInfo(senderUuid);
|
||||||
if (player == null || !player.IsMessageChainLegal())
|
if (player is null || !player.IsMessageChainLegal())
|
||||||
verifyResult = false;
|
verifyResult = false;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -1336,7 +1336,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
{
|
{
|
||||||
var player = handler.GetPlayerInfo(senderUuid);
|
var player = handler.GetPlayerInfo(senderUuid);
|
||||||
|
|
||||||
if (player == null || !player.IsMessageChainLegal())
|
if (player is null || !player.IsMessageChainLegal())
|
||||||
verifyResult = false;
|
verifyResult = false;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -2017,7 +2017,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
// Warning: It is legal to include unloaded chunks in the UnloadChunk packet.
|
// Warning: It is legal to include unloaded chunks in the UnloadChunk packet.
|
||||||
// Since chunks that have not been loaded are not recorded, this may result
|
// Since chunks that have not been loaded are not recorded, this may result
|
||||||
// in loading chunks that should be unloaded and inaccurate statistics.
|
// in loading chunks that should be unloaded and inaccurate statistics.
|
||||||
if (handler.GetWorld()[chunkX, chunkZ] != null)
|
if (handler.GetWorld()[chunkX, chunkZ] is not null)
|
||||||
Interlocked.Decrement(ref handler.GetWorld().chunkCnt);
|
Interlocked.Decrement(ref handler.GetWorld().chunkCnt);
|
||||||
|
|
||||||
handler.GetWorld()[chunkX, chunkZ] = null;
|
handler.GetWorld()[chunkX, chunkZ] = null;
|
||||||
|
|
@ -2061,7 +2061,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var playerGet = handler.GetPlayerInfo(playerUuid);
|
var playerGet = handler.GetPlayerInfo(playerUuid);
|
||||||
if (playerGet == null)
|
if (playerGet is null)
|
||||||
{
|
{
|
||||||
player = new(string.Empty, playerUuid);
|
player = new(string.Empty, playerUuid);
|
||||||
handler.OnPlayerJoin(player);
|
handler.OnPlayerJoin(player);
|
||||||
|
|
@ -2221,7 +2221,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
if (dataTypes.ReadNextBool(packetData))
|
if (dataTypes.ReadNextBool(packetData))
|
||||||
{
|
{
|
||||||
var player = handler.GetPlayerInfo(uuid);
|
var player = handler.GetPlayerInfo(uuid);
|
||||||
if (player != null)
|
if (player is not null)
|
||||||
player.DisplayName = dataTypes.ReadNextString(packetData);
|
player.DisplayName = dataTypes.ReadNextString(packetData);
|
||||||
else
|
else
|
||||||
dataTypes.SkipNextString(packetData);
|
dataTypes.SkipNextString(packetData);
|
||||||
|
|
@ -2365,7 +2365,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
for (var slotId = 0; slotId < elements; slotId++)
|
for (var slotId = 0; slotId < elements; slotId++)
|
||||||
{
|
{
|
||||||
var item = dataTypes.ReadNextItemSlot(packetData, itemPalette);
|
var item = dataTypes.ReadNextItemSlot(packetData, itemPalette);
|
||||||
if (item != null)
|
if (item is not null)
|
||||||
inventorySlots[slotId] = item;
|
inventorySlots[slotId] = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3109,7 +3109,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
/// <returns>Net read thread ID</returns>
|
/// <returns>Net read thread ID</returns>
|
||||||
public int GetNetMainThreadId()
|
public int GetNetMainThreadId()
|
||||||
{
|
{
|
||||||
return netMain != null ? netMain.Item1.ManagedThreadId : -1;
|
return netMain is not null ? netMain.Item1.ManagedThreadId : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -3119,12 +3119,12 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (netMain != null)
|
if (netMain is not null)
|
||||||
{
|
{
|
||||||
netMain.Item2.Cancel();
|
netMain.Item2.Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (netReader != null)
|
if (netReader is not null)
|
||||||
{
|
{
|
||||||
netReader.Item2.Cancel();
|
netReader.Item2.Cancel();
|
||||||
socketWrapper.Disconnect();
|
socketWrapper.Disconnect();
|
||||||
|
|
@ -3212,7 +3212,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
// 1.19 - 1.19.2
|
// 1.19 - 1.19.2
|
||||||
if (protocolVersion is >= MC_1_19_Version and < MC_1_19_3_Version)
|
if (protocolVersion is >= MC_1_19_Version and < MC_1_19_3_Version)
|
||||||
{
|
{
|
||||||
if (playerKeyPair == null)
|
if (playerKeyPair is null)
|
||||||
fullLoginPacket.AddRange(dataTypes.GetBool(false)); // Has Sig Data
|
fullLoginPacket.AddRange(dataTypes.GetBool(false)); // Has Sig Data
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -3371,7 +3371,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
// 1.19 - 1.19.2
|
// 1.19 - 1.19.2
|
||||||
if (protocolVersion is >= MC_1_19_Version and < MC_1_19_3_Version)
|
if (protocolVersion is >= MC_1_19_Version and < MC_1_19_3_Version)
|
||||||
{
|
{
|
||||||
if (playerKeyPair == null)
|
if (playerKeyPair is null)
|
||||||
{
|
{
|
||||||
encryptionResponse.AddRange(dataTypes.GetBool(true)); // Has Verify Token
|
encryptionResponse.AddRange(dataTypes.GetBool(true)); // Has Verify Token
|
||||||
encryptionResponse.AddRange(dataTypes.GetArray(RSAService.Encrypt(token, false))); // Verify Token
|
encryptionResponse.AddRange(dataTypes.GetArray(RSAService.Encrypt(token, false))); // Verify Token
|
||||||
|
|
@ -3622,7 +3622,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
}
|
}
|
||||||
|
|
||||||
ConsoleIO.WriteLineFormatted("§8" + string.Format(Translations.mcc_server_protocol, version,
|
ConsoleIO.WriteLineFormatted("§8" + string.Format(Translations.mcc_server_protocol, version,
|
||||||
protocolVersion + (forgeInfo != null ? Translations.mcc_with_forge : "")));
|
protocolVersion + (forgeInfo is not null ? Translations.mcc_with_forge : "")));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -3719,7 +3719,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
public void Acknowledge(ChatMessage message)
|
public void Acknowledge(ChatMessage message)
|
||||||
{
|
{
|
||||||
var entry = message.ToLastSeenMessageEntry();
|
var entry = message.ToLastSeenMessageEntry();
|
||||||
if (entry == null) return;
|
if (entry is null) return;
|
||||||
|
|
||||||
if (protocolVersion >= MC_1_19_3_Version)
|
if (protocolVersion >= MC_1_19_3_Version)
|
||||||
{
|
{
|
||||||
|
|
@ -3768,7 +3768,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
List<Tuple<string, string>>? needSigned = null;
|
List<Tuple<string, string>>? needSigned = null;
|
||||||
bool canSignCommand = protocolVersion >= MC_1_19_Version &&
|
bool canSignCommand = protocolVersion >= MC_1_19_Version &&
|
||||||
isOnlineMode &&
|
isOnlineMode &&
|
||||||
playerKeyPair != null &&
|
playerKeyPair is not null &&
|
||||||
Config.Signature.LoginWithSecureProfile &&
|
Config.Signature.LoginWithSecureProfile &&
|
||||||
Config.Signature.SignMessageInCommand;
|
Config.Signature.SignMessageInCommand;
|
||||||
|
|
||||||
|
|
@ -3798,7 +3798,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
var timeNow = DateTimeOffset.UtcNow;
|
var timeNow = DateTimeOffset.UtcNow;
|
||||||
fields.AddRange(DataTypes.GetLong(timeNow.ToUnixTimeMilliseconds()));
|
fields.AddRange(DataTypes.GetLong(timeNow.ToUnixTimeMilliseconds()));
|
||||||
|
|
||||||
if (needSigned == null || needSigned.Count == 0)
|
if (needSigned is null || needSigned.Count == 0)
|
||||||
{
|
{
|
||||||
fields.AddRange(DataTypes.GetLong(0));
|
fields.AddRange(DataTypes.GetLong(0));
|
||||||
fields.AddRange(DataTypes.GetVarInt(0));
|
fields.AddRange(DataTypes.GetVarInt(0));
|
||||||
|
|
@ -3902,7 +3902,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
var timeNow = DateTimeOffset.UtcNow;
|
var timeNow = DateTimeOffset.UtcNow;
|
||||||
fields.AddRange(DataTypes.GetLong(timeNow.ToUnixTimeMilliseconds()));
|
fields.AddRange(DataTypes.GetLong(timeNow.ToUnixTimeMilliseconds()));
|
||||||
|
|
||||||
if (!isOnlineMode || playerKeyPair == null || !Config.Signature.LoginWithSecureProfile ||
|
if (!isOnlineMode || playerKeyPair is null || !Config.Signature.LoginWithSecureProfile ||
|
||||||
!Config.Signature.SignChat)
|
!Config.Signature.SignChat)
|
||||||
{
|
{
|
||||||
fields.AddRange(DataTypes.GetLong(0)); // Salt: Long
|
fields.AddRange(DataTypes.GetLong(0)); // Salt: Long
|
||||||
|
|
@ -5105,7 +5105,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
|
|
||||||
public bool SendPlayerSession(PlayerKeyPair? playerKeyPair)
|
public bool SendPlayerSession(PlayerKeyPair? playerKeyPair)
|
||||||
{
|
{
|
||||||
if (playerKeyPair == null || !isOnlineMode)
|
if (playerKeyPair is null || !isOnlineMode)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (protocolVersion >= MC_1_19_3_Version)
|
if (protocolVersion >= MC_1_19_3_Version)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue