login support

This commit is contained in:
BruceChen 2022-08-24 12:37:22 +08:00
parent e150bd569b
commit af1485c753
11 changed files with 247 additions and 16 deletions

View file

@ -70,7 +70,7 @@ namespace MinecraftClient
private string username;
private string uuid;
private string sessionid;
private PlayerKeyPair playerKeyPair;
private PlayerKeyPair? playerKeyPair;
private DateTime lastKeepAlive;
private object lastKeepAliveLock = new();
private int respawnTicks = 0;
@ -141,7 +141,7 @@ namespace MinecraftClient
/// <param name="server_ip">The server IP</param>
/// <param name="port">The server port to use</param>
/// <param name="protocolversion">Minecraft protocol version to use</param>
public McClient(string username, string uuid, string sessionID, PlayerKeyPair playerKeyPair, int protocolversion, ForgeInfo forgeInfo, string server_ip, ushort port)
public McClient(string username, string uuid, string sessionID, PlayerKeyPair? playerKeyPair, int protocolversion, ForgeInfo forgeInfo, string server_ip, ushort port)
{
StartClient(username, uuid, sessionID, playerKeyPair, server_ip, port, protocolversion, forgeInfo, false, "");
}
@ -156,7 +156,7 @@ namespace MinecraftClient
/// <param name="port">The server port to use</param>
/// <param name="protocolversion">Minecraft protocol version to use</param>
/// <param name="command">The text or command to send.</param>
public McClient(string username, string uuid, string sessionID, PlayerKeyPair playerKeyPair, string server_ip, ushort port, int protocolversion, ForgeInfo forgeInfo, string command)
public McClient(string username, string uuid, string sessionID, PlayerKeyPair? playerKeyPair, string server_ip, ushort port, int protocolversion, ForgeInfo forgeInfo, string command)
{
StartClient(username, uuid, sessionID, playerKeyPair, server_ip, port, protocolversion, forgeInfo, true, command);
}
@ -172,7 +172,7 @@ namespace MinecraftClient
/// <param name="uuid">The player's UUID for online-mode authentication</param>
/// <param name="singlecommand">If set to true, the client will send a single command and then disconnect from the server</param>
/// <param name="command">The text or command to send. Will only be sent if singlecommand is set to true.</param>
private void StartClient(string user, string uuid, string sessionID, PlayerKeyPair playerKeyPair, string server_ip, ushort port, int protocolversion, ForgeInfo forgeInfo, bool singlecommand, string command)
private void StartClient(string user, string uuid, string sessionID, PlayerKeyPair? playerKeyPair, string server_ip, ushort port, int protocolversion, ForgeInfo forgeInfo, bool singlecommand, string command)
{
terrainAndMovementsEnabled = Settings.TerrainAndMovements;
inventoryHandlingEnabled = Settings.InventoryHandling;

View file

@ -40,7 +40,7 @@ namespace MinecraftClient
public const string Version = MCHighestVersion;
public const string MCLowestVersion = "1.4.6";
public const string MCHighestVersion = "1.19";
public const string MCHighestVersion = "1.19.2";
public static readonly string BuildInfo = null;
private static Tuple<Thread, CancellationTokenSource>? offlinePrompt = null;

View file

@ -0,0 +1,184 @@
using System.Collections.Generic;
namespace MinecraftClient.Protocol.Handlers.PacketPalettes
{
public class PacketPalette1192 : PacketTypePalette
{
private Dictionary<int, PacketTypesIn> typeIn = new Dictionary<int, PacketTypesIn>()
{
{ 0x00, PacketTypesIn.SpawnEntity }, // Changed in 1.19 (Wiki name: Spawn Entity) - DONE
{ 0x01, PacketTypesIn.SpawnExperienceOrb }, //(Wiki name: Spawn Exeprience Orb)
{ 0x02, PacketTypesIn.SpawnPlayer },
{ 0x03, PacketTypesIn.EntityAnimation }, //(Wiki name: Entity Animation (clientbound))
{ 0x04, PacketTypesIn.Statistics }, //(Wiki name: Award Statistics)
{ 0x05, PacketTypesIn.BlockChangedAck }, //Added 1.19 (Wiki name: Acknowledge Block Change) - DONE
{ 0x06, PacketTypesIn.BlockBreakAnimation }, //(Wiki name: Set Block Destroy Stage)
{ 0x07, PacketTypesIn.BlockEntityData },
{ 0x08, PacketTypesIn.BlockAction },
{ 0x09, PacketTypesIn.BlockChange }, //(Wiki name: Block Update)
{ 0x0A, PacketTypesIn.BossBar },
{ 0x0B, PacketTypesIn.ServerDifficulty }, // (Wiki name: Change Difficulty)
{ 0x0C, PacketTypesIn.ChatPreview }, // Added 1.19
{ 0x0D, PacketTypesIn.ClearTiles },
{ 0x0E, PacketTypesIn.TabComplete }, // (Wiki name: Command Suggestions Response)
{ 0x0F, PacketTypesIn.DeclareCommands }, // (Wiki name: Commands)
{ 0x10, PacketTypesIn.CloseWindow }, // (Wiki name: Close Container (clientbound))
{ 0x11, PacketTypesIn.WindowItems }, // (Wiki name: Set Container Content)
{ 0x12, PacketTypesIn.WindowProperty }, // (Wiki name: Set Container Property)
{ 0x13, PacketTypesIn.SetSlot }, // (Wiki name: Set Container Slot)
{ 0x14, PacketTypesIn.SetCooldown },
{ 0x15, PacketTypesIn.ChatSuggestions }, // Added 1.19.1
{ 0x16, PacketTypesIn.PluginMessage }, // (Wiki name: Plugin Message (clientbound))
{ 0x17, PacketTypesIn.NamedSoundEffect }, // Changed in 1.19 (Added "Speed" field) (Wiki name: Custom Sound Effect) - DONE (No need to be implemented)
{ 0x18, PacketTypesIn.HideMessage }, // Added 1.19.1
{ 0x19, PacketTypesIn.Disconnect },
{ 0x1A, PacketTypesIn.EntityStatus }, // (Wiki name: Entity Event)
{ 0x1B, PacketTypesIn.Explosion }, // Changed in 1.19 (Location fields are now Double instead of Float) (Wiki name: Explosion) - DONE
{ 0x1C, PacketTypesIn.UnloadChunk }, // (Wiki name: Forget Chunk)
{ 0x1D, PacketTypesIn.ChangeGameState }, // (Wiki name: Game Event)
{ 0x1E, PacketTypesIn.OpenHorseWindow }, // (Wiki name: Horse Screen Open)
{ 0x1F, PacketTypesIn.InitializeWorldBorder },
{ 0x20, PacketTypesIn.KeepAlive },
{ 0x21, PacketTypesIn.ChunkData },
{ 0x22, PacketTypesIn.Effect }, // (Wiki name: Level Event)
{ 0x23, PacketTypesIn.Particle }, // Changed in 1.19 ("Particle Data" field is now "Max Speed", it's the same Float data type) (Wiki name: Level Particle) - DONE (No need to be implemented)
{ 0x24, PacketTypesIn.UpdateLight }, // (Wiki name: Light Update)
{ 0x25, PacketTypesIn.JoinGame }, // Changed in 1.19 (lot's of changes) (Wiki name: Login (play)) - DONE
{ 0x26, PacketTypesIn.MapData }, // (Wiki name: Map Item Data)
{ 0x27, PacketTypesIn.TradeList }, // (Wiki name: Merchant Offers)
{ 0x28, PacketTypesIn.EntityPosition }, // (Wiki name: Move Entity Position)
{ 0x29, PacketTypesIn.EntityPositionAndRotation }, // (Wiki name: Move Entity Position and Rotation)
{ 0x2A, PacketTypesIn.EntityRotation }, // (Wiki name: Move Entity Rotation)
{ 0x2B, PacketTypesIn.VehicleMove }, // (Wiki name: Move Vehicle)
{ 0x2C, PacketTypesIn.OpenBook },
{ 0x2D, PacketTypesIn.OpenWindow }, // (Wiki name: Open Screen)
{ 0x2E, PacketTypesIn.OpenSignEditor },
{ 0x2F, PacketTypesIn.Ping }, // (Wiki name: Ping (play))
{ 0x30, PacketTypesIn.CraftRecipeResponse }, // (Wiki name: Place Ghost Recipe)
{ 0x31, PacketTypesIn.PlayerAbilities },
{ 0x32, PacketTypesIn.MessageHeader }, // Added 1.19.1
{ 0x33, PacketTypesIn.ChatMessage }, // Changed in 1.19 (Completely changed) (Wiki name: Player Chat Message)
{ 0x34, PacketTypesIn.EndCombatEvent }, // (Wiki name: Player Combat End)
{ 0x35, PacketTypesIn.EnterCombatEvent }, // (Wiki name: Player Combat Enter)
{ 0x36, PacketTypesIn.DeathCombatEvent }, // (Wiki name: Player Combat Kill)
{ 0x37, PacketTypesIn.PlayerInfo }, // Changed in 1.19 (Heavy changes) - DONE
{ 0x38, PacketTypesIn.FacePlayer }, // (Wiki name: Player Look At)
{ 0x39, PacketTypesIn.PlayerPositionAndLook }, // (Wiki name: Player Position)
{ 0x3A, PacketTypesIn.UnlockRecipes }, // (Wiki name: Recipe)
{ 0x3B, PacketTypesIn.DestroyEntities }, // (Wiki name: Remove Entites)
{ 0x3C, PacketTypesIn.RemoveEntityEffect },
{ 0x3D, PacketTypesIn.ResourcePackSend }, // (Wiki name: Resource Pack)
{ 0x3E, PacketTypesIn.Respawn }, // Changed in 1.19 (Heavy changes) - DONE
{ 0x3F, PacketTypesIn.EntityHeadLook }, // (Wiki name: Rotate Head)
{ 0x40, PacketTypesIn.MultiBlockChange }, // (Wiki name: Sections Block Update)
{ 0x41, PacketTypesIn.SelectAdvancementTab },
{ 0x42, PacketTypesIn.ServerData }, // Added in 1.19
{ 0x43, PacketTypesIn.ActionBar }, // (Wiki name: Set Action Bar Text)
{ 0x44, PacketTypesIn.WorldBorderCenter }, // (Wiki name: Set Border Center)
{ 0x45, PacketTypesIn.WorldBorderLerpSize },
{ 0x46, PacketTypesIn.WorldBorderSize }, // (Wiki name: Set World Border Size)
{ 0x47, PacketTypesIn.WorldBorderWarningDelay }, // (Wiki name: Set World Border Warning Delay)
{ 0x48, PacketTypesIn.WorldBorderWarningReach }, // (Wiki name: Set Border Warning Distance)
{ 0x49, PacketTypesIn.Camera }, // (Wiki name: Set Camera)
{ 0x4A, PacketTypesIn.HeldItemChange }, // (Wiki name: Set Carried Item (clientbound))
{ 0x4B, PacketTypesIn.UpdateViewPosition }, // (Wiki name: Set Chunk Cache Center)
{ 0x4C, PacketTypesIn.UpdateViewDistance }, // (Wiki name: Set Chunk Cache Radius)
{ 0x4D, PacketTypesIn.SpawnPosition }, // (Wiki name: Set Default Spawn Position)
{ 0x4E, PacketTypesIn.SetDisplayChatPreview }, // Added in 1.19 (Wiki name: Set Display Chat Preview)
{ 0x4F, PacketTypesIn.DisplayScoreboard }, // (Wiki name: Set Display Objective)
{ 0x50, PacketTypesIn.EntityMetadata }, // (Wiki name: Set Entity Metadata)
{ 0x51, PacketTypesIn.AttachEntity }, // (Wiki name: Set Entity Link)
{ 0x52, PacketTypesIn.EntityVelocity }, // (Wiki name: Set Entity Motion)
{ 0x53, PacketTypesIn.EntityEquipment }, // (Wiki name: Set Equipment)
{ 0x54, PacketTypesIn.SetExperience },
{ 0x55, PacketTypesIn.UpdateHealth }, // (Wiki name: Set Health)
{ 0x56, PacketTypesIn.ScoreboardObjective }, // (Wiki name: Set Objective)
{ 0x57, PacketTypesIn.SetPassengers },
{ 0x58, PacketTypesIn.Teams }, // (Wiki name: Set Player Team)
{ 0x59, PacketTypesIn.UpdateScore }, // (Wiki name: Set Score)
{ 0x5A, PacketTypesIn.UpdateSimulationDistance }, // (Wiki name: Set Simulation Distance)
{ 0x5B, PacketTypesIn.SetTitleSubTitle }, // (Wiki name: Set Subtitle Test)
{ 0x5C, PacketTypesIn.TimeUpdate }, // (Wiki name: Set Time)
{ 0x5D, PacketTypesIn.SetTitleText }, // (Wiki name: Set Title)
{ 0x5E, PacketTypesIn.SetTitleTime }, // (Wiki name: Set Titles Animation)
{ 0x5F, PacketTypesIn.EntitySoundEffect }, // (Wiki name: Sound Entity)
{ 0x60, PacketTypesIn.SoundEffect }, // Changed in 1.19 (Added "Seed" field) (Wiki name: Sound Effect) - DONE (No need to be implemented)
{ 0x61, PacketTypesIn.StopSound },
{ 0x62, PacketTypesIn.SystemChat }, // Added in 1.19 (Wiki name: System Chat Message)
{ 0x63, PacketTypesIn.PlayerListHeaderAndFooter }, // (Wiki name: Tab List)
{ 0x64, PacketTypesIn.NBTQueryResponse }, // (Wiki name: Tab Query)
{ 0x65, PacketTypesIn.CollectItem }, // (Wiki name: Take Item Entity)
{ 0x66, PacketTypesIn.EntityTeleport }, // (Wiki name: Teleport Entity)
{ 0x67, PacketTypesIn.Advancements }, // (Wiki name: Update Advancements)
{ 0x68, PacketTypesIn.EntityProperties }, // (Wiki name: Update Attributes)
{ 0x69, PacketTypesIn.EntityEffect }, // Changed in 1.19 (Added "Has Factor Data" and "Factor Codec" fields) (Wiki name: Entity Effect) - DONE
{ 0x6A, PacketTypesIn.DeclareRecipes }, // (Wiki name: Update Recipes)
{ 0x6B, PacketTypesIn.Tags }, // (Wiki name: Update Tags)
};
private Dictionary<int, PacketTypesOut> typeOut = new Dictionary<int, PacketTypesOut>()
{
{ 0x00, PacketTypesOut.TeleportConfirm }, // (Wiki name: Confirm Teleportation)
{ 0x01, PacketTypesOut.QueryBlockNBT }, // (Wiki name: Query Block Entity Tag)
{ 0x02, PacketTypesOut.SetDifficulty }, // (Wiki name: Change Difficutly)
{ 0x03, PacketTypesOut.MessageAcknowledgment }, // Added in 1.19.1
{ 0x04, PacketTypesOut.ChatCommand }, // Added in 1.19
{ 0x05, PacketTypesOut.ChatMessage }, // Changed in 1.19 (Completely changed) (Wiki name: Chat)
{ 0x06, PacketTypesOut.ChatPreview }, // Added in 1.19 (Wiki name: Chat Preview (serverbound))
{ 0x07, PacketTypesOut.ClientStatus }, // (Wiki name: Client Command)
{ 0x08, PacketTypesOut.ClientSettings }, // (Wiki name: Client Information)
{ 0x09, PacketTypesOut.TabComplete }, // (Wiki name: Command Suggestions Request)
{ 0x0A, PacketTypesOut.ClickWindowButton }, // (Wiki name: Click Container Button)
{ 0x0B, PacketTypesOut.ClickWindow }, // (Wiki name: Click Container)
{ 0x0C, PacketTypesOut.CloseWindow }, // (Wiki name: Close Container (serverbound))
{ 0x0D, PacketTypesOut.PluginMessage }, // (Wiki name: Plugin Message (serverbound))
{ 0x0E, PacketTypesOut.EditBook },
{ 0x0F, PacketTypesOut.EntityNBTRequest }, // (Wiki name: Query Entity Tag)
{ 0x10, PacketTypesOut.InteractEntity }, // (Wiki name: Interact)
{ 0x11, PacketTypesOut.GenerateStructure }, // (Wiki name: Jigsaw Generate)
{ 0x12, PacketTypesOut.KeepAlive },
{ 0x13, PacketTypesOut.LockDifficulty },
{ 0x14, PacketTypesOut.PlayerPosition }, // (Wiki name: Move Player Position)
{ 0x15, PacketTypesOut.PlayerPositionAndRotation }, // (Wiki name: Set Player Position and Rotation)
{ 0x16, PacketTypesOut.PlayerRotation }, // (Wiki name: Set Player Rotation)
{ 0x17, PacketTypesOut.PlayerMovement }, // (Wiki name: Set Player On Ground)
{ 0x18, PacketTypesOut.VehicleMove }, // (Wiki name: Move Vehicle (serverbound))
{ 0x19, PacketTypesOut.SteerBoat }, // (Wiki name: Paddle Boat)
{ 0x1A, PacketTypesOut.PickItem },
{ 0x1B, PacketTypesOut.CraftRecipeRequest }, // (Wiki name: Place recipe)
{ 0x1C, PacketTypesOut.PlayerAbilities },
{ 0x1D, PacketTypesOut.PlayerDigging }, // Changed in 1.19 (Added a "Sequence" field) (Wiki name: Player Action) - DONE
{ 0x1E, PacketTypesOut.EntityAction }, // (Wiki name: Player Command)
{ 0x1F, PacketTypesOut.SteerVehicle }, // (Wiki name: Player Input)
{ 0x20, PacketTypesOut.Pong }, // (Wiki name: Pong (play))
{ 0x21, PacketTypesOut.SetDisplayedRecipe }, // (Wiki name: Recipe Book Change Settings)
{ 0x22, PacketTypesOut.SetRecipeBookState }, // (Wiki name: Recipe Book Seen Recipe)
{ 0x23, PacketTypesOut.NameItem }, // (Wiki name: Rename Item)
{ 0x24, PacketTypesOut.ResourcePackStatus }, // (Wiki name: Resource Pack (serverbound))
{ 0x25, PacketTypesOut.AdvancementTab }, // (Wiki name: Seen Advancements)
{ 0x26, PacketTypesOut.SelectTrade },
{ 0x27, PacketTypesOut.SetBeaconEffect }, // Changed in 1.19 (Added a "Secondary Effect Present" and "Secondary Effect" fields) (Wiki name: Set Beacon) - DONE - (No need to be implemented)
{ 0x28, PacketTypesOut.HeldItemChange }, // (Wiki name: Set Carried Item (serverbound))
{ 0x29, PacketTypesOut.UpdateCommandBlock }, // (Wiki name: Set Command Block)
{ 0x2A, PacketTypesOut.UpdateCommandBlockMinecart },
{ 0x2B, PacketTypesOut.CreativeInventoryAction }, // (Wiki name: Set Creative Mode Slot)
{ 0x2C, PacketTypesOut.UpdateJigsawBlock }, // (Wiki name: Set Jigsaw Block)
{ 0x2D, PacketTypesOut.UpdateStructureBlock }, // (Wiki name: Set Structure Block)
{ 0x2E, PacketTypesOut.UpdateSign }, // (Wiki name: Sign Update)
{ 0x2F, PacketTypesOut.Animation }, // (Wiki name: Swing)
{ 0x30, PacketTypesOut.Spectate }, // (Wiki name: Teleport To Entity)
{ 0x31, PacketTypesOut.PlayerBlockPlacement }, // Changed in 1.19 (Added a "Sequence" field) (Wiki name: Use Item On) - DONE
{ 0x32, PacketTypesOut.UseItem }, // Changed in 1.19 (Added a "Sequence" field) (Wiki name: Use Item) - DONE
};
protected override Dictionary<int, PacketTypesIn> GetListIn()
{
return typeIn;
}
protected override Dictionary<int, PacketTypesOut> GetListOut()
{
return typeOut;
}
}
}

View file

@ -51,7 +51,7 @@ namespace MinecraftClient.Protocol.Handlers
public PacketTypePalette GetTypeHandler(int protocol)
{
PacketTypePalette p;
if (protocol > Protocol18Handler.MC_1_19_Version)
if (protocol > Protocol18Handler.MC_1_19_2_Version)
throw new NotImplementedException(Translations.Get("exception.palette.packet"));
if (protocol <= Protocol18Handler.MC_1_8_Version)
p = new PacketPalette17();
@ -75,8 +75,10 @@ namespace MinecraftClient.Protocol.Handlers
p = new PacketPalette117();
else if (protocol <= Protocol18Handler.MC_1_18_2_Version)
p = new PacketPalette118();
else
else if (protocol <= Protocol18Handler.MC_1_19_Version)
p = new PacketPalette119();
else
p = new PacketPalette1192();
p.SetForgeEnabled(this.forgeEnabled);
return p;

View file

@ -132,6 +132,11 @@ namespace MinecraftClient.Protocol.Handlers
ChatPreview,
ServerData,
SetDisplayChatPreview,
SystemChat
SystemChat,
// Added in 1.19.1 (1.19.2)
ChatSuggestions,
HideMessage,
MessageHeader
}
}

