mirror of
https://github.com/MeexReay/bRAC.git
synced 2025-05-06 13:38:04 +03:00
ddddd
This commit is contained in:
parent
9ef0046e9a
commit
2402716a6d
67
src/chat.rs
67
src/chat.rs
@ -1,8 +1,7 @@
|
||||
use std::{cmp::{max, min}, error::Error, io::{stdout, Write}, sync::{atomic::{AtomicUsize, Ordering}, Arc, RwLock}, thread, time::{Duration, SystemTime}};
|
||||
use std::{cmp::{max, min}, error::Error, io::{stdout, Write}, sync::{atomic::{AtomicUsize, Ordering}, Arc, RwLock}, thread, time::{Duration, SystemTime, UNIX_EPOCH}};
|
||||
|
||||
use colored::{Color, Colorize};
|
||||
use crossterm::{cursor::{MoveLeft, MoveRight}, event::{self, Event, KeyCode, KeyModifiers, MouseEventKind}, execute, terminal::{self, disable_raw_mode, enable_raw_mode}};
|
||||
use rand::random;
|
||||
|
||||
use crate::{proto::{connect, send_message_auth}, util::{char_index_to_byte_index, string_chunks}, IP_REGEX};
|
||||
|
||||
@ -42,38 +41,51 @@ impl ChatStorage {
|
||||
}
|
||||
|
||||
|
||||
const HELP_MESSAGE: &str = "Help message:\r
|
||||
/help - show help message\r
|
||||
/clear n - send empty message n times\r
|
||||
/spam n text - send message with text n times\r
|
||||
/ping - check server ping\r
|
||||
\r
|
||||
Press enter to close";
|
||||
|
||||
|
||||
fn on_command(ctx: Arc<Context>, command: &str) -> Result<(), Box<dyn Error>> {
|
||||
let command = command.trim_start_matches("/");
|
||||
let (command, args) = command.split_once(" ").unwrap_or((&command, ""));
|
||||
let args = args.split(" ").collect::<Vec<&str>>();
|
||||
|
||||
let response = move || -> Option<String> {
|
||||
if command == "clear" {
|
||||
send_message(&mut connect(&ctx.host, ctx.enable_ssl)?,
|
||||
&prepare_message(ctx.clone(),
|
||||
&format!("\r\x1B[1A{}", " ".repeat(64)).repeat(ctx.max_messages)
|
||||
))?;
|
||||
let times = args.get(0)?.parse().ok()?;
|
||||
for _ in 0..times {
|
||||
send_message(&mut connect(&ctx.host, ctx.enable_ssl).ok()?, "\r").ok()?;
|
||||
}
|
||||
None
|
||||
} else if command == "spam" {
|
||||
send_message(&mut connect(&ctx.host, ctx.enable_ssl)?,
|
||||
&prepare_message(ctx.clone(),
|
||||
&format!("\r\x1B[1A{}{}", args.join(" "), " ".repeat(10)).repeat(ctx.max_messages)
|
||||
))?;
|
||||
let times = args.get(0)?.parse().ok()?;
|
||||
let msg = args[1..].join(" ");
|
||||
for _ in 0..times {
|
||||
send_message(&mut connect(&ctx.host, ctx.enable_ssl).ok()?, &("\r".to_string()+&msg)).ok()?;
|
||||
}
|
||||
None
|
||||
// send_message(&mut connect(&ctx.host, ctx.enable_ssl)?,
|
||||
// &prepare_message(ctx.clone(),
|
||||
// &format!("\r\x1B[1A{}{}", args.join(" "), " ".repeat(10)).repeat(ctx.max_messages)
|
||||
// ))?;
|
||||
} else if command == "help" {
|
||||
write!(stdout(), "Help message:\r
|
||||
/help - show help message\r
|
||||
/clear - clear console\r
|
||||
/spam *args - spam console with text\r
|
||||
/ping - check server ping\r
|
||||
\r
|
||||
Press enter to close")?;
|
||||
stdout().flush()?;
|
||||
Some(HELP_MESSAGE.to_string())
|
||||
} else if command == "ping" {
|
||||
let mut before = ctx.messages.packet_size();
|
||||
let message = format!("Checking ping... {:X}", SystemTime::now().duration_since(UNIX_EPOCH).ok()?.as_millis());
|
||||
|
||||
send_message(&mut connect(&ctx.host, ctx.enable_ssl).ok()?, &message).ok()?;
|
||||
|
||||
let start = SystemTime::now();
|
||||
let message = format!("Checking ping... {:X}", random::<u16>());
|
||||
send_message(&mut connect(&ctx.host, ctx.enable_ssl)?, &message)?;
|
||||
|
||||
loop {
|
||||
let data = read_messages(
|
||||
&mut connect(&ctx.host, ctx.enable_ssl)?,
|
||||
&mut connect(&ctx.host, ctx.enable_ssl).ok()?,
|
||||
ctx.max_messages,
|
||||
before,
|
||||
!ctx.enable_ssl,
|
||||
@ -92,7 +104,18 @@ Press enter to close")?;
|
||||
}
|
||||
}
|
||||
}
|
||||
send_message(&mut connect(&ctx.host, ctx.enable_ssl)?, &format!("Ping = {}ms", start.elapsed().unwrap().as_millis()))?;
|
||||
|
||||
send_message(&mut connect(&ctx.host, ctx.enable_ssl).ok()?, &format!("Ping = {}ms", start.elapsed().unwrap().as_millis())).ok()?;
|
||||
|
||||
None
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}();
|
||||
|
||||
if let Some(response) = response {
|
||||
write!(stdout(), "{}", response)?;
|
||||
stdout().flush()?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user