mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Player session
This commit is contained in:
parent
08da49756f
commit
4be7a05006
6 changed files with 87 additions and 8 deletions
|
|
@ -9,6 +9,7 @@ using MinecraftClient.Inventory;
|
|||
using MinecraftClient.Logger;
|
||||
using MinecraftClient.Mapping;
|
||||
using MinecraftClient.Protocol;
|
||||
using MinecraftClient.Protocol.Handlers;
|
||||
using MinecraftClient.Protocol.Handlers.Forge;
|
||||
using MinecraftClient.Protocol.Keys;
|
||||
using MinecraftClient.Protocol.Message;
|
||||
|
|
@ -1127,6 +1128,11 @@ namespace MinecraftClient
|
|||
}
|
||||
}
|
||||
|
||||
public PlayerKeyPair? GetPlayerKeyPair()
|
||||
{
|
||||
return playerKeyPair;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Action methods: Perform an action on the Server
|
||||
|
|
@ -2402,6 +2408,10 @@ namespace MinecraftClient
|
|||
Config.MCSettings.Skin.GetByte(),
|
||||
(byte)Config.MCSettings.MainHand);
|
||||
|
||||
if (protocolversion >= Protocol18Handler.MC_1_19_3_Version
|
||||
&& playerKeyPair != null)
|
||||
handler.SendPlayerSession(playerKeyPair);
|
||||
|
||||
|
||||
if (inventoryHandlingRequested)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -909,5 +909,10 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
{
|
||||
return false; //Currently not implemented
|
||||
}
|
||||
|
||||
public bool SendPlayerSession(PlayerKeyPair? playerKeyPair)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2490,6 +2490,8 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
fields.AddRange(dataTypes.GetLong(0)); // Salt: Long
|
||||
if (protocolVersion < MC_1_19_3_Version)
|
||||
fields.AddRange(dataTypes.GetVarInt(0)); // Signature Length: VarInt (1.19 - 1.19.2)
|
||||
else
|
||||
fields.AddRange(dataTypes.GetBool(false)); // Has signature: bool (1.19.3)
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -2507,24 +2509,35 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
else // 1.19.3
|
||||
sign = playerKeyPair.PrivateKey.SignMessage(message, uuid, timeNow, ref salt); // TODO?
|
||||
|
||||
if (protocolVersion < MC_1_19_3_Version)
|
||||
fields.AddRange(dataTypes.GetVarInt(sign.Length));
|
||||
else
|
||||
if (protocolVersion >= MC_1_19_3_Version)
|
||||
fields.AddRange(dataTypes.GetBool(true));
|
||||
else
|
||||
fields.AddRange(dataTypes.GetVarInt(sign.Length));
|
||||
fields.AddRange(sign);
|
||||
}
|
||||
|
||||
// Signed Preview: Boolean
|
||||
if (protocolVersion < MC_1_19_3_Version)
|
||||
fields.AddRange(dataTypes.GetBool(false));
|
||||
else
|
||||
if (protocolVersion >= MC_1_19_3_Version)
|
||||
fields.AddRange(dataTypes.GetVarInt(1)); // message count
|
||||
else
|
||||
fields.AddRange(dataTypes.GetBool(false));
|
||||
|
||||
if (protocolVersion >= MC_1_19_2_Version)
|
||||
{
|
||||
if (protocolVersion >= MC_1_19_3_Version)
|
||||
{
|
||||
// 1.19.3
|
||||
// Acknowledged: BitSet (no idea what is this)
|
||||
//fields.AddRange(dataTypes.GetVarInt(0));
|
||||
fields.AddRange(new byte[3] {0,0,0 });
|
||||
}
|
||||
else
|
||||
{
|
||||
// 1.19.2
|
||||
// Message Acknowledgment
|
||||
fields.AddRange(dataTypes.GetAcknowledgment(acknowledgment!, isOnlineMode && Config.Signature.LoginWithSecureProfile));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
SendPacket(PacketTypesOut.ChatMessage, fields);
|
||||
|
|
@ -3175,6 +3188,40 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
else { return false; }
|
||||
}
|
||||
|
||||
public bool SendPlayerSession(PlayerKeyPair? playerKeyPair)
|
||||
{
|
||||
if (protocolVersion >= MC_1_19_3_Version)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<byte> packet = new();
|
||||
|
||||
var uuid = Guid.NewGuid();
|
||||
|
||||
byte[] timestampByte = BitConverter.GetBytes(playerKeyPair.GetExpirationMilliseconds());
|
||||
Array.Reverse(timestampByte);
|
||||
var signature = KeyUtils.ComputeHash(timestampByte.Concat(playerKeyPair.PublicKey.Key).ToArray());
|
||||
|
||||
packet.AddRange(dataTypes.GetUUID(uuid));
|
||||
packet.AddRange(dataTypes.GetLong(playerKeyPair.GetExpirationMilliseconds()));
|
||||
packet.AddRange(dataTypes.GetVarInt(playerKeyPair.PublicKey.Key.Length));
|
||||
packet.AddRange(playerKeyPair.PublicKey.Key);
|
||||
//packet.AddRange(dataTypes.GetVarInt(signature.Length));
|
||||
//packet.AddRange(signature);
|
||||
packet.AddRange(dataTypes.GetVarInt(playerKeyPair.PublicKey.SignatureV2.Length));
|
||||
packet.AddRange(playerKeyPair.PublicKey.SignatureV2);
|
||||
|
||||
SendPacket(PacketTypesOut.PlayerSession, packet);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (SocketException) { return false; }
|
||||
catch (System.IO.IOException) { return false; }
|
||||
catch (ObjectDisposedException) { return false; }
|
||||
}
|
||||
else { return false; }
|
||||
}
|
||||
|
||||
private byte[] GenerateSalt()
|
||||
{
|
||||
byte[] salt = new byte[8];
|
||||
|
|
|
|||
|
|
@ -255,6 +255,12 @@ namespace MinecraftClient.Protocol
|
|||
/// <param name="uuid">The uuid of the player/entity to spectate/teleport to.</param>
|
||||
bool SendSpectate(Guid uuid);
|
||||
|
||||
/// <summary>
|
||||
/// Send player session
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
bool SendPlayerSession(PlayerKeyPair? playerKeyPair);
|
||||
|
||||
/// <summary>
|
||||
/// Get net read thread (main thread) ID
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using MinecraftClient.Inventory;
|
||||
using MinecraftClient.Logger;
|
||||
using MinecraftClient.Mapping;
|
||||
using MinecraftClient.Protocol.Keys;
|
||||
using MinecraftClient.Protocol.Message;
|
||||
|
||||
namespace MinecraftClient.Protocol
|
||||
|
|
@ -27,6 +28,7 @@ namespace MinecraftClient.Protocol
|
|||
string[] GetOnlinePlayers();
|
||||
Dictionary<string, string> GetOnlinePlayersWithUUID();
|
||||
PlayerInfo? GetPlayerInfo(Guid uuid);
|
||||
PlayerKeyPair? GetPlayerKeyPair();
|
||||
Location GetCurrentLocation();
|
||||
World GetWorld();
|
||||
bool GetIsSupportPreviewsChat();
|
||||
|
|
|
|||
|
|
@ -124,6 +124,15 @@ namespace MinecraftClient.Protocol.Keys
|
|||
return data.ToArray();
|
||||
}
|
||||
|
||||
public static byte[] GetSignatureData(string message, DateTimeOffset timestamp, ref byte[] salt, Guid sender, Guid sessionUuid)
|
||||
{
|
||||
List<byte> data = new();
|
||||
|
||||
// TODO!
|
||||
|
||||
return data.ToArray();
|
||||
}
|
||||
|
||||
// https://github.com/mono/mono/blob/master/mcs/class/System.Json/System.Json/JsonValue.cs
|
||||
public static string EscapeString(string src)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue