quectocraft/src/main.rs

41 lines
1.0 KiB
Rust
Raw Normal View History

2022-12-04 06:06:21 +00:00
use std::time::{Duration, SystemTime};
2022-12-02 23:27:53 +00:00
2022-12-04 06:06:21 +00:00
use env_logger::Env;
use log::info;
2022-12-02 23:27:53 +00:00
use mlua::Lua;
use network::NetworkServer;
2022-12-04 06:06:21 +00:00
use plugins::Plugins;
2022-12-02 23:27:53 +00:00
mod plugins;
mod protocol;
mod network;
2022-12-04 06:06:21 +00:00
pub const VERSION: &'static str = std::env!("CARGO_PKG_VERSION");
2022-12-02 23:27:53 +00:00
fn main() {
2022-12-04 06:06:21 +00:00
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
info!("quectocraft version {}", VERSION);
2022-12-02 23:27:53 +00:00
let lua = Lua::new();
2022-12-04 06:06:21 +00:00
let mut plugins = Plugins::new(&lua).expect("Error initializing lua environment");
std::fs::create_dir_all("plugins").expect("couldn't create the plugins directory");
plugins.load_plugins();
info!("{} plugins loaded", plugins.count());
2022-12-02 23:27:53 +00:00
let mut server = NetworkServer::new("127.0.0.1:25565".to_owned(), plugins);
let sleep_dur = Duration::from_millis(5);
let mut i = 0;
loop {
server.get_new_clients();
server.handle_connections();
if i % 1024 == 0 {
server.send_keep_alive();
i = 0;
}
i += 1;
2022-12-04 06:06:21 +00:00
std::thread::sleep(sleep_dur);
2022-12-02 23:27:53 +00:00
}
}