Allow headless hosting via cli

This commit is contained in:
Sofia 2026-08-14 22:05:55 +03:00
parent c910946151
commit 791c879a13
4 changed files with 16 additions and 7 deletions

View File

@ -88,7 +88,7 @@ impl INode3D for CliParser {
.connect_other(self, |s| s.on_join_lobby());
if let Some(port) = options.host {
NetworkManager::singleton().bind_mut().host(port);
NetworkManager::singleton().bind_mut().host(port, false);
} else if let Some(addr) = options.join {
NetworkManager::singleton().bind_mut().join_directly(addr);
}

View File

@ -62,7 +62,7 @@ impl INode for NetworkManager {
cli.bind_mut()
.signals()
.on_host()
.connect_other(self, |s, port| s.host(port));
.connect_other(self, |s, port, headless| s.host(port, headless));
cli.bind_mut()
.signals()
.on_join()
@ -188,7 +188,7 @@ impl NetworkManager {
}
}
pub fn host(&mut self, port: u16) {
pub fn host(&mut self, port: u16, headless: bool) {
if self.peer.is_none() {
let mut cli = CommandLinePanel::singleton();
cli.bind_mut()
@ -216,7 +216,9 @@ impl NetworkManager {
.default_name
.clone();
if let Some(game) = &mut Game::singleton() {
if let Some(game) = &mut Game::singleton()
&& !headless
{
let id = game.bind_mut().new_player(
SocketAddr::from(([0, 0, 0, 0], 0)),
Some(default_name),

View File

@ -128,7 +128,7 @@ impl IPanel for CommandLinePanel {
#[godot_api]
impl CommandLinePanel {
#[signal]
pub fn on_host(port: u16);
pub fn on_host(port: u16, headless: bool);
#[signal]
pub fn on_join(port: String);
#[signal]
@ -223,7 +223,14 @@ impl Command for HostCommand {
fn execute(&self, cli: &mut CommandLinePanel, params: &[&str]) {
if let Some(port_str) = params.first() {
if let Ok(port) = u16::from_str_radix(*port_str, 10) {
cli.signals().on_host().emit(port);
let headless = if let Some(param) = params.get(1)
&& *param == "--headless"
{
true
} else {
false
};
cli.signals().on_host().emit(port, headless);
} else {
cli.publish_message(format!("Invalid port: {}", port_str), CliColor::Error);
}

View File

@ -211,7 +211,7 @@ impl MainMenu {
if let Some(host_port) = &self.host_port {
NetworkManager::singleton()
.bind_mut()
.host(host_port.get_value() as u16);
.host(host_port.get_value() as u16, false);
}
}