Fix
- Added docs - Added cs2dumper files to gitignore again. - Fixed workspace manifest
This commit is contained in:
228
docs/src/radarflow/cli.rs.html
Normal file
228
docs/src/radarflow/cli.rs.html
Normal file
@@ -0,0 +1,228 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Source of the Rust file `radarflow/src/cli.rs`."><title>cli.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-fa3bb1812debf86c.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="radarflow" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0 (79e9716c9 2023-11-13)" data-channel="1.74.0" data-search-js="search-8be46b629f5f14a8.js" data-settings-js="settings-74424d7eec62a23e.js" ><script src="../../static.files/storage-fec3eaa3851e447d.js"></script><script defer src="../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../src-files.js"></script><script defer src="../../static.files/main-c5bd66d33317d69f.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-5d8b3c7633ad77ba.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../radarflow/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
|
||||
<a href="#2" id="2">2</a>
|
||||
<a href="#3" id="3">3</a>
|
||||
<a href="#4" id="4">4</a>
|
||||
<a href="#5" id="5">5</a>
|
||||
<a href="#6" id="6">6</a>
|
||||
<a href="#7" id="7">7</a>
|
||||
<a href="#8" id="8">8</a>
|
||||
<a href="#9" id="9">9</a>
|
||||
<a href="#10" id="10">10</a>
|
||||
<a href="#11" id="11">11</a>
|
||||
<a href="#12" id="12">12</a>
|
||||
<a href="#13" id="13">13</a>
|
||||
<a href="#14" id="14">14</a>
|
||||
<a href="#15" id="15">15</a>
|
||||
<a href="#16" id="16">16</a>
|
||||
<a href="#17" id="17">17</a>
|
||||
<a href="#18" id="18">18</a>
|
||||
<a href="#19" id="19">19</a>
|
||||
<a href="#20" id="20">20</a>
|
||||
<a href="#21" id="21">21</a>
|
||||
<a href="#22" id="22">22</a>
|
||||
<a href="#23" id="23">23</a>
|
||||
<a href="#24" id="24">24</a>
|
||||
<a href="#25" id="25">25</a>
|
||||
<a href="#26" id="26">26</a>
|
||||
<a href="#27" id="27">27</a>
|
||||
<a href="#28" id="28">28</a>
|
||||
<a href="#29" id="29">29</a>
|
||||
<a href="#30" id="30">30</a>
|
||||
<a href="#31" id="31">31</a>
|
||||
<a href="#32" id="32">32</a>
|
||||
<a href="#33" id="33">33</a>
|
||||
<a href="#34" id="34">34</a>
|
||||
<a href="#35" id="35">35</a>
|
||||
<a href="#36" id="36">36</a>
|
||||
<a href="#37" id="37">37</a>
|
||||
<a href="#38" id="38">38</a>
|
||||
<a href="#39" id="39">39</a>
|
||||
<a href="#40" id="40">40</a>
|
||||
<a href="#41" id="41">41</a>
|
||||
<a href="#42" id="42">42</a>
|
||||
<a href="#43" id="43">43</a>
|
||||
<a href="#44" id="44">44</a>
|
||||
<a href="#45" id="45">45</a>
|
||||
<a href="#46" id="46">46</a>
|
||||
<a href="#47" id="47">47</a>
|
||||
<a href="#48" id="48">48</a>
|
||||
<a href="#49" id="49">49</a>
|
||||
<a href="#50" id="50">50</a>
|
||||
<a href="#51" id="51">51</a>
|
||||
<a href="#52" id="52">52</a>
|
||||
<a href="#53" id="53">53</a>
|
||||
<a href="#54" id="54">54</a>
|
||||
<a href="#55" id="55">55</a>
|
||||
<a href="#56" id="56">56</a>
|
||||
<a href="#57" id="57">57</a>
|
||||
<a href="#58" id="58">58</a>
|
||||
<a href="#59" id="59">59</a>
|
||||
<a href="#60" id="60">60</a>
|
||||
<a href="#61" id="61">61</a>
|
||||
<a href="#62" id="62">62</a>
|
||||
<a href="#63" id="63">63</a>
|
||||
<a href="#64" id="64">64</a>
|
||||
<a href="#65" id="65">65</a>
|
||||
<a href="#66" id="66">66</a>
|
||||
<a href="#67" id="67">67</a>
|
||||
<a href="#68" id="68">68</a>
|
||||
<a href="#69" id="69">69</a>
|
||||
<a href="#70" id="70">70</a>
|
||||
<a href="#71" id="71">71</a>
|
||||
<a href="#72" id="72">72</a>
|
||||
<a href="#73" id="73">73</a>
|
||||
<a href="#74" id="74">74</a>
|
||||
<a href="#75" id="75">75</a>
|
||||
<a href="#76" id="76">76</a>
|
||||
<a href="#77" id="77">77</a>
|
||||
<a href="#78" id="78">78</a>
|
||||
<a href="#79" id="79">79</a>
|
||||
<a href="#80" id="80">80</a>
|
||||
<a href="#81" id="81">81</a>
|
||||
<a href="#82" id="82">82</a>
|
||||
<a href="#83" id="83">83</a>
|
||||
<a href="#84" id="84">84</a>
|
||||
<a href="#85" id="85">85</a>
|
||||
<a href="#86" id="86">86</a>
|
||||
<a href="#87" id="87">87</a>
|
||||
<a href="#88" id="88">88</a>
|
||||
<a href="#89" id="89">89</a>
|
||||
<a href="#90" id="90">90</a>
|
||||
<a href="#91" id="91">91</a>
|
||||
<a href="#92" id="92">92</a>
|
||||
<a href="#93" id="93">93</a>
|
||||
<a href="#94" id="94">94</a>
|
||||
<a href="#95" id="95">95</a>
|
||||
<a href="#96" id="96">96</a>
|
||||
<a href="#97" id="97">97</a>
|
||||
<a href="#98" id="98">98</a>
|
||||
<a href="#99" id="99">99</a>
|
||||
<a href="#100" id="100">100</a>
|
||||
<a href="#101" id="101">101</a>
|
||||
<a href="#102" id="102">102</a>
|
||||
<a href="#103" id="103">103</a>
|
||||
<a href="#104" id="104">104</a>
|
||||
<a href="#105" id="105">105</a>
|
||||
<a href="#106" id="106">106</a>
|
||||
<a href="#107" id="107">107</a>
|
||||
<a href="#108" id="108">108</a>
|
||||
<a href="#109" id="109">109</a>
|
||||
<a href="#110" id="110">110</a>
|
||||
<a href="#111" id="111">111</a>
|
||||
<a href="#112" id="112">112</a>
|
||||
<a href="#113" id="113">113</a>
|
||||
<a href="#114" id="114">114</a>
|
||||
</pre></div><pre class="rust"><code><span class="kw">use </span>std::path::PathBuf;
|
||||
|
||||
<span class="kw">use </span>clap::{Parser, ValueEnum};
|
||||
<span class="kw">use </span>csflow::{Connector, memflow::Inventory};
|
||||
|
||||
<span class="kw">const </span>PORT_RANGE: std::ops::RangeInclusive<usize> = <span class="number">8000</span>..=<span class="number">65535</span>;
|
||||
<span class="kw">const </span>POLL_RANGE: std::ops::RangeInclusive<usize> = <span class="number">1</span>..=<span class="number">1000</span>;
|
||||
|
||||
<span class="attr">#[derive(Parser)]
|
||||
#[command(author, version = version(), about, long_about = <span class="prelude-val">None</span>)]
|
||||
</span><span class="kw">pub struct </span>Cli {
|
||||
<span class="doccomment">/// Specifies the connector type for DMA
|
||||
</span><span class="attr">#[clap(value_enum, short, long, ignore_case = <span class="bool-val">true</span>, default_value_t = Connector::Qemu)]
|
||||
</span><span class="kw">pub </span>connector: Connector,
|
||||
|
||||
<span class="doccomment">/// Name of the Pcileech device
|
||||
</span><span class="attr">#[clap(long, default_value_t = String::from(<span class="string">"FPGA"</span>))]
|
||||
</span><span class="kw">pub </span>pcileech_device: String,
|
||||
|
||||
<span class="doccomment">/// Port number for the Webserver to run on
|
||||
</span><span class="attr">#[arg(short, long, default_value_t = <span class="number">8000</span>, value_parser = port_in_range)]
|
||||
</span><span class="kw">pub </span>port: u16,
|
||||
|
||||
<span class="doccomment">/// Path to the directory served by the Webserver
|
||||
</span><span class="attr">#[arg(short, long, default_value = <span class="string">"./webradar"</span>, value_parser = valid_path)]
|
||||
</span><span class="kw">pub </span>web_path: PathBuf,
|
||||
|
||||
<span class="doccomment">/// Polling frequency in times per second for the DMA thread
|
||||
</span><span class="attr">#[arg(short = <span class="string">'r'</span>, long, default_value_t = <span class="number">60</span>, value_parser = poll_in_range)]
|
||||
</span><span class="kw">pub </span>poll_rate: u16,
|
||||
|
||||
<span class="doccomment">/// Verbosity level for logging to the console
|
||||
</span><span class="attr">#[arg(value_enum, long, short, ignore_case = <span class="bool-val">true</span>, default_value_t = Loglevel::Warn)]
|
||||
</span><span class="kw">pub </span>loglevel: Loglevel,
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>version() -> String {
|
||||
<span class="kw">let </span>pkg_ver = <span class="macro">env!</span>(<span class="string">"CARGO_PKG_VERSION"</span>);
|
||||
<span class="kw">let </span>git_hash = <span class="macro">option_env!</span>(<span class="string">"VERGEN_GIT_SHA"</span>).unwrap_or(<span class="string">"unknown"</span>);
|
||||
<span class="kw">let </span>commit_date = <span class="macro">option_env!</span>(<span class="string">"VERGEN_GIT_COMMIT_DATE"</span>).unwrap_or(<span class="string">"unknown"</span>);
|
||||
<span class="kw">let </span>avail_cons = {
|
||||
<span class="kw">let </span>inventory = Inventory::scan();
|
||||
inventory.available_connectors().join(<span class="string">", "</span>)
|
||||
};
|
||||
|
||||
<span class="macro">format!</span>(<span class="string">" {pkg_ver} (rev {git_hash})\nCommit Date: {commit_date}\nAvailable Connectors: {avail_cons}"</span>)
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>port_in_range(s: <span class="kw-2">&</span>str) -> <span class="prelude-ty">Result</span><u16, String> {
|
||||
<span class="kw">let </span>port: usize = s
|
||||
.parse()
|
||||
.map_err(|<span class="kw">_</span>| <span class="macro">format!</span>(<span class="string">"`{s}` isn't a port number"</span>))<span class="question-mark">?</span>;
|
||||
<span class="kw">if </span>PORT_RANGE.contains(<span class="kw-2">&</span>port) {
|
||||
<span class="prelude-val">Ok</span>(port <span class="kw">as </span>u16)
|
||||
} <span class="kw">else </span>{
|
||||
<span class="prelude-val">Err</span>(<span class="macro">format!</span>(
|
||||
<span class="string">"port not in range {}-{}"</span>,
|
||||
PORT_RANGE.start(),
|
||||
PORT_RANGE.end()
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>valid_path(s: <span class="kw-2">&</span>str) -> <span class="prelude-ty">Result</span><PathBuf, String> {
|
||||
<span class="kw">let </span>path = PathBuf::from(s);
|
||||
|
||||
<span class="kw">if </span>!path.exists() {
|
||||
<span class="kw">return </span><span class="prelude-val">Err</span>(<span class="string">"Path does not exist"</span>.to_string())
|
||||
}
|
||||
|
||||
<span class="kw">if </span>!path.is_dir() {
|
||||
<span class="kw">return </span><span class="prelude-val">Err</span>(<span class="string">"Path is not a directory"</span>.to_string())
|
||||
}
|
||||
|
||||
<span class="prelude-val">Ok</span>(path)
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>poll_in_range(s: <span class="kw-2">&</span>str) -> <span class="prelude-ty">Result</span><u16, String> {
|
||||
<span class="kw">let </span>port: usize = s
|
||||
.parse()
|
||||
.map_err(|<span class="kw">_</span>| <span class="macro">format!</span>(<span class="string">"`{s}` isn't a valid number"</span>))<span class="question-mark">?</span>;
|
||||
<span class="kw">if </span>POLL_RANGE.contains(<span class="kw-2">&</span>port) {
|
||||
<span class="prelude-val">Ok</span>(port <span class="kw">as </span>u16)
|
||||
} <span class="kw">else </span>{
|
||||
<span class="prelude-val">Err</span>(<span class="macro">format!</span>(
|
||||
<span class="string">"not in range {}-{}"</span>,
|
||||
POLL_RANGE.start(),
|
||||
POLL_RANGE.end()
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
<span class="doccomment">/// Wrapper because log::LevelFilter doesn't implement ValueEnum
|
||||
</span><span class="attr">#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Default)]
|
||||
</span><span class="kw">pub enum </span>Loglevel {
|
||||
Error,
|
||||
<span class="attr">#[default]
|
||||
</span>Warn,
|
||||
Info,
|
||||
Debug,
|
||||
Trace,
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>From<Loglevel> <span class="kw">for </span>log::LevelFilter {
|
||||
<span class="kw">fn </span>from(val: Loglevel) -> <span class="self">Self </span>{
|
||||
<span class="kw">match </span>val {
|
||||
Loglevel::Error => log::LevelFilter::Error,
|
||||
Loglevel::Warn => log::LevelFilter::Warn,
|
||||
Loglevel::Info => log::LevelFilter::Info,
|
||||
Loglevel::Debug => log::LevelFilter::Debug,
|
||||
Loglevel::Trace => log::LevelFilter::Trace,
|
||||
}
|
||||
}
|
||||
}</code></pre></div></section></main></body></html>
|
||||
136
docs/src/radarflow/comms.rs.html
Normal file
136
docs/src/radarflow/comms.rs.html
Normal file
@@ -0,0 +1,136 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Source of the Rust file `radarflow/src/comms.rs`."><title>comms.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-fa3bb1812debf86c.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="radarflow" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0 (79e9716c9 2023-11-13)" data-channel="1.74.0" data-search-js="search-8be46b629f5f14a8.js" data-settings-js="settings-74424d7eec62a23e.js" ><script src="../../static.files/storage-fec3eaa3851e447d.js"></script><script defer src="../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../src-files.js"></script><script defer src="../../static.files/main-c5bd66d33317d69f.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-5d8b3c7633ad77ba.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../radarflow/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
|
||||
<a href="#2" id="2">2</a>
|
||||
<a href="#3" id="3">3</a>
|
||||
<a href="#4" id="4">4</a>
|
||||
<a href="#5" id="5">5</a>
|
||||
<a href="#6" id="6">6</a>
|
||||
<a href="#7" id="7">7</a>
|
||||
<a href="#8" id="8">8</a>
|
||||
<a href="#9" id="9">9</a>
|
||||
<a href="#10" id="10">10</a>
|
||||
<a href="#11" id="11">11</a>
|
||||
<a href="#12" id="12">12</a>
|
||||
<a href="#13" id="13">13</a>
|
||||
<a href="#14" id="14">14</a>
|
||||
<a href="#15" id="15">15</a>
|
||||
<a href="#16" id="16">16</a>
|
||||
<a href="#17" id="17">17</a>
|
||||
<a href="#18" id="18">18</a>
|
||||
<a href="#19" id="19">19</a>
|
||||
<a href="#20" id="20">20</a>
|
||||
<a href="#21" id="21">21</a>
|
||||
<a href="#22" id="22">22</a>
|
||||
<a href="#23" id="23">23</a>
|
||||
<a href="#24" id="24">24</a>
|
||||
<a href="#25" id="25">25</a>
|
||||
<a href="#26" id="26">26</a>
|
||||
<a href="#27" id="27">27</a>
|
||||
<a href="#28" id="28">28</a>
|
||||
<a href="#29" id="29">29</a>
|
||||
<a href="#30" id="30">30</a>
|
||||
<a href="#31" id="31">31</a>
|
||||
<a href="#32" id="32">32</a>
|
||||
<a href="#33" id="33">33</a>
|
||||
<a href="#34" id="34">34</a>
|
||||
<a href="#35" id="35">35</a>
|
||||
<a href="#36" id="36">36</a>
|
||||
<a href="#37" id="37">37</a>
|
||||
<a href="#38" id="38">38</a>
|
||||
<a href="#39" id="39">39</a>
|
||||
<a href="#40" id="40">40</a>
|
||||
<a href="#41" id="41">41</a>
|
||||
<a href="#42" id="42">42</a>
|
||||
<a href="#43" id="43">43</a>
|
||||
<a href="#44" id="44">44</a>
|
||||
<a href="#45" id="45">45</a>
|
||||
<a href="#46" id="46">46</a>
|
||||
<a href="#47" id="47">47</a>
|
||||
<a href="#48" id="48">48</a>
|
||||
<a href="#49" id="49">49</a>
|
||||
<a href="#50" id="50">50</a>
|
||||
<a href="#51" id="51">51</a>
|
||||
<a href="#52" id="52">52</a>
|
||||
<a href="#53" id="53">53</a>
|
||||
<a href="#54" id="54">54</a>
|
||||
<a href="#55" id="55">55</a>
|
||||
<a href="#56" id="56">56</a>
|
||||
<a href="#57" id="57">57</a>
|
||||
<a href="#58" id="58">58</a>
|
||||
<a href="#59" id="59">59</a>
|
||||
<a href="#60" id="60">60</a>
|
||||
<a href="#61" id="61">61</a>
|
||||
<a href="#62" id="62">62</a>
|
||||
<a href="#63" id="63">63</a>
|
||||
<a href="#64" id="64">64</a>
|
||||
<a href="#65" id="65">65</a>
|
||||
<a href="#66" id="66">66</a>
|
||||
<a href="#67" id="67">67</a>
|
||||
<a href="#68" id="68">68</a>
|
||||
</pre></div><pre class="rust"><code><span class="kw">use </span>csflow::{enums::PlayerType, structs::Vec3};
|
||||
<span class="kw">use </span>serde::{Serialize, Deserialize};
|
||||
|
||||
<span class="attr">#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
</span><span class="kw">pub struct </span>PlayerData {
|
||||
pos: Vec3,
|
||||
yaw: f32,
|
||||
<span class="attr">#[serde(rename = <span class="string">"playerType"</span>)]
|
||||
</span>player_type: PlayerType,
|
||||
|
||||
<span class="attr">#[serde(rename = <span class="string">"hasBomb"</span>)]
|
||||
</span>has_bomb: bool
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>PlayerData {
|
||||
<span class="kw">pub fn </span>new(pos: Vec3, yaw: f32, player_type: PlayerType, has_bomb: bool) -> PlayerData {
|
||||
PlayerData { pos, yaw, player_type, has_bomb }
|
||||
}
|
||||
}
|
||||
|
||||
<span class="attr">#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
</span><span class="kw">pub struct </span>BombData {
|
||||
pos: Vec3,
|
||||
<span class="attr">#[serde(rename = <span class="string">"isPlanted"</span>)]
|
||||
</span>is_planted: bool
|
||||
}
|
||||
|
||||
<span class="attr">#[allow(dead_code)]
|
||||
</span><span class="kw">impl </span>BombData {
|
||||
<span class="kw">pub fn </span>new(pos: Vec3, is_planted: bool) -> BombData {
|
||||
BombData { pos, is_planted }
|
||||
}
|
||||
}
|
||||
|
||||
<span class="attr">#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
</span><span class="kw">pub enum </span>EntityData {
|
||||
Player(PlayerData),
|
||||
Bomb(BombData)
|
||||
}
|
||||
|
||||
<span class="attr">#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
</span><span class="kw">pub struct </span>RadarData {
|
||||
ingame: bool,
|
||||
|
||||
<span class="attr">#[serde(rename = <span class="string">"mapName"</span>)]
|
||||
</span>map_name: String,
|
||||
|
||||
<span class="attr">#[serde(rename(serialize = <span class="string">"entityData"</span>))]
|
||||
</span>player_data: Vec<EntityData>,
|
||||
|
||||
<span class="comment">//#[serde(rename(serialize = "localYaw"))]
|
||||
//local_yaw: f32,
|
||||
</span>}
|
||||
|
||||
<span class="kw">impl </span>RadarData {
|
||||
<span class="kw">pub fn </span>new(ingame: bool, map_name: String, player_data: Vec<EntityData>) -> RadarData {
|
||||
RadarData { ingame, map_name, player_data }
|
||||
}
|
||||
|
||||
<span class="doccomment">/// Returns empty RadarData, it's also the same data that gets sent to clients when not ingame
|
||||
</span><span class="kw">pub fn </span>empty() -> RadarData {
|
||||
RadarData {
|
||||
ingame: <span class="bool-val">false</span>,
|
||||
map_name: String::new(),
|
||||
player_data: Vec::new(),
|
||||
}
|
||||
}
|
||||
}</code></pre></div></section></main></body></html>
|
||||
170
docs/src/radarflow/dma/cache.rs.html
Normal file
170
docs/src/radarflow/dma/cache.rs.html
Normal file
@@ -0,0 +1,170 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Source of the Rust file `radarflow/src/dma/cache.rs`."><title>cache.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../../static.files/rustdoc-fa3bb1812debf86c.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="radarflow" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0 (79e9716c9 2023-11-13)" data-channel="1.74.0" data-search-js="search-8be46b629f5f14a8.js" data-settings-js="settings-74424d7eec62a23e.js" ><script src="../../../static.files/storage-fec3eaa3851e447d.js"></script><script defer src="../../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../../src-files.js"></script><script defer src="../../../static.files/main-c5bd66d33317d69f.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-5d8b3c7633ad77ba.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../../radarflow/index.html"><img class="rust-logo" src="../../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
|
||||
<a href="#2" id="2">2</a>
|
||||
<a href="#3" id="3">3</a>
|
||||
<a href="#4" id="4">4</a>
|
||||
<a href="#5" id="5">5</a>
|
||||
<a href="#6" id="6">6</a>
|
||||
<a href="#7" id="7">7</a>
|
||||
<a href="#8" id="8">8</a>
|
||||
<a href="#9" id="9">9</a>
|
||||
<a href="#10" id="10">10</a>
|
||||
<a href="#11" id="11">11</a>
|
||||
<a href="#12" id="12">12</a>
|
||||
<a href="#13" id="13">13</a>
|
||||
<a href="#14" id="14">14</a>
|
||||
<a href="#15" id="15">15</a>
|
||||
<a href="#16" id="16">16</a>
|
||||
<a href="#17" id="17">17</a>
|
||||
<a href="#18" id="18">18</a>
|
||||
<a href="#19" id="19">19</a>
|
||||
<a href="#20" id="20">20</a>
|
||||
<a href="#21" id="21">21</a>
|
||||
<a href="#22" id="22">22</a>
|
||||
<a href="#23" id="23">23</a>
|
||||
<a href="#24" id="24">24</a>
|
||||
<a href="#25" id="25">25</a>
|
||||
<a href="#26" id="26">26</a>
|
||||
<a href="#27" id="27">27</a>
|
||||
<a href="#28" id="28">28</a>
|
||||
<a href="#29" id="29">29</a>
|
||||
<a href="#30" id="30">30</a>
|
||||
<a href="#31" id="31">31</a>
|
||||
<a href="#32" id="32">32</a>
|
||||
<a href="#33" id="33">33</a>
|
||||
<a href="#34" id="34">34</a>
|
||||
<a href="#35" id="35">35</a>
|
||||
<a href="#36" id="36">36</a>
|
||||
<a href="#37" id="37">37</a>
|
||||
<a href="#38" id="38">38</a>
|
||||
<a href="#39" id="39">39</a>
|
||||
<a href="#40" id="40">40</a>
|
||||
<a href="#41" id="41">41</a>
|
||||
<a href="#42" id="42">42</a>
|
||||
<a href="#43" id="43">43</a>
|
||||
<a href="#44" id="44">44</a>
|
||||
<a href="#45" id="45">45</a>
|
||||
<a href="#46" id="46">46</a>
|
||||
<a href="#47" id="47">47</a>
|
||||
<a href="#48" id="48">48</a>
|
||||
<a href="#49" id="49">49</a>
|
||||
<a href="#50" id="50">50</a>
|
||||
<a href="#51" id="51">51</a>
|
||||
<a href="#52" id="52">52</a>
|
||||
<a href="#53" id="53">53</a>
|
||||
<a href="#54" id="54">54</a>
|
||||
<a href="#55" id="55">55</a>
|
||||
<a href="#56" id="56">56</a>
|
||||
<a href="#57" id="57">57</a>
|
||||
<a href="#58" id="58">58</a>
|
||||
<a href="#59" id="59">59</a>
|
||||
<a href="#60" id="60">60</a>
|
||||
<a href="#61" id="61">61</a>
|
||||
<a href="#62" id="62">62</a>
|
||||
<a href="#63" id="63">63</a>
|
||||
<a href="#64" id="64">64</a>
|
||||
<a href="#65" id="65">65</a>
|
||||
<a href="#66" id="66">66</a>
|
||||
<a href="#67" id="67">67</a>
|
||||
<a href="#68" id="68">68</a>
|
||||
<a href="#69" id="69">69</a>
|
||||
<a href="#70" id="70">70</a>
|
||||
<a href="#71" id="71">71</a>
|
||||
<a href="#72" id="72">72</a>
|
||||
<a href="#73" id="73">73</a>
|
||||
<a href="#74" id="74">74</a>
|
||||
<a href="#75" id="75">75</a>
|
||||
<a href="#76" id="76">76</a>
|
||||
<a href="#77" id="77">77</a>
|
||||
<a href="#78" id="78">78</a>
|
||||
<a href="#79" id="79">79</a>
|
||||
<a href="#80" id="80">80</a>
|
||||
<a href="#81" id="81">81</a>
|
||||
<a href="#82" id="82">82</a>
|
||||
<a href="#83" id="83">83</a>
|
||||
<a href="#84" id="84">84</a>
|
||||
<a href="#85" id="85">85</a>
|
||||
</pre></div><pre class="rust"><code><span class="kw">use </span>csflow::{memflow::Address, enums::PlayerType};
|
||||
|
||||
<span class="attr">#[derive(Clone, Copy)]
|
||||
</span><span class="kw">pub enum </span>CachedEntity {
|
||||
Bomb {ptr: Address},
|
||||
Player {ptr: Address, player_type: PlayerType},
|
||||
}
|
||||
|
||||
<span class="kw">pub struct </span>Cache {
|
||||
timestamp: std::time::Instant,
|
||||
entity_cache: Vec<CachedEntity>,
|
||||
map_name: String,
|
||||
entity_list: Address,
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>Cache {
|
||||
<span class="kw">pub fn </span>is_valid(<span class="kw-2">&</span><span class="self">self</span>) -> bool {
|
||||
<span class="kw">if </span><span class="self">self</span>.timestamp.elapsed() > std::time::Duration::from_millis(<span class="number">250</span>) {
|
||||
<span class="kw">return </span><span class="bool-val">false</span>;
|
||||
}
|
||||
|
||||
<span class="bool-val">true
|
||||
</span>}
|
||||
|
||||
<span class="kw">pub fn </span>new_invalid() -> Cache {
|
||||
Cache {
|
||||
timestamp: std::time::Instant::now().checked_sub(std::time::Duration::from_millis(<span class="number">500</span>)).unwrap(),
|
||||
entity_cache: Vec::new(),
|
||||
map_name: String::new(),
|
||||
entity_list: Address::null(),
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">pub fn </span>entity_cache(<span class="kw-2">&mut </span><span class="self">self</span>) -> Vec<CachedEntity> {
|
||||
<span class="self">self</span>.entity_cache.clone()
|
||||
}
|
||||
|
||||
<span class="kw">pub fn </span>map_name(<span class="kw-2">&</span><span class="self">self</span>) -> String {
|
||||
<span class="self">self</span>.map_name.clone()
|
||||
}
|
||||
|
||||
<span class="kw">pub fn </span>entity_list(<span class="kw-2">&</span><span class="self">self</span>) -> Address {
|
||||
<span class="self">self</span>.entity_list
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">pub struct </span>CacheBuilder {
|
||||
entity_cache: <span class="prelude-ty">Option</span><Vec<CachedEntity>>,
|
||||
map_name: <span class="prelude-ty">Option</span><String>,
|
||||
entity_list: <span class="prelude-ty">Option</span><Address>
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>CacheBuilder {
|
||||
<span class="kw">pub fn </span>new() -> CacheBuilder {
|
||||
CacheBuilder {
|
||||
entity_cache: <span class="prelude-val">None</span>,
|
||||
map_name: <span class="prelude-val">None</span>,
|
||||
entity_list: <span class="prelude-val">None</span>,
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">pub fn </span>entity_cache(<span class="kw-2">mut </span><span class="self">self</span>, entity_cache: Vec<CachedEntity>) -> CacheBuilder {
|
||||
<span class="self">self</span>.entity_cache = <span class="prelude-val">Some</span>(entity_cache);
|
||||
<span class="self">self
|
||||
</span>}
|
||||
|
||||
<span class="kw">pub fn </span>map_name(<span class="kw-2">mut </span><span class="self">self</span>, map_name: String) -> CacheBuilder {
|
||||
<span class="self">self</span>.map_name = <span class="prelude-val">Some</span>(map_name);
|
||||
<span class="self">self
|
||||
</span>}
|
||||
|
||||
<span class="kw">pub fn </span>entity_list(<span class="kw-2">mut </span><span class="self">self</span>, entity_list: Address) -> CacheBuilder {
|
||||
<span class="self">self</span>.entity_list = <span class="prelude-val">Some</span>(entity_list);
|
||||
<span class="self">self
|
||||
</span>}
|
||||
|
||||
<span class="kw">pub fn </span>build(<span class="self">self</span>) -> anyhow::Result<Cache> {
|
||||
<span class="prelude-val">Ok</span>(Cache {
|
||||
timestamp: std::time::Instant::now(),
|
||||
entity_cache: <span class="self">self</span>.entity_cache.ok_or(<span class="macro">anyhow::anyhow!</span>(<span class="string">"entity_cache not set on builder"</span>))<span class="question-mark">?</span>,
|
||||
map_name: <span class="self">self</span>.map_name.ok_or(<span class="macro">anyhow::anyhow!</span>(<span class="string">"map_name not set on builder"</span>))<span class="question-mark">?</span>,
|
||||
entity_list: <span class="self">self</span>.entity_list.ok_or(<span class="macro">anyhow::anyhow!</span>(<span class="string">"entity_list not set on builder"</span>))<span class="question-mark">?</span>,
|
||||
})
|
||||
}
|
||||
}</code></pre></div></section></main></body></html>
|
||||
405
docs/src/radarflow/dma/mod.rs.html
Normal file
405
docs/src/radarflow/dma/mod.rs.html
Normal file
@@ -0,0 +1,405 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Source of the Rust file `radarflow/src/dma/mod.rs`."><title>mod.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../../static.files/rustdoc-fa3bb1812debf86c.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="radarflow" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0 (79e9716c9 2023-11-13)" data-channel="1.74.0" data-search-js="search-8be46b629f5f14a8.js" data-settings-js="settings-74424d7eec62a23e.js" ><script src="../../../static.files/storage-fec3eaa3851e447d.js"></script><script defer src="../../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../../src-files.js"></script><script defer src="../../../static.files/main-c5bd66d33317d69f.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-5d8b3c7633ad77ba.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../../radarflow/index.html"><img class="rust-logo" src="../../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
|
||||
<a href="#2" id="2">2</a>
|
||||
<a href="#3" id="3">3</a>
|
||||
<a href="#4" id="4">4</a>
|
||||
<a href="#5" id="5">5</a>
|
||||
<a href="#6" id="6">6</a>
|
||||
<a href="#7" id="7">7</a>
|
||||
<a href="#8" id="8">8</a>
|
||||
<a href="#9" id="9">9</a>
|
||||
<a href="#10" id="10">10</a>
|
||||
<a href="#11" id="11">11</a>
|
||||
<a href="#12" id="12">12</a>
|
||||
<a href="#13" id="13">13</a>
|
||||
<a href="#14" id="14">14</a>
|
||||
<a href="#15" id="15">15</a>
|
||||
<a href="#16" id="16">16</a>
|
||||
<a href="#17" id="17">17</a>
|
||||
<a href="#18" id="18">18</a>
|
||||
<a href="#19" id="19">19</a>
|
||||
<a href="#20" id="20">20</a>
|
||||
<a href="#21" id="21">21</a>
|
||||
<a href="#22" id="22">22</a>
|
||||
<a href="#23" id="23">23</a>
|
||||
<a href="#24" id="24">24</a>
|
||||
<a href="#25" id="25">25</a>
|
||||
<a href="#26" id="26">26</a>
|
||||
<a href="#27" id="27">27</a>
|
||||
<a href="#28" id="28">28</a>
|
||||
<a href="#29" id="29">29</a>
|
||||
<a href="#30" id="30">30</a>
|
||||
<a href="#31" id="31">31</a>
|
||||
<a href="#32" id="32">32</a>
|
||||
<a href="#33" id="33">33</a>
|
||||
<a href="#34" id="34">34</a>
|
||||
<a href="#35" id="35">35</a>
|
||||
<a href="#36" id="36">36</a>
|
||||
<a href="#37" id="37">37</a>
|
||||
<a href="#38" id="38">38</a>
|
||||
<a href="#39" id="39">39</a>
|
||||
<a href="#40" id="40">40</a>
|
||||
<a href="#41" id="41">41</a>
|
||||
<a href="#42" id="42">42</a>
|
||||
<a href="#43" id="43">43</a>
|
||||
<a href="#44" id="44">44</a>
|
||||
<a href="#45" id="45">45</a>
|
||||
<a href="#46" id="46">46</a>
|
||||
<a href="#47" id="47">47</a>
|
||||
<a href="#48" id="48">48</a>
|
||||
<a href="#49" id="49">49</a>
|
||||
<a href="#50" id="50">50</a>
|
||||
<a href="#51" id="51">51</a>
|
||||
<a href="#52" id="52">52</a>
|
||||
<a href="#53" id="53">53</a>
|
||||
<a href="#54" id="54">54</a>
|
||||
<a href="#55" id="55">55</a>
|
||||
<a href="#56" id="56">56</a>
|
||||
<a href="#57" id="57">57</a>
|
||||
<a href="#58" id="58">58</a>
|
||||
<a href="#59" id="59">59</a>
|
||||
<a href="#60" id="60">60</a>
|
||||
<a href="#61" id="61">61</a>
|
||||
<a href="#62" id="62">62</a>
|
||||
<a href="#63" id="63">63</a>
|
||||
<a href="#64" id="64">64</a>
|
||||
<a href="#65" id="65">65</a>
|
||||
<a href="#66" id="66">66</a>
|
||||
<a href="#67" id="67">67</a>
|
||||
<a href="#68" id="68">68</a>
|
||||
<a href="#69" id="69">69</a>
|
||||
<a href="#70" id="70">70</a>
|
||||
<a href="#71" id="71">71</a>
|
||||
<a href="#72" id="72">72</a>
|
||||
<a href="#73" id="73">73</a>
|
||||
<a href="#74" id="74">74</a>
|
||||
<a href="#75" id="75">75</a>
|
||||
<a href="#76" id="76">76</a>
|
||||
<a href="#77" id="77">77</a>
|
||||
<a href="#78" id="78">78</a>
|
||||
<a href="#79" id="79">79</a>
|
||||
<a href="#80" id="80">80</a>
|
||||
<a href="#81" id="81">81</a>
|
||||
<a href="#82" id="82">82</a>
|
||||
<a href="#83" id="83">83</a>
|
||||
<a href="#84" id="84">84</a>
|
||||
<a href="#85" id="85">85</a>
|
||||
<a href="#86" id="86">86</a>
|
||||
<a href="#87" id="87">87</a>
|
||||
<a href="#88" id="88">88</a>
|
||||
<a href="#89" id="89">89</a>
|
||||
<a href="#90" id="90">90</a>
|
||||
<a href="#91" id="91">91</a>
|
||||
<a href="#92" id="92">92</a>
|
||||
<a href="#93" id="93">93</a>
|
||||
<a href="#94" id="94">94</a>
|
||||
<a href="#95" id="95">95</a>
|
||||
<a href="#96" id="96">96</a>
|
||||
<a href="#97" id="97">97</a>
|
||||
<a href="#98" id="98">98</a>
|
||||
<a href="#99" id="99">99</a>
|
||||
<a href="#100" id="100">100</a>
|
||||
<a href="#101" id="101">101</a>
|
||||
<a href="#102" id="102">102</a>
|
||||
<a href="#103" id="103">103</a>
|
||||
<a href="#104" id="104">104</a>
|
||||
<a href="#105" id="105">105</a>
|
||||
<a href="#106" id="106">106</a>
|
||||
<a href="#107" id="107">107</a>
|
||||
<a href="#108" id="108">108</a>
|
||||
<a href="#109" id="109">109</a>
|
||||
<a href="#110" id="110">110</a>
|
||||
<a href="#111" id="111">111</a>
|
||||
<a href="#112" id="112">112</a>
|
||||
<a href="#113" id="113">113</a>
|
||||
<a href="#114" id="114">114</a>
|
||||
<a href="#115" id="115">115</a>
|
||||
<a href="#116" id="116">116</a>
|
||||
<a href="#117" id="117">117</a>
|
||||
<a href="#118" id="118">118</a>
|
||||
<a href="#119" id="119">119</a>
|
||||
<a href="#120" id="120">120</a>
|
||||
<a href="#121" id="121">121</a>
|
||||
<a href="#122" id="122">122</a>
|
||||
<a href="#123" id="123">123</a>
|
||||
<a href="#124" id="124">124</a>
|
||||
<a href="#125" id="125">125</a>
|
||||
<a href="#126" id="126">126</a>
|
||||
<a href="#127" id="127">127</a>
|
||||
<a href="#128" id="128">128</a>
|
||||
<a href="#129" id="129">129</a>
|
||||
<a href="#130" id="130">130</a>
|
||||
<a href="#131" id="131">131</a>
|
||||
<a href="#132" id="132">132</a>
|
||||
<a href="#133" id="133">133</a>
|
||||
<a href="#134" id="134">134</a>
|
||||
<a href="#135" id="135">135</a>
|
||||
<a href="#136" id="136">136</a>
|
||||
<a href="#137" id="137">137</a>
|
||||
<a href="#138" id="138">138</a>
|
||||
<a href="#139" id="139">139</a>
|
||||
<a href="#140" id="140">140</a>
|
||||
<a href="#141" id="141">141</a>
|
||||
<a href="#142" id="142">142</a>
|
||||
<a href="#143" id="143">143</a>
|
||||
<a href="#144" id="144">144</a>
|
||||
<a href="#145" id="145">145</a>
|
||||
<a href="#146" id="146">146</a>
|
||||
<a href="#147" id="147">147</a>
|
||||
<a href="#148" id="148">148</a>
|
||||
<a href="#149" id="149">149</a>
|
||||
<a href="#150" id="150">150</a>
|
||||
<a href="#151" id="151">151</a>
|
||||
<a href="#152" id="152">152</a>
|
||||
<a href="#153" id="153">153</a>
|
||||
<a href="#154" id="154">154</a>
|
||||
<a href="#155" id="155">155</a>
|
||||
<a href="#156" id="156">156</a>
|
||||
<a href="#157" id="157">157</a>
|
||||
<a href="#158" id="158">158</a>
|
||||
<a href="#159" id="159">159</a>
|
||||
<a href="#160" id="160">160</a>
|
||||
<a href="#161" id="161">161</a>
|
||||
<a href="#162" id="162">162</a>
|
||||
<a href="#163" id="163">163</a>
|
||||
<a href="#164" id="164">164</a>
|
||||
<a href="#165" id="165">165</a>
|
||||
<a href="#166" id="166">166</a>
|
||||
<a href="#167" id="167">167</a>
|
||||
<a href="#168" id="168">168</a>
|
||||
<a href="#169" id="169">169</a>
|
||||
<a href="#170" id="170">170</a>
|
||||
<a href="#171" id="171">171</a>
|
||||
<a href="#172" id="172">172</a>
|
||||
<a href="#173" id="173">173</a>
|
||||
<a href="#174" id="174">174</a>
|
||||
<a href="#175" id="175">175</a>
|
||||
<a href="#176" id="176">176</a>
|
||||
<a href="#177" id="177">177</a>
|
||||
<a href="#178" id="178">178</a>
|
||||
<a href="#179" id="179">179</a>
|
||||
<a href="#180" id="180">180</a>
|
||||
<a href="#181" id="181">181</a>
|
||||
<a href="#182" id="182">182</a>
|
||||
<a href="#183" id="183">183</a>
|
||||
<a href="#184" id="184">184</a>
|
||||
<a href="#185" id="185">185</a>
|
||||
<a href="#186" id="186">186</a>
|
||||
<a href="#187" id="187">187</a>
|
||||
<a href="#188" id="188">188</a>
|
||||
<a href="#189" id="189">189</a>
|
||||
<a href="#190" id="190">190</a>
|
||||
<a href="#191" id="191">191</a>
|
||||
<a href="#192" id="192">192</a>
|
||||
<a href="#193" id="193">193</a>
|
||||
<a href="#194" id="194">194</a>
|
||||
<a href="#195" id="195">195</a>
|
||||
<a href="#196" id="196">196</a>
|
||||
<a href="#197" id="197">197</a>
|
||||
<a href="#198" id="198">198</a>
|
||||
<a href="#199" id="199">199</a>
|
||||
<a href="#200" id="200">200</a>
|
||||
<a href="#201" id="201">201</a>
|
||||
<a href="#202" id="202">202</a>
|
||||
</pre></div><pre class="rust"><code><span class="kw">use </span>std::sync::Arc;
|
||||
|
||||
<span class="kw">use </span>csflow::{CheatCtx, Connector, memflow::Process, traits::{MemoryClass, BaseEntity}, enums::PlayerType, structs::{CBaseEntity, CPlayerController}};
|
||||
<span class="kw">use </span>tokio::{sync::RwLock, time::{Duration, Instant}};
|
||||
|
||||
<span class="kw">use crate</span>::{comms::{RadarData, EntityData, BombData, PlayerData}, dma::cache::CacheBuilder};
|
||||
|
||||
<span class="kw">use </span><span class="self">self</span>::cache::Cache;
|
||||
|
||||
<span class="kw">mod </span>cache;
|
||||
|
||||
<span class="kw">const </span>SECOND_AS_NANO: u64 = <span class="number">1000</span><span class="kw-2">*</span><span class="number">1000</span><span class="kw-2">*</span><span class="number">1000</span>;
|
||||
<span class="kw">static </span>ONCE: std::sync::Once = std::sync::Once::new();
|
||||
|
||||
<span class="kw">pub async fn </span>run(connector: Connector, pcileech_device: String, poll_rate: u16, data_lock: Arc<RwLock<RadarData>>) -> anyhow::Result<()> {
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>ctx = CheatCtx::setup(connector, pcileech_device)<span class="question-mark">?</span>;
|
||||
|
||||
<span class="macro">println!</span>(<span class="string">"---------------------------------------------------"</span>);
|
||||
<span class="macro">println!</span>(<span class="string">"Found cs2.exe at {:X}"</span>, ctx.process.info().address);
|
||||
<span class="macro">println!</span>(<span class="string">"Found engine module at cs2.exe+{:X}"</span>, ctx.engine_module.base);
|
||||
<span class="macro">println!</span>(<span class="string">"Found client module at cs2.exe+{:X}"</span>, ctx.client_module.base);
|
||||
<span class="macro">println!</span>(<span class="string">"---------------------------------------------------"</span>);
|
||||
|
||||
<span class="comment">// Avoid printing warnings and other stuff before the initial prints are complete
|
||||
</span>tokio::time::sleep(Duration::from_millis(<span class="number">500</span>)).<span class="kw">await</span>;
|
||||
|
||||
<span class="comment">// For poll rate timing
|
||||
</span><span class="kw">let </span>should_time = poll_rate != <span class="number">0</span>;
|
||||
|
||||
<span class="kw">let </span>target_interval = Duration::from_nanos(SECOND_AS_NANO / poll_rate <span class="kw">as </span>u64);
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>last_iteration_time = Instant::now();
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>missmatch_count = <span class="number">0</span>;
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>cache = Cache::new_invalid();
|
||||
|
||||
<span class="kw">loop </span>{
|
||||
<span class="kw">if </span>ctx.process.state().is_dead() {
|
||||
<span class="kw">break</span>;
|
||||
}
|
||||
|
||||
<span class="kw">if </span>!cache.is_valid() {
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>cached_entities = Vec::new();
|
||||
|
||||
<span class="kw">let </span>globals = ctx.get_globals()<span class="question-mark">?</span>;
|
||||
<span class="kw">let </span>highest_index = ctx.highest_entity_index()<span class="question-mark">?</span>;
|
||||
<span class="kw">let </span>map_name = ctx.map_name(globals)<span class="question-mark">?</span>;
|
||||
<span class="kw">let </span>entity_list = ctx.get_entity_list()<span class="question-mark">?</span>;
|
||||
|
||||
<span class="kw">let </span>local = ctx.get_local()<span class="question-mark">?</span>;
|
||||
|
||||
<span class="kw">if </span>local.get_pawn(<span class="kw-2">&mut </span>ctx, entity_list)<span class="question-mark">?</span>.is_some() {
|
||||
cached_entities.push(cache::CachedEntity::Player {
|
||||
ptr: local.ptr(),
|
||||
player_type: PlayerType::Local
|
||||
});
|
||||
|
||||
<span class="kw">for </span>idx <span class="kw">in </span><span class="number">1</span>..=highest_index {
|
||||
<span class="kw">if let </span><span class="prelude-val">Some</span>(entity) = CBaseEntity::from_index(<span class="kw-2">&mut </span>ctx, entity_list, idx)<span class="question-mark">? </span>{
|
||||
|
||||
<span class="kw">let </span>class_name = entity.class_name(<span class="kw-2">&mut </span>ctx)<span class="question-mark">?</span>;
|
||||
|
||||
<span class="kw">match </span>class_name.as_str() {
|
||||
<span class="string">"weapon_c4" </span>=> {
|
||||
cached_entities.push(cache::CachedEntity::Bomb {
|
||||
ptr: entity.ptr()
|
||||
})
|
||||
},
|
||||
<span class="string">"cs_player_controller" </span>=> {
|
||||
<span class="kw">let </span>controller = entity.to_player_controller();
|
||||
|
||||
<span class="kw">let </span>player_type = {
|
||||
<span class="kw">match </span>controller.get_player_type(<span class="kw-2">&mut </span>ctx, <span class="kw-2">&</span>local)<span class="question-mark">? </span>{
|
||||
<span class="prelude-val">Some</span>(t) => {
|
||||
<span class="kw">if </span>t == PlayerType::Spectator { <span class="kw">continue </span>} <span class="kw">else </span>{ t }
|
||||
},
|
||||
<span class="prelude-val">None </span>=> { <span class="kw">continue </span>},
|
||||
}
|
||||
};
|
||||
|
||||
cached_entities.push(cache::CachedEntity::Player {
|
||||
ptr: entity.ptr(),
|
||||
player_type,
|
||||
})
|
||||
}
|
||||
<span class="kw">_ </span>=> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cache = CacheBuilder::new()
|
||||
.entity_cache(cached_entities)
|
||||
.entity_list(entity_list)
|
||||
.map_name(map_name)
|
||||
.build()<span class="question-mark">?</span>;
|
||||
|
||||
<span class="macro">log::debug!</span>(<span class="string">"Rebuilt cache."</span>);
|
||||
}
|
||||
|
||||
<span class="kw">if </span>ctx.network_is_ingame()<span class="question-mark">? </span>{
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>radar_data = Vec::with_capacity(<span class="number">64</span>);
|
||||
|
||||
<span class="kw">if </span>ctx.is_bomb_planted()<span class="question-mark">? </span>{
|
||||
<span class="kw">let </span>bomb = ctx.get_plantedc4()<span class="question-mark">?</span>;
|
||||
<span class="kw">let </span>bomb_pos = bomb.pos(<span class="kw-2">&mut </span>ctx)<span class="question-mark">?</span>;
|
||||
radar_data.push(
|
||||
EntityData::Bomb(BombData::new(
|
||||
bomb_pos,
|
||||
<span class="bool-val">true
|
||||
</span>))
|
||||
);
|
||||
}
|
||||
|
||||
<span class="kw">for </span>cached_data <span class="kw">in </span>cache.entity_cache() {
|
||||
<span class="kw">match </span>cached_data {
|
||||
cache::CachedEntity::Bomb { ptr } => {
|
||||
<span class="kw">if </span>ctx.is_bomb_dropped()<span class="question-mark">? </span>{
|
||||
<span class="kw">let </span>bomb_entity = CBaseEntity::new(ptr);
|
||||
<span class="kw">let </span>pos = bomb_entity.pos(<span class="kw-2">&mut </span>ctx)<span class="question-mark">?</span>;
|
||||
|
||||
radar_data.push(
|
||||
EntityData::Bomb(
|
||||
BombData::new(
|
||||
pos,
|
||||
<span class="bool-val">false
|
||||
</span>)
|
||||
)
|
||||
);
|
||||
}
|
||||
},
|
||||
cache::CachedEntity::Player { ptr, player_type } => {
|
||||
<span class="kw">let </span>controller = CPlayerController::new(ptr);
|
||||
<span class="kw">if let </span><span class="prelude-val">Some</span>(pawn) = controller.get_pawn(<span class="kw-2">&mut </span>ctx, cache.entity_list())<span class="question-mark">? </span>{
|
||||
<span class="kw">if </span>pawn.is_alive(<span class="kw-2">&mut </span>ctx)<span class="question-mark">? </span>{
|
||||
<span class="kw">let </span>pos = pawn.pos(<span class="kw-2">&mut </span>ctx)<span class="question-mark">?</span>;
|
||||
<span class="kw">let </span>yaw = pawn.angles(<span class="kw-2">&mut </span>ctx)<span class="question-mark">?</span>.y;
|
||||
<span class="kw">let </span>has_bomb = pawn.has_c4(<span class="kw-2">&mut </span>ctx, cache.entity_list())<span class="question-mark">?</span>;
|
||||
|
||||
radar_data.push(
|
||||
EntityData::Player(
|
||||
PlayerData::new(
|
||||
pos,
|
||||
yaw,
|
||||
player_type,
|
||||
has_bomb
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>data = data_lock.write().<span class="kw">await</span>;
|
||||
<span class="kw">if </span>cache.map_name() == <span class="string">"<empty>" </span>|| cache.map_name().is_empty() {
|
||||
<span class="kw-2">*</span>data = RadarData::empty()
|
||||
} <span class="kw">else </span>{
|
||||
<span class="kw-2">*</span>data = RadarData::new(<span class="bool-val">true</span>, cache.map_name(), radar_data)
|
||||
}
|
||||
} <span class="kw">else </span>{
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>data = data_lock.write().<span class="kw">await</span>;
|
||||
<span class="kw-2">*</span>data = RadarData::empty()
|
||||
}
|
||||
|
||||
<span class="kw">if </span>should_time {
|
||||
<span class="kw">let </span>elapsed = last_iteration_time.elapsed();
|
||||
|
||||
<span class="kw">let </span>remaining = <span class="kw">match </span>target_interval.checked_sub(elapsed) {
|
||||
<span class="prelude-val">Some</span>(t) => t,
|
||||
<span class="prelude-val">None </span>=> {
|
||||
<span class="kw">if </span>missmatch_count >= <span class="number">25 </span>{
|
||||
ONCE.call_once(|| {
|
||||
<span class="macro">log::warn!</span>(<span class="string">"Remaining time till target interval was negative more than 25 times"</span>);
|
||||
<span class="macro">log::warn!</span>(<span class="string">"You should decrease your poll rate."</span>);
|
||||
<span class="macro">log::warn!</span>(<span class="string">"elapsed: {}ns"</span>, elapsed.as_nanos());
|
||||
<span class="macro">log::warn!</span>(<span class="string">"target: {}ns"</span>, target_interval.as_nanos());
|
||||
});
|
||||
} <span class="kw">else </span>{
|
||||
missmatch_count += <span class="number">1</span>;
|
||||
}
|
||||
Duration::from_nanos(<span class="number">0</span>)
|
||||
},
|
||||
};
|
||||
|
||||
<span class="attr">#[cfg(target_os = <span class="string">"linux"</span>)]
|
||||
</span>tokio_timerfd::sleep(remaining).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="attr">#[cfg(not(target_os = <span class="string">"linux"</span>))]
|
||||
</span>tokio::time::sleep(remaining).<span class="kw">await</span>;
|
||||
|
||||
<span class="macro">log::info!</span>(<span class="string">"poll rate: {:.2}Hz"</span>, SECOND_AS_NANO <span class="kw">as </span>f64 / last_iteration_time.elapsed().as_nanos() <span class="kw">as </span>f64);
|
||||
<span class="macro">log::trace!</span>(<span class="string">"elapsed: {}ns"</span>, elapsed.as_nanos());
|
||||
<span class="macro">log::trace!</span>(<span class="string">"target: {}ns"</span>, target_interval.as_nanos());
|
||||
<span class="macro">log::trace!</span>(<span class="string">"missmatch count: {}"</span>, missmatch_count);
|
||||
|
||||
last_iteration_time = Instant::now();
|
||||
}
|
||||
}
|
||||
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}
|
||||
</code></pre></div></section></main></body></html>
|
||||
115
docs/src/radarflow/main.rs.html
Normal file
115
docs/src/radarflow/main.rs.html
Normal file
@@ -0,0 +1,115 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Source of the Rust file `radarflow/src/main.rs`."><title>main.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-fa3bb1812debf86c.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="radarflow" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0 (79e9716c9 2023-11-13)" data-channel="1.74.0" data-search-js="search-8be46b629f5f14a8.js" data-settings-js="settings-74424d7eec62a23e.js" ><script src="../../static.files/storage-fec3eaa3851e447d.js"></script><script defer src="../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../src-files.js"></script><script defer src="../../static.files/main-c5bd66d33317d69f.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-5d8b3c7633ad77ba.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../radarflow/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
|
||||
<a href="#2" id="2">2</a>
|
||||
<a href="#3" id="3">3</a>
|
||||
<a href="#4" id="4">4</a>
|
||||
<a href="#5" id="5">5</a>
|
||||
<a href="#6" id="6">6</a>
|
||||
<a href="#7" id="7">7</a>
|
||||
<a href="#8" id="8">8</a>
|
||||
<a href="#9" id="9">9</a>
|
||||
<a href="#10" id="10">10</a>
|
||||
<a href="#11" id="11">11</a>
|
||||
<a href="#12" id="12">12</a>
|
||||
<a href="#13" id="13">13</a>
|
||||
<a href="#14" id="14">14</a>
|
||||
<a href="#15" id="15">15</a>
|
||||
<a href="#16" id="16">16</a>
|
||||
<a href="#17" id="17">17</a>
|
||||
<a href="#18" id="18">18</a>
|
||||
<a href="#19" id="19">19</a>
|
||||
<a href="#20" id="20">20</a>
|
||||
<a href="#21" id="21">21</a>
|
||||
<a href="#22" id="22">22</a>
|
||||
<a href="#23" id="23">23</a>
|
||||
<a href="#24" id="24">24</a>
|
||||
<a href="#25" id="25">25</a>
|
||||
<a href="#26" id="26">26</a>
|
||||
<a href="#27" id="27">27</a>
|
||||
<a href="#28" id="28">28</a>
|
||||
<a href="#29" id="29">29</a>
|
||||
<a href="#30" id="30">30</a>
|
||||
<a href="#31" id="31">31</a>
|
||||
<a href="#32" id="32">32</a>
|
||||
<a href="#33" id="33">33</a>
|
||||
<a href="#34" id="34">34</a>
|
||||
<a href="#35" id="35">35</a>
|
||||
<a href="#36" id="36">36</a>
|
||||
<a href="#37" id="37">37</a>
|
||||
<a href="#38" id="38">38</a>
|
||||
<a href="#39" id="39">39</a>
|
||||
<a href="#40" id="40">40</a>
|
||||
<a href="#41" id="41">41</a>
|
||||
<a href="#42" id="42">42</a>
|
||||
<a href="#43" id="43">43</a>
|
||||
<a href="#44" id="44">44</a>
|
||||
<a href="#45" id="45">45</a>
|
||||
<a href="#46" id="46">46</a>
|
||||
<a href="#47" id="47">47</a>
|
||||
<a href="#48" id="48">48</a>
|
||||
<a href="#49" id="49">49</a>
|
||||
<a href="#50" id="50">50</a>
|
||||
<a href="#51" id="51">51</a>
|
||||
<a href="#52" id="52">52</a>
|
||||
<a href="#53" id="53">53</a>
|
||||
<a href="#54" id="54">54</a>
|
||||
<a href="#55" id="55">55</a>
|
||||
<a href="#56" id="56">56</a>
|
||||
<a href="#57" id="57">57</a>
|
||||
</pre></div><pre class="rust"><code><span class="kw">use </span>std::sync::Arc;
|
||||
|
||||
<span class="kw">use </span>clap::Parser;
|
||||
<span class="kw">use </span>cli::Cli;
|
||||
<span class="kw">use </span>comms::RadarData;
|
||||
<span class="kw">use </span>tokio::sync::RwLock;
|
||||
|
||||
<span class="kw">mod </span>comms;
|
||||
<span class="kw">mod </span>cli;
|
||||
|
||||
<span class="kw">mod </span>dma;
|
||||
<span class="kw">mod </span>websocket;
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() -> anyhow::Result<()> {
|
||||
<span class="kw">let </span>cli = Cli::parse();
|
||||
|
||||
simple_logger::SimpleLogger::new()
|
||||
.with_level(cli.loglevel.into())
|
||||
.init()
|
||||
.expect(<span class="string">"Initializing logger"</span>);
|
||||
|
||||
<span class="kw">let </span>rwlock = Arc::new(
|
||||
RwLock::new(
|
||||
RadarData::empty()
|
||||
)
|
||||
);
|
||||
|
||||
<span class="kw">let </span>rwlock_clone = rwlock.clone();
|
||||
<span class="kw">let </span>dma_handle = tokio::spawn(<span class="kw">async move </span>{
|
||||
<span class="kw">if let </span><span class="prelude-val">Err</span>(err) = dma::run(cli.connector, cli.pcileech_device, cli.poll_rate, rwlock_clone).<span class="kw">await </span>{
|
||||
<span class="macro">log::error!</span>(<span class="string">"Error in dma thread: [{}]"</span>, err.to_string());
|
||||
}
|
||||
});
|
||||
|
||||
tokio::spawn(<span class="kw">async move </span>{
|
||||
<span class="kw">let </span>future = websocket::run(cli.web_path, cli.port, rwlock);
|
||||
|
||||
<span class="kw">if let </span><span class="prelude-val">Ok</span>(my_local_ip) = local_ip_address::local_ip() {
|
||||
<span class="kw">let </span>address = <span class="macro">format!</span>(<span class="string">"http://{}:{}"</span>, my_local_ip, cli.port);
|
||||
<span class="macro">println!</span>(<span class="string">"Launched webserver at {}"</span>, address);
|
||||
} <span class="kw">else </span>{
|
||||
<span class="kw">let </span>address = <span class="macro">format!</span>(<span class="string">"http://0.0.0.0:{}"</span>, cli.port);
|
||||
<span class="macro">println!</span>(<span class="string">"launched webserver at! {}"</span>, address);
|
||||
}
|
||||
|
||||
<span class="kw">if let </span><span class="prelude-val">Err</span>(err) = future.<span class="kw">await </span>{
|
||||
<span class="macro">log::error!</span>(<span class="string">"Error in websocket server: [{}]"</span>, err.to_string());
|
||||
}
|
||||
});
|
||||
|
||||
<span class="kw">if let </span><span class="prelude-val">Err</span>(err) = dma_handle.<span class="kw">await </span>{
|
||||
<span class="macro">log::error!</span>(<span class="string">"Error when waiting for dma thread: {}"</span>, err.to_string());
|
||||
}
|
||||
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}
|
||||
</code></pre></div></section></main></body></html>
|
||||
132
docs/src/radarflow/websocket.rs.html
Normal file
132
docs/src/radarflow/websocket.rs.html
Normal file
@@ -0,0 +1,132 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Source of the Rust file `radarflow/src/websocket.rs`."><title>websocket.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-fa3bb1812debf86c.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="radarflow" data-themes="" data-resource-suffix="" data-rustdoc-version="1.74.0 (79e9716c9 2023-11-13)" data-channel="1.74.0" data-search-js="search-8be46b629f5f14a8.js" data-settings-js="settings-74424d7eec62a23e.js" ><script src="../../static.files/storage-fec3eaa3851e447d.js"></script><script defer src="../../static.files/src-script-3280b574d94e47b4.js"></script><script defer src="../../src-files.js"></script><script defer src="../../static.files/main-c5bd66d33317d69f.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-5d8b3c7633ad77ba.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc src"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><nav class="sub"><a class="sub-logo-container" href="../../radarflow/index.html"><img class="rust-logo" src="../../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="example-wrap"><div data-nosnippet><pre class="src-line-numbers"><a href="#1" id="1">1</a>
|
||||
<a href="#2" id="2">2</a>
|
||||
<a href="#3" id="3">3</a>
|
||||
<a href="#4" id="4">4</a>
|
||||
<a href="#5" id="5">5</a>
|
||||
<a href="#6" id="6">6</a>
|
||||
<a href="#7" id="7">7</a>
|
||||
<a href="#8" id="8">8</a>
|
||||
<a href="#9" id="9">9</a>
|
||||
<a href="#10" id="10">10</a>
|
||||
<a href="#11" id="11">11</a>
|
||||
<a href="#12" id="12">12</a>
|
||||
<a href="#13" id="13">13</a>
|
||||
<a href="#14" id="14">14</a>
|
||||
<a href="#15" id="15">15</a>
|
||||
<a href="#16" id="16">16</a>
|
||||
<a href="#17" id="17">17</a>
|
||||
<a href="#18" id="18">18</a>
|
||||
<a href="#19" id="19">19</a>
|
||||
<a href="#20" id="20">20</a>
|
||||
<a href="#21" id="21">21</a>
|
||||
<a href="#22" id="22">22</a>
|
||||
<a href="#23" id="23">23</a>
|
||||
<a href="#24" id="24">24</a>
|
||||
<a href="#25" id="25">25</a>
|
||||
<a href="#26" id="26">26</a>
|
||||
<a href="#27" id="27">27</a>
|
||||
<a href="#28" id="28">28</a>
|
||||
<a href="#29" id="29">29</a>
|
||||
<a href="#30" id="30">30</a>
|
||||
<a href="#31" id="31">31</a>
|
||||
<a href="#32" id="32">32</a>
|
||||
<a href="#33" id="33">33</a>
|
||||
<a href="#34" id="34">34</a>
|
||||
<a href="#35" id="35">35</a>
|
||||
<a href="#36" id="36">36</a>
|
||||
<a href="#37" id="37">37</a>
|
||||
<a href="#38" id="38">38</a>
|
||||
<a href="#39" id="39">39</a>
|
||||
<a href="#40" id="40">40</a>
|
||||
<a href="#41" id="41">41</a>
|
||||
<a href="#42" id="42">42</a>
|
||||
<a href="#43" id="43">43</a>
|
||||
<a href="#44" id="44">44</a>
|
||||
<a href="#45" id="45">45</a>
|
||||
<a href="#46" id="46">46</a>
|
||||
<a href="#47" id="47">47</a>
|
||||
<a href="#48" id="48">48</a>
|
||||
<a href="#49" id="49">49</a>
|
||||
<a href="#50" id="50">50</a>
|
||||
<a href="#51" id="51">51</a>
|
||||
<a href="#52" id="52">52</a>
|
||||
<a href="#53" id="53">53</a>
|
||||
<a href="#54" id="54">54</a>
|
||||
<a href="#55" id="55">55</a>
|
||||
<a href="#56" id="56">56</a>
|
||||
<a href="#57" id="57">57</a>
|
||||
<a href="#58" id="58">58</a>
|
||||
<a href="#59" id="59">59</a>
|
||||
<a href="#60" id="60">60</a>
|
||||
<a href="#61" id="61">61</a>
|
||||
<a href="#62" id="62">62</a>
|
||||
<a href="#63" id="63">63</a>
|
||||
<a href="#64" id="64">64</a>
|
||||
<a href="#65" id="65">65</a>
|
||||
<a href="#66" id="66">66</a>
|
||||
</pre></div><pre class="rust"><code><span class="kw">use </span>std::{sync::Arc, path::PathBuf};
|
||||
|
||||
<span class="kw">use </span>axum::{
|
||||
extract::{ws::{WebSocketUpgrade, WebSocket, Message}, State},
|
||||
response::Response,
|
||||
routing::get,
|
||||
Router,
|
||||
};
|
||||
|
||||
<span class="kw">use </span>tokio::sync::RwLock;
|
||||
<span class="kw">use </span>tower_http::services::ServeDir;
|
||||
|
||||
<span class="kw">use </span><span class="kw">crate</span>::comms::RadarData;
|
||||
|
||||
<span class="attr">#[derive(Clone)]
|
||||
</span><span class="kw">struct </span>AppState {
|
||||
data_lock: Arc<RwLock<RadarData>>
|
||||
}
|
||||
|
||||
<span class="kw">async fn </span>ws_handler(ws: WebSocketUpgrade, State(state): State<AppState>) -> Response {
|
||||
ws.on_upgrade(|socket| handle_socket(socket, state))
|
||||
}
|
||||
|
||||
<span class="kw">async fn </span>handle_socket(<span class="kw-2">mut </span>socket: WebSocket, state: AppState) {
|
||||
<span class="kw">while let </span><span class="prelude-val">Some</span>(msg) = socket.recv().<span class="kw">await </span>{
|
||||
<span class="kw">if let </span><span class="prelude-val">Ok</span>(msg) = msg {
|
||||
<span class="kw">if </span>msg == Message::Text(<span class="string">"requestInfo"</span>.to_string()) {
|
||||
<span class="kw">let </span>data = state.data_lock.read().<span class="kw">await</span>;
|
||||
|
||||
<span class="kw">let </span>str = {
|
||||
<span class="kw">match </span>serde_json::to_string(<span class="kw-2">&*</span>data) {
|
||||
<span class="prelude-val">Ok</span>(json) => json,
|
||||
<span class="prelude-val">Err</span>(e) => {
|
||||
<span class="macro">log::error!</span>(<span class="string">"Could not serialize data into json: {}"</span>, e.to_string());
|
||||
<span class="macro">log::error!</span>(<span class="string">"Sending \"error\" instead"</span>);
|
||||
<span class="string">"error"</span>.to_string()
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
<span class="kw">if </span>socket.send(Message::Text(str)).<span class="kw">await</span>.is_err() {
|
||||
<span class="comment">// client disconnected
|
||||
</span><span class="kw">return</span>;
|
||||
}
|
||||
}
|
||||
} <span class="kw">else </span>{
|
||||
<span class="comment">// client disconnected
|
||||
</span><span class="kw">return</span>;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">pub async fn </span>run(path: PathBuf, port: u16, data_lock: Arc<RwLock<RadarData>>) -> anyhow::Result<()> {
|
||||
<span class="kw">let </span>app = Router::new()
|
||||
.nest_service(<span class="string">"/"</span>, ServeDir::new(path))
|
||||
.route(<span class="string">"/ws"</span>, get(ws_handler))
|
||||
.with_state(AppState { data_lock });
|
||||
|
||||
<span class="kw">let </span>address = <span class="macro">format!</span>(<span class="string">"0.0.0.0:{}"</span>, port);
|
||||
|
||||
axum::Server::bind(<span class="kw-2">&</span>address.parse()<span class="question-mark">?</span>)
|
||||
.serve(app.into_make_service())
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}</code></pre></div></section></main></body></html>
|
||||
Reference in New Issue
Block a user