Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgazelka committed Nov 12, 2024
1 parent af9119e commit bdadc20
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 79 deletions.
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ version = '1.0.30'
features = ['flecs_manual_registration']
git = 'https://github.com/Indra-db/Flecs-Rust'

[workspace.dependencies.gxhash]
version = '3.4.1'

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

Expand Down
34 changes: 26 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Define base arguments for versioning and optimization
ARG RUST_NIGHTLY_VERSION=nightly-2024-10-22
ARG RUST_NIGHTLY_VERSION=nightly-2024-11-11
ARG RUST_TARGET_CPU=native
ARG RUSTFLAGS="-C target-cpu=${RUST_TARGET_CPU} -Z share-generics=y -Z threads=8 --cfg tokio_unstable"
#ARG RUSTFLAGS="-C target-cpu=${RUST_TARGET_CPU} -Z share-generics=y -Z threads=8 --cfg tokio_unstable"
ARG CARGO_HOME=/usr/local/cargo

# Use Ubuntu as base image
Expand Down Expand Up @@ -53,7 +53,8 @@ RUN --mount=type=cache,target=${CARGO_HOME}/registry \
cargo build --frozen && \
mkdir -p /app/build && \
cp target/debug/hyperion-proxy /app/build/ && \
cp target/debug/proof-of-concept /app/build/
cp target/debug/proof-of-concept /app/build/ && \
cp target/debug/hyperion-bot /app/build/

# Release builder
FROM builder-base AS build-release
Expand All @@ -64,7 +65,8 @@ RUN --mount=type=cache,target=${CARGO_HOME}/registry \
cargo build --profile release-full --frozen && \
mkdir -p /app/build && \
cp target/release-full/hyperion-proxy /app/build/ && \
cp target/release-full/proof-of-concept /app/build/
cp target/release-full/proof-of-concept /app/build/ && \
cp target/release-full/hyperion-bot /app/build/

# Runtime base image
FROM ubuntu:22.04 AS runtime-base
Expand Down Expand Up @@ -96,20 +98,36 @@ EXPOSE 8080
ENTRYPOINT ["/hyperion-proxy"]
CMD ["0.0.0.0:8080"]

# NYC Debug
# Proof of Concept Debug
FROM runtime-base AS proof-of-concept-debug
COPY --from=build-debug /app/build/proof-of-concept /
LABEL org.opencontainers.image.source="https://github.com/yourusername/proof-of-concept" \
org.opencontainers.image.description="Debug Build - NYC Server" \
org.opencontainers.image.description="Debug Build - Proof of Concept Server" \
org.opencontainers.image.version="1.0.0"
ENTRYPOINT ["/proof-of-concept"]
CMD ["--ip", "0.0.0.0", "--port", "35565"]

# NYC Release
# Proof of Concept Release
FROM runtime-base AS proof-of-concept-release
COPY --from=build-release /app/build/proof-of-concept /
LABEL org.opencontainers.image.source="https://github.com/yourusername/proof-of-concept" \
org.opencontainers.image.description="Release Build - NYC Server" \
org.opencontainers.image.description="Release Build - Proof of Concept Server" \
org.opencontainers.image.version="1.0.0"
ENTRYPOINT ["/proof-of-concept"]
CMD ["--ip", "0.0.0.0", "--port", "35565"]

# Hyperion Bot Debug
FROM runtime-base AS hyperion-bot-debug
COPY --from=build-debug /app/build/hyperion-bot /
LABEL org.opencontainers.image.source="https://github.com/yourusername/hyperion-bot" \
org.opencontainers.image.description="Debug Build - Hyperion Bot" \
org.opencontainers.image.version="1.0.0"
ENTRYPOINT ["/hyperion-bot"]
CMD ["--ip", "0.0.0.0", "--port", "35565"]

# Hyperion Bot Release
FROM runtime-base AS hyperion-bot-release
COPY --from=build-release /app/build/hyperion-bot /
LABEL org.opencontainers.image.source="https://github.com/yourusername/hyperion-bot" \
org.opencontainers.image.description="Release Build - Hyperion Bot" \
org.opencontainers.image.version="1.0.0"
24 changes: 24 additions & 0 deletions crates/hyperion-bot/src/bot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use tokio::net::{TcpStream, ToSocketAddrs};
use uuid::Uuid;

mod handshake;

pub struct Bot {
name: String,
uuid: Uuid,
buf: Vec<u8>,
connection: TcpStream,
}

impl Bot {
pub async fn new(name: String, uuid: Uuid, addr: impl ToSocketAddrs) -> Self {
let addr = TcpStream::connect(addr).await.unwrap();

Self {
name,
uuid,
buf: Vec::new(),
connection: addr,
}
}
}
36 changes: 36 additions & 0 deletions crates/hyperion-bot/src/bot/handshake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use antithesis::random::AntithesisRng;
use rand::Rng;
use tokio::io::AsyncWriteExt;
use valence_protocol::{
Bounded, Encode, PROTOCOL_VERSION, VarInt, packets,
packets::handshaking::handshake_c2s::HandshakeNextState,
};

use crate::{bot::Bot, util::random_either};

