From aefe83d33af4bcab1380f0deae4fe34b3bfd4e2b Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 29 Sep 2026 00:51:41 +0000 Subject: [PATCH] voelin-core: offline messages to the unique id's bytes; voelinctl checks messageadd carries the recipient's unique id as bytes (base64 on the wire); the engine passed the base64 text itself, which the server refused as an invalid client id. voelinctl engine can now wait for an icon or a flagged poke (listen --expect matches pokes, chat and icons), for a friend to be seen online (contacts ls --expect-online), and identity show prints the unique id a TeamSpeak 6 server knows the identity by (uid6), which offline messages there need. Contacts commands wait for the stored contacts to load instead of for an event they could miss. Verified against 3.13.8 and 6.0.0-beta13.1: file upload, listing, download, a chat link downloaded by another client, avatars (the a-p file name on both), channel icons, pokes, private messages, offline messages, friend presence and blocked pokes (flagged and hidden). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G --- crates/voelin-core/src/voice.rs | 13 ++++++++- tools/voelinctl/src/client.rs | 49 +++++++++++++++++++++------------ tools/voelinctl/src/main.rs | 6 +++- 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/crates/voelin-core/src/voice.rs b/crates/voelin-core/src/voice.rs index d10e0fb..e53ce02 100644 --- a/crates/voelin-core/src/voice.rs +++ b/crates/voelin-core/src/voice.rs @@ -10,6 +10,7 @@ use std::collections::HashMap; use std::path::PathBuf; use std::time::Duration; +use base64::Engine as _; use futures::prelude::*; use tokio::sync::{broadcast, mpsc}; use tokio::task::AbortHandle; @@ -861,7 +862,17 @@ impl Voice { self.send(cmd, Pending::OfflineGet { request, id, message: None })?; } VoiceCmd::OfflineAdd { request, to_uid, subject, text } => { - let uid = tsclientlib::UidBuf(to_uid.into_bytes()); + // The command carries the unique id's bytes (base64 on the wire). + let bytes = base64::engine::general_purpose::STANDARD + .decode(to_uid.trim()) + .map_err(|_| anyhow::anyhow!("offline message: invalid unique id {to_uid:?}")); + let uid = match bytes { + Ok(bytes) => tsclientlib::UidBuf(bytes), + Err(e) => { + self.link.done(request, Err(e.to_string())); + return Ok(()); + } + }; let cmd = c2s::OutOfflineMessageAddMessage::new(&mut std::iter::once( c2s::OutOfflineMessageAddPart { client_uid: std::borrow::Cow::Borrowed(uid.as_ref()), diff --git a/tools/voelinctl/src/client.rs b/tools/voelinctl/src/client.rs index 18b5f9f..c629c03 100644 --- a/tools/voelinctl/src/client.rs +++ b/tools/voelinctl/src/client.rs @@ -207,8 +207,12 @@ pub enum ContactsCommand { Rm { uid: String, }, - /// Print the contacts, and friends' presence while connected. - Ls, + /// Connect, print the contacts and friends' presence. + Ls { + /// Succeed once this friend (unique id) is seen online. + #[arg(long)] + expect_online: Option, + }, } /// What the action waits for. @@ -241,7 +245,7 @@ pub async fn run(args: EngineArgs) -> Result<()> { // Contacts need no server. if let EngineAction::Contacts { command } = &args.action - && !matches!(command, ContactsCommand::Ls) + && !matches!(command, ContactsCommand::Ls { .. }) { let result = contacts(&engine, command, &mut events, deadline).await; engine.history().flush(); @@ -400,11 +404,12 @@ impl Runner<'_> { } } Event::Poke { from_name, message, blocked, .. } => { - println!( + let line = format!( "poke from {from_name}: {message}{}", if blocked { " (blocked)" } else { "" } ); - return Ok(self.expected(&message)); + println!("{line}"); + return Ok(self.expected(&line)); } Event::Chat { session: SESSION, message } => { println!( @@ -441,7 +446,7 @@ impl Runner<'_> { if let EngineAction::Dm { message: sent, .. } = &self.args.action { return Ok(private && message.text == *sent); } - return Ok(private && self.expected(&message.text)); + return Ok(self.expected(&message.text)); } Event::AvatarReady { client_uid, path, hash, .. } => { let nick = self @@ -467,7 +472,10 @@ impl Runner<'_> { return Ok(true); } } - Event::IconReady { icon, path, .. } => println!("icon {icon} {}", path.display()), + Event::IconReady { icon, path, .. } => { + println!("icon {icon} {}", path.display()); + return Ok(self.expected(&format!("icon {icon}"))); + } Event::OfflineMessages { result, .. } => { let list = result.map_err(|e| anyhow::anyhow!("messagelist: {e}"))?; println!("offline inbox n={}", list.len()); @@ -524,6 +532,12 @@ impl Runner<'_> { .map(|s| format!("{} as {} in {}", s.server_name, s.nickname, s.channel_name)) .collect(); println!("friend {uid}: [{}]", spots.join(", ")); + if let EngineAction::Contacts { + command: ContactsCommand::Ls { expect_online: Some(want) }, + } = &self.args.action + { + return Ok(*want == uid && !sessions.is_empty()); + } } Event::ServerDetails { details, .. } => { println!( @@ -682,10 +696,13 @@ impl Runner<'_> { self.send(Command::ListOfflineMessages { session, request: 1 }); } }, - EngineAction::Contacts { .. } => { + EngineAction::Contacts { command } => { for c in self.engine.contacts() { println!("contact {} {:?} {:?}", c.uid, c.relation, c.nickname); } + if matches!(command, ContactsCommand::Ls { expect_online: None }) { + self.finish_at = Some(Instant::now() + Duration::from_secs(2)); + } } EngineAction::Listen { .. } => {} } @@ -729,15 +746,10 @@ async fn contacts( events: &mut tokio::sync::broadcast::Receiver, deadline: Instant, ) -> Result<()> { - // The stored contacts are loaded first. - let _ = timeout_at(deadline, async { - while let Ok(e) = events.recv().await { - if matches!(e, Event::ContactsChanged { .. }) { - break; - } - } - }) - .await; + // The stored contacts are loaded first (on the database thread). + let history = engine.history(); + tokio::task::spawn_blocking(move || history.flush()).await?; + while events.try_recv().is_ok() {} match command { ContactsCommand::Set { uid, relation, nickname, note } => { let relation = match relation.as_str() { @@ -754,7 +766,7 @@ async fn contacts( engine.send(Command::SetContact { contact: Box::new(contact) }); } ContactsCommand::Rm { uid } => engine.send(Command::RemoveContact { uid: uid.clone() }), - ContactsCommand::Ls => {} + ContactsCommand::Ls { .. } => {} } let changed = timeout_at(deadline, async { while let Ok(e) = events.recv().await { @@ -768,6 +780,7 @@ async fn contacts( .ok() .flatten() .context("no contacts update")?; + println!("contacts n={}", changed.len()); for c in changed.iter() { println!("contact {} {:?} {:?} {:?}", c.uid, c.relation, c.nickname, c.note); } diff --git a/tools/voelinctl/src/main.rs b/tools/voelinctl/src/main.rs index 2967f13..8156c45 100644 --- a/tools/voelinctl/src/main.rs +++ b/tools/voelinctl/src/main.rs @@ -252,7 +252,11 @@ fn run_identity(command: IdentityCommand) -> Result<()> { let id = identity::load(&path)?; println!("uid: {}", identity::uid(&id)); println!("level: {}", id.level()); - println!("omega: {}", id.key().to_pub().to_ts()); + let omega = id.key().to_pub().to_ts(); + // TeamSpeak 6 servers know the identity by another unique id. + let ids = voelin_gateway_proto::UniqueIds::from_omega(&omega); + println!("uid6: {}", ids.ts6); + println!("omega: {omega}"); Ok(()) } }