mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
start implementing other packets and stuff
This commit is contained in:
parent
1c9e089b72
commit
2e11f5a564
6 changed files with 54 additions and 9 deletions
2
README.md
Normal file
2
README.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
# this library doesn't have a name yet idk what to call it
|
||||
|
|
@ -2,7 +2,7 @@ use minecraft_client::connect::join_server;
|
|||
use tokio::runtime::Runtime;
|
||||
|
||||
async fn bot() {
|
||||
let address = "localhost:62072";
|
||||
let address = "localhost:50388";
|
||||
let _response = join_server(&address.try_into().unwrap()).await.unwrap();
|
||||
// println!("{}", response.description.to_ansi(None));
|
||||
println!("connected");
|
||||
|
|
|
@ -33,11 +33,18 @@ pub async fn join_server(address: &ServerAddress) -> Result<(), String> {
|
|||
conn.write(ServerboundHelloPacket { username }.get()).await;
|
||||
|
||||
// encryption request
|
||||
let packet = conn.read().await.unwrap();
|
||||
let _encryption_request_packet = match packet {
|
||||
LoginPacket::ClientboundHelloPacket(p) => p,
|
||||
_ => return Err(format!("Invalid packet type: {:?}", packet)),
|
||||
};
|
||||
loop {
|
||||
let packet = conn.read().await.unwrap();
|
||||
match packet {
|
||||
LoginPacket::ClientboundHelloPacket(encryption_request_packet) => {
|
||||
println!(
|
||||
"Got encryption request {:?} {:?}",
|
||||
encryption_request_packet.nonce, encryption_request_packet.public_key
|
||||
);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: client auth
|
||||
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
trait PacketListener {
|
||||
handle(Packet)
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
use std::hash::Hash;
|
||||
use tokio::io::BufReader;
|
||||
|
||||
use crate::mc_buf;
|
||||
|
||||
use super::LoginPacket;
|
||||
|
||||
#[derive(Hash, Clone, Debug)]
|
||||
pub struct ClientboundCustomQueryPacket {
|
||||
pub transacton_id: u32,
|
||||
// TODO: this should be a resource location
|
||||
pub identifier: String,
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
impl ClientboundHelloPacket {
|
||||
pub fn get(self) -> LoginPacket {
|
||||
LoginPacket::ClientboundHelloPacket(self)
|
||||
}
|
||||
|
||||
pub fn write(&self, _buf: &mut Vec<u8>) {
|
||||
panic!("ClientboundHelloPacket::write not implemented")
|
||||
}
|
||||
|
||||
pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
|
||||
buf: &mut BufReader<T>,
|
||||
) -> Result<LoginPacket, String> {
|
||||
// let server_id = mc_buf::read_utf_with_len(buf, 20).await?;
|
||||
// let public_key = mc_buf::read_byte_array(buf).await?;
|
||||
// let nonce = mc_buf::read_byte_array(buf).await?;
|
||||
|
||||
// Ok(ClientboundHelloPacket {
|
||||
// server_id,
|
||||
// public_key,
|
||||
// nonce,
|
||||
// }
|
||||
// .get())
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue