mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-03 16:25:35 +00:00
Merge pull request #8 from OfficialLambdax/mod-request-check
Mod request check + ui toggle
This commit is contained in:
commit
669e061fdf
15
src/main.rs
15
src/main.rs
@ -11,11 +11,16 @@ mod server;
|
|||||||
mod config;
|
mod config;
|
||||||
mod heartbeat;
|
mod heartbeat;
|
||||||
|
|
||||||
|
const USE_TUI_CONSOLE_UI: bool = true; // true = uses tui.rs. false = uses pretty_env_logger (useful when developing)
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
// pretty_env_logger::formatted_timed_builder().filter_level(log::LevelFilter::max()).init();
|
if USE_TUI_CONSOLE_UI {
|
||||||
// pretty_env_logger::formatted_timed_builder().filter_level(log::LevelFilter::Debug).init();
|
logger::init(log::LevelFilter::max()).expect("Failed to enable logger!");
|
||||||
logger::init(log::LevelFilter::max()).expect("Failed to enable logger!");
|
} else {
|
||||||
|
// 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(
|
let mut user_config: config::Config = toml::from_str(
|
||||||
&std::fs::read_to_string("ServerConfig.toml")
|
&std::fs::read_to_string("ServerConfig.toml")
|
||||||
@ -48,7 +53,9 @@ async fn main() {
|
|||||||
|
|
||||||
let (cmd_tx, cmd_rx) = mpsc::channel(100);
|
let (cmd_tx, cmd_rx) = mpsc::channel(100);
|
||||||
|
|
||||||
tokio::spawn(tui::tui_main(user_config.clone(), cmd_tx));
|
if USE_TUI_CONSOLE_UI {
|
||||||
|
tokio::spawn(tui::tui_main(user_config.clone(), cmd_tx));
|
||||||
|
}
|
||||||
|
|
||||||
server_main(user_config, cmd_rx).await;
|
server_main(user_config, cmd_rx).await;
|
||||||
}
|
}
|
||||||
|
@ -206,13 +206,25 @@ impl Client {
|
|||||||
mod_name.remove(0); // Remove f
|
mod_name.remove(0); // Remove f
|
||||||
debug!("Client requested file {}", mod_name);
|
debug!("Client requested file {}", mod_name);
|
||||||
|
|
||||||
self.write_packet(Packet::Raw(RawPacket::from_str("AG"))).await?;
|
// making sure that the requested file cant point to files outside of Resources/Client/*
|
||||||
|
let path = std::path::Path::new(&mod_name);
|
||||||
// Send the first half of the file
|
let mod_name = match path.file_name() {
|
||||||
if mod_name.starts_with("/") == false {
|
Some(v) => "/".to_string() + v.to_str().unwrap(),
|
||||||
mod_name = format!("/{mod_name}");
|
None => {
|
||||||
|
error!("Client requests invalid mod. Disconnecting");
|
||||||
|
self.kick("Invalid mod request");
|
||||||
|
return Ok(());
|
||||||
|
}, // client requested path (fResources/Client/) or nothing at all (f) - invalid
|
||||||
|
};
|
||||||
|
let mod_path = format!("Resources/Client{mod_name}");
|
||||||
|
if !std::path::Path::new(&mod_path).exists() {
|
||||||
|
error!("Client requests inexistent mod. Disconnecting");
|
||||||
|
self.kick("Invalid mod request");
|
||||||
|
return Ok(()) // client requested mod that doesnt exists within "Resources/Client/*"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.write_packet(Packet::Raw(RawPacket::from_str("AG"))).await?;
|
||||||
|
|
||||||
let mut mod_id = 0;
|
let mut mod_id = 0;
|
||||||
for (i, (bmod_name, _bmod_size)) in config.mods.iter().enumerate() {
|
for (i, (bmod_name, _bmod_size)) in config.mods.iter().enumerate() {
|
||||||
if bmod_name == &mod_name {
|
if bmod_name == &mod_name {
|
||||||
@ -220,9 +232,8 @@ impl Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mod_path = format!("Resources/Client{mod_name}");
|
// Send the first half of the file over this socket and the other over the DSocket
|
||||||
let file_data = std::fs::read(mod_path)?;
|
let file_data = std::fs::read(mod_path)?;
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut lock = self.write_half.lock().await;
|
let mut lock = self.write_half.lock().await;
|
||||||
lock.writable().await?;
|
lock.writable().await?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user