veloren/server-cli/src/main.rs

75 lines
2.4 KiB
Rust
Raw Normal View History

2019-08-19 12:39:23 +00:00
#![deny(unsafe_code)]
use common::clock::Clock;
2019-06-29 16:41:26 +00:00
use server::{Event, Input, Server, ServerSettings};
use std::time::Duration;
use tracing::{info, Level};
use tracing_subscriber::{filter::LevelFilter, EnvFilter, FmtSubscriber};
const TPS: u64 = 30;
const RUST_LOG_ENV: &str = "RUST_LOG";
fn main() {
// Init logging
let filter = match std::env::var_os(RUST_LOG_ENV).map(|s| s.into_string()) {
Some(Ok(env)) => {
let mut filter = EnvFilter::new("veloren_world::sim=info")
.add_directive("veloren_world::civ=info".parse().unwrap())
.add_directive(LevelFilter::INFO.into());
for s in env.split(',').into_iter() {
match s.parse() {
Ok(d) => filter = filter.add_directive(d),
Err(err) => println!("WARN ignoring log directive: `{}`: {}", s, err),
};
}
filter
},
_ => EnvFilter::from_env(RUST_LOG_ENV)
.add_directive("veloren_world::sim=info".parse().unwrap())
.add_directive("veloren_world::civ=info".parse().unwrap())
.add_directive(LevelFilter::INFO.into()),
};
FmtSubscriber::builder()
.with_max_level(Level::ERROR)
.with_env_filter(filter)
.init();
2020-03-26 11:41:30 +00:00
info!("Starting server...");
// Set up an fps clock
let mut clock = Clock::start();
2019-07-04 09:38:17 +00:00
2019-06-29 16:41:26 +00:00
// Load settings
let settings = ServerSettings::load();
2020-06-10 04:21:56 +00:00
let server_port = &settings.gameserver_address.port();
let metrics_port = &settings.metrics_address.port();
// Create server
2019-06-29 16:41:26 +00:00
let mut server = Server::new(settings).expect("Failed to create server instance!");
2020-03-26 11:41:30 +00:00
info!("Server is ready to accept connections.");
info!(?metrics_port, "starting metrics at port");
2020-06-10 04:21:56 +00:00
info!(?server_port, "starting server at port");
loop {
let events = server
.tick(Input::default(), clock.get_last_delta())
.expect("Failed to tick server");
for event in events {
match event {
Event::ClientConnected { entity: _ } => info!("Client connected!"),
Event::ClientDisconnected { entity: _ } => info!("Client disconnected!"),
Event::Chat { entity: _, msg } => info!("[Client] {}", msg),
}
}
// Clean up the server after a tick.
server.cleanup();
// Wait for the next tick.
clock.tick(Duration::from_millis(1000 / TPS));
}
}