mirror of
https://github.com/MeexReay/bRAC.git
synced 2025-05-06 21:48:03 +03:00
register to send_message_auth
This commit is contained in:
parent
5dd56bbb28
commit
0063e56438
22
src/proto.rs
22
src/proto.rs
@ -1,4 +1,4 @@
|
|||||||
use std::{error::Error, io::{Read, Write}, net::TcpStream};
|
use std::{error::Error, io::{Read, Write}, net::{Shutdown, TcpStream}};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -10,7 +10,12 @@ pub fn send_message(host: &str, message: &str) -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_message_auth(host: &str, message: &str) -> Result<(), Box<dyn Error>> {
|
pub fn send_message_auth(host: &str, message: &str) -> Result<(), Box<dyn Error>> {
|
||||||
register_user(host, message, message)?;
|
let mut stream = TcpStream::connect(host)?;
|
||||||
|
stream.write_all(&[0x03])?;
|
||||||
|
stream.write_all(message.as_bytes())?;
|
||||||
|
stream.write_all(&[b'\n'])?;
|
||||||
|
stream.write_all(message.as_bytes())?;
|
||||||
|
stream.shutdown(Shutdown::Both)?;
|
||||||
let mut stream = TcpStream::connect(host)?;
|
let mut stream = TcpStream::connect(host)?;
|
||||||
stream.write_all(&[0x02])?;
|
stream.write_all(&[0x02])?;
|
||||||
stream.write_all(message.as_bytes())?;
|
stream.write_all(message.as_bytes())?;
|
||||||
@ -20,23 +25,12 @@ pub fn send_message_auth(host: &str, message: &str) -> Result<(), Box<dyn Error>
|
|||||||
let mut buf = vec![0; 1];
|
let mut buf = vec![0; 1];
|
||||||
if let Ok(_) = stream.read_exact(&mut buf) {
|
if let Ok(_) = stream.read_exact(&mut buf) {
|
||||||
if buf[0] == 0x02 {
|
if buf[0] == 0x02 {
|
||||||
let message = format!("\x1f{message}");
|
send_message_auth(host, &format!("\x1f{message}"))?;
|
||||||
register_user(host, &message, &message)?;
|
|
||||||
send_message_auth(host, &message)?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register_user(host: &str, name: &str, password: &str) -> Result<(), Box<dyn Error>> {
|
|
||||||
let mut stream = TcpStream::connect(host)?;
|
|
||||||
stream.write_all(&[0x03])?;
|
|
||||||
stream.write_all(name.as_bytes())?;
|
|
||||||
stream.write_all(&[b'\n'])?;
|
|
||||||
stream.write_all(password.as_bytes())?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn skip_null(stream: &mut TcpStream) -> Result<Vec<u8>, Box<dyn Error>> {
|
fn skip_null(stream: &mut TcpStream) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
loop {
|
loop {
|
||||||
let mut buf = vec![0; 1];
|
let mut buf = vec![0; 1];
|
||||||
|
Loading…
Reference in New Issue
Block a user