mirror of
https://github.com/GIKExe/rust_mc_serv.git
synced 2025-06-23 18:02:57 +03:00
до Configuration
This commit is contained in:
parent
1124373d21
commit
9a15eb92e5
24
Cargo.lock
generated
24
Cargo.lock
generated
@ -178,7 +178,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ced92e76e966ca2fd84c8f7aa01a4aea65b0eb6648d72f7c8f3e2764a67fece"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"libz-sys",
|
||||
"miniz_oxide",
|
||||
]
|
||||
|
||||
@ -286,17 +285,6 @@ version = "0.2.172"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
|
||||
|
||||
[[package]]
|
||||
name = "libz-sys"
|
||||
version = "1.1.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b70e7a7df205e92a1a4cd9aaae7898dac0aa555503cc0a649494d0d60e7651d"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"pkg-config",
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.12"
|
||||
@ -398,12 +386,6 @@ version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
|
||||
|
||||
[[package]]
|
||||
name = "powerfmt"
|
||||
version = "0.2.0"
|
||||
@ -648,12 +630,6 @@ version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
|
@ -5,7 +5,7 @@ edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
tokio = {version = "1.45.0", features = ["full"]}
|
||||
flate2 = {version = "1.1.1", features = ["zlib"]}
|
||||
flate2 = {version = "1.1.1"}
|
||||
serde = {version = "1.0.219", features = ["derive"]}
|
||||
serde_with = "3.12.0"
|
||||
serde_json = "1.0.140"
|
||||
|
38
src/cycle.rs
38
src/cycle.rs
@ -1,5 +1,5 @@
|
||||
|
||||
use tokio::net::TcpStream;
|
||||
use tokio::{net::TcpStream, time::Sleep};
|
||||
|
||||
use crate::data::{clientbound, serverbound, AsyncReader, AsyncWriter, DataError, Packet, Reader, TextComponentBuilder, Writer};
|
||||
|
||||
@ -50,10 +50,13 @@ async fn read_first_packet(stream: &mut TcpStream) -> Result<(), PacketError> {
|
||||
}
|
||||
|
||||
match ns {
|
||||
1 => the_status(stream).await,
|
||||
2 => the_login(stream, (version, host, port)).await,
|
||||
_ => Err(PacketError::NextStateIncorrect)
|
||||
}
|
||||
1 => return the_status(stream).await,
|
||||
2 => the_login(stream, (version, host, port)).await?,
|
||||
_ => return Err(PacketError::NextStateIncorrect)
|
||||
};
|
||||
|
||||
the_configuration(stream).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn the_status(stream: &mut TcpStream) -> Result<(), PacketError> {
|
||||
@ -112,12 +115,29 @@ async fn the_login(stream: &mut TcpStream, data: (i32, String, u16)) -> Result<(
|
||||
let username = packet.read_string()?;
|
||||
let uuid = packet.read_uuid()?;
|
||||
|
||||
println!("Адрес клиента: {:?}", stream.peer_addr());
|
||||
println!("Адрес сервера: {}:{}", data.1, data.2);
|
||||
println!("Username: {username}\n UUID: {:X}", uuid);
|
||||
// println!("Адрес клиента: {}", stream.peer_addr().unwrap());
|
||||
// println!("Адрес сервера: {}:{}", data.1, data.2);
|
||||
// println!("Username: {username}\nUUID: {:X}", uuid);
|
||||
|
||||
let threshold = 512usize;
|
||||
let mut packet = Packet::empty(clientbound::login::SET_COMPRESSION);
|
||||
packet.write_varint(512)?;
|
||||
packet.write_varint(threshold as i32)?;
|
||||
stream.write_packet(packet, None).await?;
|
||||
|
||||
let mut packet = Packet::empty(clientbound::login::SUCCESS);
|
||||
packet.write_uuid(uuid)?;
|
||||
packet.write_string(&username)?;
|
||||
packet.write_varint(0)?;
|
||||
stream.write_packet(packet, Some(threshold)).await?;
|
||||
|
||||
let packet = stream.read_packet(Some(threshold)).await?;
|
||||
if packet.id() != serverbound::login::ACKNOWLEDGED { return Err(PacketError::WrongPacketID); }
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn the_configuration(stream: &mut TcpStream) -> Result<(), PacketError> {
|
||||
loop {
|
||||
|
||||
}
|
||||
}
|
@ -52,7 +52,7 @@ pub trait AsyncWriter {
|
||||
|
||||
if data_buf.len() > threshold {
|
||||
packet_buf.write_varint(data_buf.len() as i32)?;
|
||||
let compressed_data = compress(&data_buf, 5)?;
|
||||
let compressed_data = compress(&data_buf)?;
|
||||
Write::write_all(&mut packet_buf, &compressed_data).or(Err(DataError::WriteError))?;
|
||||
} else {
|
||||
packet_buf.write_varint(0)?;
|
||||
|
@ -1,5 +1,7 @@
|
||||
use std::io::{Read, Write};
|
||||
|
||||
use flate2::{read::ZlibDecoder, write::ZlibEncoder, Compression};
|
||||
|
||||
use crate::inet::InetError;
|
||||
|
||||
mod async_reader;
|
||||
@ -30,8 +32,8 @@ pub fn decompress(bytes: &[u8]) -> Result<Vec<u8>, DataError> {
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
pub fn compress(bytes: &[u8], compression: u32) -> Result<Vec<u8>, DataError> {
|
||||
let mut encoder = ZlibEncoder::new(Vec::new(), Compression::new(compression));
|
||||
pub fn compress(bytes: &[u8]) -> Result<Vec<u8>, DataError> {
|
||||
let mut encoder = ZlibEncoder::new(Vec::new(), Compression::new(1));
|
||||
encoder.write_all(bytes).or(Err(DataError::ZlibError))?;
|
||||
encoder.finish().or(Err(DataError::ZlibError))
|
||||
}
|
||||
@ -40,7 +42,6 @@ pub use async_reader::*;
|
||||
pub use reader::*;
|
||||
pub use async_writer::*;
|
||||
pub use writer::*;
|
||||
use flate2::{bufread::ZlibDecoder, write::ZlibEncoder, Compression};
|
||||
pub use packet::*;
|
||||
pub use packet_id::{clientbound, serverbound};
|
||||
pub use component::*;
|
@ -50,7 +50,7 @@ pub trait Writer {
|
||||
|
||||
if data_buf.len() > threshold {
|
||||
packet_buf.write_varint(data_buf.len() as i32)?;
|
||||
let compressed_data = compress(&data_buf, 5)?;
|
||||
let compressed_data = compress(&data_buf)?;
|
||||
Write::write_all(&mut packet_buf, &compressed_data).or(Err(DataError::WriteError))?;
|
||||
} else {
|
||||
packet_buf.write_varint(0)?;
|
||||
|
Loading…
x
Reference in New Issue
Block a user