Skip to content

Commit b175eba

Browse files
committed
Fix lua dumps in directories
Have no idea how I overlooked this but lua dumps were broken if they weren't at the top level of the dump folder. * All files dumped now automatically have .lua attached (even if they didn't already have it) * Initial plugin code * Bump to 1.0.0-beta5
1 parent e17ec57 commit b175eba

File tree

6 files changed

+58
-21
lines changed

6 files changed

+58
-21
lines changed

autorun/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "autorun"
3-
version = "1.0.0-beta4"
3+
version = "1.0.0-beta5"
44
authors = ["Vurv78 <Vurv78@users.noreply.github.com>"]
55
edition = "2021"
66
publish = false

autorun/src/configs/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub static DUMP_DIR: &str = concat!(adir!(), "/lua_dumps");
1010
#[cfg(feature = "logging")]
1111
pub static LOG_DIR: &str = concat!(adir!(), "/logs");
1212
pub static INCLUDE_DIR: &str = concat!(adir!(), "/scripts");
13+
pub static PLUGIN_DIR: &str = concat!(adir!(), "/plugins");
1314

1415
pub static AUTORUN_PATH: &str = concat!(adir!(), "/autorun.lua");
1516
pub static HOOK_PATH: &str = concat!(adir!(), "/hook.lua");

autorun/src/hooks/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@ fn loadbufferx_hook(l: LuaState, code: LuaString, len: usize, identifier: LuaStr
4747
if curtime < CONNECTED.load(Ordering::Relaxed) {
4848
debug!("Curtime is less than last time connected, assuming startup");
4949
startup = true;
50-
CONNECTED.store(curtime, Ordering::Relaxed);
51-
} else {
52-
// Awful
53-
CONNECTED.store(curtime, Ordering::Relaxed);
5450
}
5551

52+
// Awful
53+
CONNECTED.store(curtime, Ordering::Relaxed);
54+
5655
let raw_path = unsafe { CStr::from_ptr(identifier) };
5756
let path = &raw_path.to_string_lossy()[1..]; // Remove the @ from the beginning of the path
5857

@@ -106,6 +105,7 @@ pub fn dispatch(l: LuaState, startup: bool, path: &str, ip: LuaString, mut code:
106105
// Will be reset by JoinServer.
107106
let ar_path = configs::path(configs::AUTORUN_PATH);
108107
trace!("Running autorun script at {}", ar_path.display());
108+
109109
if let Ok(script) = fs::read_to_string(&ar_path) {
110110
// Try to run here
111111
if let Err(why) = lua::run_env(&script, env) {

autorun/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ mod global;
1212
mod hooks;
1313
mod lua;
1414
mod util;
15+
mod plugins;
1516

1617
use logging::*;
1718

autorun/src/plugins/mod.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use crate::configs::PLUGIN_DIR;
2+
3+
#[derive(Debug, thiserror::Error)]
4+
pub enum PluginError {
5+
#[error("IO Error: {0}")]
6+
IO(#[from] std::io::Error)
7+
}
8+
9+
#[non_exhaustive]
10+
pub enum PluginLanguage {
11+
// In the future there could be more languages like Teal or Expressive
12+
Lua
13+
}
14+
15+
impl Default for PluginLanguage {
16+
fn default() -> Self { Self::Lua }
17+
}
18+
19+
#[derive(Default)]
20+
pub struct PluginSettings {
21+
language: PluginLanguage
22+
}
23+
24+
pub struct Plugin {
25+
name: String,
26+
path: std::path::PathBuf,
27+
28+
// Path to entrypoint file.
29+
autorun: std::path::PathBuf,
30+
31+
// Retrieved from plugin.toml
32+
settings: PluginSettings
33+
}
34+
35+
// Plugin system
36+
pub fn find() -> Result<(), PluginError> {
37+
let dir = std::fs::read_dir( PLUGIN_DIR )?;
38+
39+
Ok(())
40+
}
41+
42+
pub fn exec() -> Result<(), PluginError> {
43+
Ok(())
44+
}

autorun/src/util.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,17 @@ pub fn get_handle<S: AsRef<str>>(location: &str, server_ip: S) -> Result<File, H
2323
};
2424

2525
let server_ip = server_ip.as_ref();
26-
let mut lua_run_path = PathBuf::from(location);
27-
28-
let extension = match lua_run_path.extension() {
29-
Some(ext) => {
30-
match ext.to_str() {
31-
Some(ext) if ext == "lua" => "lua", // Using guards check if the extension is lua, else it will fall under _.
32-
_ => "txt",
33-
}
34-
}
35-
None => "txt",
36-
};
37-
38-
lua_run_path.set_extension(extension);
39-
4026
let file_loc = &*configs::path(configs::DUMP_DIR)
4127
.join(strip_invalid(server_ip));
4228

43-
fs::create_dir_all(file_loc)?;
29+
let mut path = file_loc.join(location);
30+
31+
let dir = path.parent().unwrap_or(file_loc);
32+
fs::create_dir_all(&dir)?;
33+
34+
path.set_extension("lua");
4435

45-
Ok( File::create( file_loc.join(location) )? )
36+
Ok( File::create( path )? )
4637
}
4738

4839
// Removes basic invalid filename stuff

0 commit comments

Comments
 (0)