Avoid Packet cloning

This commit is contained in:
Snowiiii committed 2024-08-12 17:31:43 +02:00
1 parent d47fb18465
commit 2909cad081
19 files changed
+46 -48

No files matched your search

+9 -9
View File
@@ -40,12 +40,12 @@ impl Client {
}
pub fn handle_status_request(&mut self, server: &mut Server, _status_request: SStatusRequest) {
self.send_packet(CStatusResponse::new(&server.status_response_json));
self.send_packet(&CStatusResponse::new(&server.status_response_json));
}
pub fn handle_ping_request(&mut self, _server: &mut Server, ping_request: SPingRequest) {
dbg!("ping");
self.send_packet(CPingResponse::new(ping_request.payload));
self.send_packet(&CPingResponse::new(ping_request.payload));
self.close();
}
@@ -70,7 +70,7 @@ impl Client {
&verify_token,
server.base_config.online_mode, // TODO
);
self.send_packet(packet);
self.send_packet(&packet);
}
pub async fn handle_encryption_response(
@@ -144,13 +144,13 @@ impl Client {
.packet_compression
.compression_threshold;
let level = server.advanced_config.packet_compression.compression_level;
self.send_packet(CSetCompression::new(threshold.into()));
self.send_packet(&CSetCompression::new(threshold.into()));
self.set_compression(Some((threshold, level)));
}
if let Some(profile) = self.gameprofile.as_ref().cloned() {
let packet = CLoginSuccess::new(profile.id, &profile.name, &profile.properties, false);
self.send_packet(packet);
self.send_packet(&packet);
} else {
self.kick("game profile is none");
}
@@ -178,7 +178,7 @@ impl Client {
} else {
Some(TextComponent::from(resource_config.prompt_message.clone()))
};
self.send_packet(CConfigAddResourcePack::new(
self.send_packet(&CConfigAddResourcePack::new(
uuid::Uuid::from_str(&resource_config.resource_pack_url).unwrap(),
resource_config.resource_pack_url.clone(),
resource_config.resource_pack_sha1.clone(),
@@ -188,7 +188,7 @@ impl Client {
}
// known data packs
self.send_packet(CKnownPacks::new(&[KnownPack {
self.send_packet(&CKnownPacks::new(&[KnownPack {
namespace: "minecraft",
id: "core",
version: "1.21",
@@ -226,7 +226,7 @@ impl Client {
pub fn handle_known_packs(&mut self, server: &mut Server, _config_acknowledged: SKnownPacks) {
for registry in &server.cached_registry {
self.send_packet(CRegistryData::new(
self.send_packet(&CRegistryData::new(
&registry.registry_id,
&registry.registry_entries,
));
@@ -234,7 +234,7 @@ impl Client {
// We are done with configuring
dbg!("finish config");
self.send_packet(CFinishConfig::new());
self.send_packet(&CFinishConfig::new());
}
pub fn handle_config_acknowledged(
+8 -8
View File
@@ -122,7 +122,7 @@ impl Client {
}
/// Send a Clientbound Packet to the Client
pub fn send_packet<P: ClientPacket>(&mut self, packet: P) {
pub fn send_packet<P: ClientPacket>(&mut self, packet: &P) {
self.enc
.append_packet(packet)
.unwrap_or_else(|e| self.kick(&e.to_string()));
@@ -132,7 +132,7 @@ impl Client {
.unwrap_or_else(|e| self.kick(&e.to_string()));
}
pub fn try_send_packet<P: ClientPacket>(&mut self, packet: P) -> Result<(), PacketError> {
pub fn try_send_packet<P: ClientPacket>(&mut self, packet: &P) -> Result<(), PacketError> {
self.enc.append_packet(packet)?;
self.connection
.write_all(&self.enc.take())
@@ -155,11 +155,11 @@ impl Client {
entity.yaw = yaw;
entity.pitch = pitch;
player.awaiting_teleport = Some(id.into());
self.send_packet(CSyncPlayerPostion::new(x, y, z, yaw, pitch, 0, id.into()));
self.send_packet(&CSyncPlayerPostion::new(x, y, z, yaw, pitch, 0, id.into()));
}
pub fn set_gamemode(&mut self, gamemode: GameMode) {
self.send_packet(CGameEvent::new(3, gamemode.to_f32().unwrap()));
self.send_packet(&CGameEvent::new(3, gamemode.to_f32().unwrap()));
}
pub async fn process_packets(&mut self, server: &mut Server) {
@@ -323,7 +323,7 @@ impl Client {
}
pub fn send_system_message(&mut self, text: TextComponent) {
self.send_packet(CSystemChatMessge::new(text, false));
self.send_packet(&CSystemChatMessge::new(text, false));
}
/// Kicks the Client with a reason depending on the connection state
@@ -331,17 +331,17 @@ impl Client {
dbg!(reason);
match self.connection_state {
ConnectionState::Login => {
self.try_send_packet(CLoginDisconnect::new(
self.try_send_packet(&CLoginDisconnect::new(
&serde_json::to_string_pretty(&reason).unwrap(),
))
.unwrap_or_else(|_| self.close());
}
ConnectionState::Config => {
self.try_send_packet(CConfigDisconnect::new(reason))
self.try_send_packet(&CConfigDisconnect::new(reason))
.unwrap_or_else(|_| self.close());
}
ConnectionState::Play => {
self.try_send_packet(CPlayDisconnect::new(TextComponent::from(reason)))
self.try_send_packet(&CPlayDisconnect::new(TextComponent::from(reason)))
.unwrap_or_else(|_| self.close());
}
_ => {
+1 -1
View File
@@ -186,7 +186,7 @@ impl Client {
};
let player = self.player.as_mut().unwrap();
let id = player.entity_id();
server.broadcast_packet_expect(self, CEntityAnimation::new(id.into(), animation as u8))
server.broadcast_packet_expect(self, &CEntityAnimation::new(id.into(), animation as u8))
}
pub fn handle_chat_message(&mut self, server: &mut Server, chat_message: SChatMessage) {