Compare commits
No commits in common. "c4454fe217644fa36fe09e18de7b95247d65328b" and "59e0d597a1d6d03f5e504682b31a28181263cf28" have entirely different histories.
c4454fe217
...
59e0d597a1
155
Cargo.lock
generated
155
Cargo.lock
generated
@ -17,16 +17,6 @@ version = "2.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
|
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "aead"
|
|
||||||
version = "0.5.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0"
|
|
||||||
dependencies = [
|
|
||||||
"crypto-common",
|
|
||||||
"generic-array",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aes"
|
name = "aes"
|
||||||
version = "0.8.4"
|
version = "0.8.4"
|
||||||
@ -38,20 +28,6 @@ dependencies = [
|
|||||||
"cpufeatures",
|
"cpufeatures",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "aes-gcm"
|
|
||||||
version = "0.10.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1"
|
|
||||||
dependencies = [
|
|
||||||
"aead",
|
|
||||||
"aes",
|
|
||||||
"cipher",
|
|
||||||
"ctr",
|
|
||||||
"ghash",
|
|
||||||
"subtle",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ahash"
|
name = "ahash"
|
||||||
version = "0.8.11"
|
version = "0.8.11"
|
||||||
@ -906,15 +882,6 @@ dependencies = [
|
|||||||
"generic-array",
|
"generic-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "block-padding"
|
|
||||||
version = "0.3.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a8894febbff9f758034a5b8e12d87918f56dfc64a8e1fe757d65e29041538d93"
|
|
||||||
dependencies = [
|
|
||||||
"generic-array",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bstr"
|
name = "bstr"
|
||||||
version = "1.11.3"
|
version = "1.11.3"
|
||||||
@ -1213,19 +1180,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"generic-array",
|
"generic-array",
|
||||||
"rand_core",
|
|
||||||
"typenum",
|
"typenum",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ctr"
|
|
||||||
version = "0.9.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835"
|
|
||||||
dependencies = [
|
|
||||||
"cipher",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ctrlc"
|
name = "ctrlc"
|
||||||
version = "3.4.5"
|
version = "3.4.5"
|
||||||
@ -1303,7 +1260,6 @@ dependencies = [
|
|||||||
"block-buffer",
|
"block-buffer",
|
||||||
"const-oid",
|
"const-oid",
|
||||||
"crypto-common",
|
"crypto-common",
|
||||||
"subtle",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1380,7 +1336,6 @@ dependencies = [
|
|||||||
"hyper-util",
|
"hyper-util",
|
||||||
"log",
|
"log",
|
||||||
"mlua",
|
"mlua",
|
||||||
"ncr",
|
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1584,16 +1539,6 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ghash"
|
|
||||||
version = "0.5.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1"
|
|
||||||
dependencies = [
|
|
||||||
"opaque-debug",
|
|
||||||
"polyval",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gimli"
|
name = "gimli"
|
||||||
version = "0.31.1"
|
version = "0.31.1"
|
||||||
@ -1710,15 +1655,6 @@ dependencies = [
|
|||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hmac"
|
|
||||||
version = "0.12.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
|
|
||||||
dependencies = [
|
|
||||||
"digest",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "http"
|
name = "http"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
@ -2007,7 +1943,6 @@ version = "0.1.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01"
|
checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"block-padding",
|
|
||||||
"generic-array",
|
"generic-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -2211,24 +2146,6 @@ dependencies = [
|
|||||||
"pkg-config",
|
"pkg-config",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ncr"
|
|
||||||
version = "0.1.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e905418cb5217c1e6947e8d90e0cfd7468352dbe4e6d34a0a6e7ed51e8edfcf2"
|
|
||||||
dependencies = [
|
|
||||||
"aes",
|
|
||||||
"aes-gcm",
|
|
||||||
"base64 0.21.7",
|
|
||||||
"cfb8",
|
|
||||||
"cipher",
|
|
||||||
"hmac",
|
|
||||||
"pbkdf2",
|
|
||||||
"phf",
|
|
||||||
"rand",
|
|
||||||
"sha1",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nix"
|
name = "nix"
|
||||||
version = "0.29.0"
|
version = "0.29.0"
|
||||||
@ -2389,12 +2306,6 @@ version = "1.20.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e"
|
checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "opaque-debug"
|
|
||||||
version = "0.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "overload"
|
name = "overload"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
@ -2430,15 +2341,6 @@ dependencies = [
|
|||||||
"windows-targets",
|
"windows-targets",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pbkdf2"
|
|
||||||
version = "0.12.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2"
|
|
||||||
dependencies = [
|
|
||||||
"digest",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pem-rfc7468"
|
name = "pem-rfc7468"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
@ -2464,24 +2366,6 @@ dependencies = [
|
|||||||
"indexmap 2.7.1",
|
"indexmap 2.7.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "phf"
|
|
||||||
version = "0.11.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078"
|
|
||||||
dependencies = [
|
|
||||||
"phf_shared",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "phf_shared"
|
|
||||||
version = "0.11.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5"
|
|
||||||
dependencies = [
|
|
||||||
"siphasher",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pin-project"
|
name = "pin-project"
|
||||||
version = "1.1.9"
|
version = "1.1.9"
|
||||||
@ -2541,18 +2425,6 @@ version = "0.3.31"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
|
checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "polyval"
|
|
||||||
version = "0.6.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"cpufeatures",
|
|
||||||
"opaque-debug",
|
|
||||||
"universal-hash",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ppv-lite86"
|
name = "ppv-lite86"
|
||||||
version = "0.2.20"
|
version = "0.2.20"
|
||||||
@ -2995,17 +2867,6 @@ dependencies = [
|
|||||||
"digest",
|
"digest",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "sha1"
|
|
||||||
version = "0.10.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"cpufeatures",
|
|
||||||
"digest",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sha2"
|
name = "sha2"
|
||||||
version = "0.10.8"
|
version = "0.10.8"
|
||||||
@ -3094,12 +2955,6 @@ dependencies = [
|
|||||||
"thiserror 1.0.69",
|
"thiserror 1.0.69",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "siphasher"
|
|
||||||
version = "1.0.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "slab"
|
name = "slab"
|
||||||
version = "0.4.9"
|
version = "0.4.9"
|
||||||
@ -3577,16 +3432,6 @@ version = "0.2.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "universal-hash"
|
|
||||||
version = "0.5.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea"
|
|
||||||
dependencies = [
|
|
||||||
"crypto-common",
|
|
||||||
"subtle",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "untrusted"
|
name = "untrusted"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
|
@ -28,7 +28,6 @@ hyper = { version = "1", features = ["server"] }
|
|||||||
hyper-util = "0"
|
hyper-util = "0"
|
||||||
log = { version = "0" }
|
log = { version = "0" }
|
||||||
mlua = { version = "0", features = ["async", "luajit", "send"] }
|
mlua = { version = "0", features = ["async", "luajit", "send"] }
|
||||||
ncr = { version = "0", features = ["cfb8", "ecb", "gcm"] }
|
|
||||||
tokio = { version = "1", features = ["macros"] }
|
tokio = { version = "1", features = ["macros"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
@ -11,7 +11,6 @@ A Minecraft bot with Lua scripting support, written in Rust with [azalea](https:
|
|||||||
- Listening to in-game events
|
- Listening to in-game events
|
||||||
- Pathfinding (from azalea)
|
- Pathfinding (from azalea)
|
||||||
- Entity and chest interaction
|
- Entity and chest interaction
|
||||||
- NoChatReports encryption
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
@ -4,8 +4,6 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use azalea::{brigadier::prelude::*, chat::ChatPacket, prelude::*};
|
use azalea::{brigadier::prelude::*, chat::ChatPacket, prelude::*};
|
||||||
use futures::lock::Mutex;
|
use futures::lock::Mutex;
|
||||||
use mlua::{Function, Table};
|
|
||||||
use ncr::utils::prepend_header;
|
|
||||||
|
|
||||||
pub type Ctx = CommandContext<Mutex<CommandSource>>;
|
pub type Ctx = CommandContext<Mutex<CommandSource>>;
|
||||||
|
|
||||||
@ -13,24 +11,16 @@ pub struct CommandSource {
|
|||||||
pub client: Client,
|
pub client: Client,
|
||||||
pub message: ChatPacket,
|
pub message: ChatPacket,
|
||||||
pub state: State,
|
pub state: State,
|
||||||
pub ncr_options: Option<Table>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CommandSource {
|
impl CommandSource {
|
||||||
pub fn reply(&self, message: &str) {
|
pub fn reply(&self, message: &str) {
|
||||||
for mut chunk in message
|
for chunk in message
|
||||||
.chars()
|
.chars()
|
||||||
.collect::<Vec<char>>()
|
.collect::<Vec<char>>()
|
||||||
.chunks(if self.ncr_options.is_some() { 150 } else { 236 })
|
.chunks(236)
|
||||||
.map(|chars| chars.iter().collect::<String>())
|
.map(|chars| chars.iter().collect::<String>())
|
||||||
{
|
{
|
||||||
if let (Some(options), Ok(encrypt)) = (
|
|
||||||
&self.ncr_options,
|
|
||||||
self.state.lua.globals().get::<Function>("ncr_encrypt"),
|
|
||||||
) && let Ok(encrypted) = encrypt.call::<String>((options, prepend_header(&chunk)))
|
|
||||||
{
|
|
||||||
chunk = encrypted
|
|
||||||
}
|
|
||||||
self.client.chat(
|
self.client.chat(
|
||||||
&(if self.message.is_whisper()
|
&(if self.message.is_whisper()
|
||||||
&& let Some(username) = self.message.username()
|
&& let Some(username) = self.message.username()
|
||||||
|
@ -2,15 +2,14 @@ use crate::{
|
|||||||
State,
|
State,
|
||||||
commands::CommandSource,
|
commands::CommandSource,
|
||||||
http::serve,
|
http::serve,
|
||||||
lua::{self, direction::Direction, player::Player, vec3::Vec3},
|
lua::{self, player::Player, vec3::Vec3},
|
||||||
particle,
|
particle,
|
||||||
};
|
};
|
||||||
use azalea::{prelude::*, protocol::packets::game::ClientboundGamePacket};
|
use azalea::{prelude::*, protocol::packets::game::ClientboundGamePacket};
|
||||||
use hyper::{server::conn::http1, service::service_fn};
|
use hyper::{server::conn::http1, service::service_fn};
|
||||||
use hyper_util::rt::TokioIo;
|
use hyper_util::rt::TokioIo;
|
||||||
use log::{debug, error, info, trace};
|
use log::{debug, error, info, trace};
|
||||||
use mlua::{Function, IntoLuaMulti, Table};
|
use mlua::IntoLuaMulti;
|
||||||
use ncr::utils::trim_header;
|
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
|
|
||||||
@ -21,33 +20,23 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow:
|
|||||||
call_listeners(&state, "add_player", Player::from(player_info)).await;
|
call_listeners(&state, "add_player", Player::from(player_info)).await;
|
||||||
}
|
}
|
||||||
Event::Chat(message) => {
|
Event::Chat(message) => {
|
||||||
let globals = state.lua.globals();
|
|
||||||
let (sender, mut content) = message.split_sender_and_content();
|
|
||||||
let formatted_message = message.message();
|
let formatted_message = message.message();
|
||||||
info!("{}", formatted_message.to_ansi());
|
info!("{}", formatted_message.to_ansi());
|
||||||
|
|
||||||
if let Some(sender) = sender {
|
if message.is_whisper()
|
||||||
let mut ncr_options = None;
|
&& let (Some(sender), content) = message.split_sender_and_content()
|
||||||
if let (Ok(options), Ok(decrypt)) = (
|
&& state
|
||||||
globals.get::<Table>("NcrOptions"),
|
.lua
|
||||||
globals.get::<Function>("ncr_decrypt"),
|
.globals()
|
||||||
) && let Ok(decrypted) =
|
.get::<Vec<String>>("Owners")?
|
||||||
decrypt.call::<String>((options.clone(), content.clone()))
|
.contains(&sender)
|
||||||
&& let Ok(trimmed) = trim_header(&decrypted)
|
|
||||||
{
|
{
|
||||||
ncr_options = Some(options);
|
|
||||||
content = trimmed.to_owned();
|
|
||||||
info!("Decrypted message from {sender}: {content}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if message.is_whisper() && globals.get::<Vec<String>>("Owners")?.contains(&sender) {
|
|
||||||
if let Err(error) = state.commands.execute(
|
if let Err(error) = state.commands.execute(
|
||||||
content,
|
content,
|
||||||
CommandSource {
|
CommandSource {
|
||||||
client: client.clone(),
|
client: client.clone(),
|
||||||
message: message.clone(),
|
message: message.clone(),
|
||||||
state: state.clone(),
|
state: state.clone(),
|
||||||
ncr_options: ncr_options.clone(),
|
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
) {
|
) {
|
||||||
@ -55,12 +44,10 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow:
|
|||||||
client,
|
client,
|
||||||
message,
|
message,
|
||||||
state: state.clone(),
|
state: state.clone(),
|
||||||
ncr_options,
|
|
||||||
}
|
}
|
||||||
.reply(&format!("{error:?}"));
|
.reply(&format!("{error:?}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
call_listeners(&state, "chat", formatted_message.to_string()).await;
|
call_listeners(&state, "chat", formatted_message.to_string()).await;
|
||||||
}
|
}
|
||||||
@ -83,37 +70,6 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow:
|
|||||||
call_listeners(&state, "update_player", Player::from(player_info)).await;
|
call_listeners(&state, "update_player", Player::from(player_info)).await;
|
||||||
}
|
}
|
||||||
Event::Packet(packet) => match packet.as_ref() {
|
Event::Packet(packet) => match packet.as_ref() {
|
||||||
ClientboundGamePacket::AddEntity(packet) => {
|
|
||||||
let table = state.lua.create_table()?;
|
|
||||||
table.set("id", packet.id.0)?;
|
|
||||||
table.set("uuid", packet.uuid.to_string())?;
|
|
||||||
table.set("kind", packet.entity_type.to_string())?;
|
|
||||||
table.set("position", Vec3::from(packet.position))?;
|
|
||||||
table.set(
|
|
||||||
"direction",
|
|
||||||
Direction {
|
|
||||||
y: f32::from(packet.y_rot) / (256.0 / 360.0),
|
|
||||||
x: f32::from(packet.x_rot) / (256.0 / 360.0),
|
|
||||||
},
|
|
||||||
)?;
|
|
||||||
table.set("data", packet.data)?;
|
|
||||||
call_listeners(&state, "add_entity", table).await;
|
|
||||||
}
|
|
||||||
ClientboundGamePacket::LevelParticles(packet) => {
|
|
||||||
let table = state.lua.create_table()?;
|
|
||||||
table.set("position", Vec3::from(packet.pos))?;
|
|
||||||
table.set("count", packet.count)?;
|
|
||||||
table.set("kind", particle::to_kind(&packet.particle) as u8)?;
|
|
||||||
call_listeners(&state, "level_particles", table).await;
|
|
||||||
}
|
|
||||||
ClientboundGamePacket::RemoveEntities(packet) => {
|
|
||||||
call_listeners(
|
|
||||||
&state,
|
|
||||||
"remove_entities",
|
|
||||||
packet.entity_ids.iter().map(|id| id.0).collect::<Vec<_>>(),
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
ClientboundGamePacket::SetHealth(packet) => {
|
ClientboundGamePacket::SetHealth(packet) => {
|
||||||
let table = state.lua.create_table()?;
|
let table = state.lua.create_table()?;
|
||||||
table.set("food", packet.food)?;
|
table.set("food", packet.food)?;
|
||||||
@ -127,6 +83,13 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow:
|
|||||||
table.set("passengers", &*packet.passengers)?;
|
table.set("passengers", &*packet.passengers)?;
|
||||||
call_listeners(&state, "set_passengers", table).await;
|
call_listeners(&state, "set_passengers", table).await;
|
||||||
}
|
}
|
||||||
|
ClientboundGamePacket::LevelParticles(packet) => {
|
||||||
|
let table = state.lua.create_table()?;
|
||||||
|
table.set("position", Vec3::from(packet.pos))?;
|
||||||
|
table.set("count", packet.count)?;
|
||||||
|
table.set("kind", particle::to_kind(&packet.particle) as u8)?;
|
||||||
|
call_listeners(&state, "level_particles", table).await;
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
},
|
||||||
Event::Init => {
|
Event::Init => {
|
||||||
|
@ -43,24 +43,21 @@ pub async fn get_block_states(
|
|||||||
) -> Result<Vec<u16>> {
|
) -> Result<Vec<u16>> {
|
||||||
let mut matched = Vec::new();
|
let mut matched = Vec::new();
|
||||||
for block_name in block_names {
|
for block_name in block_names {
|
||||||
for block in
|
for b in
|
||||||
(u32::MIN..u32::MAX).map_while(|possible_id| BlockState::try_from(possible_id).ok())
|
(u32::MIN..u32::MAX).map_while(|possible_id| BlockState::try_from(possible_id).ok())
|
||||||
{
|
{
|
||||||
if block_name == Into::<Box<dyn AzaleaBlock>>::into(block).id()
|
if block_name == Into::<Box<dyn AzaleaBlock>>::into(b).id()
|
||||||
&& (if let Some(filter_fn) = &filter_fn {
|
&& (if let Some(filter_fn) = &filter_fn {
|
||||||
let table = lua.create_table()?;
|
let p = lua.create_table()?;
|
||||||
table.set("chest_type", block.property::<ChestType>().map(|v| v as u8))?;
|
p.set("chest_type", b.property::<ChestType>().map(|v| v as u8))?;
|
||||||
table.set("facing", block.property::<Facing>().map(|v| v as u8))?;
|
p.set("facing", b.property::<Facing>().map(|v| v as u8))?;
|
||||||
table.set(
|
p.set("light_level", b.property::<LightLevel>().map(|v| v as u8))?;
|
||||||
"light_level",
|
filter_fn.call_async::<bool>(p.clone()).await?
|
||||||
block.property::<LightLevel>().map(|v| v as u8),
|
|
||||||
)?;
|
|
||||||
filter_fn.call_async::<bool>(table).await?
|
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
matched.push(block.id);
|
matched.push(b.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ use super::{
|
|||||||
player::Player,
|
player::Player,
|
||||||
vec3::Vec3,
|
vec3::Vec3,
|
||||||
};
|
};
|
||||||
use azalea::{Client as AzaleaClient, world::MinecraftEntityId};
|
use azalea::Client as AzaleaClient;
|
||||||
use mlua::{Lua, Result, UserData, UserDataFields, UserDataMethods};
|
use mlua::{Lua, Result, UserData, UserDataFields, UserDataMethods};
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
|
|
||||||
@ -48,7 +48,6 @@ impl UserData for Client {
|
|||||||
f.add_field_method_get("held_item", container::held_item);
|
f.add_field_method_get("held_item", container::held_item);
|
||||||
f.add_field_method_get("held_slot", container::held_slot);
|
f.add_field_method_get("held_slot", container::held_slot);
|
||||||
f.add_field_method_get("hunger", state::hunger);
|
f.add_field_method_get("hunger", state::hunger);
|
||||||
f.add_field_method_get("id", id);
|
|
||||||
f.add_field_method_get("looking_at", movement::looking_at);
|
f.add_field_method_get("looking_at", movement::looking_at);
|
||||||
f.add_field_method_get("menu", container::menu);
|
f.add_field_method_get("menu", container::menu);
|
||||||
f.add_field_method_get("pathfinder", movement::pathfinder);
|
f.add_field_method_get("pathfinder", movement::pathfinder);
|
||||||
@ -101,10 +100,6 @@ fn disconnect(_lua: &Lua, client: &Client, _: ()) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn id(_lua: &Lua, client: &Client) -> Result<i32> {
|
|
||||||
Ok(client.component::<MinecraftEntityId>().0)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn tab_list(_lua: &Lua, client: &Client) -> Result<Vec<Player>> {
|
fn tab_list(_lua: &Lua, client: &Client) -> Result<Vec<Player>> {
|
||||||
let mut tab_list = Vec::new();
|
let mut tab_list = Vec::new();
|
||||||
for (_, player_info) in client.tab_list() {
|
for (_, player_info) in client.tab_list() {
|
||||||
|
@ -18,23 +18,27 @@ impl UserData for ItemStack {
|
|||||||
f.add_field_method_get("count", |_, this| Ok(this.inner.count()));
|
f.add_field_method_get("count", |_, this| Ok(this.inner.count()));
|
||||||
f.add_field_method_get("kind", |_, this| Ok(this.inner.kind().to_string()));
|
f.add_field_method_get("kind", |_, this| Ok(this.inner.kind().to_string()));
|
||||||
f.add_field_method_get("custom_name", |_, this| {
|
f.add_field_method_get("custom_name", |_, this| {
|
||||||
Ok(this.inner.as_present().map(|data| {
|
Ok(if let Some(data) = this.inner.as_present() {
|
||||||
data.components
|
data.components
|
||||||
.get::<CustomName>()
|
.get::<CustomName>()
|
||||||
.map(|c| c.name.to_string())
|
.map(|n| n.name.to_string())
|
||||||
}))
|
} else {
|
||||||
|
None
|
||||||
|
})
|
||||||
});
|
});
|
||||||
f.add_field_method_get("damage", |_, this| {
|
f.add_field_method_get("damage", |_, this| {
|
||||||
Ok(this
|
Ok(if let Some(data) = this.inner.as_present() {
|
||||||
.inner
|
data.components.get::<Damage>().map(|d| d.amount)
|
||||||
.as_present()
|
} else {
|
||||||
.map(|data| data.components.get::<Damage>().map(|d| d.amount)))
|
None
|
||||||
|
})
|
||||||
});
|
});
|
||||||
f.add_field_method_get("max_damage", |_, this| {
|
f.add_field_method_get("max_damage", |_, this| {
|
||||||
Ok(this
|
Ok(if let Some(data) = this.inner.as_present() {
|
||||||
.inner
|
data.components.get::<MaxDamage>().map(|d| d.amount)
|
||||||
.as_present()
|
} else {
|
||||||
.map(|data| data.components.get::<MaxDamage>().map(|d| d.amount)))
|
None
|
||||||
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,20 +56,28 @@ pub fn register_functions(lua: &Lua, globals: &Table, event_listeners: ListenerM
|
|||||||
"get_listeners",
|
"get_listeners",
|
||||||
lua.create_function(move |lua, (): ()| {
|
lua.create_function(move |lua, (): ()| {
|
||||||
let m = block_on(event_listeners.read());
|
let m = block_on(event_listeners.read());
|
||||||
let listeners_table = lua.create_table()?;
|
|
||||||
|
let listeners = lua.create_table()?;
|
||||||
for (event_type, callbacks) in m.iter() {
|
for (event_type, callbacks) in m.iter() {
|
||||||
let type_listeners_table = lua.create_table()?;
|
let type_listeners = lua.create_table()?;
|
||||||
for (id, callback) in callbacks {
|
for (id, callback) in callbacks {
|
||||||
let info = callback.info();
|
let listener = lua.create_table()?;
|
||||||
let table = lua.create_table()?;
|
let i = callback.info();
|
||||||
table.set("name", info.name)?;
|
if let Some(n) = i.name {
|
||||||
table.set("line_defined", info.line_defined)?;
|
listener.set("name", n)?;
|
||||||
table.set("source", info.source)?;
|
|
||||||
type_listeners_table.set(id.to_owned(), table)?;
|
|
||||||
}
|
}
|
||||||
listeners_table.set(event_type.to_owned(), type_listeners_table)?;
|
if let Some(l) = i.line_defined {
|
||||||
|
listener.set("line_defined", l)?;
|
||||||
}
|
}
|
||||||
Ok(listeners_table)
|
if let Some(s) = i.source {
|
||||||
|
listener.set("source", s)?;
|
||||||
|
}
|
||||||
|
type_listeners.set(id.to_owned(), listener)?;
|
||||||
|
}
|
||||||
|
listeners.set(event_type.to_owned(), type_listeners)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(listeners)
|
||||||
})?,
|
})?,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ pub mod container;
|
|||||||
pub mod direction;
|
pub mod direction;
|
||||||
pub mod events;
|
pub mod events;
|
||||||
pub mod logging;
|
pub mod logging;
|
||||||
pub mod nochatreports;
|
|
||||||
pub mod player;
|
pub mod player;
|
||||||
pub mod system;
|
pub mod system;
|
||||||
pub mod vec3;
|
pub mod vec3;
|
||||||
@ -40,7 +39,6 @@ pub fn register_functions(
|
|||||||
block::register_functions(lua, globals)?;
|
block::register_functions(lua, globals)?;
|
||||||
events::register_functions(lua, globals, event_listeners)?;
|
events::register_functions(lua, globals, event_listeners)?;
|
||||||
logging::register_functions(lua, globals)?;
|
logging::register_functions(lua, globals)?;
|
||||||
nochatreports::register_functions(lua, globals)?;
|
|
||||||
system::register_functions(lua, globals)
|
system::register_functions(lua, globals)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
macro_rules! crypt_with {
|
|
||||||
($op:ident, $encoding:expr, $key:expr, $text:expr, $algo:ident) => {
|
|
||||||
match $encoding {
|
|
||||||
1 => $algo::<Base64Encoding>::$op($text, $key),
|
|
||||||
2 => $algo::<Base64rEncoding>::$op($text, $key),
|
|
||||||
_ => $algo::<NewBase64rEncoding>::$op($text, $key),
|
|
||||||
}
|
|
||||||
.map_err(|error| Error::external(error.to_string()))?
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! crypt {
|
|
||||||
($op:ident, $encoding:expr, $options:expr, $text:expr) => {
|
|
||||||
match $options.get("encryption").unwrap_or_default() {
|
|
||||||
1 => CaesarEncryption::$op(&$text, &$options.get("key")?)
|
|
||||||
.map_err(|error| Error::external(error.to_string()))?,
|
|
||||||
2 => crypt_with!(
|
|
||||||
$op,
|
|
||||||
$encoding,
|
|
||||||
&$options.get::<UserDataRef<AesKey>>("key")?.inner,
|
|
||||||
&$text,
|
|
||||||
EcbEncryption
|
|
||||||
),
|
|
||||||
3 => crypt_with!(
|
|
||||||
$op,
|
|
||||||
$encoding,
|
|
||||||
&$options.get::<UserDataRef<AesKey>>("key")?.inner,
|
|
||||||
&$text,
|
|
||||||
GcmEncryption
|
|
||||||
),
|
|
||||||
_ => crypt_with!(
|
|
||||||
$op,
|
|
||||||
$encoding,
|
|
||||||
&$options.get::<UserDataRef<AesKey>>("key")?.inner,
|
|
||||||
&$text,
|
|
||||||
Cfb8Encryption
|
|
||||||
),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
use mlua::UserData;
|
|
||||||
|
|
||||||
pub struct AesKey {
|
|
||||||
pub inner: ncr::AesKey,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UserData for AesKey {
|
|
||||||
fn add_fields<F: mlua::UserDataFields<Self>>(f: &mut F) {
|
|
||||||
f.add_field_method_get("base64", |_, this| Ok(this.inner.encode_base64()));
|
|
||||||
f.add_field_method_get("bytes", |_, this| Ok(this.inner.as_ref().to_vec()));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,81 +0,0 @@
|
|||||||
#[macro_use]
|
|
||||||
pub mod crypt;
|
|
||||||
pub mod key;
|
|
||||||
|
|
||||||
use key::AesKey;
|
|
||||||
use mlua::{Error, Lua, Result, Table, UserDataRef};
|
|
||||||
use ncr::{
|
|
||||||
encoding::{Base64Encoding, Base64rEncoding, NewBase64rEncoding},
|
|
||||||
encryption::{CaesarEncryption, Cfb8Encryption, EcbEncryption, Encryption, GcmEncryption},
|
|
||||||
utils::{prepend_header, trim_header},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn register_functions(lua: &Lua, globals: &Table) -> Result<()> {
|
|
||||||
globals.set(
|
|
||||||
"ncr_aes_key_from_passphrase",
|
|
||||||
lua.create_function(|_, passphrase: Vec<u8>| {
|
|
||||||
Ok(AesKey {
|
|
||||||
inner: ncr::AesKey::gen_from_passphrase(&passphrase),
|
|
||||||
})
|
|
||||||
})?,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
globals.set(
|
|
||||||
"ncr_aes_key_from_base64",
|
|
||||||
lua.create_function(|_, base64: String| {
|
|
||||||
Ok(AesKey {
|
|
||||||
inner: ncr::AesKey::decode_base64(&base64)
|
|
||||||
.map_err(|error| Error::external(error.to_string()))?,
|
|
||||||
})
|
|
||||||
})?,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
globals.set(
|
|
||||||
"ncr_generate_random_aes_key",
|
|
||||||
lua.create_function(|_, (): ()| {
|
|
||||||
Ok(AesKey {
|
|
||||||
inner: ncr::AesKey::gen_random_key(),
|
|
||||||
})
|
|
||||||
})?,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
globals.set(
|
|
||||||
"ncr_encrypt",
|
|
||||||
lua.create_function(|_, (options, plaintext): (Table, String)| {
|
|
||||||
Ok(crypt!(
|
|
||||||
encrypt,
|
|
||||||
options.get("encoding").unwrap_or_default(),
|
|
||||||
options,
|
|
||||||
plaintext
|
|
||||||
))
|
|
||||||
})?,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
globals.set(
|
|
||||||
"ncr_decrypt",
|
|
||||||
lua.create_function(|_, (options, ciphertext): (Table, String)| {
|
|
||||||
Ok(crypt!(
|
|
||||||
decrypt,
|
|
||||||
options.get("encoding").unwrap_or_default(),
|
|
||||||
options,
|
|
||||||
ciphertext
|
|
||||||
))
|
|
||||||
})?,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
globals.set(
|
|
||||||
"ncr_prepend_header",
|
|
||||||
lua.create_function(|_, text: String| Ok(prepend_header(&text)))?,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
globals.set(
|
|
||||||
"ncr_trim_header",
|
|
||||||
lua.create_function(|_, text: String| {
|
|
||||||
Ok(trim_header(&text)
|
|
||||||
.map_err(|error| Error::external(error.to_string()))?
|
|
||||||
.to_owned())
|
|
||||||
})?,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user