From fa8969d6a2244ad5bb5e21a5668143e0ee1b0e04 Mon Sep 17 00:00:00 2001 From: lukas0008 Date: Wed, 7 Aug 2024 19:57:36 +0200 Subject: [PATCH 1/7] Tokio --- Cargo.lock | 13 +++++++++++++ Cargo.toml | 3 +++ pumpkin/Cargo.toml | 3 +-- pumpkin/src/main.rs | 3 ++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 55ce38c4..3523957d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1177,6 +1177,7 @@ dependencies = [ "sha1", "simple_logger", "thiserror", + "tokio", "toml", "uuid", ] @@ -1788,9 +1789,21 @@ dependencies = [ "mio", "pin-project-lite", "socket2", + "tokio-macros", "windows-sys 0.52.0", ] +[[package]] +name = "tokio-macros" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", +] + [[package]] name = "tokio-native-tls" version = "0.3.1" diff --git a/Cargo.toml b/Cargo.toml index 7ce9d72c..158cf41d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,6 @@ edition = "2021" [profile.release] lto = true + +[workspace.dependencies] +tokio = { version = "1.39.2", features = ["net", "macros", "rt-multi-thread", "fs", "io-util"] } diff --git a/pumpkin/Cargo.toml b/pumpkin/Cargo.toml index 3f9fe1c1..2572cf18 100644 --- a/pumpkin/Cargo.toml +++ b/pumpkin/Cargo.toml @@ -49,5 +49,4 @@ crossbeam-channel = "0.5.13" uuid = { version = "1.10", features = ["serde"]} - - +tokio.workspace = true \ No newline at end of file diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index 0b5372ae..d1aa3600 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -23,7 +23,8 @@ pub mod server; pub mod util; #[cfg(not(target_os = "wasi"))] -fn main() -> io::Result<()> { +#[tokio::main] +async fn main() -> io::Result<()> { use std::{cell::RefCell, time::Instant}; let time = Instant::now(); From 2fd8686fea70348d54226b4a011caf0740d52b1c Mon Sep 17 00:00:00 2001 From: lukas0008 Date: Wed, 7 Aug 2024 20:33:51 +0200 Subject: [PATCH 2/7] todo to TODO --- pumpkin-entity/src/entity_type.rs | 2 +- pumpkin/src/client/authentication.rs | 2 +- pumpkin/src/client/client_packet.rs | 6 +++--- pumpkin/src/client/mod.rs | 2 +- pumpkin/src/client/player_packet.rs | 2 +- pumpkin/src/commands/gamemode.rs | 6 +++--- pumpkin/src/commands/mod.rs | 4 ++-- pumpkin/src/config/mod.rs | 2 +- pumpkin/src/server.rs | 16 ++++++++-------- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pumpkin-entity/src/entity_type.rs b/pumpkin-entity/src/entity_type.rs index 4062e73a..e5cbc49d 100644 --- a/pumpkin-entity/src/entity_type.rs +++ b/pumpkin-entity/src/entity_type.rs @@ -1,6 +1,6 @@ use num_derive::ToPrimitive; -// todo +// TODO #[derive(ToPrimitive, Clone)] pub enum EntityType { Zombie = 124, diff --git a/pumpkin/src/client/authentication.rs b/pumpkin/src/client/authentication.rs index dcebe09a..eaff1611 100644 --- a/pumpkin/src/client/authentication.rs +++ b/pumpkin/src/client/authentication.rs @@ -80,7 +80,7 @@ pub fn authenticate( } pub fn unpack_textures(property: Property, config: &TextureConfig) { - // todo: no unwrap + // TODO: no unwrap let from64 = general_purpose::STANDARD.decode(property.value).unwrap(); let textures: ProfileTextures = serde_json::from_slice(&from64).unwrap(); dbg!(&textures); diff --git a/pumpkin/src/client/client_packet.rs b/pumpkin/src/client/client_packet.rs index a62286c4..8a82ca91 100644 --- a/pumpkin/src/client/client_packet.rs +++ b/pumpkin/src/client/client_packet.rs @@ -48,10 +48,10 @@ impl Client { } pub fn handle_login_start(&mut self, server: &mut Server, login_start: SLoginStart) { - // todo: do basic name validation + // TODO: do basic name validation dbg!("login start"); // default game profile, when no online mode - // todo: make offline uuid + // TODO: make offline uuid self.gameprofile = Some(GameProfile { id: login_start.uuid, name: login_start.name, @@ -59,7 +59,7 @@ impl Client { profile_actions: None, }); - // todo: check config for encryption + // TODO: check config for encryption let verify_token: [u8; 4] = rand::random(); let public_key_der = &server.public_key_der; let packet = CEncryptionRequest::new( diff --git a/pumpkin/src/client/mod.rs b/pumpkin/src/client/mod.rs index a9997b44..47962892 100644 --- a/pumpkin/src/client/mod.rs +++ b/pumpkin/src/client/mod.rs @@ -136,7 +136,7 @@ impl Client { pub fn teleport(&mut self, x: f64, y: f64, z: f64, yaw: f32, pitch: f32) { assert!(self.is_player()); - // todo + // TODO let id = 0; let player = self.player.as_mut().unwrap(); let entity = &mut player.entity; diff --git a/pumpkin/src/client/player_packet.rs b/pumpkin/src/client/player_packet.rs index 1850fd34..34384b9a 100644 --- a/pumpkin/src/client/player_packet.rs +++ b/pumpkin/src/client/player_packet.rs @@ -49,7 +49,7 @@ impl Client { entity.x = position.x; entity.y = position.feet_y; entity.z = position.z; - // todo: teleport when moving > 8 block + // TODO: teleport when moving > 8 block // send new position to all other players let on_ground = player.on_ground; diff --git a/pumpkin/src/commands/gamemode.rs b/pumpkin/src/commands/gamemode.rs index 5cc26b34..f2134598 100644 --- a/pumpkin/src/commands/gamemode.rs +++ b/pumpkin/src/commands/gamemode.rs @@ -18,7 +18,7 @@ impl<'a> Command<'a> for GamemodeCommand { let args: Vec<&str> = command.split_whitespace().collect(); if args.len() != 2 { - // todo red + // TODO: red player.send_system_message("Usage: /gamemode ".into()); return; } @@ -30,13 +30,13 @@ impl<'a> Command<'a> for GamemodeCommand { player.send_system_message(format!("Set own game mode to {mode_str}").into()); } Err(_) => { - // todo red + // TODO: red player.send_system_message("Invalid gamemode".into()); } } } - // todo: support console, (name required) + // TODO: support console, (name required) fn player_required() -> bool { true } diff --git a/pumpkin/src/commands/mod.rs b/pumpkin/src/commands/mod.rs index 9c97c0f2..bc6160f3 100644 --- a/pumpkin/src/commands/mod.rs +++ b/pumpkin/src/commands/mod.rs @@ -29,7 +29,7 @@ pub enum CommandSender<'a> { impl<'a> CommandSender<'a> { pub fn send_message(&mut self, text: TextComponent) { match self { - // todo: add color and stuff to console + // TODO: add color and stuff to console CommandSender::Console => log::info!("{}", text.text), CommandSender::Player(c) => c.send_system_message(text), } @@ -66,6 +66,6 @@ pub fn handle_command(sender: &mut CommandSender, command: String) { GamemodeCommand::on_execute(sender, command); return; } - // todo: red color + // TODO: red color sender.send_message("Command not Found".into()); } diff --git a/pumpkin/src/config/mod.rs b/pumpkin/src/config/mod.rs index 3430a233..cd515490 100644 --- a/pumpkin/src/config/mod.rs +++ b/pumpkin/src/config/mod.rs @@ -23,7 +23,7 @@ pub struct AdvancedConfiguration { pub struct Commands { /// Are commands from the Console accepted ? pub use_console: bool, - // todo commands... + // TODO: commands... } impl Default for Commands { diff --git a/pumpkin/src/server.rs b/pumpkin/src/server.rs index dd7b1923..1a454c5a 100644 --- a/pumpkin/src/server.rs +++ b/pumpkin/src/server.rs @@ -50,8 +50,8 @@ pub struct Server { pub current_clients: HashMap, Rc>>, - // todo replace with HashMap - entity_id: AtomicI32, // todo: place this into every world + // TODO: replace with HashMap + entity_id: AtomicI32, // TODO: place this into every world pub base_config: BasicConfiguration, pub advanced_config: AdvancedConfiguration, @@ -66,7 +66,7 @@ impl Server { .expect("Failed to parse Status response into JSON"); let cached_server_brand = Self::build_brand(); - // todo, only create when needed + // TODO: only create when needed let (public_key, private_key) = Self::generate_keys(); let public_key_der = rsa_der::public_key_to_der( @@ -100,7 +100,7 @@ impl Server { // Returns Tokens to remove pub fn poll(&mut self, client: &mut Client, _poll: &Poll, event: &Event) { - // todo, Poll players in every world + // TODO: Poll players in every world client.poll(self, event) } @@ -113,7 +113,7 @@ impl Server { } // here is where the magic happens - // todo: do this in a world + // TODO: do this in a world pub fn spawn_player(&mut self, client: &mut Client) { // This code follows the vanilla packet order let entity_id = self.new_entity_id(); @@ -127,8 +127,8 @@ impl Server { self.base_config.hardcore, vec!["minecraft:overworld".into()], self.base_config.max_players.into(), - self.base_config.view_distance.into(), // view distance todo - self.base_config.simulation_distance.into(), // sim view dinstance todo + self.base_config.view_distance.into(), // TODO: view distance + self.base_config.simulation_distance.into(), // TODO: sim view dinstance false, false, false, @@ -283,7 +283,7 @@ impl Server { } } - // todo: do this in a world + // TODO: do this in a world fn _spawn_test_chunk(client: &mut Client) { let test_chunk = TestChunk::new(); client.send_packet(CChunkDataUpdateLight::new( From 7891d2848deb9ddf7d1190f91aa166258b04a332 Mon Sep 17 00:00:00 2001 From: lukas0008 Date: Wed, 7 Aug 2024 20:44:04 +0200 Subject: [PATCH 3/7] Revert "Tokio" This reverts commit fa8969d6a2244ad5bb5e21a5668143e0ee1b0e04. --- Cargo.lock | 13 ------------- Cargo.toml | 3 --- pumpkin/Cargo.toml | 3 ++- pumpkin/src/main.rs | 3 +-- 4 files changed, 3 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3523957d..55ce38c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1177,7 +1177,6 @@ dependencies = [ "sha1", "simple_logger", "thiserror", - "tokio", "toml", "uuid", ] @@ -1789,21 +1788,9 @@ dependencies = [ "mio", "pin-project-lite", "socket2", - "tokio-macros", "windows-sys 0.52.0", ] -[[package]] -name = "tokio-macros" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.72", -] - [[package]] name = "tokio-native-tls" version = "0.3.1" diff --git a/Cargo.toml b/Cargo.toml index 158cf41d..7ce9d72c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,3 @@ edition = "2021" [profile.release] lto = true - -[workspace.dependencies] -tokio = { version = "1.39.2", features = ["net", "macros", "rt-multi-thread", "fs", "io-util"] } diff --git a/pumpkin/Cargo.toml b/pumpkin/Cargo.toml index 2572cf18..3f9fe1c1 100644 --- a/pumpkin/Cargo.toml +++ b/pumpkin/Cargo.toml @@ -49,4 +49,5 @@ crossbeam-channel = "0.5.13" uuid = { version = "1.10", features = ["serde"]} -tokio.workspace = true \ No newline at end of file + + diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index 84b445fb..66bae804 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -23,8 +23,7 @@ pub mod server; pub mod util; #[cfg(not(target_os = "wasi"))] -#[tokio::main] -async fn main() -> io::Result<()> { +fn main() -> io::Result<()> { use std::{cell::RefCell, time::Instant}; let time = Instant::now(); From f1b7d649dbfb4fdd0809c4cf5a014442f9abbe1a Mon Sep 17 00:00:00 2001 From: lukas0008 Date: Wed, 7 Aug 2024 20:45:22 +0200 Subject: [PATCH 4/7] Reapply "Tokio" This reverts commit 7891d2848deb9ddf7d1190f91aa166258b04a332. --- Cargo.lock | 13 +++++++++++++ Cargo.toml | 3 +++ pumpkin/Cargo.toml | 3 +-- pumpkin/src/main.rs | 3 ++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 55ce38c4..3523957d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1177,6 +1177,7 @@ dependencies = [ "sha1", "simple_logger", "thiserror", + "tokio", "toml", "uuid", ] @@ -1788,9 +1789,21 @@ dependencies = [ "mio", "pin-project-lite", "socket2", + "tokio-macros", "windows-sys 0.52.0", ] +[[package]] +name = "tokio-macros" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", +] + [[package]] name = "tokio-native-tls" version = "0.3.1" diff --git a/Cargo.toml b/Cargo.toml index 7ce9d72c..158cf41d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,6 @@ edition = "2021" [profile.release] lto = true + +[workspace.dependencies] +tokio = { version = "1.39.2", features = ["net", "macros", "rt-multi-thread", "fs", "io-util"] } diff --git a/pumpkin/Cargo.toml b/pumpkin/Cargo.toml index 3f9fe1c1..2572cf18 100644 --- a/pumpkin/Cargo.toml +++ b/pumpkin/Cargo.toml @@ -49,5 +49,4 @@ crossbeam-channel = "0.5.13" uuid = { version = "1.10", features = ["serde"]} - - +tokio.workspace = true \ No newline at end of file diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index 66bae804..84b445fb 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -23,7 +23,8 @@ pub mod server; pub mod util; #[cfg(not(target_os = "wasi"))] -fn main() -> io::Result<()> { +#[tokio::main] +async fn main() -> io::Result<()> { use std::{cell::RefCell, time::Instant}; let time = Instant::now(); From 76ce44e58d0f99ddbc76afa75331772156761c5b Mon Sep 17 00:00:00 2001 From: lukas0008 Date: Wed, 7 Aug 2024 21:11:13 +0200 Subject: [PATCH 5/7] Remove reqwest blocking feature --- Cargo.lock | 13 +------------ pumpkin-world/Cargo.toml | 3 ++- pumpkin/Cargo.toml | 2 +- pumpkin/src/client/authentication.rs | 5 +++-- pumpkin/src/client/client_packet.rs | 6 ++++-- pumpkin/src/client/mod.rs | 12 ++++++------ pumpkin/src/main.rs | 2 +- pumpkin/src/server.rs | 8 ++++---- 8 files changed, 22 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3523957d..c9d4122f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -455,7 +455,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", - "futures-sink", ] [[package]] @@ -464,12 +463,6 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - [[package]] name = "futures-sink" version = "0.3.30" @@ -489,13 +482,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-core", - "futures-io", - "futures-sink", "futures-task", - "memchr", "pin-project-lite", "pin-utils", - "slab", ] [[package]] @@ -1236,6 +1225,7 @@ dependencies = [ "fastnbt 2.5.0 (git+https://github.com/owengage/fastnbt.git)", "fastsnbt", "pumpkin-protocol", + "tokio", ] [[package]] @@ -1295,7 +1285,6 @@ dependencies = [ "base64", "bytes", "encoding_rs", - "futures-channel", "futures-core", "futures-util", "h2", diff --git a/pumpkin-world/Cargo.toml b/pumpkin-world/Cargo.toml index 56e82b44..c100edab 100644 --- a/pumpkin-world/Cargo.toml +++ b/pumpkin-world/Cargo.toml @@ -7,4 +7,5 @@ edition.workspace = true pumpkin-protocol = { path = "../pumpkin-protocol"} fastanvil = "0.31" fastnbt = { git = "https://github.com/owengage/fastnbt.git" } -fastsnbt = "0.2" \ No newline at end of file +fastsnbt = "0.2" +tokio.workspace = true \ No newline at end of file diff --git a/pumpkin/Cargo.toml b/pumpkin/Cargo.toml index 2572cf18..0239c0f1 100644 --- a/pumpkin/Cargo.toml +++ b/pumpkin/Cargo.toml @@ -28,7 +28,7 @@ rsa-der = "0.3.0" flate2 = "1.0.30" # authentication -reqwest = { version = "0.12.5", features = ["json", "blocking"]} +reqwest = { version = "0.12.5", features = ["json"]} sha1 = "0.10.6" digest = "=0.11.0-pre.9" diff --git a/pumpkin/src/client/authentication.rs b/pumpkin/src/client/authentication.rs index eaff1611..e8761993 100644 --- a/pumpkin/src/client/authentication.rs +++ b/pumpkin/src/client/authentication.rs @@ -46,7 +46,7 @@ pub struct GameProfile { pub profile_actions: Option>, } -pub fn authenticate( +pub async fn authenticate( username: &str, server_hash: &str, ip: &IpAddr, @@ -69,13 +69,14 @@ pub fn authenticate( .unwrap() .get(address) .send() + .await .map_err(|_| AuthError::FailedResponse)?; match response.status() { StatusCode::OK => {} StatusCode::NO_CONTENT => Err(AuthError::UnverifiedUsername)?, other => Err(AuthError::UnknownStatusCode(other.as_str().to_string()))?, } - let profile: GameProfile = response.json().map_err(|_| AuthError::FailedParse)?; + let profile: GameProfile = response.json().await.map_err(|_| AuthError::FailedParse)?; Ok(profile) } diff --git a/pumpkin/src/client/client_packet.rs b/pumpkin/src/client/client_packet.rs index 8a82ca91..52d8c072 100644 --- a/pumpkin/src/client/client_packet.rs +++ b/pumpkin/src/client/client_packet.rs @@ -71,7 +71,7 @@ impl Client { self.send_packet(packet); } - pub fn handle_encryption_response( + pub async fn handle_encryption_response( &mut self, server: &mut Server, encryption_response: SEncryptionResponse, @@ -96,7 +96,9 @@ impl Client { &hash, &ip, server, - ) { + ) + .await + { Ok(p) => { // Check if player should join if let Some(p) = &p.profile_actions { diff --git a/pumpkin/src/client/mod.rs b/pumpkin/src/client/mod.rs index e0359722..b7ddd230 100644 --- a/pumpkin/src/client/mod.rs +++ b/pumpkin/src/client/mod.rs @@ -156,17 +156,17 @@ impl Client { self.send_packet(CGameEvent::new(3, gamemode.to_f32().unwrap())); } - pub fn process_packets(&mut self, server: &mut Server) { + pub async fn process_packets(&mut self, server: &mut Server) { let mut i = 0; while i < self.client_packets_queue.len() { let mut packet = self.client_packets_queue.remove(i).unwrap(); - self.handle_packet(server, &mut packet); + self.handle_packet(server, &mut packet).await; i += 1; } } /// Handles an incoming decoded Packet - pub fn handle_packet(&mut self, server: &mut Server, packet: &mut RawPacket) { + pub async fn handle_packet(&mut self, server: &mut Server, packet: &mut RawPacket) { // TODO: handle each packet's Error instead of calling .unwrap() let bytebuf = &mut packet.bytebuf; match self.connection_state { @@ -198,7 +198,7 @@ impl Client { 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 @@ -267,7 +267,7 @@ impl Client { // Reads the connection until our buffer of len 4096 is full, then decode /// Close connection when an error occurs - pub fn poll(&mut self, server: &mut Server, event: &Event) { + pub async fn poll(&mut self, server: &mut Server, event: &Event) { if event.is_readable() { let mut received_data = vec![0; 4096]; let mut bytes_read = 0; @@ -302,7 +302,7 @@ impl Client { Ok(packet) => { if let Some(packet) = packet { self.add_packet(packet); - self.process_packets(server); + self.process_packets(server).await; } } Err(err) => self.kick(&err.to_string()), diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index 84b445fb..2746444a 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -131,7 +131,7 @@ async fn main() -> io::Result<()> { // Maybe received an event for a TCP connection. let done = if let Some(client) = connections.get_mut(&token) { let mut client = client.borrow_mut(); - client.poll(&mut server, event); + client.poll(&mut server, event).await; client.closed } else { // Sporadic events happen, we can safely ignore them. diff --git a/pumpkin/src/server.rs b/pumpkin/src/server.rs index c13c1b3e..61066f86 100644 --- a/pumpkin/src/server.rs +++ b/pumpkin/src/server.rs @@ -56,7 +56,7 @@ pub struct Server { pub advanced_config: AdvancedConfiguration, /// Used for Authentication, None is Online mode is disabled - pub auth_client: Option, + pub auth_client: Option, } impl Server { @@ -75,7 +75,7 @@ impl Server { ) .into_boxed_slice(); let auth_client = if config.0.online_mode { - Some(reqwest::blocking::Client::new()) + Some(reqwest::Client::new()) } else { None }; @@ -99,9 +99,9 @@ impl Server { } // Returns Tokens to remove - pub fn poll(&mut self, client: &mut Client, _poll: &Poll, event: &Event) { + pub async fn poll(&mut self, client: &mut Client, _poll: &Poll, event: &Event) { // TODO: Poll players in every world - client.poll(self, event) + client.poll(self, event).await } pub fn add_client(&mut self, token: Rc, client: Rc>) { From 33df6b0b1f68fb7399246ef218ffbf5685d3bf0e Mon Sep 17 00:00:00 2001 From: lukas0008 Date: Wed, 7 Aug 2024 21:16:00 +0200 Subject: [PATCH 6/7] Revert "Remove reqwest blocking feature" This reverts commit 76ce44e58d0f99ddbc76afa75331772156761c5b. --- Cargo.lock | 13 ++++++++++++- pumpkin-world/Cargo.toml | 3 +-- pumpkin/Cargo.toml | 2 +- pumpkin/src/client/authentication.rs | 5 ++--- pumpkin/src/client/client_packet.rs | 6 ++---- pumpkin/src/client/mod.rs | 12 ++++++------ pumpkin/src/main.rs | 2 +- pumpkin/src/server.rs | 8 ++++---- 8 files changed, 29 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c9d4122f..3523957d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -455,6 +455,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -463,6 +464,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + [[package]] name = "futures-sink" version = "0.3.30" @@ -482,9 +489,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-core", + "futures-io", + "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", + "slab", ] [[package]] @@ -1225,7 +1236,6 @@ dependencies = [ "fastnbt 2.5.0 (git+https://github.com/owengage/fastnbt.git)", "fastsnbt", "pumpkin-protocol", - "tokio", ] [[package]] @@ -1285,6 +1295,7 @@ dependencies = [ "base64", "bytes", "encoding_rs", + "futures-channel", "futures-core", "futures-util", "h2", diff --git a/pumpkin-world/Cargo.toml b/pumpkin-world/Cargo.toml index c100edab..56e82b44 100644 --- a/pumpkin-world/Cargo.toml +++ b/pumpkin-world/Cargo.toml @@ -7,5 +7,4 @@ edition.workspace = true pumpkin-protocol = { path = "../pumpkin-protocol"} fastanvil = "0.31" fastnbt = { git = "https://github.com/owengage/fastnbt.git" } -fastsnbt = "0.2" -tokio.workspace = true \ No newline at end of file +fastsnbt = "0.2" \ No newline at end of file diff --git a/pumpkin/Cargo.toml b/pumpkin/Cargo.toml index 0239c0f1..2572cf18 100644 --- a/pumpkin/Cargo.toml +++ b/pumpkin/Cargo.toml @@ -28,7 +28,7 @@ rsa-der = "0.3.0" flate2 = "1.0.30" # authentication -reqwest = { version = "0.12.5", features = ["json"]} +reqwest = { version = "0.12.5", features = ["json", "blocking"]} sha1 = "0.10.6" digest = "=0.11.0-pre.9" diff --git a/pumpkin/src/client/authentication.rs b/pumpkin/src/client/authentication.rs index e8761993..eaff1611 100644 --- a/pumpkin/src/client/authentication.rs +++ b/pumpkin/src/client/authentication.rs @@ -46,7 +46,7 @@ pub struct GameProfile { pub profile_actions: Option>, } -pub async fn authenticate( +pub fn authenticate( username: &str, server_hash: &str, ip: &IpAddr, @@ -69,14 +69,13 @@ pub async fn authenticate( .unwrap() .get(address) .send() - .await .map_err(|_| AuthError::FailedResponse)?; match response.status() { StatusCode::OK => {} StatusCode::NO_CONTENT => Err(AuthError::UnverifiedUsername)?, other => Err(AuthError::UnknownStatusCode(other.as_str().to_string()))?, } - let profile: GameProfile = response.json().await.map_err(|_| AuthError::FailedParse)?; + let profile: GameProfile = response.json().map_err(|_| AuthError::FailedParse)?; Ok(profile) } diff --git a/pumpkin/src/client/client_packet.rs b/pumpkin/src/client/client_packet.rs index 52d8c072..8a82ca91 100644 --- a/pumpkin/src/client/client_packet.rs +++ b/pumpkin/src/client/client_packet.rs @@ -71,7 +71,7 @@ impl Client { self.send_packet(packet); } - pub async fn handle_encryption_response( + pub fn handle_encryption_response( &mut self, server: &mut Server, encryption_response: SEncryptionResponse, @@ -96,9 +96,7 @@ impl Client { &hash, &ip, server, - ) - .await - { + ) { Ok(p) => { // Check if player should join if let Some(p) = &p.profile_actions { diff --git a/pumpkin/src/client/mod.rs b/pumpkin/src/client/mod.rs index b7ddd230..e0359722 100644 --- a/pumpkin/src/client/mod.rs +++ b/pumpkin/src/client/mod.rs @@ -156,17 +156,17 @@ impl Client { self.send_packet(CGameEvent::new(3, gamemode.to_f32().unwrap())); } - pub async fn process_packets(&mut self, server: &mut Server) { + pub fn process_packets(&mut self, server: &mut Server) { let mut i = 0; while i < self.client_packets_queue.len() { let mut packet = self.client_packets_queue.remove(i).unwrap(); - self.handle_packet(server, &mut packet).await; + self.handle_packet(server, &mut packet); i += 1; } } /// Handles an incoming decoded Packet - pub async fn handle_packet(&mut self, server: &mut Server, packet: &mut RawPacket) { + pub fn handle_packet(&mut self, server: &mut Server, packet: &mut RawPacket) { // TODO: handle each packet's Error instead of calling .unwrap() let bytebuf = &mut packet.bytebuf; match self.connection_state { @@ -198,7 +198,7 @@ impl Client { 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 @@ -267,7 +267,7 @@ impl Client { // Reads the connection until our buffer of len 4096 is full, then decode /// Close connection when an error occurs - pub async fn poll(&mut self, server: &mut Server, event: &Event) { + pub fn poll(&mut self, server: &mut Server, event: &Event) { if event.is_readable() { let mut received_data = vec![0; 4096]; let mut bytes_read = 0; @@ -302,7 +302,7 @@ impl Client { Ok(packet) => { if let Some(packet) = packet { self.add_packet(packet); - self.process_packets(server).await; + self.process_packets(server); } } Err(err) => self.kick(&err.to_string()), diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index 2746444a..84b445fb 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -131,7 +131,7 @@ async fn main() -> io::Result<()> { // Maybe received an event for a TCP connection. let done = if let Some(client) = connections.get_mut(&token) { let mut client = client.borrow_mut(); - client.poll(&mut server, event).await; + client.poll(&mut server, event); client.closed } else { // Sporadic events happen, we can safely ignore them. diff --git a/pumpkin/src/server.rs b/pumpkin/src/server.rs index 61066f86..c13c1b3e 100644 --- a/pumpkin/src/server.rs +++ b/pumpkin/src/server.rs @@ -56,7 +56,7 @@ pub struct Server { pub advanced_config: AdvancedConfiguration, /// Used for Authentication, None is Online mode is disabled - pub auth_client: Option, + pub auth_client: Option, } impl Server { @@ -75,7 +75,7 @@ impl Server { ) .into_boxed_slice(); let auth_client = if config.0.online_mode { - Some(reqwest::Client::new()) + Some(reqwest::blocking::Client::new()) } else { None }; @@ -99,9 +99,9 @@ impl Server { } // Returns Tokens to remove - pub async fn poll(&mut self, client: &mut Client, _poll: &Poll, event: &Event) { + pub fn poll(&mut self, client: &mut Client, _poll: &Poll, event: &Event) { // TODO: Poll players in every world - client.poll(self, event).await + client.poll(self, event) } pub fn add_client(&mut self, token: Rc, client: Rc>) { From fc4c9b3b989c75e2cb59cf4e9c20720f2d1877c4 Mon Sep 17 00:00:00 2001 From: lukas0008 Date: Wed, 7 Aug 2024 21:16:03 +0200 Subject: [PATCH 7/7] Revert "Reapply "Tokio"" This reverts commit f1b7d649dbfb4fdd0809c4cf5a014442f9abbe1a. --- Cargo.lock | 13 ------------- Cargo.toml | 3 --- pumpkin/Cargo.toml | 3 ++- pumpkin/src/main.rs | 3 +-- 4 files changed, 3 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3523957d..55ce38c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1177,7 +1177,6 @@ dependencies = [ "sha1", "simple_logger", "thiserror", - "tokio", "toml", "uuid", ] @@ -1789,21 +1788,9 @@ dependencies = [ "mio", "pin-project-lite", "socket2", - "tokio-macros", "windows-sys 0.52.0", ] -[[package]] -name = "tokio-macros" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.72", -] - [[package]] name = "tokio-native-tls" version = "0.3.1" diff --git a/Cargo.toml b/Cargo.toml index 158cf41d..7ce9d72c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,3 @@ edition = "2021" [profile.release] lto = true - -[workspace.dependencies] -tokio = { version = "1.39.2", features = ["net", "macros", "rt-multi-thread", "fs", "io-util"] } diff --git a/pumpkin/Cargo.toml b/pumpkin/Cargo.toml index 2572cf18..3f9fe1c1 100644 --- a/pumpkin/Cargo.toml +++ b/pumpkin/Cargo.toml @@ -49,4 +49,5 @@ crossbeam-channel = "0.5.13" uuid = { version = "1.10", features = ["serde"]} -tokio.workspace = true \ No newline at end of file + + diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index 84b445fb..66bae804 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -23,8 +23,7 @@ pub mod server; pub mod util; #[cfg(not(target_os = "wasi"))] -#[tokio::main] -async fn main() -> io::Result<()> { +fn main() -> io::Result<()> { use std::{cell::RefCell, time::Instant}; let time = Instant::now();