Skip to content

Commit

Permalink
fix(server): hoster not identified as server
Browse files Browse the repository at this point in the history
  • Loading branch information
Sequal32 committed Dec 27, 2022
1 parent 1e4985c commit d464374
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/yourcontrols-server/src/hoster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn process_payload(
Payloads::PlayerJoined {
name: name.clone(),
in_control: state.in_control == *name,
is_server: false,
is_server: info.is_host,
is_observer: info.is_observer,
},
addr,
Expand All @@ -101,13 +101,7 @@ fn process_payload(
}

// Add client
state.clients.insert(
name.clone(),
Client {
addr,
is_observer: false,
},
);
state.clients.insert(name.clone(), Client::new(addr));

// If the client is the first one to connect, give them control and have them "host"
if state.in_control == SERVER_NAME {
Expand Down Expand Up @@ -174,6 +168,7 @@ fn process_payload(
fn set_host(name: String, state: &mut ServerState, net: &mut SenderReceiver) {
let client = state.clients.get_mut(&name).expect("always there");
client.is_observer = false;
client.is_host = true;

net.send_message(Payloads::SetHost, client.addr).ok();
send_to_all(
Expand Down
11 changes: 11 additions & 0 deletions src/yourcontrols-server/src/servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ use crate::util::{get_random_id, SESSION_ID_LENGTH};
pub struct Client {
pub addr: SocketAddr,
pub is_observer: bool,
pub is_host: bool,
}

impl Client {
pub fn new(addr: SocketAddr) -> Self {
Self {
addr,
is_observer: false,
is_host: false,
}
}
}

pub struct ServerState {
Expand Down

0 comments on commit d464374

Please sign in to comment.