Admin status added when registering; cargo fmt

This commit is contained in:
CapsizeGlimmer 2020-06-23 23:29:46 -04:00 committed by Forest Anderson
parent 92127292d4
commit 59db2fcd3b
8 changed files with 62 additions and 23 deletions

View File

@ -1,12 +1,12 @@
use crate::{assets, comp, npc}; use crate::{assets, comp, npc};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use tracing::warn;
use std::{ use std::{
collections::HashMap, collections::HashMap,
fmt::{self, Display}, fmt::{self, Display},
path::Path, path::Path,
str::FromStr, str::FromStr,
}; };
use tracing::warn;
/// Struct representing a command that a user can run from server chat. /// Struct representing a command that a user can run from server chat.
pub struct ChatCommandData { pub struct ChatCommandData {

View File

@ -1,4 +1,5 @@
use specs::{Component, NullStorage}; use specs::{Component, NullStorage};
use std::ops::Deref;
#[derive(Clone, Copy, Default)] #[derive(Clone, Copy, Default)]
pub struct Admin; pub struct Admin;
@ -6,3 +7,12 @@ pub struct Admin;
impl Component for Admin { impl Component for Admin {
type Storage = NullStorage<Self>; type Storage = NullStorage<Self>;
} }
/// List of admin usernames. This is stored as a specs resource so that the list
/// can be read by specs systems.
pub struct AdminList(pub Vec<String>);
impl Deref for AdminList {
type Target = Vec<String>;
fn deref(&self) -> &Vec<String> { &self.0 }
}

View File

@ -18,7 +18,7 @@ mod visual;
// Reexports // Reexports
pub use ability::{CharacterAbility, CharacterAbilityType, ItemConfig, Loadout}; pub use ability::{CharacterAbility, CharacterAbilityType, ItemConfig, Loadout};
pub use admin::Admin; pub use admin::{Admin, AdminList};
pub use agent::{Agent, Alignment}; pub use agent::{Agent, Alignment};
pub use body::{ pub use body::{
biped_large, bird_medium, bird_small, critter, dragon, fish_medium, fish_small, golem, biped_large, bird_medium, bird_small, critter, dragon, fish_medium, fish_small, golem,

View File

@ -105,6 +105,17 @@ impl Server {
state state
.ecs_mut() .ecs_mut()
.insert(CharacterLoader::new(settings.persistence_db_dir.clone())); .insert(CharacterLoader::new(settings.persistence_db_dir.clone()));
state
.ecs_mut()
.insert(persistence::character::CharacterUpdater::new(
settings.persistence_db_dir.clone(),
));
state.ecs_mut().insert(crate::settings::PersistenceDBDir(
settings.persistence_db_dir.clone(),
));
state
.ecs_mut()
.insert(comp::AdminList(settings.admins.clone()));
// System timers for performance monitoring // System timers for performance monitoring
state.ecs_mut().insert(sys::EntitySyncTimer::default()); state.ecs_mut().insert(sys::EntitySyncTimer::default());

View File

@ -10,11 +10,11 @@ use common::{
sync::{Uid, UidAllocator, WorldSyncExt}, sync::{Uid, UidAllocator, WorldSyncExt},
util::Dir, util::Dir,
}; };
use tracing::warn;
use specs::{ use specs::{
saveload::MarkerAllocator, Builder, Entity as EcsEntity, EntityBuilder as EcsEntityBuilder, saveload::MarkerAllocator, Builder, Entity as EcsEntity, EntityBuilder as EcsEntityBuilder,
Join, WorldExt, Join, WorldExt,
}; };
use tracing::warn;
use vek::*; use vek::*;
pub trait StateExt { pub trait StateExt {
@ -212,6 +212,8 @@ impl StateExt for State {
fn update_character_data(&mut self, entity: EcsEntity, components: PersistedComponents) { fn update_character_data(&mut self, entity: EcsEntity, components: PersistedComponents) {
let (body, stats, inventory, loadout) = components; let (body, stats, inventory, loadout) = components;
// Make sure physics are accepted.
self.write_component(entity, comp::ForceUpdate);
// Notify clients of a player list update // Notify clients of a player list update
let client_uid = self let client_uid = self

View File

@ -5,8 +5,8 @@ use crate::{
}; };
use common::{ use common::{
comp::{ comp::{
Admin, CanBuild, ChatMode, ChatMsg, ChatType, ControlEvent, Controller, ForceUpdate, Ori, Admin, AdminList, CanBuild, ChatMode, ChatMsg, ChatType, ControlEvent, Controller,
Player, Pos, Stats, Vel, ForceUpdate, Ori, Player, Pos, Stats, Vel,
}, },
event::{EventBus, ServerEvent}, event::{EventBus, ServerEvent},
msg::{ msg::{
@ -34,7 +34,6 @@ impl<'a> System<'a> for Sys {
ReadExpect<'a, CharacterLoader>, ReadExpect<'a, CharacterLoader>,
ReadExpect<'a, TerrainGrid>, ReadExpect<'a, TerrainGrid>,
Write<'a, SysTimer<Self>>, Write<'a, SysTimer<Self>>,
ReadStorage<'a, Admin>,
ReadStorage<'a, Uid>, ReadStorage<'a, Uid>,
ReadStorage<'a, CanBuild>, ReadStorage<'a, CanBuild>,
ReadStorage<'a, ForceUpdate>, ReadStorage<'a, ForceUpdate>,
@ -42,6 +41,8 @@ impl<'a> System<'a> for Sys {
ReadStorage<'a, ChatMode>, ReadStorage<'a, ChatMode>,
WriteExpect<'a, AuthProvider>, WriteExpect<'a, AuthProvider>,
Write<'a, BlockChange>, Write<'a, BlockChange>,
ReadExpect<'a, AdminList>,
WriteStorage<'a, Admin>,
WriteStorage<'a, Pos>, WriteStorage<'a, Pos>,
WriteStorage<'a, Vel>, WriteStorage<'a, Vel>,
WriteStorage<'a, Ori>, WriteStorage<'a, Ori>,
@ -64,7 +65,6 @@ impl<'a> System<'a> for Sys {
character_loader, character_loader,
terrain, terrain,
mut timer, mut timer,
admins,
uids, uids,
can_build, can_build,
force_updates, force_updates,
@ -72,6 +72,8 @@ impl<'a> System<'a> for Sys {
chat_modes, chat_modes,
mut accounts, mut accounts,
mut block_changes, mut block_changes,
admin_list,
mut admins,
mut positions, mut positions,
mut velocities, mut velocities,
mut orientations, mut orientations,
@ -163,6 +165,7 @@ impl<'a> System<'a> for Sys {
let vd = view_distance let vd = view_distance
.map(|vd| vd.min(settings.max_view_distance.unwrap_or(vd))); .map(|vd| vd.min(settings.max_view_distance.unwrap_or(vd)));
let player = Player::new(username, None, vd, uuid); let player = Player::new(username, None, vd, uuid);
let is_admin = admin_list.contains(&username);
if !player.is_valid() { if !player.is_valid() {
// Invalid player // Invalid player
@ -175,6 +178,12 @@ impl<'a> System<'a> for Sys {
// Add Player component to this client // Add Player component to this client
let _ = players.insert(entity, player); let _ = players.insert(entity, player);
// Give the Admin component to the player if their name exists in
// admin list
if is_admin {
let _ = admins.insert(entity, Admin);
}
// Tell the client its request was successful. // Tell the client its request was successful.
client.allow_state(ClientState::Registered); client.allow_state(ClientState::Registered);
@ -348,7 +357,11 @@ impl<'a> System<'a> for Sys {
Err(ChatMsgValidationError::TooLong) => { Err(ChatMsgValidationError::TooLong) => {
let max = MAX_BYTES_CHAT_MSG; let max = MAX_BYTES_CHAT_MSG;
let len = message.len(); let len = message.len();
tracing::warn!(?len, ?max, "Recieved a chat message that's too long") tracing::warn!(
?len,
?max,
"Recieved a chat message that's too long"
)
}, },
}, },
ClientState::Pending => {}, ClientState::Pending => {},

View File

@ -284,7 +284,11 @@ impl<'a> Widget for Overhead<'a> {
} }
} }
text_shadow.set(state.ids.speech_bubble_shadow, ui); text_shadow.set(state.ids.speech_bubble_shadow, ui);
let icon = if self.settings.speech_bubble_icon { bubble_icon(&bubble, &self.imgs) } else { self.imgs.nothing }; let icon = if self.settings.speech_bubble_icon {
bubble_icon(&bubble, &self.imgs)
} else {
self.imgs.nothing
};
Image::new(icon) Image::new(icon)
.w_h(16.0, 16.0) .w_h(16.0, 16.0)
.top_left_with_margin_on(state.ids.speech_bubble_text, -16.0) .top_left_with_margin_on(state.ids.speech_bubble_text, -16.0)

View File

@ -950,11 +950,11 @@ impl<'a> Widget for SettingsWindow<'a> {
self.imgs.checkbox, self.imgs.checkbox,
self.imgs.checkbox_checked, self.imgs.checkbox_checked,
) )
.down_from(state.ids.speech_bubble_text, 10.0) .down_from(state.ids.speech_bubble_text, 10.0)
.w_h(18.0, 18.0) .w_h(18.0, 18.0)
.hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo) .hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo)
.press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked) .press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked)
.set(state.ids.speech_bubble_dark_mode_button, ui); .set(state.ids.speech_bubble_dark_mode_button, ui);
if self.global_state.settings.gameplay.speech_bubble_dark_mode if self.global_state.settings.gameplay.speech_bubble_dark_mode
!= speech_bubble_dark_mode != speech_bubble_dark_mode
{ {
@ -962,14 +962,14 @@ impl<'a> Widget for SettingsWindow<'a> {
} }
Text::new( Text::new(
&self &self
.localized_strings .localized_strings
.get("hud.settings.speech_bubble_dark_mode"), .get("hud.settings.speech_bubble_dark_mode"),
) )
.right_from(state.ids.speech_bubble_dark_mode_button, 10.0) .right_from(state.ids.speech_bubble_dark_mode_button, 10.0)
.font_size(self.fonts.cyri.scale(15)) .font_size(self.fonts.cyri.scale(15))
.font_id(self.fonts.cyri.conrod_id) .font_id(self.fonts.cyri.conrod_id)
.color(TEXT_COLOR) .color(TEXT_COLOR)
.set(state.ids.speech_bubble_dark_mode_text, ui); .set(state.ids.speech_bubble_dark_mode_text, ui);
// Speech bubble icon // Speech bubble icon
let speech_bubble_icon = ToggleButton::new( let speech_bubble_icon = ToggleButton::new(
self.global_state.settings.gameplay.speech_bubble_icon, self.global_state.settings.gameplay.speech_bubble_icon,
@ -981,8 +981,7 @@ impl<'a> Widget for SettingsWindow<'a> {
.hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo) .hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo)
.press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked) .press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked)
.set(state.ids.speech_bubble_icon_button, ui); .set(state.ids.speech_bubble_icon_button, ui);
if self.global_state.settings.gameplay.speech_bubble_icon != speech_bubble_icon if self.global_state.settings.gameplay.speech_bubble_icon != speech_bubble_icon {
{
events.push(Event::SpeechBubbleIcon(speech_bubble_icon)); events.push(Event::SpeechBubbleIcon(speech_bubble_icon));
} }
Text::new( Text::new(