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

View file

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

View file

@ -1,9 +1,6 @@
use aes::cipher::inout::InOutBuf;
use aes::cipher::BlockEncrypt;
use aes::{
cipher::{
generic_array::GenericArray, AsyncStreamCipher, BlockDecryptMut, BlockEncryptMut, KeyIvInit,
},
cipher::{BlockDecryptMut, BlockEncryptMut, KeyIvInit},
Aes128,
};
use rand::{rngs::OsRng, RngCore};
@ -15,7 +12,7 @@ fn generate_secret_key() -> [u8; 16] {
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();
digest.update(server_id);
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()
}
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.
// 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
@ -48,9 +45,8 @@ pub fn encrypt(public_key: &[u8], nonce: &[u8]) -> Result<EncryptResult, String>
// this.keybytes = Crypt.encryptUsingKey(publicKey, secretKey.getEncoded());
// this.nonce = Crypt.encryptUsingKey(publicKey, arrby);
let encrypted_public_key: Vec<u8> =
rsa_public_encrypt_pkcs1::encrypt(&public_key, &secret_key)?;
let encrypted_nonce: Vec<u8> = rsa_public_encrypt_pkcs1::encrypt(&public_key, &nonce)?;
let encrypted_public_key: Vec<u8> = rsa_public_encrypt_pkcs1::encrypt(public_key, &secret_key)?;
let encrypted_nonce: Vec<u8> = rsa_public_encrypt_pkcs1::encrypt(public_key, nonce)?;
Ok(EncryptResult {
secret_key,

View file

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

View file

@ -232,13 +232,12 @@ struct PacketIdMap {
impl Parse for PacketIdMap {
fn parse(input: ParseStream) -> Result<Self> {
let mut packets = vec![];
loop {
// 0x0e: clientbound_change_difficulty_packet::ClientboundChangeDifficultyPacket,
// 0x0e
let packet_id: LitInt = match input.parse() {
Ok(i) => i,
Err(_) => break,
};
// example:
// 0x0e: clientbound_change_difficulty_packet::ClientboundChangeDifficultyPacket,
// 0x0e
while let Ok(packet_id) = input.parse::<LitInt>() {
let packet_id = packet_id.base10_parse::<u32>()?;
// :
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_core::{
difficulty::Difficulty, game_type::GameType, resource_location::ResourceLocation,
serializable_uuid::SerializableUuid, BlockPos, Direction, Slot, SlotData,
};
use byteorder::{ReadBytesExt, WriteBytesExt, BE};
use byteorder::{ReadBytesExt, BE};
use serde::Deserialize;
use std::io::Read;
use tokio::io::{AsyncRead, AsyncReadExt};
@ -421,7 +421,7 @@ impl McBufReadable for Component {
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
let string = buf.read_utf()?;
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())?;
Ok(component)
}

View file

@ -20,8 +20,8 @@ pub trait Writable: Write {
Ok(())
}
fn write_int_id_list(&mut self, list: &Vec<i32>) -> Result<(), std::io::Error> {
self.write_list(&list, |buf, n| buf.write_varint(*n))
fn write_int_id_list(&mut self, list: &[i32]) -> Result<(), std::io::Error> {
self.write_list(list, |buf, n| buf.write_varint(*n))
}
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> {
self.write_all(bytes);
self.write_all(bytes)?;
Ok(())
}
@ -333,7 +333,7 @@ impl McBufWritable for Component {
// let component = Component::deserialize(json).map_err(|e| e.to_string())?;
// 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
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 {
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
let flags = u8::read_into(buf)?;
@ -292,20 +292,18 @@ impl McBufReadable for BrigadierNodeStub {
}
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_suggestions_type = flags & 0x10 != 0;
let children = buf.read_int_id_list()?;
let redirect_node = if has_redirect { buf.read_varint()? } else { 0 };
let _children = buf.read_int_id_list()?;
let _redirect_node = if has_redirect { buf.read_varint()? } else { 0 };
// argument node
if node_type == 2 {
let name = buf.read_utf()?;
let parser = BrigadierParser::read_into(buf)?;
let suggestions_type = if has_suggestions_type {
let _name = buf.read_utf()?;
let _parser = BrigadierParser::read_into(buf)?;
let _suggestions_type = if has_suggestions_type {
Some(buf.read_resource_location()?)
} else {
None
@ -314,7 +312,7 @@ impl McBufReadable for BrigadierNodeStub {
}
// literal node
if node_type == 1 {
let name = buf.read_utf()?;
let _name = buf.read_utf()?;
return Ok(BrigadierNodeStub {});
}
Ok(BrigadierNodeStub {})

View file

@ -1,5 +1,4 @@
use crate::mc_buf::BitSet;
use azalea_core::{game_type::GameType, resource_location::ResourceLocation};
use packet_macros::{GamePacket, McBufReadable, McBufWritable};
#[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> {
let mut byte = 0;
if self.invulnerable {
byte = byte | 1;
byte |= 0b1;
}
if self.flying {
byte = byte | 2;
byte |= 0b10;
}
if self.can_fly {
byte = byte | 4;
byte |= 0b100;
}
if self.instant_break {
byte = byte | 8;
byte |= 0b1000;
}
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> {
let mut byte = 0;
if self.x {
byte = byte | 0b1;
byte |= 0b1;
}
if self.y {
byte = byte | 0b10;
byte |= 0b10;
}
if self.z {
byte = byte | 0b100;
byte |= 0b100;
}
if self.y_rot {
byte = byte | 0b1000;
byte |= 0b1000;
}
if self.x_rot {
byte = byte | 0b10000;
byte |= 0b10000;
}
u8::write_into(&byte, buf)
}

View file

@ -1,5 +1,5 @@
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 std::io::{Read, Write};
@ -41,7 +41,7 @@ impl McBufWritable for State {
}
impl McBufReadable for State {
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 {
0 => State::Init,
1 => State::Add,

View file

@ -123,7 +123,7 @@ impl McBufReadable 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!();
}
}
@ -398,7 +398,7 @@ impl McBufReadable 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!()
}
}

View file

@ -122,7 +122,7 @@ pub struct Ingredient {
}
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!()
}
}

View file

@ -1,5 +1,3 @@
use super::LoginPacket;
use crate::mc_buf::Writable;
use packet_macros::LoginPacket;
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 azalea_crypto::Aes128CfbEnc;
use std::fmt::Debug;
use tokio::{
io::{AsyncReadExt, AsyncWrite, AsyncWriteExt},
net::TcpStream,
};
use tokio::io::{AsyncReadExt, AsyncWrite, AsyncWriteExt};
fn frame_prepender(data: &mut Vec<u8>) -> Result<Vec<u8>, String> {
let mut buf = Vec::new();

View file

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