Compare commits
No commits in common. "master" and "v0.2.0" have entirely different histories.
14
.github/workflows/build.yml
vendored
14
.github/workflows/build.yml
vendored
@ -80,10 +80,10 @@ jobs:
|
|||||||
command: clippy
|
command: clippy
|
||||||
args: -- -D warnings
|
args: -- -D warnings
|
||||||
|
|
||||||
# - name: Run rustdoc lints
|
- name: Run rustdoc lints
|
||||||
# uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
# env:
|
env:
|
||||||
# RUSTDOCFLAGS: "-D missing_docs -D rustdoc::missing_doc_code_examples"
|
RUSTDOCFLAGS: "-D missing_docs -D rustdoc::missing_doc_code_examples"
|
||||||
# with:
|
with:
|
||||||
# command: doc
|
command: doc
|
||||||
# args: --workspace --all-features --no-deps --document-private-items
|
args: --workspace --all-features --no-deps --document-private-items
|
||||||
|
6
justfile
6
justfile
@ -1,6 +1,6 @@
|
|||||||
alias r := run
|
alias r := run
|
||||||
alias t := test
|
alias t := test
|
||||||
alias b := book
|
alias b := build
|
||||||
|
|
||||||
run:
|
run:
|
||||||
cd rte; cargo run
|
cd rte; cargo run
|
||||||
@ -8,8 +8,8 @@ run:
|
|||||||
test:
|
test:
|
||||||
cargo test
|
cargo test
|
||||||
|
|
||||||
book:
|
build:
|
||||||
cd book; mdbook serve
|
mdbook build
|
||||||
|
|
||||||
install_book_toolchain:
|
install_book_toolchain:
|
||||||
cargo install mdbook --locked --version 0.4.47
|
cargo install mdbook --locked --version 0.4.47
|
||||||
|
16
src/error.rs
16
src/error.rs
@ -21,14 +21,14 @@ pub enum AppError {
|
|||||||
impl fmt::Display for AppError {
|
impl fmt::Display for AppError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
AppError::IoError(err) => write!(f, "IO Error: {err}"),
|
AppError::IoError(err) => write!(f, "IO Error: {}", err),
|
||||||
AppError::RegexError(err) => write!(f, "Extension Regex Error: {err}"),
|
AppError::RegexError(err) => write!(f, "Extension Regex Error: {}", err),
|
||||||
AppError::ParseIntError(err) => write!(f, "Parse int error: {err}"),
|
AppError::ParseIntError(err) => write!(f, "Parse int error: {}", err),
|
||||||
AppError::ParseFloatError(err) => write!(f, "Parse float error: {err}"),
|
AppError::ParseFloatError(err) => write!(f, "Parse float error: {}", err),
|
||||||
AppError::TryFromIntError(err) => write!(f, "Integer conversion error: {err}"),
|
AppError::TryFromIntError(err) => write!(f, "Integer conversion error: {}", err),
|
||||||
AppError::RhaiError(err) => write!(f, "Rhai compilation error: {err}"),
|
AppError::RhaiError(err) => write!(f, "Rhai compilation error: {}", err),
|
||||||
AppError::MutexPoisoned(err) => write!(f, "Poisoned mutex: {err}"),
|
AppError::MutexPoisoned(err) => write!(f, "Poisoned mutex: {}", err),
|
||||||
AppError::DeserializerError(err) => write!(f, "Config Deserializer Failed: {err}"),
|
AppError::DeserializerError(err) => write!(f, "Config Deserializer Failed: {}", err),
|
||||||
AppError::InvalidWorldFile => write!(f, "Invalid world file"),
|
AppError::InvalidWorldFile => write!(f, "Invalid world file"),
|
||||||
// AppError::InvalidExtensionVersion => write!(f, "Invalid extension version"),
|
// AppError::InvalidExtensionVersion => write!(f, "Invalid extension version"),
|
||||||
}
|
}
|
||||||
|
@ -462,7 +462,7 @@ impl Extensions {
|
|||||||
let extension_path = extension?.path();
|
let extension_path = extension?.path();
|
||||||
|
|
||||||
if extension_path.extension() != Some(OsStr::new("rhai")) {
|
if extension_path.extension() != Some(OsStr::new("rhai")) {
|
||||||
continue;
|
break;
|
||||||
}
|
}
|
||||||
info!("Loading extension {}", extension_path.display());
|
info!("Loading extension {}", extension_path.display());
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
#![feature(coverage_attribute)]
|
|
||||||
|
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use simple_logger::SimpleLogger;
|
use simple_logger::SimpleLogger;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
@ -75,7 +75,7 @@ pub fn handle_client(
|
|||||||
let mut verif_key_formatted = String::new();
|
let mut verif_key_formatted = String::new();
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
for &byte in &verif_key {
|
for &byte in &verif_key {
|
||||||
write!(&mut verif_key_formatted, "{byte:X}").expect("Piss");
|
write!(&mut verif_key_formatted, "{:X}", byte).expect("Piss");
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let mut players = players_arc_clone.lock().unwrap();
|
let mut players = players_arc_clone.lock().unwrap();
|
||||||
|
132
src/utils.rs
132
src/utils.rs
@ -58,8 +58,6 @@ pub fn init_level() -> Vec<u8> {
|
|||||||
vec![0x02]
|
vec![0x02]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mutex coverage difficult, this whole function is basic rust literals anyway
|
|
||||||
#[coverage(off)]
|
|
||||||
pub fn finalize_level(world_arc_clone: &Arc<Mutex<World>>) -> Result<Vec<u8>, AppError> {
|
pub fn finalize_level(world_arc_clone: &Arc<Mutex<World>>) -> Result<Vec<u8>, AppError> {
|
||||||
let mut ret_val: Vec<u8> = vec![];
|
let mut ret_val: Vec<u8> = vec![];
|
||||||
ret_val.push(0x04);
|
ret_val.push(0x04);
|
||||||
@ -145,7 +143,6 @@ pub fn set_position_and_orientation(
|
|||||||
ret_val
|
ret_val
|
||||||
}
|
}
|
||||||
|
|
||||||
#[coverage(off)]
|
|
||||||
pub fn send_level_data(world_arc_clone: &Arc<Mutex<World>>) -> Result<Vec<u8>, AppError> {
|
pub fn send_level_data(world_arc_clone: &Arc<Mutex<World>>) -> Result<Vec<u8>, AppError> {
|
||||||
let mut ret_val: Vec<u8> = vec![];
|
let mut ret_val: Vec<u8> = vec![];
|
||||||
let mut world_dat = world_arc_clone.lock()?.data.clone();
|
let mut world_dat = world_arc_clone.lock()?.data.clone();
|
||||||
@ -212,7 +209,6 @@ pub fn send_level_data(world_arc_clone: &Arc<Mutex<World>>) -> Result<Vec<u8>, A
|
|||||||
Ok(ret_val)
|
Ok(ret_val)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[coverage(off)]
|
|
||||||
pub fn bomb_server_details(
|
pub fn bomb_server_details(
|
||||||
config: ServerConfig,
|
config: ServerConfig,
|
||||||
stream: &mut TcpStream,
|
stream: &mut TcpStream,
|
||||||
@ -246,8 +242,6 @@ pub fn bomb_server_details(
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::config::WorldConfig;
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -265,7 +259,6 @@ mod tests {
|
|||||||
// implemented, and also that you can't test a range of data but to that I say...
|
// implemented, and also that you can't test a range of data but to that I say...
|
||||||
// yeah ig TODO:
|
// yeah ig TODO:
|
||||||
// Make this not a pile of shit
|
// Make this not a pile of shit
|
||||||
// UPDATE: I have looked at the compiled code, the version that's actually used live is slighly shorter and is faster
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -282,129 +275,4 @@ mod tests {
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_server_ident() {
|
|
||||||
assert_eq!(
|
|
||||||
server_identification(
|
|
||||||
ServerConfig {
|
|
||||||
port: 25565,
|
|
||||||
max_players: 255,
|
|
||||||
name: "Shrimp".to_string(),
|
|
||||||
motd: "Also shrimp".to_string()
|
|
||||||
},
|
|
||||||
true
|
|
||||||
),
|
|
||||||
[
|
|
||||||
0, 7, 83, 104, 114, 105, 109, 112, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
||||||
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
||||||
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
||||||
32, 32, 32, 32, 65, 108, 115, 111, 32, 115, 104, 114, 105, 109, 112, 32, 32, 32,
|
|
||||||
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
||||||
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
||||||
32, 32, 32, 32, 32, 32, 32, 32, 100
|
|
||||||
]
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
server_identification(
|
|
||||||
ServerConfig {
|
|
||||||
port: 25565,
|
|
||||||
max_players: 255,
|
|
||||||
name: "Shrimp".to_string(),
|
|
||||||
motd: "Also shrimp".to_string()
|
|
||||||
},
|
|
||||||
false
|
|
||||||
),
|
|
||||||
[
|
|
||||||
0, 7, 83, 104, 114, 105, 109, 112, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
||||||
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
||||||
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
||||||
32, 32, 32, 32, 65, 108, 115, 111, 32, 115, 104, 114, 105, 109, 112, 32, 32, 32,
|
|
||||||
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
||||||
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
||||||
32, 32, 32, 32, 32, 32, 32, 32, 0
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_ping() {
|
|
||||||
assert_eq!(ping(), [1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_init_level() {
|
|
||||||
assert_eq!(init_level(), [2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_finalize_level() {
|
|
||||||
assert_eq!(
|
|
||||||
finalize_level(&Arc::new(Mutex::new(
|
|
||||||
World::load(&WorldConfig {
|
|
||||||
world: "testpath.testwrld".to_string(),
|
|
||||||
size_x: 256,
|
|
||||||
size_y: 128,
|
|
||||||
size_z: 256
|
|
||||||
})
|
|
||||||
.unwrap()
|
|
||||||
)))
|
|
||||||
.unwrap(),
|
|
||||||
[4, 1, 0, 0, 128, 1, 0]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_spawn_player() {
|
|
||||||
assert_eq!(
|
|
||||||
spawn_player(7, "jimmy the 9", 25, 47, 3, 90, 90),
|
|
||||||
[
|
|
||||||
7, 7, 106, 105, 109, 109, 121, 32, 116, 104, 101, 32, 57, 32, 32, 32, 32, 32, 32,
|
|
||||||
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
||||||
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
|
|
||||||
32, 32, 32, 32, 32, 3, 32, 5, 224, 0, 96, 90, 90
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_despawn_player() {
|
|
||||||
for x in u8::MIN..u8::MAX {
|
|
||||||
assert_eq!(despawn_player(x), [0x0C, x]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_send_chat_message() {
|
|
||||||
assert_eq!(
|
|
||||||
send_chat_message(12, "Testy toes".to_string(), "Whurrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr".to_string()),
|
|
||||||
[
|
|
||||||
13, 12, 84, 101, 115, 116, 121, 32, 116, 111, 101, 115, 58, 32, 87, 104, 117, 114,
|
|
||||||
114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114,
|
|
||||||
114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114,
|
|
||||||
114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, 114
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_write_chat_stream() {
|
|
||||||
assert_eq!(
|
|
||||||
write_chat_stream("This message is nice and long, like the message before it, it is long because this also tests for truncation".to_string()),
|
|
||||||
[
|
|
||||||
13, 255, 84, 104, 105, 115, 32, 109, 101, 115, 115, 97, 103, 101, 32, 105, 115, 32,
|
|
||||||
110, 105, 99, 101, 32, 97, 110, 100, 32, 108, 111, 110, 103, 44, 32, 108, 105, 107,
|
|
||||||
101, 32, 116, 104, 101, 32, 109, 101, 115, 115, 97, 103, 101, 32, 98, 101, 102, 111,
|
|
||||||
114, 101, 32, 105, 116, 44, 32, 105, 116, 32, 105, 115
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_set_position_and_orientation() {
|
|
||||||
assert_eq!(
|
|
||||||
set_position_and_orientation(120, 15, 16, 17, 90, 90),
|
|
||||||
[8, 120, 0, 15, 0, 16, 0, 17, 90, 90]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user