Implemented 1.20.3

This commit is contained in:
Anon 2024-01-30 12:51:47 +01:00
parent 1e60b611e9
commit 790e0bfe55
13 changed files with 650 additions and 271 deletions

View file

@ -1221,16 +1221,16 @@ public class WebSocketBot : ChatBot
}
public override void OnScoreboardObjective(string objectiveName, byte mode, string objectiveValue, int type,
string json_)
string json_, int numberFormat)
{
SendEvent("OnScoreboardObjective",
new { objectiveName, mode, objectiveValue, type, rawJson = json_ });
new { objectiveName, mode, objectiveValue, type, rawJson = json_, numberFormat });
}
public override void OnUpdateScore(string entityName, int action, string objectiveName, int value)
public override void OnUpdateScore(string entityName, int action, string objectiveName, string objectiveDisplayName, int value, int numberFormat)
{
SendEvent("OnUpdateScore",
new { entityName, action, objectiveName, type = value });
new { entityName, action, objectiveName, objectiveDisplayName, type = value, numberFormat });
}
public override void OnInventoryUpdate(int inventoryId)

View file

@ -22,7 +22,7 @@ public abstract class EntityMetadataPalette
<= Protocol18Handler.MC_1_12_2_Version => new EntityMetadataPalette1122(), // 1.9 - 1.12.2
<= Protocol18Handler.MC_1_19_2_Version => new EntityMetadataPalette1191(), // 1.13 - 1.19.2
<= Protocol18Handler.MC_1_19_3_Version => new EntityMetadataPalette1193(), // 1.19.3
<= Protocol18Handler.MC_1_20_2_Version => new EntityMetadataPalette1194(), // 1.19.4 - 1.20.2 +
<= Protocol18Handler.MC_1_20_4_Version => new EntityMetadataPalette1194(), // 1.19.4 - 1.20.4 +
_ => throw new NotImplementedException()
};
}

View file

@ -3414,29 +3414,32 @@ namespace MinecraftClient
}
/// <summary>
/// Called when coreboardObjective
/// Called when Soreboard Objective
/// </summary>
/// <param name="objectivename">objective name</param>
/// <param name="objectiveName">objective name</param>
/// <param name="mode">0 to create the scoreboard. 1 to remove the scoreboard. 2 to update the display text.</param>
/// <param name="objectivevalue">Only if mode is 0 or 2. The text to be displayed for the score</param>
/// <param name="objectiveValue">Only if mode is 0 or 2. The text to be displayed for the score</param>
/// <param name="type">Only if mode is 0 or 2. 0 = "integer", 1 = "hearts".</param>
public void OnScoreboardObjective(string objectivename, byte mode, string objectivevalue, int type)
/// <param name="numberFormat">Number format: 0 - blank, 1 - styled, 2 - fixed</param>
public void OnScoreboardObjective(string objectiveName, byte mode, string objectiveValue, int type, int numberFormat)
{
string json = objectivevalue;
objectivevalue = ChatParser.ParseText(objectivevalue);
DispatchBotEvent(bot => bot.OnScoreboardObjective(objectivename, mode, objectivevalue, type, json));
var json = objectiveValue;
objectiveValue = ChatParser.ParseText(objectiveValue);
DispatchBotEvent(bot => bot.OnScoreboardObjective(objectiveName, mode, objectiveValue, type, json, numberFormat));
}
/// <summary>
/// Called when DisplayScoreboard
/// </summary>
/// <param name="entityname">The entity whose score this is. For players, this is their username; for other entities, it is their UUID.</param>
/// <param name="entityName">The entity whose score this is. For players, this is their username; for other entities, it is their UUID.</param>
/// <param name="action">0 to create/update an item. 1 to remove an item.</param>
/// <param name="objectivename">The name of the objective the score belongs to</param>
/// <param name="value">he score to be displayed next to the entry. Only sent when Action does not equal 1.</param>
public void OnUpdateScore(string entityname, int action, string objectivename, int value)
/// <param name="objectiveName">The name of the objective the score belongs to</param>
/// <param name="objectiveDisplayName">The name of the objective the score belongs to, but with chat formatting</param>
/// <param name="objectiveValue">The score to be displayed next to the entry. Only sent when Action does not equal 1.</param>
/// <param name="numberFormat">Number format: 0 - blank, 1 - styled, 2 - fixed</param>
public void OnUpdateScore(string entityName, int action, string objectiveName, string objectiveDisplayName, int objectiveValue, int numberFormat)
{
DispatchBotEvent(bot => bot.OnUpdateScore(entityname, action, objectivename, value));
DispatchBotEvent(bot => bot.OnUpdateScore(entityName, action, objectiveName, objectiveDisplayName, objectiveValue, numberFormat));
}
/// <summary>

View file

@ -9,6 +9,7 @@ public enum ConfigurationPacketTypesIn
Ping,
RegistryData,
ResourcePack,
RemoveResourcePack,
FeatureFlags,
UpdateTags,

View file

