feat: extend packet send and receive events
This commit is contained in:
parent
376001dbd4
commit
c17e7124d8
@ -34,6 +34,10 @@ pub fn build() -> String {
|
|||||||
&mut clientbound_variant,
|
&mut clientbound_variant,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Add an 'unknown' fallback variant (no payload) — raw payload is carried on the event record
|
||||||
|
serverbound_variant.case(VariantCase::empty("unknown"));
|
||||||
|
clientbound_variant.case(VariantCase::empty("unknown"));
|
||||||
|
|
||||||
interface.type_def(TypeDef::new(
|
interface.type_def(TypeDef::new(
|
||||||
"serverbound-packet",
|
"serverbound-packet",
|
||||||
TypeDefKind::Variant(serverbound_variant),
|
TypeDefKind::Variant(serverbound_variant),
|
||||||
|
|||||||
@ -35,6 +35,10 @@ pub fn build() -> String {
|
|||||||
&mut clientbound_variant,
|
&mut clientbound_variant,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Add an 'unknown' fallback variant (no payload) — raw payload is carried on the event record
|
||||||
|
serverbound_variant.case(VariantCase::empty("unknown"));
|
||||||
|
clientbound_variant.case(VariantCase::empty("unknown"));
|
||||||
|
|
||||||
interface.type_def(TypeDef::new(
|
interface.type_def(TypeDef::new(
|
||||||
"serverbound-packet",
|
"serverbound-packet",
|
||||||
TypeDefKind::Variant(serverbound_variant),
|
TypeDefKind::Variant(serverbound_variant),
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
Subproject commit 6e8b554b38803b0b6f76f39a88fded7a49d72908
|
Subproject commit 40ae442280098742f84dd5e2427729bb07057f1a
|
||||||
@ -30,27 +30,27 @@ impl ToFromWasmEvent for PacketReceivedEvent {
|
|||||||
let packet = match &self.player.client {
|
let packet = match &self.player.client {
|
||||||
ClientPlatform::Java(client) => {
|
ClientPlatform::Java(client) => {
|
||||||
let version = client.version.load();
|
let version = client.version.load();
|
||||||
let wit_packet = generated_packets::deserialize_java_serverbound_packet(
|
generated_packets::deserialize_java_serverbound_packet(
|
||||||
self.packet_id,
|
self.packet_id,
|
||||||
&self.payload,
|
&self.payload,
|
||||||
version,
|
version,
|
||||||
);
|
)
|
||||||
wit_packet.map(ServerboundPacket::Java)
|
.map_or(ServerboundPacket::Unknown, ServerboundPacket::Java)
|
||||||
}
|
}
|
||||||
ClientPlatform::Bedrock(_) => {
|
ClientPlatform::Bedrock(_) => {
|
||||||
let wit_packet = generated_packets::deserialize_bedrock_serverbound_packet(
|
generated_packets::deserialize_bedrock_serverbound_packet(
|
||||||
self.packet_id,
|
self.packet_id,
|
||||||
&self.payload,
|
&self.payload,
|
||||||
);
|
)
|
||||||
wit_packet.map(ServerboundPacket::Bedrock)
|
.map_or(ServerboundPacket::Unknown, ServerboundPacket::Bedrock)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let packet = packet.expect("Failed to deserialize serverbound packet to WIT. Ensure the packet is supported in the WIT API.");
|
|
||||||
|
|
||||||
Event::PacketReceivedEvent(PacketReceivedEventData {
|
Event::PacketReceivedEvent(PacketReceivedEventData {
|
||||||
player: player_res,
|
player: player_res,
|
||||||
packet,
|
packet,
|
||||||
|
packet_id: self.packet_id,
|
||||||
|
raw_payload: self.payload.to_vec(),
|
||||||
cancelled: self.cancelled,
|
cancelled: self.cancelled,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -77,22 +77,20 @@ impl ToFromWasmEvent for PacketSentEvent {
|
|||||||
|
|
||||||
let packet = match &self.player.client {
|
let packet = match &self.player.client {
|
||||||
ClientPlatform::Java(_) => {
|
ClientPlatform::Java(_) => {
|
||||||
let wit_packet =
|
generated_packets::clientbound_java_any_to_wit(self.packet.as_ref())
|
||||||
generated_packets::clientbound_java_any_to_wit(self.packet.as_ref());
|
.map_or(ClientboundPacket::Unknown, ClientboundPacket::Java)
|
||||||
wit_packet.map(ClientboundPacket::Java)
|
|
||||||
}
|
}
|
||||||
ClientPlatform::Bedrock(_) => {
|
ClientPlatform::Bedrock(_) => {
|
||||||
let wit_packet =
|
generated_packets::clientbound_bedrock_any_to_wit(self.packet.as_ref())
|
||||||
generated_packets::clientbound_bedrock_any_to_wit(self.packet.as_ref());
|
.map_or(ClientboundPacket::Unknown, ClientboundPacket::Bedrock)
|
||||||
wit_packet.map(ClientboundPacket::Bedrock)
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let packet = packet.expect("Failed to convert clientbound packet to WIT. Ensure the packet is supported in the WIT API and ToWit is generated.");
|
|
||||||
|
|
||||||
Event::PacketSentEvent(PacketSentEventData {
|
Event::PacketSentEvent(PacketSentEventData {
|
||||||
player: player_res,
|
player: player_res,
|
||||||
packet,
|
packet,
|
||||||
|
packet_id: self.packet_id,
|
||||||
|
raw_payload: self.payload.iter().copied().collect(),
|
||||||
cancelled: self.cancelled,
|
cancelled: self.cancelled,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user