Initial commit
This commit is contained in:
commit
4447fbafab
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/target
|
||||
**/*.rs.bk
|
43
.vscode/launch.json
vendored
Normal file
43
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Debug executable 'minetest-mumble-wrapper'",
|
||||
"cargo": {
|
||||
"args": [
|
||||
"build",
|
||||
"--bin=minetest-mumble-wrapper",
|
||||
"--package=minetest-mumble-wrapper"
|
||||
],
|
||||
"filter": {
|
||||
"kind": "bin"
|
||||
}
|
||||
},
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Debug unit tests in executable 'minetest-mumble-wrapper'",
|
||||
"cargo": {
|
||||
"args": [
|
||||
"test",
|
||||
"--no-run",
|
||||
"--bin=minetest-mumble-wrapper",
|
||||
"--package=minetest-mumble-wrapper"
|
||||
],
|
||||
"filter": {
|
||||
"kind": "bin"
|
||||
}
|
||||
},
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
}
|
||||
]
|
||||
}
|
129
Cargo.lock
generated
Normal file
129
Cargo.lock
generated
Normal file
@ -0,0 +1,129 @@
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.6.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "kernel32-sys"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.44"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "minetest-mumble-wrapper"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"mumble-link 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mumble-link"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex-syntax 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ucd-util"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "utf8-ranges"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-build"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[metadata]
|
||||
"checksum aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1e9a933f4e58658d7b12defcf96dc5c720f20832deebe3e0a19efd3b6aaeeb9e"
|
||||
"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
|
||||
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
||||
"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1"
|
||||
"checksum libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)" = "10923947f84a519a45c8fefb7dd1b3e8c08747993381adee176d7a82b4195311"
|
||||
"checksum memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0a3eb002f0535929f1199681417029ebea04aadc0c7a4224b46be99c7f5d6a16"
|
||||
"checksum mumble-link 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a92ff7d87d3ca752fda7a1ccfcde284ea3de84fc8b8a0c43bf434652226bd95"
|
||||
"checksum regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37e7cbbd370869ce2e8dff25c7018702d10b21a20ef7135316f8daecd6c25b7f"
|
||||
"checksum regex-syntax 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4e47a2ed29da7a9e1960e1639e7a982e6edc6d49be308a3b02daf511504a16d1"
|
||||
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
|
||||
"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86"
|
||||
"checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737"
|
||||
"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
|
||||
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
|
||||
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
|
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "minetest-mumble-wrapper"
|
||||
version = "0.1.0"
|
||||
authors = ["David <gw.chip.gw@gmail.com>"]
|
||||
|
||||
[dependencies]
|
||||
mumble-link = "0.1.0"
|
||||
regex = "1.1.0"
|
7
LICENSE
Normal file
7
LICENSE
Normal file
@ -0,0 +1,7 @@
|
||||
Copyright (c) 2018 chipgw
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
29
minetestmod/mumble/init.lua
Normal file
29
minetestmod/mumble/init.lua
Normal file
@ -0,0 +1,29 @@
|
||||
local player
|
||||
|
||||
minetest.register_on_connect(function()
|
||||
player = minetest.localplayer
|
||||
end)
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if player then
|
||||
local player_name = player:get_name()
|
||||
local player_pos = player:get_pos() or {x=0, y=0, z=0}
|
||||
local player_look = {x=0, y=0, z=0}
|
||||
local camera_pos = {x=0, y=0, z=0}
|
||||
local camera_look = {x=0, y=0, z=0}
|
||||
if minetest.camera then
|
||||
camera_pos = minetest.camera:get_pos()
|
||||
camera_pos.x = (camera_pos.x/10)
|
||||
camera_pos.y = (camera_pos.y/10)
|
||||
camera_pos.z = (camera_pos.z/10)
|
||||
camera_look = minetest.camera:get_look_dir()
|
||||
player_look = camera_look
|
||||
end
|
||||
print("mumble id "..player_name)
|
||||
print("p p ["..(player_pos.x).." "..(player_pos.y).." "..(player_pos.z).."]")
|
||||
print("p l ["..(player_look.x).." "..(player_look.y).." "..(player_look.z).."]")
|
||||
print("c p ["..(camera_pos.x).." "..(camera_pos.y).." "..(camera_pos.z).."]")
|
||||
print("c l ["..(camera_look.x).." "..(camera_look.y).." "..(camera_look.z).."]")
|
||||
print("mumble submit")
|
||||
end
|
||||
end)
|
109
src/main.rs
Normal file
109
src/main.rs
Normal file
@ -0,0 +1,109 @@
|
||||
extern crate mumble_link;
|
||||
extern crate regex;
|
||||
|
||||
use mumble_link::*;
|
||||
use regex::Regex;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
fn get_data(captures: ®ex::Captures) -> Result<([f32; 3], char, char), String> {
|
||||
// Function to convert float parsing errors to error strings so we can return that as a result.
|
||||
fn errstr(e: std::num::ParseFloatError) -> String {
|
||||
e.to_string()
|
||||
}
|
||||
|
||||
// Get all the named captures.
|
||||
Ok(([captures["x"].parse().map_err(errstr)?, captures["y"].parse().map_err(errstr)?, captures["z"].parse().map_err(errstr)?,],
|
||||
captures["subject"].chars().next().ok_or("unable to get vec subject")?,
|
||||
captures["type"].chars().next().ok_or("unable to get vec type")?,
|
||||
))
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Hook into Mumble using the very handy crate somebody made.
|
||||
let mut link = MumbleLink::new("Minetest", "Minetest positional audio using a mod and wrapper.").expect("Unable to link to Mumble. Is it running?");
|
||||
|
||||
// Default command to launch.
|
||||
let mut minetest_command = "/usr/bin/minetest".to_owned();
|
||||
|
||||
// Look for an argument containing "minetest" to replace default command.
|
||||
for argument in std::env::args() {
|
||||
if argument.contains("minetest") {
|
||||
minetest_command = argument
|
||||
}
|
||||
}
|
||||
|
||||
let mut child = Command::new(minetest_command)
|
||||
.stderr(Stdio::piped()) // We need the output to be piped. For some reason Minetest lua's print function goes to stderr...
|
||||
.spawn().unwrap(); // Spawn the process, panic if it fails.
|
||||
|
||||
// This regex parses lines like "p l [1.0 1.0 1.0]".
|
||||
// the first letter (the subject) is either 'p' or 'c' denoting whether this is a player or camera vector.
|
||||
// the second letter (the type) is either 'p' or 'l' denoting whether this is a position or look vector.
|
||||
// then inside brakets are the x, y, and z components, respectively.
|
||||
let vec_regex_str = format!(r"(?P<subject>[cp]) (?P<type>[pl]) \[(?P<x>{f}) (?P<y>{f}) (?P<z>{f})\]", f=r"[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?");
|
||||
let vec_regex = Regex::new(&vec_regex_str).unwrap();
|
||||
|
||||
// This regex parses commands like "mumble id playername".
|
||||
let cmd_regex = Regex::new(r"mumble (?P<cmd>submit|id|context) *(?P<arg>[[:alpha:]]*)").unwrap();
|
||||
|
||||
let mut player = Position::default();
|
||||
let mut camera = Position::default();
|
||||
|
||||
// Run as long as the child proccess is running.
|
||||
while child.try_wait().unwrap().is_none() {
|
||||
// Get the output from the child process.
|
||||
if let Some(ref mut child_output) = child.stderr {
|
||||
// Using a BufReader allows us to go through all the lines in a loop.
|
||||
for line_result in BufReader::new(child_output).lines() {
|
||||
// Gotta make sure the line is valid...
|
||||
if let Ok(ref line) = line_result {
|
||||
// Try getting the captures from the regex.
|
||||
if let Some(captures) = vec_regex.captures(line) {
|
||||
match get_data(&captures) {
|
||||
Ok((vec, s, t)) => {
|
||||
// Get the Position item that we need to set something on.
|
||||
let mut target = match s {
|
||||
'p' => &mut player,
|
||||
'c' => &mut camera,
|
||||
_ => continue,
|
||||
};
|
||||
// Figure out which component to set.
|
||||
match t {
|
||||
'p' => target.position = vec,
|
||||
'l' => target.front = vec,
|
||||
_ => continue,
|
||||
}
|
||||
println!("got {} {} {:?}", s, t, vec);
|
||||
}
|
||||
Err(err) => {
|
||||
println!("error getting vec: {}", err);
|
||||
}
|
||||
}
|
||||
} else if let Some(captures) = cmd_regex.captures(line) {
|
||||
let arg = &captures["arg"];
|
||||
|
||||
match &captures["cmd"] {
|
||||
"submit" => {
|
||||
// Submit the gathered data to Mumble.
|
||||
println!("Updating...");
|
||||
link.update(player, camera)
|
||||
},
|
||||
"id" => {
|
||||
println!("got identity: {}", arg);
|
||||
link.set_identity(arg);
|
||||
},
|
||||
"context" => {
|
||||
println!("got context: {}", arg);
|
||||
link.set_context(arg.as_bytes());
|
||||
},
|
||||
cmd => {
|
||||
println!("Invalid command {}!", cmd);
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user