Skip to content

Commit

Permalink
feat(server): add no_tag team to player join world (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgazelka authored Jun 15, 2024
1 parent 0bf5041 commit 50ee267
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
29 changes: 29 additions & 0 deletions crates/server/src/system/player_join_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ pub fn player_join_world(
.unwrap();

let mut entries = Vec::new();
let mut all_player_names = Vec::new();

query.iter_stage(world).each(|(uuid, name, _)| {
let entry = PlayerListEntry {
Expand All @@ -398,8 +399,11 @@ pub fn player_join_world(
};

entries.push(entry);
all_player_names.push(name.to_string());
});

let all_player_names = all_player_names.iter().map(String::as_str).collect();

let actions = PlayerListActions::default()
.with_add_player(true)
.with_update_listed(true)
Expand Down Expand Up @@ -433,6 +437,31 @@ pub fn player_join_world(

compose.broadcast(&pkt).send().unwrap();

let player_name = vec![name];

compose
.broadcast(&play::TeamS2c {
team_name: "no_tag",
mode: Mode::AddEntities {
entities: player_name,
},
})
.exclude(packets)
.send()
.unwrap();

compose
.unicast(
&play::TeamS2c {
team_name: "no_tag",
mode: Mode::AddEntities {
entities: all_player_names,
},
},
packets,
)
.unwrap();

let current_entity_id = VarInt(entity.id().0 as i32);

let spawn_player = play::PlayerSpawnS2c {
Expand Down
5 changes: 4 additions & 1 deletion crates/server/src/system/stats_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ use crate::net::Compose;

#[rustfmt::skip]
pub fn stats_message(world: &World) {
let mode = std::env::var("RUN_MODE").unwrap_or_else(|_| "Unknown".to_string());


world
.system_named::<&Compose>("stats_message")
.term_at(0).singleton()
.each(move |compose| {
let ms_per_tick = compose.global().ms_last_tick;

let title = format!("{ms_per_tick:05.2} ms/tick");
let title = format!("{ms_per_tick:05.2} ms/tick, {mode}");
let title = title.into_cow_text();
let health = (ms_per_tick / 50.0).min(1.0);

Expand Down
9 changes: 5 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
default: fmt lint unused-deps deny test

project_root := `git rev-parse --show-toplevel`
arch := `uname -m`

# builds in release mode
build:
Expand Down Expand Up @@ -37,20 +38,20 @@ debug:
#!/usr/bin/env -S parallel --shebang --ungroup --jobs 3
hyperion-proxy
cargo watch -x build -s 'touch {{project_root}}/.trigger'
cargo watch --postpone --no-vcs-ignores -w {{project_root}}/.trigger -s './target/debug/infection'
RUN_MODE=debug-{{arch}} cargo watch --postpone --no-vcs-ignores -w {{project_root}}/.trigger -s './target/debug/infection'

# run in release mode with tracy; auto-restarts on changes
release:
#!/usr/bin/env -S parallel --shebang --ungroup --jobs 3
ulimit -Sn 1024 && hyperion-proxy
cargo watch -x 'build --release' -s 'touch {{project_root}}/.trigger'
cargo watch --postpone --no-vcs-ignores -w {{project_root}}/.trigger -s './target/release/infection -t'
RUN_MODE=release-{{arch}} cargo watch --postpone --no-vcs-ignores -w {{project_root}}/.trigger -s './target/release/infection -t'

# run a given number of bots to connect to hyperion
bots count='1000':
cargo install --git https://github.com/andrewgazelka/rust-mc-bot --branch optimize
cargo install -q --git https://github.com/andrewgazelka/rust-mc-bot --branch optimize
ulimit -Sn 1024 && rust-mc-bot 127.0.0.1:25566 {{count}}

# run in release mode with tracy
run:
cargo run --release -- -t
cargo run --release -- -t

0 comments on commit 50ee267

Please sign in to comment.