veloren/server-cli/src/main.rs

54 lines
1.5 KiB
Rust
Raw Normal View History

2019-08-19 12:39:23 +00:00
#![deny(unsafe_code)]
#![allow(clippy::option_map_unit_fn)]
2019-08-19 12:39:23 +00:00
use common::clock::Clock;
use log::info;
2019-06-29 16:41:26 +00:00
use server::{Event, Input, Server, ServerSettings};
use std::time::Duration;
const TPS: u64 = 30;
#[allow(clippy::redundant_pattern_matching)] // TODO: Pending review in #587
fn main() {
// Init logging
2020-03-26 11:41:30 +00:00
if let Err(_) = std::env::var("RUST_LOG") {
std::env::set_var("RUST_LOG", "info");
}
pretty_env_logger::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();
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: {}", metrics_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));
}
}