Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Started with extension. Lgtm so far. #13

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ members = [
"webapp/axum_htmx",
"webapp/yew_csr",
"api",
"shrimpstats_tf2",
]
26 changes: 23 additions & 3 deletions api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
}
16 changes: 16 additions & 0 deletions shrimpstats_tf2/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -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"]
12 changes: 12 additions & 0 deletions shrimpstats_tf2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
45 changes: 45 additions & 0 deletions shrimpstats_tf2/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<dyn std::error::Error>> {
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) {
}
}
Loading