impl Bot {
pub async fn handshake(mut self) -> eyre::Result<()> {
let mut rng = AntithesisRng;

let protocol_version: i32 = random_either(|| PROTOCOL_VERSION, || rng.r#gen::<i32>());

let is_correct_protocol_version = protocol_version == PROTOCOL_VERSION;

let addr = "placeholder";

let packet = packets::handshaking::HandshakeC2s {
protocol_version: VarInt(protocol_version),
server_address: Bounded(addr),
server_port: 25565, // probably does not matter
next_state: HandshakeNextState::Status,
};

packet
.encode(&mut self.buf)
.map_err(|e| eyre::eyre!("failed to encode handshake packet: {e}"))?;

self.connection.write_all(&self.buf).await?;

Ok(())
}
}
2 changes: 1 addition & 1 deletion crates/hyperion-bot/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct Config {
pub max_number_of_bots: usize,
pub add
pub host: String,
}
29 changes: 0 additions & 29 deletions crates/hyperion-bot/src/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,3 @@ use valence_protocol::{

use crate::{Bot, util::random_either};

impl Bot {
pub async fn handshake(mut self) -> eyre::Result<()> {
let mut rng = AntithesisRng;

let protocol_version: i32 = random_either(|| PROTOCOL_VERSION, || rng.r#gen::<i32>());

let correct_protocol_version = protocol_version == PROTOCOL_VERSION;
let protocol_version = VarInt(protocol_version);

let addr = "placeholder";

// want to test {correct_protocol_version} <=> pass

let packet = packets::handshaking::HandshakeC2s {
protocol_version: VarInt(0),
server_address: Bounded(addr),
server_port: 0,
next_state: HandshakeNextState::Status,
};

packet
.encode(&mut self.buf)
.map_err(|e| eyre::eyre!("failed to encode handshake packet: {e}"))?;

self.connection.write_all(&self.buf).await?;

Ok(())
}
}
28 changes: 10 additions & 18 deletions crates/hyperion-bot/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
use antithesis::{assert_sometimes, random::AntithesisRng};
use derive_more::Constructor;
use rand::{rngs::StdRng, Rng};
use rand::Rng;
use uuid::Uuid;
use valence_protocol::{
packets, packets::handshaking::handshake_c2s::HandshakeNextState, Bounded, VarInt,
PROTOCOL_VERSION,
};

mod config;
pub use config::Config;

use crate::bot::Bot;

mod generate;
mod util;

mod bot;
mod handshake;

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

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

Expand All @@ -31,14 +21,16 @@ pub fn bootstrap(config: &Config) {
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);

for _ in 0..10 {
let name = first_name.value.clone();
let addr = config.host.clone();
tokio::spawn(async move {
let mut bot = Bot::new(first_name.value, first_uuid, first_addr);
let bot = Bot::new(name, first_uuid, addr);
bot.await.handshake().await.unwrap();
});
}
}

2 changes: 1 addition & 1 deletion crates/hyperion-bot/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use eyre::{eyre, Context};
use eyre::Context;
use hyperion_bot::bootstrap;

#[tokio::main]
Expand Down
1 change: 0 additions & 1 deletion crates/hyperion-command/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ publish = false
[dependencies]
flecs_ecs.workspace = true
hyperion.workspace = true
gxhash.workspace = true
tracing.workspace = true
indexmap.workspace = true

Expand Down
2 changes: 1 addition & 1 deletion crates/hyperion-command/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub type CommandHandler = fn(input: &str, world: &World, caller: Entity);

#[derive(Component)]
pub struct CommandRegistry {
pub(crate) commands: IndexMap<String, CommandHandler, gxhash::GxBuildHasher>,
pub(crate) commands: IndexMap<String, CommandHandler>,
}

impl CommandRegistry {
Expand Down
1 change: 0 additions & 1 deletion events/proof-of-concept/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ tracing-subscriber.workspace = true
tracing-tracy.workspace = true
tracing.workspace = true
rayon.workspace = true
gxhash.workspace = true
derive_more.workspace = true

[dev-dependencies]
Expand Down
7 changes: 3 additions & 4 deletions events/proof-of-concept/src/command/replace.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::{HashSet, VecDeque};

use flecs_ecs::core::{Entity, EntityViewGet, World, WorldGet};
use gxhash::GxBuildHasher;
use hyperion::{BlockState, glam::IVec3, simulation::blocks::Blocks};
use rayon::iter::ParallelIterator;

Expand Down Expand Up @@ -62,8 +61,8 @@ const ADJACENT: [IVec3; 6] = [

/// Groups connected positions in 3D space
/// Returns a vector of groups, where each group is a vector of connected positions
fn group(positions: &HashSet<IVec3, GxBuildHasher>) -> Vec<Vec<IVec3>> {
let mut visited: HashSet<IVec3, GxBuildHasher> = HashSet::default();
fn group(positions: &HashSet<IVec3>) -> Vec<Vec<IVec3>> {
let mut visited: HashSet<IVec3> = HashSet::default();
let mut groups: Vec<Vec<IVec3>> = Vec::new();

// Iterate through all positions
Expand Down Expand Up @@ -108,7 +107,7 @@ impl hyperion_clap::MinecraftCommand for ReplaceCommand {
world.get::<&mut Blocks>(|blocks| {
let started_time = std::time::Instant::now();

let concrete_positions: HashSet<_, GxBuildHasher> =
let concrete_positions: HashSet<_> =
blocks.par_scan_for(BlockState::ORANGE_CONCRETE).collect();

let scan_time = started_time.elapsed();
Expand Down
3 changes: 2 additions & 1 deletion events/proof-of-concept/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#![feature(iter_from_coroutine)]
#![feature(exact_size_is_empty)]

use std::collections::HashSet;
use std::net::ToSocketAddrs;

use flecs_ecs::prelude::*;
Expand Down Expand Up @@ -37,7 +38,7 @@ mod skin;

#[derive(Component, Default, Deref, DerefMut)]
struct OreVeins {
ores: gxhash::HashSet<IVec3>,
ores: HashSet<IVec3>,
}

impl Module for ProofOfConceptModule {
Expand Down
Binary file added libvoidstar.so
Binary file not shown.

0 comments on commit bdadc20

Please sign in to comment.