352 |
352 |
353 pub fn handle_client_accept( |
353 pub fn handle_client_accept( |
354 server: &mut HwServer, |
354 server: &mut HwServer, |
355 client_id: ClientId, |
355 client_id: ClientId, |
356 response: &mut Response, |
356 response: &mut Response, |
|
357 addr: [u8; 4], |
357 is_local: bool, |
358 is_local: bool, |
358 ) { |
359 ) { |
359 let mut salt = [0u8; 18]; |
360 let ban_reason = Some(addr) |
360 thread_rng().fill_bytes(&mut salt); |
361 .filter(|_| !is_local) |
361 |
362 .and_then(|a| server.anteroom.find_ip_ban(a)); |
362 server |
363 if let Some(reason) = ban_reason { |
363 .anteroom |
364 response.add(HwServerMessage::Bye(reason).send_self()); |
364 .add_client(client_id, encode(&salt), is_local); |
365 response.remove_client(client_id); |
365 |
366 } else { |
366 response.add(HwServerMessage::Connected(utils::SERVER_VERSION).send_self()); |
367 let mut salt = [0u8; 18]; |
|
368 thread_rng().fill_bytes(&mut salt); |
|
369 |
|
370 server |
|
371 .anteroom |
|
372 .add_client(client_id, encode(&salt), is_local); |
|
373 |
|
374 response.add(HwServerMessage::Connected(utils::SERVER_VERSION).send_self()); |
|
375 } |
367 } |
376 } |
368 |
377 |
369 pub fn handle_client_loss(server: &mut HwServer, client_id: ClientId, response: &mut Response) { |
378 pub fn handle_client_loss(server: &mut HwServer, client_id: ClientId, response: &mut Response) { |
370 if server.anteroom.remove_client(client_id).is_none() { |
379 if server.anteroom.remove_client(client_id).is_none() { |
371 common::remove_client(server, response, "Connection reset".to_string()); |
380 common::remove_client(server, response, "Connection reset".to_string()); |