Skip to content

Commit

Permalink
Fix random Unknown nb_ctl request: 4 errors
Browse files Browse the repository at this point in the history
Fixes #26

* Bump to 1.0.0-beta4
* Add CODE_LEN field to the ``sautorun`` table
  • Loading branch information
Vurv78 committed Feb 21, 2022
1 parent 5f9c708 commit e17ec57
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 10 deletions.
12 changes: 12 additions & 0 deletions autorun-shared/src/top.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::fmt;
// I know this is a waste to contain 'server' but I want it to be able to be used with GetLuaInterface
#[repr(u8)]
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "gui", derive(bincode::Decode, bincode::Encode))]
pub enum Realm {
Client = 0,
Server = 1,
Expand All @@ -19,6 +20,17 @@ impl fmt::Display for Realm {
}
}

impl From<u8> for Realm {
fn from(realm: u8) -> Self {
match realm {
0 => Realm::Client,
1 => Realm::Server,
2 => Realm::Menu,
_ => panic!("Invalid realm")
}
}
}

impl Into<u8> for Realm {
fn into(self) -> u8 {
match self {
Expand Down
2 changes: 1 addition & 1 deletion autorun/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "autorun"
version = "1.0.0-beta3"
version = "1.0.0-beta4"
authors = ["Vurv78 <Vurv78@users.noreply.github.com>"]
edition = "2021"
publish = false
Expand Down
39 changes: 39 additions & 0 deletions autorun/src/lua/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,42 @@ pub struct AutorunEnv {
pub code_len: usize,
}

impl AutorunEnv {
pub fn from_lua(state: LuaState) -> Option<Self> {
lua_getglobal(state, cstr!("sautorun"));
if lua_type(state, -1) == rglua::lua::TTABLE {
lua_getfield(state, -1, cstr!("STARTUP"));
let startup = lua_toboolean(state, -1) != 0;

lua_getfield(state, -1, cstr!("NAME"));
let identifier = lua_tostring(state, -1);

lua_getfield(state, -1, cstr!("CODE_LEN"));
let mut code_len = lua_tointeger(state, -1) as usize;

lua_getfield(state, -1, cstr!("CODE"));
let code = lua_tolstring(state, -1, &mut code_len);

lua_getfield(state, -1, cstr!("IP"));
let ip = lua_tostring(state, -1);

lua_pop(state, 6);

return Some(AutorunEnv {
is_autorun_file: false,
startup,
code,
identifier,
code_len,
ip
});
}

lua_pop(state, 1);
None
}
}

// Functions to interact with lua without triggering the detours
pub fn compile<S: AsRef<str>>(l: LuaState, code: S) -> Result<(), &'static str> {
let s = code.as_ref();
Expand Down Expand Up @@ -135,6 +171,9 @@ pub fn run_env(
lua_pushstring(l, env.identifier); // stack[3] = identifier
lua_setfield(l, -2, cstr!("NAME")); // stack[2].NAME = table.remove(stack, 3)

lua_pushinteger(l, env.code_len as LuaInteger); // stack[3] = code_len
lua_setfield(l, -2, cstr!("CODE_LEN")); // stack[2].CODE_LEN = table.remove(stack, 3)

lua_pushlstring(l, env.code, env.code_len); // stack[3] = identifier
lua_setfield(l, -2, cstr!("CODE")); // stack[2].CODE = table.remove(stack, 3)

Expand Down
7 changes: 6 additions & 1 deletion autorun/src/ui/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ use std::path::Path;
use indoc::printdoc;

pub fn init() {
unsafe { winapi::um::consoleapi::AllocConsole() };
unsafe {
// Load this library before it starts spamming useless errors into our console.
// https://github.com/Vurv78/Autorun-rs/issues/26
winapi::um::libloaderapi::LoadLibraryA( rglua::cstr!("vaudio_speex.dll") );
winapi::um::consoleapi::AllocConsole()
};

let version = env!("CARGO_PKG_VERSION");
printdoc!("
Expand Down
11 changes: 3 additions & 8 deletions autorun/src/ui/gui.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{io::Read, time::Duration};
use std::io::Read;
use autorun_shared::serde::{ToGUI, ToAutorun, Setting};
use message_io::{node::{self, NodeEvent}, network::{Transport, NetEvent}};
use message_io::{node, network::{Transport, NetEvent}};
use crate::{lua, logging::error, global::{FILESTEAL_ENABLED, LOGGING_ENABLED}};

pub fn init() {
Expand All @@ -12,11 +12,6 @@ pub fn init() {
});
}

enum Signal {
Greet,
Msg(String)
}

pub fn instance(mut stdout: shh::ShhStdout) {
//let connection = std::net::TcpListener::bind("127.0.0.1:8080").unwrap();
// connection.set_nonblocking(true).expect("Couldn't set nonblocking");
Expand All @@ -29,7 +24,7 @@ pub fn instance(mut stdout: shh::ShhStdout) {
let endpoints = Arc::new(Mutex::new(vec![]));
let for_listener = Arc::clone(&endpoints);

let config = bincode::config::Configuration::standard();
let config = bincode::config::standard();
listener.for_each(move |event| match event.network() {
NetEvent::Connected(_, _ok) => unreachable!(),
NetEvent::Accepted(endpoint, _) => {
Expand Down

0 comments on commit e17ec57

Please sign in to comment.