2019-08-19 12:39:23 +00:00
|
|
|
#![deny(unsafe_code)]
|
2020-09-27 16:20:40 +00:00
|
|
|
#![deny(clippy::clone_on_ref_ptr)]
|
2019-08-19 12:39:23 +00:00
|
|
|
|
2023-01-27 02:26:36 +00:00
|
|
|
#[cfg(all(
|
|
|
|
target_os = "windows",
|
|
|
|
not(feature = "hot-agent"),
|
|
|
|
not(feature = "hot-site"),
|
|
|
|
))]
|
2022-07-04 07:15:18 +00:00
|
|
|
#[global_allocator]
|
|
|
|
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
|
|
|
|
2021-03-13 06:48:30 +00:00
|
|
|
/// `server-cli` interface commands not to be confused with the commands sent
|
|
|
|
/// from the client to the server
|
Added non-admin moderators and timed bans.
The security model has been updated to reflect this change (for example,
moderators cannot revert a ban by an administrator). Ban history is
also now recorded in the ban file, and much more information about the
ban is stored (whitelists and administrators also have extra
information).
To support the new information without losing important information,
this commit also introduces a new migration path for editable settings
(both from legacy to the new format, and between versions). Examples
of how to do this correctly, and migrate to new versions of a settings
file, are in the settings/ subdirectory.
As part of this effort, editable settings have been revamped to
guarantee atomic saves (due to the increased amount of information in
each file), some latent bugs in networking were fixed, and server-cli
has been updated to go through StructOpt for both calls through TUI
and argv, greatly simplifying parsing logic.
2021-05-08 18:22:21 +00:00
|
|
|
mod cli;
|
2020-10-05 08:35:24 +00:00
|
|
|
mod settings;
|
2020-10-03 19:10:34 +00:00
|
|
|
mod shutdown_coordinator;
|
2020-08-31 08:41:11 +00:00
|
|
|
mod tui_runner;
|
|
|
|
mod tuilog;
|
2023-10-15 18:17:45 +00:00
|
|
|
mod web;
|
2021-03-28 23:40:53 +00:00
|
|
|
use crate::{
|
Added non-admin moderators and timed bans.
The security model has been updated to reflect this change (for example,
moderators cannot revert a ban by an administrator). Ban history is
also now recorded in the ban file, and much more information about the
ban is stored (whitelists and administrators also have extra
information).
To support the new information without losing important information,
this commit also introduces a new migration path for editable settings
(both from legacy to the new format, and between versions). Examples
of how to do this correctly, and migrate to new versions of a settings
file, are in the settings/ subdirectory.
As part of this effort, editable settings have been revamped to
guarantee atomic saves (due to the increased amount of information in
each file), some latent bugs in networking were fixed, and server-cli
has been updated to go through StructOpt for both calls through TUI
and argv, greatly simplifying parsing logic.
2021-05-08 18:22:21 +00:00
|
|
|
cli::{Admin, ArgvApp, ArgvCommand, Message, SharedCommand, Shutdown},
|
|
|
|
shutdown_coordinator::ShutdownCoordinator,
|
|
|
|
tui_runner::Tui,
|
|
|
|
tuilog::TuiLog,
|
2021-03-28 23:40:53 +00:00
|
|
|
};
|
2021-05-04 19:41:08 +00:00
|
|
|
use common::{clock::Clock, consts::MIN_RECOMMENDED_TOKIO_THREADS};
|
2021-03-08 22:40:02 +00:00
|
|
|
use common_base::span;
|
2021-03-15 22:50:26 +00:00
|
|
|
use core::sync::atomic::{AtomicUsize, Ordering};
|
2021-10-15 11:45:55 +00:00
|
|
|
use server::{persistence::DatabaseSettings, settings::Protocol, Event, Input, Server};
|
2020-10-03 19:10:34 +00:00
|
|
|
use std::{
|
|
|
|
io,
|
|
|
|
sync::{atomic::AtomicBool, mpsc, Arc},
|
2023-06-14 06:45:39 +00:00
|
|
|
time::{Duration, Instant},
|
2020-10-03 19:10:34 +00:00
|
|
|
};
|
2023-10-15 18:17:45 +00:00
|
|
|
use tokio::sync::Notify;
|
2021-03-21 17:33:39 +00:00
|
|
|
use tracing::{info, trace};
|
2020-07-27 16:26:34 +00:00
|
|
|
|
2021-03-28 23:40:53 +00:00
|
|
|
lazy_static::lazy_static! {
|
|
|
|
pub static ref LOG: TuiLog<'static> = TuiLog::default();
|
|
|
|
}
|
2019-03-19 19:53:35 +00:00
|
|
|
const TPS: u64 = 30;
|
2020-07-27 16:26:34 +00:00
|
|
|
|
|
|
|
fn main() -> io::Result<()> {
|
2022-05-10 07:28:13 +00:00
|
|
|
#[cfg(feature = "tracy")]
|
|
|
|
common_base::tracy_client::Client::start();
|
|
|
|
|
2022-04-02 21:29:22 +00:00
|
|
|
use clap::Parser;
|
|
|
|
let app = ArgvApp::parse();
|
Added non-admin moderators and timed bans.
The security model has been updated to reflect this change (for example,
moderators cannot revert a ban by an administrator). Ban history is
also now recorded in the ban file, and much more information about the
ban is stored (whitelists and administrators also have extra
information).
To support the new information without losing important information,
this commit also introduces a new migration path for editable settings
(both from legacy to the new format, and between versions). Examples
of how to do this correctly, and migrate to new versions of a settings
file, are in the settings/ subdirectory.
As part of this effort, editable settings have been revamped to
guarantee atomic saves (due to the increased amount of information in
each file), some latent bugs in networking were fixed, and server-cli
has been updated to go through StructOpt for both calls through TUI
and argv, greatly simplifying parsing logic.
2021-05-08 18:22:21 +00:00
|
|
|
|
2021-07-14 19:03:16 +00:00
|
|
|
let basic = !app.tui || app.command.is_some();
|
Added non-admin moderators and timed bans.
The security model has been updated to reflect this change (for example,
moderators cannot revert a ban by an administrator). Ban history is
also now recorded in the ban file, and much more information about the
ban is stored (whitelists and administrators also have extra
information).
To support the new information without losing important information,
this commit also introduces a new migration path for editable settings
(both from legacy to the new format, and between versions). Examples
of how to do this correctly, and migrate to new versions of a settings
file, are in the settings/ subdirectory.
As part of this effort, editable settings have been revamped to
guarantee atomic saves (due to the increased amount of information in
each file), some latent bugs in networking were fixed, and server-cli
has been updated to go through StructOpt for both calls through TUI
and argv, greatly simplifying parsing logic.
2021-05-08 18:22:21 +00:00
|
|
|
let noninteractive = app.non_interactive;
|
|
|
|
let no_auth = app.no_auth;
|
|
|
|
let sql_log_mode = app.sql_log_mode;
|
2021-04-13 22:05:47 +00:00
|
|
|
|
2021-03-25 23:22:46 +00:00
|
|
|
// noninteractive implies basic
|
|
|
|
let basic = basic || noninteractive;
|
|
|
|
|
2020-10-03 19:10:34 +00:00
|
|
|
let sigusr1_signal = Arc::new(AtomicBool::new(false));
|
|
|
|
|
|
|
|
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
2021-03-09 19:12:57 +00:00
|
|
|
let _ = signal_hook::flag::register(signal_hook::consts::SIGUSR1, Arc::clone(&sigusr1_signal));
|
2020-10-03 19:10:34 +00:00
|
|
|
|
2021-03-28 23:40:53 +00:00
|
|
|
let (_guards, _guards2) = if basic {
|
2022-02-20 00:22:13 +00:00
|
|
|
(Vec::new(), common_frontend::init_stdout(None))
|
2021-03-28 23:40:53 +00:00
|
|
|
} else {
|
2022-02-20 00:22:13 +00:00
|
|
|
(common_frontend::init(None, &|| LOG.clone()), Vec::new())
|
2021-03-28 23:40:53 +00:00
|
|
|
};
|
2019-01-30 12:11:34 +00:00
|
|
|
|
2020-10-05 08:35:24 +00:00
|
|
|
// Load settings
|
|
|
|
let settings = settings::Settings::load();
|
|
|
|
|
2020-10-05 07:41:58 +00:00
|
|
|
// Determine folder to save server data in
|
2020-10-06 02:59:47 +00:00
|
|
|
let server_data_dir = {
|
2021-03-08 22:40:02 +00:00
|
|
|
let mut path = common_base::userdata_dir_workspace!();
|
2020-10-25 20:19:39 +00:00
|
|
|
info!("Using userdata folder at {}", path.display());
|
2020-10-05 07:41:58 +00:00
|
|
|
path.push(server::DEFAULT_DATA_DIR_NAME);
|
|
|
|
path
|
2020-10-06 02:59:47 +00:00
|
|
|
};
|
2020-10-05 07:41:58 +00:00
|
|
|
|
2021-05-04 17:42:45 +00:00
|
|
|
// We don't need that many threads in the async pool, at least 2 but generally
|
|
|
|
// 25% of all available will do
|
2021-05-04 19:41:08 +00:00
|
|
|
// TODO: evaluate std::thread::available_concurrency as a num_cpus replacement
|
2021-03-11 00:08:12 +00:00
|
|
|
let runtime = Arc::new(
|
|
|
|
tokio::runtime::Builder::new_multi_thread()
|
|
|
|
.enable_all()
|
2021-05-04 19:41:08 +00:00
|
|
|
.worker_threads((num_cpus::get() / 4).max(MIN_RECOMMENDED_TOKIO_THREADS))
|
2021-03-15 22:50:26 +00:00
|
|
|
.thread_name_fn(|| {
|
|
|
|
static ATOMIC_ID: AtomicUsize = AtomicUsize::new(0);
|
|
|
|
let id = ATOMIC_ID.fetch_add(1, Ordering::SeqCst);
|
|
|
|
format!("tokio-server-{}", id)
|
|
|
|
})
|
2021-03-11 00:08:12 +00:00
|
|
|
.build()
|
|
|
|
.unwrap(),
|
|
|
|
);
|
|
|
|
|
2022-09-16 00:29:12 +00:00
|
|
|
#[cfg(feature = "hot-agent")]
|
|
|
|
{
|
|
|
|
agent::init();
|
|
|
|
}
|
2023-01-10 00:41:07 +00:00
|
|
|
#[cfg(feature = "hot-site")]
|
2023-01-06 02:06:28 +00:00
|
|
|
{
|
|
|
|
world::init();
|
|
|
|
}
|
2022-09-16 00:29:12 +00:00
|
|
|
|
2020-10-05 08:35:24 +00:00
|
|
|
// Load server settings
|
2020-10-06 02:59:47 +00:00
|
|
|
let mut server_settings = server::Settings::load(&server_data_dir);
|
2020-10-10 06:10:04 +00:00
|
|
|
let mut editable_settings = server::EditableSettings::load(&server_data_dir);
|
2021-04-13 22:05:47 +00:00
|
|
|
|
2021-12-21 16:35:49 +00:00
|
|
|
// Apply no_auth modifier to the settings
|
|
|
|
if no_auth {
|
|
|
|
server_settings.auth_server_address = None;
|
|
|
|
}
|
|
|
|
|
2021-04-13 22:05:47 +00:00
|
|
|
// Relative to data_dir
|
|
|
|
const PERSISTENCE_DB_DIR: &str = "saves";
|
|
|
|
|
|
|
|
let database_settings = DatabaseSettings {
|
|
|
|
db_dir: server_data_dir.join(PERSISTENCE_DB_DIR),
|
|
|
|
sql_log_mode,
|
|
|
|
};
|
|
|
|
|
2023-06-14 06:45:39 +00:00
|
|
|
let mut bench = None;
|
Added non-admin moderators and timed bans.
The security model has been updated to reflect this change (for example,
moderators cannot revert a ban by an administrator). Ban history is
also now recorded in the ban file, and much more information about the
ban is stored (whitelists and administrators also have extra
information).
To support the new information without losing important information,
this commit also introduces a new migration path for editable settings
(both from legacy to the new format, and between versions). Examples
of how to do this correctly, and migrate to new versions of a settings
file, are in the settings/ subdirectory.
As part of this effort, editable settings have been revamped to
guarantee atomic saves (due to the increased amount of information in
each file), some latent bugs in networking were fixed, and server-cli
has been updated to go through StructOpt for both calls through TUI
and argv, greatly simplifying parsing logic.
2021-05-08 18:22:21 +00:00
|
|
|
if let Some(command) = app.command {
|
2023-06-14 06:45:39 +00:00
|
|
|
match command {
|
Added non-admin moderators and timed bans.
The security model has been updated to reflect this change (for example,
moderators cannot revert a ban by an administrator). Ban history is
also now recorded in the ban file, and much more information about the
ban is stored (whitelists and administrators also have extra
information).
To support the new information without losing important information,
this commit also introduces a new migration path for editable settings
(both from legacy to the new format, and between versions). Examples
of how to do this correctly, and migrate to new versions of a settings
file, are in the settings/ subdirectory.
As part of this effort, editable settings have been revamped to
guarantee atomic saves (due to the increased amount of information in
each file), some latent bugs in networking were fixed, and server-cli
has been updated to go through StructOpt for both calls through TUI
and argv, greatly simplifying parsing logic.
2021-05-08 18:22:21 +00:00
|
|
|
ArgvCommand::Shared(SharedCommand::Admin { command }) => {
|
|
|
|
let login_provider = server::login_provider::LoginProvider::new(
|
|
|
|
server_settings.auth_server_address,
|
|
|
|
runtime,
|
|
|
|
);
|
|
|
|
|
2023-06-14 06:45:39 +00:00
|
|
|
return match command {
|
Added non-admin moderators and timed bans.
The security model has been updated to reflect this change (for example,
moderators cannot revert a ban by an administrator). Ban history is
also now recorded in the ban file, and much more information about the
ban is stored (whitelists and administrators also have extra
information).
To support the new information without losing important information,
this commit also introduces a new migration path for editable settings
(both from legacy to the new format, and between versions). Examples
of how to do this correctly, and migrate to new versions of a settings
file, are in the settings/ subdirectory.
As part of this effort, editable settings have been revamped to
guarantee atomic saves (due to the increased amount of information in
each file), some latent bugs in networking were fixed, and server-cli
has been updated to go through StructOpt for both calls through TUI
and argv, greatly simplifying parsing logic.
2021-05-08 18:22:21 +00:00
|
|
|
Admin::Add { username, role } => {
|
|
|
|
// FIXME: Currently the UUID can get returned even if the file didn't
|
|
|
|
// change, so this can't be relied on as an error
|
|
|
|
// code; moreover, we do nothing with the UUID
|
|
|
|
// returned in the success case. Fix the underlying function to return
|
|
|
|
// enough information that we can reliably return an error code.
|
|
|
|
let _ = server::add_admin(
|
|
|
|
&username,
|
|
|
|
role,
|
|
|
|
&login_provider,
|
|
|
|
&mut editable_settings,
|
|
|
|
&server_data_dir,
|
|
|
|
);
|
2023-06-14 06:45:39 +00:00
|
|
|
Ok(())
|
Added non-admin moderators and timed bans.
The security model has been updated to reflect this change (for example,
moderators cannot revert a ban by an administrator). Ban history is
also now recorded in the ban file, and much more information about the
ban is stored (whitelists and administrators also have extra
information).
To support the new information without losing important information,
this commit also introduces a new migration path for editable settings
(both from legacy to the new format, and between versions). Examples
of how to do this correctly, and migrate to new versions of a settings
file, are in the settings/ subdirectory.
As part of this effort, editable settings have been revamped to
guarantee atomic saves (due to the increased amount of information in
each file), some latent bugs in networking were fixed, and server-cli
has been updated to go through StructOpt for both calls through TUI
and argv, greatly simplifying parsing logic.
2021-05-08 18:22:21 +00:00
|
|
|
},
|
|
|
|
Admin::Remove { username } => {
|
|
|
|
// FIXME: Currently the UUID can get returned even if the file didn't
|
|
|
|
// change, so this can't be relied on as an error
|
|
|
|
// code; moreover, we do nothing with the UUID
|
|
|
|
// returned in the success case. Fix the underlying function to return
|
|
|
|
// enough information that we can reliably return an error code.
|
|
|
|
let _ = server::remove_admin(
|
|
|
|
&username,
|
|
|
|
&login_provider,
|
|
|
|
&mut editable_settings,
|
|
|
|
&server_data_dir,
|
|
|
|
);
|
2023-06-14 06:45:39 +00:00
|
|
|
Ok(())
|
Added non-admin moderators and timed bans.
The security model has been updated to reflect this change (for example,
moderators cannot revert a ban by an administrator). Ban history is
also now recorded in the ban file, and much more information about the
ban is stored (whitelists and administrators also have extra
information).
To support the new information without losing important information,
this commit also introduces a new migration path for editable settings
(both from legacy to the new format, and between versions). Examples
of how to do this correctly, and migrate to new versions of a settings
file, are in the settings/ subdirectory.
As part of this effort, editable settings have been revamped to
guarantee atomic saves (due to the increased amount of information in
each file), some latent bugs in networking were fixed, and server-cli
has been updated to go through StructOpt for both calls through TUI
and argv, greatly simplifying parsing logic.
2021-05-08 18:22:21 +00:00
|
|
|
},
|
2023-06-14 06:45:39 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
ArgvCommand::Bench(params) => {
|
|
|
|
bench = Some(params);
|
|
|
|
// If we are trying to benchmark, don't limit the server view distance.
|
|
|
|
server_settings.max_view_distance = None;
|
2023-09-15 02:59:16 +00:00
|
|
|
// TODO: add setting to adjust wildlife spawn density, note I
|
|
|
|
// tried but Index setup makes it a bit
|
|
|
|
// annoying, might require a more involved refactor to get
|
|
|
|
// working nicely
|
Added non-admin moderators and timed bans.
The security model has been updated to reflect this change (for example,
moderators cannot revert a ban by an administrator). Ban history is
also now recorded in the ban file, and much more information about the
ban is stored (whitelists and administrators also have extra
information).
To support the new information without losing important information,
this commit also introduces a new migration path for editable settings
(both from legacy to the new format, and between versions). Examples
of how to do this correctly, and migrate to new versions of a settings
file, are in the settings/ subdirectory.
As part of this effort, editable settings have been revamped to
guarantee atomic saves (due to the increased amount of information in
each file), some latent bugs in networking were fixed, and server-cli
has been updated to go through StructOpt for both calls through TUI
and argv, greatly simplifying parsing logic.
2021-05-08 18:22:21 +00:00
|
|
|
},
|
|
|
|
};
|
2020-10-10 06:10:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Panic hook to ensure that console mode is set back correctly if in non-basic
|
|
|
|
// mode
|
|
|
|
if !basic {
|
|
|
|
let hook = std::panic::take_hook();
|
|
|
|
std::panic::set_hook(Box::new(move |info| {
|
|
|
|
Tui::shutdown(basic);
|
|
|
|
hook(info);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
Added non-admin moderators and timed bans.
The security model has been updated to reflect this change (for example,
moderators cannot revert a ban by an administrator). Ban history is
also now recorded in the ban file, and much more information about the
ban is stored (whitelists and administrators also have extra
information).
To support the new information without losing important information,
this commit also introduces a new migration path for editable settings
(both from legacy to the new format, and between versions). Examples
of how to do this correctly, and migrate to new versions of a settings
file, are in the settings/ subdirectory.
As part of this effort, editable settings have been revamped to
guarantee atomic saves (due to the increased amount of information in
each file), some latent bugs in networking were fixed, and server-cli
has been updated to go through StructOpt for both calls through TUI
and argv, greatly simplifying parsing logic.
2021-05-08 18:22:21 +00:00
|
|
|
let tui = (!noninteractive).then(|| Tui::run(basic));
|
2020-10-10 06:10:04 +00:00
|
|
|
|
|
|
|
info!("Starting server...");
|
2020-10-05 07:41:58 +00:00
|
|
|
|
2021-10-15 11:45:55 +00:00
|
|
|
let protocols_and_addresses = server_settings.gameserver_protocols.clone();
|
2023-10-15 18:17:45 +00:00
|
|
|
let web_port = &settings.web_address.port();
|
2020-07-28 10:02:48 +00:00
|
|
|
// Create server
|
2021-01-15 13:04:32 +00:00
|
|
|
let mut server = Server::new(
|
|
|
|
server_settings,
|
|
|
|
editable_settings,
|
2021-04-13 22:05:47 +00:00
|
|
|
database_settings,
|
2021-01-15 13:04:32 +00:00
|
|
|
&server_data_dir,
|
2023-10-02 14:51:03 +00:00
|
|
|
&|_| {},
|
2023-10-15 18:17:45 +00:00
|
|
|
Arc::clone(&runtime),
|
2021-01-15 13:04:32 +00:00
|
|
|
)
|
|
|
|
.expect("Failed to create server instance!");
|
2020-07-28 10:02:48 +00:00
|
|
|
|
2023-10-15 18:17:45 +00:00
|
|
|
let registry = Arc::clone(server.metrics_registry());
|
|
|
|
let chat = server.chat_cache().clone();
|
|
|
|
let metrics_shutdown = Arc::new(Notify::new());
|
|
|
|
let metrics_shutdown_clone = Arc::clone(&metrics_shutdown);
|
|
|
|
let web_chat_secret = settings.web_chat_secret.clone();
|
|
|
|
|
|
|
|
runtime.spawn(async move {
|
|
|
|
web::run(
|
|
|
|
registry,
|
|
|
|
chat,
|
|
|
|
web_chat_secret,
|
|
|
|
settings.web_address,
|
|
|
|
metrics_shutdown_clone.notified(),
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
});
|
|
|
|
|
2022-02-20 00:22:13 +00:00
|
|
|
// Collect addresses that the server is listening to log.
|
|
|
|
let gameserver_addresses = protocols_and_addresses
|
|
|
|
.into_iter()
|
|
|
|
.map(|protocol| match protocol {
|
2021-10-17 22:00:20 +00:00
|
|
|
Protocol::Tcp { address } => ("TCP", address),
|
2021-10-15 11:45:55 +00:00
|
|
|
Protocol::Quic {
|
|
|
|
address,
|
|
|
|
cert_file_path: _,
|
|
|
|
key_file_path: _,
|
2021-10-17 22:00:20 +00:00
|
|
|
} => ("QUIC", address),
|
2022-02-20 00:22:13 +00:00
|
|
|
});
|
2020-10-03 19:10:34 +00:00
|
|
|
|
2021-10-17 22:00:20 +00:00
|
|
|
info!(
|
2023-10-15 18:17:45 +00:00
|
|
|
?web_port,
|
2021-10-17 22:00:20 +00:00
|
|
|
?gameserver_addresses,
|
|
|
|
"Server is ready to accept connections."
|
|
|
|
);
|
2021-10-15 11:45:55 +00:00
|
|
|
|
2020-10-03 19:10:34 +00:00
|
|
|
let mut shutdown_coordinator = ShutdownCoordinator::new(Arc::clone(&sigusr1_signal));
|
2020-07-28 10:02:48 +00:00
|
|
|
|
2020-10-10 06:10:04 +00:00
|
|
|
// Set up an fps clock
|
2020-11-12 02:47:22 +00:00
|
|
|
let mut clock = Clock::new(Duration::from_secs_f64(1.0 / TPS as f64));
|
2023-06-14 06:45:39 +00:00
|
|
|
|
|
|
|
if let Some(bench) = bench {
|
|
|
|
#[cfg(feature = "worldgen")]
|
|
|
|
server.create_centered_persister(bench.view_distance);
|
|
|
|
}
|
|
|
|
let mut bench_exit_time = None;
|
2020-10-10 06:10:04 +00:00
|
|
|
|
2021-03-21 17:33:39 +00:00
|
|
|
let mut tick_no = 0u64;
|
2020-07-28 10:02:48 +00:00
|
|
|
loop {
|
2020-11-22 08:50:25 +00:00
|
|
|
span!(guard, "work");
|
2023-06-14 06:45:39 +00:00
|
|
|
if let Some(bench) = bench {
|
|
|
|
if let Some(t) = bench_exit_time {
|
|
|
|
if Instant::now() > t {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if tick_no != 0 && !server.chunks_pending() {
|
|
|
|
println!("Chunk loading complete");
|
|
|
|
bench_exit_time = Some(Instant::now() + Duration::from_secs(bench.duration.into()));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
tick_no += 1;
|
2020-10-03 19:10:34 +00:00
|
|
|
// Terminate the server if instructed to do so by the shutdown coordinator
|
2020-10-05 08:35:24 +00:00
|
|
|
if shutdown_coordinator.check(&mut server, &settings) {
|
2023-10-15 18:17:45 +00:00
|
|
|
metrics_shutdown.notify_one();
|
2020-10-03 19:10:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-07-28 10:02:48 +00:00
|
|
|
let events = server
|
2020-11-10 12:30:01 +00:00
|
|
|
.tick(Input::default(), clock.dt())
|
2020-07-28 10:02:48 +00:00
|
|
|
.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();
|
|
|
|
|
2021-03-21 17:33:39 +00:00
|
|
|
if tick_no.rem_euclid(1000) == 0 {
|
|
|
|
trace!(?tick_no, "keepalive")
|
|
|
|
}
|
|
|
|
|
2020-09-20 02:40:26 +00:00
|
|
|
if let Some(tui) = tui.as_ref() {
|
|
|
|
match tui.msg_r.try_recv() {
|
|
|
|
Ok(msg) => match msg {
|
Added non-admin moderators and timed bans.
The security model has been updated to reflect this change (for example,
moderators cannot revert a ban by an administrator). Ban history is
also now recorded in the ban file, and much more information about the
ban is stored (whitelists and administrators also have extra
information).
To support the new information without losing important information,
this commit also introduces a new migration path for editable settings
(both from legacy to the new format, and between versions). Examples
of how to do this correctly, and migrate to new versions of a settings
file, are in the settings/ subdirectory.
As part of this effort, editable settings have been revamped to
guarantee atomic saves (due to the increased amount of information in
each file), some latent bugs in networking were fixed, and server-cli
has been updated to go through StructOpt for both calls through TUI
and argv, greatly simplifying parsing logic.
2021-05-08 18:22:21 +00:00
|
|
|
Message::Shutdown {
|
|
|
|
command: Shutdown::Cancel,
|
|
|
|
} => shutdown_coordinator.abort_shutdown(&mut server),
|
|
|
|
Message::Shutdown {
|
|
|
|
command: Shutdown::Graceful { seconds, reason },
|
|
|
|
} => {
|
|
|
|
shutdown_coordinator.initiate_shutdown(
|
|
|
|
&mut server,
|
|
|
|
Duration::from_secs(seconds),
|
|
|
|
reason,
|
|
|
|
);
|
2020-09-20 02:40:26 +00:00
|
|
|
},
|
Added non-admin moderators and timed bans.
The security model has been updated to reflect this change (for example,
moderators cannot revert a ban by an administrator). Ban history is
also now recorded in the ban file, and much more information about the
ban is stored (whitelists and administrators also have extra
information).
To support the new information without losing important information,
this commit also introduces a new migration path for editable settings
(both from legacy to the new format, and between versions). Examples
of how to do this correctly, and migrate to new versions of a settings
file, are in the settings/ subdirectory.
As part of this effort, editable settings have been revamped to
guarantee atomic saves (due to the increased amount of information in
each file), some latent bugs in networking were fixed, and server-cli
has been updated to go through StructOpt for both calls through TUI
and argv, greatly simplifying parsing logic.
2021-05-08 18:22:21 +00:00
|
|
|
Message::Shutdown {
|
|
|
|
command: Shutdown::Immediate,
|
|
|
|
} => {
|
2020-09-20 02:40:26 +00:00
|
|
|
info!("Closing the server");
|
|
|
|
break;
|
|
|
|
},
|
Added non-admin moderators and timed bans.
The security model has been updated to reflect this change (for example,
moderators cannot revert a ban by an administrator). Ban history is
also now recorded in the ban file, and much more information about the
ban is stored (whitelists and administrators also have extra
information).
To support the new information without losing important information,
this commit also introduces a new migration path for editable settings
(both from legacy to the new format, and between versions). Examples
of how to do this correctly, and migrate to new versions of a settings
file, are in the settings/ subdirectory.
As part of this effort, editable settings have been revamped to
guarantee atomic saves (due to the increased amount of information in
each file), some latent bugs in networking were fixed, and server-cli
has been updated to go through StructOpt for both calls through TUI
and argv, greatly simplifying parsing logic.
2021-05-08 18:22:21 +00:00
|
|
|
Message::Shared(SharedCommand::Admin {
|
|
|
|
command: Admin::Add { username, role },
|
|
|
|
}) => {
|
|
|
|
server.add_admin(&username, role);
|
2020-10-10 06:10:04 +00:00
|
|
|
},
|
Added non-admin moderators and timed bans.
The security model has been updated to reflect this change (for example,
moderators cannot revert a ban by an administrator). Ban history is
also now recorded in the ban file, and much more information about the
ban is stored (whitelists and administrators also have extra
information).
To support the new information without losing important information,
this commit also introduces a new migration path for editable settings
(both from legacy to the new format, and between versions). Examples
of how to do this correctly, and migrate to new versions of a settings
file, are in the settings/ subdirectory.
As part of this effort, editable settings have been revamped to
guarantee atomic saves (due to the increased amount of information in
each file), some latent bugs in networking were fixed, and server-cli
has been updated to go through StructOpt for both calls through TUI
and argv, greatly simplifying parsing logic.
2021-05-08 18:22:21 +00:00
|
|
|
Message::Shared(SharedCommand::Admin {
|
|
|
|
command: Admin::Remove { username },
|
|
|
|
}) => {
|
2020-10-10 06:10:04 +00:00
|
|
|
server.remove_admin(&username);
|
|
|
|
},
|
Added non-admin moderators and timed bans.
The security model has been updated to reflect this change (for example,
moderators cannot revert a ban by an administrator). Ban history is
also now recorded in the ban file, and much more information about the
ban is stored (whitelists and administrators also have extra
information).
To support the new information without losing important information,
this commit also introduces a new migration path for editable settings
(both from legacy to the new format, and between versions). Examples
of how to do this correctly, and migrate to new versions of a settings
file, are in the settings/ subdirectory.
As part of this effort, editable settings have been revamped to
guarantee atomic saves (due to the increased amount of information in
each file), some latent bugs in networking were fixed, and server-cli
has been updated to go through StructOpt for both calls through TUI
and argv, greatly simplifying parsing logic.
2021-05-08 18:22:21 +00:00
|
|
|
Message::LoadArea { view_distance } => {
|
2021-04-15 18:07:46 +00:00
|
|
|
#[cfg(feature = "worldgen")]
|
2021-03-13 06:48:30 +00:00
|
|
|
server.create_centered_persister(view_distance);
|
|
|
|
},
|
Added non-admin moderators and timed bans.
The security model has been updated to reflect this change (for example,
moderators cannot revert a ban by an administrator). Ban history is
also now recorded in the ban file, and much more information about the
ban is stored (whitelists and administrators also have extra
information).
To support the new information without losing important information,
this commit also introduces a new migration path for editable settings
(both from legacy to the new format, and between versions). Examples
of how to do this correctly, and migrate to new versions of a settings
file, are in the settings/ subdirectory.
As part of this effort, editable settings have been revamped to
guarantee atomic saves (due to the increased amount of information in
each file), some latent bugs in networking were fixed, and server-cli
has been updated to go through StructOpt for both calls through TUI
and argv, greatly simplifying parsing logic.
2021-05-08 18:22:21 +00:00
|
|
|
Message::SqlLogMode { mode } => {
|
|
|
|
server.set_sql_log_mode(mode);
|
2021-04-13 22:05:47 +00:00
|
|
|
},
|
|
|
|
Message::DisconnectAllClients => {
|
|
|
|
server.disconnect_all_clients();
|
|
|
|
},
|
2020-10-03 19:10:34 +00:00
|
|
|
},
|
2020-09-20 02:40:26 +00:00
|
|
|
Err(mpsc::TryRecvError::Empty) | Err(mpsc::TryRecvError::Disconnected) => {},
|
|
|
|
}
|
|
|
|
}
|
2020-07-28 10:02:48 +00:00
|
|
|
|
2020-11-22 08:50:25 +00:00
|
|
|
drop(guard);
|
2020-07-28 10:02:48 +00:00
|
|
|
// Wait for the next tick.
|
2020-11-10 12:30:01 +00:00
|
|
|
clock.tick();
|
2020-11-22 08:50:25 +00:00
|
|
|
#[cfg(feature = "tracy")]
|
2022-05-10 07:28:13 +00:00
|
|
|
common_base::tracy_client::frame_mark();
|
2020-07-28 10:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|