voelin-core: channel moves report why they fail; password and token on connect

A move went out without asking for an answer, so a wrong password or a
full channel came back as nothing. It is sent with a return code now,
and a refusal comes as Event::JoinFailed: Password, Full, or a sentence
for anything else. Moving to the channel we are in says nothing. The UI
does not show it yet; the channel password dialog will.

VoiceOptions gets channel_password and token, for joining a channel
when connecting and for links with a privilege key; tsclientlib's
ConnectOptions gets default_token for the latter (UPSTREAM.md patch 15).
Live tests on both dev servers check the password and the key on
connect, and the refused moves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AVRENKftQqGoEeswiR9TDQ
This commit is contained in:
Claude committed 2026-10-06 10:25:41 +00:00
1 parent 61636b23c8
commit e441156ee6
6 files changed
+260 -9

No files matched your search

+18
View File
@@ -153,6 +153,7 @@ pub enum Command {
session: SessionId,
request: GatewayRequest,
},
/// Refusals come as [`Event::JoinFailed`].
MoveToChannel {
session: SessionId,
channel: ChannelId,
@@ -469,6 +470,17 @@ pub struct SessionState {
pub server_uid: Option<String>,
}
/// Why the server did not let us into a channel ([`Event::JoinFailed`]).
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum JoinFailure {
/// The channel's password is missing or wrong.
Password,
/// The channel, or the channel with its subchannels, is full.
Full,
/// Anything else, as a sentence for the user.
Other(String),
}
/// What the engine reports.
#[derive(Clone, Debug)]
pub enum Event {
@@ -534,6 +546,12 @@ pub enum Event {
session: SessionId,
message: String,
},
/// The server refused [`Command::MoveToChannel`] into `channel`.
JoinFailed {
session: SessionId,
channel: ChannelId,
reason: JoinFailure,
},
/// The streams in our channel (TeamSpeak 6), full list.
StreamsChanged {
session: SessionId,
+90 -8
View File
@@ -33,7 +33,7 @@ use crate::cache;
use crate::files::{self, FileEntry, Report, RequestId, Sink, TransferId, TransferState};
use crate::offline::{OfflineMessage, OfflineMessageInfo};
use crate::settings::{FILES_PROGRESS_MS, SharedSettings};
use crate::{Event, SessionId};
use crate::{Event, JoinFailure, SessionId};
#[derive(Clone, Debug)]
pub struct VoiceOptions {
@@ -45,6 +45,10 @@ pub struct VoiceOptions {
pub server_password: Option<String>,
/// Channel path to join, e.g. `Lobby/Sub`.
pub channel: Option<String>,
/// The password of `channel`.
pub channel_password: Option<String>,
/// A privilege key to use when connecting.
pub token: Option<String>,
/// Open the audio devices (capture and playback).
pub audio: bool,
/// Network settings for stream peer connections (TeamSpeak 6).
@@ -60,6 +64,8 @@ impl VoiceOptions {
client_version: None,
server_password: None,
channel: None,
channel_password: None,
token: None,
audio: false,
stream_peer: PeerConfig::default(),
}
@@ -253,6 +259,10 @@ enum Pending {
id: u32,
message: Option<OfflineMessage>,
},
/// Moving ourselves; refusals are reported as [`Event::JoinFailed`].
Move {
channel: ChannelId,
},
/// Failures are reported as [`VoiceEvent::Error`] with this label.
Report(&'static str),
/// Best effort: the answer does not matter.
@@ -365,6 +375,12 @@ async fn run_inner(
if let Some(channel) = &options.channel {
builder = builder.channel(channel.clone());
}
if let Some(pw) = options.channel_password.as_ref().filter(|p| !p.is_empty()) {
builder = builder.channel_password(pw.clone());
}
if let Some(token) = &options.token {
builder = builder.default_token(token.clone());
}
let mut identity = link.myts_identity.clone();
// A changed account invalidates an in-flight handshake. Drop that connection
// and take a fresh snapshot before publishing any connected state.
@@ -801,6 +817,13 @@ impl Voice {
};
self.link.emit(Event::OfflineMessage { session, request, result });
}
Pending::Move { channel } => {
if let Err(e) = result
&& let Some(reason) = join_failure(e)
{
self.link.emit(Event::JoinFailed { session, channel, reason });
}
}
Pending::Quiet | Pending::MytsIdentity(_) => {}
Pending::Report(what) => {
if let Err(e) = result {
@@ -840,13 +863,15 @@ impl Voice {
self.send(out, Pending::Report("message"))?;
}
VoiceCmd::Move(channel, password) => {
let state = self.con.get_state()?;
let own = &state.clients[&state.own_client];
let mut part = own.client_move(tsclientlib::ChannelId(channel));
if let Some(pw) = &password {
part = part.set_password(pw);
}
part.send(&mut self.con)?;
let own = self.con.get_state()?.own_client;
let cpw = encode_password(password.as_deref());
let cmd =
c2s::OutClientMoveMessage::new(&mut std::iter::once(c2s::OutClientMovePart {
client_id: own,
channel_id: tsclientlib::ChannelId(channel),
channel_password: (!cpw.is_empty()).then_some(cpw.as_str().into()),
}));
self.send(cmd, Pending::Move { channel })?;
}
VoiceCmd::SetInputMuted(muted) => {
self.con.get_state()?.client_update().set_input_muted(muted).send(&mut self.con)?;
@@ -1053,6 +1078,39 @@ impl Voice {
}
}
/// Why a move into a channel failed, for the user; `None` when there is
/// nothing to tell (we are in that channel already).
fn join_failure(error: TsError) -> Option<JoinFailure> {
let text = match error {
TsError::ChannelAlreadyIn => return None,
TsError::ChannelInvalidPassword => return Some(JoinFailure::Password),
TsError::ChannelMaxclientsReached | TsError::ChannelMaxfamilyReached => {
return Some(JoinFailure::Full);
}
TsError::ChannelInvalidId => "The channel does not exist any more.".to_owned(),
TsError::PermissionsClientInsufficient | TsError::Permissions => {
"You are not allowed to join this channel.".to_owned()
}
TsError::ClientIsFlooding => "Too many requests: try again in a moment.".to_owned(),
// The error's name in words (its Display is the name).
e => format!("The server refused to move you: {}.", error_words(e)),
};
Some(JoinFailure::Other(text))
}
/// A TeamSpeak error's name in lowercase words:
/// `ChannelIsPrivateChannel` is "channel is private channel".
fn error_words(error: TsError) -> String {
let mut words = String::new();
for c in format!("{error:?}").chars() {
if c.is_ascii_uppercase() && !words.is_empty() {
words.push(' ');
}
words.push(c.to_ascii_lowercase());
}
words
}
/// A failed transfer, for the user.
fn transfer_error(error: &tsclientlib::Error) -> String {
match error {
@@ -1063,6 +1121,30 @@ fn transfer_error(error: &tsclientlib::Error) -> String {
}
}
#[cfg(test)]
mod join_tests {
use super::*;
#[test]
fn refused_moves_say_why() {
assert_eq!(join_failure(TsError::ChannelInvalidPassword), Some(JoinFailure::Password));
assert_eq!(join_failure(TsError::ChannelMaxclientsReached), Some(JoinFailure::Full));
assert_eq!(join_failure(TsError::ChannelMaxfamilyReached), Some(JoinFailure::Full));
// Moving to the channel we are in.
assert_eq!(join_failure(TsError::ChannelAlreadyIn), None);
let other = |text: &str| Some(JoinFailure::Other(text.into()));
assert_eq!(
join_failure(TsError::PermissionsClientInsufficient),
other("You are not allowed to join this channel.")
);
// The rest in words, not the error's name.
assert_eq!(
join_failure(TsError::ChannelIsPrivateChannel),
other("The server refused to move you: channel is private channel.")
);
}
}
#[cfg(test)]
mod image_download_tests {
use super::*;