Make finishing game possible from client with host privileges
This commit is contained in:
parent
3a0eaa58be
commit
42438914e1
@ -497,6 +497,10 @@ impl Game {
|
||||
}
|
||||
|
||||
pub fn finish_game(&mut self) {
|
||||
if !self.game_started {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(recorder) = &mut self.replay_recorder {
|
||||
recorder.bind_mut().stop_recording();
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use godot::obj::Singleton;
|
||||
use godot::{global::godot_print, obj::Singleton};
|
||||
use teanet::PeerMessage;
|
||||
|
||||
use crate::{
|
||||
@ -595,6 +595,18 @@ impl NetworkManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
Package::FinishGame => {
|
||||
if let Some(game) = &mut Game::singleton() {
|
||||
let player =
|
||||
game.bind().find_player_by_addr(&conn.address).cloned();
|
||||
if let Some(player) = player
|
||||
&& player.has_host_privileges
|
||||
{
|
||||
godot_print!("Finishing game");
|
||||
game.bind_mut().finish_game();
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
},
|
||||
|
||||
@ -871,7 +871,14 @@ impl LocalPlayer {
|
||||
#[func]
|
||||
pub fn exit_to_lobby(&mut self) {
|
||||
if let Some(game) = &mut Game::singleton() {
|
||||
game.bind_mut().finish_game();
|
||||
if let Some(peer) = &mut NetworkManager::singleton().bind_mut().peer {
|
||||
match peer {
|
||||
PeerKind::Client(peer, socket_addr) => {
|
||||
peer.send_reliable(socket_addr, Package::FinishGame);
|
||||
}
|
||||
PeerKind::Server(..) => game.bind_mut().finish_game(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -43,8 +43,10 @@ pub struct Hud {
|
||||
impl IControl for Hud {
|
||||
fn ready(&mut self) {
|
||||
self.run_deferred(|s| {
|
||||
if let Some(exit_to_lobby) = &mut s.exit_to_lobby {
|
||||
exit_to_lobby.set_visible(NetworkManager::singleton().bind().is_host());
|
||||
if let Some(exit_to_lobby) = &mut s.exit_to_lobby
|
||||
&& let Some(game) = &Game::singleton()
|
||||
{
|
||||
exit_to_lobby.set_visible(game.bind().has_host_privileges());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user