Basic support for minecraft 1.19 (#2084)

* merge commit from milutinke
* chat signature & encrypted login
* Bug fix :EncryptionResponse format error below 1.18.2
* Implemented chat command signature
* Chat message parsing and verification for 1.19
* Add signature settings
* Update Simplified Chinese Translation
* Clear up comments
* Fix wrong variable naming
* Bug fix: SignatureV2 Processing
This commit is contained in:
BruceChen 2022-08-15 23:55:44 +08:00 committed by GitHub
parent d9f1a77ac2
commit a8bbb1ac76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
55 changed files with 5218 additions and 1174 deletions

View file

@ -9,6 +9,7 @@ using MinecraftClient.Proxy;
using System.Security.Cryptography;
using MinecraftClient.Mapping;
using MinecraftClient.Inventory;
using MinecraftClient.Protocol.Keys;
namespace MinecraftClient.Protocol.Handlers
{
@ -62,12 +63,12 @@ namespace MinecraftClient.Protocol.Handlers
private void Updater(object? o)
{
if (((CancellationToken) o!).IsCancellationRequested)
if (((CancellationToken)o!).IsCancellationRequested)
return;
try
{
while (!((CancellationToken) o!).IsCancellationRequested)
while (!((CancellationToken)o!).IsCancellationRequested)
{
do
{
@ -79,9 +80,9 @@ namespace MinecraftClient.Protocol.Handlers
catch (SocketException) { }
catch (ObjectDisposedException) { }
if (((CancellationToken) o!).IsCancellationRequested)
if (((CancellationToken)o!).IsCancellationRequested)
return;
handler.OnConnectionLost(ChatBot.DisconnectReason.ConnectionLost, "");
}
@ -102,7 +103,8 @@ namespace MinecraftClient.Protocol.Handlers
int nbr = 0;
switch (id)
{
case 0x00: byte[] keepalive = new byte[5] { 0, 0, 0, 0, 0 };
case 0x00:
byte[] keepalive = new byte[5] { 0, 0, 0, 0, 0 };
Receive(keepalive, 1, 4, SocketFlags.None);
handler.OnServerKeepAlive();
Send(keepalive); break;
@ -110,7 +112,7 @@ namespace MinecraftClient.Protocol.Handlers
case 0x02: readData(1); readNextString(); readNextString(); readData(4); break;
case 0x03:
string message = readNextString();
handler.OnTextReceived(message, protocolversion >= 72); break;
handler.OnTextReceived(new ChatMessage(message, protocolversion >= 72, 0, Guid.Empty)); break;
case 0x04: readData(16); break;
case 0x05: readData(6); readNextItemSlot(); break;
case 0x06: readData(12); break;
@ -181,7 +183,7 @@ namespace MinecraftClient.Protocol.Handlers
case 0xC9:
string name = readNextString(); bool online = readNextByte() != 0x00; readData(2);
Guid FakeUUID = new Guid(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(name)).Take(16).ToArray());
if (online) { handler.OnPlayerJoin(FakeUUID, name); } else { handler.OnPlayerLeave(FakeUUID); }
if (online) { handler.OnPlayerJoin(new PlayerInfo(name, FakeUUID)); } else { handler.OnPlayerLeave(FakeUUID); }
break;
case 0xCA: if (protocolversion >= 72) { readData(9); } else readData(3); break;
case 0xCB: autocomplete_result = readNextString(); autocomplete_received = true; break;
@ -191,18 +193,20 @@ namespace MinecraftClient.Protocol.Handlers
case 0xCF: if (protocolversion > 51) { readNextString(); readData(1); readNextString(); } readData(4); break;
case 0xD0: if (protocolversion > 51) { readData(1); readNextString(); } break;
case 0xD1: if (protocolversion > 51) { readNextTeamData(); } break;
case 0xFA: string channel = readNextString();
case 0xFA:
string channel = readNextString();
byte[] payload = readNextByteArray();
handler.OnPluginChannelMessage(channel, payload);
break;
case 0xFF: string reason = readNextString();
case 0xFF:
string reason = readNextString();
handler.OnConnectionLost(ChatBot.DisconnectReason.InGameKick, reason); break;
default: return false; //unknown packet!
}
return true; //packet has been successfully skipped
}
private void StartUpdating()
private void StartUpdating()
{
netRead = new(new Thread(new ParameterizedThreadStart(Updater)), new CancellationTokenSource());
netRead.Item1.Name = "ProtocolPacketHandler";
@ -553,7 +557,7 @@ namespace MinecraftClient.Protocol.Handlers
}
}
public bool Login()
public bool Login(PlayerKeyPair playerKeyPair)
{
if (Handshake(handler.GetUserUUID(), handler.GetUsername(), handler.GetSessionID(), handler.GetServerHost(), handler.GetServerPort()))
{
@ -639,7 +643,7 @@ namespace MinecraftClient.Protocol.Handlers
return protocolversion;
}
public bool SendChatMessage(string message)
public bool SendChatMessage(string message, PlayerKeyPair? playerKeyPair)
{
if (String.IsNullOrEmpty(message))
return true;
@ -674,12 +678,12 @@ namespace MinecraftClient.Protocol.Handlers
}
catch (SocketException) { return false; }
}
public bool SendUpdateSign(Location location, string line1, string line2, string line3, string line4)
{
return false; //Currently not implemented
}
public bool SendBrandInfo(string brandInfo)
{
return false; //Only supported since MC 1.7
@ -709,18 +713,18 @@ namespace MinecraftClient.Protocol.Handlers
{
return false; //Currently not implemented
}
public bool SendInteractEntity(int EntityID, int type, int hand)
{
return false; //Currently not implemented
}
public bool UpdateCommandBlock(Location location, string command, CommandBlockMode mode, CommandBlockFlags flags)
{
return false; //Currently not implemented
}
public bool SendUseItem(int hand)
public bool SendUseItem(int hand, int sequenceId)
{
return false; //Currently not implemented
}
@ -735,7 +739,7 @@ namespace MinecraftClient.Protocol.Handlers
return false; //Currently not implemented
}
public bool SendCreativeInventoryAction(int slot, ItemType item, int count, Dictionary<string, object> nbt)
public bool SendCreativeInventoryAction(int slot, ItemType item, int count, Dictionary<string, object>? nbt)
{
return false; //Currently not implemented
}
@ -745,7 +749,7 @@ namespace MinecraftClient.Protocol.Handlers
return false; //Currently not implemented
}
public bool SendPlayerBlockPlacement(int hand, Location location, Direction face)
public bool SendPlayerBlockPlacement(int hand, Location location, Direction face, int sequenceId)
{
return false; //Currently not implemented
}
@ -755,7 +759,7 @@ namespace MinecraftClient.Protocol.Handlers
return false; //Currently not implemented
}
public bool SendPlayerDigging(int status, Location location, Direction face)
public bool SendPlayerDigging(int status, Location location, Direction face, int sequenceId)
{
return false; //Currently not implemented
}
@ -767,7 +771,8 @@ namespace MinecraftClient.Protocol.Handlers
/// <param name="data">packet Data</param>
public bool SendPluginChannelPacket(string channel, byte[] data)
{
try {
try
{
byte[] channelLength = BitConverter.GetBytes((short)channel.Length);
Array.Reverse(channelLength);