Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for custom tablist header and footer #513

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions feather/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ uuid = { version = "0.8", features = [ "v4" ] }
libcraft-core = { path = "../../libcraft/core" }
libcraft-inventory = { path = "../../libcraft/inventory" }
libcraft-items = { path = "../../libcraft/items" }
libcraft-text = { path = "../../libcraft/text" }
rayon = "1.5"
worldgen = { path = "../worldgen", package = "feather-worldgen" }
rand = "0.8"
10 changes: 10 additions & 0 deletions feather/common/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use base::{ChunkHandle, ChunkPosition};
use libcraft_text::Text;

use crate::view::View;

Expand Down Expand Up @@ -58,3 +59,12 @@ pub struct ChunkLoadEvent {
pub struct ChunkLoadFailEvent {
pub position: ChunkPosition,
}

#[derive(Debug, Clone)]
pub struct TablistHeaderFooter {
pub header: Text,
pub footer: Text,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feather_common::events is for events, while TablistHeaderFooter is a resource. I'm not sure what file would fit best for this small struct, but definitely not events.rs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does it need to be for plugins to get to it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quill/common. Quill doesn't support resources though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can create feather/common/src/tablist.rs or quill/common/src/tablist.rs, but not in feather/server. No other crate can access feather-server.


#[derive(Debug)]
pub struct TablistExtrasUpdateEvent;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#522 is now merged, so quill-compatible events should be in quill/common/srs/events/change.rs, implement Serialize, Deserialize, Clone, be defined in quill/common/src/component.rs in HostComponent enum and have bincode_component_impl! in the end.

1 change: 1 addition & 0 deletions feather/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ uuid = "0.8"
slab = "0.4"
libcraft-core = { path = "../../libcraft/core" }
libcraft-items = { path = "../../libcraft/items" }
libcraft-text = { path = "../../libcraft/text" }
worldgen = { path = "../worldgen", package = "feather-worldgen" }

[features]
Expand Down
2 changes: 2 additions & 0 deletions feather/server/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ motd = "A Feather server"
max_players = 16
default_gamemode = "creative"
view_distance = 12
default_header = ""
default_footer = ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users won't understand what header/footer is, I think it should be named like tablist_header or playerlist_header, and have default values to make it even more obvious (like vanilla's "A Minecraft Server" default motd).


[log]
# If you prefer less verbose logs, switch this to "info".
Expand Down
13 changes: 12 additions & 1 deletion feather/server/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ use common::{
Window,
};
use libcraft_items::InventorySlot;
use packets::server::{Particle, SetSlot, SpawnLivingEntity, UpdateLight, WindowConfirmation};
use packets::server::{
Particle, PlayerListHeaderAndFooter, SetSlot, SpawnLivingEntity, UpdateLight,
WindowConfirmation,
};
use protocol::packets::server::{
EntityPosition, EntityPositionAndRotation, EntityTeleport, HeldItemChange, PlayerAbilities,
};
Expand Down Expand Up @@ -331,6 +334,14 @@ impl Client {
self.send_packet(PlayerInfo::RemovePlayers(vec![uuid]));
}

pub fn send_tablist_header_footer(&self, header: &str, footer: &str) {
log::trace!("Sending PlayerListHeaderAndFooter ({},{})", header, footer);
self.send_packet(PlayerListHeaderAndFooter {
header: header.to_string(),
footer: footer.to_string(),
})
}

pub fn unload_entity(&self, id: NetworkId) {
log::trace!("Unloading {:?} on {}", id, self.username);
self.sent_entities.borrow_mut().remove(&id);
Expand Down
6 changes: 5 additions & 1 deletion feather/server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::{fs, net::IpAddr, path::Path, str::FromStr};

use anyhow::Context;
use base::Gamemode;
use base::{Gamemode, Text};
use serde::{Deserialize, Deserializer};

use crate::{favicon::Favicon, Options};
Expand Down Expand Up @@ -66,6 +66,8 @@ impl Config {
view_distance: self.server.view_distance,
max_players: self.server.max_players,
default_gamemode: self.server.default_gamemode,
default_header: self.server.default_header.clone(),
default_footer: self.server.default_footer.clone(),
proxy_mode: match self.proxy.proxy_mode {
ProxyMode::None => None,
ProxyMode::Bungee => Some(crate::options::ProxyMode::Bungeecord),
Expand All @@ -90,6 +92,8 @@ pub struct ServerConfig {
pub max_players: u32,
pub default_gamemode: Gamemode,
pub view_distance: u32,
pub default_header: Text,
pub default_footer: Text,
}

#[derive(Debug, Deserialize)]
Expand Down
8 changes: 7 additions & 1 deletion feather/server/src/options.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use base::Gamemode;
use base::{Gamemode, Text};

use crate::favicon::Favicon;

Expand Down Expand Up @@ -28,6 +28,12 @@ pub struct Options {
/// The default gamemode for new players.
pub default_gamemode: Gamemode,

/// The default tablist header.
pub default_header: Text,

/// The default tablist footer.
pub default_footer: Text,

/// Proxy IP forwarding mode
pub proxy_mode: Option<ProxyMode>,
// HMAC key used with Velocity IP forwarding.
Expand Down
2 changes: 1 addition & 1 deletion feather/server/src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn register(server: Server, game: &mut Game, systems: &mut SystemExecutor<Ga
view::register(game, systems);
crate::chunk_subscriptions::register(systems);
player_leave::register(systems);
tablist::register(systems);
tablist::register(game, systems);
block::register(systems);
entity::register(game, systems);
chat::register(game, systems);
Expand Down
46 changes: 43 additions & 3 deletions feather/server/src/systems/tablist.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
//! Sends tablist info to clients via the Player Info packet.

use base::{Gamemode, ProfileProperty};
use common::Game;
use common::{
events::{TablistExtrasUpdateEvent, TablistHeaderFooter},
Game,
};
use ecs::{SysResult, SystemExecutor};
use quill_common::events::{EntityRemoveEvent, PlayerJoinEvent};
use quill_common::{components::Name, entities::Player};
use uuid::Uuid;

use crate::{ClientId, Server};

pub fn register(systems: &mut SystemExecutor<Game>) {
pub fn register(game: &mut Game, systems: &mut SystemExecutor<Game>) {
let server_options = game.resources.get::<Server>().unwrap().options.clone();

game.insert_resource(TablistHeaderFooter {
header: server_options.default_header.clone(),
footer: server_options.default_footer.clone(),
});

systems
.group::<Server>()
.add_system(remove_tablist_players)
.add_system(add_tablist_players);
.add_system(add_tablist_players)
.add_system(update_tablist_header)
.add_system(send_tablist_header_on_join);
}

fn remove_tablist_players(game: &mut Game, server: &mut Server) -> SysResult {
Expand Down Expand Up @@ -60,3 +72,31 @@ fn add_tablist_players(game: &mut Game, server: &mut Server) -> SysResult {
}
Ok(())
}

fn update_tablist_header(game: &mut Game, server: &mut Server) -> SysResult {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It updates not only header, but also footer.

for _ in game.ecs.query::<&TablistExtrasUpdateEvent>().iter() {
let header_footer = game.resources.get::<TablistHeaderFooter>()?;
server.broadcast_with(|client| {
client.send_tablist_header_footer(
&header_footer.header.to_string(),
&header_footer.footer.to_string(),
)
});
}
Ok(())
}

fn send_tablist_header_on_join(game: &mut Game, server: &mut Server) -> SysResult {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sends not only header, but also footer.

for (_, (_, &client_id)) in game.ecs.query::<(&PlayerJoinEvent, &ClientId)>().iter() {
let header_footer = game.resources.get::<TablistHeaderFooter>()?;
server
.clients
.get(client_id)
.unwrap()
.send_tablist_header_footer(
&header_footer.header.to_string(),
&header_footer.footer.to_string(),
);
}
Ok(())
}