mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Allow changing mode only with enabled settings
- send warning in force mode
This commit is contained in:
parent
3fd573f1ec
commit
68a4b269d2
@ -3,12 +3,15 @@
|
|||||||
//! in [do_command].
|
//! in [do_command].
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
client::Client,
|
||||||
|
login_provider::LoginProvider,
|
||||||
settings::{
|
settings::{
|
||||||
Ban, BanAction, BanInfo, EditableSetting, SettingError, WhitelistInfo, WhitelistRecord,
|
Ban, BanAction, BanInfo, EditableSetting, SettingError, WhitelistInfo, WhitelistRecord,
|
||||||
},
|
},
|
||||||
sys::terrain::NpcData,
|
sys::terrain::NpcData,
|
||||||
|
wiring,
|
||||||
wiring::{Logic, OutputFormula},
|
wiring::{Logic, OutputFormula},
|
||||||
Server, SpawnPoint, StateExt,
|
Server, Settings, SpawnPoint, StateExt,
|
||||||
};
|
};
|
||||||
use assets::AssetExt;
|
use assets::AssetExt;
|
||||||
use authc::Uuid;
|
use authc::Uuid;
|
||||||
@ -52,7 +55,6 @@ use vek::*;
|
|||||||
use wiring::{Circuit, Wire, WiringAction, WiringActionEffect, WiringElement};
|
use wiring::{Circuit, Wire, WiringAction, WiringActionEffect, WiringElement};
|
||||||
use world::{site::SiteKind, util::Sampler};
|
use world::{site::SiteKind, util::Sampler};
|
||||||
|
|
||||||
use crate::{client::Client, login_provider::LoginProvider, wiring};
|
|
||||||
use std::ops::DerefMut;
|
use std::ops::DerefMut;
|
||||||
use tracing::{error, info, warn};
|
use tracing::{error, info, warn};
|
||||||
|
|
||||||
@ -3105,6 +3107,10 @@ fn handle_battlemode(
|
|||||||
_action: &ChatCommand,
|
_action: &ChatCommand,
|
||||||
) -> CmdResult<()> {
|
) -> CmdResult<()> {
|
||||||
let ecs = server.state.ecs();
|
let ecs = server.state.ecs();
|
||||||
|
let settings = ecs.read_resource::<Settings>();
|
||||||
|
if !settings.battle_mode.allow_choosing() {
|
||||||
|
return Err("Toggling battlemode is disabled.".to_owned());
|
||||||
|
}
|
||||||
if let Some(mode) = parse_args!(args, String) {
|
if let Some(mode) = parse_args!(args, String) {
|
||||||
let world = &server.world;
|
let world = &server.world;
|
||||||
let index = &server.index;
|
let index = &server.index;
|
||||||
@ -3113,7 +3119,7 @@ fn handle_battlemode(
|
|||||||
let chunk_pos = Vec2::from(pos.0).map(|x: f32| x as i32);
|
let chunk_pos = Vec2::from(pos.0).map(|x: f32| x as i32);
|
||||||
let chunk = sim
|
let chunk = sim
|
||||||
.get(chunk_pos)
|
.get(chunk_pos)
|
||||||
.ok_or_else(|| "Cannot get current chunk for target")?;
|
.ok_or("Cannot get current chunk for target")?;
|
||||||
let site_ids = &chunk.sites;
|
let site_ids = &chunk.sites;
|
||||||
let mut in_town = false;
|
let mut in_town = false;
|
||||||
for site_id in site_ids.iter() {
|
for site_id in site_ids.iter() {
|
||||||
@ -3131,7 +3137,7 @@ fn handle_battlemode(
|
|||||||
let mut players = ecs.write_storage::<comp::Player>();
|
let mut players = ecs.write_storage::<comp::Player>();
|
||||||
let mut player = players
|
let mut player = players
|
||||||
.get_mut(target)
|
.get_mut(target)
|
||||||
.ok_or_else(|| "Cannot get player component for target".to_owned())?;
|
.ok_or("Cannot get player component for target")?;
|
||||||
// FIXME: handle cooldown before merge here!
|
// FIXME: handle cooldown before merge here!
|
||||||
//
|
//
|
||||||
set_battlemode(&mode, player.deref_mut(), server, client)
|
set_battlemode(&mode, player.deref_mut(), server, client)
|
||||||
@ -3139,7 +3145,7 @@ fn handle_battlemode(
|
|||||||
let players = ecs.read_storage::<comp::Player>();
|
let players = ecs.read_storage::<comp::Player>();
|
||||||
let player = players
|
let player = players
|
||||||
.get(target)
|
.get(target)
|
||||||
.ok_or_else(|| "Cannot get player component for target".to_string())?;
|
.ok_or("Cannot get player component for target")?;
|
||||||
server.notify_client(
|
server.notify_client(
|
||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(
|
ServerGeneral::server_msg(
|
||||||
@ -3160,10 +3166,20 @@ fn handle_battlemode_force(
|
|||||||
) -> CmdResult<()> {
|
) -> CmdResult<()> {
|
||||||
let mode = parse_args!(args, String).ok_or_else(|| action.help_string())?;
|
let mode = parse_args!(args, String).ok_or_else(|| action.help_string())?;
|
||||||
let ecs = server.state.ecs();
|
let ecs = server.state.ecs();
|
||||||
|
let settings = ecs.read_resource::<Settings>();
|
||||||
|
if !settings.battle_mode.allow_choosing() {
|
||||||
|
server.notify_client(
|
||||||
|
client,
|
||||||
|
ServerGeneral::server_msg(
|
||||||
|
ChatType::CommandInfo,
|
||||||
|
"Warning! Forcing battle_mode while not enabled in settings!".to_owned(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
let mut players = ecs.write_storage::<comp::Player>();
|
let mut players = ecs.write_storage::<comp::Player>();
|
||||||
let mut player = players
|
let mut player = players
|
||||||
.get_mut(target)
|
.get_mut(target)
|
||||||
.ok_or_else(|| "Cannot get player component for target".to_owned())?;
|
.ok_or("Cannot get player component for target")?;
|
||||||
set_battlemode(&mode, player.deref_mut(), server, client)
|
set_battlemode(&mode, player.deref_mut(), server, client)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +46,15 @@ pub enum ServerBattleMode {
|
|||||||
PerPlayer { default: BattleMode },
|
PerPlayer { default: BattleMode },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ServerBattleMode {
|
||||||
|
pub fn allow_choosing(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
ServerBattleMode::Global { .. } => false,
|
||||||
|
ServerBattleMode::PerPlayer { .. } => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
|
Loading…
Reference in New Issue
Block a user