Add Chat support

This commit is contained in:
Snowiiii committed 2024-08-08 11:27:09 +02:00
1 parent 1076cc69f0
commit fe8cd334e1
18 files changed
+171 -48

No files matched your search

-1
View File
@@ -84,7 +84,6 @@ pub fn unpack_textures(property: Property, config: &TextureConfig) {
// TODO: no unwrap
let from64 = general_purpose::STANDARD.decode(property.value).unwrap();
let textures: ProfileTextures = serde_json::from_slice(&from64).unwrap();
dbg!(&textures);
for texture in textures.textures {
is_texture_url_valid(Url::parse(&texture.1.url).unwrap(), config);
}
+3 -3
View File
@@ -11,7 +11,7 @@ use pumpkin_protocol::{
login::{SEncryptionResponse, SLoginAcknowledged, SLoginPluginResponse, SLoginStart},
status::{SPingRequest, SStatusRequest},
},
ConnectionState, KnownPack,
ConnectionState, KnownPack, RawBytes,
};
use pumpkin_registry::Registry;
use rsa::Pkcs1v15Encrypt;
@@ -64,8 +64,8 @@ impl Client {
let public_key_der = &server.public_key_der;
let packet = CEncryptionRequest::new(
"",
public_key_der,
&verify_token,
RawBytes(public_key_der),
RawBytes(&verify_token),
server.base_config.online_mode, // TODO
);
self.send_packet(packet);
+11 -5
View File
@@ -27,7 +27,7 @@ use pumpkin_protocol::{
handshake::SHandShake,
login::{SEncryptionResponse, SLoginAcknowledged, SLoginPluginResponse, SLoginStart},
play::{
SChatCommand, SConfirmTeleport, SPlayerCommand, SPlayerPosition,
SChatCommand, SChatMessage, SConfirmTeleport, SPlayerCommand, SPlayerPosition,
SPlayerPositionRotation, SPlayerRotation, SSwingArm,
},
status::{SPingRequest, SStatusRequest},
@@ -195,10 +195,13 @@ impl Client {
SLoginStart::PACKET_ID => {
self.handle_login_start(server, SLoginStart::read(bytebuf).unwrap())
}
SEncryptionResponse::PACKET_ID => self.handle_encryption_response(
server,
SEncryptionResponse::read(bytebuf).unwrap(),
).await,
SEncryptionResponse::PACKET_ID => {
self.handle_encryption_response(
server,
SEncryptionResponse::read(bytebuf).unwrap(),
)
.await
}
SLoginPluginResponse::PACKET_ID => self
.handle_plugin_response(server, SLoginPluginResponse::read(bytebuf).unwrap()),
SLoginAcknowledged::PACKET_ID => self
@@ -261,6 +264,9 @@ impl Client {
SSwingArm::PACKET_ID => {
self.handle_swing_arm(server, SSwingArm::read(bytebuf).unwrap())
}
SChatMessage::PACKET_ID => {
self.handle_chat_message(server, SChatMessage::read(bytebuf).unwrap())
}
_ => log::error!("Failed to handle player packet id {}", packet.id.0),
}
}
+46 -4
View File
@@ -1,13 +1,14 @@
use num_traits::FromPrimitive;
use pumpkin_protocol::{
client::play::{
Animation, CEntityAnimation, CHeadRot, CUpdateEntityPos, CUpdateEntityPosRot,
CUpdateEntityRot,
Animation, CEntityAnimation, CHeadRot, CSystemChatMessge, CUpdateEntityPos,
CUpdateEntityPosRot, CUpdateEntityRot,
},
server::play::{
SChatCommand, SConfirmTeleport, SPlayerCommand, SPlayerPosition, SPlayerPositionRotation,
SPlayerRotation, SSwingArm,
SChatCommand, SChatMessage, SConfirmTeleport, SPlayerCommand, SPlayerPosition,
SPlayerPositionRotation, SPlayerRotation, SSwingArm,
},
text::TextComponent,
};
use crate::{
@@ -171,4 +172,45 @@ impl Client {
let id = player.entity_id();
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) {
let message = chat_message.message;
// TODO: filter message & validation
let gameprofile = self.gameprofile.as_ref().unwrap();
dbg!("got message");
// yeah a "raw system message", the ugly way to do that, but it works
server.broadcast_packet(
self,
CSystemChatMessge::new(
TextComponent::from(format!("{}: {}", gameprofile.name, message)),
false,
),
)
/*server.broadcast_packet(
self,
CPlayerChatMessage::new(
gameprofile.id,
0.into(),
None,
message.clone(),
chat_message.timestamp,
chat_message.salt,
&[],
Some(TextComponent::from(message.clone())),
pumpkin_protocol::VarInt(FilterType::PassThrough as i32),
0.into(),
TextComponent::from(gameprofile.name.clone()),
None,
),
) */
/* server.broadcast_packet(
self,
CDisguisedChatMessage::new(
TextComponent::from(message.clone()),
VarInt(0),
gameprofile.name.clone().into(),
None,
),
) */
}
}