Skip to content

Commit 1615989

Browse files
authored
Merge pull request #209 from feather-rs/commands
Initial command support Resolves #161. Changes: * New task manager, used for scheduling async tasks. * New feather-server-commands crate implements all commands * Implement basic commands: * tp * gamemode
2 parents 615ded0 + 26be150 commit 1615989

File tree

45 files changed

+1155
-168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1155
-168
lines changed

Cargo.lock

Lines changed: 90 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ members = [
2525
"server/template",
2626
"server/chat",
2727
"server/chunk",
28+
"server/commands",
2829
"server/config",
2930
"server/entity",
3031
"server/lighting",

core/inventory/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2018"
77
[dependencies]
88
feather-items = { path = "../items" }
99

10-
fecs = { git = "https://github.com/feather-rs/fecs", rev = "fed8bcb516941b12cb980e354e77b699be075a89" }
10+
fecs = { git = "https://github.com/feather-rs/fecs", rev = "0c4838d65b41ca059012b6e9147eabf0c275a731" }
1111
legion = { git = "https://github.com/TomGillen/legion", rev = "bd441f4811e7a9e877a0f479a674bbdbf4e4cda3" }
1212
thiserror = "1.0"
1313
parking_lot = "0.10"

core/network/src/packet.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,11 @@ static PACKET_ID_MAPPINGS: Lazy<AHashMap<PacketId, PacketType>> = Lazy::new(|| {
615615
PacketType::CollectItem,
616616
);
617617

618+
m.insert(
619+
PacketId(0x50, PacketDirection::Clientbound, PacketStage::Play),
620+
PacketType::EntityTeleport,
621+
);
622+
618623
m
619624
});
620625

core/network/src/packets.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ pub static IMPL_MAP: Lazy<AHashMap<PacketType, PacketBuilder>> = Lazy::new(|| {
309309
SpawnPosition,
310310
TimeUpdate,
311311
CollectItem,
312+
EntityTeleport,
312313
Response,
313314
Pong,
314315
);
@@ -2279,3 +2280,14 @@ pub struct CollectItem {
22792280
pub collector: VarInt,
22802281
pub count: VarInt,
22812282
}
2283+
2284+
#[derive(Default, AsAny, Packet, Clone)]
2285+
pub struct EntityTeleport {
2286+
pub entity_id: VarInt,
2287+
pub x: f64,
2288+
pub y: f64,
2289+
pub z: f64,
2290+
pub yaw: u8,
2291+
pub pitch: u8,
2292+
pub on_ground: bool,
2293+
}

core/text/src/lib.rs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use serde::{Deserialize, Deserializer, Serialize, Serializer};
22
use std::borrow::Cow;
3+
use std::fmt::{self, Display, Formatter};
34
use std::str::FromStr;
45
use uuid::Uuid;
56

@@ -64,7 +65,7 @@ impl From<Color> for Text {
6465
}
6566
}
6667

67-
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
68+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
6869
#[serde(rename_all = "snake_case")]
6970
pub enum Style {
7071
Bold,
@@ -95,7 +96,7 @@ impl From<Style> for Text {
9596
}
9697
}
9798

