1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00
This commit is contained in:
mat 2022-05-03 18:20:24 +00:00
parent 477c367fc4
commit c987812927
17 changed files with 60 additions and 75 deletions

View file

@ -13,8 +13,8 @@ use azalea_protocol::{
}, },
resolver, ServerAddress, resolver, ServerAddress,
}; };
use azalea_world::{Chunk, ChunkStorage, World}; use azalea_world::{ChunkStorage, World};
use std::{fmt::Debug, ops::Deref, sync::Arc}; use std::{fmt::Debug, sync::Arc};
use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
use tokio::sync::Mutex; use tokio::sync::Mutex;
@ -34,8 +34,8 @@ pub struct ClientState {
/// A player that you can control that is currently in a Minecraft server. /// A player that you can control that is currently in a Minecraft server.
pub struct Client { pub struct Client {
event_receiver: UnboundedReceiver<Event>, event_receiver: UnboundedReceiver<Event>,
conn: Arc<Mutex<GameConnection>>, pub conn: Arc<Mutex<GameConnection>>,
state: Arc<Mutex<ClientState>>, pub state: Arc<Mutex<ClientState>>,
// game_loop // game_loop
} }
@ -133,10 +133,9 @@ impl Client {
// just start up the game loop and we're ready! // just start up the game loop and we're ready!
// tokio::spawn(Self::game_loop(conn, tx, handler, state)) // tokio::spawn(Self::game_loop(conn, tx, handler, state))
let game_loop_conn = conn.clone();
let game_loop_state = client.state.clone(); let game_loop_state = client.state.clone();
tokio::spawn(Self::game_loop(game_loop_conn, tx, game_loop_state)); tokio::spawn(Self::game_loop(conn, tx, game_loop_state));
Ok(client) Ok(client)
} }
@ -221,7 +220,7 @@ impl Client {
GamePacket::ClientboundChangeDifficultyPacket(p) => { GamePacket::ClientboundChangeDifficultyPacket(p) => {
println!("Got difficulty packet {:?}", p); println!("Got difficulty packet {:?}", p);
} }
GamePacket::ClientboundDeclareCommandsPacket(p) => { GamePacket::ClientboundDeclareCommandsPacket(_p) => {
println!("Got declare commands packet"); println!("Got declare commands packet");
} }
GamePacket::ClientboundPlayerAbilitiesPacket(p) => { GamePacket::ClientboundPlayerAbilitiesPacket(p) => {
@ -230,19 +229,19 @@ impl Client {
GamePacket::ClientboundSetCarriedItemPacket(p) => { GamePacket::ClientboundSetCarriedItemPacket(p) => {
println!("Got set carried item packet {:?}", p); println!("Got set carried item packet {:?}", p);
} }
GamePacket::ClientboundUpdateTagsPacket(p) => { GamePacket::ClientboundUpdateTagsPacket(_p) => {
println!("Got update tags packet"); println!("Got update tags packet");
} }
GamePacket::ClientboundDisconnectPacket(p) => { GamePacket::ClientboundDisconnectPacket(p) => {
println!("Got disconnect packet {:?}", p); println!("Got disconnect packet {:?}", p);
} }
GamePacket::ClientboundUpdateRecipesPacket(p) => { GamePacket::ClientboundUpdateRecipesPacket(_p) => {
println!("Got update recipes packet"); println!("Got update recipes packet");
} }
GamePacket::ClientboundEntityEventPacket(p) => { GamePacket::ClientboundEntityEventPacket(p) => {
println!("Got entity event packet {:?}", p); println!("Got entity event packet {:?}", p);
} }
GamePacket::ClientboundRecipePacket(p) => { GamePacket::ClientboundRecipePacket(_p) => {
println!("Got recipe packet"); println!("Got recipe packet");
} }
GamePacket::ClientboundPlayerPositionPacket(p) => { GamePacket::ClientboundPlayerPositionPacket(p) => {

View file

@ -1,5 +1,4 @@
use crate::Entity; use crate::Entity;
use azalea_world::World;
#[derive(Default)] #[derive(Default)]
pub struct Player { pub struct Player {

View file

@ -1,9 +1,6 @@
use aes::cipher::inout::InOutBuf; use aes::cipher::inout::InOutBuf;
use aes::cipher::BlockEncrypt;
use aes::{ use aes::{
cipher::{ cipher::{BlockDecryptMut, BlockEncryptMut, KeyIvInit},
generic_array::GenericArray, AsyncStreamCipher, BlockDecryptMut, BlockEncryptMut, KeyIvInit,
},
Aes128, Aes128,
}; };
use rand::{rngs::OsRng, RngCore}; use rand::{rngs::OsRng, RngCore};
@ -15,7 +12,7 @@ fn generate_secret_key() -> [u8; 16] {
key key
} }
fn digest_data(server_id: &[u8], public_key: &[u8], private_key: &[u8]) -> Vec<u8> { pub fn digest_data(server_id: &[u8], public_key: &[u8], private_key: &[u8]) -> Vec<u8> {
let mut digest = Sha1::new(); let mut digest = Sha1::new();
digest.update(server_id); digest.update(server_id);
digest.update(public_key); digest.update(public_key);
@ -23,7 +20,7 @@ fn digest_data(server_id: &[u8], public_key: &[u8], private_key: &[u8]) -> Vec<u
digest.finalize().to_vec() digest.finalize().to_vec()
} }
fn hex_digest(digest: &[u8]) -> String { pub fn hex_digest(digest: &[u8]) -> String {
// Note that the Sha1.hexdigest() method used by minecraft is non standard. // Note that the Sha1.hexdigest() method used by minecraft is non standard.
// It doesn't match the digest method found in most programming languages // It doesn't match the digest method found in most programming languages
// and libraries. It works by treating the sha1 output bytes as one large // and libraries. It works by treating the sha1 output bytes as one large
@ -48,9 +45,8 @@ pub fn encrypt(public_key: &[u8], nonce: &[u8]) -> Result<EncryptResult, String>
// this.keybytes = Crypt.encryptUsingKey(publicKey, secretKey.getEncoded()); // this.keybytes = Crypt.encryptUsingKey(publicKey, secretKey.getEncoded());
// this.nonce = Crypt.encryptUsingKey(publicKey, arrby); // this.nonce = Crypt.encryptUsingKey(publicKey, arrby);
let encrypted_public_key: Vec<u8> = let encrypted_public_key: Vec<u8> = rsa_public_encrypt_pkcs1::encrypt(public_key, &secret_key)?;
rsa_public_encrypt_pkcs1::encrypt(&public_key, &secret_key)?; let encrypted_nonce: Vec<u8> = rsa_public_encrypt_pkcs1::encrypt(public_key, nonce)?;
let encrypted_nonce: Vec<u8> = rsa_public_encrypt_pkcs1::encrypt(&public_key, &nonce)?;
Ok(EncryptResult { Ok(EncryptResult {
secret_key, secret_key,

View file

@ -98,7 +98,7 @@ fn write_compound(
if end_tag { if end_tag {
writer.write_u8(Tag::End.id())?; writer.write_u8(Tag::End.id())?;
} }
return Ok(()); Ok(())
} }
#[inline] #[inline]

View file

@ -232,13 +232,12 @@ struct PacketIdMap {
impl Parse for PacketIdMap { impl Parse for PacketIdMap {
fn parse(input: ParseStream) -> Result<Self> { fn parse(input: ParseStream) -> Result<Self> {
let mut packets = vec![]; let mut packets = vec![];
loop {
// example:
// 0x0e: clientbound_change_difficulty_packet::ClientboundChangeDifficultyPacket, // 0x0e: clientbound_change_difficulty_packet::ClientboundChangeDifficultyPacket,
// 0x0e // 0x0e
let packet_id: LitInt = match input.parse() { while let Ok(packet_id) = input.parse::<LitInt>() {
Ok(i) => i,
Err(_) => break,
};
let packet_id = packet_id.base10_parse::<u32>()?; let packet_id = packet_id.base10_parse::<u32>()?;
// : // :
input.parse::<Token![:]>()?; input.parse::<Token![:]>()?;

View file

@ -1,10 +1,10 @@
use super::{BitSet, UnsizedByteArray, MAX_STRING_LENGTH}; use super::{UnsizedByteArray, MAX_STRING_LENGTH};
use azalea_chat::component::Component; use azalea_chat::component::Component;
use azalea_core::{ use azalea_core::{
difficulty::Difficulty, game_type::GameType, resource_location::ResourceLocation, difficulty::Difficulty, game_type::GameType, resource_location::ResourceLocation,
serializable_uuid::SerializableUuid, BlockPos, Direction, Slot, SlotData, serializable_uuid::SerializableUuid, BlockPos, Direction, Slot, SlotData,
}; };
use byteorder::{ReadBytesExt, WriteBytesExt, BE}; use byteorder::{ReadBytesExt, BE};
use serde::Deserialize; use serde::Deserialize;
use std::io::Read; use std::io::Read;
use tokio::io::{AsyncRead, AsyncReadExt}; use tokio::io::{AsyncRead, AsyncReadExt};
@ -421,7 +421,7 @@ impl McBufReadable for Component {
fn read_into(buf: &mut impl Read) -> Result<Self, String> { fn read_into(buf: &mut impl Read) -> Result<Self, String> {
let string = buf.read_utf()?; let string = buf.read_utf()?;
let json: serde_json::Value = serde_json::from_str(string.as_str()) let json: serde_json::Value = serde_json::from_str(string.as_str())
.map_err(|e| "Component isn't valid JSON".to_string())?; .map_err(|_| "Component isn't valid JSON".to_string())?;
let component = Component::deserialize(json).map_err(|e| e.to_string())?; let component = Component::deserialize(json).map_err(|e| e.to_string())?;
Ok(component) Ok(component)
} }

View file

@ -20,8 +20,8 @@ pub trait Writable: Write {
Ok(()) Ok(())
} }
fn write_int_id_list(&mut self, list: &Vec<i32>) -> Result<(), std::io::Error> { fn write_int_id_list(&mut self, list: &[i32]) -> Result<(), std::io::Error> {
self.write_list(&list, |buf, n| buf.write_varint(*n)) self.write_list(list, |buf, n| buf.write_varint(*n))
} }
fn write_map<KF, VF, KT, VT>( fn write_map<KF, VF, KT, VT>(
@ -47,7 +47,7 @@ pub trait Writable: Write {
} }
fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), std::io::Error> { fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), std::io::Error> {
self.write_all(bytes); self.write_all(bytes)?;
Ok(()) Ok(())
} }
@ -333,7 +333,7 @@ impl McBufWritable for Component {
// let component = Component::deserialize(json).map_err(|e| e.to_string())?; // let component = Component::deserialize(json).map_err(|e| e.to_string())?;
// Ok(component) // Ok(component)
// } // }
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { fn write_into(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> {
// component doesn't have serialize implemented yet // component doesn't have serialize implemented yet
todo!() todo!()
} }

View file

@ -281,7 +281,7 @@ impl McBufReadable for BrigadierParser {
} }
} }
// azalea_brigadier::tree::CommandNode // TODO: BrigadierNodeStub should have more stuff
impl McBufReadable for BrigadierNodeStub { impl McBufReadable for BrigadierNodeStub {
fn read_into(buf: &mut impl Read) -> Result<Self, String> { fn read_into(buf: &mut impl Read) -> Result<Self, String> {
let flags = u8::read_into(buf)?; let flags = u8::read_into(buf)?;
@ -292,20 +292,18 @@ impl McBufReadable for BrigadierNodeStub {
} }
let node_type = flags & 0x03; let node_type = flags & 0x03;
let is_executable = flags & 0x04 != 0; let _is_executable = flags & 0x04 != 0;
let has_redirect = flags & 0x08 != 0; let has_redirect = flags & 0x08 != 0;
let has_suggestions_type = flags & 0x10 != 0; let has_suggestions_type = flags & 0x10 != 0;
let children = buf.read_int_id_list()?; let _children = buf.read_int_id_list()?;
let redirect_node = if has_redirect { buf.read_varint()? } else { 0 }; let _redirect_node = if has_redirect { buf.read_varint()? } else { 0 };
// argument node // argument node
if node_type == 2 { if node_type == 2 {
let name = buf.read_utf()?; let _name = buf.read_utf()?;
let _parser = BrigadierParser::read_into(buf)?;
let parser = BrigadierParser::read_into(buf)?; let _suggestions_type = if has_suggestions_type {
let suggestions_type = if has_suggestions_type {
Some(buf.read_resource_location()?) Some(buf.read_resource_location()?)
} else { } else {
None None
@ -314,7 +312,7 @@ impl McBufReadable for BrigadierNodeStub {
} }
// literal node // literal node
if node_type == 1 { if node_type == 1 {
let name = buf.read_utf()?; let _name = buf.read_utf()?;
return Ok(BrigadierNodeStub {}); return Ok(BrigadierNodeStub {});
} }
Ok(BrigadierNodeStub {}) Ok(BrigadierNodeStub {})

View file

@ -1,5 +1,4 @@
use crate::mc_buf::BitSet; use crate::mc_buf::BitSet;
use azalea_core::{game_type::GameType, resource_location::ResourceLocation};
use packet_macros::{GamePacket, McBufReadable, McBufWritable}; use packet_macros::{GamePacket, McBufReadable, McBufWritable};
#[derive(Clone, Debug, GamePacket)] #[derive(Clone, Debug, GamePacket)]

View file

@ -34,16 +34,16 @@ impl McBufWritable for PlayerAbilitiesFlags {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
let mut byte = 0; let mut byte = 0;
if self.invulnerable { if self.invulnerable {
byte = byte | 1; byte |= 0b1;
} }
if self.flying { if self.flying {
byte = byte | 2; byte |= 0b10;
} }
if self.can_fly { if self.can_fly {
byte = byte | 4; byte |= 0b100;
} }
if self.instant_break { if self.instant_break {
byte = byte | 8; byte |= 0b1000;
} }
u8::write_into(&byte, buf) u8::write_into(&byte, buf)
} }

View file

@ -43,19 +43,19 @@ impl McBufWritable for RelativeArguments {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
let mut byte = 0; let mut byte = 0;
if self.x { if self.x {
byte = byte | 0b1; byte |= 0b1;
} }
if self.y { if self.y {
byte = byte | 0b10; byte |= 0b10;
} }
if self.z { if self.z {
byte = byte | 0b100; byte |= 0b100;
} }
if self.y_rot { if self.y_rot {
byte = byte | 0b1000; byte |= 0b1000;
} }
if self.x_rot { if self.x_rot {
byte = byte | 0b10000; byte |= 0b10000;
} }
u8::write_into(&byte, buf) u8::write_into(&byte, buf)
} }

View file

@ -1,5 +1,5 @@
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable}; use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
use azalea_core::{resource_location::ResourceLocation, Slot}; use azalea_core::resource_location::ResourceLocation;
use packet_macros::{GamePacket, McBufReadable, McBufWritable}; use packet_macros::{GamePacket, McBufReadable, McBufWritable};
use std::io::{Read, Write}; use std::io::{Read, Write};
@ -41,7 +41,7 @@ impl McBufWritable for State {
} }
impl McBufReadable for State { impl McBufReadable for State {
fn read_into(buf: &mut impl Read) -> Result<Self, String> { fn read_into(buf: &mut impl Read) -> Result<Self, String> {
let state = buf.read_varint()?.try_into().unwrap(); let state = buf.read_varint()?;
Ok(match state { Ok(match state {
0 => State::Init, 0 => State::Init,
1 => State::Add, 1 => State::Add,

View file

@ -123,7 +123,7 @@ impl McBufReadable for EntityDataValue {
} }
impl McBufWritable for EntityDataValue { impl McBufWritable for EntityDataValue {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { fn write_into(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> {
todo!(); todo!();
} }
} }
@ -398,7 +398,7 @@ impl McBufReadable for ParticleData {
} }
impl McBufWritable for ParticleData { impl McBufWritable for ParticleData {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { fn write_into(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> {
todo!() todo!()
} }
} }

View file

@ -122,7 +122,7 @@ pub struct Ingredient {
} }
impl McBufWritable for Recipe { impl McBufWritable for Recipe {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { fn write_into(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> {
todo!() todo!()
} }
} }

View file

@ -1,5 +1,3 @@
use super::LoginPacket;
use crate::mc_buf::Writable;
use packet_macros::LoginPacket; use packet_macros::LoginPacket;
use std::hash::Hash; use std::hash::Hash;

View file

@ -2,10 +2,7 @@ use crate::{mc_buf::Writable, packets::ProtocolPacket, read::MAXIMUM_UNCOMPRESSE
use async_compression::tokio::bufread::ZlibEncoder; use async_compression::tokio::bufread::ZlibEncoder;
use azalea_crypto::Aes128CfbEnc; use azalea_crypto::Aes128CfbEnc;
use std::fmt::Debug; use std::fmt::Debug;
use tokio::{ use tokio::io::{AsyncReadExt, AsyncWrite, AsyncWriteExt};
io::{AsyncReadExt, AsyncWrite, AsyncWriteExt},
net::TcpStream,
};
fn frame_prepender(data: &mut Vec<u8>) -> Result<Vec<u8>, String> { fn frame_prepender(data: &mut Vec<u8>) -> Result<Vec<u8>, String> {
let mut buf = Vec::new(); let mut buf = Vec::new();

View file

@ -35,9 +35,9 @@ impl McBufWritable for PalettedContainer {
pub enum Palette { pub enum Palette {
/// ID of the corresponding entry in its global palette /// ID of the corresponding entry in its global palette
SingleValue(u32), SingleValue(u32),
LinearPalette(Vec<u32>), Linear(Vec<u32>),
HashmapPalette(Vec<u32>), Hashmap(Vec<u32>),
GlobalPalette, Global,
} }
impl Palette { impl Palette {
@ -47,9 +47,9 @@ impl Palette {
) -> Result<Palette, String> { ) -> Result<Palette, String> {
Ok(match bits_per_entry { Ok(match bits_per_entry {
0 => Palette::SingleValue(u32::read_into(buf)?), 0 => Palette::SingleValue(u32::read_into(buf)?),
1..=4 => Palette::LinearPalette(Vec::<u32>::read_into(buf)?), 1..=4 => Palette::Linear(Vec::<u32>::read_into(buf)?),
5..=8 => Palette::HashmapPalette(Vec::<u32>::read_into(buf)?), 5..=8 => Palette::Hashmap(Vec::<u32>::read_into(buf)?),
_ => Palette::GlobalPalette, _ => Palette::Global,
}) })
} }
} }
@ -60,13 +60,13 @@ impl McBufWritable for Palette {
Palette::SingleValue(value) => { Palette::SingleValue(value) => {
value.write_into(buf)?; value.write_into(buf)?;
} }
Palette::LinearPalette(values) => { Palette::Linear(values) => {
values.write_into(buf)?; values.write_into(buf)?;
} }
Palette::HashmapPalette(values) => { Palette::Hashmap(values) => {
values.write_into(buf)?; values.write_into(buf)?;
} }
Palette::GlobalPalette => {} Palette::Global => {}
} }
Ok(()) Ok(())
} }