veloren/server-cli/src/main.rs

46 lines
1.1 KiB
Rust
Raw Normal View History

use common::clock::Clock;
use heaptrack::track_mem;
use log::info;
2019-06-29 16:41:26 +00:00
use server::{Event, Input, Server, ServerSettings};
use std::time::Duration;
track_mem!();
const TPS: u64 = 30;
fn main() {
// Init logging
pretty_env_logger::init();
info!("Starting server-cli...");
// 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();
// Create server
2019-06-29 16:41:26 +00:00
let mut server = Server::new(settings).expect("Failed to create server instance!");
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));
}
}