View file

@ -67,5 +67,8 @@ namespace MinecraftClient.Protocol.Handlers
// Added in 1.19
ChatCommand,
ChatPreview,
// Added in 1.19.1 (1.19.2)
MessageAcknowledgment
}
}

View file

@ -55,6 +55,7 @@ namespace MinecraftClient.Protocol.Handlers
internal const int MC_1_18_1_Version = 757;
internal const int MC_1_18_2_Version = 758;
internal const int MC_1_19_Version = 759;
internal const int MC_1_19_2_Version = 760;
private int compression_treshold = 0;
private bool autocomplete_received = false;
@ -414,7 +415,7 @@ namespace MinecraftClient.Protocol.Handlers
handler.OnTextReceived(new(message, true, messageType, senderUUID));
}
else // 1.19+
else if (protocolversion == MC_1_19_Version) // 1.19
{
string signedChat = dataTypes.ReadNextString(packetData);
@ -443,6 +444,10 @@ namespace MinecraftClient.Protocol.Handlers
handler.OnTextReceived(new(signedChat, true, messageType, senderUUID, unsignedChatContent, senderDisplayName, senderTeamName, timestamp, verifyResult));
}
else // 1.19.1 +
{
// Todo
}
break;
case PacketTypesIn.Respawn:
string? dimensionNameInRespawn = null;
@ -1533,7 +1538,21 @@ namespace MinecraftClient.Protocol.Handlers
fullLoginPacket.AddRange(dataTypes.GetBool(true)); // Has Sig Data
fullLoginPacket.AddRange(dataTypes.GetLong(playerKeyPair.GetExpirationMilliseconds())); // Expiration time
fullLoginPacket.AddRange(dataTypes.GetArray(playerKeyPair.PublicKey.Key)); // Public key received from Microsoft API
fullLoginPacket.AddRange(dataTypes.GetArray(playerKeyPair.PublicKey.Signature)); // Public key signature received from Microsoft API
if (protocolversion >= MC_1_19_2_Version)
fullLoginPacket.AddRange(dataTypes.GetArray(playerKeyPair.PublicKey.SignatureV2!)); // Public key signature received from Microsoft API
else
fullLoginPacket.AddRange(dataTypes.GetArray(playerKeyPair.PublicKey.Signature!)); // Public key signature received from Microsoft API
}
}
if (protocolversion >= MC_1_19_2_Version)
{
string uuid = handler.GetUserUUID();
if (uuid == "0")
fullLoginPacket.AddRange(dataTypes.GetBool(false)); // Has UUID
else
{
fullLoginPacket.AddRange(dataTypes.GetBool(true)); // Has UUID
fullLoginPacket.AddRange(dataTypes.GetUUID(Guid.Parse(uuid))); // UUID
}
}
SendPacket(0x00, fullLoginPacket);
@ -1952,6 +1971,13 @@ namespace MinecraftClient.Protocol.Handlers
if (String.IsNullOrEmpty(message))
return true;
if (protocolversion >= MC_1_19_2_Version)
{
// Todo
log.Warn("Not implement");
return false;
}
// Process Chat Command - 1.19 and above
if (protocolversion >= MC_1_19_Version && message.StartsWith('/'))
return SendChatCommand(message[1..], playerKeyPair);
@ -1989,6 +2015,9 @@ namespace MinecraftClient.Protocol.Handlers
// Signed Preview: Boolean
fields.AddRange(dataTypes.GetBool(false));
fields.AddRange(dataTypes.GetVarInt(0));
fields.AddRange(dataTypes.GetBool(false));
}
SendPacket(PacketTypesOut.ChatMessage, fields);
return true;

