resolve merge conflicts
This commit is contained in:
commit
3ec539d418
53 files changed
+261
-257
No files matched your search
@@ -1,5 +1,3 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use num_traits::FromPrimitive;
|
||||
use pumpkin_protocol::{
|
||||
client::{
|
||||
@@ -39,11 +37,15 @@ impl Client {
|
||||
self.protocol_version = handshake.protocol_version.0;
|
||||
self.connection_state = handshake.next_state;
|
||||
if self.connection_state == ConnectionState::Login {
|
||||
if self.protocol_version < CURRENT_MC_PROTOCOL as i32 {
|
||||
let protocol = self.protocol_version;
|
||||
self.kick(&format!("Client outdated ({protocol}), Server uses Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL}"));
|
||||
} else if self.protocol_version > CURRENT_MC_PROTOCOL as i32 {
|
||||
self.kick(&format!("Server outdated, Server uses Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL}"));
|
||||
let protocol = self.protocol_version;
|
||||
match protocol.cmp(&(CURRENT_MC_PROTOCOL as i32)) {
|
||||
std::cmp::Ordering::Less => {
|
||||
self.kick(&format!("Client outdated ({protocol}), Server uses Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL}"));
|
||||
}
|
||||
std::cmp::Ordering::Equal => {}
|
||||
std::cmp::Ordering::Greater => {
|
||||
self.kick(&format!("Server outdated, Server uses Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -200,12 +202,15 @@ impl Client {
|
||||
let prompt_message = if resource_config.prompt_message.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(TextComponent::from(resource_config.prompt_message.clone()))
|
||||
Some(TextComponent::text(&resource_config.prompt_message))
|
||||
};
|
||||
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(),
|
||||
pumpkin_protocol::uuid::UUID(uuid::Uuid::new_v3(
|
||||
&uuid::Uuid::NAMESPACE_DNS,
|
||||
resource_config.resource_pack_url.as_bytes(),
|
||||
)),
|
||||
&resource_config.resource_pack_url,
|
||||
&resource_config.resource_pack_sha1,
|
||||
resource_config.force,
|
||||
prompt_message,
|
||||
));
|
||||
|
||||
@@ -65,7 +65,7 @@ pub struct Client {
|
||||
|
||||
pub protocol_version: i32,
|
||||
pub connection_state: ConnectionState,
|
||||
pub encrytion: bool,
|
||||
pub encryption: bool,
|
||||
pub closed: bool,
|
||||
pub token: Rc<Token>,
|
||||
pub connection: TcpStream,
|
||||
@@ -89,7 +89,7 @@ impl Client {
|
||||
connection,
|
||||
enc: PacketEncoder::default(),
|
||||
dec: PacketDecoder::default(),
|
||||
encrytion: true,
|
||||
encryption: true,
|
||||
closed: false,
|
||||
client_packets_queue: VecDeque::new(),
|
||||
}
|
||||
@@ -105,7 +105,7 @@ impl Client {
|
||||
&mut self,
|
||||
shared_secret: &[u8], // decrypted
|
||||
) -> Result<(), EncryptionError> {
|
||||
self.encrytion = true;
|
||||
self.encryption = true;
|
||||
let crypt_key: [u8; 16] = shared_secret
|
||||
.try_into()
|
||||
.map_err(|_| EncryptionError::SharedWrongLength)?;
|
||||
@@ -375,11 +375,11 @@ impl Client {
|
||||
.unwrap_or_else(|_| self.close());
|
||||
}
|
||||
ConnectionState::Play => {
|
||||
self.try_send_packet(&CPlayDisconnect::new(TextComponent::from(reason)))
|
||||
self.try_send_packet(&CPlayDisconnect::new(TextComponent::text(reason)))
|
||||
.unwrap_or_else(|_| self.close());
|
||||
}
|
||||
_ => {
|
||||
log::warn!("Cant't kick in {:?} State", self.connection_state)
|
||||
log::warn!("Can't kick in {:?} State", self.connection_state)
|
||||
}
|
||||
}
|
||||
self.close()
|
||||
|
||||
@@ -5,7 +5,7 @@ use pumpkin_entity::EntityId;
|
||||
use pumpkin_protocol::{
|
||||
client::play::{
|
||||
Animation, CBlockUpdate, CEntityAnimation, CEntityVelocity, CHeadRot, CHurtAnimation,
|
||||
CSystemChatMessge, CUpdateEntityPos, CUpdateEntityPosRot, CUpdateEntityRot,
|
||||
CPlayerChatMessage, CUpdateEntityPos, CUpdateEntityPosRot, CUpdateEntityRot, FilterType,
|
||||
},
|
||||
position::WorldPosition,
|
||||
server::play::{
|
||||
@@ -116,7 +116,7 @@ impl Client {
|
||||
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) % 360.0;
|
||||
entity.yaw = wrap_degrees(position_rotation.yaw) % 360.0;
|
||||
entity.pitch = wrap_degrees(position_rotation.pitch).clamp(-90.0, 90.0) % 360.0;
|
||||
|
||||
// send new position to all other players
|
||||
@@ -209,38 +209,30 @@ impl Client {
|
||||
}
|
||||
|
||||
pub fn handle_chat_message(&mut self, server: &mut Server, chat_message: SChatMessage) {
|
||||
dbg!("got message");
|
||||
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(
|
||||
&CPlayerChatMessage::new(
|
||||
pumpkin_protocol::uuid::UUID(gameprofile.id),
|
||||
0.into(),
|
||||
None,
|
||||
message.clone(),
|
||||
chat_message.messagee_count,
|
||||
chat_message.signature.as_deref(),
|
||||
&message,
|
||||
chat_message.timestamp,
|
||||
chat_message.salt,
|
||||
&[],
|
||||
Some(TextComponent::from(message.clone())),
|
||||
Some(TextComponent::text(&message)),
|
||||
pumpkin_protocol::VarInt(FilterType::PassThrough as i32),
|
||||
0.into(),
|
||||
TextComponent::from(gameprofile.name.clone()),
|
||||
None,
|
||||
1.into(),
|
||||
TextComponent::text(&gameprofile.name.clone()),
|
||||
None,
|
||||
),
|
||||
)
|
||||
|
||||
*/
|
||||
/* server.broadcast_packet(
|
||||
self,
|
||||
&CDisguisedChatMessage::new(
|
||||
@@ -272,12 +264,13 @@ impl Client {
|
||||
pub fn handle_interact(&mut self, server: &mut Server, interact: SInteract) {
|
||||
let action = ActionType::from_i32(interact.typ.0).unwrap();
|
||||
if action == ActionType::Attack {
|
||||
let attacker_player = self.player.as_ref().unwrap();
|
||||
let entity_id = interact.entity_id;
|
||||
// TODO: do validation and stuff
|
||||
let config = &server.advanced_config.pvp;
|
||||
if config.enabled {
|
||||
let attacked_client = server.get_by_entityid(self, entity_id.0 as EntityId);
|
||||
let attacker_player = self.player.as_mut().unwrap();
|
||||
attacker_player.sneaking = interact.sneaking;
|
||||
if let Some(mut client) = attacked_client {
|
||||
let token = client.token.clone();
|
||||
let player = client.player.as_mut().unwrap();
|
||||
@@ -299,9 +292,10 @@ impl Client {
|
||||
player.velocity.y as f32,
|
||||
player.velocity.z as f32,
|
||||
);
|
||||
attacker_player.velocity = attacker_player.velocity.multiply(0.6, 1.0, 0.6);
|
||||
|
||||
player.velocity = velo;
|
||||
client.send_packet(packet);
|
||||
// attacker_player.velocity = attacker_player.velocity.multiply(0.6, 1.0, 0.6);
|
||||
}
|
||||
if config.hurt_animation {
|
||||
// TODO
|
||||
@@ -314,16 +308,14 @@ impl Client {
|
||||
&CHurtAnimation::new(&entity_id, 10.0),
|
||||
)
|
||||
}
|
||||
if config.swing {
|
||||
|
||||
}
|
||||
if config.swing {}
|
||||
} else {
|
||||
self.kick("Interacted with invalid entitiy id")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn handle_player_action(&mut self, _server: &mut Server, player_action: SPlayerAction) {}
|
||||
pub fn handle_player_action(&mut self, _server: &mut Server, _player_action: SPlayerAction) {}
|
||||
|
||||
pub fn handle_use_item_on(&mut self, server: &mut Server, use_item_on: SUseItemOn) {
|
||||
let location = use_item_on.location;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use num_traits::FromPrimitive;
|
||||
use pumpkin_text::TextComponent;
|
||||
|
||||
use crate::commands::arg_player::{consume_arg_player, parse_arg_player};
|
||||
|
||||
@@ -68,7 +69,9 @@ pub(crate) fn init_command_tree<'a>() -> CommandTree<'a> {
|
||||
|
||||
return if let Player(target) = sender {
|
||||
target.set_gamemode(gamemode);
|
||||
target.send_system_message(format!("Game mode was set to {:?}", gamemode).into());
|
||||
target.send_system_message(TextComponent::text(
|
||||
&format!("Game mode was set to {:?}", gamemode)
|
||||
));
|
||||
|
||||
Ok(())
|
||||
} else {
|
||||
@@ -85,7 +88,9 @@ pub(crate) fn init_command_tree<'a>() -> CommandTree<'a> {
|
||||
let target = parse_arg_player(sender, ARG_TARGET, args)?;
|
||||
|
||||
target.set_gamemode(gamemode);
|
||||
target.send_system_message(format!("Game mode was set to {:?}", gamemode).into());
|
||||
target.send_system_message(TextComponent::text(
|
||||
&format!("Set own game mode to {:?}", gamemode)
|
||||
));
|
||||
|
||||
Ok(())
|
||||
})
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use pumpkin_text::TextComponent;
|
||||
use crate::commands::{CommandSender, DISPATCHER, dispatcher_init};
|
||||
use crate::commands::dispatcher::{CommandDispatcher, InvalidTreeError};
|
||||
use crate::commands::dispatcher::InvalidTreeError::InvalidConsumptionError;
|
||||
@@ -41,7 +42,9 @@ pub(crate) fn init_command_tree<'a>() -> CommandTree<'a> {
|
||||
let (name, tree) = parse_arg_command(args, dispatcher)?;
|
||||
|
||||
sender.send_message(
|
||||
format!("{} - {} Usage:{}", name, tree.description, tree.paths_formatted(name)).into()
|
||||
TextComponent::text(
|
||||
&format!("{} - {} Usage:{}", name, tree.description, tree.paths_formatted(name))
|
||||
)
|
||||
);
|
||||
|
||||
Ok(())
|
||||
@@ -52,7 +55,9 @@ pub(crate) fn init_command_tree<'a>() -> CommandTree<'a> {
|
||||
|
||||
for (name, tree) in &dispatcher.commands {
|
||||
sender.send_message(
|
||||
format!("{} - {} Usage:{}", name, tree.description, tree.paths_formatted(name)).into()
|
||||
TextComponent::text(
|
||||
&format!("{} - {} Usage:{}", name, tree.description, tree.paths_formatted(name))
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -12,9 +12,10 @@ pub(crate) fn init_command_tree<'a>() -> CommandTree<'a> {
|
||||
CommandTree::new(DESCRIPTION).execute(&|sender, _| {
|
||||
let version = env!("CARGO_PKG_VERSION");
|
||||
let description = env!("CARGO_PKG_DESCRIPTION");
|
||||
sender.send_message(TextComponent::from(
|
||||
format!("Pumpkin {version}, {description} (Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL})")).color_named(NamedColor::Green)
|
||||
);
|
||||
|
||||
sender.send_message(TextComponent::text(
|
||||
&format!("Pumpkin {version}, {description} (Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL})")
|
||||
).color_named(NamedColor::Green));
|
||||
|
||||
Ok(())
|
||||
})
|
||||
|
||||
@@ -89,7 +89,7 @@ pub fn handle_command(sender: &mut CommandSender, cmd: &str) {
|
||||
|
||||
if let Err(err) = dispatcher.dispatch(sender, cmd) {
|
||||
sender.send_message(
|
||||
TextComponent::from(err)
|
||||
TextComponent::text(&err)
|
||||
.color_named(pumpkin_text::color::NamedColor::Red),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ pub mod resource_pack;
|
||||
const CURRENT_BASE_VERSION: &str = "1.0.0";
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
/// The idea is that Pumpkin should very customizable, You can Enable or Disable Features depning on your needs.
|
||||
/// The idea is that Pumpkin should very customizable, You can Enable or Disable Features depending on your needs.
|
||||
/// This also allows you get some Performance or Resource boosts.
|
||||
/// Important: The Configuration should match Vanilla by default
|
||||
pub struct AdvancedConfiguration {
|
||||
@@ -182,7 +182,7 @@ impl AdvancedConfiguration {
|
||||
if path.as_ref().exists() {
|
||||
let toml = std::fs::read_to_string(path).expect("Couldn't read configuration");
|
||||
let config: AdvancedConfiguration =
|
||||
toml::from_str(toml.as_str()).expect("Couldn't parse features.toml, Proberbly old config, Replacing with a new one or just delete it");
|
||||
toml::from_str(toml.as_str()).expect("Couldn't parse features.toml, Probably old config, Replacing with a new one or just delete it");
|
||||
config.validate();
|
||||
config
|
||||
} else {
|
||||
@@ -202,7 +202,7 @@ impl BasicConfiguration {
|
||||
pub fn load<P: AsRef<Path>>(path: P) -> BasicConfiguration {
|
||||
if path.as_ref().exists() {
|
||||
let toml = std::fs::read_to_string(path).expect("Couldn't read configuration");
|
||||
let config: BasicConfiguration = toml::from_str(toml.as_str()).expect("Couldn't parse configuration.toml, Proberbly old config, Replacing with a new one or just delete it");
|
||||
let config: BasicConfiguration = toml::from_str(toml.as_str()).expect("Couldn't parse configuration.toml, Probably old config, Replacing with a new one or just delete it");
|
||||
config.validate();
|
||||
config
|
||||
} else {
|
||||
@@ -219,7 +219,7 @@ impl BasicConfiguration {
|
||||
self.config_version, CURRENT_BASE_VERSION,
|
||||
"Config version does not match used Config version. Please update your config"
|
||||
);
|
||||
assert!(self.view_distance >= 2, "View distance must be atleast 2");
|
||||
assert!(self.view_distance >= 2, "View distance must be at least 2");
|
||||
assert!(
|
||||
self.view_distance <= 32,
|
||||
"View distance must be less than 32"
|
||||
|
||||
@@ -7,7 +7,7 @@ pub struct ResourcePackConfig {
|
||||
pub resource_pack_url: String,
|
||||
/// The SHA1 hash (40) of the resource pack.
|
||||
pub resource_pack_sha1: String,
|
||||
/// Custom propmt Text component, Leave blank for none
|
||||
/// Custom prompt Text component, Leave blank for none
|
||||
pub prompt_message: String,
|
||||
/// Will force the Player to accept the resource pack
|
||||
pub force: bool,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use num_traits::Float;
|
||||
use pumpkin_entity::{entity_type::EntityType, Entity, EntityId};
|
||||
use pumpkin_inventory::player::PlayerInventory;
|
||||
use pumpkin_protocol::VarInt;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#![allow(clippy::await_holding_refcell_ref)]
|
||||
|
||||
use mio::net::TcpListener;
|
||||
use mio::{Events, Interest, Poll, Token};
|
||||
use std::io::{self};
|
||||
|
||||
@@ -65,7 +65,7 @@ impl Packet {
|
||||
buf.put_slice(bytes);
|
||||
buf.put_u8(0);
|
||||
buf.put_u8(0);
|
||||
connection.write(&buf).unwrap();
|
||||
let _ = connection.write(&buf).unwrap();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
+22
-12
@@ -3,7 +3,10 @@ use std::{
|
||||
collections::HashMap,
|
||||
io::Cursor,
|
||||
rc::Rc,
|
||||
sync::atomic::{AtomicI32, Ordering},
|
||||
sync::{
|
||||
atomic::{AtomicI32, Ordering},
|
||||
Arc,
|
||||
},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
@@ -25,12 +28,12 @@ use pumpkin_protocol::{
|
||||
uuid::UUID,
|
||||
ClientPacket, Players, Sample, StatusResponse, VarInt, Version, CURRENT_MC_PROTOCOL,
|
||||
};
|
||||
use pumpkin_world::{dimension::Dimension, radial_chunk_iterator::RadialIterator};
|
||||
use pumpkin_world::{dimension::Dimension, radial_chunk_iterator::RadialIterator, World};
|
||||
|
||||
use pumpkin_registry::Registry;
|
||||
use rsa::{traits::PublicKeyParts, RsaPrivateKey, RsaPublicKey};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::sync::mpsc;
|
||||
use tokio::sync::{mpsc, Mutex};
|
||||
|
||||
use crate::{
|
||||
client::Client,
|
||||
@@ -47,7 +50,7 @@ pub struct Server {
|
||||
pub private_key: RsaPrivateKey,
|
||||
pub public_key_der: Box<[u8]>,
|
||||
|
||||
// pub world: World,
|
||||
pub world: Arc<Mutex<World>>,
|
||||
pub status_response: StatusResponse,
|
||||
// We cache the json response here so we don't parse it every time someone makes a Status request.
|
||||
// Keep in mind that we must parse this again, when the StatusResponse changes which usally happen when a player joins or leaves
|
||||
@@ -97,11 +100,17 @@ impl Server {
|
||||
None
|
||||
};
|
||||
|
||||
log::debug!("Pumpkin does currently not have World or Chunk generation, Using ../world folder with vanilla pregenerated chunks");
|
||||
let world = World::load(Dimension::OverWorld.into_level(
|
||||
// TODO: load form config
|
||||
"./world".parse().unwrap(),
|
||||
));
|
||||
|
||||
Self {
|
||||
cached_registry: Registry::get_static(),
|
||||
// 0 is invalid
|
||||
entity_id: 2.into(),
|
||||
// world: World::load(""),
|
||||
world: Arc::new(Mutex::new(world)),
|
||||
compression_threshold: None, // 256
|
||||
public_key,
|
||||
cached_server_brand,
|
||||
@@ -288,7 +297,8 @@ impl Server {
|
||||
)
|
||||
}
|
||||
|
||||
Server::spawn_test_chunk(client, self.base_config.view_distance as u32).await;
|
||||
self.spawn_test_chunk(client, self.base_config.view_distance as u32)
|
||||
.await;
|
||||
}
|
||||
|
||||
/// TODO: This definitly should be in world
|
||||
@@ -337,15 +347,15 @@ impl Server {
|
||||
}
|
||||
|
||||
// TODO: do this in a world
|
||||
async fn spawn_test_chunk(client: &mut Client, distance: u32) {
|
||||
async fn spawn_test_chunk(&self, client: &mut Client, distance: u32) {
|
||||
let inst = std::time::Instant::now();
|
||||
let (sender, mut chunk_receiver) = mpsc::channel(distance as usize);
|
||||
let world = self.world.clone();
|
||||
tokio::spawn(async move {
|
||||
let level = Dimension::OverWorld.into_level(
|
||||
// TODO: load form config
|
||||
"./world".parse().unwrap(),
|
||||
);
|
||||
level
|
||||
world
|
||||
.lock()
|
||||
.await
|
||||
.level
|
||||
.read_chunks(RadialIterator::new(distance).collect(), sender)
|
||||
.await;
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user