98-
#[derive(Debug, PartialEq)]
99+
#[derive(Clone, Debug, PartialEq, Eq)]
99100
/// Represent all possible keybinds in vanilla.
100101
pub enum Keybind {
101102
Attack,
@@ -108,7 +109,7 @@ pub enum Keybind {
108109
Sneak,
109110
Sprint,
110111
Drop,
111-
Iventory,
112+
Inventory,
112113
Chat,
113114
ListPlayers,
114115
PickBlock,
@@ -176,7 +177,7 @@ where
176177
"key_key.sneak" => Keybind::Sneak,
177178
"key_key.sprint" => Keybind::Sprint,
178179
"key_key.drop" => Keybind::Drop,
179-
"key_key.inventory" => Keybind::Iventory,
180+
"key_key.inventory" => Keybind::Inventory,
180181
"key_key.chat" => Keybind::Chat,
181182
"key_key.playerlist" => Keybind::ListPlayers,
182183
"key_key.pickItem" => Keybind::PickBlock,
@@ -217,7 +218,7 @@ impl From<&Keybind> for String {
217218
Keybind::Sneak => "key_key.sneak",
218219
Keybind::Sprint => "key_key.sprint",
219220
Keybind::Drop => "key_key.drop",
220-
Keybind::Iventory => "key_key.inventory",
221+
Keybind::Inventory => "key_key.inventory",
221222
Keybind::Chat => "key_key.chat",
222223
Keybind::ListPlayers => "key_key.playerlist",
223224
Keybind::PickBlock => "key_key.pickItem",
@@ -246,7 +247,7 @@ impl From<&Keybind> for String {
246247
}
247248
}
248249

249-
#[derive(Debug, PartialEq)]
250+
#[derive(Clone, Debug, PartialEq, Eq)]
250251
/// Represent all possible translation keys in vanilla.
251252
pub enum Translate {
252253
ChatTypeText,
@@ -309,7 +310,7 @@ impl<'a> From<&Translate> for String {
309310
}
310311
}
311312

312-
#[derive(Debug, PartialEq, Serialize, Deserialize)]
313+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
313314
#[serde(tag = "action", content = "value")]
314315
// TODO: Accept any json primitive as string
315316
pub enum Click {
@@ -322,14 +323,14 @@ pub enum Click {
322323
}
323324

324325
#[serde_with::skip_serializing_none]
325-
#[derive(Debug, PartialEq, Serialize, Deserialize)]
326+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
326327
pub struct Entity {
327328
id: Uuid,
328329
ty: Option<Cow<'static, str>>,
329330
name: Cow<'static, str>,
330331
}
331332

332-
#[derive(Debug, PartialEq, Serialize, Deserialize)]
333+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
333334
#[serde(tag = "action", content = "value")]
334335
// TODO: Accept any json primitive as string
335336
pub enum Hover {
@@ -342,7 +343,7 @@ pub enum Hover {
342343
ShowEntity(Entity),
343344
}
344345

345-
#[derive(Debug, PartialEq, Serialize, Deserialize)]
346+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
346347
#[serde(untagged)]
347348
/// Text component can either be Text, Translate, Score, Selector, Keybind, or Nbt.
348349
pub enum TextValue {
@@ -424,7 +425,7 @@ impl TextValue {
424425
}
425426

426427
#[serde_with::skip_serializing_none]
427-
#[derive(Debug, PartialEq, Serialize, Deserialize)]
428+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
428429
/// Text json object that holds all styles.
429430
pub struct TextComponent {
430431
#[serde(flatten)]
@@ -895,7 +896,7 @@ impl From<Text> for TextComponent {
895896
}
896897

897898
/// Text can either be a json String, Object, or an Array.
898-
#[derive(Debug, PartialEq, Serialize, Deserialize)]
899+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
899900
#[serde(untagged)]
900901
pub enum Text {
901902
String(Cow<'static, str>),
@@ -952,6 +953,18 @@ impl Text {
952953
}
953954
}
954955

956+
impl From<Text> for String {
957+
fn from(text: Text) -> Self {
958+
TextRoot(text).into()
959+
}
960+
}
961+
962+
impl Display for Text {
963+
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
964+
f.write_str(&serde_json::to_string(self).unwrap())
965+
}
966+
}
967+
955968
impl From<TextComponent> for Text {
956969
fn from(component: TextComponent) -> Self {
957970
Text::Component(Box::new(component))
@@ -994,19 +1007,13 @@ impl std::ops::Add<Text> for Text {
9941007
}
9951008
}
9961009

997-
impl From<Text> for String {
998-
fn from(text: Text) -> String {
999-
serde_json::to_string(&text).unwrap()
1000-
}
1001-
}
1002-
10031010
/// Ensures Text is either an Array or Object.
10041011
/// This is required at some places when sending to the client.
10051012
pub struct TextRoot(Text);
10061013

10071014
impl From<TextRoot> for String {
10081015
fn from(text: TextRoot) -> String {
1009-
text.0.into()
1016+
text.0.to_string()
10101017
}
10111018
}
10121019

core/util/src/positions.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::ops::{Add, Sub};
66

77
#[macro_export]
88
macro_rules! position {
9-
($x:expr, $y:expr, $z:expr, $pitch:expr, $yaw:expr, $on_ground:expr) => {
9+
($x:expr, $y:expr, $z:expr, $pitch:expr, $yaw:expr, $on_ground:expr $(,)?) => {
1010
$crate::Position {
1111
x: $x,
1212
y: $y,
@@ -16,13 +16,13 @@ macro_rules! position {
1616
on_ground: $on_ground,
1717
}
1818
};
19-
($x:expr, $y:expr, $z:expr, $pitch: expr, $yaw: expr) => {
19+
($x:expr, $y:expr, $z:expr, $pitch: expr, $yaw: expr $(,)?) => {
2020
position!($x, $y, $z, $pitch, $yaw, true)
2121
};
22-
($x:expr, $y:expr, $z:expr) => {
22+
($x:expr, $y:expr, $z:expr $(,)?) => {
2323
position!($x, $y, $z, 0.0, 0.0)
2424
};
25-
($x:expr, $y:expr, $z:expr, $on_ground: expr) => {
25+
($x:expr, $y:expr, $z:expr, $on_ground: expr $(,)?) => {
2626
position!($x, $y, $z, 0.0, 0.0, $on_ground)
2727
};
2828
}

server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ feather-server-util = { path = "util" }
3030
feather-server-weather = { path = "weather" }
3131
feather-server-worldgen = { path = "worldgen" }
3232

33-
fecs = { git = "https://github.com/feather-rs/fecs", rev = "fed8bcb516941b12cb980e354e77b699be075a89" }
33+
fecs = { git = "https://github.com/feather-rs/fecs", rev = "0c4838d65b41ca059012b6e9147eabf0c275a731" }
3434
tokio = { version = "0.2", features = ["full"] }
3535
simple_logger = "1.6"
3636
log = "0.4"

0 commit comments

Comments
 (0)