Replicate Sounds (#68)
This commit is contained in:
@@ -21,11 +21,15 @@ use shared::{
|
||||
control::ControlState,
|
||||
global_observer,
|
||||
player::Player,
|
||||
protocol::{DespawnTbMapEntity, TbMapEntityId, TbMapEntityMapping},
|
||||
protocol::{
|
||||
ClientEnteredPlaying, TbMapEntityId, TbMapEntityMapping,
|
||||
channels::UnorderedReliableChannel, messages::DespawnTbMapEntity,
|
||||
},
|
||||
tb_entities::{Platform, PlatformTarget},
|
||||
};
|
||||
use std::{
|
||||
env::current_exe,
|
||||
fs::File,
|
||||
io::{BufRead, BufReader},
|
||||
net::{IpAddr, Ipv4Addr, SocketAddr},
|
||||
process::Stdio,
|
||||
@@ -43,7 +47,7 @@ pub fn plugin(app: &mut App) {
|
||||
parse_local_server_stdout.run_if(resource_exists::<LocalServerStdout>),
|
||||
);
|
||||
app.add_systems(Last, close_server_processes);
|
||||
app.add_systems(FixedUpdate, despawn_absent_map_entities);
|
||||
app.add_systems(Update, despawn_absent_map_entities);
|
||||
|
||||
global_observer!(app, on_connecting);
|
||||
global_observer!(app, on_connection_failed);
|
||||
@@ -124,9 +128,11 @@ fn on_connection_succeeded(
|
||||
_trigger: Trigger<OnAdd, Connected>,
|
||||
state: Res<State<GameState>>,
|
||||
mut change_state: ResMut<NextState<GameState>>,
|
||||
mut sender: Single<&mut TriggerSender<ClientEnteredPlaying>>,
|
||||
) {
|
||||
if *state == GameState::Connecting {
|
||||
change_state.set(GameState::Playing);
|
||||
sender.trigger::<UnorderedReliableChannel>(ClientEnteredPlaying);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +154,7 @@ fn on_connection_failed(
|
||||
mut commands: Commands,
|
||||
client_active: Query<&ClientActive>,
|
||||
mut opened_server: Local<bool>,
|
||||
) {
|
||||
) -> Result {
|
||||
let disconnected = disconnected.get(trigger.target()).unwrap();
|
||||
if *opened_server {
|
||||
panic!(
|
||||
@@ -164,11 +170,13 @@ fn on_connection_failed(
|
||||
// the server executable is assumed to be adjacent to the client executable
|
||||
let mut exe_path = current_exe().expect("failed to get path of client executable");
|
||||
exe_path.set_file_name("server");
|
||||
let server_log_file = File::create("server.log")?;
|
||||
let mut server_process = std::process::Command::new(exe_path)
|
||||
.args(["--timeout", "60", "--close-on-client-disconnect"])
|
||||
.env("NO_COLOR", "1")
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::null())
|
||||
.stderr(server_log_file)
|
||||
.spawn()
|
||||
.expect("failed to start server");
|
||||
let server_stdout = server_process.stdout.take().unwrap();
|
||||
@@ -195,6 +203,8 @@ fn on_connection_failed(
|
||||
|
||||
*opened_server = true;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Event)]
|
||||
@@ -206,6 +216,8 @@ fn parse_local_server_stdout(mut commands: Commands, mut stdout: ResMut<LocalSer
|
||||
while let Ok(line) = stdout.0.get().try_recv() {
|
||||
if let "hedz.server_started" = &line[..] {
|
||||
commands.trigger(LocalServerStarted);
|
||||
} else {
|
||||
info!("SERVER: {line}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user