feat: initial commit for TheFarmer project

This commit is contained in:
Karriis
2026-02-18 13:52:06 +08:00
commit 8ceb5fa9db
420 changed files with 61918 additions and 0 deletions

139
server/client.js Normal file
View File

@@ -0,0 +1,139 @@
/**
* QQ经典农场 挂机脚本 - 入口文件
*
* 模块结构:
* src/config.js - 配置常量与枚举
* src/utils.js - 通用工具函数
* src/proto.js - Protobuf 加载与类型管理
* src/core/ - 核心逻辑 (FarmBot, Network, FarmManager, FriendManager)
* src/decode.js - PB解码/验证工具模式
*/
const { CONFIG } = require('./src/config');
const { loadProto } = require('./src/proto');
const { FarmBot } = require('./src/core/FarmBot');
const { verifyMode, decodeMode } = require('./src/decode');
const { emitRuntimeHint, sleep } = require('./src/utils');
// ============ 帮助信息 ============
function showHelp() {
console.log(`
QQ经典农场 挂机脚本 (重构版)
====================
用法:
node client.js --code <登录code> [--wx] [--interval <秒>] [--friend-interval <秒>]
node client.js --verify
node client.js --decode <数据> [--hex] [--gate] [--type <消息类型>]
参数:
--code 小程序 login() 返回的临时凭证 (必需)
--wx 使用微信登录 (默认为QQ小程序)
--interval 自己农场巡查完成后等待秒数, 默认10秒, 最低10秒
--friend-interval 好友巡查完成后等待秒数, 默认1秒, 最低1秒
--verify 验证proto定义
--decode 解码PB数据 (运行 --decode 无参数查看详细帮助)
功能:
- 自动收获成熟作物 → 购买种子 → 种植 → 施肥
- 自动除草、除虫、浇水
- 自动铲除枯死作物
- 自动巡查好友农场: 帮忙浇水/除草/除虫 + 偷菜
- 自动领取任务奖励 (支持分享翻倍)
- 每分钟自动出售仓库果实
- 启动时读取 share.txt 处理邀请码 (仅微信)
- 心跳保活
`);
}
// ============ 参数解析 ============
function parseArgs(args) {
const options = {
code: '',
deleteAccountMode: false,
name: '',
certId: '',
certType: 0,
};
for (let i = 0; i < args.length; i++) {
if (args[i] === '--code' && args[i + 1]) {
options.code = args[++i];
}
if (args[i] === '--wx') {
CONFIG.platform = 'wx';
}
if (args[i] === '--interval' && args[i + 1]) {
const sec = parseInt(args[++i]);
CONFIG.farmCheckInterval = Math.max(sec, 1) * 1000;
}
if (args[i] === '--friend-interval' && args[i + 1]) {
const sec = parseInt(args[++i]);
CONFIG.friendCheckInterval = Math.max(sec, 1) * 1000; // 最低1秒
}
}
return options;
}
// ============ 主函数 ============
async function main() {
const args = process.argv.slice(2);
// 加载 proto 定义
await loadProto();
// 验证模式
if (args.includes('--verify')) {
await verifyMode();
return;
}
// 解码模式
if (args.includes('--decode')) {
await decodeMode(args);
return;
}
// 正常运行模式
const options = parseArgs(args);
if (!options.code) {
showHelp();
return;
}
// 更新 CONFIG 中的 code (注意: FarmBot 构造函数会合并 CONFIG 和传入的 config)
// 这里我们可以直接修改全局 CONFIG或者传入 options
// 为了兼容旧代码习惯,我们修改全局 CONFIG
// 但 FarmBot 建议传入 config
const botConfig = {
code: options.code,
// 其他参数已通过 modify global CONFIG 生效,或者也可以显式传入
};
console.log('正在启动 FarmBot...');
const bot = new FarmBot(botConfig);
// 优雅退出
process.on('SIGINT', () => {
console.log('\n正在停止...');
bot.stop();
process.exit(0);
});
try {
await bot.start();
// 保持进程运行 (如果 start() 返回后没有挂起的操作)
// FarmBot 内部启动了 interval所以进程应该会保持运行
} catch (error) {
console.error('Bot 运行出错:', error);
process.exit(1);
}
}
main().catch(err => {
console.error('未捕获的异常:', err);
process.exit(1);
});