2019-08-19 12:39:23 +00:00
|
|
|
#![deny(unsafe_code)]
|
|
|
|
|
2019-01-30 12:11:34 +00:00
|
|
|
use common::clock::Clock;
|
2019-06-29 16:41:26 +00:00
|
|
|
use server::{Event, Input, Server, ServerSettings};
|
2019-04-29 20:37:19 +00:00
|
|
|
use std::time::Duration;
|
2020-06-29 08:53:43 +00:00
|
|
|
use tracing::{info, Level};
|
|
|
|
use tracing_subscriber::{filter::LevelFilter, EnvFilter, FmtSubscriber};
|
2019-01-30 12:11:34 +00:00
|
|
|
|
2019-03-19 19:53:35 +00:00
|
|
|
const TPS: u64 = 30;
|
2020-06-29 08:53:43 +00:00
|
|
|
const RUST_LOG_ENV: &str = "RUST_LOG";
|
2019-01-30 12:11:34 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// Init logging
|
2020-06-29 08:53:43 +00:00
|
|
|
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()),
|
|
|
|
};
|
2020-06-21 14:26:06 +00:00
|
|
|
|
2020-06-29 08:53:43 +00:00
|
|
|
FmtSubscriber::builder()
|
|
|
|
.with_max_level(Level::ERROR)
|
|
|
|
.with_env_filter(filter)
|
|
|
|
.init();
|
2019-01-30 12:11:34 +00:00
|
|
|
|
2020-03-26 11:41:30 +00:00
|
|
|
info!("Starting server...");
|
2019-01-30 12:11:34 +00:00
|
|
|
|
|
|
|
// Set up an fps clock
|
2019-07-01 20:42:43 +00:00
|
|
|
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();
|
2019-10-26 00:05:57 +00:00
|
|
|
let metrics_port = &settings.metrics_address.port();
|
2019-01-30 12:11:34 +00:00
|
|
|
|
|
|
|
// Create server
|
2019-06-29 16:41:26 +00:00
|
|
|
let mut server = Server::new(settings).expect("Failed to create server instance!");
|
2019-01-30 12:11:34 +00:00
|
|
|
|
2020-03-26 11:41:30 +00:00
|
|
|
info!("Server is ready to accept connections.");
|
2020-06-21 21:47:49 +00:00
|
|
|
info!(?metrics_port, "starting metrics at port");
|
2020-06-10 04:21:56 +00:00
|
|
|
info!(?server_port, "starting server at port");
|
2019-10-18 20:05:37 +00:00
|
|
|
|
2019-01-30 12:11:34 +00:00
|
|
|
loop {
|
2019-04-29 20:37:19 +00:00
|
|
|
let events = server
|
|
|
|
.tick(Input::default(), clock.get_last_delta())
|
2019-01-30 12:11:34 +00:00
|
|
|
.expect("Failed to tick server");
|
|
|
|
|
2019-03-03 22:02:38 +00:00
|
|
|
for event in events {
|
|
|
|
match event {
|
2019-06-06 14:48:41 +00:00
|
|
|
Event::ClientConnected { entity: _ } => info!("Client connected!"),
|
|
|
|
Event::ClientDisconnected { entity: _ } => info!("Client disconnected!"),
|
|
|
|
Event::Chat { entity: _, msg } => info!("[Client] {}", msg),
|
2019-03-03 22:02:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-17 09:22:32 +00:00
|
|
|
// Clean up the server after a tick.
|
2019-01-30 12:11:34 +00:00
|
|
|
server.cleanup();
|
|
|
|
|
2019-05-17 09:22:32 +00:00
|
|
|
// Wait for the next tick.
|
2019-03-05 00:00:11 +00:00
|
|
|
clock.tick(Duration::from_millis(1000 / TPS));
|
2019-01-30 12:11:34 +00:00
|
|
|
}
|
|
|
|
}
|