mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-08 16:56:08 +00:00
cpu usage finally fixed
This commit is contained in:
@@ -10,8 +10,8 @@ mod heartbeat;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
pretty_env_logger::formatted_timed_builder().filter_level(log::LevelFilter::max()).init();
|
||||
// pretty_env_logger::formatted_timed_builder().filter_level(log::LevelFilter::Info).init();
|
||||
// pretty_env_logger::formatted_timed_builder().filter_level(log::LevelFilter::max()).init();
|
||||
pretty_env_logger::formatted_timed_builder().filter_level(log::LevelFilter::Debug).init();
|
||||
|
||||
let mut user_config: config::Config = toml::from_str(
|
||||
&std::fs::read_to_string("ServerConfig.toml")
|
||||
|
||||
@@ -26,7 +26,7 @@ use super::packet::*;
|
||||
static ATOMIC_ID_COUNTER: AtomicU8 = AtomicU8::new(0);
|
||||
|
||||
lazy_static! {
|
||||
pub static ref CLIENT_MOD_PROGRESS: Mutex<HashMap<u8, usize>> = Mutex::new(HashMap::new());
|
||||
pub static ref CLIENT_MOD_PROGRESS: Mutex<HashMap<u8, isize>> = Mutex::new(HashMap::new());
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
@@ -170,10 +170,12 @@ impl Client {
|
||||
if packet.data.len() == 0 {
|
||||
continue;
|
||||
}
|
||||
if packet.data.len() == 4 {
|
||||
if packet.data == [68, 111, 110, 101] {
|
||||
break 'syncing;
|
||||
if (packet.data.len() == 4 && packet.data == [68, 111, 110, 101]) || packet.data.len() == 0 {
|
||||
{
|
||||
let mut lock = CLIENT_MOD_PROGRESS.lock().await;
|
||||
lock.insert(self.id, -1);
|
||||
}
|
||||
break 'syncing;
|
||||
}
|
||||
match packet.data[0] as char {
|
||||
'S' if packet.data.len() > 1 => match packet.data[1] as char {
|
||||
@@ -237,7 +239,7 @@ impl Client {
|
||||
|
||||
{
|
||||
let mut lock = CLIENT_MOD_PROGRESS.lock().await;
|
||||
lock.insert(self.id, mod_id);
|
||||
lock.insert(self.id, mod_id as isize);
|
||||
}
|
||||
}
|
||||
_ => error!("Unknown packet! {:?}", packet),
|
||||
|
||||
@@ -233,11 +233,14 @@ impl Server {
|
||||
if sent_mods.contains(&mod_id) { continue; }
|
||||
debug!("[D] Starting download!");
|
||||
let mut mod_name = {
|
||||
if mod_id >= cfg_ref.mods.len() {
|
||||
if mod_id < 0 {
|
||||
break 'download;
|
||||
}
|
||||
if mod_id as usize >= cfg_ref.mods.len() {
|
||||
break 'download;
|
||||
}
|
||||
|
||||
let bmod = &cfg_ref.mods[mod_id]; // TODO: This is a bit uhh yeah
|
||||
let bmod = &cfg_ref.mods[mod_id as usize]; // TODO: This is a bit uhh yeah
|
||||
debug!("[D] Mod name: {}", bmod.0);
|
||||
|
||||
bmod.0.clone()
|
||||
@@ -528,6 +531,11 @@ impl Server {
|
||||
plugin.send_event(PluginBoundPluginEvent::CallEventHandler((ScriptEvent::OnPlayerDisconnect { pid: id, name: name.clone() }, None))).await;
|
||||
}
|
||||
|
||||
{
|
||||
let mut lock = CLIENT_MOD_PROGRESS.lock().await;
|
||||
lock.insert(id, -1);
|
||||
}
|
||||
|
||||
info!("Disconnecting client {}...", id);
|
||||
if i == self.clients.len() - 1 {
|
||||
self.clients.remove(i);
|
||||
|
||||
Reference in New Issue
Block a user