Implement player info update packet
All checks were successful
Build & Test / nix-build (push) Successful in 3m10s
Build & Test / nix-build (pull_request) Successful in 3m10s

This commit is contained in:
Kodi Craft 2024-10-01 08:21:30 +02:00
parent f0c2ef80ec
commit c880ea95f3
Signed by: kodi
GPG Key ID: 69D9EED60B242822
2 changed files with 59 additions and 1 deletions

View File

@ -95,6 +95,7 @@ defmodule Amethyst.ConnectionState.Macros do
Enum.reduce(Map.get(packet, name), "", fn item, acc ->
acc <> write_signature(item, signature)
end)
{:literal, {type, value}} -> acc <> apply(Write, type, [value])
t -> acc <> apply(Write, t, [Map.get(packet, name)])
end
end)
@ -104,7 +105,12 @@ defmodule Amethyst.ConnectionState.Macros do
try do
Enum.all?(signature, fn {name, type} ->
case Map.get(packet, name, :missing) do
:missing -> throw {:missing, name}
:missing ->
if elem(type, 0) == :literal do
true
else
throw {:missing, name}
end
value -> case type_matches(value, type) do
true -> true
false -> throw {:mismatch, name, value, type}

View File

@ -71,6 +71,58 @@ defmodule Amethyst.ConnectionState.Play do
portal_cooldown: :varint,
enforces_secure_chat: :bool,
]
Macros.defpacket_clientbound :player_info_update_add_player, 0x2E, 767, [
actions: {:literal, 0x01},
players: {:array, [
uuid: :uuid,
name: :string,
properties: {:array, [
name: :string,
value: :string,
signature: {:optional, :string},
]}
]}
]
Macros.defpacket_clientbound :player_info_update_initialize_chat, 0x2E, 767, [
actions: {:literal, 0x02},
players: {:array, [
uuid: :uuid,
data: {:optional, {:compound, [
chat_session_id: :uuid,
public_key_expiry_time: :long,
encoded_public_key: :byte_array,
public_key_signature: :byte_array
]}}
]}
]
Macros.defpacket_clientbound :player_info_update_update_game_mode, 0x2E, 767, [
actions: {:literal, 0x04},
players: {:array, [
uuid: :uuid,
gamemode: :varint
]}
]
Macros.defpacket_clientbound :player_info_update_update_listed, 0x2E, 767, [
actions: {:literal, 0x08},
players: {:array, [
uuid: :uuid,
listed: :bool
]}
]
Macros.defpacket_clientbound :player_info_update_update_latency, 0x2E, 767, [
actions: {:literal, 0x10},
players: {:array, [
uuid: :uuid,
ping: :varint, # Milliseconds
]}
]
Macros.defpacket_clientbound :player_info_update_update_display_name, 0x2E, 767, [
actions: {:literal, 0x20},
players: {:array, [
uuid: :uuid,
display_name: {:optional, :nbt}
]}
]
Macros.defpacket_clientbound :synchronize_player_position, 0x40, 767, [
x: :double,
y: :double,