2019-08-19 12:39:23 +00:00
|
|
|
#![deny(unsafe_code)]
|
2020-06-14 16:48:07 +00:00
|
|
|
#![allow(clippy::option_map_unit_fn)]
|
2019-08-19 12:39:23 +00:00
|
|
|
|
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-21 14:26:06 +00:00
|
|
|
use tracing::info;
|
2019-01-30 12:11:34 +00:00
|
|
|
|
2019-03-19 19:53:35 +00:00
|
|
|
const TPS: u64 = 30;
|
2019-01-30 12:11:34 +00:00
|
|
|
|
2020-06-10 19:47:36 +00:00
|
|
|
#[allow(clippy::redundant_pattern_matching)] // TODO: Pending review in #587
|
2019-01-30 12:11:34 +00:00
|
|
|
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");
|
|
|
|
}
|
2020-06-21 14:26:06 +00:00
|
|
|
|
|
|
|
tracing_subscriber::fmt::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
|
|
|
}
|
|
|
|
}
|