View file

@ -22,7 +22,7 @@ namespace MinecraftClient.Protocol
/// Start the login procedure once connected to the server
/// </summary>
/// <returns>True if login was successful</returns>
bool Login(PlayerKeyPair playerKeyPair);
bool Login(PlayerKeyPair? playerKeyPair);
/// <summary>
/// Disconnect from the server

View file

@ -65,6 +65,9 @@ namespace MinecraftClient.Protocol.Keys
{
List<string> datas = new List<string>();
datas.Add(Convert.ToBase64String(PublicKey.Key));
if (PublicKey.Signature == null)
datas.Add(String.Empty);
else
datas.Add(Convert.ToBase64String(PublicKey.Signature));
if (PublicKey.SignatureV2 == null)
datas.Add(String.Empty);

View file

@ -10,18 +10,19 @@ namespace MinecraftClient.Protocol.Keys
public class PublicKey
{
public byte[] Key { get; set; }
public byte[] Signature { get; set; }
public byte[]? Signature { get; set; }
public byte[]? SignatureV2 { get; set; }
private readonly RSA rsa;
public PublicKey(string pemKey, string sig, string? sigV2 = null)
public PublicKey(string pemKey, string? sig = null, string? sigV2 = null)
{
this.Key = KeyUtils.DecodePemKey(pemKey, "-----BEGIN RSA PUBLIC KEY-----", "-----END RSA PUBLIC KEY-----");
this.rsa = RSA.Create();
rsa.ImportSubjectPublicKeyInfo(this.Key, out _);
if (!string.IsNullOrEmpty(sig))
this.Signature = Convert.FromBase64String(sig);
if (!string.IsNullOrEmpty(sigV2))

View file

@ -131,7 +131,7 @@ namespace MinecraftClient.Protocol
if (Array.IndexOf(supportedVersions_Protocol16, ProtocolVersion) > -1)
return new Protocol16Handler(Client, ProtocolVersion, Handler);
int[] supportedVersions_Protocol18 = { 4, 5, 47, 107, 108, 109, 110, 210, 315, 316, 335, 338, 340, 393, 401, 404, 477, 480, 485, 490, 498, 573, 575, 578, 735, 736, 751, 753, 754, 755, 756, 757, 758, 759 };
int[] supportedVersions_Protocol18 = { 4, 5, 47, 107, 108, 109, 110, 210, 315, 316, 335, 338, 340, 393, 401, 404, 477, 480, 485, 490, 498, 573, 575, 578, 735, 736, 751, 753, 754, 755, 756, 757, 758, 759, 760 };
if (Array.IndexOf(supportedVersions_Protocol18, ProtocolVersion) > -1)
return new Protocol18Handler(Client, ProtocolVersion, Handler, forgeInfo);
@ -263,6 +263,9 @@ namespace MinecraftClient.Protocol
return 758;
case "1.19":
return 759;
case "1.19.1":
case "1.19.2":
return 760;
default:
return 0;
}
@ -329,6 +332,7 @@ namespace MinecraftClient.Protocol
case 757: return "1.18.1";
case 758: return "1.18.2";
case 759: return "1.19";
case 760: return "1.19.2";
default: return "0.0";
}
}