-
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
f785c9f
commit dda7052
Showing
11 changed files
with
280 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,25 @@ | ||
[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 = "2021" | ||
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, | ||
} | ||
} |
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,82 @@ | ||
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; | ||
|
||
#[derive(Constructor)] | ||
struct Bot { | ||
name: String, | ||
uuid: Uuid, | ||
} | ||
|
||
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 second_name = generate::name(); | ||
assert_sometimes!(second_name.is_valid, "Second name is never invalid"); | ||
assert_sometimes!(!second_name.is_valid, "Second name is always valid"); | ||
|
||
assert_sometimes!( | ||
first_name.value != second_name.value, | ||
"Names are never the same" | ||
); | ||
assert_sometimes!( | ||
first_name.is_valid && second_name.is_valid && first_name.value != second_name.value, | ||
"Names are never valid and the same" | ||
); | ||
|
||
let first_uuid: u128 = rng.r#gen(); | ||
let first_uuid = Uuid::from_u128(first_uuid); | ||
|
||
// todo: do we need to coax the fuzzer to more likely generate the same UUID? | ||
let second_uuid: u128 = rng.r#gen(); | ||
let second_uuid = Uuid::from_u128(second_uuid); | ||
|
||
assert_sometimes!(first_uuid == second_uuid, "UUIDs are always different"); | ||
|
||
let first_bot = Bot::new(first_name.value, first_uuid); | ||
let second_bot = Bot::new(second_name.value, second_uuid); | ||
|
||
let first_handle = tokio::spawn(login(first_bot)); | ||
let second_handle = tokio::spawn(login(second_bot)); | ||
} | ||
|
||
async fn login(bot: Bot) { | ||
// let mut rng = AntithesisRng; | ||
// | ||
// let protocol_version = util::random_either( | ||
// || PROTOCOL_VERSION, | ||
// || rng.gen(), | ||
// ); | ||
// | ||
// let is_valid_protocol_version = protocol_version == PROTOCOL_VERSION; | ||
// | ||
// | ||
// let arbitrary_packet = packets::handshaking::HandshakeC2s::arbitrary(&mut rng); | ||
// | ||
// let | ||
// | ||
// | ||
// let handshake = packets::handshaking::HandshakeC2s { | ||
// protocol_version: VarInt(protocol_version), | ||
// server_address: Default::default(), | ||
// server_port: 0, | ||
// next_state: HandshakeNextState::Login, | ||
// }; | ||
} |
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(()) | ||
} |
Oops, something went wrong.