Compare commits

..

No commits in common. "2c865d43d24ddab4d2131f7a66b07461c40c907c" and "f36d47044c9de704fe39e81e35d5bf290f029bd0" have entirely different histories.

2 changed files with 14 additions and 52 deletions

@ -1 +1 @@
Subproject commit cd15222685e3bbd80acaa279ceabc1514636b08c
Subproject commit fea845a5335691b8e75b3981f93ae59335043eb1

View file

@ -22,11 +22,7 @@ use std::{
io::{prelude::*,Read},
net::TcpStream,
};
use irc_proto::command::{
CapSubCommand,
Command,
};
use irc_proto::message::Message;
use irc_proto;
use irc_stream::{IrcStream, IrcRead, IrcWrite};
use toml::Value;
use native_tls::{TlsConnector,TlsStream};
@ -64,7 +60,7 @@ fn get_config<P: AsRef<Path>>(config_path: P)
Ok(config)
}
fn get_tcp_stream (config: &Value) -> Result<TcpStream, Box<dyn std::error::Error>> {
fn connect_irc (config: &Value) -> Result<TcpStream, Box<dyn std::error::Error>> {
let adress = format!("{}:{}",
config["server"].as_str().ok_or("Could not get server adress from config")?,
config["port"].as_str().ok_or("Could not get port from config")?
@ -72,10 +68,10 @@ fn get_tcp_stream (config: &Value) -> Result<TcpStream, Box<dyn std::error::Erro
Ok(TcpStream::connect("127.0.0.1:8080")?)
}
fn get_tls_stream (config: &Value)
fn connect_irc_tls (config: &Value)
-> Result<TlsStream<TcpStream>, Box<dyn std::error::Error>> {
let connector = TlsConnector::new().unwrap();
let stream = get_tcp_stream(config)?;
let stream = connect_irc(config)?;
Ok(connector.connect(config["server"]
.as_str()
.ok_or("Could not get server adress from config")?,
@ -83,39 +79,6 @@ fn get_tls_stream (config: &Value)
)
}
fn identify_irc<S: std::io::Read + std::io::Write> (
stream: &mut IrcStream<S>,
pass: Option<String>,
nick: String,
user: String,
real_name: String
) -> Result<(), irc_stream::IrcStreamError>{
stream.write(Message::from(
Command::CAP(
None,
CapSubCommand::END,
None,
None
)
))?;
match pass {
Some(p) => stream.write(Message::from(
Command::PASS(p)
))?,
None => ()
}
stream.write(Message::from(
Command::NICK(nick)
))?;
stream.write(Message::from(
Command::USER(
user,
"0".to_owned(),
real_name)
))?;
Ok(())
}
fn main() {
let config_path = args().nth(1)
.expect("no config given");
@ -129,17 +92,16 @@ fn main() {
let mut stream: &dyn IrcReadWrite;
if config["tls"].as_bool().unwrap() == true {
stream = &IrcStream::new(get_tls_stream(&config).unwrap());
stream = &IrcStream::new(connect_irc_tls(&config).unwrap());
} else {
stream = &IrcStream::new(get_tcp_stream(&config).unwrap());
stream = &IrcStream::new(connect_irc(&config).unwrap());
}
identify_irc(
&mut stream,
None,
config["Nick"].to_string(),
config["User"].to_string(),
config["Real"].to_string()
);
//let irc_stream = IrcStream::new(stream);
// TODO: Identify with irc server
//stream.write(irc_proto.Message{
// tags: None,
// prefix:
}