Compare commits
14 Commits
e81fab7bf8
...
c19af70274
Author | SHA1 | Date | |
---|---|---|---|
c19af70274 | |||
c15ea64bd3 | |||
26611d30f9 | |||
d117914205 | |||
553465e3b5 | |||
21798fa2a9 | |||
54c09b3dc5 | |||
71f0c557c7 | |||
28fac5468f | |||
54b32a22a8 | |||
2bc1e85f94 | |||
f121addc40 | |||
2932c12468 | |||
a98b6814b1 |
199
Cargo.lock
generated
199
Cargo.lock
generated
@ -961,25 +961,6 @@ version = "1.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f61dac84819c6588b558454b194026eb1f09c293b9036ae9b159e74e73ab6cf9"
|
||||
|
||||
[[package]]
|
||||
name = "bzip2"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49ecfb22d906f800d4fe833b6282cf4dc1c298f5057ca0b5445e5c209735ca47"
|
||||
dependencies = [
|
||||
"bzip2-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bzip2-sys"
|
||||
version = "0.1.13+1.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "225bff33b2141874fe80d71e07d6eec4f85c5c216453dd96388240f96e1acc14"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "castaway"
|
||||
version = "0.2.3"
|
||||
@ -1206,12 +1187,6 @@ dependencies = [
|
||||
"tiny-keccak",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "constant_time_eq"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6"
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.17"
|
||||
@ -1221,21 +1196,6 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc"
|
||||
version = "3.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636"
|
||||
dependencies = [
|
||||
"crc-catalog",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc-catalog"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5"
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.4.2"
|
||||
@ -1302,12 +1262,6 @@ version = "2.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "575f75dfd25738df5b91b8e43e14d44bda14637a58fae779fd2b064f8bf3e010"
|
||||
|
||||
[[package]]
|
||||
name = "deflate64"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da692b8d1080ea3045efaab14434d40468c3d8657e42abddfffca87b428f4c1b"
|
||||
|
||||
[[package]]
|
||||
name = "der"
|
||||
version = "0.7.9"
|
||||
@ -1319,15 +1273,6 @@ dependencies = [
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "deranged"
|
||||
version = "0.3.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4"
|
||||
dependencies = [
|
||||
"powerfmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_arbitrary"
|
||||
version = "1.4.1"
|
||||
@ -1467,10 +1412,12 @@ dependencies = [
|
||||
"hyper",
|
||||
"hyper-util",
|
||||
"log",
|
||||
"mimalloc",
|
||||
"mlua",
|
||||
"ncr",
|
||||
"parking_lot",
|
||||
"serde_json",
|
||||
"smallvec",
|
||||
"tokio",
|
||||
"zip",
|
||||
]
|
||||
@ -2204,6 +2151,16 @@ version = "0.2.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa"
|
||||
|
||||
[[package]]
|
||||
name = "libmimalloc-sys"
|
||||
version = "0.1.39"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23aa6811d3bd4deb8a84dde645f943476d13b248d818edcf8ce0b2f37f036b44"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libz-sys"
|
||||
version = "1.1.21"
|
||||
@ -2238,12 +2195,6 @@ dependencies = [
|
||||
"scopeguard",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lockfree-object-pool"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9374ef4228402d4b7e403e5838cb880d9ee663314b0a900d5a6aabf0c213552e"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.26"
|
||||
@ -2259,16 +2210,6 @@ dependencies = [
|
||||
"linked-hash-map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lzma-rs"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "297e814c836ae64db86b36cf2a557ba54368d03f6afcd7d947c266692f71115e"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"crc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "matchers"
|
||||
version = "0.1.0"
|
||||
@ -2300,6 +2241,15 @@ version = "2.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||
|
||||
[[package]]
|
||||
name = "mimalloc"
|
||||
version = "0.1.43"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68914350ae34959d83f732418d51e2427a794055d0b9529f48259ac07af65633"
|
||||
dependencies = [
|
||||
"libmimalloc-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mime"
|
||||
version = "0.3.17"
|
||||
@ -2476,12 +2426,6 @@ dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-conv"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
|
||||
|
||||
[[package]]
|
||||
name = "num-format"
|
||||
version = "0.4.4"
|
||||
@ -2596,7 +2540,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2"
|
||||
dependencies = [
|
||||
"digest",
|
||||
"hmac",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2713,12 +2656,6 @@ dependencies = [
|
||||
"universal-hash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "powerfmt"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.20"
|
||||
@ -3208,12 +3145,6 @@ dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simd-adler32"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
|
||||
|
||||
[[package]]
|
||||
name = "simd_cesu8"
|
||||
version = "1.0.1"
|
||||
@ -3442,25 +3373,6 @@ dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.39"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dad298b01a40a23aac4580b67e3dbedb7cc8402f3592d7f49469de2ea4aecdd8"
|
||||
dependencies = [
|
||||
"deranged",
|
||||
"num-conv",
|
||||
"powerfmt",
|
||||
"serde",
|
||||
"time-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time-core"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "765c97a5b985b7c11d7bc27fa927dc4fe6af3a6dfb021d28deb60d3bf51e76ef"
|
||||
|
||||
[[package]]
|
||||
name = "tiny-keccak"
|
||||
version = "2.0.2"
|
||||
@ -4183,20 +4095,6 @@ name = "zeroize"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde"
|
||||
dependencies = [
|
||||
"zeroize_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zeroize_derive"
|
||||
version = "1.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerovec"
|
||||
@ -4226,67 +4124,12 @@ version = "2.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b280484c454e74e5fff658bbf7df8fdbe7a07c6b2de4a53def232c15ef138f3a"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"arbitrary",
|
||||
"bzip2",
|
||||
"constant_time_eq",
|
||||
"crc32fast",
|
||||
"crossbeam-utils",
|
||||
"deflate64",
|
||||
"displaydoc",
|
||||
"flate2",
|
||||
"hmac",
|
||||
"indexmap 2.7.1",
|
||||
"lzma-rs",
|
||||
"memchr",
|
||||
"pbkdf2",
|
||||
"rand",
|
||||
"sha1",
|
||||
"thiserror 2.0.11",
|
||||
"time",
|
||||
"zeroize",
|
||||
"zopfli",
|
||||
"zstd",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zopfli"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5019f391bac5cf252e93bbcc53d039ffd62c7bfb7c150414d61369afe57e946"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"crc32fast",
|
||||
"lockfree-object-pool",
|
||||
"log",
|
||||
"once_cell",
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zstd"
|
||||
version = "0.13.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a"
|
||||
dependencies = [
|
||||
"zstd-safe",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zstd-safe"
|
||||
version = "7.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f3051792fbdc2e1e143244dc28c60f73d8470e93f3f9cbd0ead44da5ed802722"
|
||||
dependencies = [
|
||||
"zstd-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zstd-sys"
|
||||
version = "2.0.14+zstd.1.5.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fb060d4926e4ac3a3ad15d864e99ceb5f343c6b34f5bd6d81ae6ed417311be5"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
@ -32,12 +32,18 @@ http-body-util = "0"
|
||||
hyper = { version = "1", features = ["server"] }
|
||||
hyper-util = "0"
|
||||
log = { version = "0" }
|
||||
mimalloc = { version = "0", optional = true }
|
||||
mlua = { version = "0", features = ["async", "luajit", "send"] }
|
||||
ncr = { version = "0", features = ["cfb8", "ecb", "gcm"] }
|
||||
parking_lot = "0"
|
||||
serde_json = "1"
|
||||
smallvec = { version = "1", features = ["write"] }
|
||||
tokio = { version = "1", features = ["macros"] }
|
||||
zip = "2"
|
||||
zip = { version = "2", default-features = false, features = [
|
||||
"deflate-flate2",
|
||||
"flate2",
|
||||
] }
|
||||
|
||||
[features]
|
||||
console-subscriber = ["dep:console-subscriber"]
|
||||
mimalloc = ["dep:mimalloc"]
|
||||
|
2
build.rs
2
build.rs
@ -1,3 +1,3 @@
|
||||
fn main() {
|
||||
built::write_built_file().unwrap();
|
||||
built::write_built_file().expect("appropriate environment variables should have been set");
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
Server = "localhost"
|
||||
Username = "ErrorNoWatcher"
|
||||
HttpAddress = "127.0.0.1:8080"
|
||||
Owners = { "ErrorNoInternet" }
|
||||
|
||||
for _, module in ipairs({
|
||||
"lib",
|
||||
"automation",
|
||||
"enum",
|
||||
"events",
|
||||
"inventory",
|
||||
"lib",
|
||||
"movement",
|
||||
"utils",
|
||||
}) do
|
||||
|
@ -1,6 +1,6 @@
|
||||
Center = { x = 0, y = 64, z = 0 }
|
||||
Radius = 100
|
||||
Whitelist = Owners
|
||||
Whitelist = table.shallow_copy(Owners)
|
||||
Ticks = -1
|
||||
|
||||
function check_radius()
|
||||
|
@ -145,7 +145,7 @@ function interact_bed()
|
||||
return
|
||||
end
|
||||
|
||||
client:go_to(bed, { type = REACH_BLOCK_POS_GOAL, options = { without_mining = true } })
|
||||
client:go_to({ position = bed, radius = 2 }, { type = RADIUS_GOAL, options = { without_mining = true } })
|
||||
while client.pathfinder.is_calculating or client.pathfinder.is_executing do
|
||||
sleep(500)
|
||||
end
|
||||
|
@ -1,16 +1,16 @@
|
||||
use crate::build_info;
|
||||
use clap::Parser;
|
||||
use std::{net::SocketAddr, path::PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// A Minecraft utility bot
|
||||
#[derive(Parser)]
|
||||
#[command(version = build_info::version_formatted())]
|
||||
pub struct Arguments {
|
||||
/// Path to main Lua file
|
||||
/// Path to Lua entrypoint
|
||||
#[arg(short, long)]
|
||||
pub script: Option<PathBuf>,
|
||||
|
||||
/// Socket address to bind HTTP server to
|
||||
#[arg(short = 'a', long)]
|
||||
pub http_address: Option<SocketAddr>,
|
||||
/// Code to execute after loading script
|
||||
#[arg(short, long)]
|
||||
pub exec: Option<String>,
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use crate::{
|
||||
http::serve,
|
||||
lua::{client, direction::Direction, player::Player, vec3::Vec3},
|
||||
particle,
|
||||
replay::Recorder,
|
||||
replay::recorder::Recorder,
|
||||
};
|
||||
use anyhow::Context;
|
||||
use azalea::{
|
||||
@ -16,6 +16,7 @@ use hyper_util::rt::TokioIo;
|
||||
use log::{debug, error, info, trace};
|
||||
use mlua::{Error, Function, IntoLuaMulti, Table};
|
||||
use ncr::utils::trim_header;
|
||||
use std::net::SocketAddr;
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
@ -164,6 +165,13 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow:
|
||||
table.set("passengers", &*packet.passengers)?;
|
||||
call_listeners(&state, "set_passengers", table).await;
|
||||
}
|
||||
ClientboundGamePacket::SetTime(packet) => {
|
||||
let table = state.lua.create_table()?;
|
||||
table.set("day_time", packet.day_time)?;
|
||||
table.set("game_time", packet.game_time)?;
|
||||
table.set("tick_day_time", packet.tick_day_time)?;
|
||||
call_listeners(&state, "set_time", table).await;
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
Event::Init => {
|
||||
@ -191,7 +199,11 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow:
|
||||
)?;
|
||||
call_listeners(&state, "init", ()).await;
|
||||
|
||||
let Some(address) = state.http_address else {
|
||||
let Some(address): Option<SocketAddr> = globals
|
||||
.get::<String>("HttpAddress")
|
||||
.ok()
|
||||
.and_then(|string| string.parse().ok())
|
||||
else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
|
@ -41,7 +41,7 @@ pub async fn get_block_states(
|
||||
lua: Lua,
|
||||
(block_names, filter_fn): (Vec<String>, Option<Function>),
|
||||
) -> Result<Vec<u16>> {
|
||||
let mut matched = Vec::new();
|
||||
let mut matched = Vec::with_capacity(16);
|
||||
for block_name in block_names {
|
||||
for block in
|
||||
(u32::MIN..u32::MAX).map_while(|possible_id| BlockState::try_from(possible_id).ok())
|
||||
|
@ -109,11 +109,7 @@ fn id(_lua: &Lua, client: &Client) -> Result<i32> {
|
||||
}
|
||||
|
||||
fn tab_list(_lua: &Lua, client: &Client) -> Result<Vec<Player>> {
|
||||
let mut tab_list = Vec::new();
|
||||
for (_, player_info) in client.tab_list() {
|
||||
tab_list.push(Player::from(player_info));
|
||||
}
|
||||
Ok(tab_list)
|
||||
Ok(client.tab_list().into_values().map(Player::from).collect())
|
||||
}
|
||||
|
||||
fn username(_lua: &Lua, client: &Client) -> Result<String> {
|
||||
|
@ -56,7 +56,7 @@ pub async fn find_all_entities(
|
||||
client: UserDataRef<Client>,
|
||||
(): (),
|
||||
) -> Result<Vec<Table>> {
|
||||
let mut matched = Vec::new();
|
||||
let mut matched = Vec::with_capacity(256);
|
||||
for (position, custom_name, kind, uuid, direction, id, owner_uuid, pose) in
|
||||
get_entities!(client)
|
||||
{
|
||||
|
@ -52,7 +52,7 @@ pub fn reload(lua: &Lua, sender: Option<String>) -> Result<(), Error> {
|
||||
lua.load(
|
||||
&std::fs::read_to_string(
|
||||
lua.globals()
|
||||
.get::<String>("script_path")
|
||||
.get::<String>("SCRIPT_PATH")
|
||||
.map_err(Error::MissingPath)?,
|
||||
)
|
||||
.map_err(Error::ReadFile)?,
|
||||
|
@ -4,7 +4,7 @@ macro_rules! crypt {
|
||||
macro_rules! crypt_with {
|
||||
($algo:ident) => {{
|
||||
let encoding = $options.get("encoding").unwrap_or_default();
|
||||
let key = &$options.get::<UserDataRef<AesKey>>("$key")?.inner;
|
||||
let key = &$options.get::<UserDataRef<AesKey>>("key")?.inner;
|
||||
match encoding {
|
||||
1 => $algo::<Base64Encoding>::$op($text, &key),
|
||||
2 => $algo::<Base64rEncoding>::$op($text, &key),
|
||||
|
@ -13,7 +13,7 @@ pub struct Player {
|
||||
impl From<PlayerInfo> for Player {
|
||||
fn from(p: PlayerInfo) -> Self {
|
||||
Self {
|
||||
display_name: p.display_name.map(|n| n.to_string()),
|
||||
display_name: p.display_name.map(|text| text.to_string()),
|
||||
gamemode: p.gamemode.to_id(),
|
||||
latency: p.latency,
|
||||
name: p.profile.name,
|
||||
|
21
src/main.rs
21
src/main.rs
@ -9,6 +9,7 @@ mod lua;
|
||||
mod particle;
|
||||
mod replay;
|
||||
|
||||
use anyhow::Context;
|
||||
use arguments::Arguments;
|
||||
use azalea::{
|
||||
DefaultBotPlugins, DefaultPlugins, brigadier::prelude::CommandDispatcher, prelude::*,
|
||||
@ -23,23 +24,23 @@ use commands::{CommandSource, register};
|
||||
use futures::lock::Mutex;
|
||||
use futures_locks::RwLock;
|
||||
use mlua::{Function, Lua, Table};
|
||||
use replay::{Recorder, plugin::RecordPlugin};
|
||||
use replay::{plugin::RecordPlugin, recorder::Recorder};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
env,
|
||||
fs::{OpenOptions, read_to_string},
|
||||
net::SocketAddr,
|
||||
path::PathBuf,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
const DEFAULT_SCRIPT_PATH: &str = "errornowatcher.lua";
|
||||
#[cfg(feature = "mimalloc")]
|
||||
#[global_allocator]
|
||||
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
||||
|
||||
type ListenerMap = Arc<RwLock<HashMap<String, Vec<(String, Function)>>>>;
|
||||
|
||||
#[derive(Default, Clone, Component)]
|
||||
pub struct State {
|
||||
http_address: Option<SocketAddr>,
|
||||
lua: Arc<Lua>,
|
||||
event_listeners: ListenerMap,
|
||||
commands: Arc<CommandDispatcher<Mutex<CommandSource>>>,
|
||||
@ -51,18 +52,21 @@ async fn main() -> anyhow::Result<()> {
|
||||
console_subscriber::init();
|
||||
|
||||
let args = Arguments::parse();
|
||||
let script_path = args.script.unwrap_or(PathBuf::from(DEFAULT_SCRIPT_PATH));
|
||||
let script_path = args.script.unwrap_or(PathBuf::from("errornowatcher.lua"));
|
||||
let event_listeners = Arc::new(RwLock::new(HashMap::new()));
|
||||
let lua = unsafe { Lua::unsafe_new() };
|
||||
let globals = lua.globals();
|
||||
|
||||
globals.set("script_path", &*script_path)?;
|
||||
lua::register_globals(&lua, &globals, event_listeners.clone())?;
|
||||
globals.set("SCRIPT_PATH", &*script_path)?;
|
||||
lua.load(
|
||||
read_to_string(script_path)
|
||||
.expect(&(DEFAULT_SCRIPT_PATH.to_owned() + " should be in current directory")),
|
||||
read_to_string(&script_path).with_context(|| format!("failed to read {script_path:?}"))?,
|
||||
)
|
||||
.exec()?;
|
||||
if let Some(code) = args.exec {
|
||||
lua.load(code).exec()?;
|
||||
}
|
||||
|
||||
let server = globals
|
||||
.get::<String>("Server")
|
||||
.expect("Server should be in lua globals");
|
||||
@ -116,7 +120,6 @@ async fn main() -> anyhow::Result<()> {
|
||||
.add_plugins(DefaultBotPlugins)
|
||||
.set_handler(events::handle_event)
|
||||
.set_state(State {
|
||||
http_address: args.http_address,
|
||||
lua: Arc::new(lua),
|
||||
event_listeners,
|
||||
commands: Arc::new(commands),
|
||||
|
@ -1,88 +1,2 @@
|
||||
pub mod plugin;
|
||||
|
||||
use crate::build_info;
|
||||
use anyhow::Result;
|
||||
use azalea::{
|
||||
buf::AzaleaWriteVar,
|
||||
prelude::Resource,
|
||||
protocol::packets::{PROTOCOL_VERSION, ProtocolPacket, VERSION_NAME},
|
||||
};
|
||||
use serde_json::json;
|
||||
use std::{
|
||||
fs::File,
|
||||
io::Write,
|
||||
time::{SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
use zip::{ZipWriter, write::SimpleFileOptions};
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct Recorder {
|
||||
zip_writer: ZipWriter<File>,
|
||||
start_time: u128,
|
||||
server: String,
|
||||
ignore_compression: bool,
|
||||
}
|
||||
|
||||
impl Recorder {
|
||||
pub fn new(path: String, server: String, ignore_compression: bool) -> Result<Self> {
|
||||
let mut zip_writer = ZipWriter::new(
|
||||
File::options()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open(path)?,
|
||||
);
|
||||
zip_writer.start_file("recording.tmcpr", SimpleFileOptions::default())?;
|
||||
Ok(Self {
|
||||
zip_writer,
|
||||
start_time: SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis(),
|
||||
server,
|
||||
ignore_compression,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn finish(mut self) -> Result<()> {
|
||||
self.zip_writer
|
||||
.start_file("metaData.json", SimpleFileOptions::default())?;
|
||||
self.zip_writer.write_all(
|
||||
json!({
|
||||
"singleplayer": false,
|
||||
"serverName": self.server,
|
||||
"duration": SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis() - self.start_time,
|
||||
"date": self.start_time,
|
||||
"mcversion": VERSION_NAME,
|
||||
"fileFormat": "MCPR",
|
||||
"fileFormatVersion": 14,
|
||||
"protocol": PROTOCOL_VERSION,
|
||||
"generator": build_info::version_formatted(),
|
||||
})
|
||||
.to_string()
|
||||
.as_bytes(),
|
||||
)?;
|
||||
self.zip_writer.finish()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_timestamp(&self) -> Result<[u8; 4]> {
|
||||
Ok(TryInto::<u32>::try_into(
|
||||
SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis() - self.start_time,
|
||||
)?
|
||||
.to_be_bytes())
|
||||
}
|
||||
|
||||
fn save_raw_packet(&mut self, raw_packet: &[u8]) -> Result<()> {
|
||||
let mut data = Vec::from(self.get_timestamp()?);
|
||||
data.extend(TryInto::<u32>::try_into(raw_packet.len())?.to_be_bytes());
|
||||
data.extend(raw_packet);
|
||||
self.zip_writer.write_all(&data)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn save_packet<T: ProtocolPacket>(&mut self, packet: &T) -> Result<()> {
|
||||
let mut raw_packet = Vec::new();
|
||||
packet.id().azalea_write_var(&mut raw_packet)?;
|
||||
packet.write(&mut raw_packet)?;
|
||||
self.save_raw_packet(&raw_packet)
|
||||
}
|
||||
}
|
||||
pub mod recorder;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use super::Recorder;
|
||||
use super::recorder::Recorder;
|
||||
use azalea::{
|
||||
ecs::{event::EventReader, system::Query},
|
||||
packet_handling::{
|
||||
@ -36,7 +36,7 @@ fn record_login_packets(
|
||||
) {
|
||||
if let Some(mut recorder) = recorder {
|
||||
for event in events.read() {
|
||||
if recorder.ignore_compression
|
||||
if recorder.should_ignore_compression
|
||||
&& let ClientboundLoginPacket::LoginCompression(_) = *event.packet
|
||||
{
|
||||
continue;
|
||||
|
87
src/replay/recorder.rs
Normal file
87
src/replay/recorder.rs
Normal file
@ -0,0 +1,87 @@
|
||||
use crate::build_info;
|
||||
use anyhow::Result;
|
||||
use azalea::{
|
||||
buf::AzaleaWriteVar,
|
||||
prelude::Resource,
|
||||
protocol::packets::{PROTOCOL_VERSION, ProtocolPacket, VERSION_NAME},
|
||||
};
|
||||
use serde_json::json;
|
||||
use smallvec::SmallVec;
|
||||
use std::{
|
||||
fs::File,
|
||||
io::Write,
|
||||
time::{Instant, SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
use zip::{ZipWriter, write::SimpleFileOptions};
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct Recorder {
|
||||
zip_writer: ZipWriter<File>,
|
||||
start: Instant,
|
||||
server: String,
|
||||
pub should_ignore_compression: bool,
|
||||
}
|
||||
|
||||
impl Recorder {
|
||||
pub fn new(path: String, server: String, should_ignore_compression: bool) -> Result<Self> {
|
||||
let mut zip_writer = ZipWriter::new(
|
||||
File::options()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open(path)?,
|
||||
);
|
||||
zip_writer.start_file("recording.tmcpr", SimpleFileOptions::default())?;
|
||||
Ok(Self {
|
||||
zip_writer,
|
||||
start: Instant::now(),
|
||||
server,
|
||||
should_ignore_compression,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn finish(mut self) -> Result<()> {
|
||||
let elapsed = self.start.elapsed();
|
||||
|
||||
self.zip_writer
|
||||
.start_file("metaData.json", SimpleFileOptions::default())?;
|
||||
self.zip_writer.write_all(
|
||||
json!({
|
||||
"singleplayer": false,
|
||||
"serverName": self.server,
|
||||
"duration": elapsed.as_millis(),
|
||||
"date": (SystemTime::now().duration_since(UNIX_EPOCH)? - elapsed).as_millis(),
|
||||
"mcversion": VERSION_NAME,
|
||||
"fileFormat": "MCPR",
|
||||
"fileFormatVersion": 14,
|
||||
"protocol": PROTOCOL_VERSION,
|
||||
"generator": format!("errornowatcher {}", build_info::version_formatted()),
|
||||
})
|
||||
.to_string()
|
||||
.as_bytes(),
|
||||
)?;
|
||||
self.zip_writer.finish()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_timestamp(&self) -> Result<[u8; 4]> {
|
||||
Ok(TryInto::<u32>::try_into(self.start.elapsed().as_millis())?.to_be_bytes())
|
||||
}
|
||||
|
||||
pub fn save_raw_packet(&mut self, raw_packet: &[u8]) -> Result<()> {
|
||||
let mut data = Vec::with_capacity(raw_packet.len() + 8);
|
||||
data.extend(self.get_timestamp()?);
|
||||
data.extend(&TryInto::<u32>::try_into(raw_packet.len())?.to_be_bytes());
|
||||
data.extend(raw_packet);
|
||||
self.zip_writer.write_all(&data)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn save_packet<T: ProtocolPacket>(&mut self, packet: &T) -> Result<()> {
|
||||
let mut raw_packet = SmallVec::<[u8; 256]>::new();
|
||||
packet.id().azalea_write_var(&mut raw_packet)?;
|
||||
packet.write(&mut raw_packet)?;
|
||||
self.save_raw_packet(&raw_packet)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user