Add host-privileges toggle
This commit is contained in:
parent
30b64ab475
commit
abc89c1e3e
@ -175,6 +175,7 @@ pub struct Game {
|
||||
pub private_opts: PrivateGameOptions,
|
||||
|
||||
is_host: bool,
|
||||
host_privileges: bool,
|
||||
player_counter: u16,
|
||||
pub self_id: Option<u16>,
|
||||
pub players: Vec<Player>,
|
||||
@ -351,6 +352,10 @@ impl Game {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_host_privileges(&mut self, privileges: bool) {
|
||||
self.host_privileges = privileges;
|
||||
}
|
||||
|
||||
pub fn start_playback(&mut self, time_delta: f64, spectated_id: u16) {
|
||||
if let Some(recorder) = &self.replay_recorder
|
||||
&& self.self_id.is_some()
|
||||
@ -618,7 +623,13 @@ impl Game {
|
||||
self.self_id = Some(id);
|
||||
}
|
||||
|
||||
pub fn new_player(&mut self, addr: SocketAddr, name: Option<String>, id: Option<u16>) -> u16 {
|
||||
pub fn new_player(
|
||||
&mut self,
|
||||
addr: SocketAddr,
|
||||
name: Option<String>,
|
||||
id: Option<u16>,
|
||||
host_privileges: bool,
|
||||
) -> u16 {
|
||||
let id = if let Some(id) = id {
|
||||
id
|
||||
} else {
|
||||
@ -641,6 +652,7 @@ impl Game {
|
||||
character: None,
|
||||
last_held_weapon: WeaponType::Raygun,
|
||||
last_position: Vector3::ZERO,
|
||||
has_host_privileges: host_privileges,
|
||||
});
|
||||
self.run_deferred(move |s| s.signals().on_new_player().emit(id));
|
||||
|
||||
@ -1628,6 +1640,7 @@ pub struct Player {
|
||||
pub killing_spree_cd: f64,
|
||||
pub last_held_weapon: WeaponType,
|
||||
pub last_position: Vector3,
|
||||
pub has_host_privileges: bool,
|
||||
}
|
||||
|
||||
impl Player {
|
||||
@ -1814,6 +1827,7 @@ impl From<NetPlayer> for Player {
|
||||
killing_spree_cd: 0.,
|
||||
last_held_weapon: WeaponType::Raygun,
|
||||
last_position: Vector3::ZERO,
|
||||
has_host_privileges: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -223,6 +223,7 @@ impl NetworkManager {
|
||||
SocketAddr::from(([0, 0, 0, 0], 0)),
|
||||
Some(default_name),
|
||||
None,
|
||||
true,
|
||||
);
|
||||
game.bind_mut().update_player_ready(id, true);
|
||||
game.bind_mut().set_self(id);
|
||||
@ -350,7 +351,7 @@ pub enum Package {
|
||||
Hello,
|
||||
|
||||
// Meta values
|
||||
Players(Vec<NetPlayer>, u16),
|
||||
Players(Vec<NetPlayer>, u16, bool),
|
||||
UpdatePings(HashMap<u16, u128>),
|
||||
SetNick(u16, String),
|
||||
SetSelfNick(String),
|
||||
|
||||
@ -95,13 +95,17 @@ impl NetworkManager {
|
||||
cli.bind_mut()
|
||||
.publish_message(format!("Got \"Hello\"!"), CliColor::Info);
|
||||
}
|
||||
Package::Players(players, self_id) => {
|
||||
Package::Players(players, self_id, host_privileges) => {
|
||||
cli.bind_mut()
|
||||
.publish_message(format!("Got players"), CliColor::Info);
|
||||
if let Some(game) = &mut Game::singleton() {
|
||||
game.bind_mut().set_players(
|
||||
players.into_iter().map(|p| p.clone().into()).collect(),
|
||||
);
|
||||
if host_privileges {
|
||||
game.bind_mut().set_host_privileges(true);
|
||||
}
|
||||
|
||||
game.bind_mut().set_self(self_id);
|
||||
}
|
||||
}
|
||||
@ -129,6 +133,7 @@ impl NetworkManager {
|
||||
SocketAddr::from(([0, 0, 0, 0], 0)),
|
||||
Some(player.name),
|
||||
Some(player.id),
|
||||
false,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -321,8 +326,13 @@ impl NetworkManager {
|
||||
);
|
||||
|
||||
if let Some(game) = &mut Game::singleton() {
|
||||
let self_id =
|
||||
game.bind_mut().new_player(connection.address, None, None);
|
||||
let is_first = game.bind().players.is_empty();
|
||||
let self_id = game.bind_mut().new_player(
|
||||
connection.address,
|
||||
None,
|
||||
None,
|
||||
is_first,
|
||||
);
|
||||
peer.send_reliable(
|
||||
&connection.address,
|
||||
Package::Players(
|
||||
@ -333,6 +343,7 @@ impl NetworkManager {
|
||||
.map(|p| p.into())
|
||||
.collect(),
|
||||
self_id,
|
||||
is_first,
|
||||
),
|
||||
);
|
||||
peer.send_reliable(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user