mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-10-26 14:00:22 +00:00
cpu usage finally fixed
This commit is contained in:
1 parent
6c2b131d72
commit
a61554187e
3 files changed
+19
-9
No files matched your search
+2
-2
@@ -10,8 +10,8 @@ mod heartbeat;
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn 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::max()).init();
|
||||||
// pretty_env_logger::formatted_timed_builder().filter_level(log::LevelFilter::Info).init();
|
pretty_env_logger::formatted_timed_builder().filter_level(log::LevelFilter::Debug).init();
|
||||||
|
|
||||||
let mut user_config: config::Config = toml::from_str(
|
let mut user_config: config::Config = toml::from_str(
|
||||||
&std::fs::read_to_string("ServerConfig.toml")
|
&std::fs::read_to_string("ServerConfig.toml")
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ use super::packet::*;
|
|||||||
static ATOMIC_ID_COUNTER: AtomicU8 = AtomicU8::new(0);
|
static ATOMIC_ID_COUNTER: AtomicU8 = AtomicU8::new(0);
|
||||||
|
|
||||||
lazy_static! {
|
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)]
|
#[derive(PartialEq)]
|
||||||
@@ -170,10 +170,12 @@ impl Client {
|
|||||||
if packet.data.len() == 0 {
|
if packet.data.len() == 0 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if packet.data.len() == 4 {
|
if (packet.data.len() == 4 && packet.data == [68, 111, 110, 101]) || packet.data.len() == 0 {
|
||||||
if packet.data == [68, 111, 110, 101] {
|
{
|
||||||
break 'syncing;
|
let mut lock = CLIENT_MOD_PROGRESS.lock().await;
|
||||||
|
lock.insert(self.id, -1);
|
||||||
}
|
}
|
||||||
|
break 'syncing;
|
||||||
}
|
}
|
||||||
match packet.data[0] as char {
|
match packet.data[0] as char {
|
||||||
'S' if packet.data.len() > 1 => match packet.data[1] 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;
|
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),
|
_ => error!("Unknown packet! {:?}", packet),
|
||||||
|
|||||||
+10
-2
@@ -233,11 +233,14 @@ impl Server {
|
|||||||
if sent_mods.contains(&mod_id) { continue; }
|
if sent_mods.contains(&mod_id) { continue; }
|
||||||
debug!("[D] Starting download!");
|
debug!("[D] Starting download!");
|
||||||
let mut mod_name = {
|
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;
|
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);
|
debug!("[D] Mod name: {}", bmod.0);
|
||||||
|
|
||||||
bmod.0.clone()
|
bmod.0.clone()
|
||||||
@@ -528,6 +531,11 @@ impl Server {
|
|||||||
plugin.send_event(PluginBoundPluginEvent::CallEventHandler((ScriptEvent::OnPlayerDisconnect { pid: id, name: name.clone() }, None))).await;
|
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);
|
info!("Disconnecting client {}...", id);
|
||||||
if i == self.clients.len() - 1 {
|
if i == self.clients.len() - 1 {
|
||||||
self.clients.remove(i);
|
self.clients.remove(i);
|
||||||
|
|||||||
Reference in new issue
Block a user