Compare commits
1 commit
Author | SHA1 | Date | |
---|---|---|---|
d1d9042807 |
137 changed files with 114 additions and 107 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -126,6 +126,10 @@ version = "0.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nat_traversal"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nom"
|
name = "nom"
|
||||||
version = "7.1.3"
|
version = "7.1.3"
|
||||||
|
|
22
Cargo.toml
22
Cargo.toml
|
@ -1,18 +1,12 @@
|
||||||
[package]
|
[workspace]
|
||||||
name = "dt_p2p"
|
resolver = "2"
|
||||||
version = "0.1.0"
|
members = [
|
||||||
edition = "2021"
|
"lib/dt_p2p",
|
||||||
|
"lib/nat_traversal"
|
||||||
|
]
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
[unstable]
|
||||||
|
build-std = true
|
||||||
[dependencies]
|
|
||||||
libc = "0.2.144"
|
|
||||||
|
|
||||||
[build-dependencies]
|
|
||||||
bindgen = "0.65.1"
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
crate-type = ["cdylib", "lib"]
|
|
||||||
|
|
||||||
# [profile.dev.package.backtrace]
|
# [profile.dev.package.backtrace]
|
||||||
# opt-level = 3
|
# opt-level = 3
|
||||||
|
|
15
lib/dt_p2p/Cargo.toml
Normal file
15
lib/dt_p2p/Cargo.toml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
[package]
|
||||||
|
name = "dt_p2p"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
libc = "0.2.144"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
crate-type = ["cdylib", "lib"]
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
bindgen = "0.65.1"
|
64
lib/dt_p2p/src/lib.rs
Normal file
64
lib/dt_p2p/src/lib.rs
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
use std::{
|
||||||
|
ffi::{c_char, CString},
|
||||||
|
sync::RwLock,
|
||||||
|
};
|
||||||
|
|
||||||
|
mod stingray_sdk;
|
||||||
|
|
||||||
|
use crate::stingray_sdk::{GetApiFunction, LoggingApi, PluginApi, PluginApiID};
|
||||||
|
|
||||||
|
const PLUGIN_NAME: &str = "dt_p2p";
|
||||||
|
|
||||||
|
struct Plugin {
|
||||||
|
log: Option<LoggingApi>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Plugin {
|
||||||
|
pub const fn new() -> Self {
|
||||||
|
Self { log: None }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static PLUGIN: RwLock<Plugin> = RwLock::new(Plugin::new());
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn get_name() -> *const c_char {
|
||||||
|
let s = CString::new(PLUGIN_NAME).expect("Failed to create CString from plugin name");
|
||||||
|
s.as_ptr()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn setup_game(get_engine_api: GetApiFunction) {
|
||||||
|
println!("setup_game");
|
||||||
|
|
||||||
|
PLUGIN.log = Some(LoggingApi::get(get_engine_api));
|
||||||
|
let log = PLUGIN.log.as_ref().unwrap();
|
||||||
|
|
||||||
|
log.info(
|
||||||
|
PLUGIN_NAME,
|
||||||
|
format!("Hello, world! This is {}!", PLUGIN_NAME),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn shutdown_game() {
|
||||||
|
println!("shutdown_game");
|
||||||
|
|
||||||
|
// log.info(PLUGIN_NAME, format!("Goodbye, world!", PLUGIN_NAME));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn get_plugin_api(id: PluginApiID) -> *mut PluginApi {
|
||||||
|
if id == PluginApiID::PLUGIN_API_ID {
|
||||||
|
let api = PluginApi {
|
||||||
|
get_name: Some(get_name),
|
||||||
|
setup_game: Some(setup_game),
|
||||||
|
shutdown_game: Some(shutdown_game),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
Box::into_raw(Box::new(api))
|
||||||
|
} else {
|
||||||
|
std::ptr::null_mut()
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue