-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55b1fe6
commit 50ae8bf
Showing
12 changed files
with
312 additions
and
79 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# hyperion-bot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mod name; | ||
pub use name::{generate as name, Name}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |