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 3 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
9 changes: 9 additions & 0 deletions feather/common/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,12 @@ pub struct EntityRemoveEvent;
/// Triggered when an entity is added into the world.
#[derive(Debug)]
pub struct EntityCreateEvent;

#[derive(Debug, Clone)]
pub struct TablistHeaderFooter {
pub header: String,
pub footer: String,
Kecerim24 marked this conversation as resolved.
Show resolved Hide resolved
}

#[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.

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
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
34 changes: 31 additions & 3 deletions feather/server/src/systems/tablist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use base::{Gamemode, ProfileProperty};
use common::{
events::{EntityRemoveEvent, PlayerJoinEvent},
events::{EntityRemoveEvent, PlayerJoinEvent, TablistExtrasUpdateEvent, TablistHeaderFooter},
Game,
};
use ecs::{SysResult, SystemExecutor};
Expand All @@ -11,11 +11,17 @@ use uuid::Uuid;

use crate::{ClientId, Server};

pub fn register(systems: &mut SystemExecutor<Game>) {
pub fn register(game: &mut Game, systems: &mut SystemExecutor<Game>) {
game.insert_resource(TablistHeaderFooter {
header: "{\"text\":\"\"}".to_string(),
footer: "{\"text\":\"\"}".to_string(),
});
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be great if you add the initial values to config.toml

Copy link
Author

Choose a reason for hiding this comment

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

I don't think it's that important to have default values, because this isn't a vanilla feature. If anyone needs this, it would be better to use a plugin.

Copy link
Contributor

Choose a reason for hiding this comment

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

Feather is not even close to be fully survival-compatible, so the only usage for Feather in production will be lobbies and mini-games. And there's 99% chance that everyone needs this feature. If someone wants more advanced features (like placeholders, animations), it would still be possible to override the resource by a plugin. I don't know why vanilla server doesn't have this feature, but lack of feature is not a good thing to copy.

Copy link
Author

Choose a reason for hiding this comment

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

Then in what format and where in the config would you like it?

Copy link
Contributor

Choose a reason for hiding this comment

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

In what format

Just like motd, using Text::from(str). Or there is libcraft_text::markdown module that allows writing rich text components in format @red some text @on_hover @show_text @green some hover text, but I don't see any existing usage or documentation for this format.

Where

[server] section

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 @@ -62,3 +68,25 @@ 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, &header_footer.footer)
});
}
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, &header_footer.footer);
}
Ok(())
}