@ -844,21 +844,21 @@ namespace MinecraftClient.Protocol.Handlers
/// </summary>
/// <param name="cache"></param>
/// <param name="itemPalette"></param>
protected void ReadParticleData(Queue<byte> cache, ItemPalette itemPalette)
public void ReadParticleData(Queue<byte> cache, ItemPalette itemPalette)
{
if (protocolversion < Protocol18Handler.MC_1_13_Version)
return;
int ParticleID = ReadNextVarInt(cache);
var particleId = ReadNextVarInt(cache);
// Refernece:
// 1.19.3 - https://wiki.vg/index.php?title=Data_types&oldid=17986
// Documentation:
// 1.19.3+ - https://wiki.vg/index.php?title=Data_types&oldid=17986
// 1.18 - https://wiki.vg/index.php?title=Data_types&oldid=17180
// 1.17 - https://wiki.vg/index.php?title=Data_types&oldid=16740
// 1.15 - https://wiki.vg/index.php?title=Data_types&oldid=15338
// 1.13 - https://wiki.vg/index.php?title=Data_types&oldid=14271
switch (ParticleID)
switch (particleId)
{
case 2:
// 1.18 +
@ -866,14 +866,12 @@ namespace MinecraftClient.Protocol.Handlers
ReadNextVarInt(cache); // Block state (minecraft:block)
break;
case 3:
if (protocolversion < Protocol18Handler.MC_1_17_Version
|| protocolversion > Protocol18Handler.MC_1_17_1_Version)
if (protocolversion is < Protocol18Handler.MC_1_17_Version or > Protocol18Handler.MC_1_17_1_Version)
ReadNextVarInt(
cache); // Block State (minecraft:block before 1.18, minecraft:block_marker after 1.18)
break;
case 4:
if (protocolversion == Protocol18Handler.MC_1_17_Version
|| protocolversion == Protocol18Handler.MC_1_17_1_Version)
if (protocolversion is Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version)
ReadNextVarInt(cache); // Block State (minecraft:block)
break;
case 11:
@ -883,44 +881,38 @@ namespace MinecraftClient.Protocol.Handlers
break;
case 14:
// 1.15 - 1.16.5 and 1.18 - 1.19.4
if ((protocolversion >= Protocol18Handler.MC_1_15_Version &&
protocolversion < Protocol18Handler.MC_1_17_Version)
|| protocolversion > Protocol18Handler.MC_1_17_1_Version)
if (protocolversion is >= Protocol18Handler.MC_1_15_Version and < Protocol18Handler.MC_1_17_Version or > Protocol18Handler.MC_1_17_1_Version)
ReadDustParticle(cache);
break;
case 15:
if (protocolversion == Protocol18Handler.MC_1_17_Version ||
protocolversion == Protocol18Handler.MC_1_17_1_Version)
ReadDustParticle(cache);
else
switch (protocolversion)
{
if (protocolversion > Protocol18Handler.MC_1_17_1_Version)
case Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version:
ReadDustParticle(cache);
break;
case > Protocol18Handler.MC_1_17_1_Version:
ReadDustParticleColorTransition(cache);
break;
}
break;
case 16:
if (protocolversion == Protocol18Handler.MC_1_17_Version ||
protocolversion == Protocol18Handler.MC_1_17_1_Version)
if (protocolversion is Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version)
ReadDustParticleColorTransition(cache);
break;
case 23:
// 1.15 - 1.16.5
if (protocolversion >= Protocol18Handler.MC_1_15_Version &&
protocolversion < Protocol18Handler.MC_1_17_Version)
if (protocolversion is >= Protocol18Handler.MC_1_15_Version and < Protocol18Handler.MC_1_17_Version)
ReadNextVarInt(cache); // Block State (minecraft:falling_dust)
break;
case 24:
// 1.18 - 1.19.2 onwards
if (protocolversion > Protocol18Handler.MC_1_17_1_Version &&
protocolversion < Protocol18Handler.MC_1_19_3_Version)
if (protocolversion is > Protocol18Handler.MC_1_17_1_Version and < Protocol18Handler.MC_1_19_3_Version)
ReadNextVarInt(cache); // Block State (minecraft:falling_dust)
break;
case 25:
// 1.17 - 1.17.1 and 1.19.3 onwards
if (protocolversion == Protocol18Handler.MC_1_17_Version
|| protocolversion == Protocol18Handler.MC_1_17_1_Version
|| protocolversion >= Protocol18Handler.MC_1_19_3_Version)
if (protocolversion is Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version or >= Protocol18Handler.MC_1_19_3_Version)
ReadNextVarInt(cache); // Block State (minecraft:falling_dust)
break;
case 27:
@ -934,31 +926,28 @@ namespace MinecraftClient.Protocol.Handlers
break;
case 32:
// 1.15 - 1.16.5
if (protocolversion >= Protocol18Handler.MC_1_15_Version &&
protocolversion < Protocol18Handler.MC_1_17_Version)
if (protocolversion is >= Protocol18Handler.MC_1_15_Version and < Protocol18Handler.MC_1_17_Version)
ReadNextItemSlot(cache, itemPalette); // Item (minecraft:item)
break;
case 36:
switch (protocolversion)
{
// 1.17 - 1.17.1
if (protocolversion == Protocol18Handler.MC_1_17_Version ||
protocolversion == Protocol18Handler.MC_1_17_1_Version)
{
case Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version:
ReadNextItemSlot(cache, itemPalette); // Item (minecraft:item)
}
else if (protocolversion > Protocol18Handler.MC_1_17_1_Version &&
protocolversion < Protocol18Handler.MC_1_19_3_Version)
{
break;
case > Protocol18Handler.MC_1_17_1_Version and < Protocol18Handler.MC_1_19_3_Version:
// minecraft:vibration
ReadNextLocation(cache); // Origin (Starting Position)
ReadNextLocation(cache); // Desitination (Ending Position)
ReadNextLocation(cache); // Destination (Ending Position)
ReadNextVarInt(cache); // Ticks
break;
}
break;
case 37:
// minecraft:vibration
if (protocolversion == Protocol18Handler.MC_1_17_Version
|| protocolversion == Protocol18Handler.MC_1_17_1_Version)
if (protocolversion is Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version)
{
ReadNextDouble(cache); // Origin X
ReadNextDouble(cache); // Origin Y
@ -977,15 +966,16 @@ namespace MinecraftClient.Protocol.Handlers
case 40:
if (protocolversion >= Protocol18Handler.MC_1_19_3_Version)
{
string positionSourceType = ReadNextString(cache);
if (positionSourceType == "minecraft:block")
var positionSourceType = ReadNextString(cache);
switch (positionSourceType)
{
case "minecraft:block":
ReadNextLocation(cache);
}
else if (positionSourceType == "minecraft:entity")
{
break;
case "minecraft:entity":
ReadNextVarInt(cache);
ReadNextFloat(cache);
break;
}
ReadNextVarInt(cache);

View file

@ -0,0 +1,215 @@
using System.Collections.Generic;
namespace MinecraftClient.Protocol.Handlers.PacketPalettes;
public class PacketPalette1204 : PacketTypePalette
{
private readonly Dictionary<int, PacketTypesIn> typeIn = new()
{
{ 0x00, PacketTypesIn.Bundle }, // Added in 1.19.4
{ 0x01, PacketTypesIn.SpawnEntity }, // Changed in 1.19 (Wiki name: Spawn Entity)
{ 0x02, PacketTypesIn.SpawnExperienceOrb }, // (Wiki name: Spawn Exeprience Orb)
{ 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)
{ 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.ChunkBatchFinished }, // Added in 1.20.2
{ 0x0D, PacketTypesIn.ChunkBatchStarted }, // Added in 1.20.2
{ 0x0E, PacketTypesIn.ChunksBiomes }, // Added in 1.19.4
{ 0x0F, PacketTypesIn.ClearTiles }, //
{ 0x10, PacketTypesIn.TabComplete }, // (Wiki name: Command Suggestions Response)
{ 0x11, PacketTypesIn.DeclareCommands }, // (Wiki name: Commands)
{ 0x12, PacketTypesIn.CloseWindow }, // (Wiki name: Close Container (clientbound))
{ 0x13, PacketTypesIn.WindowItems }, // (Wiki name: Set Container Content)
{ 0x14, PacketTypesIn.WindowProperty }, // (Wiki name: Set Container Property)
{ 0x15, PacketTypesIn.SetSlot }, // (Wiki name: Set Container Slot)
{ 0x16, PacketTypesIn.SetCooldown }, //
{ 0x17, PacketTypesIn.ChatSuggestions }, // Added in 1.19.1
{ 0x18, PacketTypesIn.PluginMessage }, // (Wiki name: Plugin Message (clientbound))
{ 0x19, PacketTypesIn.DamageEvent }, // Added in 1.19.4
{ 0x1A, PacketTypesIn.HideMessage }, // Added in 1.19.1
{ 0x1B, PacketTypesIn.Disconnect }, //
{ 0x1C, PacketTypesIn.ProfilelessChatMessage }, // Added in 1.19.3 (Wiki name: Disguised Chat Message)
{ 0x1D, PacketTypesIn.EntityStatus }, // (Wiki name: Entity Event)
{ 0x1E, PacketTypesIn.Explosion }, // Changed in 1.19 (Location fields are now Double instead of Float) (Wiki name: Explosion)
{ 0x1F, PacketTypesIn.UnloadChunk }, // (Wiki name: Forget Chunk)
{ 0x20, PacketTypesIn.ChangeGameState }, // (Wiki name: Game Event)
{ 0x21, PacketTypesIn.OpenHorseWindow }, // (Wiki name: Horse Screen Open)
{ 0x22, PacketTypesIn.HurtAnimation }, // Added in 1.19.4
{ 0x23, PacketTypesIn.InitializeWorldBorder }, //
{ 0x24, PacketTypesIn.KeepAlive }, //
{ 0x25, PacketTypesIn.ChunkData }, //
{ 0x26, PacketTypesIn.Effect }, // (Wiki name: World Event)
{ 0x27, PacketTypesIn.Particle }, // Changed in 1.19 (Wiki name: Level Particle) (No need to be implemented)
{ 0x28, PacketTypesIn.UpdateLight }, // (Wiki name: Light Update)
{ 0x29, PacketTypesIn.JoinGame }, // Changed in 1.20.2 (Wiki name: Login (play))
{ 0x2A, PacketTypesIn.MapData }, // (Wiki name: Map Item Data)
{ 0x2B, PacketTypesIn.TradeList }, // (Wiki name: Merchant Offers)
{ 0x2C, PacketTypesIn.EntityPosition }, // (Wiki name: Move Entity Position)
{ 0x2D, PacketTypesIn.EntityPositionAndRotation }, // (Wiki name: Move Entity Position and Rotation)
{ 0x2E, PacketTypesIn.EntityRotation }, // (Wiki name: Move Entity Rotation)
{ 0x2F, PacketTypesIn.VehicleMove }, // (Wiki name: Move Vehicle)
{ 0x30, PacketTypesIn.OpenBook }, //
{ 0x31, PacketTypesIn.OpenWindow }, // (Wiki name: Open Screen)
{ 0x32, PacketTypesIn.OpenSignEditor }, //
{ 0x33, PacketTypesIn.Ping }, // (Wiki name: Ping (play))
{ 0x34, PacketTypesIn.PingResponse }, // Added in 1.20.2
{ 0x35, PacketTypesIn.CraftRecipeResponse }, // (Wiki name: Place Ghost Recipe)
{ 0x36, PacketTypesIn.PlayerAbilities }, //
{ 0x37, PacketTypesIn.ChatMessage }, // Changed in 1.19 (Completely changed) (Wiki name: Player Chat Message)
{ 0x38, PacketTypesIn.EndCombatEvent }, // (Wiki name: End Combat)
{ 0x39, PacketTypesIn.EnterCombatEvent }, // (Wiki name: Enter Combat)
{ 0x3A, PacketTypesIn.DeathCombatEvent }, // (Wiki name: Combat Death)
{ 0x3B, PacketTypesIn.PlayerRemove }, // Added in 1.19.3 (Not used)
{ 0x3C, PacketTypesIn.PlayerInfo }, // Changed in 1.19 (Heavy changes)
{ 0x3D, PacketTypesIn.FacePlayer }, // (Wiki name: Player Look At)
{ 0x3E, PacketTypesIn.PlayerPositionAndLook }, // (Wiki name: Synchronize Player Position)
{ 0x3F, PacketTypesIn.UnlockRecipes }, // (Wiki name: Update Recipe Book)
{ 0x40, PacketTypesIn.DestroyEntities }, // (Wiki name: Remove Entites)
{ 0x41, PacketTypesIn.RemoveEntityEffect }, //
{ 0x42, PacketTypesIn.ResetScore }, // Added in 1.20.3
{ 0x43, PacketTypesIn.RemoveResourcePack }, // Added in 1.20.3
{ 0x44, PacketTypesIn.ResourcePackSend }, // (Wiki name: Add Resource pack (play))
{ 0x45, PacketTypesIn.Respawn }, // Changed in 1.20.2
{ 0x46, PacketTypesIn.EntityHeadLook }, // (Wiki name: Set Head Rotation)
{ 0x47, PacketTypesIn.MultiBlockChange }, // (Wiki name: Update Section Blocks)
{ 0x48, PacketTypesIn.SelectAdvancementTab }, //
{ 0x49, PacketTypesIn.ServerData }, // Added in 1.19
{ 0x4A, PacketTypesIn.ActionBar }, // (Wiki name: Set Action Bar Text)
{ 0x4B, PacketTypesIn.WorldBorderCenter }, // (Wiki name: Set Border Center)
{ 0x4C, PacketTypesIn.WorldBorderLerpSize }, //
{ 0x4D, PacketTypesIn.WorldBorderSize }, // (Wiki name: Set World Border Size)
{ 0x4E, PacketTypesIn.WorldBorderWarningDelay }, // (Wiki name: Set World Border Warning Delay)
{ 0x4F, PacketTypesIn.WorldBorderWarningReach }, // (Wiki name: Set Border Warning Distance)
{ 0x50, PacketTypesIn.Camera }, // (Wiki name: Set Camera)
{ 0x51, PacketTypesIn.HeldItemChange }, // (Wiki name: Set Held Item)
{ 0x52, PacketTypesIn.UpdateViewPosition }, // (Wiki name: Set Center Chunk)
{ 0x53, PacketTypesIn.UpdateViewDistance }, // (Wiki name: Set Render Distance)
{ 0x54, PacketTypesIn.SpawnPosition }, // (Wiki name: Set Default Spawn Position)
{ 0x55, PacketTypesIn.DisplayScoreboard }, // (Wiki name: Set Display Objective)
{ 0x56, PacketTypesIn.EntityMetadata }, // (Wiki name: Set Entity Metadata)
{ 0x57, PacketTypesIn.AttachEntity }, // (Wiki name: Link Entities)
{ 0x58, PacketTypesIn.EntityVelocity }, // (Wiki name: Set Entity Velocity)
{ 0x59, PacketTypesIn.EntityEquipment }, // (Wiki name: Set Equipment)
{ 0x5A, PacketTypesIn.SetExperience }, // Changed in 1.20.2
{ 0x5B, PacketTypesIn.UpdateHealth }, // (Wiki name: Set Health)
{ 0x5C, PacketTypesIn.ScoreboardObjective }, // (Wiki name: Update Objectives) - Changed in 1.20.3
{ 0x5D, PacketTypesIn.SetPassengers }, //
{ 0x5E, PacketTypesIn.Teams }, // (Wiki name: Update Teams)
{ 0x5F, PacketTypesIn.UpdateScore }, // (Wiki name: Update Score)
{ 0x60, PacketTypesIn.UpdateSimulationDistance }, // (Wiki name: Set Simulation Distance)
{ 0x61, PacketTypesIn.SetTitleSubTitle }, // (Wiki name: Set Subtitle Test)
{ 0x62, PacketTypesIn.TimeUpdate }, // (Wiki name: Set Time)
{ 0x63, PacketTypesIn.SetTitleText }, // (Wiki name: Set Title)
{ 0x64, PacketTypesIn.SetTitleTime }, // (Wiki name: Set Title Animation Times)
{ 0x65, PacketTypesIn.EntitySoundEffect }, // (Wiki name: Sound Entity)
{ 0x66, PacketTypesIn.SoundEffect }, // Changed in 1.19 (Added "Seed" field) (Wiki name: Sound Effect) (No need to be implemented)
{ 0x67, PacketTypesIn.StartConfiguration }, // Added in 1.20.2
{ 0x68, PacketTypesIn.StopSound }, //
{ 0x69, PacketTypesIn.SystemChat }, // Added in 1.19 (Wiki name: System Chat Message)
{ 0x6A, PacketTypesIn.PlayerListHeaderAndFooter }, // (Wiki name: Set Tab List Header And Footer)
{ 0x6B, PacketTypesIn.NBTQueryResponse }, // (Wiki name: Tag Query Response)
{ 0x6C, PacketTypesIn.CollectItem }, // (Wiki name: Pickup Item)
{ 0x6D, PacketTypesIn.EntityTeleport }, // (Wiki name: Teleport Entity)
{ 0x6E, PacketTypesIn.SetTickingState }, // Added in 1.20.3
{ 0x6F, PacketTypesIn.StepTick }, // Added in 1.20.3
{ 0x70, PacketTypesIn.Advancements }, // (Wiki name: Update Advancements) (Unused)
{ 0x71, PacketTypesIn.EntityProperties }, // (Wiki name: Update Attributes)
{ 0x72, PacketTypesIn.EntityEffect }, // Changed in 1.19 (Added "Has Factor Data" and "Factor Codec" fields) (Wiki name: Entity Effect)
{ 0x73, PacketTypesIn.DeclareRecipes }, // (Wiki name: Update Recipes) (Unused)
{ 0x74, PacketTypesIn.Tags }, // (Wiki name: Update Tags)
};
private readonly Dictionary<int, PacketTypesOut> typeOut = new()
{
{ 0x00, PacketTypesOut.TeleportConfirm }, // (Wiki name: Confirm Teleportation)
{ 0x01, PacketTypesOut.QueryBlockNBT }, // (Wiki name: Query Block Entity Tag)
{ 0x02, PacketTypesOut.SetDifficulty }, // (Wiki name: Change Difficulty)
{ 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.PlayerSession }, // Added in 1.19.3
{ 0x07, PacketTypesOut.ChunkBatchReceived }, // Added in 1.20.2
{ 0x08, PacketTypesOut.ClientStatus }, // (Wiki name: Client Command)
{ 0x09, PacketTypesOut.ClientSettings }, // (Wiki name: Client Information)
{ 0x0A, PacketTypesOut.TabComplete }, // (Wiki name: Command Suggestions Request)
{ 0x0B, PacketTypesOut.AcknowledgeConfiguration }, // Added in 1.20.2
{ 0x0C, PacketTypesOut.ClickWindowButton }, // (Wiki name: Click Container Button)
{ 0x0D, PacketTypesOut.ClickWindow }, // (Wiki name: Click Container)
{ 0x0E, PacketTypesOut.CloseWindow }, // (Wiki name: Close Container (serverbound))
{ 0x0F, PacketTypesOut.ChangeContainerSlotState }, // Added in 1.20.3
{ 0x10, PacketTypesOut.PluginMessage }, // (Wiki name: Serverbound Plugin Message)
{ 0x11, PacketTypesOut.EditBook }, //
{ 0x12, PacketTypesOut.EntityNBTRequest }, // (Wiki name: Query Entity Tag)
{ 0x13, PacketTypesOut.InteractEntity }, // (Wiki name: Interact)
{ 0x14, PacketTypesOut.GenerateStructure }, // (Wiki name: Jigsaw Generate)
{ 0x15, PacketTypesOut.KeepAlive }, // (Wiki name: Serverbound Keep Alive (play))
{ 0x16, PacketTypesOut.LockDifficulty }, //
{ 0x17, PacketTypesOut.PlayerPosition }, // (Wiki name: Move Player Position)
{ 0x18, PacketTypesOut.PlayerPositionAndRotation }, // (Wiki name: Set Player Position and Rotation)
{ 0x19, PacketTypesOut.PlayerRotation }, // (Wiki name: Set Player Rotation)
{ 0x1A, PacketTypesOut.PlayerMovement }, // (Wiki name: Set Player On Ground)
{ 0x1B, PacketTypesOut.VehicleMove }, // (Wiki name: Move Vehicle (serverbound))
{ 0x1C, PacketTypesOut.SteerBoat }, // (Wiki name: Paddle Boat)
{ 0x1D, PacketTypesOut.PickItem }, //
{ 0x1E, PacketTypesOut.PingRequest }, // Added in 1.20.2
{ 0x1F, PacketTypesOut.CraftRecipeRequest }, // (Wiki name: Place recipe)
{ 0x20, PacketTypesOut.PlayerAbilities }, //
{ 0x21, PacketTypesOut.PlayerDigging }, // Changed in 1.19 (Added a "Sequence" field) (Wiki name: Player Action)
{ 0x22, PacketTypesOut.EntityAction }, // (Wiki name: Player Command)
{ 0x23, PacketTypesOut.SteerVehicle }, // (Wiki name: Player Input)
{ 0x24, PacketTypesOut.Pong }, // (Wiki name: Pong (play))
{ 0x25, PacketTypesOut.SetDisplayedRecipe }, // (Wiki name: Recipe Book Change Settings)
{ 0x26, PacketTypesOut.SetRecipeBookState }, // (Wiki name: Recipe Book Seen Recipe)
{ 0x27, PacketTypesOut.NameItem }, // (Wiki name: Rename Item)
{ 0x28, PacketTypesOut.ResourcePackStatus }, // (Wiki name: Resource Pack (serverbound))
{ 0x29, PacketTypesOut.AdvancementTab }, // (Wiki name: Seen Advancements)
{ 0x2A, PacketTypesOut.SelectTrade }, //
{ 0x2B, PacketTypesOut.SetBeaconEffect }, // Changed in 1.19 (No need to be implemented yet)
{ 0x2C, PacketTypesOut.HeldItemChange }, // (Wiki name: Set Carried Item (serverbound))
{ 0x2D, PacketTypesOut.UpdateCommandBlock }, // (Wiki name: Program Command Block)
{ 0x2E, PacketTypesOut.UpdateCommandBlockMinecart }, // (Wiki name: Program Command Block Minecart)
{ 0x2F, PacketTypesOut.CreativeInventoryAction }, // (Wiki name: Set Creative Mode Slot)
{ 0x30, PacketTypesOut.UpdateJigsawBlock }, // (Wiki name: Program Jigsaw Block)
{ 0x31, PacketTypesOut.UpdateStructureBlock }, // (Wiki name: Program Structure Block)
{ 0x32, PacketTypesOut.UpdateSign }, // (Wiki name: Update Sign)
{ 0x33, PacketTypesOut.Animation }, // (Wiki name: Swing Arm)
{ 0x34, PacketTypesOut.Spectate }, // (Wiki name: Teleport To Entity)
{ 0x35, PacketTypesOut.PlayerBlockPlacement }, // Changed in 1.19 (Added a "Sequence" field) (Wiki name: Use Item On)
{ 0x36, PacketTypesOut.UseItem }, // Changed in 1.19 (Added a "Sequence" field) (Wiki name: Use Item)
};
private readonly Dictionary<int, ConfigurationPacketTypesIn> configurationTypesIn = new()
{
{ 0x00, ConfigurationPacketTypesIn.PluginMessage },
{ 0x01, ConfigurationPacketTypesIn.Disconnect },
{ 0x02, ConfigurationPacketTypesIn.FinishConfiguration },
{ 0x03, ConfigurationPacketTypesIn.KeepAlive },
{ 0x04, ConfigurationPacketTypesIn.Ping },
{ 0x05, ConfigurationPacketTypesIn.RegistryData },
{ 0x06, ConfigurationPacketTypesIn.RemoveResourcePack },
{ 0x07, ConfigurationPacketTypesIn.ResourcePack },
{ 0x08, ConfigurationPacketTypesIn.FeatureFlags },
{ 0x09, ConfigurationPacketTypesIn.UpdateTags },
};
private readonly Dictionary<int, ConfigurationPacketTypesOut> configurationTypesOut = new()
{
{ 0x00, ConfigurationPacketTypesOut.ClientInformation },
{ 0x01, ConfigurationPacketTypesOut.PluginMessage },
{ 0x02, ConfigurationPacketTypesOut.FinishConfiguration },
{ 0x03, ConfigurationPacketTypesOut.KeepAlive },
{ 0x04, ConfigurationPacketTypesOut.Pong },
{ 0x05, ConfigurationPacketTypesOut.ResourcePackResponse }
};
protected override Dictionary<int, PacketTypesIn> GetListIn() => typeIn;
protected override Dictionary<int, PacketTypesOut> GetListOut() => typeOut;
protected override Dictionary<int, ConfigurationPacketTypesIn> GetConfigurationListIn() => configurationTypesIn!;
protected override Dictionary<int, ConfigurationPacketTypesOut> GetConfigurationListOut() => configurationTypesOut!;
}

View file

@ -48,7 +48,7 @@ namespace MinecraftClient.Protocol.Handlers
{
PacketTypePalette p = protocol switch
{
> Protocol18Handler.MC_1_20_2_Version => throw new NotImplementedException(Translations
> Protocol18Handler.MC_1_20_4_Version => throw new NotImplementedException(Translations
.exception_palette_packet),
<= Protocol18Handler.MC_1_8_Version => new PacketPalette17(),
<= Protocol18Handler.MC_1_11_2_Version => new PacketPalette110(),
@ -64,8 +64,9 @@ namespace MinecraftClient.Protocol.Handlers
<= Protocol18Handler.MC_1_19_Version => new PacketPalette119(),
<= Protocol18Handler.MC_1_19_2_Version => new PacketPalette1192(),
<= Protocol18Handler.MC_1_19_3_Version => new PacketPalette1193(),
< Protocol18Handler.MC_1_20_2_Version => new PacketPalette1194(),
_ => new PacketPalette1202()
<= Protocol18Handler.MC_1_19_4_Version => new PacketPalette1194(),
<= Protocol18Handler.MC_1_20_2_Version => new PacketPalette1202(),
_ => new PacketPalette1204()
};
p.SetForgeEnabled(forgeEnabled);

View file

@ -1,7 +1,7 @@
namespace MinecraftClient.Protocol.Handlers
{
/// <summary>
/// Incomming packet types
/// Incoming packet types
/// </summary>
public enum PacketTypesIn
{
@ -84,6 +84,8 @@
PluginMessage, //
ProfilelessChatMessage, // Added in 1.19.3
RemoveEntityEffect, //
RemoveResourcePack, // Added in 1.20.3
ResetScore, // Added in 1.20.3
ResourcePackSend, //
Respawn, //
ScoreboardObjective, //
@ -96,6 +98,8 @@
SetExperience, //
SetPassengers, //
SetSlot, //
SetTickingState, // Added in 1.20.3
StepTick, // Added in 1.20.3
SetTitleSubTitle, //
SetTitleText, //
SetTitleTime, //

View file

@ -8,6 +8,7 @@
AcknowledgeConfiguration, // Added in 1.20.2
AdvancementTab, //
Animation, //
ChangeContainerSlotState, // Added in 1.20.3
ChatCommand, // Added in 1.19
ChatMessage, //
ChatPreview, // Added in 1.19

View file

@ -69,6 +69,7 @@ namespace MinecraftClient.Protocol.Handlers
internal const int MC_1_19_4_Version = 762;
internal const int MC_1_20_Version = 763;
internal const int MC_1_20_2_Version = 764;
internal const int MC_1_20_4_Version = 765;
private int compression_treshold = 0;
private int autocomplete_transaction_id = 0;
@ -120,21 +121,21 @@ namespace MinecraftClient.Protocol.Handlers
lastSeenMessagesCollector = protocolVersion >= MC_1_19_3_Version ? new(20) : new(5);
chunkBatchStartTime = GetNanos();
if (handler.GetTerrainEnabled() && protocolVersion > MC_1_20_2_Version)
if (handler.GetTerrainEnabled() && protocolVersion > MC_1_20_4_Version)
{
log.Error($"§c{Translations.extra_terrainandmovement_disabled}");
handler.SetTerrainEnabled(false);
}
if (handler.GetInventoryEnabled() &&
protocolVersion is < MC_1_9_Version or > MC_1_20_2_Version)
protocolVersion is < MC_1_9_Version or > MC_1_20_4_Version)
{
log.Error($"§c{Translations.extra_inventory_disabled}");
handler.SetInventoryEnabled(false);
}
if (handler.GetEntityHandlingEnabled() &&
protocolVersion is < MC_1_8_Version or > MC_1_20_2_Version)
protocolVersion is < MC_1_8_Version or > MC_1_20_4_Version)
{
log.Error($"§c{Translations.extra_entity_disabled}");
handler.SetEntityHandlingEnabled(false);
@ -143,7 +144,7 @@ namespace MinecraftClient.Protocol.Handlers
Block.Palette = protocolVersion switch
{
// Block palette
> MC_1_20_2_Version when handler.GetTerrainEnabled() =>
> MC_1_20_4_Version when handler.GetTerrainEnabled() =>
throw new NotImplementedException(Translations.exception_palette_block),
>= MC_1_20_Version => new Palette120(),
MC_1_19_4_Version => new Palette1194(),
@ -160,7 +161,7 @@ namespace MinecraftClient.Protocol.Handlers
entityPalette = protocolVersion switch
{
// Entity palette
> MC_1_20_2_Version when handler.GetEntityHandlingEnabled() =>
> MC_1_20_4_Version when handler.GetEntityHandlingEnabled() =>
throw new NotImplementedException(Translations.exception_palette_entity),
>= MC_1_20_Version => new EntityPalette120(),
MC_1_19_4_Version => new EntityPalette1194(),
@ -181,7 +182,7 @@ namespace MinecraftClient.Protocol.Handlers
itemPalette = protocolVersion switch
{
// Item palette
> MC_1_20_2_Version when handler.GetInventoryEnabled() =>
> MC_1_20_4_Version when handler.GetInventoryEnabled() =>
throw new NotImplementedException(Translations.exception_palette_item),
>= MC_1_20_Version => new ItemPalette120(),
MC_1_19_4_Version => new ItemPalette1194(),
@ -422,28 +423,13 @@ namespace MinecraftClient.Protocol.Handlers
break;
case ConfigurationPacketTypesIn.ResourcePack:
var url = dataTypes.ReadNextString(packetData);
var hash = dataTypes.ReadNextString(packetData);
dataTypes.ReadNextBool(packetData); // Forced
var hasPromptMessage =
dataTypes.ReadNextBool(packetData);
if (hasPromptMessage)
dataTypes.SkipNextString(packetData);
// Some server plugins may send invalid resource packs to probe the client and we need to ignore them (issue #1056)
if (!url.StartsWith("http") &&
hash.Length != 40) // Some server may have null hash value
case ConfigurationPacketTypesIn.RemoveResourcePack:
if (dataTypes.ReadNextBool(packetData)) // Has UUID
dataTypes.ReadNextUUID(packetData); // UUID
break;
//Send back "accepted" and "successfully loaded" responses for plugins or server config making use of resource pack mandatory
var responseHeader = Array.Empty<byte>();
SendPacket(ConfigurationPacketTypesOut.ResourcePackResponse,
dataTypes.ConcatBytes(responseHeader, DataTypes.GetVarInt(3))); // Accepted pack
SendPacket(ConfigurationPacketTypesOut.ResourcePackResponse,
dataTypes.ConcatBytes(responseHeader,
DataTypes.GetVarInt(0))); // Successfully loaded
case ConfigurationPacketTypesIn.ResourcePack:
HandleResourcePackPacket(packetData);
break;
// Ignore other packets at this stage
@ -480,6 +466,52 @@ namespace MinecraftClient.Protocol.Handlers
return true;
}
public void HandleResourcePackPacket(Queue<byte> packetData)
{
var uuid = Guid.Empty;
if (protocolVersion >= MC_1_20_4_Version)
uuid = dataTypes.ReadNextUUID(packetData);
var url = dataTypes.ReadNextString(packetData);
var hash = dataTypes.ReadNextString(packetData);
if (protocolVersion >= MC_1_17_Version)
{
dataTypes.ReadNextBool(packetData); // Forced
if (dataTypes.ReadNextBool(packetData)) // Has Prompt Message
dataTypes.SkipNextString(packetData); // Prompt Message
}
// Some server plugins may send invalid resource packs to probe the client and we need to ignore them (issue #1056)
if (!url.StartsWith("http") &&
hash.Length != 40) // Some server may have null hash value
return;
//Send back "accepted" and "successfully loaded" responses for plugins or server config making use of resource pack mandatory
var responseHeader = protocolVersion < MC_1_10_Version // After 1.10, the MC does not include resource pack hash in responses
? dataTypes.ConcatBytes(DataTypes.GetVarInt(hash.Length), Encoding.UTF8.GetBytes(hash))
: Array.Empty<byte>();
var basePacketData = protocolVersion >= MC_1_20_4_Version && uuid != Guid.Empty
? dataTypes.ConcatBytes(responseHeader, DataTypes.GetUUID(uuid))
: responseHeader;
var acceptedResourcePackData = dataTypes.ConcatBytes(basePacketData, DataTypes.GetVarInt(3));
var loadedResourcePackData = dataTypes.ConcatBytes(basePacketData, DataTypes.GetVarInt(0));
if (currentState == CurrentState.Configuration)
{
SendPacket(ConfigurationPacketTypesOut.ResourcePackResponse, acceptedResourcePackData); // Accepted
SendPacket(ConfigurationPacketTypesOut.ResourcePackResponse, loadedResourcePackData); // Successfully loaded
}
else
{
SendPacket(PacketTypesOut.ResourcePackStatus, acceptedResourcePackData); // Accepted
SendPacket(PacketTypesOut.ResourcePackStatus, loadedResourcePackData); // Successfully loaded
}
}
private bool HandlePlayPackets(int packetId, Queue<byte> packetData)
{
switch (packetPalette.GetIncomingTypeById(packetId))
@ -1648,7 +1680,15 @@ namespace MinecraftClient.Protocol.Handlers
var iconBase64 = "-";
var hasIcon = dataTypes.ReadNextBool(packetData);
if (hasIcon)
{
if(protocolVersion < MC_1_20_2_Version)
iconBase64 = dataTypes.ReadNextString(packetData);
else
{
var pngData = dataTypes.ReadNextByteArray(packetData);
iconBase64 = Convert.ToBase64String(pngData);
}
}
var previewsChat = false;
if (protocolVersion < MC_1_19_3_Version)
@ -2119,34 +2159,18 @@ namespace MinecraftClient.Protocol.Handlers
}
break;
case PacketTypesIn.ResourcePackSend:
var url = dataTypes.ReadNextString(packetData);
var hash = dataTypes.ReadNextString(packetData);
var forced = true; // Assume forced for MC 1.16 and below
if (protocolVersion >= MC_1_17_Version)
{
forced = dataTypes.ReadNextBool(packetData);
var hasPromptMessage =
dataTypes.ReadNextBool(packetData); // Has Prompt Message (Boolean) - 1.17 and above
if (hasPromptMessage)
dataTypes.SkipNextString(
packetData); // Prompt Message (Optional Chat) - 1.17 and above
}
// Some server plugins may send invalid resource packs to probe the client and we need to ignore them (issue #1056)
if (!url.StartsWith("http") && hash.Length != 40) // Some server may have null hash value
case PacketTypesIn.RemoveResourcePack:
if (dataTypes.ReadNextBool(packetData)) // Has UUID
dataTypes.ReadNextUUID(packetData); // UUID
break;
case PacketTypesIn.ResourcePackSend:
HandleResourcePackPacket(packetData);
break;
case PacketTypesIn.ResetScore:
dataTypes.ReadNextString(packetData); // Entity Name
if(dataTypes.ReadNextBool(packetData)) // Has Objective Name
dataTypes.ReadNextString(packetData); // Objective Name
//Send back "accepted" and "successfully loaded" responses for plugins or server config making use of resource pack mandatory
var responseHeader = Array.Empty<byte>();
if (protocolVersion <
MC_1_10_Version) //MC 1.10 does not include resource pack hash in responses
responseHeader = dataTypes.ConcatBytes(DataTypes.GetVarInt(hash.Length),
Encoding.UTF8.GetBytes(hash));
SendPacket(PacketTypesOut.ResourcePackStatus,
dataTypes.ConcatBytes(responseHeader, DataTypes.GetVarInt(3))); // Accepted pack
SendPacket(PacketTypesOut.ResourcePackStatus,
dataTypes.ConcatBytes(responseHeader, DataTypes.GetVarInt(0))); // Successfully loaded
break;
case PacketTypesIn.SpawnEntity:
if (handler.GetEntityHandlingEnabled())
@ -2395,7 +2419,7 @@ namespace MinecraftClient.Protocol.Handlers
// Also make a palette for field? Will be a lot of work
var healthField = protocolVersion switch
{
> MC_1_20_2_Version => throw new NotImplementedException(Translations
> MC_1_20_4_Version => throw new NotImplementedException(Translations
.exception_palette_healthfield),
// 1.17 and above
>= MC_1_17_Version => 9,
@ -2481,15 +2505,29 @@ namespace MinecraftClient.Protocol.Handlers
var explosionStrength = dataTypes.ReadNextFloat(packetData);
var explosionBlockCount = protocolVersion >= MC_1_17_Version
? dataTypes.ReadNextVarInt(packetData)
: dataTypes.ReadNextInt(packetData);
: dataTypes.ReadNextInt(packetData); // Record count
// Records
for (var i = 0; i < explosionBlockCount; i++)
dataTypes.ReadData(3, packetData);
// Maybe use in the future when the physics are implemented
var playerVelocityX = dataTypes.ReadNextFloat(packetData);
var playerVelocityY = dataTypes.ReadNextFloat(packetData);
var playerVelocityZ = dataTypes.ReadNextFloat(packetData);
dataTypes.ReadNextFloat(packetData); // Player Motion X
dataTypes.ReadNextFloat(packetData); // Player Motion Y
dataTypes.ReadNextFloat(packetData); // Player Motion Z
if (protocolVersion >= MC_1_20_4_Version)
{
dataTypes.ReadNextVarInt(packetData); // Block Interaction
dataTypes.ReadParticleData(packetData, itemPalette); // Small Explosion Particles
dataTypes.ReadParticleData(packetData, itemPalette); // Large Explosion Particles
// Explosion Sound
dataTypes.ReadNextString(packetData); // Sound Name
var hasFixedRange = dataTypes.ReadNextBool(packetData);
if (hasFixedRange)
dataTypes.ReadNextFloat(packetData); // Range
}
handler.OnExplosion(explosionLocation, explosionStrength, explosionBlockCount);
break;
@ -2497,30 +2535,61 @@ namespace MinecraftClient.Protocol.Handlers
handler.OnHeldItemChange(dataTypes.ReadNextByte(packetData)); // Slot
break;
case PacketTypesIn.ScoreboardObjective:
var objectiveName2 = dataTypes.ReadNextString(packetData);
var objectiveName = dataTypes.ReadNextString(packetData);
var mode = dataTypes.ReadNextByte(packetData);
var objectiveValue = string.Empty;
var type2 = -1;
var objectiveType = -1;
var numberFormat = 0;
if (mode is 0 or 2)
{
objectiveValue = dataTypes.ReadNextString(packetData);
type2 = dataTypes.ReadNextVarInt(packetData);
objectiveType = dataTypes.ReadNextVarInt(packetData);
if (protocolVersion >= MC_1_20_4_Version)
{
if (dataTypes.ReadNextBool(packetData)) // Has Number Format
numberFormat = dataTypes.ReadNextVarInt(packetData); // Number Format
}
}
handler.OnScoreboardObjective(objectiveName2, mode, objectiveValue, type2);
handler.OnScoreboardObjective(objectiveName, mode, objectiveValue, objectiveType, numberFormat);
break;
case PacketTypesIn.UpdateScore:
var entityName = dataTypes.ReadNextString(packetData);
var action3 = protocolVersion >= MC_1_18_2_Version
var action3 = 0;
var objectiveName3 = string.Empty;
var objectiveValue2 = -1;
var objectiveDisplayName3 = string.Empty;
var numberFormat2 = 0;
if (protocolVersion >= MC_1_20_4_Version)
{
objectiveName3 = dataTypes.ReadNextString(packetData); // Objective Name
objectiveValue2 = dataTypes.ReadNextVarInt(packetData); // Value
if (dataTypes.ReadNextBool(packetData)) // Has Display Name
objectiveDisplayName3 = ChatParser.ParseText(dataTypes.ReadNextString(packetData)); // Has Display Name
if (dataTypes.ReadNextBool(packetData)) // Has Number Format
numberFormat2 = dataTypes.ReadNextVarInt(packetData); // Number Format
}
else
{
action3 = protocolVersion >= MC_1_18_2_Version
? dataTypes.ReadNextVarInt(packetData)
: dataTypes.ReadNextByte(packetData);
var objectiveName3 = string.Empty;
var value = -1;
if (action3 != 1 || protocolVersion >= MC_1_8_Version)
objectiveName3 = dataTypes.ReadNextString(packetData);
if (action3 != 1)
value = dataTypes.ReadNextVarInt(packetData);
handler.OnUpdateScore(entityName, action3, objectiveName3, value);
objectiveValue2 = dataTypes.ReadNextVarInt(packetData);
}
handler.OnUpdateScore(entityName, action3, objectiveName3, objectiveDisplayName3, objectiveValue2, numberFormat2);
break;
case PacketTypesIn.BlockChangedAck:
handler.OnBlockChangeAck(dataTypes.ReadNextVarInt(packetData));
@ -4175,7 +4244,7 @@ namespace MinecraftClient.Protocol.Handlers
}
}
public bool SendAnimation(int animation, int playerid)
public bool SendAnimation(int animation, int playerId)
{
try
{
@ -4186,7 +4255,7 @@ namespace MinecraftClient.Protocol.Handlers
switch (protocolVersion)
{
case < MC_1_8_Version:
packet.AddRange(DataTypes.GetInt(playerid));
packet.AddRange(DataTypes.GetInt(playerId));
packet.Add(1); // Swing arm
break;
case < MC_1_9_Version:
@ -4423,11 +4492,9 @@ namespace MinecraftClient.Protocol.Handlers
return false;
}
}
else
{
return false;
}
}
public bool SendRenameItem(string itemName)
{

View file

@ -430,22 +430,25 @@ namespace MinecraftClient.Protocol
void OnEntityEffect(int entityid, Effects effect, int amplifier, int duration, byte flags, bool hasFactorData, Dictionary<String, object>? factorCodec);
/// <summary>
/// Called when coreboardObjective
/// Called when Soreboard Objective
/// </summary>
/// <param name="objectivename">objective name</param>
/// <param name="objectiveName">objective name</param>
/// <param name="mode">0 to create the scoreboard. 1 to remove the scoreboard. 2 to update the display text.</param>
/// <param name="objectivevalue">Only if mode is 0 or 2. The text to be displayed for the score</param>
/// <param name="objectiveValue">Only if mode is 0 or 2. The text to be displayed for the score</param>
/// <param name="type">Only if mode is 0 or 2. 0 = "integer", 1 = "hearts".</param>
void OnScoreboardObjective(string objectivename, byte mode, string objectivevalue, int type);
/// <param name="numberFormat">Number format: 0 - blank, 1 - styled, 2 - fixed</param>
void OnScoreboardObjective(string objectiveName, byte mode, string objectiveValue, int type, int numberFormat);
/// <summary>
/// Called when DisplayScoreboard
/// </summary>
/// <param name="entityname">The entity whose score this is. For players, this is their username; for other entities, it is their UUID.</param>
/// <param name="entityName">The entity whose score this is. For players, this is their username; for other entities, it is their UUID.</param>
/// <param name="action">0 to create/update an item. 1 to remove an item.</param>
/// <param name="objectivename">The name of the objective the score belongs to</param>
/// <param name="value">he score to be displayed next to the entry. Only sent when Action does not equal 1.</param>
void OnUpdateScore(string entityname, int action, string objectivename, int value);
/// <param name="objectiveName">The name of the objective the score belongs to</param>
/// <param name="objectiveDisplayName">The name of the objective the score belongs to, but with chat formatting</param>
/// <param name="objectiveValue">The score to be displayed next to the entry. Only sent when Action does not equal 1.</param>
/// <param name="numberFormat">Number format: 0 - blank, 1 - styled, 2 - fixed</param>
void OnUpdateScore(string entityName, int action, string objectiveName, string objectiveDisplayName, int objectiveValue, int numberFormat);
/// <summary>
/// Called when the client received the Tab Header and Footer

View file

@ -12,7 +12,6 @@ using MinecraftClient.Protocol.Handlers;
using MinecraftClient.Protocol.Handlers.Forge;
using MinecraftClient.Protocol.Session;
using MinecraftClient.Proxy;
using static MinecraftClient.Protocol.Microsoft;
using static MinecraftClient.Settings;
using static MinecraftClient.Settings.MainConfigHealper.MainConfig.GeneralConfig;
@ -48,7 +47,8 @@ namespace MinecraftClient.Protocol
{
ConsoleIO.WriteLine(string.Format(Translations.mcc_resolve, domainVal));
var lookupClient = new LookupClient();
var response = lookupClient.Query(new DnsQuestion($"_minecraft._tcp.{domainVal}", QueryType.SRV));
var response =
lookupClient.Query(new DnsQuestion($"_minecraft._tcp.{domainVal}", QueryType.SRV));
if (response.HasError != true && response.Answers.SrvRecords().Any())
{
//Order SRV records by priority and weight, then randomly
@ -58,7 +58,8 @@ namespace MinecraftClient.Protocol
.ThenBy(record => Guid.NewGuid())
.First();
string target = result.Target.Value.Trim('.');
ConsoleIO.WriteLineFormatted("§8" + string.Format(Translations.mcc_found, target, result.Port, domainVal));
ConsoleIO.WriteLineFormatted("§8" + string.Format(Translations.mcc_found, target,
result.Port, domainVal));
domainVal = target;
portVal = result.Port;
foundService = true;
@ -66,9 +67,14 @@ namespace MinecraftClient.Protocol
}
catch (Exception e)
{
ConsoleIO.WriteLineFormatted("§8" + string.Format(Translations.mcc_not_found, domainVal, e.GetType().FullName, e.Message));
ConsoleIO.WriteLineFormatted("§8" + string.Format(Translations.mcc_not_found, domainVal,
e.GetType().FullName, e.Message));
}
}, TimeSpan.FromSeconds(Config.Main.Advanced.ResolveSrvRecords == MainConfigHealper.MainConfig.AdvancedConfig.ResolveSrvRecordType.fast ? 10 : 30));
},
TimeSpan.FromSeconds(Config.Main.Advanced.ResolveSrvRecords ==
MainConfigHealper.MainConfig.AdvancedConfig.ResolveSrvRecordType.fast
? 10
: 30));
}
domain = domainVal;
@ -83,7 +89,8 @@ namespace MinecraftClient.Protocol
/// <param name="serverPort">Server Port to ping</param>
/// <param name="protocolversion">Will contain protocol version, if ping successful</param>
/// <returns>TRUE if ping was successful</returns>
public static bool GetServerInfo(string serverIP, ushort serverPort, ref int protocolversion, ref ForgeInfo? forgeInfo)
public static bool GetServerInfo(string serverIP, ushort serverPort, ref int protocolversion,
ref ForgeInfo? forgeInfo)
{
bool success = false;
int protocolversionTmp = 0;
@ -98,13 +105,18 @@ namespace MinecraftClient.Protocol
success = true;
}
else
ConsoleIO.WriteLineFormatted("§8" + Translations.error_unexpect_response, acceptnewlines: true);
ConsoleIO.WriteLineFormatted("§8" + Translations.error_unexpect_response,
acceptnewlines: true);
}
catch (Exception e)
{
ConsoleIO.WriteLineFormatted(String.Format("§8{0}: {1}", e.GetType().FullName, e.Message));
ConsoleIO.WriteLineFormatted(string.Format("§8{0}: {1}", e.GetType().FullName, e.Message));
}
}, TimeSpan.FromSeconds(Config.Main.Advanced.ResolveSrvRecords == MainConfigHealper.MainConfig.AdvancedConfig.ResolveSrvRecordType.fast ? 10 : 30)))
},
TimeSpan.FromSeconds(Config.Main.Advanced.ResolveSrvRecords ==
MainConfigHealper.MainConfig.AdvancedConfig.ResolveSrvRecordType.fast
? 10
: 30)))
{
if (protocolversion != 0 && protocolversion != protocolversionTmp)
ConsoleIO.WriteLineFormatted("§8" + Translations.error_version_different, acceptnewlines: true);
@ -125,23 +137,29 @@ namespace MinecraftClient.Protocol
/// <summary>
/// Get a protocol handler for the specified Minecraft version
/// </summary>
/// <param name="Client">Tcp Client connected to the server</param>
/// <param name="ProtocolVersion">Protocol version to handle</param>
/// <param name="Handler">Handler with the appropriate callbacks</param>
/// <param name="client">Tcp Client connected to the server</param>
/// <param name="protocolVersion">Protocol version to handle</param>
/// <param name="forgeInfo">Forge info</param>
/// <param name="handler">Handler with the appropriate callbacks</param>
/// <returns></returns>
public static IMinecraftCom GetProtocolHandler(TcpClient Client, int ProtocolVersion, ForgeInfo? forgeInfo, IMinecraftComHandler Handler)
public static IMinecraftCom GetProtocolHandler(TcpClient client, int protocolVersion, ForgeInfo? forgeInfo,
IMinecraftComHandler handler)
{
int[] supportedVersions_Protocol16 = { 51, 60, 61, 72, 73, 74, 78 };
int[] suppoertedVersionsProtocol16 = { 51, 60, 61, 72, 73, 74, 78 };
if (Array.IndexOf(supportedVersions_Protocol16, ProtocolVersion) > -1)
return new Protocol16Handler(Client, ProtocolVersion, Handler);
if (Array.IndexOf(suppoertedVersionsProtocol16, 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, 760, 761, 762, 763, 764};
int[] suppoertedVersionsProtocol18 =
{
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, 761, 762, 763, 764, 765
};
if (Array.IndexOf(supportedVersions_Protocol18, ProtocolVersion) > -1)
return new Protocol18Handler(Client, ProtocolVersion, Handler, forgeInfo);
if (Array.IndexOf(suppoertedVersionsProtocol18, protocolVersion) > -1)
return new Protocol18Handler(client, protocolVersion, handler, forgeInfo);
throw new NotSupportedException(string.Format(Translations.exception_version_unsupport, ProtocolVersion));
throw new NotSupportedException(string.Format(Translations.exception_version_unsupport, protocolVersion));
}
/// <summary>
@ -149,11 +167,11 @@ namespace MinecraftClient.Protocol
/// </summary>
/// <param name="MCVersion">The Minecraft version number</param>
/// <returns>The protocol version number or 0 if could not determine protocol version: error, unknown, not supported</returns>
public static int MCVer2ProtocolVersion(string MCVersion)
public static int MCVer2ProtocolVersion(string mcVersion)
{
if (MCVersion.Contains('.'))
if (mcVersion.Contains('.'))
{
switch (MCVersion.Split(' ')[0].Trim())
switch (mcVersion.Split(' ')[0].Trim())
{
case "1.0":
case "1.0.0":
@ -324,22 +342,23 @@ namespace MinecraftClient.Protocol
return 763;
case "1.20.2":
return 764;
case "1.20.3":
case "1.20.4":
return 765;
default:
return 0;
}
}
else
{
try
{
return int.Parse(MCVersion, NumberStyles.Any, CultureInfo.CurrentCulture);
return int.Parse(mcVersion, NumberStyles.Any, CultureInfo.CurrentCulture);
}
catch
{
return 0;
}
}
}
/// <summary>
/// Convert a network protocol version number to human-readable Minecraft version number
@ -404,6 +423,7 @@ namespace MinecraftClient.Protocol
762 => "1.19.4",
763 => "1.20",
764 => "1.20.2",
765 => "1.20.4",
_ => "0.0"
};
}
@ -411,7 +431,7 @@ namespace MinecraftClient.Protocol
/// <summary>
/// Check if we can force-enable Forge support for a Minecraft version without using server Ping
/// </summary>
/// <param name="protocolVersion">Minecraft protocol version</param>
/// <param name="protocol">Minecraft protocol version</param>
/// <returns>TRUE if we can force-enable Forge support without using server Ping</returns>
public static bool ProtocolMayForceForge(int protocol)
{
@ -421,15 +441,35 @@ namespace MinecraftClient.Protocol
/// <summary>
/// Server Info: Consider Forge to be enabled regardless of server Ping
/// </summary>
/// <param name="protocolVersion">Minecraft protocol version</param>
/// <param name="protocol">Minecraft protocol version</param>
/// <returns>ForgeInfo item stating that Forge is enabled</returns>
public static ForgeInfo ProtocolForceForge(int protocol)
{
return Protocol18Forge.ServerForceForge(protocol);
}
public enum LoginResult { OtherError, ServiceUnavailable, SSLError, Success, WrongPassword, AccountMigrated, NotPremium, LoginRequired, InvalidToken, InvalidResponse, NullError, UserCancel, WrongSelection };
public enum AccountType { Mojang, Microsoft };
public enum LoginResult
{
OtherError,
ServiceUnavailable,
SSLError,
Success,
WrongPassword,
AccountMigrated,
NotPremium,
LoginRequired,
InvalidToken,
InvalidResponse,
NullError,
UserCancel,
WrongSelection
};
public enum AccountType
{
Mojang,
Microsoft
};
/// <summary>
/// Allows to login to a premium Minecraft account using the Yggdrasil authentication scheme.
@ -455,7 +495,9 @@ namespace MinecraftClient.Protocol
{
return YggdrasiLogin(user, pass, out session);
}
else throw new InvalidOperationException("Account type must be Mojang or Microsoft or valid authlib 3rd Servers!");
else
throw new InvalidOperationException(
"Account type must be Mojang or Microsoft or valid authlib 3rd Servers!");
}
/// <summary>
@ -472,7 +514,9 @@ namespace MinecraftClient.Protocol
try
{
string result = "";
string json_request = "{\"agent\": { \"name\": \"Minecraft\", \"version\": 1 }, \"username\": \"" + JsonEncode(user) + "\", \"password\": \"" + JsonEncode(pass) + "\", \"clientToken\": \"" + JsonEncode(session.ClientID) + "\" }";
string json_request = "{\"agent\": { \"name\": \"Minecraft\", \"version\": 1 }, \"username\": \"" +
JsonEncode(user) + "\", \"password\": \"" + JsonEncode(pass) +
"\", \"clientToken\": \"" + JsonEncode(session.ClientID) + "\" }";
int code = DoHTTPSPost("authserver.mojang.com", 443, "/authenticate", json_request, ref result);
if (code == 200)
{
@ -490,7 +534,8 @@ namespace MinecraftClient.Protocol
{
session.ID = loginResponse.Properties["accessToken"].StringValue;
session.PlayerID = loginResponse.Properties["selectedProfile"].Properties["id"].StringValue;
session.PlayerName = loginResponse.Properties["selectedProfile"].Properties["name"].StringValue;
session.PlayerName = loginResponse.Properties["selectedProfile"].Properties["name"]
.StringValue;
return LoginResult.Success;
}
else return LoginResult.InvalidResponse;
@ -520,6 +565,7 @@ namespace MinecraftClient.Protocol
{
ConsoleIO.WriteLineFormatted("§8" + e.ToString());
}
return LoginResult.SSLError;
}
catch (System.IO.IOException e)
@ -528,6 +574,7 @@ namespace MinecraftClient.Protocol
{
ConsoleIO.WriteLineFormatted("§8" + e.ToString());
}
if (e.Message.Contains("authentication"))
{
return LoginResult.SSLError;
@ -540,9 +587,11 @@ namespace MinecraftClient.Protocol
{
ConsoleIO.WriteLineFormatted("§8" + e.ToString());
}
return LoginResult.OtherError;
}
}
private static LoginResult YggdrasiLogin(string user, string pass, out SessionToken session)
{
session = new SessionToken() { ClientID = Guid.NewGuid().ToString().Replace("-", "") };
@ -550,8 +599,11 @@ namespace MinecraftClient.Protocol
try
{
string result = "";
string json_request = "{\"agent\": { \"name\": \"Minecraft\", \"version\": 1 }, \"username\": \"" + JsonEncode(user) + "\", \"password\": \"" + JsonEncode(pass) + "\", \"clientToken\": \"" + JsonEncode(session.ClientID) + "\" }";
int code = DoHTTPSPost(Config.Main.General.AuthServer.Host,Config.Main.General.AuthServer.Port, "/api/yggdrasil/authserver/authenticate", json_request, ref result);
string json_request = "{\"agent\": { \"name\": \"Minecraft\", \"version\": 1 }, \"username\": \"" +
JsonEncode(user) + "\", \"password\": \"" + JsonEncode(pass) +
"\", \"clientToken\": \"" + JsonEncode(session.ClientID) + "\" }";
int code = DoHTTPSPost(Config.Main.General.AuthServer.Host, Config.Main.General.AuthServer.Port,
"/api/yggdrasil/authserver/authenticate", json_request, ref result);
if (code == 200)
{
if (result.Contains("availableProfiles\":[]}"))
@ -568,26 +620,33 @@ namespace MinecraftClient.Protocol
&& loginResponse.Properties["selectedProfile"].Properties.ContainsKey("id")
&& loginResponse.Properties["selectedProfile"].Properties.ContainsKey("name"))
{
session.PlayerID = loginResponse.Properties["selectedProfile"].Properties["id"].StringValue;
session.PlayerName = loginResponse.Properties["selectedProfile"].Properties["name"].StringValue;
session.PlayerID = loginResponse.Properties["selectedProfile"].Properties["id"]
.StringValue;
session.PlayerName = loginResponse.Properties["selectedProfile"].Properties["name"]
.StringValue;
return LoginResult.Success;
}
else
{
string availableProfiles = "";
foreach (Json.JSONData profile in loginResponse.Properties["availableProfiles"].DataArray)
foreach (Json.JSONData profile in loginResponse.Properties["availableProfiles"]
.DataArray)
{
availableProfiles += " " + profile.Properties["name"].StringValue;
}
ConsoleIO.WriteLine(Translations.mcc_avaliable_profiles + availableProfiles);
ConsoleIO.WriteLine(Translations.mcc_select_profile);
string selectedProfileName = ConsoleIO.ReadLine();
ConsoleIO.WriteLine(Translations.mcc_selected_profile + " " + selectedProfileName);
Json.JSONData? selectedProfile = null;
foreach (Json.JSONData profile in loginResponse.Properties["availableProfiles"].DataArray)
foreach (Json.JSONData profile in loginResponse.Properties["availableProfiles"]
.DataArray)
{
selectedProfile = profile.Properties["name"].StringValue == selectedProfileName ? profile : selectedProfile;
selectedProfile = profile.Properties["name"].StringValue == selectedProfileName
? profile
: selectedProfile;
}
if (selectedProfile != null)
@ -630,6 +689,7 @@ namespace MinecraftClient.Protocol
{
ConsoleIO.WriteLineFormatted("§8" + e.ToString());
}
return LoginResult.SSLError;
}
catch (System.IO.IOException e)
@ -638,6 +698,7 @@ namespace MinecraftClient.Protocol
{
ConsoleIO.WriteLineFormatted("§8" + e.ToString());
}
if (e.Message.Contains("authentication"))
{
return LoginResult.SSLError;
@ -650,9 +711,11 @@ namespace MinecraftClient.Protocol
{
ConsoleIO.WriteLineFormatted("§8" + e.ToString());
}
return LoginResult.OtherError;
}
}
/// <summary>
/// Sign-in to Microsoft Account without using browser. Only works if 2FA is disabled.
/// Might not work well in some rare cases.
@ -678,6 +741,7 @@ namespace MinecraftClient.Protocol
{
ConsoleIO.WriteLineFormatted("§c" + e.StackTrace);
}
return LoginResult.WrongPassword; // Might not always be wrong password
}
}
@ -748,6 +812,7 @@ namespace MinecraftClient.Protocol
{
ConsoleIO.WriteLineFormatted("§c" + e.StackTrace);
}
return LoginResult.WrongPassword; // Might not always be wrong password
}
}
@ -761,13 +826,15 @@ namespace MinecraftClient.Protocol
{
var payload = JwtPayloadDecode.GetPayload(session.ID);
var json = Json.ParseJson(payload);
var expTimestamp = long.Parse(json.Properties["exp"].StringValue, NumberStyles.Any, CultureInfo.CurrentCulture);
var expTimestamp = long.Parse(json.Properties["exp"].StringValue, NumberStyles.Any,
CultureInfo.CurrentCulture);
var now = DateTime.Now;
var tokenExp = UnixTimeStampToDateTime(expTimestamp);
if (Settings.Config.Logging.DebugMessages)
{
ConsoleIO.WriteLine("Access token expiration time is " + tokenExp.ToString());
}
if (now < tokenExp)
{
// Still valid
@ -792,7 +859,10 @@ namespace MinecraftClient.Protocol
try
{
string result = "";
string json_request = "{ \"accessToken\": \"" + JsonEncode(currentsession.ID) + "\", \"clientToken\": \"" + JsonEncode(currentsession.ClientID) + "\", \"selectedProfile\": { \"id\": \"" + JsonEncode(currentsession.PlayerID) + "\", \"name\": \"" + JsonEncode(currentsession.PlayerName) + "\" } }";
string json_request = "{ \"accessToken\": \"" + JsonEncode(currentsession.ID) +
"\", \"clientToken\": \"" + JsonEncode(currentsession.ClientID) +
"\", \"selectedProfile\": { \"id\": \"" + JsonEncode(currentsession.PlayerID) +
"\", \"name\": \"" + JsonEncode(currentsession.PlayerName) + "\" } }";
int code = DoHTTPSPost("authserver.mojang.com", 443, "/refresh", json_request, ref result);
if (code == 200)
{
@ -810,7 +880,8 @@ namespace MinecraftClient.Protocol
{
session.ID = loginResponse.Properties["accessToken"].StringValue;
session.PlayerID = loginResponse.Properties["selectedProfile"].Properties["id"].StringValue;
session.PlayerName = loginResponse.Properties["selectedProfile"].Properties["name"].StringValue;
session.PlayerName = loginResponse.Properties["selectedProfile"].Properties["name"]
.StringValue;
return LoginResult.Success;
}
else return LoginResult.InvalidResponse;
@ -838,8 +909,12 @@ namespace MinecraftClient.Protocol
try
{
string result = "";
string json_request = "{ \"accessToken\": \"" + JsonEncode(currentsession.ID) + "\", \"clientToken\": \"" + JsonEncode(currentsession.ClientID) + "\", \"selectedProfile\": { \"id\": \"" + JsonEncode(currentsession.PlayerID) + "\", \"name\": \"" + JsonEncode(currentsession.PlayerName) + "\" } }";
int code = DoHTTPSPost(Config.Main.General.AuthServer.Host, Config.Main.General.AuthServer.Port, "/api/yggdrasil/authserver/refresh", json_request, ref result);
string json_request = "{ \"accessToken\": \"" + JsonEncode(currentsession.ID) +
"\", \"clientToken\": \"" + JsonEncode(currentsession.ClientID) +
"\", \"selectedProfile\": { \"id\": \"" + JsonEncode(currentsession.PlayerID) +
"\", \"name\": \"" + JsonEncode(currentsession.PlayerName) + "\" } }";
int code = DoHTTPSPost(Config.Main.General.AuthServer.Host, Config.Main.General.AuthServer.Port,
"/api/yggdrasil/authserver/refresh", json_request, ref result);
if (code == 200)
{
if (result == null)
@ -856,7 +931,8 @@ namespace MinecraftClient.Protocol
{
session.ID = loginResponse.Properties["accessToken"].StringValue;
session.PlayerID = loginResponse.Properties["selectedProfile"].Properties["id"].StringValue;
session.PlayerName = loginResponse.Properties["selectedProfile"].Properties["name"].StringValue;
session.PlayerName = loginResponse.Properties["selectedProfile"].Properties["name"]
.StringValue;
return LoginResult.Success;
}
else return LoginResult.InvalidResponse;
@ -891,15 +967,23 @@ namespace MinecraftClient.Protocol
try
{
string result = "";
string json_request = "{\"accessToken\":\"" + accesstoken + "\",\"selectedProfile\":\"" + uuid + "\",\"serverId\":\"" + serverhash + "\"}";
string host = type == LoginType.yggdrasil ? Config.Main.General.AuthServer.Host : "sessionserver.mojang.com";
string json_request = "{\"accessToken\":\"" + accesstoken + "\",\"selectedProfile\":\"" + uuid +
"\",\"serverId\":\"" + serverhash + "\"}";
string host = type == LoginType.yggdrasil
? Config.Main.General.AuthServer.Host
: "sessionserver.mojang.com";
int port = type == LoginType.yggdrasil ? Config.Main.General.AuthServer.Port : 443;
string endpoint = type == LoginType.yggdrasil ? "/api/yggdrasil/sessionserver/session/minecraft/join" : "/session/minecraft/join";
string endpoint = type == LoginType.yggdrasil
? "/api/yggdrasil/sessionserver/session/minecraft/join"
: "/session/minecraft/join";
int code = DoHTTPSPost(host, port, endpoint, json_request, ref result);
return (code >= 200 && code < 300);
}
catch { return false; }
catch
{
return false;
}
}
/// <summary>
@ -915,7 +999,8 @@ namespace MinecraftClient.Protocol
try
{
string result = "";
string cookies = String.Format("sid=token:{0}:{1};user={2};version={3}", accesstoken, uuid, username, Program.MCHighestVersion);
string cookies = String.Format("sid=token:{0}:{1};user={2};version={3}", accesstoken, uuid, username,
Program.MCHighestVersion);
DoHTTPSGet("pc.realms.minecraft.net", 443, "/worlds", cookies, ref result);
Json.JSONData realmsWorlds = Json.ParseJson(result);
if (realmsWorlds.Properties.ContainsKey("servers")
@ -942,6 +1027,7 @@ namespace MinecraftClient.Protocol
}
}
}
if (availableWorlds.Count > 0)
{
ConsoleIO.WriteLine(Translations.mcc_realms_available);
@ -950,7 +1036,6 @@ namespace MinecraftClient.Protocol
ConsoleIO.WriteLine(Translations.mcc_realms_join);
}
}
}
catch (Exception e)
{
@ -960,6 +1045,7 @@ namespace MinecraftClient.Protocol
ConsoleIO.WriteLineFormatted("§8" + e.StackTrace);
}
}
return realmsWorldsResult;
}
@ -971,13 +1057,16 @@ namespace MinecraftClient.Protocol
/// <param name="uuid">Player UUID</param>
/// <param name="accesstoken">Access token</param>
/// <returns>Server address (host:port) or empty string if failure</returns>
public static string GetRealmsWorldServerAddress(string worldId, string username, string uuid, string accesstoken)
public static string GetRealmsWorldServerAddress(string worldId, string username, string uuid,
string accesstoken)
{
try
{
string result = "";
string cookies = String.Format("sid=token:{0}:{1};user={2};version={3}", accesstoken, uuid, username, Program.MCHighestVersion);
int statusCode = DoHTTPSGet("pc.realms.minecraft.net",443, "/worlds/v1/" + worldId + "/join/pc", cookies, ref result);
string cookies = String.Format("sid=token:{0}:{1};user={2};version={3}", accesstoken, uuid, username,
Program.MCHighestVersion);
int statusCode = DoHTTPSGet("pc.realms.minecraft.net", 443, "/worlds/v1/" + worldId + "/join/pc",
cookies, ref result);
if (statusCode == 200)
{
Json.JSONData serverAddress = Json.ParseJson(result);
@ -1002,6 +1091,7 @@ namespace MinecraftClient.Protocol
{
ConsoleIO.WriteLineFormatted("§8" + e.StackTrace);
}
return "";
}
}
@ -1078,7 +1168,8 @@ namespace MinecraftClient.Protocol
TcpClient client = ProxyHandler.NewTcpClient(host, port, true);
SslStream stream = new(client.GetStream());
stream.AuthenticateAsClient(host, null, SslProtocols.Tls12, true); // Enable TLS 1.2. Hotfix for #1780
stream.AuthenticateAsClient(host, null, SslProtocols.Tls12,
true); // Enable TLS 1.2. Hotfix for #1780
if (Settings.Config.Logging.DebugMessages)
foreach (string line in headers)

View file

@ -332,20 +332,23 @@ namespace MinecraftClient.Scripting
/// <summary>
/// Called when a scoreboard objective updated
/// </summary>
/// <param name="objectivename">objective name</param>
/// <param name="objectiveName">objective name</param>
/// <param name="mode">0 to create the scoreboard. 1 to remove the scoreboard. 2 to update the display text.</param>
/// <param name="objectivevalue">Only if mode is 0 or 2. The text to be displayed for the score</param>
/// <param name="objectiveValue">Only if mode is 0 or 2. The text to be displayed for the score</param>
/// <param name="type">Only if mode is 0 or 2. 0 = "integer", 1 = "hearts".</param>
public virtual void OnScoreboardObjective(string objectivename, byte mode, string objectivevalue, int type, string json) { }
/// <param name="numberFormat">Number format: 0 - blank, 1 - styled, 2 - fixed</param>
public virtual void OnScoreboardObjective(string objectiveName, byte mode, string objectiveValue, int type, string json, int numberFormat) { }
/// <summary>
/// Called when a scoreboard updated
/// </summary>
/// <param name="entityname">The entity whose score this is. For players, this is their username; for other entities, it is their UUID.</param>
/// <param name="entityName">The entity whose score this is. For players, this is their username; for other entities, it is their UUID.</param>
/// <param name="action">0 to create/update an item. 1 to remove an item.</param>
/// <param name="objectivename">The name of the objective the score belongs to</param>
/// <param name="objectiveName">The name of the objective the score belongs to</param>
/// <param name="objectiveDisplayName">The name of the objective the score belongs to, but with chat formatting</param>
/// <param name="value">The score to be displayed next to the entry. Only sent when Action does not equal 1.</param>
public virtual void OnUpdateScore(string entityname, int action, string objectivename, int value) { }
/// <param name="numberFormat">Number format: 0 - blank, 1 - styled, 2 - fixed</param>
public virtual void OnUpdateScore(string entityName, int action, string objectiveName, string objectiveDisplayName, int value, int numberFormat) { }
/// <summary>
/// Called when the client received the Tab Header and Footer