New paste Repaste Download
use crate::irc::error::Error;
use cowirc::networking::IrcConnection;
use std::sync::Arc;
#[derive(Debug)]
pub(crate) struct Server {
    server: String,
    port: u16,
    tls: bool,
    accept_invalid_tls_certs: bool,
    connection: Arc<Option<IrcConnection>>,
    connected: bool,
}
impl Drop for Server {
    fn drop(&mut self) {
        self.disconnect();
    }
}
impl Server {
    #[must_use]
    pub fn new(port: u16, server: &str, tls: bool, accept_invalid_tls_certs: bool) -> Self {
        Self {
            server: server.to_owned(),
            port,
            tls,
            accept_invalid_tls_certs,
            connection: Arc::new(None),
            connected: false,
        }
    }
    #[must_use]
    pub const fn server(&self) -> &String {
        &self.server
    }
    #[must_use]
    pub const fn connected(&self) -> bool {
        self.connected
    }
    pub async fn connect(&mut self) -> Result<(), Error> {
        self.connection = Arc::new(Some(
            IrcConnection::builder()
                .server(self.server.clone())
                .port(self.port)
                .tls(self.tls)
                .accept_invalid_tls_cert(self.accept_invalid_tls_certs)
                .build()
                .await
                .map_err(|e| *e)?,
        ));
        Ok(())
    }
    fn disconnect(&mut self) {
        // TODO: send quit message
        self.connection = Arc::new(None);
    }
}
Filename: src/irc/server.rs. Size: 1kb. View raw, , hex, or download this file.

This paste expires on 2024-04-20 16:22:44.648464. Pasted through v1-api.