Allow headless hosting via cli
This commit is contained in:
parent
c910946151
commit
791c879a13
@ -88,7 +88,7 @@ impl INode3D for CliParser {
|
|||||||
.connect_other(self, |s| s.on_join_lobby());
|
.connect_other(self, |s| s.on_join_lobby());
|
||||||
|
|
||||||
if let Some(port) = options.host {
|
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 {
|
} else if let Some(addr) = options.join {
|
||||||
NetworkManager::singleton().bind_mut().join_directly(addr);
|
NetworkManager::singleton().bind_mut().join_directly(addr);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -62,7 +62,7 @@ impl INode for NetworkManager {
|
|||||||
cli.bind_mut()
|
cli.bind_mut()
|
||||||
.signals()
|
.signals()
|
||||||
.on_host()
|
.on_host()
|
||||||
.connect_other(self, |s, port| s.host(port));
|
.connect_other(self, |s, port, headless| s.host(port, headless));
|
||||||
cli.bind_mut()
|
cli.bind_mut()
|
||||||
.signals()
|
.signals()
|
||||||
.on_join()
|
.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() {
|
if self.peer.is_none() {
|
||||||
let mut cli = CommandLinePanel::singleton();
|
let mut cli = CommandLinePanel::singleton();
|
||||||
cli.bind_mut()
|
cli.bind_mut()
|
||||||
@ -216,7 +216,9 @@ impl NetworkManager {
|
|||||||
.default_name
|
.default_name
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
if let Some(game) = &mut Game::singleton() {
|
if let Some(game) = &mut Game::singleton()
|
||||||
|
&& !headless
|
||||||
|
{
|
||||||
let id = game.bind_mut().new_player(
|
let id = game.bind_mut().new_player(
|
||||||
SocketAddr::from(([0, 0, 0, 0], 0)),
|
SocketAddr::from(([0, 0, 0, 0], 0)),
|
||||||
Some(default_name),
|
Some(default_name),
|
||||||
|
|||||||
@ -128,7 +128,7 @@ impl IPanel for CommandLinePanel {
|
|||||||
#[godot_api]
|
#[godot_api]
|
||||||
impl CommandLinePanel {
|
impl CommandLinePanel {
|
||||||
#[signal]
|
#[signal]
|
||||||
pub fn on_host(port: u16);
|
pub fn on_host(port: u16, headless: bool);
|
||||||
#[signal]
|
#[signal]
|
||||||
pub fn on_join(port: String);
|
pub fn on_join(port: String);
|
||||||
#[signal]
|
#[signal]
|
||||||
@ -223,7 +223,14 @@ impl Command for HostCommand {
|
|||||||
fn execute(&self, cli: &mut CommandLinePanel, params: &[&str]) {
|
fn execute(&self, cli: &mut CommandLinePanel, params: &[&str]) {
|
||||||
if let Some(port_str) = params.first() {
|
if let Some(port_str) = params.first() {
|
||||||
if let Ok(port) = u16::from_str_radix(*port_str, 10) {
|
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 {
|
} else {
|
||||||
cli.publish_message(format!("Invalid port: {}", port_str), CliColor::Error);
|
cli.publish_message(format!("Invalid port: {}", port_str), CliColor::Error);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -211,7 +211,7 @@ impl MainMenu {
|
|||||||
if let Some(host_port) = &self.host_port {
|
if let Some(host_port) = &self.host_port {
|
||||||
NetworkManager::singleton()
|
NetworkManager::singleton()
|
||||||
.bind_mut()
|
.bind_mut()
|
||||||
.host(host_port.get_value() as u16);
|
.host(host_port.get_value() as u16, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user