From f344cf83d9bdb0815021cc15c16a9aadad0f3e37 Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Wed, 1 Jan 2020 21:36:10 +0100 Subject: [PATCH] Initial working version --- .gitignore | 2 ++ Cargo.lock | 6 +++++ Cargo.toml | 9 +++++++ index.html | 23 +++++++++++++++++ racestate.txt | 1 + rx1.txt | 1 + rx2.txt | 1 + rx3.txt | 1 + src/main.rs | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ text1.lua | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ text2.lua | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ text3.lua | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ text4.lua | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ 13 files changed, 380 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 index.html create mode 100644 racestate.txt create mode 100644 rx1.txt create mode 100644 rx2.txt create mode 100644 rx3.txt create mode 100644 src/main.rs create mode 100644 text1.lua create mode 100644 text2.lua create mode 100644 text3.lua create mode 100644 text4.lua diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53eaa21 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +**/*.rs.bk diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..7a8f9cf --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "chorus-client" +version = "0.1.0" + diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..7a2e84a --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "chorus-client" +version = "0.1.0" +authors = ["Lukas Bachschwell "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/index.html b/index.html new file mode 100644 index 0000000..540c561 --- /dev/null +++ b/index.html @@ -0,0 +1,23 @@ + + + +

+ + + diff --git a/racestate.txt b/racestate.txt new file mode 100644 index 0000000..db3dbc1 --- /dev/null +++ b/racestate.txt @@ -0,0 +1 @@ +Race inactive \ No newline at end of file diff --git a/rx1.txt b/rx1.txt new file mode 100644 index 0000000..857f065 --- /dev/null +++ b/rx1.txt @@ -0,0 +1 @@ +00 \ No newline at end of file diff --git a/rx2.txt b/rx2.txt new file mode 100644 index 0000000..857f065 --- /dev/null +++ b/rx2.txt @@ -0,0 +1 @@ +00 \ No newline at end of file diff --git a/rx3.txt b/rx3.txt new file mode 100644 index 0000000..857f065 --- /dev/null +++ b/rx3.txt @@ -0,0 +1 @@ +00 \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..385c1ce --- /dev/null +++ b/src/main.rs @@ -0,0 +1,64 @@ +use std::io::Write; +use std::net; + +fn listen(socket: &net::UdpSocket) { + let mut buf: [u8; 20] = [0; 20]; + let number_of_bytes: usize = 0; + let mut result: Vec = Vec::new(); + match socket.recv_from(&mut buf) { + Ok((number_of_bytes, _)) => { + result = Vec::from(&buf[0..number_of_bytes]); + } + Err(fail) => println!("failed listening {:?}", fail), + } + + let display_result = result.clone(); + let result_str = String::from_utf8(display_result).unwrap(); + println!("received message: {:?}", result_str); + + if result_str.contains("S0R1") { + write_file("Race active", "racestate.txt"); + write_file("00", "rx1.txt"); + write_file("00", "rx2.txt"); + write_file("00", "rx3.txt"); + } + if result_str.contains("S0R0") { + write_file("Race inactive", "racestate.txt"); + } + + if result_str.contains("S0L") { + // zb sS1L0000000DAF + write_file(&result_str[3..5], "rx1.txt"); + } + if result_str.contains("S1L") { + write_file(&result_str[3..5], "rx2.txt"); + } + if result_str.contains("S2L") { + write_file(&result_str[3..5], "rx3.txt"); + } +} + +fn write_file(text: &str, filename: &str) { + let mut file = std::fs::File::create(filename).expect("create failed"); + file.write_all(text.as_bytes()).expect("write failed"); + //println!("data written to file"); +} + +fn main() { + write_file("Race inactive", "racestate.txt"); + write_file("00", "rx1.txt"); + write_file("00", "rx2.txt"); + write_file("00", "rx3.txt"); + + let socket = net::UdpSocket::bind("0.0.0.0:0").expect("failed to bind host socket"); // local bind port + + let msg = String::from("ok").into_bytes(); + + socket + .send_to(&msg, "192.168.0.141:9000") + .expect("cannot send"); + + loop { + listen(&socket); // this call is blockig + } +} diff --git a/text1.lua b/text1.lua new file mode 100644 index 0000000..3983147 --- /dev/null +++ b/text1.lua @@ -0,0 +1,68 @@ +function script_description() + return "This script lets you select a text source to force it to reread files every frame instead of once per second." +end + +obs = obslua +source_name = nil + +local open = io.open + +local function read_file(path) + local file = open(path, "rb") -- r read mode and b binary mode + if not file then return nil end + local content = file:read "*a" -- *a or *all reads the whole file + file:close() + return content +end + + + + + +function script_update(settings) + source_name = obs.obs_data_get_string(settings, "source") + filepath = obs.obs_data_get_string(settings, "filepath") + + local fileContent = read_file("/Users/LB/Desktop/z_Projects/chorus-client/racestate.txt"); + set_text(fileContent) +end + +function script_properties() + local props = obs.obs_properties_create() + local p = obs.obs_properties_add_list(props, "source", "Text Source", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING) + local p2 = obs.obs_properties_add_path(props, "filepath", "File", obs.OBS_PATH_FILE, nil, nil) + + local sources = obs.obs_enum_sources() + if sources ~= nil then + for _, source in ipairs(sources) do + source_id = obs.obs_source_get_id(source) + if source_id == "text_gdiplus" or source_id == "text_ft2_source" or source_id == "text_pango_source" then + local name = obs.obs_source_get_name(source) + obs.obs_property_list_add_string(p, name, name) + end + end + end + + obs.source_list_release(sources) + + return props +end + +function set_text(text) + + local source = obs.obs_get_source_by_name(source_name) + + if source ~= nil then + local settings = obs.obs_data_create() + obs.obs_data_set_string(settings, "text", text) + obs.obs_source_update(source, settings) + obs.obs_data_release(settings) + obs.obs_source_release(source) + end + end + +function script_tick(seconds) + if source_name == nil then return end + local fileContent = read_file(filepath); + set_text(fileContent) +end diff --git a/text2.lua b/text2.lua new file mode 100644 index 0000000..3983147 --- /dev/null +++ b/text2.lua @@ -0,0 +1,68 @@ +function script_description() + return "This script lets you select a text source to force it to reread files every frame instead of once per second." +end + +obs = obslua +source_name = nil + +local open = io.open + +local function read_file(path) + local file = open(path, "rb") -- r read mode and b binary mode + if not file then return nil end + local content = file:read "*a" -- *a or *all reads the whole file + file:close() + return content +end + + + + + +function script_update(settings) + source_name = obs.obs_data_get_string(settings, "source") + filepath = obs.obs_data_get_string(settings, "filepath") + + local fileContent = read_file("/Users/LB/Desktop/z_Projects/chorus-client/racestate.txt"); + set_text(fileContent) +end + +function script_properties() + local props = obs.obs_properties_create() + local p = obs.obs_properties_add_list(props, "source", "Text Source", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING) + local p2 = obs.obs_properties_add_path(props, "filepath", "File", obs.OBS_PATH_FILE, nil, nil) + + local sources = obs.obs_enum_sources() + if sources ~= nil then + for _, source in ipairs(sources) do + source_id = obs.obs_source_get_id(source) + if source_id == "text_gdiplus" or source_id == "text_ft2_source" or source_id == "text_pango_source" then + local name = obs.obs_source_get_name(source) + obs.obs_property_list_add_string(p, name, name) + end + end + end + + obs.source_list_release(sources) + + return props +end + +function set_text(text) + + local source = obs.obs_get_source_by_name(source_name) + + if source ~= nil then + local settings = obs.obs_data_create() + obs.obs_data_set_string(settings, "text", text) + obs.obs_source_update(source, settings) + obs.obs_data_release(settings) + obs.obs_source_release(source) + end + end + +function script_tick(seconds) + if source_name == nil then return end + local fileContent = read_file(filepath); + set_text(fileContent) +end diff --git a/text3.lua b/text3.lua new file mode 100644 index 0000000..3983147 --- /dev/null +++ b/text3.lua @@ -0,0 +1,68 @@ +function script_description() + return "This script lets you select a text source to force it to reread files every frame instead of once per second." +end + +obs = obslua +source_name = nil + +local open = io.open + +local function read_file(path) + local file = open(path, "rb") -- r read mode and b binary mode + if not file then return nil end + local content = file:read "*a" -- *a or *all reads the whole file + file:close() + return content +end + + + + + +function script_update(settings) + source_name = obs.obs_data_get_string(settings, "source") + filepath = obs.obs_data_get_string(settings, "filepath") + + local fileContent = read_file("/Users/LB/Desktop/z_Projects/chorus-client/racestate.txt"); + set_text(fileContent) +end + +function script_properties() + local props = obs.obs_properties_create() + local p = obs.obs_properties_add_list(props, "source", "Text Source", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING) + local p2 = obs.obs_properties_add_path(props, "filepath", "File", obs.OBS_PATH_FILE, nil, nil) + + local sources = obs.obs_enum_sources() + if sources ~= nil then + for _, source in ipairs(sources) do + source_id = obs.obs_source_get_id(source) + if source_id == "text_gdiplus" or source_id == "text_ft2_source" or source_id == "text_pango_source" then + local name = obs.obs_source_get_name(source) + obs.obs_property_list_add_string(p, name, name) + end + end + end + + obs.source_list_release(sources) + + return props +end + +function set_text(text) + + local source = obs.obs_get_source_by_name(source_name) + + if source ~= nil then + local settings = obs.obs_data_create() + obs.obs_data_set_string(settings, "text", text) + obs.obs_source_update(source, settings) + obs.obs_data_release(settings) + obs.obs_source_release(source) + end + end + +function script_tick(seconds) + if source_name == nil then return end + local fileContent = read_file(filepath); + set_text(fileContent) +end diff --git a/text4.lua b/text4.lua new file mode 100644 index 0000000..3983147 --- /dev/null +++ b/text4.lua @@ -0,0 +1,68 @@ +function script_description() + return "This script lets you select a text source to force it to reread files every frame instead of once per second." +end + +obs = obslua +source_name = nil + +local open = io.open + +local function read_file(path) + local file = open(path, "rb") -- r read mode and b binary mode + if not file then return nil end + local content = file:read "*a" -- *a or *all reads the whole file + file:close() + return content +end + + + + + +function script_update(settings) + source_name = obs.obs_data_get_string(settings, "source") + filepath = obs.obs_data_get_string(settings, "filepath") + + local fileContent = read_file("/Users/LB/Desktop/z_Projects/chorus-client/racestate.txt"); + set_text(fileContent) +end + +function script_properties() + local props = obs.obs_properties_create() + local p = obs.obs_properties_add_list(props, "source", "Text Source", obs.OBS_COMBO_TYPE_EDITABLE, obs.OBS_COMBO_FORMAT_STRING) + local p2 = obs.obs_properties_add_path(props, "filepath", "File", obs.OBS_PATH_FILE, nil, nil) + + local sources = obs.obs_enum_sources() + if sources ~= nil then + for _, source in ipairs(sources) do + source_id = obs.obs_source_get_id(source) + if source_id == "text_gdiplus" or source_id == "text_ft2_source" or source_id == "text_pango_source" then + local name = obs.obs_source_get_name(source) + obs.obs_property_list_add_string(p, name, name) + end + end + end + + obs.source_list_release(sources) + + return props +end + +function set_text(text) + + local source = obs.obs_get_source_by_name(source_name) + + if source ~= nil then + local settings = obs.obs_data_create() + obs.obs_data_set_string(settings, "text", text) + obs.obs_source_update(source, settings) + obs.obs_data_release(settings) + obs.obs_source_release(source) + end + end + +function script_tick(seconds) + if source_name == nil then return end + local fileContent = read_file(filepath); + set_text(fileContent) +end