Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgazelka committed Nov 11, 2024
1 parent 55b1fe6 commit 50ae8bf
Show file tree
Hide file tree
Showing 12 changed files with 312 additions and 79 deletions.
209 changes: 150 additions & 59 deletions Cargo.lock

Large diffs are not rendered by default.

48 changes: 28 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,30 @@ panic = 'abort'

[workspace]
members = [
'crates/bvh-region',
'crates/hyperion',
'crates/hyperion-crafting',
'crates/hyperion-event-macros',
'crates/hyperion-inventory',
'crates/hyperion-minecraft-proto',
'crates/hyperion-nerd-font',
'crates/hyperion-palette',
'crates/hyperion-proto',
'crates/hyperion-proxy',
'crates/hyperion-scheduled',
'crates/hyperion-stats',
'crates/hyperion-text',
'crates/hyperion-utils',
'events/proof-of-concept',
'crates/hyperion-permission',
'crates/hyperion-clap',
'crates/hyperion-command',
'crates/bvh-region',
'crates/hyperion',
'crates/hyperion-crafting',
'crates/hyperion-event-macros',
'crates/hyperion-inventory',
'crates/hyperion-minecraft-proto',
'crates/hyperion-nerd-font',
'crates/hyperion-palette',
'crates/hyperion-proto',
'crates/hyperion-proxy',
'crates/hyperion-scheduled',
'crates/hyperion-stats',
'crates/hyperion-text',
'crates/hyperion-utils',
'events/proof-of-concept',
'crates/hyperion-permission',
'crates/hyperion-clap',
'crates/hyperion-command',
'crates/hyperion-bot'
]
resolver = '2'

[workspace.dependencies]

antithesis = {version = "0.2.4", package = "antithesis_sdk"}
anyhow = '1.0.86'
approx = '0.5.1'
arrayvec = '0.7.4'
Expand All @@ -48,7 +49,9 @@ compact_str = '0.8.0'
criterion = '0.5.1'
derive-build = '0.1.1'
dirs-next = '2.0.0'
dotenvy = {version = "0.15.7"}
enumset = '1.1.5'
envy = { version = "0.4.2" }
fastrand = '2.1.0'
glam = '0.29.0'
gxhash = { version = "3.4.1" }
Expand All @@ -73,6 +76,7 @@ plotters-bitmap = '0.3.6'
pretty-hex = '0.4.1'
rand = '0.8.5'
rayon = '1.10.0'
regex = { version = "1.11.1", features = ["perf", "perf-dfa-full"] } # todo: do we want perf-dfa-full?
rustc-hash = '2.0.0'
rustc_version = '0.4.0'
serde = '1.0.214'
Expand All @@ -85,7 +89,8 @@ thiserror = "2.0.1"
tikv-jemallocator = '0.6.0'
tokio = '1.40.0'
toml = '0.8.14'
uuid = '1.8.0'
uuid = {version = '1.8.0', features = ["serde"]}

[workspace.dependencies.bvh]
git = 'https://github.com/andrewgazelka/bvh-data'

Expand Down Expand Up @@ -118,6 +123,9 @@ git = 'https://github.com/Indra-db/Flecs-Rust'
[workspace.dependencies.hyperion]
path = 'crates/hyperion'

[workspace.dependencies.hyperion-bot]
path = 'crates/hyperion-bot'

[workspace.dependencies.hyperion-clap]
path = 'crates/hyperion-clap'

Expand Down
1 change: 1 addition & 0 deletions crates/hyperion-bot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
27 changes: 27 additions & 0 deletions crates/hyperion-bot/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cargo-features = ["edition2024"]

[dependencies]
eyre = "0.6.12"
tokio = {features = ["full"], workspace = true}
antithesis.workspace = true
derive_more.workspace = true
dotenvy.workspace = true
envy.workspace = true
rand.workspace = true
regex.workspace = true
serde.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
uuid.workspace = true
valence_protocol.workspace = true

[lints]
workspace = true

[package]
authors = ["Andrew Gazelka <andrew.gazelka@gmail.com>"]
edition = "2024"
name = "hyperion-bot"
publish = false
readme = "README.md"
version = "0.1.0"
1 change: 1 addition & 0 deletions crates/hyperion-bot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# hyperion-bot
6 changes: 6 additions & 0 deletions crates/hyperion-bot/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use serde::Deserialize;

#[derive(Debug, Deserialize)]
pub struct Config {
pub max_number_of_bots: usize,
}
2 changes: 2 additions & 0 deletions crates/hyperion-bot/src/generate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod name;
pub use name::{generate as name, Name};
29 changes: 29 additions & 0 deletions crates/hyperion-bot/src/generate/name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::sync::LazyLock;

use antithesis::random::AntithesisRng;
use rand::Rng;

#[derive(Clone, Debug)]
pub struct Name {
pub value: String,
pub is_valid: bool,
}

pub fn generate() -> Name {
static NAME_REGEX: LazyLock<regex::Regex> =
LazyLock::new(|| regex::Regex::new(r"^[a-zA-Z0-9_]+$").unwrap());

let mut rng = AntithesisRng;

let len = rng.gen_range(0..20);
let name: String = (0..len).map(|_| rng.r#gen::<char>()).collect();

// name is max 16 characters

let is_valid = name.len() <= 16 && { NAME_REGEX.is_match(&name) };

Name {
value: name,
is_valid,
}
}
Empty file.
40 changes: 40 additions & 0 deletions crates/hyperion-bot/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use antithesis::{assert_sometimes, random::AntithesisRng};
use derive_more::Constructor;
use rand::{rngs::StdRng, Rng};
use uuid::Uuid;
use valence_protocol::{
packets, packets::handshaking::handshake_c2s::HandshakeNextState, Bounded, VarInt,
PROTOCOL_VERSION,
};

mod config;
pub use config::Config;

mod generate;
mod util;

mod handshake;

#[derive(Constructor)]
struct Bot {
name: String,
uuid: Uuid,
connection: tokio::net::TcpStream,
}

pub fn bootstrap(config: &Config) {
// todo: use life cycle

let mut rng = AntithesisRng;

let first_name = generate::name();
assert_sometimes!(first_name.is_valid, "First name is never invalid");
assert_sometimes!(!first_name.is_valid, "First name is always valid");

let first_uuid: u128 = rng.r#gen();
let first_uuid = Uuid::from_u128(first_uuid);

let first_handle = tokio::spawn(login(first_bot));
let second_handle = tokio::spawn(login(second_bot));
}

17 changes: 17 additions & 0 deletions crates/hyperion-bot/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use eyre::{eyre, Context};
use hyperion_bot::bootstrap;

#[tokio::main]
async fn main() -> eyre::Result<()> {
tracing_subscriber::fmt::init();

// it is not an error if a .env file is missing
drop(dotenvy::dotenv());

let config = envy::from_env().wrap_err("Failed to load config from environment variables")?;

tracing::info!("{config:?}");

bootstrap(&config);
Ok(())
}
11 changes: 11 additions & 0 deletions crates/hyperion-bot/src/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use antithesis::random::AntithesisRng;
use rand::Rng;

pub fn random_either<T>(left: impl FnOnce() -> T, right: impl FnOnce() -> T) -> T {
let mut rng = AntithesisRng;
if rng.r#gen::<bool>() {
left()
} else {
right()
}
}

0 comments on commit 50ae8bf

Please sign in to comment.