Revert "Remove reqwest blocking feature"
This reverts commit 76ce44e58d.
This commit is contained in:
parent
76ce44e58d
commit
33df6b0b1f
13
Cargo.lock
generated
13
Cargo.lock
generated
@ -455,6 +455,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78"
|
checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
|
"futures-sink",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -463,6 +464,12 @@ version = "0.3.30"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d"
|
checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-io"
|
||||||
|
version = "0.3.30"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-sink"
|
name = "futures-sink"
|
||||||
version = "0.3.30"
|
version = "0.3.30"
|
||||||
@ -482,9 +489,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48"
|
checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
|
"futures-io",
|
||||||
|
"futures-sink",
|
||||||
"futures-task",
|
"futures-task",
|
||||||
|
"memchr",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"pin-utils",
|
"pin-utils",
|
||||||
|
"slab",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1225,7 +1236,6 @@ dependencies = [
|
|||||||
"fastnbt 2.5.0 (git+https://github.com/owengage/fastnbt.git)",
|
"fastnbt 2.5.0 (git+https://github.com/owengage/fastnbt.git)",
|
||||||
"fastsnbt",
|
"fastsnbt",
|
||||||
"pumpkin-protocol",
|
"pumpkin-protocol",
|
||||||
"tokio",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1285,6 +1295,7 @@ dependencies = [
|
|||||||
"base64",
|
"base64",
|
||||||
"bytes",
|
"bytes",
|
||||||
"encoding_rs",
|
"encoding_rs",
|
||||||
|
"futures-channel",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"h2",
|
"h2",
|
||||||
|
|||||||
@ -8,4 +8,3 @@ pumpkin-protocol = { path = "../pumpkin-protocol"}
|
|||||||
fastanvil = "0.31"
|
fastanvil = "0.31"
|
||||||
fastnbt = { git = "https://github.com/owengage/fastnbt.git" }
|
fastnbt = { git = "https://github.com/owengage/fastnbt.git" }
|
||||||
fastsnbt = "0.2"
|
fastsnbt = "0.2"
|
||||||
tokio.workspace = true
|
|
||||||
@ -28,7 +28,7 @@ rsa-der = "0.3.0"
|
|||||||
flate2 = "1.0.30"
|
flate2 = "1.0.30"
|
||||||
|
|
||||||
# authentication
|
# authentication
|
||||||
reqwest = { version = "0.12.5", features = ["json"]}
|
reqwest = { version = "0.12.5", features = ["json", "blocking"]}
|
||||||
|
|
||||||
sha1 = "0.10.6"
|
sha1 = "0.10.6"
|
||||||
digest = "=0.11.0-pre.9"
|
digest = "=0.11.0-pre.9"
|
||||||
|
|||||||
@ -46,7 +46,7 @@ pub struct GameProfile {
|
|||||||
pub profile_actions: Option<Vec<ProfileAction>>,
|
pub profile_actions: Option<Vec<ProfileAction>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn authenticate(
|
pub fn authenticate(
|
||||||
username: &str,
|
username: &str,
|
||||||
server_hash: &str,
|
server_hash: &str,
|
||||||
ip: &IpAddr,
|
ip: &IpAddr,
|
||||||
@ -69,14 +69,13 @@ pub async fn authenticate(
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.get(address)
|
.get(address)
|
||||||
.send()
|
.send()
|
||||||
.await
|
|
||||||
.map_err(|_| AuthError::FailedResponse)?;
|
.map_err(|_| AuthError::FailedResponse)?;
|
||||||
match response.status() {
|
match response.status() {
|
||||||
StatusCode::OK => {}
|
StatusCode::OK => {}
|
||||||
StatusCode::NO_CONTENT => Err(AuthError::UnverifiedUsername)?,
|
StatusCode::NO_CONTENT => Err(AuthError::UnverifiedUsername)?,
|
||||||
other => Err(AuthError::UnknownStatusCode(other.as_str().to_string()))?,
|
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)
|
Ok(profile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -71,7 +71,7 @@ impl Client {
|
|||||||
self.send_packet(packet);
|
self.send_packet(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn handle_encryption_response(
|
pub fn handle_encryption_response(
|
||||||
&mut self,
|
&mut self,
|
||||||
server: &mut Server,
|
server: &mut Server,
|
||||||
encryption_response: SEncryptionResponse,
|
encryption_response: SEncryptionResponse,
|
||||||
@ -96,9 +96,7 @@ impl Client {
|
|||||||
&hash,
|
&hash,
|
||||||
&ip,
|
&ip,
|
||||||
server,
|
server,
|
||||||
)
|
) {
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(p) => {
|
Ok(p) => {
|
||||||
// Check if player should join
|
// Check if player should join
|
||||||
if let Some(p) = &p.profile_actions {
|
if let Some(p) = &p.profile_actions {
|
||||||
|
|||||||
@ -156,17 +156,17 @@ impl Client {
|
|||||||
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) {
|
pub fn process_packets(&mut self, server: &mut Server) {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while i < self.client_packets_queue.len() {
|
while i < self.client_packets_queue.len() {
|
||||||
let mut packet = self.client_packets_queue.remove(i).unwrap();
|
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;
|
i += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles an incoming decoded Packet
|
/// 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()
|
// TODO: handle each packet's Error instead of calling .unwrap()
|
||||||
let bytebuf = &mut packet.bytebuf;
|
let bytebuf = &mut packet.bytebuf;
|
||||||
match self.connection_state {
|
match self.connection_state {
|
||||||
@ -198,7 +198,7 @@ impl Client {
|
|||||||
SEncryptionResponse::PACKET_ID => self.handle_encryption_response(
|
SEncryptionResponse::PACKET_ID => self.handle_encryption_response(
|
||||||
server,
|
server,
|
||||||
SEncryptionResponse::read(bytebuf).unwrap(),
|
SEncryptionResponse::read(bytebuf).unwrap(),
|
||||||
).await,
|
),
|
||||||
SLoginPluginResponse::PACKET_ID => self
|
SLoginPluginResponse::PACKET_ID => self
|
||||||
.handle_plugin_response(server, SLoginPluginResponse::read(bytebuf).unwrap()),
|
.handle_plugin_response(server, SLoginPluginResponse::read(bytebuf).unwrap()),
|
||||||
SLoginAcknowledged::PACKET_ID => self
|
SLoginAcknowledged::PACKET_ID => self
|
||||||
@ -267,7 +267,7 @@ impl Client {
|
|||||||
|
|
||||||
// Reads the connection until our buffer of len 4096 is full, then decode
|
// Reads the connection until our buffer of len 4096 is full, then decode
|
||||||
/// Close connection when an error occurs
|
/// 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() {
|
if event.is_readable() {
|
||||||
let mut received_data = vec![0; 4096];
|
let mut received_data = vec![0; 4096];
|
||||||
let mut bytes_read = 0;
|
let mut bytes_read = 0;
|
||||||
@ -302,7 +302,7 @@ impl Client {
|
|||||||
Ok(packet) => {
|
Ok(packet) => {
|
||||||
if let Some(packet) = packet {
|
if let Some(packet) = packet {
|
||||||
self.add_packet(packet);
|
self.add_packet(packet);
|
||||||
self.process_packets(server).await;
|
self.process_packets(server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => self.kick(&err.to_string()),
|
Err(err) => self.kick(&err.to_string()),
|
||||||
|
|||||||
@ -131,7 +131,7 @@ async fn main() -> io::Result<()> {
|
|||||||
// Maybe received an event for a TCP connection.
|
// Maybe received an event for a TCP connection.
|
||||||
let done = if let Some(client) = connections.get_mut(&token) {
|
let done = if let Some(client) = connections.get_mut(&token) {
|
||||||
let mut client = client.borrow_mut();
|
let mut client = client.borrow_mut();
|
||||||
client.poll(&mut server, event).await;
|
client.poll(&mut server, event);
|
||||||
client.closed
|
client.closed
|
||||||
} else {
|
} else {
|
||||||
// Sporadic events happen, we can safely ignore them.
|
// Sporadic events happen, we can safely ignore them.
|
||||||
|
|||||||
@ -56,7 +56,7 @@ pub struct Server {
|
|||||||
pub advanced_config: AdvancedConfiguration,
|
pub advanced_config: AdvancedConfiguration,
|
||||||
|
|
||||||
/// Used for Authentication, None is Online mode is disabled
|
/// Used for Authentication, None is Online mode is disabled
|
||||||
pub auth_client: Option<reqwest::Client>,
|
pub auth_client: Option<reqwest::blocking::Client>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Server {
|
impl Server {
|
||||||
@ -75,7 +75,7 @@ impl Server {
|
|||||||
)
|
)
|
||||||
.into_boxed_slice();
|
.into_boxed_slice();
|
||||||
let auth_client = if config.0.online_mode {
|
let auth_client = if config.0.online_mode {
|
||||||
Some(reqwest::Client::new())
|
Some(reqwest::blocking::Client::new())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
@ -99,9 +99,9 @@ impl Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns Tokens to remove
|
// 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
|
// TODO: Poll players in every world
|
||||||
client.poll(self, event).await
|
client.poll(self, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_client(&mut self, token: Rc<Token>, client: Rc<RefCell<Client>>) {
|
pub fn add_client(&mut self, token: Rc<Token>, client: Rc<RefCell<Client>>) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user