mirror of
https://github.com/horizon-rust/horizon.git
synced 2026-11-09 17:19:15 -10:00
Keep lan.rs and lan_actions.rs from growing under the current size check
main's check_file_size no longer counts test modules, so moving the two inline test modules out no longer offset the new sea_level lines; it added #[path] lines instead. The tests are back inline, and two self-contained functions move to child modules unchanged (pure moves): level_event_except to lan/level_event_targets.rs and horizon_channel to lan_actions/horizon_channels.rs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
134b443675
commit
ada4756065
6 files changed
+121
-109
No files matched your search
@@ -1,45 +0,0 @@
|
||||
/// Source controls for the bounded eligibility gates; these excluded
|
||||
/// guests are not counted as successfully saved players.
|
||||
#[test]
|
||||
#[ignore = "needs prepared resources and scratch homes/cwd"]
|
||||
fn excluded_guest_records_are_not_invented_or_written() {
|
||||
let mut game = super::super::native_machines::tests::server_game();
|
||||
let _rx = super::world_spawn_sync_tests::host_for(&mut game);
|
||||
game.world_root = std::env::current_dir().unwrap().join("stats-excluded");
|
||||
std::fs::create_dir_all(&game.world_root).unwrap();
|
||||
let path = super::super::stats::player_json(&game.world_root, "stats", [0, 0, 0, 1]);
|
||||
let mut host = game.lan.take().unwrap();
|
||||
host.play
|
||||
.entry(1)
|
||||
.or_default()
|
||||
.stats
|
||||
.add("used", "minecraft:diamond_sword", 1);
|
||||
host.hub.guests[0].placed = false;
|
||||
game.save_connected_guest_statistics(&host);
|
||||
assert!(!path.exists(), "not placed: no statistics file");
|
||||
host.hub.guests[0].placed = true;
|
||||
host.hub.guests[0].released = true;
|
||||
game.save_connected_guest_statistics(&host);
|
||||
assert!(!path.exists(), "released: no statistics file");
|
||||
host.hub.guests[0].released = false;
|
||||
let play = host.play.remove(&1).unwrap();
|
||||
game.save_connected_guest_statistics(&host);
|
||||
assert!(!path.exists(), "no play record: no invented statistics");
|
||||
host.play.insert(1, play);
|
||||
game.lan = Some(host);
|
||||
game.options.dedicated = None;
|
||||
game.save_game_metadata().unwrap();
|
||||
assert!(!path.exists(), "the existing dedicated gate is preserved");
|
||||
game.options.dedicated = Some(Vec::new());
|
||||
game.options.execution_role = super::super::execution_role::ExecutionRole::Client;
|
||||
game.save_game_metadata().unwrap();
|
||||
assert!(!path.exists(), "the existing nonclient gate is preserved");
|
||||
game.options.execution_role = super::super::execution_role::ExecutionRole::DedicatedServer;
|
||||
let host = game.lan.take().unwrap();
|
||||
game.save_game_metadata().unwrap();
|
||||
assert!(!path.exists(), "no hub: no substituted record");
|
||||
assert_eq!(
|
||||
host.play[&1].stats.get("used", "minecraft:diamond_sword"),
|
||||
1
|
||||
);
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
use super::horizon_channel;
|
||||
|
||||
#[test]
|
||||
fn horizon_channels_reach_their_handlers_and_others_go_to_the_mods() {
|
||||
// The recipe viewer's transfer (`native_transfer_recipe`) was handed to the mods
|
||||
// before its own arm could run, so a viewer's "+" never reached the server.
|
||||
assert!(horizon_channel(
|
||||
horizon_client::lan::recipes::TRANSFER_CHANNEL
|
||||
));
|
||||
assert!(horizon_channel(horizon_protocol::quiet::CHANNEL));
|
||||
assert!(horizon_channel(horizon_protocol::mod_net::CHANNEL));
|
||||
assert!(horizon_channel(horizon_client::lod_net::CHANNEL));
|
||||
assert!(!horizon_channel("mymod:hello"));
|
||||
assert!(!horizon_channel("minecraft:brand"));
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
//! tick and turns what the guests do into gameplay. A world that is not open
|
||||
//! costs one `Option` check per tick.
|
||||
mod event_timings;
|
||||
mod level_event_targets;
|
||||
|
||||
use super::{Game, shield::OFFHAND_SLOT};
|
||||
use event_timings::EventTimings;
|
||||
@@ -25,6 +26,7 @@ use horizon_protocol::{
|
||||
packets::play::{self, Clientbound as C},
|
||||
};
|
||||
use horizon_world::block_collision::BlockCollisionRegistry;
|
||||
use level_event_targets::level_event_except;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
sync::{Arc, Mutex},
|
||||
@@ -3522,39 +3524,6 @@ fn event_kind(event: &HostEvent) -> EventKind {
|
||||
}
|
||||
}
|
||||
|
||||
/// Who `ServerLevel.levelEvent` leaves out of the broadcast.
|
||||
///
|
||||
/// `LevelAccessor.levelEvent(int, BlockPos, int)` passes a null source, so the
|
||||
/// acting player is included. `ComposterBlock.useItemOn` (and the hopper input
|
||||
/// container) fill that way: event 1500, which the client turns into
|
||||
/// `handleFill` (the fill particles and `playLocalSound`). A call that names
|
||||
/// the player still excludes them. `collateral_break` is a later 2001 from
|
||||
/// `destroyBlock` with no player, after the breaker's own `playerWillDestroy`.
|
||||
fn level_event_except(id: i32, acting: Option<u32>, collateral_break: bool) -> Option<u32> {
|
||||
if matches!(
|
||||
id,
|
||||
2015 | 1500
|
||||
| 1501
|
||||
| 1503
|
||||
| 1505
|
||||
| 1026
|
||||
| 1027
|
||||
| 1029
|
||||
| 1030
|
||||
| 1045
|
||||
| 1052
|
||||
| 2019
|
||||
| 2020
|
||||
| 3000
|
||||
| 3008
|
||||
) || collateral_break
|
||||
{
|
||||
None
|
||||
} else {
|
||||
acting
|
||||
}
|
||||
}
|
||||
|
||||
/// Notes how long the event that started at `started` took (`spans::note`), with what it
|
||||
/// was about when [`Game::event_detail`] said.
|
||||
fn note_event(
|
||||
@@ -4919,8 +4888,54 @@ mod connected_statistics_save_tests {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "connected_statistics_save_exclusion_tests.rs"]
|
||||
mod connected_statistics_save_exclusion_tests;
|
||||
mod connected_statistics_save_exclusion_tests {
|
||||
|
||||
/// Source controls for the bounded eligibility gates; these excluded
|
||||
/// guests are not counted as successfully saved players.
|
||||
#[test]
|
||||
#[ignore = "needs prepared resources and scratch homes/cwd"]
|
||||
fn excluded_guest_records_are_not_invented_or_written() {
|
||||
let mut game = super::super::native_machines::tests::server_game();
|
||||
let _rx = super::world_spawn_sync_tests::host_for(&mut game);
|
||||
game.world_root = std::env::current_dir().unwrap().join("stats-excluded");
|
||||
std::fs::create_dir_all(&game.world_root).unwrap();
|
||||
let path = super::super::stats::player_json(&game.world_root, "stats", [0, 0, 0, 1]);
|
||||
let mut host = game.lan.take().unwrap();
|
||||
host.play
|
||||
.entry(1)
|
||||
.or_default()
|
||||
.stats
|
||||
.add("used", "minecraft:diamond_sword", 1);
|
||||
host.hub.guests[0].placed = false;
|
||||
game.save_connected_guest_statistics(&host);
|
||||
assert!(!path.exists(), "not placed: no statistics file");
|
||||
host.hub.guests[0].placed = true;
|
||||
host.hub.guests[0].released = true;
|
||||
game.save_connected_guest_statistics(&host);
|
||||
assert!(!path.exists(), "released: no statistics file");
|
||||
host.hub.guests[0].released = false;
|
||||
let play = host.play.remove(&1).unwrap();
|
||||
game.save_connected_guest_statistics(&host);
|
||||
assert!(!path.exists(), "no play record: no invented statistics");
|
||||
host.play.insert(1, play);
|
||||
game.lan = Some(host);
|
||||
game.options.dedicated = None;
|
||||
game.save_game_metadata().unwrap();
|
||||
assert!(!path.exists(), "the existing dedicated gate is preserved");
|
||||
game.options.dedicated = Some(Vec::new());
|
||||
game.options.execution_role = super::super::execution_role::ExecutionRole::Client;
|
||||
game.save_game_metadata().unwrap();
|
||||
assert!(!path.exists(), "the existing nonclient gate is preserved");
|
||||
game.options.execution_role = super::super::execution_role::ExecutionRole::DedicatedServer;
|
||||
let host = game.lan.take().unwrap();
|
||||
game.save_game_metadata().unwrap();
|
||||
assert!(!path.exists(), "no hub: no substituted record");
|
||||
assert_eq!(
|
||||
host.play[&1].stats.get("used", "minecraft:diamond_sword"),
|
||||
1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
use super::stats;
|
||||
mod advancement_records;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
//! Who a level event broadcast leaves out.
|
||||
|
||||
/// Who `ServerLevel.levelEvent` leaves out of the broadcast.
|
||||
///
|
||||
/// `LevelAccessor.levelEvent(int, BlockPos, int)` passes a null source, so the
|
||||
/// acting player is included. `ComposterBlock.useItemOn` (and the hopper input
|
||||
/// container) fill that way: event 1500, which the client turns into
|
||||
/// `handleFill` (the fill particles and `playLocalSound`). A call that names
|
||||
/// the player still excludes them. `collateral_break` is a later 2001 from
|
||||
/// `destroyBlock` with no player, after the breaker's own `playerWillDestroy`.
|
||||
pub(super) fn level_event_except(
|
||||
id: i32,
|
||||
acting: Option<u32>,
|
||||
collateral_break: bool,
|
||||
) -> Option<u32> {
|
||||
if matches!(
|
||||
id,
|
||||
2015 | 1500
|
||||
| 1501
|
||||
| 1503
|
||||
| 1505
|
||||
| 1026
|
||||
| 1027
|
||||
| 1029
|
||||
| 1030
|
||||
| 1045
|
||||
| 1052
|
||||
| 2019
|
||||
| 2020
|
||||
| 3000
|
||||
| 3008
|
||||
) || collateral_break
|
||||
{
|
||||
None
|
||||
} else {
|
||||
acting
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,9 @@ use horizon_protocol::{
|
||||
use horizon_world::entity_move::EntityMoveWorld;
|
||||
use winit::keyboard::KeyCode;
|
||||
|
||||
mod horizon_channels;
|
||||
use horizon_channels::horizon_channel;
|
||||
|
||||
#[cfg(test)]
|
||||
mod crack_feedback_tests;
|
||||
|
||||
@@ -6956,21 +6959,24 @@ mod guest_close_listener_tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a guest's plugin channel message is for one of Horizon's own handlers in
|
||||
/// `lan_guest_packet` (its `CustomPayload` arms), not for the mods.
|
||||
fn horizon_channel(channel: &str) -> bool {
|
||||
[
|
||||
horizon_protocol::quiet::CHANNEL,
|
||||
horizon_protocol::mod_net::CHANNEL,
|
||||
horizon_client::lod_net::CHANNEL,
|
||||
horizon_client::lan::recipes::TRANSFER_CHANNEL,
|
||||
]
|
||||
.contains(&channel)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "horizon_channel_tests.rs"]
|
||||
mod horizon_channel_tests;
|
||||
mod horizon_channel_tests {
|
||||
use super::horizon_channel;
|
||||
|
||||
#[test]
|
||||
fn horizon_channels_reach_their_handlers_and_others_go_to_the_mods() {
|
||||
// The recipe viewer's transfer (`native_transfer_recipe`) was handed to the mods
|
||||
// before its own arm could run, so a viewer's "+" never reached the server.
|
||||
assert!(horizon_channel(
|
||||
horizon_client::lan::recipes::TRANSFER_CHANNEL
|
||||
));
|
||||
assert!(horizon_channel(horizon_protocol::quiet::CHANNEL));
|
||||
assert!(horizon_channel(horizon_protocol::mod_net::CHANNEL));
|
||||
assert!(horizon_channel(horizon_client::lod_net::CHANNEL));
|
||||
assert!(!horizon_channel("mymod:hello"));
|
||||
assert!(!horizon_channel("minecraft:brand"));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "boat_holder_movement_tests.rs"]
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
//! The plugin channels Horizon handles itself, before the mods.
|
||||
|
||||
/// Whether a guest's plugin channel message is for one of Horizon's own handlers in
|
||||
/// `lan_guest_packet` (its `CustomPayload` arms), not for the mods.
|
||||
pub(super) fn horizon_channel(channel: &str) -> bool {
|
||||
[
|
||||
horizon_protocol::quiet::CHANNEL,
|
||||
horizon_protocol::mod_net::CHANNEL,
|
||||
horizon_client::lod_net::CHANNEL,
|
||||
horizon_client::lan::recipes::TRANSFER_CHANNEL,
|
||||
]
|
||||
.contains(&channel)
|
||||
}
|
||||
Reference in new issue
Block a user