我也不知道这次提交是做什么的

This commit is contained in:
2026-07-22 02:18:01 +08:00
parent 2753fbba13
commit c8e5efe395
10 changed files with 2592 additions and 2580 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@
/.idea
/我是崩服小能手
/config.json
/release

View File

@@ -1,6 +1,6 @@
// bot的实现
use std::{io::{Error, Read, Write}, net::TcpStream, sync::Arc, thread::{self, sleep}, time::{self, Duration}};
use std::{io::{Error, Read, Write}, net::TcpStream, str::FromStr, sync::Arc, thread::{self, sleep}, time::{self, Duration}};
use log::{info, warn};
use rust_mc_proto::{DataBufferReader, DataBufferWriter, MinecraftConnection, Packet, ProtocolError};
@@ -11,7 +11,7 @@ use crate::{configuration::Configuration, utils};
// 让所有bot能够共享变量
pub struct BotVariable {
pub spam_file: Arc<Mutex<Option<tokio::fs::File>>>,
pub spam_cursor: Arc<Mutex<u64>>
pub spam_cursor: Arc<Mutex<u64>>,
}
// Bot主线程和worker线程间的通信
@@ -211,14 +211,24 @@ impl<T: StreamType> Bot<T> {
state: 0,
last_keepalive_sec: 0
};
let mut uuid_self = uuid::Uuid::from_str("550e8400-e29b-41d4-a716-446655440000").unwrap(); // 这个纯随机
let mut ent_self = 0;
match packet.id() {
0x02 => { // 成功登录
0x01 => { // spawn entity
let id = packet.read_i32_varint()?;
let uid = packet.read_uuid()?;
if uid.eq(&uuid_self) {
ent_self = id;
}
}
0x02 => { // 成功登录(Login Success)
// login success
info!("[{}] Successfully logged in!",self.username);
self.status = 1;
message.state = 1;
message.last_keepalive_sec = time::SystemTime::now().duration_since(time::SystemTime::UNIX_EPOCH).unwrap().as_secs();
status_tx.send(message).unwrap();
status_tx.send(message).unwrap_or(());
uuid_self = packet.read_uuid()?;
}
0x03 => {// 设置压缩CompressionThreshold
// set compression
@@ -231,14 +241,14 @@ impl<T: StreamType> Bot<T> {
0x23 => { // KeepAlive包
self.handle_keepalive(&mut packet).await?;
message.last_keepalive_sec = time::SystemTime::now().duration_since(time::SystemTime::UNIX_EPOCH).unwrap().as_secs();
status_tx.send(message).unwrap();
status_tx.send(message).unwrap_or(());
// println!("{}",self.status);
}
0x1A => {// 断连包
// disconnect
self.handle_disconnect(&mut packet).await?;
message.state = 2;
status_tx.send(message).unwrap();
status_tx.send(message).unwrap_or(());
break;
}
0x00 => {// 版本不匹配啥的就会走这
@@ -246,7 +256,7 @@ impl<T: StreamType> Bot<T> {
let text = packet.read_string()?;
warn!("[{}] Failed to login: {}", self.username, utils::parse_json_component(text.as_str()));
message.state = 2;
status_tx.send(message).unwrap();
status_tx.send(message).unwrap_or(());
break;
}
}
@@ -329,6 +339,7 @@ impl<T: StreamType> Bot<T> {
warn!("[{}/WORKER] Bot timed out", self.username);
break;
}
iter += 1;
}
sleep(Duration::from_millis(1));