Fix events caused by yourself being shown
Some checks failed
/ build-upload (push) Has been cancelled
Some checks failed
/ build-upload (push) Has been cancelled
This commit is contained in:
parent
ea7815535c
commit
70e0a1d0b4
5 changed files with 36 additions and 19 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -182,7 +182,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "teamspeak-query-lib"
|
name = "teamspeak-query-lib"
|
||||||
version = "0.1.4"
|
version = "0.1.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "teamspeak-query-lib"
|
name = "teamspeak-query-lib"
|
||||||
version = "0.1.4"
|
version = "0.1.5"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use telnet::Telnet;
|
use telnet::Telnet;
|
||||||
|
|
||||||
use crate::{commands, wrappers};
|
use crate::{commands, wrappers};
|
||||||
use crate::models::{Client, Event, EventType};
|
use crate::models::{Client, Event, EventType};
|
||||||
use crate::response::Response;
|
use crate::response::Response;
|
||||||
|
@ -12,10 +13,7 @@ pub fn register_events(connection: &mut Telnet, events: Vec<EventType>) -> Resul
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_event_response(connection: &mut Telnet, response: Response, known_clients: &mut Vec<Client>) {
|
pub fn handle_event_response(connection: &mut Telnet, event: Event, known_clients: &mut Vec<Client>) {
|
||||||
if let Response::Event(event_type, params) = response {
|
|
||||||
|
|
||||||
let event = Event::new(connection, event_type, params, known_clients);
|
|
||||||
match serde_json::to_string(&event) {
|
match serde_json::to_string(&event) {
|
||||||
Ok(json) => println!("{}", json),
|
Ok(json) => println!("{}", json),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
@ -28,13 +26,25 @@ pub fn handle_event_response(connection: &mut Telnet, response: Response, known_
|
||||||
*known_clients = new_clients;
|
*known_clients = new_clients;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn loop_response_reader(connection: &mut Telnet) {
|
pub fn loop_response_reader(connection: &mut Telnet, self_clid: i32) {
|
||||||
let mut known_clients = wrappers::get_clients(connection).unwrap_or_else(|_| Vec::new());
|
let mut known_clients = wrappers::get_clients(connection).unwrap_or_else(|_| Vec::new());
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match commands::read_response(connection, true, String::new()) {
|
match commands::read_response(connection, true, String::new()) {
|
||||||
Ok(response) => handle_event_response(connection, response, &mut known_clients),
|
Ok(response) => {
|
||||||
|
if let Response::Event(event_type, params) = response {
|
||||||
|
let event = Event::new(connection, event_type, params, &known_clients);
|
||||||
|
|
||||||
|
if let Some(client) = &event.client {
|
||||||
|
if client.clid == self_clid {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handle_event_response(connection, event, &mut known_clients);
|
||||||
|
}
|
||||||
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// print error?
|
// print error?
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use std::io::{Error, ErrorKind};
|
use std::io::{Error, ErrorKind};
|
||||||
|
use std::num::ParseIntError;
|
||||||
|
|
||||||
use telnet::Telnet;
|
use telnet::Telnet;
|
||||||
|
|
||||||
|
@ -147,7 +148,13 @@ fn main() -> Result<(), Error> {
|
||||||
loop {
|
loop {
|
||||||
command_utils::events::register_events(&mut connection, args.event.clone())
|
command_utils::events::register_events(&mut connection, args.event.clone())
|
||||||
.map_err(to_other_error)?;
|
.map_err(to_other_error)?;
|
||||||
command_utils::events::loop_response_reader(&mut connection);
|
|
||||||
|
let self_clid: i32 = wrappers::get_self_clid(&mut connection)
|
||||||
|
.map_err(|msg| make_action_error("get self clid", msg))?
|
||||||
|
.parse()
|
||||||
|
.map_err(|err: ParseIntError| make_action_error("parse clid", err.to_string()))?;
|
||||||
|
|
||||||
|
command_utils::events::loop_response_reader(&mut connection, self_clid);
|
||||||
|
|
||||||
// loop_response_reader failed. Let's try to reconnect after 1 second.
|
// loop_response_reader failed. Let's try to reconnect after 1 second.
|
||||||
std::thread::sleep(std::time::Duration::from_secs(1));
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||||
|
|
|
@ -110,7 +110,7 @@ pub fn get_channel_clients(connection: &mut Telnet, channel: &Channel) -> Result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_self_clid(connection: &mut Telnet) -> Result<String, String> {
|
pub fn get_self_clid(connection: &mut Telnet) -> Result<String, String> {
|
||||||
match commands::whoami(connection)? {
|
match commands::whoami(connection)? {
|
||||||
Response::Data(params) => {
|
Response::Data(params) => {
|
||||||
match parameter::parameter_find(¶ms, "clid") {
|
match parameter::parameter_find(¶ms, "clid") {
|
||||||
|
|
Loading…
Reference in a new issue