diff options
Diffstat (limited to 'azalea-client/src')
| -rw-r--r-- | azalea-client/src/account.rs | 27 | ||||
| -rw-r--r--[-rwxr-xr-x] | azalea-client/src/client.rs (renamed from azalea-client/src/connect.rs) | 48 | ||||
| -rwxr-xr-x | azalea-client/src/lib.rs | 6 |
3 files changed, 46 insertions, 35 deletions
diff --git a/azalea-client/src/account.rs b/azalea-client/src/account.rs new file mode 100644 index 00000000..00a5d0f6 --- /dev/null +++ b/azalea-client/src/account.rs @@ -0,0 +1,27 @@ +use crate::Client; +use azalea_protocol::{ + packets::game::{ + clientbound_player_chat_packet::ClientboundPlayerChatPacket, + clientbound_system_chat_packet::ClientboundSystemChatPacket, + }, + ServerAddress, +}; +use std::fmt::Debug; + +///! Connect to Minecraft servers. + +/// Something that can join Minecraft servers. +pub struct Account { + pub username: String, +} +impl Account { + pub fn offline(username: &str) -> Self { + Self { + username: username.to_string(), + } + } + + pub async fn join(&self, address: &ServerAddress) -> Result<Client, String> { + Client::join(self, address).await + } +} diff --git a/azalea-client/src/connect.rs b/azalea-client/src/client.rs index dd3162eb..ff8729cb 100755..100644 --- a/azalea-client/src/connect.rs +++ b/azalea-client/src/client.rs @@ -1,5 +1,5 @@ -use crate::Player; -use azalea_core::{resource_location::ResourceLocation, ChunkPos, EntityPos}; +use crate::{Account, Player}; +use azalea_core::{resource_location::ResourceLocation, ChunkPos}; use azalea_entity::Entity; use azalea_protocol::{ connect::{GameConnection, HandshakeConnection}, @@ -25,25 +25,16 @@ use std::{fmt::Debug, sync::Arc}; use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; use tokio::sync::Mutex; -///! Connect to Minecraft servers. - -/// Something that can join Minecraft servers. -pub struct Account { - username: String, -} - #[derive(Default)] pub struct ClientState { pub player: Player, pub world: Option<World>, } -/// A player that you can control that is currently in a Minecraft server. -pub struct Client { - event_receiver: UnboundedReceiver<Event>, - pub conn: Arc<Mutex<GameConnection>>, - pub state: Arc<Mutex<ClientState>>, - // game_loop +#[derive(Debug, Clone)] +pub enum Event { + Login, + Chat(ChatPacket), } #[derive(Debug, Clone)] @@ -61,17 +52,20 @@ pub enum ChatPacket { // } // } -#[derive(Debug, Clone)] -pub enum Event { - Login, - Chat(ChatPacket), +/// A player that you can control that is currently in a Minecraft server. +pub struct Client { + event_receiver: UnboundedReceiver<Event>, + pub conn: Arc<Mutex<GameConnection>>, + pub state: Arc<Mutex<ClientState>>, + // game_loop } /// Whether we should ignore errors when decoding packets. -const IGNORE_ERRORS: bool = false; +const IGNORE_ERRORS: bool = !cfg!(debug_assertions); impl Client { - async fn join(account: &Account, address: &ServerAddress) -> Result<Self, String> { + /// Connect to a Minecraft server with an account. + pub async fn join(account: &Account, address: &ServerAddress) -> Result<Self, String> { let resolved_address = resolver::resolve_address(address).await?; let mut conn = HandshakeConnection::new(&resolved_address).await?; @@ -469,15 +463,3 @@ impl Client { self.event_receiver.recv().await } } - -impl Account { - pub fn offline(username: &str) -> Self { - Self { - username: username.to_string(), - } - } - - pub async fn join(&self, address: &ServerAddress) -> Result<Client, String> { - Client::join(self, address).await - } -} diff --git a/azalea-client/src/lib.rs b/azalea-client/src/lib.rs index db935897..867f05a1 100755 --- a/azalea-client/src/lib.rs +++ b/azalea-client/src/lib.rs @@ -1,10 +1,12 @@ //! Significantly abstract azalea-protocol so it's actually useable for bots. -mod connect; +mod account; +mod client; pub mod ping; mod player; -pub use connect::{Account, Client, Event}; +pub use account::Account; +pub use client::{Client, Event}; pub use player::Player; #[cfg(test)] |
