Compare commits

..

No commits in common. "571581767ec6f8a4c6b25619a99d267c658cde0f" and "a957aaeaec9625822086786bcacdf48b3ce0c981" have entirely different histories.

4 changed files with 23 additions and 45 deletions

View File

@ -7,12 +7,11 @@ pub mod logging;
pub mod nochatreports;
pub mod player;
pub mod system;
pub mod thread;
pub mod vec3;
use crate::{ListenerMap, build_info::built};
use mlua::{Lua, Table};
use std::io;
use std::{io, time::Duration};
#[derive(Debug)]
#[allow(dead_code)]
@ -34,12 +33,19 @@ pub fn register_globals(
globals.set("GIT_COMMIT_HASH", built::GIT_COMMIT_HASH)?;
globals.set("GIT_COMMIT_HASH_SHORT", built::GIT_COMMIT_HASH_SHORT)?;
globals.set(
"sleep",
lua.create_async_function(async |_, duration: u64| {
tokio::time::sleep(Duration::from_millis(duration)).await;
Ok(())
})?,
)?;
block::register_globals(lua, globals)?;
events::register_globals(lua, globals, event_listeners)?;
logging::register_globals(lua, globals)?;
nochatreports::register_globals(lua, globals)?;
system::register_globals(lua, globals)?;
thread::register_globals(lua, globals)
system::register_globals(lua, globals)
}
pub fn reload(lua: &Lua, sender: Option<String>) -> Result<(), Error> {

View File

@ -1,27 +0,0 @@
use mlua::{Error, Function, Lua, Result, Table};
use std::time::Duration;
use tokio::time::{sleep, timeout};
pub fn register_globals(lua: &Lua, globals: &Table) -> Result<()> {
globals.set(
"sleep",
lua.create_async_function(async |_, duration: u64| {
sleep(Duration::from_millis(duration)).await;
Ok(())
})?,
)?;
globals.set(
"timeout",
lua.create_async_function(async |_, (duration, function): (u64, Function)| {
timeout(
Duration::from_millis(duration),
function.call_async::<()>(()),
)
.await
.map_err(Error::external)
})?,
)?;
Ok(())
}

View File

@ -14,7 +14,6 @@ use arguments::Arguments;
use azalea::{
DefaultBotPlugins, DefaultPlugins, brigadier::prelude::CommandDispatcher, prelude::*,
};
use azalea_hax::HaxPlugin;
use bevy_app::PluginGroup;
use bevy_log::{
LogPlugin,
@ -114,14 +113,8 @@ async fn main() -> anyhow::Result<()> {
},
)),
};
let account = if username.contains('@') {
Account::microsoft(&username).await?
} else {
Account::offline(&username)
};
let Err(error) = ClientBuilder::new_without_plugins()
.add_plugins(DefaultBotPlugins)
.add_plugins(HaxPlugin)
.add_plugins(default_plugins)
.add_plugins(record_plugin)
.set_handler(events::handle_event)
@ -130,7 +123,14 @@ async fn main() -> anyhow::Result<()> {
event_listeners,
commands: Arc::new(commands),
})
.start(account, server)
.start(
if username.contains('@') {
Account::microsoft(&username).await?
} else {
Account::offline(&username)
},
server,
)
.await;
eprintln!("{error}");

View File

@ -68,12 +68,11 @@ impl Recorder {
}
pub fn save_raw_packet(&mut self, raw_packet: &[u8]) -> Result<()> {
self.zip_writer.write_all(
&TryInto::<u32>::try_into(self.start.elapsed().as_millis())?.to_be_bytes(),
)?;
self.zip_writer
.write_all(&TryInto::<u32>::try_into(raw_packet.len())?.to_be_bytes())?;
self.zip_writer.write_all(raw_packet)?;
let mut data = Vec::with_capacity(raw_packet.len() + 8);
data.extend(TryInto::<u32>::try_into(self.start.elapsed().as_millis())?.to_be_bytes());
data.extend(TryInto::<u32>::try_into(raw_packet.len())?.to_be_bytes());
data.extend(raw_packet);
self.zip_writer.write_all(&data)?;
Ok(())
}