diff options
| author | Max Audron <audron@cocaine.farm> | 2025-02-23 17:37:39 +0100 |
|---|---|---|
| committer | Max Audron <audron@cocaine.farm> | 2025-02-23 17:37:39 +0100 |
| commit | 1d05a7394e5cf72538cc79b22c5f9330f179cfc3 (patch) | |
| tree | e389d0faeba5cef6b68b9958ec6ab9ef30329a59 | |
| parent | add basic network syncables (diff) | |
move network config to it's own file and impl it's sync
Diffstat (limited to '')
| -rw-r--r-- | src/message/signalproxy/objects/mod.rs | 2 | ||||
| -rw-r--r-- | src/message/signalproxy/objects/network.rs | 22 | ||||
| -rw-r--r-- | src/message/signalproxy/objects/networkconfig.rs | 67 | ||||
| -rw-r--r-- | src/session/mod.rs | 16 |
4 files changed, 84 insertions, 23 deletions
diff --git a/src/message/signalproxy/objects/mod.rs b/src/message/signalproxy/objects/mod.rs index b3b2858..0fb16c6 100644 --- a/src/message/signalproxy/objects/mod.rs +++ b/src/message/signalproxy/objects/mod.rs @@ -12,6 +12,7 @@ mod ignorelistmanager; mod ircchannel; mod ircuser; mod network; +mod networkconfig; mod networkinfo; pub use aliasmanager::*; @@ -28,6 +29,7 @@ pub use ignorelistmanager::*; pub use ircchannel::*; pub use ircuser::*; pub use network::*; +pub use networkconfig::*; pub use networkinfo::*; use libquassel_derive::From; diff --git a/src/message/signalproxy/objects/network.rs b/src/message/signalproxy/objects/network.rs index a8a882d..9f0150f 100644 --- a/src/message/signalproxy/objects/network.rs +++ b/src/message/signalproxy/objects/network.rs @@ -5,7 +5,7 @@ use log::{error, warn}; use num_derive::{FromPrimitive, ToPrimitive}; use num_traits::{FromPrimitive, ToPrimitive}; -use libquassel_derive::{sync, NetworkList, NetworkMap, Setters}; +use libquassel_derive::{sync, NetworkMap, Setters}; use crate::error::ProtocolError; use crate::message::signalproxy::translation::NetworkMap; @@ -616,26 +616,6 @@ pub struct NetworkServer { pub proxy_pass: String, } -#[derive(Debug, Clone, PartialEq, NetworkList)] -pub struct NetworkConfig { - #[network(rename = "pingTimeoutEnabled")] - ping_timeout_enabled: bool, - #[network(rename = "pingInterval")] - ping_interval: i32, - #[network(rename = "maxPingCount")] - max_ping_count: i32, - #[network(rename = "autoWhoEnabled")] - auto_who_enabled: bool, - #[network(rename = "autoWhoInterval")] - auto_who_interval: i32, - #[network(rename = "autoWhoNickLimit")] - auto_who_nick_limit: i32, - #[network(rename = "autoWhoDelay")] - auto_who_delay: i32, - #[network(rename = "standardCtcp")] - standard_ctcp: bool, -} - #[cfg(test)] mod tests { use super::*; diff --git a/src/message/signalproxy/objects/networkconfig.rs b/src/message/signalproxy/objects/networkconfig.rs new file mode 100644 index 0000000..c4f5397 --- /dev/null +++ b/src/message/signalproxy/objects/networkconfig.rs @@ -0,0 +1,67 @@ +use libquassel_derive::{NetworkList, NetworkMap, Setters}; + +use crate::message::{Class, Syncable}; + +#[derive(Debug, Default, Clone, PartialEq, NetworkList, NetworkMap, Setters)] +pub struct NetworkConfig { + #[network(rename = "pingTimeoutEnabled")] + ping_timeout_enabled: bool, + #[network(rename = "pingInterval")] + ping_interval: i32, + #[network(rename = "maxPingCount")] + max_ping_count: i32, + #[network(rename = "autoWhoEnabled")] + auto_who_enabled: bool, + #[network(rename = "autoWhoInterval")] + auto_who_interval: i32, + #[network(rename = "autoWhoNickLimit")] + auto_who_nick_limit: i32, + #[network(rename = "autoWhoDelay")] + auto_who_delay: i32, + #[network(rename = "standardCtcp")] + standard_ctcp: bool, +} + +impl Syncable for NetworkConfig { + const CLASS: Class = Class::NetworkConfig; +} + +#[cfg(feature = "client")] +impl crate::message::StatefulSyncableClient for NetworkConfig { + fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) + where + Self: Sized, + { + match msg.slot_name.as_str() { + "setAutoWhoDelay" => self.set_auto_who_delay(get_param!(msg)), + "setAutoWhoEnabled" => self.set_auto_who_enabled(get_param!(msg)), + "setAutoWhoInterval" => self.set_auto_who_interval(get_param!(msg)), + "setAutoWhoNickLimit" => self.set_auto_who_nick_limit(get_param!(msg)), + "setMaxPingCount" => self.set_max_ping_count(get_param!(msg)), + "setPingInterval" => self.set_ping_interval(get_param!(msg)), + "setPingTimeoutEnabled" => self.set_ping_timeout_enabled(get_param!(msg)), + "setStandardCtcp" => self.set_standard_ctcp(get_param!(msg)), + _ => (), + } + } +} + +#[cfg(feature = "server")] +impl crate::message::StatefulSyncableServer for NetworkConfig { + fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) + where + Self: Sized, + { + match msg.slot_name.as_str() { + "requestSetAutoWhoDelay" => self.set_auto_who_delay(get_param!(msg)), + "requestSetAutoWhoEnabled" => self.set_auto_who_enabled(get_param!(msg)), + "requestSetAutoWhoInterval" => self.set_auto_who_interval(get_param!(msg)), + "requestSetAutoWhoNickLimit" => self.set_auto_who_nick_limit(get_param!(msg)), + "requestSetMaxPingCount" => self.set_max_ping_count(get_param!(msg)), + "requestSetPingInterval" => self.set_ping_interval(get_param!(msg)), + "requestSetPingTimeoutEnabled" => self.set_ping_timeout_enabled(get_param!(msg)), + "requestSetStandardCtcp" => self.set_standard_ctcp(get_param!(msg)), + _ => (), + } + } +} diff --git a/src/session/mod.rs b/src/session/mod.rs index dbe29c0..f98cd04 100644 --- a/src/session/mod.rs +++ b/src/session/mod.rs @@ -5,7 +5,7 @@ use crate::message::StatefulSyncableClient; #[cfg(feature = "server")] use crate::message::StatefulSyncableServer; -use log::{debug, warn}; +use log::{debug, error, warn}; use crate::message::{ objects::{Types, *}, @@ -26,6 +26,7 @@ pub struct Session { pub identities: Vec<Identity>, pub ignore_list_manager: IgnoreListManager, pub networks: HashMap<i32, Network>, + pub network_config: NetworkConfig, } /// The Session Trait is the main point of entry and implements the basic logic @@ -42,6 +43,7 @@ pub trait SessionManager { fn ignore_list_manager(&mut self) -> &mut IgnoreListManager; fn networks(&mut self) -> &mut HashMap<i32, Network>; fn network(&mut self, id: i32) -> Option<&mut Network>; + fn network_config(&mut self) -> &mut NetworkConfig; fn sync(&mut self, msg: SyncMessage) where @@ -65,7 +67,13 @@ pub trait SessionManager { } } Class::NetworkInfo => (), - Class::NetworkConfig => (), + Class::NetworkConfig => match msg.object_name.as_ref() { + "GlobalNetworkConfig" => self.network_config().sync(msg), + _ => error!( + "received network config sync with unknown object name: {}", + msg.object_name + ), + }, Class::IrcChannel => { let mut object_name = msg.object_name.split('/'); let network_id: i32 = object_name.next().unwrap().parse().unwrap(); @@ -196,4 +204,8 @@ impl SessionManager for Session { fn network(&mut self, id: i32) -> Option<&mut Network> { self.networks.get_mut(&id) } + + fn network_config(&mut self) -> &mut NetworkConfig { + &mut self.network_config + } } |
