mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'aweinstock/validate-char-create' into 'master'
Validate starting item and body type server-side. See merge request veloren/veloren!1869
This commit is contained in:
commit
524ded586d
@ -2,6 +2,15 @@ use crate::persistence::character_loader::CharacterLoader;
|
|||||||
use common::comp::{inventory::loadout_builder::LoadoutBuilder, Body, Inventory, Item, Stats};
|
use common::comp::{inventory::loadout_builder::LoadoutBuilder, Body, Inventory, Item, Stats};
|
||||||
use specs::{Entity, ReadExpect};
|
use specs::{Entity, ReadExpect};
|
||||||
|
|
||||||
|
const VALID_STARTER_ITEMS: [&str; 6] = [
|
||||||
|
"common.items.weapons.hammer.starter_hammer",
|
||||||
|
"common.items.weapons.bow.starter",
|
||||||
|
"common.items.weapons.axe.starter_axe",
|
||||||
|
"common.items.weapons.staff.starter_staff",
|
||||||
|
"common.items.weapons.sword.starter",
|
||||||
|
"common.items.weapons.sceptre.starter_sceptre",
|
||||||
|
];
|
||||||
|
|
||||||
pub fn create_character(
|
pub fn create_character(
|
||||||
entity: Entity,
|
entity: Entity,
|
||||||
player_uuid: String,
|
player_uuid: String,
|
||||||
@ -10,13 +19,23 @@ pub fn create_character(
|
|||||||
body: Body,
|
body: Body,
|
||||||
character_loader: &ReadExpect<'_, CharacterLoader>,
|
character_loader: &ReadExpect<'_, CharacterLoader>,
|
||||||
) {
|
) {
|
||||||
|
// quick fix whitelist validation for now; eventually replace the
|
||||||
|
// `Option<String>` with an index into a server-provided list of starter
|
||||||
|
// items, and replace `comp::body::Body` with `comp::body::humanoid::Body`
|
||||||
|
// throughout the messages involved
|
||||||
|
let tool_id = match character_tool {
|
||||||
|
Some(tool_id) if VALID_STARTER_ITEMS.contains(&&*tool_id) => tool_id,
|
||||||
|
_ => return,
|
||||||
|
};
|
||||||
|
if !matches!(body, Body::Humanoid(_)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let stats = Stats::new(character_alias.to_string());
|
let stats = Stats::new(character_alias.to_string());
|
||||||
|
|
||||||
let loadout = LoadoutBuilder::new()
|
let loadout = LoadoutBuilder::new()
|
||||||
.defaults()
|
.defaults()
|
||||||
.active_item(Some(Item::new_from_asset_expect(
|
.active_item(Some(Item::new_from_asset_expect(&tool_id)))
|
||||||
character_tool.as_deref().unwrap(),
|
|
||||||
)))
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let mut inventory = Inventory::new_with_loadout(loadout);
|
let mut inventory = Inventory::new_with_loadout(loadout);
|
||||||
|
Loading…
Reference in New Issue
Block a user