mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added rules field to server description
This commit is contained in:
parent
05ca01ce89
commit
3d9ab445d9
@ -51,6 +51,7 @@ pub struct ServerInfo {
|
|||||||
pub git_hash: String,
|
pub git_hash: String,
|
||||||
pub git_date: String,
|
pub git_date: String,
|
||||||
pub auth_provider: Option<String>,
|
pub auth_provider: Option<String>,
|
||||||
|
pub rules: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reponse To ClientType
|
/// Reponse To ClientType
|
||||||
|
@ -779,7 +779,7 @@ fn handle_motd(
|
|||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(
|
ServerGeneral::server_msg(
|
||||||
ChatType::CommandInfo,
|
ChatType::CommandInfo,
|
||||||
(*server.editable_settings().server_description).clone(),
|
server.editable_settings().server_description.motd.clone(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -804,8 +804,8 @@ fn handle_set_motd(
|
|||||||
.editable_settings_mut()
|
.editable_settings_mut()
|
||||||
.server_description
|
.server_description
|
||||||
.edit(data_dir.as_ref(), |d| {
|
.edit(data_dir.as_ref(), |d| {
|
||||||
let info = format!("Server description set to {:?}", msg);
|
let info = format!("Server message of the day set to {:?}", msg);
|
||||||
**d = msg;
|
d.motd = msg;
|
||||||
Some(info)
|
Some(info)
|
||||||
});
|
});
|
||||||
drop(data_dir);
|
drop(data_dir);
|
||||||
@ -819,8 +819,8 @@ fn handle_set_motd(
|
|||||||
.editable_settings_mut()
|
.editable_settings_mut()
|
||||||
.server_description
|
.server_description
|
||||||
.edit(data_dir.as_ref(), |d| {
|
.edit(data_dir.as_ref(), |d| {
|
||||||
d.clear();
|
d.motd.clear();
|
||||||
Some("Removed server description".to_string())
|
Some("Removed server message of the day".to_string())
|
||||||
});
|
});
|
||||||
drop(data_dir);
|
drop(data_dir);
|
||||||
edit_setting_feedback(server, client, edit, || {
|
edit_setting_feedback(server, client, edit, || {
|
||||||
|
@ -627,10 +627,11 @@ impl Server {
|
|||||||
let editable_settings = self.state.ecs().fetch::<EditableSettings>();
|
let editable_settings = self.state.ecs().fetch::<EditableSettings>();
|
||||||
ServerInfo {
|
ServerInfo {
|
||||||
name: settings.server_name.clone(),
|
name: settings.server_name.clone(),
|
||||||
description: (*editable_settings.server_description).clone(),
|
description: editable_settings.server_description.motd.clone(),
|
||||||
git_hash: common::util::GIT_HASH.to_string(),
|
git_hash: common::util::GIT_HASH.to_string(),
|
||||||
git_date: common::util::GIT_DATE.to_string(),
|
git_date: common::util::GIT_DATE.to_string(),
|
||||||
auth_provider: settings.auth_server_address.clone(),
|
auth_provider: settings.auth_server_address.clone(),
|
||||||
|
rules: editable_settings.server_description.rules.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,7 +380,7 @@ impl EditableSettings {
|
|||||||
let load = Self::load(data_dir);
|
let load = Self::load(data_dir);
|
||||||
|
|
||||||
let mut server_description = ServerDescription::default();
|
let mut server_description = ServerDescription::default();
|
||||||
*server_description = "Who needs friends anyway?".into();
|
server_description.motd = "Who needs friends anyway?".into();
|
||||||
|
|
||||||
let mut admins = Admins::default();
|
let mut admins = Admins::default();
|
||||||
// TODO: Let the player choose if they want to use admin commands or not
|
// TODO: Let the player choose if they want to use admin commands or not
|
||||||
|
@ -12,20 +12,21 @@ use serde::{Deserialize, Serialize};
|
|||||||
/// ServerDescription, the previously most recent module, and add a new module
|
/// ServerDescription, the previously most recent module, and add a new module
|
||||||
/// for the latest version! Please respect the migration upgrade guarantee
|
/// for the latest version! Please respect the migration upgrade guarantee
|
||||||
/// found in the parent module with any upgrade.
|
/// found in the parent module with any upgrade.
|
||||||
pub use self::v1::*;
|
pub use self::v2::*;
|
||||||
|
|
||||||
/// Versioned settings files, one per version (v0 is only here as an example; we
|
/// Versioned settings files, one per version (v0 is only here as an example; we
|
||||||
/// do not expect to see any actual v0 settings files).
|
/// do not expect to see any actual v0 settings files).
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
pub enum ServerDescriptionRaw {
|
pub enum ServerDescriptionRaw {
|
||||||
V0(v0::ServerDescription),
|
V0(v0::ServerDescription),
|
||||||
V1(ServerDescription),
|
V1(v1::ServerDescription),
|
||||||
|
V2(ServerDescription),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ServerDescription> for ServerDescriptionRaw {
|
impl From<ServerDescription> for ServerDescriptionRaw {
|
||||||
fn from(value: ServerDescription) -> Self {
|
fn from(value: ServerDescription) -> Self {
|
||||||
// Replace variant with that of current latest version.
|
// Replace variant with that of current latest version.
|
||||||
Self::V1(value)
|
Self::V2(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,9 +40,10 @@ impl TryFrom<ServerDescriptionRaw> for (Version, ServerDescription) {
|
|||||||
Ok(match value {
|
Ok(match value {
|
||||||
// Old versions
|
// Old versions
|
||||||
V0(value) => (Version::Old, value.try_into()?),
|
V0(value) => (Version::Old, value.try_into()?),
|
||||||
|
V1(value) => (Version::Old, value.try_into()?),
|
||||||
// Latest version (move to old section using the pattern of other old version when it
|
// Latest version (move to old section using the pattern of other old version when it
|
||||||
// is no longer latest).
|
// is no longer latest).
|
||||||
V1(mut value) => (value.validate()?, value),
|
V2(mut value) => (value.validate()?, value),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,7 +133,6 @@ mod v1 {
|
|||||||
use crate::settings::editable::{EditableSetting, Version};
|
use crate::settings::editable::{EditableSetting, Version};
|
||||||
use core::ops::{Deref, DerefMut};
|
use core::ops::{Deref, DerefMut};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
/* use super::v2 as next; */
|
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, Serialize)]
|
#[derive(Clone, Deserialize, Serialize)]
|
||||||
#[serde(transparent)]
|
#[serde(transparent)]
|
||||||
@ -168,10 +169,67 @@ mod v1 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use super::{v2 as next, MIGRATION_UPGRADE_GUARANTEE};
|
||||||
|
impl TryFrom<ServerDescription> for Final {
|
||||||
|
type Error = <Final as EditableSetting>::Error;
|
||||||
|
|
||||||
|
fn try_from(mut value: ServerDescription) -> Result<Final, Self::Error> {
|
||||||
|
value.validate()?;
|
||||||
|
Ok(next::ServerDescription::migrate(value)
|
||||||
|
.try_into()
|
||||||
|
.expect(MIGRATION_UPGRADE_GUARANTEE))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod v2 {
|
||||||
|
use super::{v1 as prev, Final};
|
||||||
|
use crate::settings::editable::{EditableSetting, Version};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Clone, Deserialize, Serialize)]
|
||||||
|
pub struct ServerDescription {
|
||||||
|
pub motd: String,
|
||||||
|
pub rules: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ServerDescription {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
motd: "This is the best Veloren server".into(),
|
||||||
|
rules: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ServerDescription {
|
||||||
|
/// One-off migration from the previous version. This must be
|
||||||
|
/// guaranteed to produce a valid settings file as long as it is
|
||||||
|
/// called with a valid settings file from the previous version.
|
||||||
|
pub(super) fn migrate(prev: prev::ServerDescription) -> Self {
|
||||||
|
Self {
|
||||||
|
motd: prev.0,
|
||||||
|
rules: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Perform any needed validation on this server description that can't
|
||||||
|
/// be done using parsing.
|
||||||
|
///
|
||||||
|
/// The returned version being "Old" indicates the loaded setting has
|
||||||
|
/// been modified during validation (this is why validate takes
|
||||||
|
/// `&mut self`).
|
||||||
|
pub(super) fn validate(&mut self) -> Result<Version, <Final as EditableSetting>::Error> {
|
||||||
|
Ok(Version::Latest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NOTE: Whenever there is a version upgrade, copy this note as well as the
|
// NOTE: Whenever there is a version upgrade, copy this note as well as the
|
||||||
// commented-out code below to the next version, then uncomment the code
|
// commented-out code below to the next version, then uncomment the code
|
||||||
// for this version.
|
// for this version.
|
||||||
/* impl TryFrom<ServerDescription> for Final {
|
/*
|
||||||
|
use super::{v3 as next, MIGRATION_UPGRADE_GUARANTEE};
|
||||||
|
impl TryFrom<ServerDescription> for Final {
|
||||||
type Error = <Final as EditableSetting>::Error;
|
type Error = <Final as EditableSetting>::Error;
|
||||||
|
|
||||||
fn try_from(mut value: ServerDescription) -> Result<Final, Self::Error> {
|
fn try_from(mut value: ServerDescription) -> Result<Final, Self::Error> {
|
||||||
|
@ -45,10 +45,10 @@ impl Sys {
|
|||||||
) -> Result<(), crate::error::Error> {
|
) -> Result<(), crate::error::Error> {
|
||||||
let mut send_join_messages = || -> Result<(), crate::error::Error> {
|
let mut send_join_messages = || -> Result<(), crate::error::Error> {
|
||||||
// Give the player a welcome message
|
// Give the player a welcome message
|
||||||
if !editable_settings.server_description.is_empty() {
|
if !editable_settings.server_description.motd.is_empty() {
|
||||||
client.send(ServerGeneral::server_msg(
|
client.send(ServerGeneral::server_msg(
|
||||||
ChatType::CommandInfo,
|
ChatType::CommandInfo,
|
||||||
editable_settings.server_description.as_str(),
|
editable_settings.server_description.motd.as_str(),
|
||||||
))?;
|
))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user