Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
5d6c38d1b2
60 files changed
+1371
-344
No files matched your search
@@ -52,14 +52,16 @@ pub async fn authenticate(
|
||||
ip: &IpAddr,
|
||||
server: &mut Server,
|
||||
) -> Result<GameProfile, AuthError> {
|
||||
assert!(server.advanced_config.authentication.use_authentication);
|
||||
assert!(server.advanced_config.authentication.enabled);
|
||||
assert!(server.auth_client.is_some());
|
||||
let address = if server
|
||||
.advanced_config
|
||||
.authentication
|
||||
.prevent_proxy_connections
|
||||
{
|
||||
format!("https://sessionserver.mojang.com/session/minecraft/hasJoined?username={username}&serverId={server_hash}&ip={ip}")
|
||||
let test = format!("https://sessionserver.mojang.com/session/minecraft/hasJoined?username={username}&serverId={server_hash}&ip={ip}");
|
||||
dbg!(&test);
|
||||
test
|
||||
} else {
|
||||
format!("https://sessionserver.mojang.com/session/minecraft/hasJoined?username={username}&serverId={server_hash}")
|
||||
};
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use num_traits::FromPrimitive;
|
||||
use pumpkin_protocol::{
|
||||
client::{
|
||||
config::{CFinishConfig, CKnownPacks, CRegistryData},
|
||||
config::{CConfigAddResourcePack, CFinishConfig, CKnownPacks, CRegistryData},
|
||||
login::{CEncryptionRequest, CLoginSuccess, CSetCompression},
|
||||
status::{CPingResponse, CStatusResponse},
|
||||
},
|
||||
@@ -11,9 +13,9 @@ use pumpkin_protocol::{
|
||||
login::{SEncryptionResponse, SLoginAcknowledged, SLoginPluginResponse, SLoginStart},
|
||||
status::{SPingRequest, SStatusRequest},
|
||||
},
|
||||
ConnectionState, KnownPack, RawBytes,
|
||||
ConnectionState, KnownPack,
|
||||
};
|
||||
use pumpkin_registry::Registry;
|
||||
use pumpkin_text::TextComponent;
|
||||
use rsa::Pkcs1v15Encrypt;
|
||||
use sha1::{Digest, Sha1};
|
||||
|
||||
@@ -38,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();
|
||||
}
|
||||
|
||||
@@ -64,11 +66,11 @@ impl Client {
|
||||
let public_key_der = &server.public_key_der;
|
||||
let packet = CEncryptionRequest::new(
|
||||
"",
|
||||
RawBytes(public_key_der),
|
||||
RawBytes(&verify_token),
|
||||
public_key_der,
|
||||
&verify_token,
|
||||
server.base_config.online_mode, // TODO
|
||||
);
|
||||
self.send_packet(packet);
|
||||
self.send_packet(&packet);
|
||||
}
|
||||
|
||||
pub async fn handle_encryption_response(
|
||||
@@ -131,6 +133,7 @@ impl Client {
|
||||
}
|
||||
}
|
||||
for ele in self.gameprofile.as_ref().unwrap().properties.clone() {
|
||||
// todo, use this
|
||||
unpack_textures(ele, &server.advanced_config.authentication.textures);
|
||||
}
|
||||
|
||||
@@ -141,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);
|
||||
let packet = CLoginSuccess::new(profile.id, &profile.name, &profile.properties, false);
|
||||
self.send_packet(&packet);
|
||||
} else {
|
||||
self.kick("game profile is none");
|
||||
}
|
||||
@@ -167,8 +170,25 @@ impl Client {
|
||||
) {
|
||||
self.connection_state = ConnectionState::Config;
|
||||
server.send_brand(self);
|
||||
|
||||
let resource_config = &server.advanced_config.resource_pack;
|
||||
if resource_config.enabled {
|
||||
let prompt_message = if resource_config.prompt_message.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(TextComponent::from(resource_config.prompt_message.clone()))
|
||||
};
|
||||
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(),
|
||||
resource_config.force,
|
||||
prompt_message,
|
||||
));
|
||||
}
|
||||
|
||||
// known data packs
|
||||
self.send_packet(CKnownPacks::new(&[KnownPack {
|
||||
self.send_packet(&CKnownPacks::new(&[KnownPack {
|
||||
namespace: "minecraft",
|
||||
id: "core",
|
||||
version: "1.21",
|
||||
@@ -180,6 +200,7 @@ impl Client {
|
||||
_server: &mut Server,
|
||||
client_information: SClientInformation,
|
||||
) {
|
||||
dbg!("got client settings");
|
||||
self.config = Some(PlayerConfig {
|
||||
locale: client_information.locale,
|
||||
view_distance: client_information.view_distance,
|
||||
@@ -204,9 +225,9 @@ impl Client {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_known_packs(&mut self, _server: &mut Server, _config_acknowledged: SKnownPacks) {
|
||||
for registry in Registry::get_static() {
|
||||
self.send_packet(CRegistryData::new(
|
||||
pub fn handle_known_packs(&mut self, server: &mut Server, _config_acknowledged: SKnownPacks) {
|
||||
for registry in &server.cached_registry {
|
||||
self.send_packet(&CRegistryData::new(
|
||||
®istry.registry_id,
|
||||
®istry.registry_entries,
|
||||
));
|
||||
@@ -214,7 +235,7 @@ impl Client {
|
||||
|
||||
// We are done with configuring
|
||||
dbg!("finish config");
|
||||
self.send_packet(CFinishConfig::new());
|
||||
self.send_packet(&CFinishConfig::new());
|
||||
}
|
||||
|
||||
pub async fn handle_config_acknowledged(
|
||||
|
||||
+11
-15
@@ -32,9 +32,9 @@ use pumpkin_protocol::{
|
||||
},
|
||||
status::{SPingRequest, SStatusRequest},
|
||||
},
|
||||
text::TextComponent,
|
||||
ClientPacket, ConnectionState, PacketError, RawPacket, ServerPacket,
|
||||
};
|
||||
use pumpkin_text::TextComponent;
|
||||
|
||||
use std::io::Read;
|
||||
use thiserror::Error;
|
||||
@@ -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) {
|
||||
@@ -294,9 +294,7 @@ impl Client {
|
||||
}
|
||||
Ok(n) => {
|
||||
bytes_read += n;
|
||||
if bytes_read == received_data.len() {
|
||||
received_data.resize(received_data.len() + 1024, 0);
|
||||
}
|
||||
received_data.extend(&vec![0; n]);
|
||||
}
|
||||
// Would block "errors" are the OS's way of saying that the
|
||||
// connection is not actually ready to perform this I/O operation.
|
||||
@@ -325,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
|
||||
@@ -333,20 +331,18 @@ 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 {
|
||||
text: reason.to_string(),
|
||||
}))
|
||||
.unwrap_or_else(|_| self.close());
|
||||
self.try_send_packet(&CPlayDisconnect::new(TextComponent::from(reason)))
|
||||
.unwrap_or_else(|_| self.close());
|
||||
}
|
||||
_ => {
|
||||
log::warn!("Cant't kick in {:?} State", self.connection_state)
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
use num_traits::FromPrimitive;
|
||||
use pumpkin_inventory::WindowType;
|
||||
use pumpkin_protocol::{
|
||||
client::play::{
|
||||
Animation, CEntityAnimation, CHeadRot, CSystemChatMessge, CUpdateEntityPos,
|
||||
CUpdateEntityPosRot, CUpdateEntityRot,
|
||||
Animation, CEntityAnimation, CHeadRot, COpenScreen, CUpdateEntityPos, CUpdateEntityPosRot,
|
||||
CUpdateEntityRot,
|
||||
},
|
||||
server::play::{
|
||||
SChatCommand, SChatMessage, SConfirmTeleport, SPlayerCommand, SPlayerPosition,
|
||||
SPlayerPositionRotation, SPlayerRotation, SSwingArm,
|
||||
},
|
||||
text::TextComponent,
|
||||
VarInt,
|
||||
};
|
||||
use pumpkin_text::TextComponent;
|
||||
|
||||
use crate::{
|
||||
commands::{handle_command, CommandSender},
|
||||
entity::player::Hand,
|
||||
server::Server,
|
||||
util::math::wrap_degrees,
|
||||
};
|
||||
|
||||
use super::Client;
|
||||
@@ -38,18 +41,27 @@ impl Client {
|
||||
}
|
||||
}
|
||||
|
||||
fn clamp_horizontal(pos: f64) -> f64 {
|
||||
pos.clamp(-3.0E7, 3.0E7)
|
||||
}
|
||||
|
||||
fn clamp_vertical(pos: f64) -> f64 {
|
||||
pos.clamp(-2.0E7, 2.0E7)
|
||||
}
|
||||
|
||||
pub fn handle_position(&mut self, server: &mut Server, position: SPlayerPosition) {
|
||||
if position.x.is_nan() || position.feet_y.is_nan() || position.z.is_nan() {
|
||||
self.kick("Invalid movement");
|
||||
return;
|
||||
}
|
||||
let player = self.player.as_mut().unwrap();
|
||||
let entity = &mut player.entity;
|
||||
entity.lastx = entity.x;
|
||||
entity.lasty = entity.y;
|
||||
entity.lastz = entity.z;
|
||||
entity.x = position.x;
|
||||
entity.y = position.feet_y;
|
||||
entity.z = position.z;
|
||||
entity.x = Self::clamp_horizontal(position.x);
|
||||
entity.y = Self::clamp_vertical(position.feet_y);
|
||||
entity.z = Self::clamp_horizontal(position.z);
|
||||
// TODO: teleport when moving > 8 block
|
||||
|
||||
// send new position to all other players
|
||||
@@ -61,7 +73,7 @@ impl Client {
|
||||
|
||||
server.broadcast_packet(
|
||||
self,
|
||||
CUpdateEntityPos::new(
|
||||
&CUpdateEntityPos::new(
|
||||
entity_id.into(),
|
||||
(x * 4096.0 - lastx * 4096.0) as i16,
|
||||
(y * 4096.0 - lasty * 4096.0) as i16,
|
||||
@@ -81,18 +93,23 @@ impl Client {
|
||||
|| position_rotation.z.is_nan()
|
||||
{
|
||||
self.kick("Invalid movement");
|
||||
return;
|
||||
}
|
||||
if !position_rotation.yaw.is_finite() || !position_rotation.pitch.is_finite() {
|
||||
self.kick("Invalid rotation");
|
||||
return;
|
||||
}
|
||||
let player = self.player.as_mut().unwrap();
|
||||
let entity = &mut player.entity;
|
||||
|
||||
entity.x = position_rotation.x;
|
||||
entity.y = position_rotation.feet_y;
|
||||
entity.z = position_rotation.z;
|
||||
entity.yaw = position_rotation.yaw % 360.0;
|
||||
entity.pitch = position_rotation.pitch.clamp(-90.0, 90.0) % 360.0;
|
||||
entity.lastx = entity.x;
|
||||
entity.lasty = entity.y;
|
||||
entity.lastz = entity.z;
|
||||
entity.x = Self::clamp_horizontal(position_rotation.x);
|
||||
entity.y = Self::clamp_vertical(position_rotation.feet_y);
|
||||
entity.z = Self::clamp_horizontal(position_rotation.z);
|
||||
entity.yaw = wrap_degrees(position_rotation.yaw);
|
||||
entity.pitch = wrap_degrees(position_rotation.pitch);
|
||||
|
||||
// send new position to all other players
|
||||
let on_ground = player.on_ground;
|
||||
@@ -106,7 +123,7 @@ impl Client {
|
||||
|
||||
server.broadcast_packet(
|
||||
self,
|
||||
CUpdateEntityPosRot::new(
|
||||
&CUpdateEntityPosRot::new(
|
||||
entity_id.into(),
|
||||
(x * 4096.0 - lastx * 4096.0) as i16,
|
||||
(y * 4096.0 - lasty * 4096.0) as i16,
|
||||
@@ -116,32 +133,34 @@ impl Client {
|
||||
on_ground,
|
||||
),
|
||||
);
|
||||
server.broadcast_packet(self, CHeadRot::new(entity_id.into(), head_yaw as u8));
|
||||
server.broadcast_packet(self, &CHeadRot::new(entity_id.into(), head_yaw as u8));
|
||||
}
|
||||
|
||||
pub fn handle_rotation(&mut self, server: &mut Server, rotation: SPlayerRotation) {
|
||||
if !rotation.yaw.is_finite() || !rotation.pitch.is_finite() {
|
||||
self.kick("Invalid rotation");
|
||||
return;
|
||||
}
|
||||
let player = self.player.as_mut().unwrap();
|
||||
let entity = &mut player.entity;
|
||||
entity.yaw = rotation.yaw % 360.0;
|
||||
entity.pitch = rotation.pitch.clamp(-90.0, 90.0) % 360.0;
|
||||
entity.yaw = wrap_degrees(rotation.yaw);
|
||||
entity.pitch = wrap_degrees(rotation.pitch);
|
||||
// send new position to all other players
|
||||
let on_ground = player.on_ground;
|
||||
let entity_id = entity.entity_id;
|
||||
let yaw = entity.yaw;
|
||||
let pitch = entity.pitch;
|
||||
let yaw = (entity.yaw * 256.0 / 360.0).floor();
|
||||
let pitch = (entity.pitch * 256.0 / 360.0).floor();
|
||||
let head_yaw = (entity.head_yaw * 256.0 / 360.0).floor();
|
||||
|
||||
server.broadcast_packet(
|
||||
self,
|
||||
CUpdateEntityRot::new(entity_id.into(), yaw as u8, pitch as u8, on_ground),
|
||||
&CUpdateEntityRot::new(entity_id.into(), yaw as u8, pitch as u8, on_ground),
|
||||
);
|
||||
server.broadcast_packet(self, CHeadRot::new(entity_id.into(), yaw as u8));
|
||||
server.broadcast_packet(self, &CHeadRot::new(entity_id.into(), head_yaw as u8));
|
||||
}
|
||||
|
||||
pub fn handle_chat_command(&mut self, _server: &mut Server, command: SChatCommand) {
|
||||
handle_command(&mut CommandSender::Player(self), command.command);
|
||||
handle_command(&mut CommandSender::Player(self), &command.command);
|
||||
}
|
||||
|
||||
pub fn handle_player_command(&mut self, _server: &mut Server, command: SPlayerCommand) {
|
||||
@@ -170,39 +189,46 @@ 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) {
|
||||
let message = chat_message.message;
|
||||
self.send_packet(&COpenScreen::new(
|
||||
VarInt(0),
|
||||
VarInt(WindowType::CraftingTable as i32),
|
||||
TextComponent::from("Test Crafter"),
|
||||
));
|
||||
// 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(
|
||||
// server.broadcast_packet(
|
||||
// self,
|
||||
// CSystemChatMessge::new(
|
||||
// TextComponent::from(format!("{}: {}", gameprofile.name, message)),
|
||||
// false,
|
||||
// ),
|
||||
// );
|
||||
/* server.broadcast_packet(
|
||||
self,
|
||||
CSystemChatMessge::new(
|
||||
TextComponent::from(format!("{}: {}", gameprofile.name, message)),
|
||||
false,
|
||||
CPlayerChatMessage::new(
|
||||
pumpkin_protocol::uuid::UUID(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,
|
||||
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(
|
||||
|
||||
Reference in new issue
Block a user