mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Trim
This commit is contained in:
parent
11fe93a128
commit
6cb0c35ab8
3 changed files with 40 additions and 40 deletions
|
|
@ -116,12 +116,10 @@ namespace MinecraftClient.Mapping
|
||||||
/// <param name="nbt">The dimension type (NBT Tag Compound)</param>
|
/// <param name="nbt">The dimension type (NBT Tag Compound)</param>
|
||||||
public static void SetDimension(string name)
|
public static void SetDimension(string name)
|
||||||
{
|
{
|
||||||
if (dimensionList!.TryGetValue(name, out Dimension? dimension))
|
curDimension = dimensionList![name]; // Should not fail
|
||||||
curDimension = dimension;
|
|
||||||
else
|
|
||||||
Console.WriteLine("Can't find dimension \"" + name + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get current dimension
|
/// Get current dimension
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -1122,18 +1122,16 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
public byte[] GetLastSeenMessageList(Message.LastSeenMessageList msgList, bool isOnlineMode)
|
public byte[] GetLastSeenMessageList(Message.LastSeenMessageList msgList, bool isOnlineMode)
|
||||||
{
|
{
|
||||||
if (!isOnlineMode)
|
if (!isOnlineMode)
|
||||||
{
|
return GetVarInt(0); // Message list size
|
||||||
return GetVarInt(0);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
List<byte> fields = new List<byte>();
|
List<byte> fields = new();
|
||||||
fields.AddRange(GetVarInt(msgList.entries.Length));
|
fields.AddRange(GetVarInt(msgList.entries.Length)); // Message list size
|
||||||
foreach (Message.LastSeenMessageList.Entry entry in msgList.entries)
|
foreach (Message.LastSeenMessageList.Entry entry in msgList.entries)
|
||||||
{
|
{
|
||||||
fields.AddRange(entry.profileId.ToBigEndianBytes());
|
fields.AddRange(entry.profileId.ToBigEndianBytes()); // UUID
|
||||||
fields.AddRange(GetVarInt(entry.lastSignature.Length));
|
fields.AddRange(GetVarInt(entry.lastSignature.Length)); // Signature length
|
||||||
fields.AddRange(entry.lastSignature);
|
fields.AddRange(entry.lastSignature); // Signature data
|
||||||
}
|
}
|
||||||
return fields.ToArray();
|
return fields.ToArray();
|
||||||
}
|
}
|
||||||
|
|
@ -1147,16 +1145,16 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
/// <returns>Acknowledgment Packet Data</returns>
|
/// <returns>Acknowledgment Packet Data</returns>
|
||||||
public byte[] GetAcknowledgment(Message.LastSeenMessageList.Acknowledgment ack, bool isOnlineMode)
|
public byte[] GetAcknowledgment(Message.LastSeenMessageList.Acknowledgment ack, bool isOnlineMode)
|
||||||
{
|
{
|
||||||
List<byte> fields = new List<byte>();
|
List<byte> fields = new();
|
||||||
fields.AddRange(GetLastSeenMessageList(ack.lastSeen, isOnlineMode));
|
fields.AddRange(GetLastSeenMessageList(ack.lastSeen, isOnlineMode));
|
||||||
if (!isOnlineMode || ack.lastReceived == null)
|
if (!isOnlineMode || ack.lastReceived == null)
|
||||||
fields.AddRange(GetBool(false));
|
fields.AddRange(GetBool(false)); // Has last received message
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fields.AddRange(GetBool(true));
|
fields.AddRange(GetBool(true));
|
||||||
fields.AddRange(ack.lastReceived.profileId.ToBigEndianBytes());
|
fields.AddRange(ack.lastReceived.profileId.ToBigEndianBytes()); // Has last received message
|
||||||
fields.AddRange(GetVarInt(ack.lastReceived.lastSignature.Length));
|
fields.AddRange(GetVarInt(ack.lastReceived.lastSignature.Length)); // Last received message signature length
|
||||||
fields.AddRange(ack.lastReceived.lastSignature);
|
fields.AddRange(ack.lastReceived.lastSignature); // Last received message signature data
|
||||||
}
|
}
|
||||||
return fields.ToArray();
|
return fields.ToArray();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ using MinecraftClient.Protocol.Message;
|
||||||
namespace MinecraftClient.Protocol.Handlers
|
namespace MinecraftClient.Protocol.Handlers
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implementation for Minecraft 1.7.X+ Protocols
|
/// Implementation for Minecraft 1.8.X+ Protocols
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Typical update steps for implementing protocol changes for a new Minecraft version:
|
/// Typical update steps for implementing protocol changes for a new Minecraft version:
|
||||||
|
|
@ -1417,14 +1417,17 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
int EntityID = dataTypes.ReadNextVarInt(packetData);
|
int EntityID = dataTypes.ReadNextVarInt(packetData);
|
||||||
Dictionary<int, object> metadata = dataTypes.ReadNextMetadata(packetData, itemPalette);
|
Dictionary<int, object> metadata = dataTypes.ReadNextMetadata(packetData, itemPalette);
|
||||||
|
|
||||||
// See https://wiki.vg/Entity_metadata#Living_Entity
|
int healthField; // See https://wiki.vg/Entity_metadata#Living_Entity
|
||||||
int healthField = 7; // From 1.10 to 1.13.2
|
|
||||||
if (protocolVersion >= MC_1_14_Version)
|
|
||||||
healthField = 8; // 1.14 and above
|
|
||||||
if (protocolVersion >= MC_1_17_Version)
|
|
||||||
healthField = 9; // 1.17 and above
|
|
||||||
if (protocolVersion > MC_1_19_2_Version)
|
if (protocolVersion > MC_1_19_2_Version)
|
||||||
throw new NotImplementedException(Translations.Get("exception.palette.healthfield"));
|
throw new NotImplementedException(Translations.Get("exception.palette.healthfield"));
|
||||||
|
else if (protocolVersion >= MC_1_17_Version) // 1.17 and above
|
||||||
|
healthField = 9;
|
||||||
|
else if (protocolVersion >= MC_1_14_Version) // 1.14 and above
|
||||||
|
healthField = 8;
|
||||||
|
else if (protocolVersion >= MC_1_10_Version) // 1.10 and above
|
||||||
|
healthField = 7;
|
||||||
|
else
|
||||||
|
throw new NotImplementedException(Translations.Get("exception.palette.healthfield"));
|
||||||
|
|
||||||
if (metadata.ContainsKey(healthField) && metadata[healthField] != null && metadata[healthField].GetType() == typeof(float))
|
if (metadata.ContainsKey(healthField) && metadata[healthField] != null && metadata[healthField].GetType() == typeof(float))
|
||||||
handler.OnEntityHealth(EntityID, (float)metadata[healthField]);
|
handler.OnEntityHealth(EntityID, (float)metadata[healthField]);
|
||||||
|
|
@ -1675,19 +1678,19 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
}
|
}
|
||||||
if (protocolVersion >= MC_1_19_2_Version)
|
if (protocolVersion >= MC_1_19_2_Version)
|
||||||
{
|
{
|
||||||
string uuid = handler.GetUserUuidStr();
|
Guid uuid = handler.GetUserUuid();
|
||||||
if (uuid == "0")
|
if (uuid == Guid.Empty)
|
||||||
fullLoginPacket.AddRange(dataTypes.GetBool(false)); // Has UUID
|
fullLoginPacket.AddRange(dataTypes.GetBool(false)); // Has UUID
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fullLoginPacket.AddRange(dataTypes.GetBool(true)); // Has UUID
|
fullLoginPacket.AddRange(dataTypes.GetBool(true)); // Has UUID
|
||||||
fullLoginPacket.AddRange(dataTypes.GetUUID(Guid.Parse(uuid))); // UUID
|
fullLoginPacket.AddRange(dataTypes.GetUUID(uuid)); // UUID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SendPacket(0x00, fullLoginPacket);
|
SendPacket(0x00, fullLoginPacket);
|
||||||
|
|
||||||
int packetID = -1;
|
int packetID = -1;
|
||||||
Queue<byte> packetData = new Queue<byte>();
|
Queue<byte> packetData = new();
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
ReadNextPacket(ref packetID, packetData);
|
ReadNextPacket(ref packetID, packetData);
|
||||||
|
|
@ -2034,12 +2037,12 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="command">Command</param>
|
/// <param name="command">Command</param>
|
||||||
/// <returns> List< Argument Name, Argument Value > </returns>
|
/// <returns> List< Argument Name, Argument Value > </returns>
|
||||||
private List<Tuple<string, string>> CollectCommandArguments(string command)
|
private List<Tuple<string, string>>? CollectCommandArguments(string command)
|
||||||
{
|
{
|
||||||
List<Tuple<string, string>> needSigned = new();
|
|
||||||
|
|
||||||
if (!isOnlineMode || !Settings.SignMessageInCommand)
|
if (!isOnlineMode || !Settings.SignMessageInCommand)
|
||||||
return needSigned;
|
return null;
|
||||||
|
|
||||||
|
List<Tuple<string, string>> needSigned = new();
|
||||||
|
|
||||||
string[] argStage1 = command.Split(' ', 2, StringSplitOptions.None);
|
string[] argStage1 = command.Split(' ', 2, StringSplitOptions.None);
|
||||||
if (argStage1.Length == 2)
|
if (argStage1.Length == 2)
|
||||||
|
|
@ -2076,7 +2079,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Send a chat command to the server
|
/// Send a chat command to the server - 1.19 and above
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="command">Command</param>
|
/// <param name="command">Command</param>
|
||||||
/// <param name="playerKeyPair">PlayerKeyPair</param>
|
/// <param name="playerKeyPair">PlayerKeyPair</param>
|
||||||
|
|
@ -2105,8 +2108,9 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
DateTimeOffset timeNow = DateTimeOffset.UtcNow;
|
DateTimeOffset timeNow = DateTimeOffset.UtcNow;
|
||||||
fields.AddRange(dataTypes.GetLong(timeNow.ToUnixTimeMilliseconds()));
|
fields.AddRange(dataTypes.GetLong(timeNow.ToUnixTimeMilliseconds()));
|
||||||
|
|
||||||
List<Tuple<string, string>> needSigned = CollectCommandArguments(command); // List< Argument Name, Argument Value >
|
List<Tuple<string, string>>? needSigned =
|
||||||
if (!isOnlineMode || needSigned.Count == 0 || playerKeyPair == null || !Settings.SignMessageInCommand)
|
playerKeyPair != null ? CollectCommandArguments(command) : null; // List< Argument Name, Argument Value >
|
||||||
|
if (needSigned == null || needSigned!.Count == 0)
|
||||||
{
|
{
|
||||||
fields.AddRange(dataTypes.GetLong(0)); // Salt: Long
|
fields.AddRange(dataTypes.GetLong(0)); // Salt: Long
|
||||||
fields.AddRange(dataTypes.GetVarInt(0)); // Signature Length: VarInt
|
fields.AddRange(dataTypes.GetVarInt(0)); // Signature Length: VarInt
|
||||||
|
|
@ -2121,8 +2125,8 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
{
|
{
|
||||||
fields.AddRange(dataTypes.GetString(argument.Item1)); // Argument name: String
|
fields.AddRange(dataTypes.GetString(argument.Item1)); // Argument name: String
|
||||||
byte[] sign = (protocolVersion >= MC_1_19_2_Version) ?
|
byte[] sign = (protocolVersion >= MC_1_19_2_Version) ?
|
||||||
playerKeyPair.PrivateKey.SignMessage(argument.Item2, uuid, timeNow, ref salt, acknowledgment!.lastSeen) :
|
playerKeyPair!.PrivateKey.SignMessage(argument.Item2, uuid, timeNow, ref salt, acknowledgment!.lastSeen) :
|
||||||
playerKeyPair.PrivateKey.SignMessage(argument.Item2, uuid, timeNow, ref salt);
|
playerKeyPair!.PrivateKey.SignMessage(argument.Item2, uuid, timeNow, ref salt);
|
||||||
fields.AddRange(dataTypes.GetVarInt(sign.Length)); // Signature length: VarInt
|
fields.AddRange(dataTypes.GetVarInt(sign.Length)); // Signature length: VarInt
|
||||||
fields.AddRange(sign); // Signature: Byte Array
|
fields.AddRange(sign); // Signature: Byte Array
|
||||||
}
|
}
|
||||||
|
|
@ -2162,9 +2166,6 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
LastSeenMessageList.Acknowledgment? acknowledgment =
|
|
||||||
(protocolVersion >= MC_1_19_2_Version) ? this.consumeAcknowledgment() : null;
|
|
||||||
|
|
||||||
List<byte> fields = new();
|
List<byte> fields = new();
|
||||||
|
|
||||||
// Message: String (up to 256 chars)
|
// Message: String (up to 256 chars)
|
||||||
|
|
@ -2172,6 +2173,9 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
|
|
||||||
if (protocolVersion >= MC_1_19_Version)
|
if (protocolVersion >= MC_1_19_Version)
|
||||||
{
|
{
|
||||||
|
LastSeenMessageList.Acknowledgment? acknowledgment =
|
||||||
|
(protocolVersion >= MC_1_19_2_Version) ? this.consumeAcknowledgment() : null;
|
||||||
|
|
||||||
// Timestamp: Instant(Long)
|
// Timestamp: Instant(Long)
|
||||||
DateTimeOffset timeNow = DateTimeOffset.UtcNow;
|
DateTimeOffset timeNow = DateTimeOffset.UtcNow;
|
||||||
fields.AddRange(dataTypes.GetLong(timeNow.ToUnixTimeMilliseconds()));
|
fields.AddRange(dataTypes.GetLong(timeNow.ToUnixTimeMilliseconds()));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue