diff --git a/Cargo.lock b/Cargo.lock index 3a7c9af..0f10072 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -183,6 +183,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +[[package]] +name = "c_str_macro" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6d44951c469019e225e7667d799052f67fb8ea358d086878f3582b39f0de5e5" + [[package]] name = "cc" version = "1.0.83" @@ -1288,6 +1294,13 @@ dependencies = [ "digest", ] +[[package]] +name = "shrimpstats_tf2" +version = "0.1.0" +dependencies = [ + "sm-ext", +] + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -1306,6 +1319,28 @@ dependencies = [ "autocfg", ] +[[package]] +name = "sm-ext" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcdcd9d45b7f6d92ab1fa4dc1a9090d59ccdceab4f94aa51991c3ef0d73c8fda" +dependencies = [ + "c_str_macro", + "libc", + "sm-ext-derive", +] + +[[package]] +name = "sm-ext-derive" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75e96380b9fa81d50460fa1240990754e7f5766a74ffa5791f0cf43f50e56fc2" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "smallvec" version = "1.13.1" @@ -1329,6 +1364,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", + "quote", "unicode-ident", ] @@ -1555,9 +1591,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-bidi" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" diff --git a/Cargo.toml b/Cargo.toml index 946945c..12d6a38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,5 @@ members = [ "webapp/axum_htmx", "webapp/yew_csr", "api", + "shrimpstats_tf2", ] diff --git a/api/src/main.rs b/api/src/main.rs index cf69430..ada225d 100644 --- a/api/src/main.rs +++ b/api/src/main.rs @@ -14,16 +14,36 @@ use axum::{ Router, }; +use tokio::net::TcpListener; + #[tokio::main] async fn main() { + + let x = 5_i32; + let app = Router::new().route("/", get(root)); - let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); + let listener = match TcpListener::bind("0.0.0.0:3000").await { + Ok(x) => x, + Err(e) => { + println!("Error: {e}"); + return; + } + + }; - axum::serve(listener, app).await.unwrap(); + + + match axum::serve(listener, app).await { + Ok(x) => x, + Err(e) => { + println!("Error: {e}"); + return; + } + }; } -// basic handler that responds with a static string + async fn root() -> &'static str { "Hello, World!" } \ No newline at end of file diff --git a/shrimpstats_tf2/.cargo/config.toml b/shrimpstats_tf2/.cargo/config.toml new file mode 100644 index 0000000..2737728 --- /dev/null +++ b/shrimpstats_tf2/.cargo/config.toml @@ -0,0 +1,16 @@ +# windows target +[target.x86_64-pc-windows-gnu] +rustflags = ["-Ctarget-feature=+crt-static"] + +[target.i686-pc-windows-gnu] +rustflags = ["-Ctarget-feature=+crt-static"] + +[target.i686-pc-windows-msvc] +rustflags = ["-Ctarget-feature=+crt-static"] + +[target.x86_64-pc-windows-msvc] +rustflags = ["-Ctarget-feature=+crt-static"] + +# linux target +[target.x86_64-unknown-linux-gnu] +rustflags = ["-Ctarget-feature=+crt-static"] \ No newline at end of file diff --git a/shrimpstats_tf2/Cargo.toml b/shrimpstats_tf2/Cargo.toml new file mode 100644 index 0000000..d4d2fc9 --- /dev/null +++ b/shrimpstats_tf2/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "shrimpstats_tf2" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +crate-type = ["cdylib"] + + +[dependencies] +sm-ext = "0.3.0" \ No newline at end of file diff --git a/shrimpstats_tf2/src/lib.rs b/shrimpstats_tf2/src/lib.rs new file mode 100644 index 0000000..dcc5cd4 --- /dev/null +++ b/shrimpstats_tf2/src/lib.rs @@ -0,0 +1,45 @@ +#![deny( + unsafe_code, + clippy::correctness, + clippy::nursery, + clippy::pedantic, + clippy::complexity, + clippy::perf, + clippy::style, + clippy::suspicious +)] + + +use std::ffi::CStr; + +use sm_ext::{forwards, native, ExecType, ICallableApi, IExtension, IExtensionInterface, IForwardManager, IShareSys, SMExtension, SMInterfaceApi}; + +#[derive(Default, SMExtension)] +#[extension(name = "shrimpstats_tf2", description = "ShrimpStats TF2 Extension")] +pub struct ShrimpStatsTF2Extension; + +#[forwards] +struct MyForwards { + /// ```sourcepawn + /// forward int OnRustCall(int a, int b, const char[] c); + /// ``` + #[global_forward("OnRustCall", ExecType::Hook)] + on_rust_call: fn(a: i32, b: i32, c: &CStr) -> i32, +} + + +impl IExtensionInterface for ShrimpStatsTF2Extension { + fn on_extension_load(&mut self, me: IExtension, sys: IShareSys, late: bool) -> Result<(), Box> { + println!(">>> Rusty extension loaded! me = {:?}, sys = {:?}, late = {:?}", me, sys, late); + + let forward_manager: IForwardManager = sys.request_interface(&me)?; + println!(">>> Got interface: {:?} v{:?}", forward_manager.get_interface_name(), forward_manager.get_interface_version()); + + Ok(()) + } + + fn on_extension_unload(&mut self) {} + + fn on_extensions_all_loaded(&mut self) { + } +} \ No newline at end of file