use super::Client;
use crate::types::{ChannelId, ServerProperties, User, UserId};
use teamtalk_sys as ffi;
fn can_issue_logged_in_command(state: crate::events::ConnectionState) -> bool {
matches!(
state,
crate::events::ConnectionState::LoggedIn
| crate::events::ConnectionState::Joining(_)
| crate::events::ConnectionState::Joined(_)
)
}
impl Client {
pub fn get_server_properties(&self) -> Option<ServerProperties> {
self.backend().get_server_properties(self.ptr.0)
}
pub fn get_server_users(&self) -> Vec<User> {
self.backend().get_server_users(self.ptr.0)
}
pub fn ban_ip(&self, ip: &str, ban_type: i32) -> i32 {
if !can_issue_logged_in_command(self.connection_state()) {
return 0;
}
self.backend().do_ban_ip_address(self.ptr.0, ip, ban_type)
}
pub fn get_client_statistics(&self) -> Option<crate::types::ClientStatistics> {
self.backend().get_client_statistics(self.ptr.0)
}
pub fn list_bans(&self, channel_id: ChannelId, index: i32, count: i32) -> i32 {
if !can_issue_logged_in_command(self.connection_state()) {
return 0;
}
self.backend()
.do_list_bans(self.ptr.0, channel_id.0, index, count)
}
pub fn update_server(&self, props: &ServerProperties) -> i32 {
if !can_issue_logged_in_command(self.connection_state()) {
return 0;
}
self.backend().do_update_server(self.ptr.0, props)
}
pub fn save_server_config(&self) -> i32 {
if !can_issue_logged_in_command(self.connection_state()) {
return 0;
}
self.backend().do_save_config(self.ptr.0)
}
pub fn get_root_channel_id(&self) -> ChannelId {
self.backend().get_root_channel_id(self.ptr.0)
}
pub fn query_server_stats(&self) -> i32 {
if !can_issue_logged_in_command(self.connection_state()) {
return 0;
}
unsafe { ffi::api().TT_DoQueryServerStats(self.ptr.0) }
}
pub fn ping(&self) -> i32 {
unsafe { ffi::api().TT_DoPing(self.ptr.0) }
}
pub fn query_max_payload(&self, user_id: UserId) -> bool {
unsafe { ffi::api().TT_QueryMaxPayload(self.ptr.0, user_id.0) == 1 }
}
pub fn query_server_max_payload(&self) -> bool {
unsafe { ffi::api().TT_QueryMaxPayload(self.ptr.0, 0) == 1 }
}
#[cfg(windows)]
pub fn pump_message(&self, event: ffi::ClientEvent, id: i32) -> bool {
unsafe { ffi::api().TT_PumpMessage(self.ptr.0, event, id) == 1 }
}
pub fn quit(&self) -> i32 {
unsafe { ffi::api().TT_DoQuit(self.ptr.0) }
}
}