mirror of
https://github.com/MeexReay/bRAC.git
synced 2025-05-06 13:38:04 +03:00
v2.0 and auth abuse
This commit is contained in:
parent
9c2fe34303
commit
0111c27389
@ -13,7 +13,7 @@ better RAC client
|
|||||||
- plays sound when users receive your messages
|
- plays sound when users receive your messages
|
||||||
- coloring usernames by their clients (CRAB, clRAC, Mefidroniy, etc)
|
- coloring usernames by their clients (CRAB, clRAC, Mefidroniy, etc)
|
||||||
- configurable message format
|
- configurable message format
|
||||||
- RACv1.99.x compatible
|
- RACv1.99.x and RACv2.0 compatible
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@ -71,8 +71,9 @@ max_messages: 100 # chat messages limit
|
|||||||
|
|
||||||
## see also
|
## see also
|
||||||
|
|
||||||
- [RAC protocol (v1.99.2)](https://gitea.bedohswe.eu.org/pixtaded/crab#rac-protocol)
|
- [RAC protocol (v2.0)](https://gitea.bedohswe.eu.org/pixtaded/crab#rac-protocol)
|
||||||
- [CRAB - client & server for RAC](https://gitea.bedohswe.eu.org/pixtaded/crab)
|
- [CRAB - client & server for RAC](https://gitea.bedohswe.eu.org/pixtaded/crab)
|
||||||
|
- [Mefidroniy - client for RAC](https://github.com/OctoBanon-Main/mefedroniy-client)
|
||||||
- [Colored usernames](https://github.com/MeexReay/bRAC/blob/main/docs/colored_usernames.md)
|
- [Colored usernames](https://github.com/MeexReay/bRAC/blob/main/docs/colored_usernames.md)
|
||||||
- [AlmatyD - server for RAC](https://gitea.bedohswe.eu.org/bedohswe/almatyd)
|
- [AlmatyD - server for RACv1.0](https://gitea.bedohswe.eu.org/bedohswe/almatyd)
|
||||||
- [RAC protocol (v1.0)](https://bedohswe.eu.org/text/rac/protocol.md.html)
|
- [RAC protocol (v1.0)](https://bedohswe.eu.org/text/rac/protocol.md.html)
|
||||||
|
@ -1 +0,0 @@
|
|||||||
todo
|
|
16
src/chat.rs
16
src/chat.rs
@ -161,15 +161,15 @@ pub fn print_console(ctx: Arc<Context>, messages: Vec<String>, input: &str) -> R
|
|||||||
|
|
||||||
|
|
||||||
fn prepare_message(context: Arc<Context>, message: &str) -> String {
|
fn prepare_message(context: Arc<Context>, message: &str) -> String {
|
||||||
format!("{}{}{}",
|
format!("{}{}{}\r",
|
||||||
if !context.disable_hiding_ip {
|
if !context.disable_hiding_ip {
|
||||||
"\r\x07"
|
"\r\x07"
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
},
|
},
|
||||||
message,
|
message,
|
||||||
if !context.disable_hiding_ip && message.chars().count() < 39 {
|
if !context.disable_hiding_ip && message.chars().count() < 53 {
|
||||||
" ".repeat(39-message.chars().count())
|
" ".repeat(53-message.chars().count())
|
||||||
} else {
|
} else {
|
||||||
String::new()
|
String::new()
|
||||||
}
|
}
|
||||||
@ -300,12 +300,12 @@ fn poll_events(ctx: Arc<Context>) -> Result<(), Box<dyn Error>> {
|
|||||||
if message.starts_with("/") && !ctx.disable_commands {
|
if message.starts_with("/") && !ctx.disable_commands {
|
||||||
on_command(ctx.clone(), &message)?;
|
on_command(ctx.clone(), &message)?;
|
||||||
} else {
|
} else {
|
||||||
if let Some(password) = &ctx.auth_password {
|
let message = prepare_message(ctx.clone(), &ctx.message_format
|
||||||
send_message_auth(&ctx.host, &ctx.name, password, &message)?;
|
|
||||||
} else {
|
|
||||||
let message = ctx.message_format
|
|
||||||
.replace("{name}", &ctx.name)
|
.replace("{name}", &ctx.name)
|
||||||
.replace("{text}", &message);
|
.replace("{text}", &message));
|
||||||
|
if ctx.auth {
|
||||||
|
send_message_auth(&ctx.host, &message)?;
|
||||||
|
} else {
|
||||||
send_message(&ctx.host, &message)?;
|
send_message(&ctx.host, &message)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,8 +174,8 @@ pub struct Args {
|
|||||||
pub configure: bool,
|
pub configure: bool,
|
||||||
|
|
||||||
/// Authentication password
|
/// Authentication password
|
||||||
#[arg(short='a', long, value_name="PASSWORD")]
|
#[arg(short='a', long)]
|
||||||
pub auth: Option<String>,
|
pub auth: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Context {
|
pub struct Context {
|
||||||
@ -191,7 +191,7 @@ pub struct Context {
|
|||||||
pub max_messages: usize,
|
pub max_messages: usize,
|
||||||
pub enable_ip_viewing: bool,
|
pub enable_ip_viewing: bool,
|
||||||
pub scroll: Arc<AtomicUsize>,
|
pub scroll: Arc<AtomicUsize>,
|
||||||
pub auth_password: Option<String>,
|
pub auth: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
@ -209,7 +209,7 @@ impl Context {
|
|||||||
max_messages: config.max_messages,
|
max_messages: config.max_messages,
|
||||||
enable_ip_viewing: args.enable_users_ip_viewing || config.enable_ip_viewing,
|
enable_ip_viewing: args.enable_users_ip_viewing || config.enable_ip_viewing,
|
||||||
scroll: Arc::new(AtomicUsize::new(0)),
|
scroll: Arc::new(AtomicUsize::new(0)),
|
||||||
auth_password: args.auth.clone()
|
auth: args.auth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
28
src/proto.rs
28
src/proto.rs
@ -9,37 +9,31 @@ pub fn send_message(host: &str, message: &str) -> Result<(), Box<dyn Error>> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_message_auth(host: &str, name: &str, password: &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)?;
|
let mut stream = TcpStream::connect(host)?;
|
||||||
stream.write_all(&[0x02])?;
|
stream.write_all(&[0x02])?;
|
||||||
stream.write_all(name.as_bytes())?;
|
stream.write_all(message.as_bytes())?;
|
||||||
stream.write_all(&[b'\n'])?;
|
|
||||||
stream.write_all(password.as_bytes())?;
|
|
||||||
stream.write_all(&[b'\n'])?;
|
stream.write_all(&[b'\n'])?;
|
||||||
stream.write_all(message.as_bytes())?;
|
stream.write_all(message.as_bytes())?;
|
||||||
|
stream.write_all(b"\n\r ")?;
|
||||||
let mut buf = vec![0; 1];
|
let mut buf = vec![0; 1];
|
||||||
stream.read_exact(&mut buf)?;
|
if let Ok(_) = stream.read_exact(&mut buf) {
|
||||||
if buf[0] == 0x01 {
|
if buf[0] == 0x02 {
|
||||||
register_user(host, name, password)?;
|
let message = format!("\x1f{message}");
|
||||||
send_message_auth(host, name, password, message)?
|
register_user(host, &message, &message)?;
|
||||||
} else if buf[0] == 0x02 {
|
send_message_auth(host, &message)?;
|
||||||
println!("Password is incorrect");
|
}
|
||||||
panic!()
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register_user(host: &str, name: &str, password: &str) -> Result<(), Box<dyn Error>> {
|
pub fn register_user(host: &str, name: &str, password: &str) -> Result<(), Box<dyn Error>> {
|
||||||
let mut stream = TcpStream::connect(host)?;
|
let mut stream = TcpStream::connect(host)?;
|
||||||
stream.write_all(&[0x00])?;
|
stream.write_all(&[0x03])?;
|
||||||
stream.write_all(name.as_bytes())?;
|
stream.write_all(name.as_bytes())?;
|
||||||
stream.write_all(&[b'\n'])?;
|
stream.write_all(&[b'\n'])?;
|
||||||
stream.write_all(password.as_bytes())?;
|
stream.write_all(password.as_bytes())?;
|
||||||
// let mut buf = vec![0; 1];
|
|
||||||
// stream.read(&mut buf)?;
|
|
||||||
// if buf[0] == 0x01 {
|
|
||||||
// // похуй
|
|
||||||
// }
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user