Compare commits

..

No commits in common. "e85d02cee287a86215308c3877c438b5fac38375" and "e7133ecc5fbe09e167535a23bb24448b60b8ff5d" have entirely different histories.

7 changed files with 58 additions and 58 deletions

42
Cargo.lock generated
View File

@ -378,7 +378,7 @@ dependencies = [
[[package]] [[package]]
name = "azalea" name = "azalea"
version = "0.11.0+mc1.21.4" version = "0.11.0+mc1.21.4"
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654" source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
dependencies = [ dependencies = [
"azalea-auth", "azalea-auth",
"azalea-block", "azalea-block",
@ -416,7 +416,7 @@ dependencies = [
[[package]] [[package]]
name = "azalea-auth" name = "azalea-auth"
version = "0.11.0+mc1.21.4" version = "0.11.0+mc1.21.4"
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654" source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
dependencies = [ dependencies = [
"azalea-buf", "azalea-buf",
"azalea-crypto", "azalea-crypto",
@ -436,7 +436,7 @@ dependencies = [
[[package]] [[package]]
name = "azalea-block" name = "azalea-block"
version = "0.11.0+mc1.21.4" version = "0.11.0+mc1.21.4"
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654" source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
dependencies = [ dependencies = [
"azalea-block-macros", "azalea-block-macros",
"azalea-buf", "azalea-buf",
@ -446,7 +446,7 @@ dependencies = [
[[package]] [[package]]
name = "azalea-block-macros" name = "azalea-block-macros"
version = "0.11.0+mc1.21.4" version = "0.11.0+mc1.21.4"
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654" source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -456,7 +456,7 @@ dependencies = [
[[package]] [[package]]
name = "azalea-brigadier" name = "azalea-brigadier"
version = "0.11.0+mc1.21.4" version = "0.11.0+mc1.21.4"
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654" source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
dependencies = [ dependencies = [
"azalea-buf", "azalea-buf",
"azalea-chat", "azalea-chat",
@ -466,7 +466,7 @@ dependencies = [
[[package]] [[package]]
name = "azalea-buf" name = "azalea-buf"
version = "0.11.0+mc1.21.4" version = "0.11.0+mc1.21.4"
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654" source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
dependencies = [ dependencies = [
"azalea-buf-macros", "azalea-buf-macros",
"byteorder", "byteorder",
@ -480,7 +480,7 @@ dependencies = [
[[package]] [[package]]
name = "azalea-buf-macros" name = "azalea-buf-macros"
version = "0.11.0+mc1.21.4" version = "0.11.0+mc1.21.4"
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654" source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -490,7 +490,7 @@ dependencies = [
[[package]] [[package]]
name = "azalea-chat" name = "azalea-chat"
version = "0.11.0+mc1.21.4" version = "0.11.0+mc1.21.4"
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654" source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
dependencies = [ dependencies = [
"azalea-buf", "azalea-buf",
"azalea-language", "azalea-language",
@ -504,7 +504,7 @@ dependencies = [
[[package]] [[package]]
name = "azalea-client" name = "azalea-client"
version = "0.11.0+mc1.21.4" version = "0.11.0+mc1.21.4"
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654" source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
dependencies = [ dependencies = [
"azalea-auth", "azalea-auth",
"azalea-block", "azalea-block",
@ -539,7 +539,7 @@ dependencies = [
[[package]] [[package]]
name = "azalea-core" name = "azalea-core"
version = "0.11.0+mc1.21.4" version = "0.11.0+mc1.21.4"
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654" source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
dependencies = [ dependencies = [
"azalea-buf", "azalea-buf",
"azalea-chat", "azalea-chat",
@ -556,7 +556,7 @@ dependencies = [
[[package]] [[package]]
name = "azalea-crypto" name = "azalea-crypto"
version = "0.11.0+mc1.21.4" version = "0.11.0+mc1.21.4"
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654" source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
dependencies = [ dependencies = [
"aes", "aes",
"azalea-buf", "azalea-buf",
@ -573,7 +573,7 @@ dependencies = [
[[package]] [[package]]
name = "azalea-entity" name = "azalea-entity"
version = "0.11.0+mc1.21.4" version = "0.11.0+mc1.21.4"
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654" source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
dependencies = [ dependencies = [
"azalea-block", "azalea-block",
"azalea-buf", "azalea-buf",
@ -597,7 +597,7 @@ dependencies = [
[[package]] [[package]]
name = "azalea-inventory" name = "azalea-inventory"
version = "0.11.0+mc1.21.4" version = "0.11.0+mc1.21.4"
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654" source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
dependencies = [ dependencies = [
"azalea-buf", "azalea-buf",
"azalea-chat", "azalea-chat",
@ -613,7 +613,7 @@ dependencies = [
[[package]] [[package]]
name = "azalea-inventory-macros" name = "azalea-inventory-macros"
version = "0.11.0+mc1.21.4" version = "0.11.0+mc1.21.4"
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654" source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -623,7 +623,7 @@ dependencies = [
[[package]] [[package]]
name = "azalea-language" name = "azalea-language"
version = "0.11.0+mc1.21.4" version = "0.11.0+mc1.21.4"
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654" source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
dependencies = [ dependencies = [
"compact_str", "compact_str",
"serde", "serde",
@ -633,7 +633,7 @@ dependencies = [
[[package]] [[package]]
name = "azalea-physics" name = "azalea-physics"
version = "0.11.0+mc1.21.4" version = "0.11.0+mc1.21.4"
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654" source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
dependencies = [ dependencies = [
"azalea-block", "azalea-block",
"azalea-core", "azalea-core",
@ -650,7 +650,7 @@ dependencies = [
[[package]] [[package]]
name = "azalea-protocol" name = "azalea-protocol"
version = "0.11.0+mc1.21.4" version = "0.11.0+mc1.21.4"
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654" source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
dependencies = [ dependencies = [
"async-recursion", "async-recursion",
"azalea-auth", "azalea-auth",
@ -684,7 +684,7 @@ dependencies = [
[[package]] [[package]]
name = "azalea-protocol-macros" name = "azalea-protocol-macros"
version = "0.11.0+mc1.21.4" version = "0.11.0+mc1.21.4"
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654" source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -694,7 +694,7 @@ dependencies = [
[[package]] [[package]]
name = "azalea-registry" name = "azalea-registry"
version = "0.11.0+mc1.21.4" version = "0.11.0+mc1.21.4"
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654" source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
dependencies = [ dependencies = [
"azalea-buf", "azalea-buf",
"azalea-registry-macros", "azalea-registry-macros",
@ -705,7 +705,7 @@ dependencies = [
[[package]] [[package]]
name = "azalea-registry-macros" name = "azalea-registry-macros"
version = "0.11.0+mc1.21.4" version = "0.11.0+mc1.21.4"
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654" source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
dependencies = [ dependencies = [
"quote", "quote",
"syn", "syn",
@ -714,7 +714,7 @@ dependencies = [
[[package]] [[package]]
name = "azalea-world" name = "azalea-world"
version = "0.11.0+mc1.21.4" version = "0.11.0+mc1.21.4"
source = "git+https://github.com/azalea-rs/azalea#aa2039c86888e8ef47072fde63634ec58b22a654" source = "git+https://github.com/azalea-rs/azalea#75efbc83fdc4a47f880e95259a339d41839af01a"
dependencies = [ dependencies = [
"azalea-block", "azalea-block",
"azalea-buf", "azalea-buf",

View File

@ -2,7 +2,7 @@ Server = "localhost"
Username = "ErrorNoWatcher" Username = "ErrorNoWatcher"
HttpAddress = "127.0.0.1:8080" HttpAddress = "127.0.0.1:8080"
Owners = { "ErrorNoInternet" } Owners = { "ErrorNoInternet" }
Matrix = { Owners = { "@errornointernet:envs.net" } } MatrixOwners = { "@errornointernet:envs.net" }
for _, module in ipairs({ for _, module in ipairs({
"lib", "lib",

View File

@ -46,7 +46,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
.call::<String>((options.clone(), content.clone())) .call::<String>((options.clone(), content.clone()))
.ok() .ok()
.as_deref() .as_deref()
.and_then(|string| trim_header(string).ok()) .and_then(|s| trim_header(s).ok())
{ {
is_encrypted = true; is_encrypted = true;
ncr_options = Some(options); ncr_options = Some(options);
@ -128,7 +128,6 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
Event::RemovePlayer(player_info) => { Event::RemovePlayer(player_info) => {
call_listeners(&state, "remove_player", || Ok(Player::from(player_info))).await call_listeners(&state, "remove_player", || Ok(Player::from(player_info))).await
} }
Event::Spawn => call_listeners(&state, "spawn", || Ok(())).await,
Event::Tick => call_listeners(&state, "tick", || Ok(())).await, Event::Tick => call_listeners(&state, "tick", || Ok(())).await,
Event::UpdatePlayer(player_info) => { Event::UpdatePlayer(player_info) => {
call_listeners(&state, "update_player", || Ok(Player::from(player_info))).await call_listeners(&state, "update_player", || Ok(Player::from(player_info))).await
@ -256,7 +255,6 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
}); });
} }
} }
_ => todo!(),
} }
} }
@ -280,10 +278,15 @@ async fn lua_init(client: Client, state: &State, globals: &Table) -> Result<()>
#[cfg(feature = "matrix")] #[cfg(feature = "matrix")]
fn matrix_init(client: &Client, state: State) { fn matrix_init(client: &Client, state: State) {
let globals = state.lua.globals(); let globals = state.lua.globals();
if let Ok(matrix_options) = globals.get::<Table>("MatrixOptions") { if let Ok(homeserver_url) = globals.get::<String>("MatrixHomeserverUrl")
&& let Ok(username) = globals.get::<String>("MatrixUsername")
&& let Ok(password) = globals.get::<String>("MatrixPassword")
{
let name = client.username(); let name = client.username();
tokio::spawn(async move { tokio::spawn(async move {
if let Err(error) = matrix::login(state, matrix_options, globals, name).await { if let Err(error) =
matrix::login(homeserver_url, username, &password, state, globals, name).await
{
error!("failed to log into matrix account: {error:?}"); error!("failed to log into matrix account: {error:?}");
} }
}); });

View File

@ -22,10 +22,9 @@ pub fn held_slot(_lua: &Lua, client: &Client) -> Result<u8> {
#[allow(clippy::too_many_lines)] #[allow(clippy::too_many_lines)]
pub fn menu(lua: &Lua, client: &Client) -> Result<Value> { pub fn menu(lua: &Lua, client: &Client) -> Result<Value> {
fn from_slot_list<const N: usize>(slot_list: SlotList<N>) -> Vec<ItemStack> { fn from_slot_list<const N: usize>(s: SlotList<N>) -> Vec<ItemStack> {
slot_list s.iter()
.iter() .map(|i| ItemStack(i.to_owned()))
.map(|item_stack| ItemStack(item_stack.to_owned()))
.collect::<Vec<_>>() .collect::<Vec<_>>()
} }

View File

@ -28,7 +28,7 @@ pub fn get_block_state(_lua: &Lua, client: &Client, position: Vec3) -> Result<Op
position.y as i32, position.y as i32,
position.z as i32, position.z as i32,
)) ))
.map(|block| block.id)) .map(|b| b.id))
} }
pub fn get_fluid_state(lua: &Lua, client: &Client, position: Vec3) -> Result<Option<Table>> { pub fn get_fluid_state(lua: &Lua, client: &Client, position: Vec3) -> Result<Option<Table>> {

View File

@ -28,7 +28,15 @@ pub async fn on_regular_room_message(
return Ok(()); return Ok(());
}; };
if ctx.is_owner(&event.sender.to_string()) && text_content.body.starts_with(&ctx.name) { if ctx
.state
.lua
.globals()
.get::<Vec<String>>("MatrixOwners")
.unwrap_or_default()
.contains(&event.sender.to_string())
&& text_content.body.starts_with(&ctx.name)
{
let body = text_content.body[ctx.name.len()..] let body = text_content.body[ctx.name.len()..]
.trim_start_matches(':') .trim_start_matches(':')
.trim(); .trim();
@ -93,7 +101,13 @@ pub async fn on_stripped_state_member(
) -> Result<()> { ) -> Result<()> {
if let Some(user_id) = client.user_id() if let Some(user_id) = client.user_id()
&& member.state_key == user_id && member.state_key == user_id
&& ctx.is_owner(&member.sender.to_string()) && ctx
.state
.lua
.globals()
.get::<Vec<String>>("MatrixOwners")
.unwrap_or_default()
.contains(&member.sender.to_string())
{ {
debug!("joining room {}", room.room_id()); debug!("joining room {}", room.room_id());
while let Err(error) = room.join().await { while let Err(error) = room.join().await {

View File

@ -20,23 +20,6 @@ pub struct Context {
name: String, name: String,
} }
impl Context {
fn is_owner(&self, name: &String) -> bool {
self.state
.lua
.globals()
.get::<Table>("MatrixOptions")
.ok()
.and_then(|options| {
options
.get::<Vec<String>>("Owners")
.ok()
.and_then(|owners| owners.contains(name).then_some(()))
})
.is_some()
}
}
#[derive(Clone, Serialize, Deserialize)] #[derive(Clone, Serialize, Deserialize)]
struct Session { struct Session {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -54,13 +37,14 @@ async fn persist_sync_token(
Ok(()) Ok(())
} }
pub async fn login(state: State, options: Table, globals: Table, name: String) -> Result<()> { pub async fn login(
let (homeserver_url, username, password) = ( homeserver_url: String,
options.get::<String>("HomeserverUrl")?, username: String,
options.get::<String>("Username")?, password: &str,
&options.get::<String>("Password")?, state: State,
); globals: Table,
name: String,
) -> Result<()> {
let root_dir = dirs::data_dir() let root_dir = dirs::data_dir()
.context("no data directory")? .context("no data directory")?
.join("errornowatcher") .join("errornowatcher")