diff --git a/src/lua_engine.rs b/src/lua_engine.rs index 9864ab2..314c49f 100644 --- a/src/lua_engine.rs +++ b/src/lua_engine.rs @@ -322,6 +322,16 @@ pub fn install_lua_globals( register_stateless_class_function!(mud_class_table, "new", new_mud); register_class_function!(mud_class_table, "term_resized", mud_term_resized); register_class_function!(mud_class_table, local_naws_enabled); + register_stateless_class_function!( + mud_class_table, + "local_termtype_enabled", + opt_enabled_noop + ); + register_stateless_class_function!( + mud_class_table, + "remote_eor_enabled", + opt_enabled_noop + ); macro_rules! register_class_nop { ($class_table: ident, $sym: ident) => { diff --git a/src/lua_engine/muds.rs b/src/lua_engine/muds.rs index fcec8a4..678520d 100644 --- a/src/lua_engine/muds.rs +++ b/src/lua_engine/muds.rs @@ -4,7 +4,7 @@ use piccolo::{ self, async_sequence, Callback, CallbackReturn, Context, FromValue, Function, IntoValue, SequenceReturn, StashedTable, StashedUserData, StashedValue, Table, UserData, Value, }; -use telopt::TERMTYPE_TELOPT; +use telopt::{EOR_TELOPT, TERMTYPE_TELOPT}; use wasm_bindgen::JsValue; use web_sys::{console, window}; use yew::UseStateSetter; @@ -241,6 +241,7 @@ pub(super) fn connect_mud<'gc>( set_option_supported(ctx, &conntab, &NAWS_TELOPT, &Side::Us); } set_option_supported(ctx, &conntab, &TERMTYPE_TELOPT, &Side::Us); + set_option_supported(ctx, &conntab, &EOR_TELOPT, &Side::Him); // Call conntab:new... let seq = async_sequence(&ctx, |locals, mut seq| { @@ -361,6 +362,10 @@ pub(super) fn mudoutput<'gc>(ctx: Context<'gc>, _global_memo: &GlobalMemoCell) - .collect(); async move { for (func_name, params) in fns { + console::log_1(&JsValue::from_str(&format!( + "Calling {}", + func_name + ))); call_checking_metatable::( &mut seq, conntab.clone(), @@ -478,7 +483,48 @@ pub(super) fn mudoutput_prompt<'gc>( ctx: Context<'gc>, _global_memo: &GlobalMemoCell, ) -> Callback<'gc> { - Callback::from_fn(&ctx, move |_ctx, _ex, _stack| Ok(CallbackReturn::Return)) + Callback::from_fn(&ctx, move |ctx, _ex, mut stack| { + let mud = Table::from_value( + ctx, + stack + .pop_front() + .ok_or_else(|| anyhow::Error::msg("Missing muds:mudoutput_line self"))?, + )?; + let prompt = piccolo::String::from_value( + ctx, + stack + .pop_front() + .ok_or_else(|| anyhow::Error::msg("Missing muds:mudoutput_line line"))?, + )?; + + let frameroutes: Table = mud.get(ctx, "frameroutes")?; + + let seq = async_sequence(&ctx, |locals, mut seq| { + let frameroutes: Vec = frameroutes + .iter() + .filter_map(|fr| { + Table::from_value(ctx, fr.1) + .ok() + .map(|v| locals.stash(&ctx, v)) + }) + .collect(); + let line = locals.stash(&ctx, prompt.into_value(ctx)); + async move { + for frameroute in frameroutes { + call_checking_metatable::( + &mut seq, + frameroute, + "route", + &[line.clone()], + ) + .await?; + } + Ok(SequenceReturn::Return) + } + }); + + Ok(CallbackReturn::Sequence(seq)) + }) } fn name_telopt(ctx: Context, optno: u8) -> anyhow::Result { @@ -933,6 +979,10 @@ pub(super) fn local_naws_enabled<'gc>( }) } +pub(super) fn opt_enabled_noop<'gc>(ctx: Context<'gc>) -> Callback<'gc> { + Callback::from_fn(&ctx, move |_ctx, _ex, _stack| Ok(CallbackReturn::Return)) +} + fn name_mud<'gc>(ctx: Context<'gc>, mud: &Table<'gc>) -> String { fn name_mud_internal<'gc>(ctx: Context<'gc>, mud: &Table<'gc>) -> anyhow::Result { let socket: Value<'gc> = mud.get(ctx, "socket")?; diff --git a/src/lua_engine/muds/telopt.rs b/src/lua_engine/muds/telopt.rs index 4de9fd1..1b3a90b 100644 --- a/src/lua_engine/muds/telopt.rs +++ b/src/lua_engine/muds/telopt.rs @@ -428,6 +428,7 @@ pub fn handle_incoming_dont<'gc, T: SendOptNeg>( } pub const TERMTYPE_TELOPT: Telopt = Telopt(24); +pub const EOR_TELOPT: Telopt = Telopt(25); pub const NAWS_TELOPT: Telopt = Telopt(31); pub const GMCP_TELOPT: Telopt = Telopt(201); @@ -523,6 +524,9 @@ pub fn configure_telopt_table<'gc>(ctx: Context<'gc>, table: &Table<'gc>) { table .set(ctx, "naws", NAWS_TELOPT.0) .expect("Can't set NAWS in telopt table"); + table + .set(ctx, "eor", EOR_TELOPT.0) + .expect("Can't set EOR in telopt table"); table .set(ctx, "gmcp", GMCP_TELOPT.0) .expect("Can't set GMCP in telopt table");