aboutsummaryrefslogtreecommitdiff
path: root/bot
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-09-19 23:05:05 -0500
committermat <github@matdoes.dev>2022-09-19 23:05:05 -0500
commite63f605c824d62231bc2741347f8743a62e00617 (patch)
treef43846da56ef9813d2a6a7384bc00f4053c70260 /bot
parenta87c4cf718fcf7b16fecf463333bd46310c88c87 (diff)
downloadazalea-drasl-e63f605c824d62231bc2741347f8743a62e00617.tar.xz
add shutdown function
Diffstat (limited to 'bot')
-rwxr-xr-xbot/Cargo.toml2
-rw-r--r--bot/src/main.rs14
2 files changed, 15 insertions, 1 deletions
diff --git a/bot/Cargo.toml b/bot/Cargo.toml
index fa0b0c67..b51e6705 100755
--- a/bot/Cargo.toml
+++ b/bot/Cargo.toml
@@ -6,9 +6,11 @@ version = "0.1.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+anyhow = "1.0.65"
azalea-client = {path = "../azalea-client"}
azalea-core = {path = "../azalea-core"}
azalea-physics = {path = "../azalea-physics"}
azalea-protocol = {path = "../azalea-protocol"}
+env_logger = "0.9.1"
tokio = "1.19.2"
uuid = "1.1.2"
diff --git a/bot/src/main.rs b/bot/src/main.rs
index 5423e017..92c1bc91 100644
--- a/bot/src/main.rs
+++ b/bot/src/main.rs
@@ -1,8 +1,11 @@
use azalea_client::{Account, Client, Event, MoveDirection};
+use azalea_protocol::packets::game::ClientboundGamePacket;
use std::convert::TryInto;
#[tokio::main]
async fn main() {
+ env_logger::init();
+
let bot = Account::offline("bot");
let (bot, mut rx) = bot.join(&"localhost".try_into().unwrap()).await.unwrap();
@@ -12,7 +15,7 @@ async fn main() {
}
}
-async fn handle_event(event: Event, mut bot: Client) {
+async fn handle_event(event: Event, mut bot: Client) -> anyhow::Result<()> {
match event {
Event::Login => {
// tokio::time::sleep(std::time::Duration::from_secs(1)).await;
@@ -22,6 +25,15 @@ async fn handle_event(event: Event, mut bot: Client) {
// }
// bot.walk(MoveDirection::None);
}
+ Event::Packet(packet) => {
+ if let ClientboundGamePacket::SetHealth(_) = *packet {
+ println!("got set health");
+ bot.shutdown().await?;
+ panic!();
+ }
+ }
_ => {}
}
+
+ Ok(())
}