mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-06 07:46:06 +00:00
small improvements + players cmd + cleanup
This commit is contained in:
@@ -24,17 +24,17 @@ use super::car::*;
|
||||
use super::packet::*;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref TAKEN_PLAYER_IDS: Mutex<[bool;256]> = Mutex::new([false; 256]);
|
||||
pub static ref TAKEN_PLAYER_IDS: Mutex<Vec<u8>> = Mutex::new(Vec::new());
|
||||
pub static ref CLIENT_MOD_PROGRESS: Mutex<HashMap<u8, isize>> = Mutex::new(HashMap::new());
|
||||
}
|
||||
|
||||
// TODO: Return a proper error?
|
||||
async fn claim_id() -> Result<u8, ()> {
|
||||
let mut lock = TAKEN_PLAYER_IDS.lock().await;
|
||||
for index in 0..255 {
|
||||
if !lock[index] {
|
||||
lock[index] = true;
|
||||
return Ok(index as u8);
|
||||
for index in 0..=255 {
|
||||
if !lock.contains(&index) {
|
||||
lock.push(index);
|
||||
return Ok(index);
|
||||
}
|
||||
}
|
||||
// requires more then 255 players on the server to error
|
||||
@@ -43,7 +43,7 @@ async fn claim_id() -> Result<u8, ()> {
|
||||
|
||||
async fn free_id(id: u8) {
|
||||
let mut lock = TAKEN_PLAYER_IDS.lock().await;
|
||||
lock[id as usize] = false;
|
||||
*lock = lock.drain(..).filter(|i| *i != id).collect::<Vec<u8>>();
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
|
||||
@@ -288,7 +288,6 @@ impl Server {
|
||||
}
|
||||
|
||||
if set.is_empty() == false {
|
||||
info!("what!");
|
||||
// Because join_next() is cancel safe, we can simply cancel it after N duration
|
||||
// so at worst this client acceptance loop blocks for N duration
|
||||
tokio::select! {
|
||||
|
||||
Reference in New Issue
Block a user