veloren/server-cli/src/main.rs

52 lines
1.3 KiB
Rust
Raw Normal View History

2019-08-19 12:39:23 +00:00
#![deny(unsafe_code)]
#[cfg(not(target_env = "msvc"))]
2019-10-05 21:43:46 +00:00
use jemallocator::Jemalloc;
#[cfg(not(target_env = "msvc"))]
2019-10-05 21:43:46 +00:00
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
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;
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));
}
}