diff --git a/crates/proto/UPSTREAM.md b/crates/proto/UPSTREAM.md index f9a7792..eb0261a 100644 --- a/crates/proto/UPSTREAM.md +++ b/crates/proto/UPSTREAM.md @@ -106,3 +106,14 @@ against or offered back to upstream. handed those fewer than 32 bytes to `from_short`, which refused them: one identity in 256 (the official client's ones included) could not be imported. The scalar is padded to 32 bytes now; a test round-trips such keys. +13. **Channel banners** (`tsproto-structs/declarations/Messages.toml`, `Book.toml`). + TeamSpeak 6 channels have a banner picture, `channel_banner_gfx_url` and + `channel_banner_mode`, which its server sends in `channellist`, + `notifychannelcreated` and `notifychanneledited` (verified against + 6.0.0-beta13.1; upstream declared them for `channellist` only, so creating + or editing a channel logged "Unknown argument" and lost them). The book's + `Channel` keeps them as `banner_gfx_url` and `banner_mode`. The mode stays + a string, as upstream declared it, so a value the parser does not know + cannot drop the whole channel list; its numbers are those of + `HostBannerMode` (the server's `channeledit` documentation: 0 as it is, + 1 stretched, 2 scaled keeping the aspect ratio). diff --git a/crates/proto/tsproto-structs/declarations/Book.toml b/crates/proto/tsproto-structs/declarations/Book.toml index cd8d5ba..e84e844 100644 --- a/crates/proto/tsproto-structs/declarations/Book.toml +++ b/crates/proto/tsproto-structs/declarations/Book.toml @@ -76,6 +76,8 @@ properties = [ { name="Icon", type="IconId", opt=true }, { name="IsPrivate", type="bool", opt=true }, { name="StorageQuota", type="u32", opt=true }, + { name="BannerGfxUrl", type="str", opt=true, doc="TeamSpeak 6: the address of the channel's banner picture" }, + { name="BannerMode", type="str", opt=true, doc="TeamSpeak 6: how the banner is scaled, the values of `HostBannerMode`" }, { name="Subscribed", type="bool" }, { name="PermissionHints", type="ChannelPermissionHint", opt=true }, { name="OptionalData", type="OptionalChannelData", opt=true }, diff --git a/crates/proto/tsproto-structs/declarations/Messages.toml b/crates/proto/tsproto-structs/declarations/Messages.toml index d9921b1..b4495aa 100644 --- a/crates/proto/tsproto-structs/declarations/Messages.toml +++ b/crates/proto/tsproto-structs/declarations/Messages.toml @@ -24,7 +24,7 @@ fields = [ { map="cgi", ts="cgi", pretty="ChannelGroupIndex", type="ChannelGroupId" }, { map="cgid", ts="cgid", pretty="ChannelGroup", type="ChannelGroupId" }, # TODO: Consider name 'ChannelGroup' for consistency { map="channel_banner_gfx_url", ts="channel_banner_gfx_url", pretty="BannerGfxUrl", type="str" }, - { map="channel_banner_mode", ts="channel_banner_mode", pretty="BannerMode", type="str" }, # ?? Same as HostBannerMode maybe? There's no ui for this setting + { map="channel_banner_mode", ts="channel_banner_mode", pretty="BannerMode", type="str" }, # Like HostBannerMode: 0 as it is, 1 stretched, 2 scaled keeping the aspect ratio (TeamSpeak 6 channeledit docs). A string, so an unknown mode cannot drop the channel list { map="channel_codec", ts="channel_codec", pretty="Codec", type="Codec" }, { map="channel_codec_is_unencrypted", ts="channel_codec_is_unencrypted", pretty="IsUnencrypted", type="bool" }, { map="channel_codec_latency_factor", ts="channel_codec_latency_factor", pretty="CodecLatencyFactor", type="i32" }, @@ -606,10 +606,10 @@ default = { s2c=true, c2s=false, response=true, low=false, np=false } msg = [ { name="BanList", notify="notifybanlist", attributes=["banid", "ip", "name", "uid", "mytsid?", "lastnickname", "created", "duration@time", "invokercldbid", "invokername", "invokeruid?", "reason", "enforcements"] }, { name="ChannelClientPermList", notify="notifychannelclientpermlist", attributes=["cid", "cldbid", "permid?", "permsid?", "permvalue", "permnegated", "permskip"] }, - { name="ChannelCreated", notify="notifychannelcreated", attributes=["cid", "invokerid", "invokername", "invokeruid?", "channel_order", "channel_name", "channel_topic?", "channel_flag_default?", "channel_flag_password?", "channel_flag_permanent?", "channel_flag_semi_permanent?", "channel_codec?", "channel_codec_quality?", "channel_needed_talk_power?", "channel_icon_id?", "channel_maxclients?", "channel_maxfamilyclients?", "channel_codec_latency_factor?", "channel_codec_is_unencrypted?", "channel_delete_delay?", "channel_unique_identifier?", "channel_flag_maxclients_unlimited?", "channel_flag_maxfamilyclients_unlimited?", "channel_flag_maxfamilyclients_inherited?", "channel_name_phonetic?", "channel_storage_quota?", "cpid"] }, + { name="ChannelCreated", notify="notifychannelcreated", attributes=["cid", "invokerid", "invokername", "invokeruid?", "channel_order", "channel_name", "channel_topic?", "channel_flag_default?", "channel_flag_password?", "channel_flag_permanent?", "channel_flag_semi_permanent?", "channel_codec?", "channel_codec_quality?", "channel_needed_talk_power?", "channel_icon_id?", "channel_maxclients?", "channel_maxfamilyclients?", "channel_codec_latency_factor?", "channel_codec_is_unencrypted?", "channel_delete_delay?", "channel_unique_identifier?", "channel_flag_maxclients_unlimited?", "channel_flag_maxfamilyclients_unlimited?", "channel_flag_maxfamilyclients_inherited?", "channel_name_phonetic?", "channel_storage_quota?", "cpid", "channel_banner_gfx_url?", "channel_banner_mode?"] }, { name="ChannelDeleted", notify="notifychanneldeleted", attributes=["cid", "invokerid", "invokername", "invokeruid?"] }, # Has no invoker when we requested the description with: channelgetdescription cid=1 - { name="ChannelEdited", notify="notifychanneledited", attributes=["cid", "invokerid?", "invokername?", "invokeruid?", "reasonid", "channel_order?", "channel_name?", "channel_topic?", "channel_flag_default?", "channel_flag_password?", "channel_flag_permanent?", "channel_flag_semi_permanent?", "channel_codec?", "channel_codec_quality?", "channel_needed_talk_power?", "channel_icon_id?", "channel_maxclients?", "channel_maxfamilyclients?", "channel_codec_latency_factor?", "channel_codec_is_unencrypted?", "channel_delete_delay?", "channel_flag_maxclients_unlimited?", "channel_flag_maxfamilyclients_unlimited?", "channel_flag_maxfamilyclients_inherited?", "channel_name_phonetic?", "cpid?", "channel_description?"] }, + { name="ChannelEdited", notify="notifychanneledited", attributes=["cid", "invokerid?", "invokername?", "invokeruid?", "reasonid", "channel_order?", "channel_name?", "channel_topic?", "channel_flag_default?", "channel_flag_password?", "channel_flag_permanent?", "channel_flag_semi_permanent?", "channel_codec?", "channel_codec_quality?", "channel_needed_talk_power?", "channel_icon_id?", "channel_maxclients?", "channel_maxfamilyclients?", "channel_codec_latency_factor?", "channel_codec_is_unencrypted?", "channel_delete_delay?", "channel_flag_maxclients_unlimited?", "channel_flag_maxfamilyclients_unlimited?", "channel_flag_maxfamilyclients_inherited?", "channel_name_phonetic?", "cpid?", "channel_description?", "channel_banner_gfx_url?", "channel_banner_mode?"] }, { name="ChannelGroupClientList", notify="notifychannelgroupclientlist", attributes=["cid", "cldbid", "cgid"] }, { name="ChannelGroupList", notify="notifychannelgrouplist", attributes=["cgid", "name", "type@group", "iconid", "savedb", "sortid", "namemode", "n_modifyp", "n_member_addp", "n_member_removep?"] }, { name="ChannelGroupPermList", notify="notifychannelgrouppermlist", attributes=["cgid", "permid?", "permsid?", "permvalue", "permnegated", "permskip"] }, diff --git a/crates/voelin-core/src/book.rs b/crates/voelin-core/src/book.rs index cf20f97..83c65d3 100644 --- a/crates/voelin-core/src/book.rs +++ b/crates/voelin-core/src/book.rs @@ -2,8 +2,8 @@ use tsclientlib::{ClientType, MaxClients, data}; use voelin_model::{ - ChannelInfo, ClientInfo, GroupInfo, GroupNamingMode, GroupType, HostBannerMode, - HostMessageMode, Presence, ServerDetails, parse_badges, + BannerMode, ChannelInfo, ClientInfo, GroupInfo, GroupNamingMode, GroupType, HostMessageMode, + Presence, ServerDetails, parse_badges, }; fn group_info( @@ -49,9 +49,9 @@ fn server_details(server: &data::Server, uid: Option<&str>) -> ServerDetails { banner_gfx_url: server.hostbanner_gfx_url.clone(), banner_gfx_interval_s: server.hostbanner_gfx_interval.whole_seconds().max(0) as u64, banner_mode: match server.hostbanner_mode { - tsclientlib::HostBannerMode::NoAdjust => HostBannerMode::NoAdjust, - tsclientlib::HostBannerMode::AdjustIgnoreAspect => HostBannerMode::IgnoreAspect, - tsclientlib::HostBannerMode::AdjustKeepAspect => HostBannerMode::KeepAspect, + tsclientlib::HostBannerMode::NoAdjust => BannerMode::NoAdjust, + tsclientlib::HostBannerMode::AdjustIgnoreAspect => BannerMode::IgnoreAspect, + tsclientlib::HostBannerMode::AdjustKeepAspect => BannerMode::KeepAspect, }, host_button_tooltip: server.hostbutton_tooltip.clone(), host_button_url: server.hostbutton_url.clone(), @@ -115,6 +115,12 @@ pub(crate) fn presence_from_book( needed_talk_power: c.needed_talk_power.unwrap_or(0), is_default: c.is_default.unwrap_or(false), icon: c.icon.map_or(0, |i| i.0), + banner_gfx_url: c.banner_gfx_url.clone().filter(|u| !u.is_empty()), + // A number the book keeps as text. + banner_mode: c + .banner_mode + .as_deref() + .map_or(BannerMode::NoAdjust, BannerMode::from_wire), }, ) }) @@ -157,3 +163,107 @@ pub(crate) fn presence_from_book( .collect(), } } + +#[cfg(test)] +mod tests { + use tsclientlib::InMessage; + use tsproto_packets::packets::{Direction, Flags, OutPacket, PacketType}; + use tsproto_types::crypto::EccKeyPrivP256; + + use super::*; + + fn message(text: &str) -> InMessage { + let packet = OutPacket::new_with_dir(Direction::S2C, Flags::empty(), PacketType::Command); + InMessage::new(&packet.header(), text.as_bytes()).unwrap() + } + + /// Channel banners as a TeamSpeak 6 server (6.0.0-beta13.1) sends them: + /// in the channel list, when a channel is created and when it is edited. + #[test] + fn channel_banners() { + let InMessage::InitServer(init) = message(concat!( + "initserver virtualserver_name=Test virtualserver_welcomemessage ", + "virtualserver_platform=Linux virtualserver_version=6.0.0-beta13.1 ", + "virtualserver_maxclients=32 virtualserver_created=0 ", + "virtualserver_codec_encryption_mode=0 virtualserver_hostmessage ", + "virtualserver_hostmessage_mode=0 virtualserver_default_server_group=8 ", + "virtualserver_default_channel_group=8 virtualserver_hostbanner_url ", + r"virtualserver_hostbanner_gfx_url=https:\/\/example.com\/banner.png ", + "virtualserver_hostbanner_gfx_interval=60 ", + "virtualserver_priority_speaker_dimm_modificator=-18.0000 virtualserver_id=1 ", + "virtualserver_ask_for_privilegekey=0 ", + "virtualserver_hostbutton_tooltip virtualserver_hostbutton_url ", + "virtualserver_hostbutton_gfx_url virtualserver_name_phonetic ", + "virtualserver_icon_id=0 virtualserver_hostbanner_mode=2 ", + "virtualserver_channel_temp_delete_delay_default=0 acn=t aclid=2 pv=7 ", + "client_talk_power=75 client_needed_serverquery_view_power=75", + )) else { + panic!("not an initserver"); + }; + let mut book = data::Connection::new(EccKeyPrivP256::create().to_pub(), &init); + let channel = |cid: u64, order: u64, name: &str, banner: &str| { + format!( + "cid={cid} cpid=0 channel_name={name} channel_topic channel_codec=4 \ + channel_codec_quality=6 channel_maxclients=-1 channel_maxfamilyclients=-1 \ + channel_order={order} channel_flag_permanent=1 channel_flag_semi_permanent=0 \ + channel_flag_default=0 channel_flag_password=0 channel_codec_latency_factor=1 \ + channel_codec_is_unencrypted=1 channel_delete_delay=0 \ + channel_flag_maxclients_unlimited=1 channel_flag_maxfamilyclients_unlimited=1 \ + channel_flag_maxfamilyclients_inherited=0 channel_needed_talk_power=0 \ + channel_forced_silence=0 channel_name_phonetic channel_icon_id=0 {banner} \ + channel_storage_quota=4294967295" + ) + }; + let list = format!( + "channellist {}|{}", + channel(1, 0, "Lobby", "channel_banner_gfx_url channel_banner_mode=0"), + channel( + 12, + 1, + "Raid", + r"channel_banner_gfx_url=http:\/\/127.0.0.1:1\/d.png channel_banner_mode=2" + ), + ); + for text in [ + list.as_str(), + concat!( + "notifychannelcreated cid=13 cpid=0 invokerid=1 invokername=serveradmin ", + "invokeruid=serveradmin channel_name=New channel_order=12 ", + r"channel_flag_permanent=1 channel_banner_gfx_url=https:\/\/example.com\/new.jpg ", + "channel_banner_mode=1", + ), + concat!( + "notifychanneledited cid=12 reasonid=10 invokerid=1 invokername=serveradmin ", + "invokeruid=serveradmin channel_banner_mode=1", + ), + ] { + book.handle_command(&message(text)).unwrap(); + } + let p = presence_from_book(&book, None, |_| false); + let banner = |p: &Presence, cid| { + let c = &p.channels[&cid]; + (c.banner_gfx_url.clone(), c.banner_mode) + }; + assert_eq!(banner(&p, 1), (None, BannerMode::NoAdjust)); + assert_eq!( + banner(&p, 12), + (Some("http://127.0.0.1:1/d.png".into()), BannerMode::IgnoreAspect) + ); + assert_eq!( + banner(&p, 13), + (Some("https://example.com/new.jpg".into()), BannerMode::IgnoreAspect) + ); + // Removing the banner sends an empty address. + book.handle_command(&message( + "notifychanneledited cid=12 reasonid=10 invokerid=1 invokername=x channel_banner_gfx_url", + )) + .unwrap(); + let p = presence_from_book(&book, None, |_| false); + assert_eq!(p.channels[&12].banner_gfx_url, None); + // The host banner, for comparison. + assert_eq!(p.server.banner_gfx_url, "https://example.com/banner.png"); + assert_eq!(p.server.banner_gfx_interval_s, 60); + assert_eq!(p.server.banner_mode, BannerMode::KeepAspect); + assert_eq!(BannerMode::from_wire("7"), BannerMode::NoAdjust); + } +} diff --git a/crates/voelin-model/src/lib.rs b/crates/voelin-model/src/lib.rs index e8024e0..95acfa9 100644 --- a/crates/voelin-model/src/lib.rs +++ b/crates/voelin-model/src/lib.rs @@ -14,6 +14,6 @@ pub use presence::{ Presence, PresenceDelta, PresenceSnapshot, parse_badges, }; pub use server::{ - Capabilities, HostBannerMode, HostMessageMode, ServerDetails, ServerFlavor, ServerVersion, + BannerMode, Capabilities, HostMessageMode, ServerDetails, ServerFlavor, ServerVersion, }; pub use tree::{TreeRow, order_siblings, tree_rows}; diff --git a/crates/voelin-model/src/presence.rs b/crates/voelin-model/src/presence.rs index d0adf59..7776838 100644 --- a/crates/voelin-model/src/presence.rs +++ b/crates/voelin-model/src/presence.rs @@ -13,7 +13,7 @@ use std::collections::BTreeMap; use serde::{Deserialize, Serialize}; -use crate::server::ServerDetails; +use crate::server::{BannerMode, ServerDetails}; pub type ChannelId = u64; pub type ClientId = u16; @@ -32,6 +32,10 @@ fn is_false(b: &bool) -> bool { !*b } +fn is_default(v: &T) -> bool { + *v == T::default() +} + #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] pub struct ChannelInfo { pub id: ChannelId, @@ -56,6 +60,12 @@ pub struct ChannelInfo { /// Icon id (`channel_icon_id`); 0: none. #[serde(default, skip_serializing_if = "is_zero_u32")] pub icon: u32, + /// The address of the channel's banner picture (TeamSpeak 6, + /// `channel_banner_gfx_url`), drawn behind the channel. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub banner_gfx_url: Option, + #[serde(default, skip_serializing_if = "is_default")] + pub banner_mode: BannerMode, } #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] diff --git a/crates/voelin-model/src/server.rs b/crates/voelin-model/src/server.rs index 20925f7..20f0333 100644 --- a/crates/voelin-model/src/server.rs +++ b/crates/voelin-model/src/server.rs @@ -116,10 +116,11 @@ pub enum HostMessageMode { ModalQuit, } -/// How the host banner image is scaled. +/// How a banner picture (the host banner, a TeamSpeak 6 channel banner) is +/// scaled to its area: `0`, `1` and `2` on the wire. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] -pub enum HostBannerMode { +pub enum BannerMode { /// As it is. #[default] NoAdjust, @@ -129,6 +130,18 @@ pub enum HostBannerMode { KeepAspect, } +impl BannerMode { + /// From its number on the wire; an unknown one shows the picture as it + /// is. + pub fn from_wire(value: &str) -> Self { + match value.trim() { + "1" => Self::IgnoreAspect, + "2" => Self::KeepAspect, + _ => Self::NoAdjust, + } + } +} + /// What a server tells its (voice) clients about itself. #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] pub struct ServerDetails { @@ -152,7 +165,7 @@ pub struct ServerDetails { #[serde(default)] pub banner_gfx_interval_s: u64, #[serde(default)] - pub banner_mode: HostBannerMode, + pub banner_mode: BannerMode, #[serde(default)] pub host_button_tooltip: String, #[serde(default)] diff --git a/crates/voelin-observer/src/convert.rs b/crates/voelin-observer/src/convert.rs index 288750d..a174f40 100644 --- a/crates/voelin-observer/src/convert.rs +++ b/crates/voelin-observer/src/convert.rs @@ -1,10 +1,10 @@ //! Query rows and events to model types. -use voelin_model::{ChannelInfo, ChatMessage, ChatTarget, ClientInfo, PresenceDelta}; +use voelin_model::{BannerMode, ChannelInfo, ChatMessage, ChatTarget, ClientInfo, PresenceDelta}; use voelin_query::{Notification, Row}; -/// From a `channellist -topic -flags -voice -limits` row, or the fields of -/// `notifychannelcreated`. +/// From a `channellist -topic -flags -voice -limits -icon -banners` row, or +/// the fields of `notifychannelcreated`. pub fn channel_from_row(row: &Row) -> Option { Some(ChannelInfo { id: row.parse("cid")?, @@ -18,6 +18,13 @@ pub fn channel_from_row(row: &Row) -> Option { needed_talk_power: row.parse("channel_needed_talk_power").unwrap_or(0), is_default: row.flag("channel_flag_default").unwrap_or(false), icon: row.parse::("channel_icon_id").map_or(0, |i| i as u32), + banner_gfx_url: row + .get("channel_banner_gfx_url") + .filter(|u| !u.is_empty()) + .map(str::to_string), + banner_mode: row + .get("channel_banner_mode") + .map_or(BannerMode::NoAdjust, BannerMode::from_wire), }) } @@ -48,6 +55,15 @@ pub fn update_channel(channel: &mut ChannelInfo, row: &Row) { if let Some(d) = row.flag("channel_flag_default") { channel.is_default = d; } + if let Some(i) = row.parse::("channel_icon_id") { + channel.icon = i as u32; + } + if let Some(url) = row.get("channel_banner_gfx_url") { + channel.banner_gfx_url = Some(url.to_string()).filter(|u| !u.is_empty()); + } + if let Some(mode) = row.get("channel_banner_mode") { + channel.banner_mode = BannerMode::from_wire(mode); + } } /// From a `clientlist -uid -away -voice -groups -country` row or a @@ -186,11 +202,24 @@ mod tests { channel_flag_default=1 channel_flag_password=0 channel_maxclients=-1 \ channel_needed_subscribe_power=0 channel_needed_talk_power=5", )[0]; - let c = channel_from_row(row).unwrap(); + let mut c = channel_from_row(row).unwrap(); assert_eq!(c.name, "Default Channel"); assert!(c.is_default && !c.has_password); assert_eq!(c.max_clients, None); assert_eq!(c.needed_talk_power, 5); + assert_eq!((c.banner_gfx_url.as_deref(), c.banner_mode), (None, BannerMode::NoAdjust)); + // `-banners` (TeamSpeak 6 and 3.13), and the edit that changes them. + let row = &voelin_query::parse_rows( + "cid=2 pid=0 channel_name=Raid channel_banner_gfx_url=https:\\/\\/e.com\\/b.png \ + channel_banner_mode=2", + )[0]; + let banner = |c: &ChannelInfo| (c.banner_gfx_url.clone(), c.banner_mode); + let raid = channel_from_row(row).unwrap(); + assert_eq!(banner(&raid), (Some("https://e.com/b.png".into()), BannerMode::KeepAspect)); + update_channel(&mut c, row); + assert_eq!(banner(&c), banner(&raid)); + update_channel(&mut c, &voelin_query::parse_rows("cid=1 channel_banner_gfx_url")[0]); + assert_eq!(banner(&c), (None, BannerMode::KeepAspect)); } #[test] diff --git a/crates/voelin-observer/src/observer.rs b/crates/voelin-observer/src/observer.rs index 2dcb7c7..2d3b785 100644 --- a/crates/voelin-observer/src/observer.rs +++ b/crates/voelin-observer/src/observer.rs @@ -105,7 +105,15 @@ async fn run( async fn load(client: &QueryClient) -> voelin_query::Result { let info = client.send(&Command::new("serverinfo")).await?; let channels = client - .send(&Command::new("channellist").flag("topic").flag("flags").flag("voice").flag("limits")) + .send( + &Command::new("channellist") + .flag("topic") + .flag("flags") + .flag("voice") + .flag("limits") + .flag("icon") + .flag("banners"), + ) .await?; let clients = client .send(